@canboat/canboatjs 2.5.4 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/fromPgn.js +3 -1
- package/lib/stringMsg.js +24 -4
- package/lib/toPgn.js +2 -1
- package/package.json +1 -1
package/lib/fromPgn.js
CHANGED
|
@@ -611,6 +611,7 @@ function readField(options, runPostProcessor, pgn, field, bs, fields) {
|
|
|
611
611
|
}
|
|
612
612
|
if ( options.checkForInvalidFields !== false && max !== 'undefined' &&
|
|
613
613
|
field.FieldType !== 'LOOKUP' &&
|
|
614
|
+
field.FieldType !== 'FIELDTYPE_LOOKUP' &&
|
|
614
615
|
field.BitLength > 1 &&
|
|
615
616
|
max - value <= 0 ) {
|
|
616
617
|
//console.log(`Bad field ${field.Name} ${max - value}`)
|
|
@@ -633,7 +634,8 @@ function readField(options, runPostProcessor, pgn, field, bs, fields) {
|
|
|
633
634
|
value = Number.parseFloat(value.toFixed(precision))
|
|
634
635
|
}
|
|
635
636
|
|
|
636
|
-
if (field.FieldType === 'LOOKUP'
|
|
637
|
+
if ((field.FieldType === 'LOOKUP' ||
|
|
638
|
+
field.FieldType === 'FIELDTYPE_LOOKUP') &&
|
|
637
639
|
runPostProcessor &&
|
|
638
640
|
(_.isUndefined(options.resolveEnums) ||
|
|
639
641
|
options.resolveEnums)) {
|
package/lib/stringMsg.js
CHANGED
|
@@ -112,10 +112,26 @@ exports.encodeYDRAW = ({ data, ...canIdInfo }) => {
|
|
|
112
112
|
return pgns.map(buffer => canId + ' ' + byteString(buffer, ' '))
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
const get0183Sentence = (msg) => {
|
|
116
|
+
let sentence = msg
|
|
117
|
+
if (sentence.charAt(0) === '\\') {
|
|
118
|
+
split = sentence.split('\\')
|
|
119
|
+
if ( split.length < 3 ) {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
sentence = split[2]
|
|
123
|
+
}
|
|
124
|
+
return sentence
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
// $PCDIN,01F119,00000000,0F,2AAF00D1067414FF*59
|
|
116
|
-
exports.isPCDIN =
|
|
128
|
+
exports.isPCDIN = (msg) => {
|
|
129
|
+
const sentence = get0183Sentence(msg)
|
|
130
|
+
return sentence.startsWith('$PCDIN,')
|
|
131
|
+
}
|
|
117
132
|
exports.parsePCDIN = (input) => {
|
|
118
|
-
const
|
|
133
|
+
const sentence = get0183Sentence(input)
|
|
134
|
+
const [ prefix, pgn, timeHex, src, data ] = sentence.split(',')
|
|
119
135
|
let timer = parseInt(timeHex, 32)
|
|
120
136
|
|
|
121
137
|
timer = timer / 1024
|
|
@@ -136,9 +152,13 @@ exports.encodePCDIN = ({ prefix = '$PCDIN', pgn, data, dst = 255}) => {
|
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
// $MXPGN,01F801,2801,C1308AC40C5DE343*19
|
|
139
|
-
exports.isMXPGN =
|
|
155
|
+
exports.isMXPGN = (msg) => {
|
|
156
|
+
const sentence = get0183Sentence(msg)
|
|
157
|
+
return sentence.startsWith('$MXPGN,')
|
|
158
|
+
}
|
|
140
159
|
exports.parseMXPGN = (input) => {
|
|
141
|
-
const
|
|
160
|
+
const sentence = get0183Sentence(input)
|
|
161
|
+
const [ prefix, pgn, attr_word, data ] = sentence.split(',')
|
|
142
162
|
|
|
143
163
|
const send_prio_len = (parseInt(attr_word.substr(0,2), 16).toString(2)).padStart(8, '0');
|
|
144
164
|
const addr = (parseInt(attr_word.substr(2,2), 16));
|
package/lib/toPgn.js
CHANGED
|
@@ -190,7 +190,8 @@ function writeField(bs, pgn_number, field, data, value, fields, bitLength) {
|
|
|
190
190
|
}
|
|
191
191
|
} else if ( type && fieldTypeMappers[type] ) {
|
|
192
192
|
value = fieldTypeMappers[type](field, value)
|
|
193
|
-
} else if (field.FieldType === 'LOOKUP'
|
|
193
|
+
} else if ((field.FieldType === 'LOOKUP' ||
|
|
194
|
+
field.FieldType === 'FIELDTYPE_LOOKUP') && _.isString(value)) {
|
|
194
195
|
if (!(field.Id === "timeStamp" && value < 60)) {
|
|
195
196
|
value = lookup(field, value)
|
|
196
197
|
}
|