diff --git a/src/longframe.ts b/src/longframe.ts index aa287a2..985f0f2 100644 --- a/src/longframe.ts +++ b/src/longframe.ts @@ -17,6 +17,10 @@ export namespace MeterbusLibLongFrame { this._fixedDataHeader = new FixedDataHeader(this._telegram.slice(7, 19)) this._fixedDataHeader.parse() } + + getJSON() : string { + return JSON.stringify(this) + } } export class FixedDataHeader { diff --git a/src/meterbus.test.ts b/src/meterbus.test.ts index 6e0092d..8f3c386 100644 --- a/src/meterbus.test.ts +++ b/src/meterbus.test.ts @@ -179,6 +179,9 @@ describe('The Meterbus Library', () => { expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.signature) .to.deep.equal(new Uint8Array([0,0])) }) + it('should print itself as json', () => { + console.log((telegram.frame as MeterbusLibLongFrame.LongFrame).getJSON()) + }) }) }) \ No newline at end of file diff --git a/src/utils.test.ts b/src/utils.test.ts index a00d03d..ae8819d 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -8,21 +8,21 @@ const expect = chai.expect describe('The Meterbus Library Utils', () => { it('should convert a bcd to a number (10203)', () => { - expect(MeterbusLibUtils.bcd([1, 2, 3])).to.equal(10203) + expect(MeterbusLibUtils.bcd(new Uint8Array([1, 2, 3]))).to.equal(10203) }) it('should convert a bcd to a number (0010203)', () => { - expect(MeterbusLibUtils.bcd([0, 1, 2, 3])).to.equal(10203) + expect(MeterbusLibUtils.bcd(new Uint8Array([0, 1, 2, 3]))).to.equal(10203) }) it('should convert a bcd to a number (0)', () => { - expect(MeterbusLibUtils.bcd([0, 0, 0])).to.equal(0) + expect(MeterbusLibUtils.bcd(new Uint8Array([0, 0, 0]))).to.equal(0) }) it('should convert a bcd to a number (0)', () => { - expect(MeterbusLibUtils.bcd([0, 0, 0, 0])).to.equal(0) + expect(MeterbusLibUtils.bcd(new Uint8Array([0, 0, 0, 0]))).to.equal(0) }) it('should convert a bcd to a number (99999999)', () => { - expect(MeterbusLibUtils.bcd([0x99, 0x99, 0x99, 0x99])).to.equal(99999999) + expect(MeterbusLibUtils.bcd(new Uint8Array([0x99, 0x99, 0x99, 0x99]))).to.equal(99999999) }) it('should convert two number to manufacturer code', () => { - expect(MeterbusLibUtils.manufCode([0x2e, 0x19])).to.equal("FIN") + expect(MeterbusLibUtils.manufCode(new Uint8Array([0x2e, 0x19]))).to.equal("FIN") }) })