@canboat/canboatjs 1.24.2 → 1.24.3
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/toPgn.js +30 -0
- package/package.json +1 -1
package/lib/toPgn.js
CHANGED
|
@@ -327,6 +327,36 @@ const actisenseToiKonvert = _.flow(parseActisense, encodePDGY)
|
|
|
327
327
|
const actisenseToN2KAsciiFormat = _.flow(parseActisense, encodeActisenseN2KACSII)
|
|
328
328
|
const actisenseToN2KActisenseFormat = _.flow(parseActisense, encodeN2KActisense)
|
|
329
329
|
|
|
330
|
+
function bitIsSet(field, index, value) {
|
|
331
|
+
if (!field.value2name) {
|
|
332
|
+
field.value2name = {};
|
|
333
|
+
field.EnumBitValues.forEach(function(enumPair) {
|
|
334
|
+
var key = _.keys(enumPair)[0]
|
|
335
|
+
field.value2name[Number(key)] = enumPair[key]
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
return value.indexOf(field.value2name[index]) != -1
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
fieldTypeWriters['Bitfield'] = (pgn, field, value, bs) => {
|
|
342
|
+
if ( _.isUndefined(value) || value.length === 0 ) {
|
|
343
|
+
if ( field.BitLength % 8 == 0 ) {
|
|
344
|
+
var bytes = field.BitLength/8
|
|
345
|
+
var lastByte = field.Signed ? 0x7f : 0xff
|
|
346
|
+
for ( var i = 0; i < bytes-1; i++ ) {
|
|
347
|
+
bs.writeUint8(0x0)
|
|
348
|
+
}
|
|
349
|
+
bs.writeUint8(0x0)
|
|
350
|
+
} else {
|
|
351
|
+
bs.writeBits(0xffffffff, field.BitLength)
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
for ( var i = 0; i < field.BitLength; i++ ) {
|
|
355
|
+
bs.writeBits(bitIsSet(field, i, value) ? 1 : 0, 1)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
330
360
|
fieldTypeWriters['ASCII text'] = (pgn, field, value, bs) => {
|
|
331
361
|
|
|
332
362
|
let fill = 0xff
|