@canboat/canboatjs 3.0.2 → 3.2.2

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 (222) hide show
  1. package/.github/workflows/publish.yml +18 -9
  2. package/.github/workflows/test.yml +2 -2
  3. package/.github/workflows/test_canboat_changes.yml +91 -0
  4. package/.husky/pre-commit +4 -0
  5. package/.mocharc.js +7 -0
  6. package/.prettierrc.json +5 -0
  7. package/README.md +5 -14
  8. package/dist/actisense-serial.d.ts +17 -0
  9. package/dist/actisense-serial.d.ts.map +1 -0
  10. package/dist/actisense-serial.js +569 -0
  11. package/dist/actisense-serial.js.map +1 -0
  12. package/dist/bin/actisense-file.d.ts +3 -0
  13. package/dist/bin/actisense-file.d.ts.map +1 -0
  14. package/dist/bin/actisense-file.js +49 -0
  15. package/dist/bin/actisense-file.js.map +1 -0
  16. package/dist/bin/actisense-n2k-tcp.d.ts +3 -0
  17. package/dist/bin/actisense-n2k-tcp.d.ts.map +1 -0
  18. package/dist/bin/actisense-n2k-tcp.js +46 -0
  19. package/dist/bin/actisense-n2k-tcp.js.map +1 -0
  20. package/dist/bin/actisense-serialjs.d.ts +3 -0
  21. package/dist/bin/actisense-serialjs.d.ts.map +1 -0
  22. package/dist/bin/actisense-serialjs.js +51 -0
  23. package/dist/bin/actisense-serialjs.js.map +1 -0
  24. package/dist/bin/analyzerjs.d.ts +3 -0
  25. package/dist/bin/analyzerjs.d.ts.map +1 -0
  26. package/dist/bin/analyzerjs.js +61 -0
  27. package/dist/bin/analyzerjs.js.map +1 -0
  28. package/dist/bin/candumpjs.d.ts +3 -0
  29. package/dist/bin/candumpjs.d.ts.map +1 -0
  30. package/dist/bin/candumpjs.js +73 -0
  31. package/dist/bin/candumpjs.js.map +1 -0
  32. package/dist/bin/cansend.d.ts +3 -0
  33. package/dist/bin/cansend.d.ts.map +1 -0
  34. package/dist/bin/cansend.js +123 -0
  35. package/dist/bin/cansend.js.map +1 -0
  36. package/dist/bin/ikonvert-serial.d.ts +3 -0
  37. package/dist/bin/ikonvert-serial.d.ts.map +1 -0
  38. package/dist/bin/ikonvert-serial.js +36 -0
  39. package/dist/bin/ikonvert-serial.js.map +1 -0
  40. package/dist/bin/to-pgn.d.ts +3 -0
  41. package/dist/bin/to-pgn.d.ts.map +1 -0
  42. package/dist/bin/to-pgn.js +57 -0
  43. package/dist/bin/to-pgn.js.map +1 -0
  44. package/dist/canId.d.ts +21 -0
  45. package/dist/canId.d.ts.map +1 -0
  46. package/dist/canId.js +66 -0
  47. package/dist/canId.js.map +1 -0
  48. package/dist/canId.test.d.ts +2 -0
  49. package/dist/canId.test.d.ts.map +1 -0
  50. package/dist/canId.test.js +58 -0
  51. package/dist/canId.test.js.map +1 -0
  52. package/dist/canbus.d.ts +17 -0
  53. package/dist/canbus.d.ts.map +1 -0
  54. package/dist/canbus.js +261 -0
  55. package/dist/canbus.js.map +1 -0
  56. package/dist/candevice.d.ts +23 -0
  57. package/dist/candevice.d.ts.map +1 -0
  58. package/dist/candevice.js +36 -0
  59. package/dist/candevice.js.map +1 -0
  60. package/dist/codes.d.ts +2 -0
  61. package/dist/codes.d.ts.map +1 -0
  62. package/dist/codes.js +24 -0
  63. package/dist/codes.js.map +1 -0
  64. package/dist/discovery.d.ts +17 -0
  65. package/dist/discovery.d.ts.map +1 -0
  66. package/dist/discovery.js +119 -0
  67. package/dist/discovery.js.map +1 -0
  68. package/dist/fromPgn.d.ts +51 -0
  69. package/dist/fromPgn.d.ts.map +1 -0
  70. package/dist/fromPgn.js +989 -0
  71. package/dist/fromPgn.js.map +1 -0
  72. package/dist/fromPgnStream.d.ts +17 -0
  73. package/dist/fromPgnStream.d.ts.map +1 -0
  74. package/dist/fromPgnStream.js +47 -0
  75. package/dist/fromPgnStream.js.map +1 -0
  76. package/dist/ikonvert.d.ts +17 -0
  77. package/dist/ikonvert.d.ts.map +1 -0
  78. package/dist/ikonvert.js +224 -0
  79. package/dist/ikonvert.js.map +1 -0
  80. package/dist/index.d.ts +31 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +60 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/n2k-actisense.d.ts +24 -0
  85. package/dist/n2k-actisense.d.ts.map +1 -0
  86. package/dist/n2k-actisense.js +126 -0
  87. package/dist/n2k-actisense.js.map +1 -0
  88. package/dist/n2k-actisense.test.d.ts +2 -0
  89. package/dist/n2k-actisense.test.d.ts.map +1 -0
  90. package/dist/n2k-actisense.test.js +49 -0
  91. package/dist/n2k-actisense.test.js.map +1 -0
  92. package/dist/n2kDevice.d.ts +44 -0
  93. package/dist/n2kDevice.d.ts.map +1 -0
  94. package/dist/n2kDevice.js +436 -0
  95. package/dist/n2kDevice.js.map +1 -0
  96. package/dist/pgns.d.ts +22 -0
  97. package/dist/pgns.d.ts.map +1 -0
  98. package/dist/pgns.js +157 -0
  99. package/dist/pgns.js.map +1 -0
  100. package/dist/pgns.test.d.ts +2 -0
  101. package/dist/pgns.test.d.ts.map +1 -0
  102. package/dist/pgns.test.js +14 -0
  103. package/dist/pgns.test.js.map +1 -0
  104. package/dist/simpleCan.d.ts +17 -0
  105. package/dist/simpleCan.d.ts.map +1 -0
  106. package/dist/simpleCan.js +125 -0
  107. package/dist/simpleCan.js.map +1 -0
  108. package/dist/stringMsg.d.ts +33 -0
  109. package/dist/stringMsg.d.ts.map +1 -0
  110. package/dist/stringMsg.js +359 -0
  111. package/dist/stringMsg.js.map +1 -0
  112. package/dist/stringMsg.test.d.ts +2 -0
  113. package/dist/stringMsg.test.d.ts.map +1 -0
  114. package/dist/stringMsg.test.js +244 -0
  115. package/dist/stringMsg.test.js.map +1 -0
  116. package/dist/toPgn.d.ts +34 -0
  117. package/dist/toPgn.d.ts.map +1 -0
  118. package/dist/toPgn.js +500 -0
  119. package/dist/toPgn.js.map +1 -0
  120. package/dist/utilities.d.ts +28 -0
  121. package/dist/utilities.d.ts.map +1 -0
  122. package/dist/utilities.js +159 -0
  123. package/dist/utilities.js.map +1 -0
  124. package/dist/utilities.test.d.ts +2 -0
  125. package/dist/utilities.test.d.ts.map +1 -0
  126. package/dist/utilities.test.js +9 -0
  127. package/dist/utilities.test.js.map +1 -0
  128. package/dist/venus-mqtt.d.ts +11 -0
  129. package/dist/venus-mqtt.d.ts.map +1 -0
  130. package/dist/venus-mqtt.js +100 -0
  131. package/dist/venus-mqtt.js.map +1 -0
  132. package/dist/venus.d.ts +11 -0
  133. package/dist/venus.d.ts.map +1 -0
  134. package/dist/venus.js +71 -0
  135. package/dist/venus.js.map +1 -0
  136. package/dist/w2k01.d.ts +17 -0
  137. package/dist/w2k01.d.ts.map +1 -0
  138. package/dist/w2k01.js +119 -0
  139. package/dist/w2k01.js.map +1 -0
  140. package/dist/yddevice.d.ts +25 -0
  141. package/dist/yddevice.d.ts.map +1 -0
  142. package/dist/yddevice.js +43 -0
  143. package/dist/yddevice.js.map +1 -0
  144. package/dist/ydgw02.d.ts +17 -0
  145. package/dist/ydgw02.d.ts.map +1 -0
  146. package/dist/ydgw02.js +163 -0
  147. package/dist/ydgw02.js.map +1 -0
  148. package/dist/ydvr.d.ts +17 -0
  149. package/dist/ydvr.d.ts.map +1 -0
  150. package/dist/ydvr.js +120 -0
  151. package/dist/ydvr.js.map +1 -0
  152. package/eslint.config.js +58 -0
  153. package/jest.config.js +5 -0
  154. package/lib/actisense-serial.ts +644 -0
  155. package/lib/bin/actisense-file.ts +53 -0
  156. package/lib/bin/actisense-n2k-tcp.ts +50 -0
  157. package/lib/bin/actisense-serialjs.ts +55 -0
  158. package/{bin/analyzerjs → lib/bin/analyzerjs.ts} +16 -15
  159. package/{bin/candumpjs → lib/bin/candumpjs.ts} +19 -20
  160. package/lib/bin/cansend.ts +131 -0
  161. package/lib/bin/ikonvert-serial.ts +44 -0
  162. package/{bin/to-pgn → lib/bin/to-pgn.ts} +23 -17
  163. package/lib/bin/ydvr-file +33 -0
  164. package/lib/canId.test.js +35 -15
  165. package/lib/canId.ts +84 -0
  166. package/lib/canbus.ts +293 -0
  167. package/lib/candevice.ts +41 -0
  168. package/lib/codes.ts +21 -0
  169. package/lib/{discovery.js → discovery.ts} +32 -30
  170. package/lib/fromPgn.ts +1207 -0
  171. package/lib/{fromPgnStream.js → fromPgnStream.ts} +17 -12
  172. package/lib/{ikonvert.js → ikonvert.ts} +99 -94
  173. package/lib/index.ts +48 -0
  174. package/lib/n2k-actisense.test.js +31 -32
  175. package/lib/n2k-actisense.ts +152 -0
  176. package/lib/n2kDevice.ts +516 -0
  177. package/lib/pgns.test.ts +12 -0
  178. package/lib/pgns.ts +191 -0
  179. package/lib/simpleCan.ts +140 -0
  180. package/lib/stringMsg.test.js +58 -41
  181. package/lib/stringMsg.ts +464 -0
  182. package/lib/toPgn.ts +597 -0
  183. package/lib/utilities.ts +169 -0
  184. package/lib/venus-mqtt.js +69 -73
  185. package/lib/venus.js +8 -8
  186. package/lib/w2k01.ts +142 -0
  187. package/lib/{yddevice.js → yddevice.ts} +18 -16
  188. package/lib/{ydgw02.js → ydgw02.ts} +58 -51
  189. package/lib/ydvr.js +65 -147
  190. package/package.json +54 -18
  191. package/tsconfig.json +19 -0
  192. package/tsconfig.tsbuildinfo +1 -0
  193. package/CHANGELOG.md +0 -101
  194. package/bin/actisense-file +0 -47
  195. package/bin/actisense-n2k-tcp +0 -45
  196. package/bin/actisense-serialjs +0 -52
  197. package/bin/candumpanalyzerjs +0 -29
  198. package/bin/cansend +0 -130
  199. package/bin/ikonvert-serial +0 -50
  200. package/bin/ydgw-analyzerjs +0 -36
  201. package/bin/ydvr-file +0 -33
  202. package/index.js +0 -53
  203. package/ios_canboat.js/main.js +0 -2
  204. package/ios_canboat.js/main.js.LICENSE.txt +0 -17
  205. package/ios_canboat.js/main.js.map +0 -1
  206. package/lib/canId.js +0 -64
  207. package/lib/canbus.js +0 -278
  208. package/lib/candevice.js +0 -51
  209. package/lib/codes.js +0 -69
  210. package/lib/codes.test.js +0 -17
  211. package/lib/codesMfgs.json +0 -166
  212. package/lib/fromPgn.js +0 -1027
  213. package/lib/n2k-actisense.js +0 -108
  214. package/lib/n2kDevice.js +0 -390
  215. package/lib/pgns.js +0 -196
  216. package/lib/pgns.test.js +0 -13
  217. package/lib/serial.js +0 -647
  218. package/lib/simpleCan.js +0 -105
  219. package/lib/stringMsg.js +0 -339
  220. package/lib/toPgn.js +0 -518
  221. package/lib/utilities.js +0 -111
  222. package/lib/w2k01.js +0 -129
@@ -14,26 +14,31 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const debug = require('debug')('canboatjs:ydgw02')
18
- const Transform = require('stream').Transform
19
- const FromPgn = require('./fromPgn').Parser
20
- const Parser = require('./fromPgn').Parser
21
- const YdDevice = require('./yddevice')
22
- const _ = require('lodash')
23
- const { defaultTransmitPGNs } = require('./codes')
24
- const { pgnToYdgwRawFormat, pgnToYdgwFullRawFormat, actisenseToYdgwRawFormat, actisenseToYdgwFullRawFormat } = require('./toPgn')
17
+ import { PGN } from '@canboat/ts-pgns'
18
+ import { createDebug } from './utilities'
19
+ import { Transform } from 'stream'
20
+ import { Parser as FromPgn } from './fromPgn'
21
+ import { YdDevice } from './yddevice'
22
+ import {
23
+ pgnToYdgwRawFormat,
24
+ pgnToYdgwFullRawFormat,
25
+ actisenseToYdgwRawFormat,
26
+ actisenseToYdgwFullRawFormat
27
+ } from './toPgn'
28
+ import util from 'util'
25
29
 
26
30
  //const pgnsSent = {}
27
31
 
28
- function Ydgw02Stream (options, type) {
29
- if (!(this instanceof Ydgw02Stream)) {
30
- return new Ydgw02Stream(options)
32
+ export function Ydgw02Stream(this: any, options: any, type: string) {
33
+ if (this === undefined) {
34
+ return new (Ydgw02Stream as any)(options, type)
31
35
  }
32
36
 
33
37
  Transform.call(this, {
34
38
  objectMode: true
35
39
  })
36
40
 
41
+ this.debug = createDebug('canboatjs:ydgw02', options)
37
42
  this.sentAvailable = false
38
43
  this.options = options
39
44
  this.outEvent = options.ydgwOutEvent || 'ydwg02-out'
@@ -41,18 +46,17 @@ function Ydgw02Stream (options, type) {
41
46
 
42
47
  this.fromPgn = new FromPgn(options)
43
48
 
44
- this.fromPgn.on('warning', (pgn, warning) => {
49
+ this.fromPgn.on('warning', (_pgn: any, _warning: string) => {
45
50
  //debug(`[warning] ${pgn.pgn} ${warning}`)
46
51
  })
47
52
 
48
- this.fromPgn.on('error', (pgn, error) => {
49
- debug(`[error] ${pgn.pgn} ${error}`)
53
+ this.fromPgn.on('error', (pgn: PGN, error: any) => {
54
+ this.debug(`[error] ${pgn.pgn} ${error}`)
50
55
  })
51
56
 
52
-
53
- if ( options.app ) {
54
- options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
55
- if ( typeof msg === 'string' ) {
57
+ if (options.app) {
58
+ options.app.on(this.options.outEevent || 'nmea2000out', (msg: string) => {
59
+ if (typeof msg === 'string') {
56
60
  this.sendYdgwPGN(msg)
57
61
  } else {
58
62
  this.sendPGN(msg)
@@ -60,78 +64,77 @@ function Ydgw02Stream (options, type) {
60
64
  options.app.emit('connectionwrite', { providerId: options.providerId })
61
65
  })
62
66
 
63
- options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
67
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
64
68
  this.sendPGN(msg)
65
69
  options.app.emit('connectionwrite', { providerId: options.providerId })
66
70
  })
67
71
 
68
- options.app.on('ydFullRawOut', (msgs) => {
72
+ options.app.on('ydFullRawOut', (msgs: string[]) => {
69
73
  this.sendYdgwFullPGN(msgs)
70
74
  options.app.emit('connectionwrite', { providerId: options.providerId })
71
75
  })
72
76
 
73
77
  //this.sendString('$PDGY,N2NET_OFFLINE')
74
78
 
75
- if ( type === 'usb' ) {
79
+ if (type === 'usb') {
76
80
  // set ydnu to RAW mode
77
81
  options.app.emit(this.outEvent, Buffer.from([0x30, 0x0a]))
78
82
  }
79
83
 
80
- if ( options.createDevice === true ) {
84
+ if (options.createDevice === true) {
81
85
  this.device = new YdDevice(options)
82
86
  this.device.start()
83
87
  }
84
-
85
- debug('started')
86
- }
87
88
 
89
+ this.debug('started')
90
+ }
88
91
  }
89
92
 
90
- Ydgw02Stream.prototype.cansend = function (msg) {
93
+ Ydgw02Stream.prototype.cansend = function (_msg: any) {
91
94
  return this.device ? this.device.cansend : true
92
95
  }
93
96
 
94
- Ydgw02Stream.prototype.sendString = function (msg, forceSend) {
95
- if ( this.cansend() || forceSend === true ) {
96
- debug('sending %s', msg)
97
+ Ydgw02Stream.prototype.sendString = function (msg: string, forceSend: boolean) {
98
+ if (this.cansend() || forceSend === true) {
99
+ this.debug('sending %s', msg)
97
100
  this.options.app.emit(this.outEvent, msg)
98
101
  }
99
102
  }
100
103
 
101
- Ydgw02Stream.prototype.sendPGN = function (pgn) {
102
- if ( this.cansend() || pgn.forceSend === true ) {
104
+ Ydgw02Stream.prototype.sendPGN = function (pgn: PGN) {
105
+ if (this.cansend() || (pgn as any).forceSend === true) {
103
106
  //let now = Date.now()
104
107
  //let lastSent = pgnsSent[pgn.pgn]
105
108
  let msgs
106
- if ( pgn.ydFullFormat === true || this.device !== undefined ) {
109
+ if ((pgn as any).ydFullFormat === true || this.device !== undefined) {
110
+ pgn.src = this.device.address
107
111
  msgs = pgnToYdgwFullRawFormat(pgn)
108
112
  } else {
109
113
  msgs = pgnToYdgwRawFormat(pgn)
110
114
  }
111
- msgs.forEach(raw => {
112
- this.sendString(raw + '\r\n', pgn.forceSend)
115
+ msgs.forEach((raw) => {
116
+ this.sendString(raw + '\r\n', (pgn as any).forceSend)
113
117
  })
114
118
  //pgnsSent[pgn.pgn] = now
115
119
  }
116
120
  }
117
121
 
118
- Ydgw02Stream.prototype.sendYdgwFullPGN = function (msgs) {
119
- msgs.forEach(raw => {
122
+ Ydgw02Stream.prototype.sendYdgwFullPGN = function (msgs: string[]) {
123
+ msgs.forEach((raw) => {
120
124
  this.sendString(raw + '\r\n')
121
125
  })
122
126
  }
123
127
 
124
- Ydgw02Stream.prototype.sendYdgwPGN = function (msg) {
125
-
128
+ Ydgw02Stream.prototype.sendYdgwPGN = function (msg: string) {
126
129
  let msgs
127
130
 
128
- if ( this.device != undefined ) {
131
+ if (this.device != undefined) {
129
132
  msgs = actisenseToYdgwFullRawFormat(msg)
130
133
  } else {
131
134
  msgs = actisenseToYdgwRawFormat(msg)
132
135
  }
133
136
 
134
- msgs.forEach(raw => {
137
+ msgs.forEach((raw) => {
135
138
  this.sendString(raw + '\r\n')
136
139
  })
137
140
 
@@ -161,28 +164,32 @@ Ydgw02Stream.prototype.sendYdgwPGN = function (msg) {
161
164
  */
162
165
  }
163
166
 
164
- require('util').inherits(Ydgw02Stream, Transform)
167
+ util.inherits(Ydgw02Stream, Transform)
165
168
 
166
- Ydgw02Stream.prototype._transform = function (chunk, encoding, done) {
167
- let line = chunk.toString().trim()
169
+ Ydgw02Stream.prototype._transform = function (
170
+ chunk: any,
171
+ encoding: any,
172
+ done: any
173
+ ) {
174
+ const line = chunk.toString().trim()
168
175
  //line = line.substring(0, line.length) // take off the \r
169
176
 
170
- if ( this.device === undefined && !this.sentAvailable ) {
171
- debug('emit nmea2000OutAvailable')
177
+ if (this.device === undefined && !this.sentAvailable) {
178
+ this.debug('emit nmea2000OutAvailable')
172
179
  this.options.app.emit('nmea2000OutAvailable')
173
180
  this.sentAvailable = true
174
181
  }
175
182
 
176
183
  const pgn = this.fromPgn.parseYDGW02(line)
177
- if ( !_.isUndefined(pgn) ) {
184
+ if (pgn !== undefined) {
178
185
  this.push(pgn)
179
- this.options.app.emit(this.options.analyzerOutEvent || 'N2KAnalyzerOut', pgn)
186
+ this.options.app.emit(
187
+ this.options.analyzerOutEvent || 'N2KAnalyzerOut',
188
+ pgn
189
+ )
180
190
  }
181
191
 
182
192
  done()
183
193
  }
184
194
 
185
- Ydgw02Stream.prototype.end = function () {
186
- }
187
-
188
- module.exports = Ydgw02Stream
195
+ Ydgw02Stream.prototype.end = function () {}
package/lib/ydvr.js CHANGED
@@ -1,180 +1,98 @@
1
- const BitStream = require('bit-buffer').BitStream;
2
- const Transform = require('stream').Transform;
1
+ const BitStream = require('bit-buffer').BitStream
2
+ const Transform = require('stream').Transform
3
3
  const FromPgn = require('./fromPgn').Parser
4
- const parseCanId = require('./canId').parseCanId;
4
+ const parseCanId = require('./canId').parseCanId
5
5
 
6
6
  // https://www.yachtd.com/downloads/ydvr04.pdf Appendix D
7
7
  var sequencePgns = new Set([
8
- 65240,
9
- 126208,
10
- 126464,
11
- 126720,
12
- 126983,
13
- 126984,
14
- 126985,
15
- 126986,
16
- 126987,
17
- 126988,
18
- 126996,
19
- 126998,
20
- 127233,
21
- 127237,
22
- 127489,
23
- 127496,
24
- 127497,
25
- 127498,
26
- 127503,
27
- 127504,
28
- 127506,
29
- 127507,
30
- 127509,
31
- 127510,
32
- 127511,
33
- 127512,
34
- 127513,
35
- 127514,
36
- 128275,
37
- 128520,
38
- 129029,
39
- 129038,
40
- 129039,
41
- 129040,
42
- 129041,
43
- 129044,
44
- 129045,
45
- 129284,
46
- 129285,
47
- 129301,
48
- 129302,
49
- 129538,
50
- 129540,
51
- 129541,
52
- 129542,
53
- 129545,
54
- 129547,
55
- 129549,
56
- 129551,
57
- 129556,
58
- 129792,
59
- 129793,
60
- 129794,
61
- 129795,
62
- 129796,
63
- 129797,
64
- 129798,
65
- 129799,
66
- 129800,
67
- 129801,
68
- 129802,
69
- 129803,
70
- 129804,
71
- 129805,
72
- 129806,
73
- 129807,
74
- 129808,
75
- 129809,
76
- 129810,
77
- 130052,
78
- 130053,
79
- 130054,
80
- 130060,
81
- 130061,
82
- 130064,
83
- 130065,
84
- 130066,
85
- 130067,
86
- 130068,
87
- 130069,
88
- 130070,
89
- 130071,
90
- 130072,
91
- 130073,
92
- 130074,
93
- 130320,
94
- 130321,
95
- 130322,
96
- 130323,
97
- 130324,
98
- 130567,
99
- 130577,
100
- 130578,
101
- 130816,
102
- ]);
8
+ 65240, 126208, 126464, 126720, 126983, 126984, 126985, 126986, 126987, 126988,
9
+ 126996, 126998, 127233, 127237, 127489, 127496, 127497, 127498, 127503,
10
+ 127504, 127506, 127507, 127509, 127510, 127511, 127512, 127513, 127514,
11
+ 128275, 128520, 129029, 129038, 129039, 129040, 129041, 129044, 129045,
12
+ 129284, 129285, 129301, 129302, 129538, 129540, 129541, 129542, 129545,
13
+ 129547, 129549, 129551, 129556, 129792, 129793, 129794, 129795, 129796,
14
+ 129797, 129798, 129799, 129800, 129801, 129802, 129803, 129804, 129805,
15
+ 129806, 129807, 129808, 129809, 129810, 130052, 130053, 130054, 130060,
16
+ 130061, 130064, 130065, 130066, 130067, 130068, 130069, 130070, 130071,
17
+ 130072, 130073, 130074, 130320, 130321, 130322, 130323, 130324, 130567,
18
+ 130577, 130578, 130816
19
+ ])
103
20
 
104
21
  function YdvrStream() {
105
22
  if (!(this instanceof YdvrStream)) {
106
- return new YdvrStream();
23
+ return new YdvrStream()
107
24
  }
108
25
 
109
- this.parser = new FromPgn();
26
+ this.parser = new FromPgn()
110
27
 
111
- this.messageCount = 0;
112
- this.errorCount = 0;
113
- this.timerResetCount = 0;
28
+ this.messageCount = 0
29
+ this.errorCount = 0
30
+ this.timerResetCount = 0
114
31
 
115
32
  this.parser.on('error', (pgn, error) => {
116
- console.error(`Error parsing ${pgn.pgn} ${error}`);
117
- console.error(error.stack);
118
- });
33
+ console.error(`Error parsing ${pgn.pgn} ${error}`)
34
+ console.error(error.stack)
35
+ })
119
36
 
120
- this.parser.on('warning', (pgn, error) => {
37
+ this.parser.on('warning', (_pgn, _error) => {
121
38
  //console.error(`Warning parsing ${pgn.pgn} ${error}`)
122
- });
39
+ })
123
40
 
124
41
  // this.parser.on('pgn', (pgn) => {
125
42
  // console.log(JSON.stringify(pgn));
126
43
  // });
127
44
 
128
45
  Transform.call(this, {
129
- objectMode: true,
130
- });
46
+ objectMode: true
47
+ })
131
48
  }
132
49
 
133
- require('util').inherits(YdvrStream, Transform);
50
+ require('util').inherits(YdvrStream, Transform)
134
51
 
135
52
  YdvrStream.prototype.end = function () {
136
53
  // console.log('end');
137
- };
54
+ }
138
55
 
139
56
  YdvrStream.prototype.parseNextRecord = function () {
140
57
  if (this.bs.bitsLeft < 6 * 8) {
141
- return false;
58
+ return false
142
59
  }
143
60
 
144
- var time = this.bs.readUint16();
145
- let timeAbsolute;
61
+ var time = this.bs.readUint16()
62
+ //let timeAbsolute;
146
63
  if (this.lastTime != null && time < this.lastTime) {
147
- this.timeOffset = (this.timeOffset || 0) + 60000;
148
- timeAbsolute = time + this.timeOffset;
149
- this.timerResetCount += 1;
150
- } else {
64
+ this.timeOffset = (this.timeOffset || 0) + 60000
65
+ //timeAbsolute = time + this.timeOffset;
66
+ this.timerResetCount += 1
67
+ } /*else {
151
68
  timeAbsolute = time;
152
- }
153
- this.lastTime = time;
69
+ }
70
+ */
71
+ this.lastTime = time
154
72
 
155
- var identifier = this.bs.readUint32();
73
+ var identifier = this.bs.readUint32()
156
74
  if (identifier === 0xffffffff) {
157
75
  // service record
158
76
  if (this.bs.bitsLeft < 8 * 8) {
159
- return false;
77
+ return false
160
78
  }
161
- var srData = this.bs.readArrayBuffer(8);
79
+ var _srData = this.bs.readArrayBuffer(8)
162
80
  } else {
163
- const pgn = parseCanId(identifier);
81
+ const pgn = parseCanId(identifier)
164
82
 
165
- var bodyLen;
83
+ var bodyLen
166
84
  if (pgn.pgn == 59904) {
167
- bodyLen = 3;
85
+ bodyLen = 3
168
86
  } else if (sequencePgns.has(pgn.pgn)) {
169
- var seq = this.bs.readUint8();
170
- bodyLen = this.bs.readUint8();
87
+ var _seq = this.bs.readUint8()
88
+ bodyLen = this.bs.readUint8()
171
89
  } else {
172
- bodyLen = 8;
90
+ bodyLen = 8
173
91
  }
174
92
  if (this.bs.bitsLeft < bodyLen * 8) {
175
- return false;
93
+ return false
176
94
  }
177
- var body = this.bs.readArrayBuffer(bodyLen);
95
+ var body = this.bs.readArrayBuffer(bodyLen)
178
96
 
179
97
  const parsed = this.parser.parsePgnData(
180
98
  { ...pgn, time: new Date(time).toISOString().slice(11, 23) },
@@ -182,38 +100,38 @@ YdvrStream.prototype.parseNextRecord = function () {
182
100
  Buffer.from(body),
183
101
  false,
184
102
  undefined
185
- );
103
+ )
186
104
  if (parsed) {
187
- this.push(parsed);
105
+ this.push(parsed)
188
106
  }
189
107
  }
190
108
 
191
- this.messageCount += 1;
192
- return true;
109
+ this.messageCount += 1
110
+ return true
193
111
  }
194
112
 
195
113
  YdvrStream.prototype._transform = function (chunk, encoding, done) {
196
114
  if (this.bs == null) {
197
- this.bs = new BitStream(chunk);
115
+ this.bs = new BitStream(chunk)
198
116
  } else {
199
- var remainingBuffer = this.bs.view.buffer.subarray(this.bs.byteIndex);
200
- this.bs = new BitStream(Buffer.concat([remainingBuffer, chunk]));
117
+ var remainingBuffer = this.bs.view.buffer.subarray(this.bs.byteIndex)
118
+ this.bs = new BitStream(Buffer.concat([remainingBuffer, chunk]))
201
119
  }
202
120
  while (true) {
203
121
  var startIndex = this.bs.byteIndex
204
- let parsed = false;
122
+ let parsed = false
205
123
  try {
206
- parsed = this.parseNextRecord();
124
+ parsed = this.parseNextRecord()
207
125
  } catch (ex) {
208
- console.error(ex);
209
- this.errorCount += 1;
126
+ console.error(ex)
127
+ this.errorCount += 1
210
128
  }
211
129
  if (!parsed) {
212
- this.bs.byteIndex = startIndex;
213
- break;
130
+ this.bs.byteIndex = startIndex
131
+ break
214
132
  }
215
133
  }
216
- done();
217
- };
134
+ done()
135
+ }
218
136
 
219
137
  module.exports = YdvrStream
package/package.json CHANGED
@@ -1,28 +1,45 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "3.0.2",
3
+ "version": "3.2.2",
4
4
  "description": "Native javascript version of canboat",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "./dist/index.d.ts",
6
7
  "scripts": {
7
8
  "dev-test": "jest --watch",
8
- "test": "jest && mocha --exit",
9
+ "test": "jest && mocha --require ts-node/register --exit 'test/*.[jt]s'",
9
10
  "code-coverage": "jest --coverage && nyc mocha --exit",
10
11
  "build_ios": "webpack -c ./webpack.config.js --mode development ./ios.js -o ios_canboat.js",
11
- "build_prod_ios": "webpack -c ./webpack.config.js --mode production ./ios.js -o ios_canboat.js"
12
+ "build_prod_ios": "webpack -c ./webpack.config.js --mode production ./ios.js -o ios_canboat.js",
13
+ "build": "tsc -b --pretty false",
14
+ "watch": "tsc --watch",
15
+ "prepublishOnly": "npm run build",
16
+ "prettier": "prettier --write lib test",
17
+ "lint": "eslint --fix",
18
+ "ci-lint": "eslint && prettier --check lib test",
19
+ "ci-test": "npm run build && npm run test && npm run ci-lint",
20
+ "format": "npm run prettier && npm run lint",
21
+ "prepare": "husky install"
12
22
  },
13
- "bin": {
14
- "analyzerjs": "./bin/analyzerjs",
15
- "to-pgn": "./bin/to-pgn",
16
- "candumpanalyzerjs": "./bin/candumpanalyzerjs",
17
- "actisense-serialjs": "./bin/actisense-serialjs",
18
- "actisense-file": "./bin/actisense-file",
19
- "actisense-n2k-tcp": "./bin/actisense-n2k-tcp",
20
- "candumpjs": "./bin/candumpjs",
21
- "ikonvert-serial": "./bin/ikonvert-serial",
22
- "cansend": "./bin/cansend"
23
+ "husky": {
24
+ "hooks": {
25
+ "pre-commit": "lint-staged"
26
+ }
23
27
  },
24
- "jest": {
25
- "rootDir": "lib"
28
+ "lint-staged": {
29
+ "lib/**/*.{js,ts}": [
30
+ "prettier --write",
31
+ "eslint --fix"
32
+ ]
33
+ },
34
+ "bin": {
35
+ "analyzerjs": "./dist/bin/analyzerjs.js",
36
+ "to-pgn": "./dist/bin/to-pgn.js",
37
+ "actisense-serialjs": "./dist/bin/actisense-serialjs.js",
38
+ "actisense-file": "./dist/bin/actisense-file.js",
39
+ "actisense-n2k-tcp": "./dist/bin/actisense-n2k-tcp.js",
40
+ "candumpjs": "./dist/bin/candumpjs.js",
41
+ "ikonvert-serial": "./dist/bin/ikonvert-serial.js",
42
+ "cansend": "./dist/bin/cansend.js"
26
43
  },
27
44
  "keywords": [
28
45
  "boat",
@@ -53,8 +70,11 @@
53
70
  }
54
71
  ],
55
72
  "license": "Apache-2.0",
73
+ "engines": {
74
+ "node": ">=20"
75
+ },
56
76
  "dependencies": {
57
- "@canboat/pgns": "6.0.x",
77
+ "@canboat/ts-pgns": "^1.0.0",
58
78
  "bit-buffer": "0.2.3",
59
79
  "debug": "^4.3.4",
60
80
  "dnssd": "^0.4.1",
@@ -67,15 +87,31 @@
67
87
  },
68
88
  "devDependencies": {
69
89
  "@signalk/server-api": "^1.39.0",
90
+ "@tsconfig/node20": "^20.1.6",
91
+ "@types/chai": "^5.2.2",
92
+ "@types/debug": "^4.1.12",
93
+ "@types/jest": "^30.0.0",
94
+ "@types/lodash": "^4.17.19",
95
+ "@types/minimist": "^1.2.5",
70
96
  "baconjs": "^1.0.1",
71
97
  "buffer": "^6.0.3",
72
98
  "chai": "^4.1.2",
73
99
  "chai-json-equal": "0.0.1",
74
100
  "chai-string": "^1.5.0",
75
101
  "chai-things": "^0.2.0",
76
- "jest": "^24.7.1",
102
+ "eslint": "^9.30.0",
103
+ "eslint-config-prettier": "^10.1.5",
104
+ "eslint-plugin-prettier": "^5.5.1",
105
+ "husky": "^8.0.0",
106
+ "jest": "^30.0.3",
107
+ "lint-staged": "^16.1.2",
77
108
  "mocha": "^5.0.0",
78
109
  "nyc": "^15.1.0",
110
+ "prettier": "^3.6.2",
111
+ "ts-jest": "^29.4.0",
112
+ "ts-node": "^10.9.2",
113
+ "typescript": "^5.8.3",
114
+ "typescript-eslint": "^8.35.0",
79
115
  "webpack-cli": "^5.1.4"
80
116
  },
81
117
  "optionalDependencies": {
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "@tsconfig/node20/tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "${configDir}/dist",
5
+ "rootDir": "${configDir}/lib",
6
+ "allowJs": true,
7
+ "typeRoots": ["./node_modules/@types"],
8
+ "resolveJsonModule": true,
9
+ "composite": true,
10
+ "declaration": true,
11
+ "declarationMap": true,
12
+ "sourceMap": true,
13
+ "isolatedModules": true
14
+ },
15
+ "ts-node": {
16
+ "files": true
17
+ },
18
+ "include": ["./lib/**/*"],
19
+ }