parse FixedDataHeader in longframe
This commit is contained in:
parent
0c998e7709
commit
41a38f2d50
31
src/codetables.ts
Normal file
31
src/codetables.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
export namespace MeterbusLibCodeTables {
|
||||||
|
export const MEDIUM_CODE : string[] =
|
||||||
|
['Other',
|
||||||
|
'Oil',
|
||||||
|
'Electrity',
|
||||||
|
'Gas',
|
||||||
|
'Heat (Volume measured at return temperature: outlet',
|
||||||
|
'Steam',
|
||||||
|
'Hot Water',
|
||||||
|
'Water',
|
||||||
|
'Heat Cost Allocator',
|
||||||
|
'Compressed Air',
|
||||||
|
'Cooling Load Meter (Volume measured at return temperature: outlet',
|
||||||
|
'Cooling Load Meter (Volume measured at flow temperature: inlet',
|
||||||
|
'Heat (Volume measured at flow temperature: inlet)',
|
||||||
|
'Heat / Cooling Load Meter',
|
||||||
|
'Bus / System',
|
||||||
|
'Unknown Medium',
|
||||||
|
'Reserved (10)',
|
||||||
|
'Reserved (11)',
|
||||||
|
'Reserved (12)',
|
||||||
|
'Reserved (13)',
|
||||||
|
'Reserved (14)',
|
||||||
|
'Reserved (15)',
|
||||||
|
'Cold Water',
|
||||||
|
'Dual Water',
|
||||||
|
'Pressure',
|
||||||
|
'A/D Converter',
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
export {MeterbusLib} from './meterbus'
|
export {MeterbusLib} from './meterbus'
|
||||||
export {MeterbusLibUtils} from './utils'
|
export {MeterbusLibUtils} from './utils'
|
||||||
export {MeterbusLibLongFrame} from './longframe'
|
export {MeterbusLibLongFrame} from './longframe'
|
||||||
import {MeterbusLibExceptions} from './exceptions'
|
export {MeterbusLibExceptions} from './exceptions'
|
||||||
import {MeterbusLibFrames} from './simpleframes'
|
export {MeterbusLibFrames} from './simpleframes'
|
||||||
|
export {MeterbusLibCodeTables} from './codetables'
|
||||||
|
@ -1,16 +1,60 @@
|
|||||||
import {MeterbusLibExceptions} from './exceptions'
|
import {MeterbusLibExceptions} from './exceptions'
|
||||||
import {MeterbusLibFrames} from './simpleframes'
|
import {MeterbusLibFrames} from './simpleframes'
|
||||||
|
import {MeterbusLibUtils} from './utils'
|
||||||
|
import {MeterbusLibCodeTables} from './codetables'
|
||||||
|
|
||||||
export namespace MeterbusLibLongFrame {
|
export namespace MeterbusLibLongFrame {
|
||||||
export class LongFrame extends MeterbusLibFrames.ControlFrame {
|
export class LongFrame extends MeterbusLibFrames.ControlFrame {
|
||||||
|
private _fixedDataHeader : FixedDataHeader
|
||||||
|
get fixedDataHeader() : FixedDataHeader { return this._fixedDataHeader }
|
||||||
|
|
||||||
constructor(telegram : number[]) {
|
constructor(telegram : number[]) {
|
||||||
super(telegram)
|
super(telegram)
|
||||||
}
|
}
|
||||||
|
|
||||||
parse2() {
|
parse2() {
|
||||||
super.parse2() // control frame parse2 method
|
super.parse2() // control frame parse2 method
|
||||||
|
this._fixedDataHeader = new FixedDataHeader(this._telegram.slice(7, 19))
|
||||||
|
this._fixedDataHeader.parse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class FixedDataHeader {
|
||||||
|
private _data : number[]
|
||||||
|
|
||||||
|
private _identNo : number
|
||||||
|
private _manufacturer : string
|
||||||
|
private _version : number
|
||||||
|
private _medium : string
|
||||||
|
private _accessNo : number
|
||||||
|
private _status : number
|
||||||
|
private _signature : number[]
|
||||||
|
|
||||||
|
get identNo() : number { return this._identNo }
|
||||||
|
get manufacturer() : string { return this._manufacturer }
|
||||||
|
get version() : number { return this._version }
|
||||||
|
get medium() : string { return this._medium }
|
||||||
|
get accessNo() : number { return this._accessNo }
|
||||||
|
get status() : number { return this._status }
|
||||||
|
get signature() : number[] { return this._signature }
|
||||||
|
|
||||||
|
constructor(data : number[]) {
|
||||||
|
this._data = data
|
||||||
|
}
|
||||||
|
|
||||||
|
parse() : void {
|
||||||
|
this._identNo = MeterbusLibUtils.bcd(this._data.slice(0, 4))
|
||||||
|
this._manufacturer = MeterbusLibUtils.manufCode(this._data.slice(4, 6))
|
||||||
|
this._version = this._data[6]
|
||||||
|
this._medium = MeterbusLibCodeTables.MEDIUM_CODE[this._data[7]]
|
||||||
|
this._accessNo = this._data[8]
|
||||||
|
this._status = this._data[9]
|
||||||
|
this._signature = this._data.slice(10, 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
getJSON() : string {
|
||||||
|
return JSON.stringify(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ import {MeterbusLib} from './meterbus'
|
|||||||
import {MeterbusLibLongFrame} from './longframe'
|
import {MeterbusLibLongFrame} from './longframe'
|
||||||
import {MeterbusLibExceptions} from './exceptions'
|
import {MeterbusLibExceptions} from './exceptions'
|
||||||
import {MeterbusLibFrames} from './simpleframes'
|
import {MeterbusLibFrames} from './simpleframes'
|
||||||
|
import {MeterbusLibCodeTables} from './codetables'
|
||||||
|
|
||||||
|
|
||||||
import * as mocha from 'mocha'
|
import * as mocha from 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
@ -134,4 +136,43 @@ describe('The Meterbus Library', () => {
|
|||||||
expect((telegram.frame as MeterbusLibFrames.ControlFrame).ciField).to.equal(3)
|
expect((telegram.frame as MeterbusLibFrames.ControlFrame).ciField).to.equal(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('The Meterbus Longframe Library', () => {
|
||||||
|
let telegram : MeterbusLib.Telegram
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
telegram = new MeterbusLib.Telegram()
|
||||||
|
telegram.fromHexString(inputOkLongFrame_1phase_electric)
|
||||||
|
telegram.parse()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should find the identNo', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.identNo)
|
||||||
|
.to.equal(17001300)
|
||||||
|
})
|
||||||
|
it('should find the manufacturer', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.manufacturer)
|
||||||
|
.to.equal("FIN")
|
||||||
|
})
|
||||||
|
it('should find the version', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.version)
|
||||||
|
.to.equal(0x24)
|
||||||
|
})
|
||||||
|
it('should find the medium', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.medium)
|
||||||
|
.to.equal("Electrity")
|
||||||
|
})
|
||||||
|
it('should find the accessNo', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.accessNo)
|
||||||
|
.to.equal(0xd6)
|
||||||
|
})
|
||||||
|
it('should find the status', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.status)
|
||||||
|
.to.equal(0)
|
||||||
|
})
|
||||||
|
it('should find the signature', () => {
|
||||||
|
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.signature)
|
||||||
|
.to.deep.equal([0,0])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
@ -22,4 +22,7 @@ describe('The Meterbus Library Utils', () => {
|
|||||||
it('should convert a bcd to a number (99999999)', () => {
|
it('should convert a bcd to a number (99999999)', () => {
|
||||||
expect(MeterbusLibUtils.bcd([0x99, 0x99, 0x99, 0x99])).to.equal(99999999)
|
expect(MeterbusLibUtils.bcd([0x99, 0x99, 0x99, 0x99])).to.equal(99999999)
|
||||||
})
|
})
|
||||||
|
it('should convert two number to manufacturer code', () => {
|
||||||
|
expect(MeterbusLibUtils.manufCode([0x2e, 0x19])).to.equal("FIN")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -9,4 +9,8 @@ export namespace MeterbusLibUtils {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function manufCode(data : number[]) : string {
|
||||||
|
let v : number = (data[1] << 8) + data[0]
|
||||||
|
return String.fromCharCode((((v >> 10) & 0x1f) + 64), (((v >> 5) & 0x1f) + 64), ((v & 0x1f) + 64))
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user