@canboat/canboatjs 3.0.2 → 3.1.0

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/test.yml +2 -2
  2. package/.github/workflows/test_canboat_changes.yml +91 -0
  3. package/.husky/pre-commit +4 -0
  4. package/.mocharc.js +7 -0
  5. package/.prettierrc.json +5 -0
  6. package/README.md +2 -7
  7. package/dist/actisense-serial.d.ts +17 -0
  8. package/dist/actisense-serial.d.ts.map +1 -0
  9. package/dist/actisense-serial.js +569 -0
  10. package/dist/actisense-serial.js.map +1 -0
  11. package/dist/bin/actisense-file.d.ts +3 -0
  12. package/dist/bin/actisense-file.d.ts.map +1 -0
  13. package/dist/bin/actisense-file.js +49 -0
  14. package/dist/bin/actisense-file.js.map +1 -0
  15. package/dist/bin/actisense-n2k-tcp.d.ts +3 -0
  16. package/dist/bin/actisense-n2k-tcp.d.ts.map +1 -0
  17. package/dist/bin/actisense-n2k-tcp.js +46 -0
  18. package/dist/bin/actisense-n2k-tcp.js.map +1 -0
  19. package/dist/bin/actisense-serialjs.d.ts +3 -0
  20. package/dist/bin/actisense-serialjs.d.ts.map +1 -0
  21. package/dist/bin/actisense-serialjs.js +51 -0
  22. package/dist/bin/actisense-serialjs.js.map +1 -0
  23. package/dist/bin/analyzerjs.d.ts +3 -0
  24. package/dist/bin/analyzerjs.d.ts.map +1 -0
  25. package/dist/bin/analyzerjs.js +61 -0
  26. package/dist/bin/analyzerjs.js.map +1 -0
  27. package/dist/bin/candumpanalyzerjs.d.ts +3 -0
  28. package/dist/bin/candumpanalyzerjs.d.ts.map +1 -0
  29. package/dist/bin/candumpanalyzerjs.js +31 -0
  30. package/dist/bin/candumpanalyzerjs.js.map +1 -0
  31. package/dist/bin/candumpjs.d.ts +3 -0
  32. package/dist/bin/candumpjs.d.ts.map +1 -0
  33. package/dist/bin/candumpjs.js +73 -0
  34. package/dist/bin/candumpjs.js.map +1 -0
  35. package/dist/bin/cansend.d.ts +3 -0
  36. package/dist/bin/cansend.d.ts.map +1 -0
  37. package/dist/bin/cansend.js +123 -0
  38. package/dist/bin/cansend.js.map +1 -0
  39. package/dist/bin/ikonvert-serial.d.ts +3 -0
  40. package/dist/bin/ikonvert-serial.d.ts.map +1 -0
  41. package/dist/bin/ikonvert-serial.js +36 -0
  42. package/dist/bin/ikonvert-serial.js.map +1 -0
  43. package/dist/bin/to-pgn.d.ts +3 -0
  44. package/dist/bin/to-pgn.d.ts.map +1 -0
  45. package/dist/bin/to-pgn.js +57 -0
  46. package/dist/bin/to-pgn.js.map +1 -0
  47. package/dist/canId.d.ts +21 -0
  48. package/dist/canId.d.ts.map +1 -0
  49. package/dist/canId.js +66 -0
  50. package/dist/canId.js.map +1 -0
  51. package/dist/canId.test.d.ts +2 -0
  52. package/dist/canId.test.d.ts.map +1 -0
  53. package/dist/canId.test.js +58 -0
  54. package/dist/canId.test.js.map +1 -0
  55. package/dist/canbus.d.ts +17 -0
  56. package/dist/canbus.d.ts.map +1 -0
  57. package/dist/canbus.js +261 -0
  58. package/dist/canbus.js.map +1 -0
  59. package/dist/candevice.d.ts +23 -0
  60. package/dist/candevice.d.ts.map +1 -0
  61. package/dist/candevice.js +38 -0
  62. package/dist/candevice.js.map +1 -0
  63. package/dist/codes.d.ts +2 -0
  64. package/dist/codes.d.ts.map +1 -0
  65. package/dist/codes.js +24 -0
  66. package/dist/codes.js.map +1 -0
  67. package/dist/discovery.d.ts +17 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +119 -0
  70. package/dist/discovery.js.map +1 -0
  71. package/dist/fromPgn.d.ts +51 -0
  72. package/dist/fromPgn.d.ts.map +1 -0
  73. package/dist/fromPgn.js +989 -0
  74. package/dist/fromPgn.js.map +1 -0
  75. package/dist/fromPgnStream.d.ts +17 -0
  76. package/dist/fromPgnStream.d.ts.map +1 -0
  77. package/dist/fromPgnStream.js +47 -0
  78. package/dist/fromPgnStream.js.map +1 -0
  79. package/dist/ikonvert.d.ts +17 -0
  80. package/dist/ikonvert.d.ts.map +1 -0
  81. package/dist/ikonvert.js +224 -0
  82. package/dist/ikonvert.js.map +1 -0
  83. package/dist/index.d.ts +31 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +60 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/n2k-actisense.d.ts +24 -0
  88. package/dist/n2k-actisense.d.ts.map +1 -0
  89. package/dist/n2k-actisense.js +126 -0
  90. package/dist/n2k-actisense.js.map +1 -0
  91. package/dist/n2k-actisense.test.d.ts +2 -0
  92. package/dist/n2k-actisense.test.d.ts.map +1 -0
  93. package/dist/n2k-actisense.test.js +49 -0
  94. package/dist/n2k-actisense.test.js.map +1 -0
  95. package/dist/n2kDevice.d.ts +40 -0
  96. package/dist/n2kDevice.d.ts.map +1 -0
  97. package/dist/n2kDevice.js +387 -0
  98. package/dist/n2kDevice.js.map +1 -0
  99. package/dist/ncanbus.d.ts +17 -0
  100. package/dist/ncanbus.d.ts.map +1 -0
  101. package/dist/ncanbus.js +92 -0
  102. package/dist/ncanbus.js.map +1 -0
  103. package/dist/pgns.d.ts +22 -0
  104. package/dist/pgns.d.ts.map +1 -0
  105. package/dist/pgns.js +157 -0
  106. package/dist/pgns.js.map +1 -0
  107. package/dist/pgns.test.d.ts +2 -0
  108. package/dist/pgns.test.d.ts.map +1 -0
  109. package/dist/pgns.test.js +14 -0
  110. package/dist/pgns.test.js.map +1 -0
  111. package/dist/simpleCan.d.ts +17 -0
  112. package/dist/simpleCan.d.ts.map +1 -0
  113. package/dist/simpleCan.js +125 -0
  114. package/dist/simpleCan.js.map +1 -0
  115. package/dist/stringMsg.d.ts +33 -0
  116. package/dist/stringMsg.d.ts.map +1 -0
  117. package/dist/stringMsg.js +359 -0
  118. package/dist/stringMsg.js.map +1 -0
  119. package/dist/stringMsg.test.d.ts +2 -0
  120. package/dist/stringMsg.test.d.ts.map +1 -0
  121. package/dist/stringMsg.test.js +244 -0
  122. package/dist/stringMsg.test.js.map +1 -0
  123. package/dist/toPgn.d.ts +34 -0
  124. package/dist/toPgn.d.ts.map +1 -0
  125. package/dist/toPgn.js +500 -0
  126. package/dist/toPgn.js.map +1 -0
  127. package/dist/utilities.d.ts +26 -0
  128. package/dist/utilities.d.ts.map +1 -0
  129. package/dist/utilities.js +112 -0
  130. package/dist/utilities.js.map +1 -0
  131. package/dist/utilities.test.d.ts +2 -0
  132. package/dist/utilities.test.d.ts.map +1 -0
  133. package/dist/utilities.test.js +9 -0
  134. package/dist/utilities.test.js.map +1 -0
  135. package/dist/venus-mqtt.d.ts +11 -0
  136. package/dist/venus-mqtt.d.ts.map +1 -0
  137. package/dist/venus-mqtt.js +100 -0
  138. package/dist/venus-mqtt.js.map +1 -0
  139. package/dist/venus.d.ts +11 -0
  140. package/dist/venus.d.ts.map +1 -0
  141. package/dist/venus.js +71 -0
  142. package/dist/venus.js.map +1 -0
  143. package/dist/w2k01.d.ts +17 -0
  144. package/dist/w2k01.d.ts.map +1 -0
  145. package/dist/w2k01.js +119 -0
  146. package/dist/w2k01.js.map +1 -0
  147. package/dist/yddevice.d.ts +25 -0
  148. package/dist/yddevice.d.ts.map +1 -0
  149. package/dist/yddevice.js +45 -0
  150. package/dist/yddevice.js.map +1 -0
  151. package/dist/ydgw02.d.ts +17 -0
  152. package/dist/ydgw02.d.ts.map +1 -0
  153. package/dist/ydgw02.js +163 -0
  154. package/dist/ydgw02.js.map +1 -0
  155. package/dist/ydvr.d.ts +17 -0
  156. package/dist/ydvr.d.ts.map +1 -0
  157. package/dist/ydvr.js +120 -0
  158. package/dist/ydvr.js.map +1 -0
  159. package/eslint.config.js +58 -0
  160. package/jest.config.js +5 -0
  161. package/lib/actisense-serial.ts +644 -0
  162. package/lib/bin/actisense-file.ts +53 -0
  163. package/lib/bin/actisense-n2k-tcp.ts +50 -0
  164. package/lib/bin/actisense-serialjs.ts +55 -0
  165. package/{bin/analyzerjs → lib/bin/analyzerjs.ts} +16 -15
  166. package/{bin/candumpjs → lib/bin/candumpjs.ts} +19 -20
  167. package/lib/bin/cansend.ts +131 -0
  168. package/lib/bin/ikonvert-serial.ts +44 -0
  169. package/{bin/to-pgn → lib/bin/to-pgn.ts} +23 -17
  170. package/lib/bin/ydvr-file +33 -0
  171. package/lib/canId.test.js +35 -15
  172. package/lib/canId.ts +84 -0
  173. package/lib/canbus.ts +293 -0
  174. package/lib/{candevice.js → candevice.ts} +14 -21
  175. package/lib/codes.ts +21 -0
  176. package/lib/{discovery.js → discovery.ts} +32 -30
  177. package/lib/fromPgn.ts +1207 -0
  178. package/lib/{fromPgnStream.js → fromPgnStream.ts} +17 -12
  179. package/lib/{ikonvert.js → ikonvert.ts} +90 -85
  180. package/lib/index.ts +48 -0
  181. package/lib/n2k-actisense.test.js +31 -32
  182. package/lib/n2k-actisense.ts +152 -0
  183. package/lib/n2kDevice.ts +458 -0
  184. package/lib/pgns.test.ts +12 -0
  185. package/lib/pgns.ts +191 -0
  186. package/lib/simpleCan.ts +140 -0
  187. package/lib/stringMsg.test.js +58 -41
  188. package/lib/stringMsg.ts +464 -0
  189. package/lib/toPgn.ts +597 -0
  190. package/lib/{utilities.js → utilities.ts} +48 -37
  191. package/lib/venus-mqtt.js +69 -73
  192. package/lib/venus.js +8 -8
  193. package/lib/{w2k01.js → w2k01.ts} +57 -44
  194. package/lib/{yddevice.js → yddevice.ts} +18 -13
  195. package/lib/{ydgw02.js → ydgw02.ts} +55 -47
  196. package/lib/ydvr.js +65 -147
  197. package/package.json +54 -18
  198. package/tsconfig.json +19 -0
  199. package/tsconfig.tsbuildinfo +1 -0
  200. package/bin/actisense-file +0 -47
  201. package/bin/actisense-n2k-tcp +0 -45
  202. package/bin/actisense-serialjs +0 -52
  203. package/bin/candumpanalyzerjs +0 -29
  204. package/bin/cansend +0 -130
  205. package/bin/ikonvert-serial +0 -50
  206. package/bin/ydgw-analyzerjs +0 -36
  207. package/bin/ydvr-file +0 -33
  208. package/index.js +0 -53
  209. package/lib/canId.js +0 -64
  210. package/lib/canbus.js +0 -278
  211. package/lib/codes.js +0 -69
  212. package/lib/codes.test.js +0 -17
  213. package/lib/codesMfgs.json +0 -166
  214. package/lib/fromPgn.js +0 -1027
  215. package/lib/n2k-actisense.js +0 -108
  216. package/lib/n2kDevice.js +0 -390
  217. package/lib/pgns.js +0 -196
  218. package/lib/pgns.test.js +0 -13
  219. package/lib/serial.js +0 -647
  220. package/lib/simpleCan.js +0 -105
  221. package/lib/stringMsg.js +0 -339
  222. package/lib/toPgn.js +0 -518
@@ -14,20 +14,26 @@
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'
29
+
30
+ const debug = createDebug('canboatjs:ydgw02')
25
31
 
26
32
  //const pgnsSent = {}
27
33
 
28
- function Ydgw02Stream (options, type) {
29
- if (!(this instanceof Ydgw02Stream)) {
30
- return new Ydgw02Stream(options)
34
+ export function Ydgw02Stream(this: any, options: any, type: string) {
35
+ if (this === undefined) {
36
+ return new (Ydgw02Stream as any)(options, type)
31
37
  }
32
38
 
33
39
  Transform.call(this, {
@@ -41,18 +47,17 @@ function Ydgw02Stream (options, type) {
41
47
 
42
48
  this.fromPgn = new FromPgn(options)
43
49
 
44
- this.fromPgn.on('warning', (pgn, warning) => {
50
+ this.fromPgn.on('warning', (_pgn: any, _warning: string) => {
45
51
  //debug(`[warning] ${pgn.pgn} ${warning}`)
46
52
  })
47
53
 
48
- this.fromPgn.on('error', (pgn, error) => {
54
+ this.fromPgn.on('error', (pgn: PGN, error: any) => {
49
55
  debug(`[error] ${pgn.pgn} ${error}`)
50
56
  })
51
57
 
52
-
53
- if ( options.app ) {
54
- options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
55
- if ( typeof msg === 'string' ) {
58
+ if (options.app) {
59
+ options.app.on(this.options.outEevent || 'nmea2000out', (msg: string) => {
60
+ if (typeof msg === 'string') {
56
61
  this.sendYdgwPGN(msg)
57
62
  } else {
58
63
  this.sendPGN(msg)
@@ -60,78 +65,77 @@ function Ydgw02Stream (options, type) {
60
65
  options.app.emit('connectionwrite', { providerId: options.providerId })
61
66
  })
62
67
 
63
- options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
68
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
64
69
  this.sendPGN(msg)
65
70
  options.app.emit('connectionwrite', { providerId: options.providerId })
66
71
  })
67
72
 
68
- options.app.on('ydFullRawOut', (msgs) => {
73
+ options.app.on('ydFullRawOut', (msgs: string[]) => {
69
74
  this.sendYdgwFullPGN(msgs)
70
75
  options.app.emit('connectionwrite', { providerId: options.providerId })
71
76
  })
72
77
 
73
78
  //this.sendString('$PDGY,N2NET_OFFLINE')
74
79
 
75
- if ( type === 'usb' ) {
80
+ if (type === 'usb') {
76
81
  // set ydnu to RAW mode
77
82
  options.app.emit(this.outEvent, Buffer.from([0x30, 0x0a]))
78
83
  }
79
84
 
80
- if ( options.createDevice === true ) {
85
+ if (options.createDevice === true) {
81
86
  this.device = new YdDevice(options)
82
87
  this.device.start()
83
88
  }
84
-
89
+
85
90
  debug('started')
86
91
  }
87
-
88
92
  }
89
93
 
90
- Ydgw02Stream.prototype.cansend = function (msg) {
94
+ Ydgw02Stream.prototype.cansend = function (_msg: any) {
91
95
  return this.device ? this.device.cansend : true
92
96
  }
93
97
 
94
- Ydgw02Stream.prototype.sendString = function (msg, forceSend) {
95
- if ( this.cansend() || forceSend === true ) {
98
+ Ydgw02Stream.prototype.sendString = function (msg: string, forceSend: boolean) {
99
+ if (this.cansend() || forceSend === true) {
96
100
  debug('sending %s', msg)
97
101
  this.options.app.emit(this.outEvent, msg)
98
102
  }
99
103
  }
100
104
 
101
- Ydgw02Stream.prototype.sendPGN = function (pgn) {
102
- if ( this.cansend() || pgn.forceSend === true ) {
105
+ Ydgw02Stream.prototype.sendPGN = function (pgn: PGN) {
106
+ if (this.cansend() || (pgn as any).forceSend === true) {
103
107
  //let now = Date.now()
104
108
  //let lastSent = pgnsSent[pgn.pgn]
105
109
  let msgs
106
- if ( pgn.ydFullFormat === true || this.device !== undefined ) {
110
+ if ((pgn as any).ydFullFormat === true || this.device !== undefined) {
111
+ pgn.src = this.device.address
107
112
  msgs = pgnToYdgwFullRawFormat(pgn)
108
113
  } else {
109
114
  msgs = pgnToYdgwRawFormat(pgn)
110
115
  }
111
- msgs.forEach(raw => {
112
- this.sendString(raw + '\r\n', pgn.forceSend)
116
+ msgs.forEach((raw) => {
117
+ this.sendString(raw + '\r\n', (pgn as any).forceSend)
113
118
  })
114
119
  //pgnsSent[pgn.pgn] = now
115
120
  }
116
121
  }
117
122
 
118
- Ydgw02Stream.prototype.sendYdgwFullPGN = function (msgs) {
119
- msgs.forEach(raw => {
123
+ Ydgw02Stream.prototype.sendYdgwFullPGN = function (msgs: string[]) {
124
+ msgs.forEach((raw) => {
120
125
  this.sendString(raw + '\r\n')
121
126
  })
122
127
  }
123
128
 
124
- Ydgw02Stream.prototype.sendYdgwPGN = function (msg) {
125
-
129
+ Ydgw02Stream.prototype.sendYdgwPGN = function (msg: string) {
126
130
  let msgs
127
131
 
128
- if ( this.device != undefined ) {
132
+ if (this.device != undefined) {
129
133
  msgs = actisenseToYdgwFullRawFormat(msg)
130
134
  } else {
131
135
  msgs = actisenseToYdgwRawFormat(msg)
132
136
  }
133
137
 
134
- msgs.forEach(raw => {
138
+ msgs.forEach((raw) => {
135
139
  this.sendString(raw + '\r\n')
136
140
  })
137
141
 
@@ -161,28 +165,32 @@ Ydgw02Stream.prototype.sendYdgwPGN = function (msg) {
161
165
  */
162
166
  }
163
167
 
164
- require('util').inherits(Ydgw02Stream, Transform)
168
+ util.inherits(Ydgw02Stream, Transform)
165
169
 
166
- Ydgw02Stream.prototype._transform = function (chunk, encoding, done) {
167
- let line = chunk.toString().trim()
170
+ Ydgw02Stream.prototype._transform = function (
171
+ chunk: any,
172
+ encoding: any,
173
+ done: any
174
+ ) {
175
+ const line = chunk.toString().trim()
168
176
  //line = line.substring(0, line.length) // take off the \r
169
177
 
170
- if ( this.device === undefined && !this.sentAvailable ) {
178
+ if (this.device === undefined && !this.sentAvailable) {
171
179
  debug('emit nmea2000OutAvailable')
172
180
  this.options.app.emit('nmea2000OutAvailable')
173
181
  this.sentAvailable = true
174
182
  }
175
183
 
176
184
  const pgn = this.fromPgn.parseYDGW02(line)
177
- if ( !_.isUndefined(pgn) ) {
185
+ if (pgn !== undefined) {
178
186
  this.push(pgn)
179
- this.options.app.emit(this.options.analyzerOutEvent || 'N2KAnalyzerOut', pgn)
187
+ this.options.app.emit(
188
+ this.options.analyzerOutEvent || 'N2KAnalyzerOut',
189
+ pgn
190
+ )
180
191
  }
181
192
 
182
193
  done()
183
194
  }
184
195
 
185
- Ydgw02Stream.prototype.end = function () {
186
- }
187
-
188
- module.exports = Ydgw02Stream
196
+ 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.1.0",
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
+ }