var readState = function (cb) { var ads = this var buf = Buffer.alloc(0) var options = { commandId: ID_READ_STATE, data: buf, cb: cb } runCommand.call(ads, options) }
function align (ps, n) { var pad = n - ps._offset % n; if (pad === 0 || pad === n) return; // TODO: write8(0) in a loop (3 to 7 times here) could be more efficient var padBuff = Buffer.alloc(pad); ps.put(Buffer.from(padBuff)); ps._offset += pad; }
var getWriteReadResult = function (data, cb) { var ads = this var adsError = data.readUInt32LE(0) var result // emitAdsError.call(ads, adsError) var err = getError(adsError) if (!err) { var bytelength = data.readUInt32LE(4) result = Buffer.alloc(bytelength) data.copy(result, 0, 8, 8 + bytelength) } cb.call(ads, err, result) }
/// ///////////////////// COMMANDS /////////////////////// var readCommand = function (commandOptions, cb) { var buf = Buffer.alloc(12) buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.bytelength, 8) var options = { commandId: ID_READ, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
function Parser(options) { options = options || {}; this._supportBigNumbers = options.config && options.config.supportBigNumbers; this._buffer = Buffer.alloc(0); this._nextBuffers = new BufferList(); this._longPacketBuffers = new BufferList(); this._offset = 0; this._packetEnd = null; this._packetHeader = null; this._packetOffset = null; this._onError = options.onError || function(err) { throw err; }; this._onPacket = options.onPacket || function() {}; this._nextPacketNumber = 0; this._encoding = 'utf-8'; this._paused = false; }
var deleteDeviceNotificationCommand = function (notificationHandle, cb) { var ads = this if (ads.connected) { var buf = Buffer.alloc(4) buf.writeUInt32LE(notificationHandle, 0) var options = { commandId: ID_DEL_NOTIFICATION, data: buf, cb: cb } runCommand.call(ads, options) } else if (typeof cb !== 'undefined') cb.call(ads) }
const readState = function(callback) { var buf = Buffer.alloc(0); var options = { commandId: ID.READ_STATE, data: buf, callback: callback }; command.run.call(this, options); }
var writeCommand = function (commandOptions, cb) { var buf = Buffer.alloc(12 + commandOptions.bytelength) buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.bytelength, 8) commandOptions.bytes.copy(buf, 12) var options = { commandId: ID_WRITE, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
var writeReadCommand = function (commandOptions, cb) { var buf = Buffer.alloc(16 + commandOptions.writeBuffer.length) buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.readLength, 8) buf.writeUInt32LE(commandOptions.writeBuffer.length, 12) commandOptions.writeBuffer.copy(buf, 16) var options = { commandId: ID_READ_WRITE, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
size = data.readUInt32LE(offset) offset += 4 var buf = Buffer.alloc(size) data.copy(buf, 0, offset) offset += size
/// ///////////////// HELPERS ///////////////////////////////////////// var stringToBuffer = function (someString) { var buf = Buffer.alloc(someString.length + 1) buf.write(someString) buf[someString.length] = 0 return buf }
var addNotificationCommand = function (commandOptions, cb) { var buf = Buffer.alloc(40); buf.writeUInt32LE(commandOptions.indexGroup, 0) buf.writeUInt32LE(commandOptions.indexOffset, 4) buf.writeUInt32LE(commandOptions.bytelength, 8) buf.writeUInt32LE(commandOptions.transmissionMode, 12) buf.writeUInt32LE(commandOptions.maxDelay, 16) buf.writeUInt32LE(commandOptions.cycleTime * 10000, 20) buf.writeUInt32LE(0, 24) buf.writeUInt32LE(0, 28) buf.writeUInt32LE(0, 32) buf.writeUInt32LE(0, 36) var options = { commandId: ID_ADD_NOTIFICATION, data: buf, cb: cb, symname: commandOptions.symname } runCommand.call(this, options) }
// ///////////////////// ADS FUNCTIONS /////////////////////// const readDeviceInfo = function(callback) { var buf = Buffer.alloc(0); var options = { commandId: ID.READ_DEVICE_INFO, data: buf, callback: callback }; command.run.call(this, options); }
/// //////////////////// ADS FUNCTIONS /////////////////////// var readDeviceInfo = function (cb) { var ads = this var buf = Buffer.alloc(0) var options = { commandId: ID_READ_DEVICE_INFO, data: buf, cb: cb } runCommand.call(ads, options) }
var getReadResult = function (data, cb) { var ads = this var adsError = data.readUInt32LE(0) var result // emitAdsError.call(ads, adsError) var err = getError(adsError) if (!err) { var bytelength = data.readUInt32LE(4) result = Buffer.alloc(bytelength) data.copy(result, 0, 8, 8 + bytelength) } cb.call(ads, err, result) }