Skip to content

Commit

Permalink
Merge pull request #93 from GermanBluefox/master
Browse files Browse the repository at this point in the history
Remove let
  • Loading branch information
GermanBluefox authored Nov 24, 2016
2 parents 2b10098 + 2030697 commit 155d80f
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/handler/client/ReadCoils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ module.exports = Stampit()
return
}

let cntr = 0
var cntr = 0
for (var i = 0; i < byteCount; i += 1) {
let h = 1
let cur = pdu.readUInt8(2 + i)
var h = 1
var cur = pdu.readUInt8(2 + i)
for (var j = 0; j < 8; j += 1) {
resp.coils[cntr] = (cur & h) > 0
h = h << 1
Expand All @@ -42,9 +42,9 @@ module.exports = Stampit()
}.bind(this)

this.readCoils = function (start, quantity) {
let fc = 1
let defer = Promise.defer()
let pdu = Buffer.allocUnsafe(5)
var fc = 1
var defer = Promise.defer()
var pdu = Buffer.allocUnsafe(5)

pdu.writeUInt8(fc, 0)
pdu.writeUInt16BE(start, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/ReadCoils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = stampit()
this.log.debug('handling read coils request.')

if (pdu.length !== 5) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x81, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -35,7 +35,7 @@ module.exports = stampit()
var mem = this.getCoils()

if (start > mem.length * 8 || start + quantity > mem.length * 8) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)
buf.writeUInt8(0x81, 0)
buf.writeUInt8(0x02, 1)
cb(buf)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/ReadDiscreteInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var handler = stampit()
if (pdu.length !== 5) {
this.log.debug('wrong pdu length.')

let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x82, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -40,7 +40,7 @@ var handler = stampit()
if (start > mem.length * 8 || start + quantity > mem.length * 8) {
this.log.debug('wrong pdu length.')

let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x82, 0)
buf.writeUInt8(0x02, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/ReadHoldingRegisters.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = stampit()
if (pdu.length !== 5) {
this.log.debug('wrong pdu length.')

let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x83, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -40,7 +40,7 @@ module.exports = stampit()

if (byteStart > mem.length || byteStart + (quantity * 2) > mem.length) {
this.log.debug('request outside register boundaries.')
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x83, 0)
buf.writeUInt8(0x02, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/ReadInputRegisters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = stampit()
this.log.debug('handling read input registers request.')

if (pdu.length !== 5) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x84, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -36,7 +36,7 @@ module.exports = stampit()
var mem = this.getInput()

if (byteStart > mem.length || byteStart + (quantity * 2) > mem.length) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x84, 0)
buf.writeUInt8(0x02, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/WriteMultipleCoils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = stampit()
this.log.debug('handling write multiple coils request.')

if (pdu.length < 3) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x8F, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -37,7 +37,7 @@ module.exports = stampit()

// error response
if (start > mem.length * 8 || start + quantity > mem.length * 8) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x8F, 0)
buf.writeUInt8(0x02, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/WriteMultipleRegisters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = stampit()
this.log.debug('handling write multiple registers request.')

if (pdu.length < 3) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x90, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -33,7 +33,7 @@ module.exports = stampit()
var byteCount = pdu.readUInt8(5)

if (quantity > 0x007b) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x90, 0)
buf.writeUInt8(0x03, 1)
Expand Down
6 changes: 3 additions & 3 deletions src/handler/server/WriteSingleCoil.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = stampit()
this.log.debug('handling write single coil request.')

if (pdu.length !== 5) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x85, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -31,7 +31,7 @@ module.exports = stampit()
var value = !(pdu.readUInt16BE(3) === 0x0000)

if (pdu.readUInt16BE(3) !== 0x0000 && pdu.readUInt16BE(3) !== 0xFF00) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x85, 0)
buf.writeUInt8(0x03, 1)
Expand All @@ -44,7 +44,7 @@ module.exports = stampit()
var mem = this.getCoils()

if (address > mem.length * 8) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x85, 0)
buf.writeUInt8(0x02, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/handler/server/WriteSingleRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = stampit()
this.log.debug('handling write single register request.')

if (pdu.length !== 5) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x86, 0)
buf.writeUInt8(0x02, 1)
Expand All @@ -36,7 +36,7 @@ module.exports = stampit()
var mem = this.getHolding()

if (byteAddress > mem.length) {
let buf = Buffer.allocUnsafe(2)
var buf = Buffer.allocUnsafe(2)

buf.writeUInt8(0x86, 0)
buf.writeUInt8(0x02, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/modbus-serial-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ module.exports = stampit()
crc = (buf.readUInt8(i) + crc) % 0xFFFF
}

let crc16 = crc.crc16modbus(buf)
let crcBuf = Buffer.allocUnsafe(2)
var crc16 = crc.crc16modbus(buf)
var crcBuf = Buffer.allocUnsafe(2)

crcBuf.writeUInt16LE(crc16, 0)

Expand Down
15 changes: 15 additions & 0 deletions src/modbus-tcp-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,20 @@ module.exports = stampit()
return this
}

// following is required to test of stream processing
// and is only during test active
if (process.env.DEBUG) {
this.getSocket = function () {
return socket
}
this.setCurrentRequestId = function (id) {
currentRequestId = id
}
this.registerOnSend = function (_onSend) {
this.removeListener(onSend)
this.on('send', _onSend.bind(this))
}
}

init()
})
2 changes: 1 addition & 1 deletion test/heap-test-coils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const client = modbus.client.tcp.complete({
client.connect()

client.on('connect', function () {
for (let i = 1; i < 1e5; i++) {
for (var i = 1; i < 1e5; i++) {
client.readCoils(0, 13)
}

Expand Down

0 comments on commit 155d80f

Please sign in to comment.