properties beginning with two underscores will be automatically hidden from json
This commit is contained in:
parent
3d551201e8
commit
e857b7baa7
@ -4,25 +4,24 @@ import {MeterbusLibUtils} from './utils'
|
|||||||
export namespace MeterbusLibFrames {
|
export namespace MeterbusLibFrames {
|
||||||
export abstract class Frame {
|
export abstract class Frame {
|
||||||
protected _telegram : number[]
|
protected _telegram : number[]
|
||||||
protected _startCharacter : number
|
protected __startCharacter : number
|
||||||
protected _frameLength : number
|
protected __frameLength : number
|
||||||
protected _firstPayload : number
|
protected __firstPayload : number
|
||||||
protected _payloadLength : number
|
protected __payloadLength : number
|
||||||
|
|
||||||
constructor(startCharacter : number, frameLength : number,
|
constructor(startCharacter : number, frameLength : number,
|
||||||
firstPayload : number, telegram : number[]) {
|
firstPayload : number, telegram : number[]) {
|
||||||
this._startCharacter = startCharacter
|
this.__startCharacter = startCharacter
|
||||||
this._frameLength = frameLength
|
this.__frameLength = frameLength
|
||||||
this._firstPayload = firstPayload
|
this.__firstPayload = firstPayload
|
||||||
this._telegram = telegram
|
this._telegram = telegram
|
||||||
this._payloadLength = this._frameLength - 6
|
this.__payloadLength = this.__frameLength - 6
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
toJSON() : any {
|
toJSON() : any {
|
||||||
return MeterbusLibUtils.jsonPrepaper(this, ["_startCharacter", "_frameLength",
|
return MeterbusLibUtils.jsonPrepaper(this, [])
|
||||||
"_firstPayload", "_payloadLength" ])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getJSON() : string {
|
getJSON() : string {
|
||||||
@ -30,12 +29,12 @@ export namespace MeterbusLibFrames {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verifyChecksumAndEnd() {
|
verifyChecksumAndEnd() {
|
||||||
if (this._firstPayload != 0) {
|
if (this.__firstPayload != 0) {
|
||||||
if (this._telegram[this._telegram.length - 1] != 0x16) {
|
if (this._telegram[this._telegram.length - 1] != 0x16) {
|
||||||
throw new MeterbusLibExceptions.InvalidStopCharError()
|
throw new MeterbusLibExceptions.InvalidStopCharError()
|
||||||
}
|
}
|
||||||
let checksum : number = 0
|
let checksum : number = 0
|
||||||
this._telegram.slice(this._firstPayload, this._telegram.length -2).forEach((val) => {
|
this._telegram.slice(this.__firstPayload, this._telegram.length -2).forEach((val) => {
|
||||||
checksum += val
|
checksum += val
|
||||||
})
|
})
|
||||||
// console.log(`calc. checksum ${checksum}, ${checksum & 0xff}`)
|
// console.log(`calc. checksum ${checksum}, ${checksum & 0xff}`)
|
||||||
@ -49,10 +48,10 @@ export namespace MeterbusLibFrames {
|
|||||||
abstract parse2()
|
abstract parse2()
|
||||||
|
|
||||||
parse() {
|
parse() {
|
||||||
if (this._telegram[0] != this._startCharacter) {
|
if (this._telegram[0] != this.__startCharacter) {
|
||||||
throw new MeterbusLibExceptions.InvalidStartCharError()
|
throw new MeterbusLibExceptions.InvalidStartCharError()
|
||||||
}
|
}
|
||||||
if (this._telegram.length != this._frameLength) {
|
if (this._telegram.length != this.__frameLength) {
|
||||||
throw new MeterbusLibExceptions.InvalidLengthError()
|
throw new MeterbusLibExceptions.InvalidLengthError()
|
||||||
}
|
}
|
||||||
this.verifyChecksumAndEnd()
|
this.verifyChecksumAndEnd()
|
||||||
@ -83,10 +82,10 @@ export namespace MeterbusLibFrames {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse2() {
|
parse2() {
|
||||||
if (this._telegram[2] != this._payloadLength) {
|
if (this._telegram[2] != this.__payloadLength) {
|
||||||
throw new MeterbusLibExceptions.InvalidSecondLengthError()
|
throw new MeterbusLibExceptions.InvalidSecondLengthError()
|
||||||
}
|
}
|
||||||
if (this._payloadLength < 3) {
|
if (this.__payloadLength < 3) {
|
||||||
throw new MeterbusLibExceptions.PayloadTooShortError()
|
throw new MeterbusLibExceptions.PayloadTooShortError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,7 @@ export namespace MeterbusLibUtils {
|
|||||||
export function jsonPrepaper(obj:any, hideKeys:string[]) : any {
|
export function jsonPrepaper(obj:any, hideKeys:string[]) : any {
|
||||||
let dup = {}
|
let dup = {}
|
||||||
for (let key in obj) {
|
for (let key in obj) {
|
||||||
if (hideKeys.indexOf(key) == -1) {
|
if ((hideKeys.indexOf(key) == -1) && ! ((key[0] == "_") && (key[1] == "_"))) {
|
||||||
//if (key[0] == "_") {
|
|
||||||
// key = key.slice(1)
|
|
||||||
//}
|
|
||||||
let dkey = (key[0] == "_") ? key.slice(1) : key
|
let dkey = (key[0] == "_") ? key.slice(1) : key
|
||||||
dup[dkey] = obj[key]
|
dup[dkey] = obj[key]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user