<commit_before>// Part of <http://miracle.systems/p/h5.modbus> licensed under <MIT>

'use strict';

const inspect = require('util').inspect;
const helpers = require('../helpers');
const FunctionCode = require('../FunctionCode');
const Request = require('../Request');

/**
 * The write multiple registers request (code 0x10).
 *
 * A binary representation of this request varies in length and consists of:
 *
 *   - a function code (1 byte),
 *   - a starting address (2 bytes),
 *   - a quantity of registers (2 bytes),
 *   - a byte count (`n`; 1 byte),
 *   - new register data (`n` bytes).
 */
class WriteMultipleRegistersRequest extends Request
{
  /**
   * @param {number} startingAddress A starting address of the registers to write. Must be between 0 and 0xFFFF.
   * @param {Buffer} values Register values to write. Must have an even length of between 2 and 246 bytes.
   * @throws {Error} If the specified `startingAddress` is not a number between 0 and 0xFFFF.
   * @throws {Error} If the specified `values` is not an array of length between 1 and 1968.
   * @throws {Error} If the sum of `startingAddress` and a half of `values.length` is not between 1 and 0x10000.
   */
  constructor(startingAddress, values)
  {
    super(FunctionCode.WriteMultipleCoils);

    /**
     * Register values to write. A Buffer of even length between 2 and 246 bytes.
     *
     * @readonly
     * @type {Buffer}
     */
    this.values = helpers.prepareRegisterValues(values);

    /**
     * A starting address of the registers to write. A number between 0 and 0xFFFF.
     *
     * @readonly
     * @type {number}
     */
    this.startingAddress = helpers.prepareAddress(startingAddress, this.quantity);
  }

  /**
   * Creates a new request from the specified `options`.
   *
   * @param {Object} options
   * @param {number} [options.startingAddress=0] A starting address of the outputs to set.
   * If specified, must be a number between 0 and 0xFFFF. Defaults to 0.
   * @param {Buffer} options.values Register values to write.
   * Must be a Buffer of even length between 2 and 246 bytes.
   * @returns {WriteMultipleRegistersRequest}
   * @throws {Error} If any of the specified `options` are invalid.
   */<commit_msg>WriteMultipleRegistersRequest: fixed an invalid function code.<commit_after>// Part of <http://miracle.systems/p/h5.modbus> licensed under <MIT>

'use strict';

const inspect = require('util').inspect;
const helpers = require('../helpers');
const FunctionCode = require('../FunctionCode');
const Request = require('../Request');

/**
 * The write multiple registers request (code 0x10).
 *
 * A binary representation of this request varies in length and consists of:
 *
 *   - a function code (1 byte),
 *   - a starting address (2 bytes),
 *   - a quantity of registers (2 bytes),
 *   - a byte count (`n`; 1 byte),
 *   - new register data (`n` bytes).
 */
class WriteMultipleRegistersRequest extends Request
{
  /**
   * @param {number} startingAddress A starting address of the registers to write. Must be between 0 and 0xFFFF.
   * @param {Buffer} values Register values to write. Must have an even length of between 2 and 246 bytes.
   * @throws {Error} If the specified `startingAddress` is not a number between 0 and 0xFFFF.
   * @throws {Error} If the specified `values` is not an array of length between 1 and 1968.
   * @throws {Error} If the sum of `startingAddress` and a half of `values.length` is not between 1 and 0x10000.
   */
  constructor(startingAddress, values)
  {
    super(FunctionCode.WriteMultipleRegisters);

    /**
     * Register values to write. A Buffer of even length between 2 and 246 bytes.
     *
     * @readonly
     * @type {Buffer}
     */
    this.values = helpers.prepareRegisterValues(values);

    /**
     * A starting address of the registers to write. A number between 0 and 0xFFFF.
     *
     * @readonly
     * @type {number}
     */
    this.startingAddress = helpers.prepareAddress(startingAddress, this.quantity);
  }

  /**
   * Creates a new request from the specified `options`.
   *
   * @param {Object} options
   * @param {number} [options.startingAddress=0] A starting address of the outputs to set.
   * If specified, must be a number between 0 and 0xFFFF. Defaults to 0.
   * @param {Buffer} options.values Register values to write.
   * Must be a Buffer of even length between 2 and 246 bytes.
   * @returns {WriteMultipleRegistersRequest}
   * @throws {Error} If any of the specified `options` are invalid.
   */
{'fraction_non_alphanumeric': 0.1057542768273717, 'fraction_numerical': 0.01866251944012442, 'mean_word_length': 3.2035480859010272, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1360647', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1252, 'n_words': 529}