@canboat/canboatjs 3.3.3 → 3.3.4

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.
Files changed (73) hide show
  1. package/dist/bin/actisense-file.js +2 -0
  2. package/dist/bin/actisense-file.js.map +1 -1
  3. package/dist/bin/actisense-n2k-tcp.js +2 -0
  4. package/dist/bin/actisense-n2k-tcp.js.map +1 -1
  5. package/dist/bin/actisense-serialjs.js +2 -0
  6. package/dist/bin/actisense-serialjs.js.map +1 -1
  7. package/dist/bin/analyzerjs.js +2 -0
  8. package/dist/bin/analyzerjs.js.map +1 -1
  9. package/dist/bin/candumpjs.js +7 -4
  10. package/dist/bin/candumpjs.js.map +1 -1
  11. package/dist/bin/cansend.js +2 -0
  12. package/dist/bin/cansend.js.map +1 -1
  13. package/dist/bin/to-pgn.js +2 -0
  14. package/dist/bin/to-pgn.js.map +1 -1
  15. package/dist/bin/utils.d.ts +4 -0
  16. package/dist/bin/utils.d.ts.map +1 -0
  17. package/dist/bin/utils.js +15 -0
  18. package/dist/bin/utils.js.map +1 -0
  19. package/dist/bin/ydvr-file.d.ts +3 -0
  20. package/dist/bin/ydvr-file.d.ts.map +1 -0
  21. package/dist/bin/ydvr-file.js +31 -0
  22. package/dist/bin/ydvr-file.js.map +1 -0
  23. package/dist/fromPgn.d.ts.map +1 -1
  24. package/dist/fromPgn.js +1 -0
  25. package/dist/fromPgn.js.map +1 -1
  26. package/package.json +3 -2
  27. package/tsconfig.tsbuildinfo +1 -1
  28. package/.github/workflows/publish.yml +0 -32
  29. package/.github/workflows/release_on_tag.yml +0 -27
  30. package/.github/workflows/require_pr_label.yml +0 -13
  31. package/.github/workflows/test.yml +0 -28
  32. package/.github/workflows/test_canboat_changes.yml +0 -92
  33. package/examples/signalk-device-emulator/index.js +0 -1
  34. package/examples/signalk-device-emulator/package.json +0 -24
  35. package/examples/simpleCan.js +0 -42
  36. package/ios.js +0 -67
  37. package/lib/actisense-serial.ts +0 -644
  38. package/lib/bin/actisense-file.ts +0 -53
  39. package/lib/bin/actisense-n2k-tcp.ts +0 -50
  40. package/lib/bin/actisense-serialjs.ts +0 -55
  41. package/lib/bin/analyzerjs.ts +0 -91
  42. package/lib/bin/candumpjs.ts +0 -100
  43. package/lib/bin/cansend.ts +0 -131
  44. package/lib/bin/ikonvert-serial.ts +0 -44
  45. package/lib/bin/to-pgn.ts +0 -65
  46. package/lib/bin/ydvr-file +0 -33
  47. package/lib/canId.test.js +0 -61
  48. package/lib/canId.ts +0 -84
  49. package/lib/canbus.ts +0 -293
  50. package/lib/candevice.ts +0 -41
  51. package/lib/codes.ts +0 -21
  52. package/lib/discovery.ts +0 -118
  53. package/lib/fromPgn.ts +0 -1217
  54. package/lib/fromPgnStream.ts +0 -54
  55. package/lib/ikonvert.ts +0 -250
  56. package/lib/index.ts +0 -48
  57. package/lib/n2k-actisense.test.js +0 -58
  58. package/lib/n2k-actisense.ts +0 -152
  59. package/lib/n2kDevice.ts +0 -509
  60. package/lib/pgns.test.ts +0 -12
  61. package/lib/pgns.ts +0 -191
  62. package/lib/simpleCan.ts +0 -140
  63. package/lib/stringMsg.test.js +0 -288
  64. package/lib/stringMsg.ts +0 -478
  65. package/lib/toPgn.ts +0 -601
  66. package/lib/utilities.test.js +0 -8
  67. package/lib/utilities.ts +0 -169
  68. package/lib/venus-mqtt.js +0 -118
  69. package/lib/venus.js +0 -88
  70. package/lib/w2k01.ts +0 -142
  71. package/lib/yddevice.ts +0 -48
  72. package/lib/ydgw02.ts +0 -197
  73. package/lib/ydvr.js +0 -138
package/lib/toPgn.ts DELETED
@@ -1,601 +0,0 @@
1
- /**
2
- * Copyright 2018 Scott Bender (scott@scottbender.net)
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import { Field, PGN } from '@canboat/ts-pgns'
18
- import { getField } from './fromPgn'
19
- import {
20
- getPgn,
21
- getCustomPgn,
22
- lookupEnumerationValue,
23
- lookupFieldTypeEnumerationValue,
24
- lookupBitEnumerationName,
25
- lookupFieldTypeEnumerationBits
26
- } from './pgns'
27
- import _ from 'lodash'
28
- import { BitStream } from 'bit-buffer'
29
- import { Int64LE, Uint64LE } from 'int64-buffer'
30
- import {
31
- encodeActisense,
32
- encodeActisenseN2KACSII,
33
- encodeYDRAW,
34
- encodeYDRAWFull,
35
- parseActisense,
36
- encodePCDIN,
37
- encodeMXPGN,
38
- encodePDGY
39
- } from './stringMsg'
40
- import { encodeN2KActisense } from './n2k-actisense'
41
- import { createDebug } from './utilities'
42
-
43
- const debug = createDebug('canboatjs:toPgn')
44
-
45
- const RES_STRINGLAU = 'STRING_LAU' //'ASCII or UNICODE string starting with length and control byte'
46
- const RES_STRINGLZ = 'STRING_LZ' //'ASCII string starting with length byte'
47
-
48
- type FieldTypeWriter = (
49
- pgn: number,
50
- field: Field,
51
- value: any,
52
- bs: BitStream
53
- ) => void
54
- type FieldTypeMapper = (field: Field, value: any) => any
55
-
56
- const fieldTypeWriters: {
57
- [key: string]: FieldTypeWriter
58
- } = {}
59
- const fieldTypeMappers: {
60
- [key: string]: FieldTypeMapper
61
- } = {}
62
-
63
- //const lengthsOff: {[key: number]: number} = { 129029: 45, 127257:8, 127258:8, 127251:8 }
64
-
65
- const a126208_oldKey = '# of Parameters'
66
- const a126208_newKey = 'Number of Parameters'
67
-
68
- export function toPgn(data: any): Buffer | undefined {
69
- const customPgns = getCustomPgn(data.pgn)
70
- let pgnList = getPgn(data.pgn)
71
- if (!pgnList && !customPgns) {
72
- debug('no pgn found: ' + data.pgn)
73
- return
74
- }
75
-
76
- if (customPgns) {
77
- pgnList = [...customPgns.definitions, ...(pgnList || [])]
78
- }
79
-
80
- if (!pgnList || pgnList.length === 0) {
81
- debug('no pgn found: ' + data.pgn)
82
- return undefined
83
- }
84
-
85
- const pgn_number = data.pgn
86
- let pgnData = pgnList[0]
87
-
88
- const bs = new BitStream(Buffer.alloc(500))
89
-
90
- if (data.fields) {
91
- data = data.fields
92
- }
93
-
94
- if (pgn_number === 126208 && !data[a126208_newKey] && data[a126208_oldKey]) {
95
- //a bit of a hack because this field name changed and I'm sure there is code out
96
- //there that still uses the old field name
97
-
98
- data[a126208_newKey] = data[a126208_oldKey]
99
- }
100
-
101
- let fields = pgnData.Fields
102
- let RepeatingFields = pgnData.RepeatingFieldSet1Size
103
- ? pgnData.RepeatingFieldSet1Size
104
- : 0
105
- for (let index = 0; index < fields.length - RepeatingFields; index++) {
106
- const field = fields[index]
107
- let value =
108
- data[field.Name] !== undefined ? data[field.Name] : data[field.Id]
109
-
110
- if (!_.isUndefined(field.Match)) {
111
- //console.log(`matching ${field.Name} ${field.Match} ${value} ${_.isString(value)}`)
112
- if (_.isString(value)) {
113
- pgnList = pgnList.filter((f) => f.Fields[index].Description == value)
114
- } else {
115
- pgnList = pgnList.filter((f) => f.Fields[index].Match == value)
116
- }
117
- if (pgnList.length > 0) {
118
- //console.log(`matched ${field.Name} ${pgnList[0].Fields[index].Match}`)
119
- pgnData = pgnList[0]
120
- value = pgnData.Fields[index].Match
121
- fields = pgnData.Fields
122
- RepeatingFields = pgnData.RepeatingFieldSet1Size
123
- ? pgnData.RepeatingFieldSet1Size
124
- : 0
125
- }
126
- }
127
- writeField(bs, pgn_number, field, data, value, fields)
128
- }
129
-
130
- if (data.list) {
131
- data.list.forEach((repeat: any) => {
132
- for (let index = 0; index < RepeatingFields; index++) {
133
- const field = fields[pgnData.Fields.length - RepeatingFields + index]
134
- const value =
135
- repeat[field.Name] !== undefined
136
- ? repeat[field.Name]
137
- : repeat[field.Id]
138
-
139
- writeField(bs, pgn_number, field, data, value, fields)
140
- }
141
- })
142
- }
143
-
144
- const bitsLeft = bs.byteIndex * 8 - bs.index
145
- if (bitsLeft > 0) {
146
- //finish off the last byte
147
- bs.writeBits(0xffff, bitsLeft)
148
- //console.log(`bits left ${bitsLeft}`)
149
- }
150
-
151
- if (
152
- pgnData.Length !== undefined &&
153
- pgnData.Length !== 0xff &&
154
- fields[fields.length - 1].FieldType !== RES_STRINGLAU &&
155
- fields[fields.length - 1].FieldType !== RES_STRINGLZ &&
156
- !RepeatingFields
157
- ) {
158
- //const len = lengthsOff[pgnData.PGN] || pgnData.Length
159
- //console.log(`Length ${len}`)
160
-
161
- //if ( bs.byteIndex < pgnData.Length ) {
162
- //console.log(`bytes left ${pgnData.Length-bs.byteIndex}`)
163
- //}
164
-
165
- for (let i = bs.byteIndex; i < pgnData.Length; i++) {
166
- bs.writeUint8(0xff)
167
- }
168
- }
169
-
170
- return bs.view.buffer.slice(0, bs.byteIndex)
171
- }
172
-
173
- /*
174
- function dumpWritten(bs, field, startPos, value) {
175
- //console.log(`${startPos} ${bs.byteIndex}`)
176
- if ( startPos == bs.byteIndex )
177
- startPos--
178
- let string = `${field.Name} (${field.BitLength}): [`
179
- for ( let i = startPos; i < bs.byteIndex; i++ ) {
180
- string = string + bs.view.buffer[i].toString(16) + ', '
181
- }
182
- console.log(string + `] ${value}`)
183
- }
184
- */
185
-
186
- function writeField(
187
- bs: BitStream,
188
- pgn_number: number,
189
- field: Field,
190
- data: any,
191
- value: any,
192
- fields: Field[],
193
- bitLength: number | undefined = undefined
194
- ) {
195
- //const startPos = bs.byteIndex
196
-
197
- if (bitLength === undefined) {
198
- if (field.BitLengthVariable && field.FieldType === 'DYNAMIC_FIELD_VALUE') {
199
- bitLength = lookupKeyBitLength(data, fields)
200
- } else {
201
- bitLength = field.BitLength
202
- }
203
- }
204
-
205
- // console.log(`${field.Name}:${value}(${bitLength}-${field.Resolution})`)
206
- if (value === undefined || value === null) {
207
- if (field.FieldType && fieldTypeWriters[field.FieldType]) {
208
- fieldTypeWriters[field.FieldType](pgn_number, field, value, bs)
209
- } else if (bitLength !== undefined && bitLength % 8 == 0) {
210
- const bytes = bitLength / 8
211
- //const byte = field.Name.startsWith('Reserved') ? 0x00 : 0xff
212
- for (let i = 0; i < bytes - 1; i++) {
213
- bs.writeUint8(0xff)
214
- }
215
- bs.writeUint8(field.Signed ? 0x7f : 0xff)
216
- } else if (bitLength !== undefined) {
217
- bs.writeBits(0xffffffff, bitLength)
218
- } else {
219
- //FIXME: error! should not happen
220
- }
221
- } else {
222
- const type = field.FieldType
223
- if (type && fieldTypeMappers[type]) {
224
- value = fieldTypeMappers[type](field, value)
225
- } else if (
226
- (field.FieldType === 'LOOKUP' ||
227
- field.FieldType === 'DYNAMIC_FIELD_KEY') &&
228
- _.isString(value)
229
- ) {
230
- value = lookup(field, value)
231
- }
232
-
233
- if (field.FieldType == 'NUMBER' && _.isString(value)) {
234
- value = Number(value)
235
- }
236
-
237
- if (field.Resolution && typeof value === 'number') {
238
- value = Number((value / field.Resolution).toFixed(0))
239
- }
240
-
241
- if (field.FieldType && fieldTypeWriters[field.FieldType]) {
242
- fieldTypeWriters[field.FieldType](pgn_number, field, value, bs)
243
- } else {
244
- /*
245
- if ( _.isString(value) && typeof bitLength !== 'undefined' && bitLength !== 0 ) {
246
- value = Number(value)
247
- }
248
- */
249
-
250
- if (field.Unit === 'kWh') {
251
- value /= 3.6e6 // 1 kWh = 3.6 MJ.
252
- } else if (field.Unit === 'Ah') {
253
- value /= 3600.0 // 1 Ah = 3600 C.
254
- }
255
- if (field.Offset) {
256
- value -= field.Offset
257
- }
258
-
259
- if (field.FieldType === 'VARIABLE') {
260
- writeVariableLengthField(bs, pgn_number, data, field, value, fields)
261
- } else if (_.isBuffer(value)) {
262
- value.copy(bs.view.buffer, bs.byteIndex)
263
- bs.byteIndex += value.length
264
- } else if (bitLength !== undefined) {
265
- if (bitLength === 8) {
266
- if (field.Signed) {
267
- bs.writeInt8(value)
268
- } else {
269
- bs.writeUint8(value)
270
- }
271
- } else if (bitLength === 16) {
272
- if (field.Signed) {
273
- bs.writeInt16(value)
274
- } else {
275
- bs.writeUint16(value)
276
- }
277
- } else if (bitLength === 32) {
278
- if (field.Signed) {
279
- bs.writeInt32(value)
280
- } else {
281
- bs.writeUint32(value)
282
- }
283
- } else if (bitLength === 48 || bitLength == 24) {
284
- let count = bitLength / 8
285
- let val = value
286
- if (value < 0) {
287
- val++
288
- }
289
- while (count-- > 0) {
290
- if (value > 0) {
291
- bs.writeUint8(val & 255)
292
- val /= 256
293
- } else {
294
- bs.writeUint8((-val & 255) ^ 255)
295
- val /= 256
296
- }
297
- }
298
- } else if (bitLength === 64) {
299
- let num
300
- if (field.Signed) {
301
- num = new Int64LE(value)
302
- } else {
303
- num = new Uint64LE(value)
304
- }
305
- const buf = num.toBuffer()
306
- buf.copy(bs.view.buffer, bs.byteIndex)
307
- bs.byteIndex += buf.length
308
- } else {
309
- bs.writeBits(value, bitLength)
310
- }
311
- }
312
- }
313
- }
314
- //dumpWritten(bs, field, startPos, value)
315
- }
316
-
317
- function writeVariableLengthField(
318
- bs: BitStream,
319
- pgn_number: number,
320
- pgn: any,
321
- field: Field,
322
- value: any,
323
- fields: Field[]
324
- ) {
325
- const refField = getField(
326
- pgn.pgn | pgn.PGN,
327
- bs.view.buffer[bs.byteIndex - 1] - 1,
328
- pgn
329
- )
330
-
331
- if (refField) {
332
- let bits
333
-
334
- if (refField.BitLength !== undefined) {
335
- bits = (refField.BitLength + 7) & ~7 // Round # of bits in field refField up to complete bytes: 1->8, 7->8, 8->8 etc.
336
- }
337
-
338
- return writeField(bs, pgn_number, refField, pgn, value, fields, bits)
339
- }
340
- }
341
-
342
- function lookup(field: Field, stringValue: string) {
343
- let res
344
- if (field.LookupEnumeration) {
345
- res = lookupEnumerationValue(field.LookupEnumeration, stringValue)
346
- } else {
347
- res = lookupFieldTypeEnumerationValue(
348
- field.LookupFieldTypeEnumeration,
349
- stringValue
350
- )
351
- }
352
- return _.isUndefined(res) ? stringValue : res
353
- }
354
-
355
- function lookupKeyBitLength(data: any, fields: Field[]) {
356
- const field = fields.find((field) => field.Name === 'Key')
357
-
358
- if (field) {
359
- let val = data['Key'] || data['key']
360
- if (typeof val === 'string') {
361
- val = lookupFieldTypeEnumerationValue(
362
- field.LookupFieldTypeEnumeration,
363
- val
364
- )
365
- }
366
- return lookupFieldTypeEnumerationBits(field.LookupFieldTypeEnumeration, val)
367
- }
368
- }
369
-
370
- /*
371
-
372
- function parseHex(s:string): number {
373
- return parseInt(s, 16)
374
- };
375
-
376
- function canboat2Buffer(canboatData:string) {
377
- return Buffer.alloc(canboatData
378
- .split(',')
379
- .slice(6)
380
- .map(parseHex), 'hex')
381
- }
382
- */
383
-
384
- export function pgnToActisenseSerialFormat(pgn: PGN) {
385
- return encodeActisense({
386
- pgn: pgn.pgn,
387
- data: toPgn(pgn),
388
- dst: pgn.dst,
389
- src: pgn.src,
390
- prio: pgn.prio,
391
- timestamp: undefined
392
- })
393
- }
394
-
395
- export function pgnToActisenseN2KAsciiFormat(pgn: PGN) {
396
- return encodeActisenseN2KACSII({
397
- pgn: pgn.pgn,
398
- data: toPgn(pgn),
399
- dst: pgn.dst,
400
- src: pgn.src,
401
- prio: pgn.prio,
402
- timestamp: undefined
403
- })
404
- }
405
-
406
- export function pgnToN2KActisenseFormat(pgn: PGN) {
407
- const data = toPgn(pgn)
408
- if (data) {
409
- return encodeN2KActisense(pgn, data)
410
- }
411
- }
412
-
413
- export function toiKonvertSerialFormat(pgn: number, data: Buffer, dst = 255) {
414
- return `!PDGY,${pgn},${dst},${data.toString('base64')}`
415
- }
416
-
417
- export function pgnToiKonvertSerialFormat(pgn: any) {
418
- const data = toPgn(pgn)
419
- if (data) {
420
- return toiKonvertSerialFormat(pgn.pgn, data, pgn.dst)
421
- }
422
- }
423
-
424
- export function pgnToYdgwRawFormat(info: any) {
425
- return encodeYDRAW({ ...info, data: toPgn(info) })
426
- }
427
-
428
- export function pgnToYdgwFullRawFormat(info: any) {
429
- return encodeYDRAWFull({ ...info, data: toPgn(info) })
430
- }
431
-
432
- export function pgnToPCDIN(info: any) {
433
- return encodePCDIN({ ...info, data: toPgn(info) })
434
- }
435
-
436
- export function pgnToMXPGN(info: any) {
437
- return encodeMXPGN({ ...info, data: toPgn(info) })
438
- }
439
-
440
- export const actisenseToYdgwRawFormat = _.flow(parseActisense, encodeYDRAW)
441
- export const actisenseToYdgwFullRawFormat = _.flow(
442
- parseActisense,
443
- encodeYDRAWFull
444
- )
445
- export const actisenseToPCDIN = _.flow(parseActisense, encodePCDIN)
446
- export const actisenseToMXPGN = _.flow(parseActisense, encodeMXPGN)
447
- export const actisenseToiKonvert = _.flow(parseActisense, encodePDGY)
448
- export const actisenseToN2KAsciiFormat = _.flow(
449
- parseActisense,
450
- encodeActisenseN2KACSII
451
- )
452
- export const actisenseToN2KActisenseFormat = _.flow(
453
- parseActisense,
454
- encodeN2KActisense
455
- )
456
-
457
- function bitIsSet(field: Field, index: number, value: string) {
458
- const enumName = lookupBitEnumerationName(
459
- field.LookupBitEnumeration as string,
460
- index
461
- )
462
-
463
- return enumName ? value.indexOf(enumName) != -1 : false
464
- }
465
-
466
- fieldTypeWriters['BITLOOKUP'] = (pgn, field, value, bs) => {
467
- if (field.BitLength !== undefined) {
468
- if (value === undefined || value.length === 0) {
469
- if (field.BitLength % 8 == 0) {
470
- const bytes = field.BitLength / 8
471
- //const lastByte = field.Signed ? 0x7f : 0xff
472
- for (let i = 0; i < bytes - 1; i++) {
473
- bs.writeUint8(0x0)
474
- }
475
- bs.writeUint8(0x0)
476
- } else {
477
- bs.writeBits(0xffffffff, field.BitLength)
478
- }
479
- } else {
480
- for (let i = 0; i < field.BitLength; i++) {
481
- bs.writeBits(bitIsSet(field, i, value) ? 1 : 0, 1)
482
- }
483
- }
484
- }
485
- }
486
-
487
- fieldTypeWriters['STRING_FIX'] = (pgn, field, value, bs) => {
488
- if (field.BitLength !== undefined) {
489
- let fill = 0xff
490
- if (
491
- (pgn === 129810 &&
492
- (field.Name === 'Vendor ID' || field.Name === 'Callsign')) ||
493
- (pgn === 129809 && field.Name === 'Name')
494
- ) {
495
- if (_.isUndefined(value) || value.length == 0) {
496
- {
497
- fill = 0x40
498
- value = ''
499
- }
500
- }
501
- }
502
-
503
- if (value === undefined) {
504
- value = ''
505
- }
506
- const fieldLen = field.BitLength / 8
507
-
508
- for (let i = 0; i < value.length; i++) {
509
- bs.writeUint8(value.charCodeAt(i))
510
- }
511
-
512
- for (let i = 0; i < fieldLen - value.length; i++) {
513
- bs.writeUint8(fill)
514
- }
515
- }
516
- }
517
-
518
- fieldTypeWriters[RES_STRINGLZ] = (pgn, field, value, bs) => {
519
- if (_.isUndefined(value)) {
520
- value = ''
521
- }
522
- bs.writeUint8(value.length)
523
- for (let i = 0; i < value.length; i++) {
524
- bs.writeUint8(value.charCodeAt(i))
525
- }
526
- bs.writeUint8(0)
527
- }
528
-
529
- fieldTypeWriters['String with start/stop byte'] = (pgn, field, value, bs) => {
530
- if (_.isUndefined(value)) {
531
- value = ''
532
- }
533
- bs.writeUint8(0x02)
534
- for (let i = 0; i < value.length; i++) {
535
- bs.writeUint8(value.charCodeAt(i))
536
- }
537
- bs.writeUint8(0x01)
538
- }
539
-
540
- fieldTypeWriters[RES_STRINGLAU] = (pgn, field, value, bs) => {
541
- if (pgn === 129041 && field.Name === 'AtoN Name') {
542
- if (value.length > 18) {
543
- value = value.substring(0, 18)
544
- } else {
545
- value = value.padEnd(18, ' ')
546
- }
547
- }
548
-
549
- bs.writeUint8(value ? value.length + 2 : 2)
550
- bs.writeUint8(1)
551
-
552
- if (value) {
553
- for (let idx = 0; idx < value.length; idx++) {
554
- bs.writeUint8(value.charCodeAt(idx))
555
- }
556
- }
557
- }
558
-
559
- fieldTypeMappers['DATE'] = (field, value) => {
560
- //console.log(`Date: ${value}`)
561
- if (_.isString(value)) {
562
- const date = new Date(value)
563
- return date.getTime() / 86400 / 1000
564
- }
565
-
566
- return value
567
- }
568
-
569
- fieldTypeMappers['TIME'] = (field, value) => {
570
- if (_.isString(value)) {
571
- const split = value.split(':')
572
-
573
- const hours = Number(split[0])
574
- const minutes = Number(split[1])
575
- const seconds = Number(split[2])
576
-
577
- value = hours * 60 * 60 + minutes * 60 + seconds
578
- }
579
- return value
580
- }
581
-
582
- fieldTypeMappers['DURATION'] = fieldTypeMappers['TIME']
583
-
584
- fieldTypeMappers['Pressure'] = (field, value) => {
585
- if (field.Unit) {
586
- switch (field.Unit[0]) {
587
- case 'h':
588
- case 'H':
589
- value /= 100
590
- break
591
- case 'k':
592
- case 'K':
593
- value /= 1000
594
- break
595
- case 'd':
596
- value *= 10
597
- break
598
- }
599
- }
600
- return value
601
- }
@@ -1,8 +0,0 @@
1
- const { byteString } = require('./utilities')
2
-
3
- describe('byteString', () => {
4
- test('Buffer to string', () => {
5
- const data = Buffer.from('00ff7f520021feff', 'hex')
6
- expect(byteString(data)).toEqual('00,ff,7f,52,00,21,fe,ff')
7
- })
8
- })