forked from z0mt3c/ehz-sml-reader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
28 lines (24 loc) · 2.16 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const assert = require('assert')
const mockBinding = require('serialport/lib/bindings/mock')
const Reader = require('./index.js')
describe('Reader', () => {
describe('#on("data")', () => {
it('should provide a message', (done) => {
// Create a port for fun and profit
mockBinding.reset()
mockBinding.createPort('/dev/mock', { echo: true })
const reader = new Reader({ port: '/dev/mock', portOptions: {binding: mockBinding }})
reader.on('data', (msg) => {
console.log(msg)
assert.equal(msg.total, 197.4644, 'Total should be given')
assert.equal(msg.t1, 197.4644, 't1 should be given')
assert.equal(msg.t2, 0, 't2 should be given')
assert.equal(msg.w1, 215, 'w1 should be given')
done()
})
reader.on('open', () => {
reader._port.binding.emitData(new Buffer('1b1b1b1b010101017605003a95bb6200620072630101760101050013873f0b0649534b010e1f5a783c010163c5be007605003a95bc620062007263070177010b0649534b010e1f5a783c070100620affff72620165002582d07777078181c78203ff010101010449534b0177070100000009ff010101010b0649534b010e1f5a783c0177070100010800ff650000018201621e52ff5900000000001e21740177070100010801ff0101621e52ff5900000000001e21740177070100010802ff0101621e52ff5900000000000000000177070100100700ff0101621b520055000000d70177078181c78205ff010101018302e22de327ff72f076d2fbdb01cf88d170872a19232939373871d28b6725e7dae09b22976cd40eaf5fb409c74ac5493f3001010163d55e007605003a95bd6200620072630201710163d85c001b1b1b1b1a00ccea1b1b1b1b010101017605003a95be620062007263010176010105001387400b0649534b010e1f5a783c01016319b2007605003a95bf620062007263070177010b0649534b010e1f5a783c070100620affff72620165002582d27777078181c78203ff010101010449534b0177070100000009ff010101010b0649534b010e1f5a783c0177070100010800ff650000018201621e52ff5900000000001e21750177070100010801ff0101621e52ff5900000000001e21750177070100010802ff0101621e52ff5900000000000000000177070100100700ff0101621b520055000000d60177078181c78205ff010101018302e22de327ff72f076d2fbdb01cf88d170872a19232939373871d28b6725e7dae09b22976cd40eaf5fb409c74ac5493f30010101633c0f007605003a95c062006200726302017101637cb5001b1b1b1b1a000418', 'hex'))
})
})
})
})