@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,36 +14,41 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const debug = require('debug')('canboatjs:FromPgnStream')
18
- const Transform = require('stream').Transform
19
- const FromPgn = require('./fromPgn').Parser
20
- const _ = require('lodash')
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 util from 'util'
21
22
 
22
- function fromPgnStream (options) {
23
+ const debug = createDebug('canboatjs:FromPgnStream')
24
+
25
+ export function fromPgnStream(this: any, options: any = {}) {
23
26
  Transform.call(this, {
24
27
  objectMode: true
25
28
  })
26
29
 
27
30
  this.fromPgn = new FromPgn(options)
28
31
 
29
- this.fromPgn.on('pgn', pgn => {
32
+ this.fromPgn.on('pgn', (pgn: PGN) => {
30
33
  this.push(pgn)
31
34
  })
32
35
 
33
- this.fromPgn.on('warning', (pgn, warning) => {
36
+ this.fromPgn.on('warning', (pgn: PGN, warning: string) => {
34
37
  debug(`[warning] ${pgn.pgn} ${warning}`)
35
38
  })
36
39
 
37
- this.fromPgn.on('error', (pgn, error) => {
40
+ this.fromPgn.on('error', (pgn: PGN, error: any) => {
38
41
  debug(`[error] ${pgn.pgn} ${error}`)
39
42
  })
40
43
  }
41
44
 
42
- require('util').inherits(fromPgnStream, Transform)
45
+ util.inherits(fromPgnStream, Transform)
43
46
 
44
- fromPgnStream.prototype._transform = function (chunk, encoding, done) {
47
+ fromPgnStream.prototype._transform = function (
48
+ chunk: any,
49
+ encoding: string,
50
+ done: any
51
+ ) {
45
52
  this.fromPgn.parse(chunk)
46
53
  done()
47
54
  }
48
-
49
- module.exports = fromPgnStream
@@ -14,23 +14,22 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const debug = require('debug')('canboatjs:ikonvert')
18
- const Transform = require('stream').Transform
19
- const isArray = require('lodash').isArray
20
- const BitStream = require('bit-buffer').BitStream
21
- const BitView = require('bit-buffer').BitView
22
- const {toPgn, pgnToiKonvertSerialFormat} = require('./toPgn')
23
- const Parser = require('./fromPgn').Parser
24
- const _ = require('lodash')
25
- const CanDevice = require('./candevice')
26
- const { defaultTransmitPGNs } = require('./codes')
27
- const { parseCanId } = require('./canId')
28
-
29
- const pgnsSent = {}
30
-
31
- function iKonvertStream (options) {
32
- if (!(this instanceof iKonvertStream)) {
33
- return new iKonvertStream(options)
17
+ import { PGN } from '@canboat/ts-pgns'
18
+ import { createDebug } from './utilities'
19
+ import { Transform } from 'stream'
20
+ import { toPgn, pgnToiKonvertSerialFormat } from './toPgn'
21
+ import { Parser } from './fromPgn'
22
+ import _ from 'lodash'
23
+ import { defaultTransmitPGNs } from './codes'
24
+ import util from 'util'
25
+
26
+ const debug = createDebug('canboatjs:ikonvert')
27
+
28
+ //const pgnsSent = {}
29
+
30
+ export function iKonvertStream(this: any, options: any) {
31
+ if (this == undefined) {
32
+ return new (iKonvertStream as any)(options)
34
33
  }
35
34
 
36
35
  Transform.call(this, {
@@ -39,8 +38,8 @@ function iKonvertStream (options) {
39
38
 
40
39
  this.isTcp = options.tcp === true
41
40
 
42
- this.outEvent = this.isTcp? 'navlink2-out' : 'ikonvertOut'
43
-
41
+ this.outEvent = this.isTcp ? 'navlink2-out' : 'ikonvertOut'
42
+
44
43
  this.plainText = false
45
44
  this.reconnect = options.reconnect || true
46
45
  this.options = options
@@ -49,35 +48,37 @@ function iKonvertStream (options) {
49
48
  this.bufferOffset = 0
50
49
  this.start()
51
50
 
52
- this.setProviderStatus = options.app && options.app.setProviderStatus
53
- ? (msg) => {
54
- options.app.setProviderStatus(options.providerId, msg)
55
- }
56
- : () => {}
57
- this.setProviderError = options.app && options.app.setProviderError
58
- ? (msg) => {
59
- options.app.setProviderError(options.providerId, msg)
60
- }
61
- : () => {}
51
+ this.setProviderStatus =
52
+ options.app && options.app.setProviderStatus
53
+ ? (msg: string) => {
54
+ options.app.setProviderStatus(options.providerId, msg)
55
+ }
56
+ : () => {}
57
+ this.setProviderError =
58
+ options.app && options.app.setProviderError
59
+ ? (msg: string) => {
60
+ options.app.setProviderError(options.providerId, msg)
61
+ }
62
+ : () => {}
62
63
 
63
64
  this.transmitPGNs = defaultTransmitPGNs
64
- if ( this.options.transmitPGNs ) {
65
- this.transmitPGNs = _.union(this.transmitPGNs,
66
- this.options.transmitPGNs)
65
+ if (this.options.transmitPGNs) {
66
+ this.transmitPGNs = _.union(this.transmitPGNs, this.options.transmitPGNs)
67
67
  }
68
68
 
69
- var that = this
69
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
70
+ const that = this
70
71
 
71
- if ( this.options.app ) {
72
- options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
73
- if ( typeof msg === 'string' ) {
72
+ if (this.options.app) {
73
+ options.app.on(this.options.outEevent || 'nmea2000out', (msg: string) => {
74
+ if (typeof msg === 'string') {
74
75
  that.sendActisensePGN(msg)
75
76
  } else {
76
77
  that.sendPGN(msg)
77
78
  }
78
79
  options.app.emit('connectionwrite', { providerId: options.providerId })
79
80
  })
80
- options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
81
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
81
82
  that.sendPGN(msg)
82
83
  options.app.emit('connectionwrite', { providerId: options.providerId })
83
84
  })
@@ -92,46 +93,46 @@ function iKonvertStream (options) {
92
93
  }
93
94
  }
94
95
 
95
- require('util').inherits(iKonvertStream, Transform)
96
+ util.inherits(iKonvertStream, Transform)
96
97
 
97
- iKonvertStream.prototype.start = function () {
98
- }
98
+ iKonvertStream.prototype.start = function () {}
99
99
 
100
- iKonvertStream.prototype.sendString = function (msg) {
100
+ iKonvertStream.prototype.sendString = function (msg: string) {
101
101
  debug('sending %s', msg)
102
- if ( this.isTcp ) {
103
- msg = msg + "\n\r"
102
+ if (this.isTcp) {
103
+ msg = msg + '\n\r'
104
104
  }
105
105
  this.options.app.emit(this.outEvent, msg)
106
106
  }
107
107
 
108
- iKonvertStream.prototype.sendPGN = function (pgn) {
109
- if ( this.cansend ) {
110
- let now = Date.now()
111
- let lastSent = pgnsSent[pgn.pgn]
112
- let msg = pgnToiKonvertSerialFormat(pgn)
108
+ iKonvertStream.prototype.sendPGN = function (pgn: PGN) {
109
+ if (this.cansend) {
110
+ //let now = Date.now()
111
+ //let lastSent = pgnsSent[pgn.pgn]
112
+ const msg = pgnToiKonvertSerialFormat(pgn)
113
113
  this.sendString(msg)
114
- pgnsSent[pgn.pgn] = now
114
+ //pgnsSent[pgn.pgn] = now
115
115
  }
116
116
  }
117
117
 
118
- iKonvertStream.prototype.sendActisensePGN = function (msg) {
119
- if ( this.cansend ) {
120
- if ( !this.parser ) {
118
+ iKonvertStream.prototype.sendActisensePGN = function (msg: string) {
119
+ if (this.cansend) {
120
+ if (!this.parser) {
121
121
  this.parser = new Parser(this.options)
122
122
 
123
- let that = this
124
- this.parser.on('error', (pgn, error) => {
123
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
124
+ const that = this
125
+ this.parser.on('error', (pgn: PGN, error: any) => {
125
126
  console.error(`Error parsing ${pgn.pgn} ${error}`)
126
127
  console.error(error.stack)
127
128
  })
128
129
 
129
- this.parser.on('pgn', (pgn) => {
130
- let now = Date.now()
131
- let lastSent = pgnsSent[pgn.pgn]
132
- let msg = pgnToiKonvertSerialFormat(pgn)
130
+ this.parser.on('pgn', (pgn: PGN) => {
131
+ //let now = Date.now()
132
+ //let lastSent = pgnsSent[pgn.pgn]
133
+ const msg = pgnToiKonvertSerialFormat(pgn)
133
134
  that.sendString(msg)
134
- pgnsSent[pgn.pgn] = now
135
+ //pgnsSent[pgn.pgn] = now
135
136
  })
136
137
  }
137
138
  this.parser.parseString(msg)
@@ -140,7 +141,7 @@ iKonvertStream.prototype.sendActisensePGN = function (msg) {
140
141
 
141
142
  iKonvertStream.prototype.setup = function () {
142
143
  let txPgns = '$PDGY,TX_LIST'
143
- this.transmitPGNs.forEach(pgn => {
144
+ this.transmitPGNs.forEach((pgn: number) => {
144
145
  txPgns = txPgns + `,${pgn}`
145
146
  })
146
147
  debug('sending pgn tx list')
@@ -149,14 +150,14 @@ iKonvertStream.prototype.setup = function () {
149
150
 
150
151
  iKonvertStream.prototype.getSetupCommands = function () {
151
152
  let txPgns = '$PDGY,TX_LIST'
152
- this.transmitPGNs.forEach(pgn => {
153
+ this.transmitPGNs.forEach((pgn: number) => {
153
154
  txPgns = txPgns + `,${pgn}`
154
155
  })
155
156
 
156
- const setupCommands = [];
157
+ const setupCommands = []
157
158
 
158
159
  setupCommands.push('$PDGY,N2NET_OFFLINE:$PDGY,TEXT,Digital_Yacht_')
159
- if ( this.isTcp ) {
160
+ if (this.isTcp) {
160
161
  setupCommands.push('$PDGY,N2NET_MODE,15:$PDGY,ACK,N2NET_MODE')
161
162
  }
162
163
  setupCommands.push('$PDGY,TX_LIMIT,OFF:$PDGY,') // NACK is ok with old firmware
@@ -166,16 +167,21 @@ iKonvertStream.prototype.getSetupCommands = function () {
166
167
  return setupCommands
167
168
  }
168
169
 
169
- iKonvertStream.prototype._transform = function (chunk, encoding, done) {
170
+ iKonvertStream.prototype._transform = function (
171
+ chunk: any,
172
+ encoding: string,
173
+ done: any
174
+ ) {
170
175
  let line = chunk.toString().trim()
171
176
  line = line.substring(0, line.length) // take off the \r
172
177
 
173
- if ( line.startsWith('$PDGY,TEXT') ) {
178
+ if (line.startsWith('$PDGY,TEXT')) {
174
179
  debug(line)
175
- } else if ( line.startsWith('$PDGY,000000,') ) {
176
- let parts = line.split(',')
180
+ } else if (line.startsWith('$PDGY,000000,')) {
181
+ const parts = line.split(',')
177
182
 
178
- if ( this.options.sendNetworkStats && parts[2] && parts[2].length > 0 ) {
183
+ //FIXME, camelCase?
184
+ if (this.options.sendNetworkStats && parts[2] && parts[2].length > 0) {
179
185
  const pgn = {
180
186
  pgn: 0x40100,
181
187
  prio: 7,
@@ -184,37 +190,39 @@ iKonvertStream.prototype._transform = function (chunk, encoding, done) {
184
190
  'CAN network load': Number(parts[2]),
185
191
  Errors: Number(parts[3]),
186
192
  'Device count': Number(parts[4]),
187
- 'Uptime': Number(parts[5]),
193
+ Uptime: Number(parts[5]),
188
194
  'Gateway address': Number(parts[6]),
189
195
  'Rejected TX requests': Number(parts[7])
190
196
  }
191
197
  const buf = toPgn(pgn)
192
- if ( buf ) {
193
- this.push(`!PDGY,${pgn.pgn},${pgn.prio},${pgn.src},${pgn.dst},0,${buf.toString('base64')}`)
198
+ if (buf) {
199
+ this.push(
200
+ `!PDGY,${pgn.pgn},${pgn.prio},${pgn.src},${pgn.dst},0,${buf.toString('base64')}`
201
+ )
194
202
  }
195
203
  done()
196
204
  return
197
205
  }
198
- } else if ( line.startsWith('$PDGY,NAK') ) {
199
- let parts = line.split(',')
200
- let msg = `NavLink2 error ${parts[2]}: ${parts[3]}`
206
+ } else if (line.startsWith('$PDGY,NAK')) {
207
+ const parts = line.split(',')
208
+ const msg = `NavLink2 error ${parts[2]}: ${parts[3]}`
201
209
  console.error(msg)
202
210
  //this.setProviderError(msg)
203
211
  }
204
212
 
205
- if ( !this.isSetup ) {
213
+ if (!this.isSetup) {
206
214
  debug(line)
207
215
  let command = this.setupCommands[this.state].split(':')
208
- if ( !this.expecting ) {
216
+ if (!this.expecting) {
209
217
  this.sendString(command[0])
210
218
  this.expecting = true
211
219
  this.sentTime = Date.now()
212
220
  debug(`Waiting for ${command[1]}`)
213
221
  } else {
214
- if ( line.startsWith(command[1]) ) {
222
+ if (line.startsWith(command[1])) {
215
223
  this.state = this.state + 1
216
-
217
- if ( this.state == this.setupCommands.length ) {
224
+
225
+ if (this.state == this.setupCommands.length) {
218
226
  this.isSetup = true
219
227
  this.cansend = true
220
228
  this.options.app.emit('nmea2000OutAvailable')
@@ -226,7 +234,7 @@ iKonvertStream.prototype._transform = function (chunk, encoding, done) {
226
234
  this.sentTime = Date.now()
227
235
  debug(`Waiting for ${command[1]}`)
228
236
  }
229
- } else if ( Date.now() - this.sentTime > 5000 ) {
237
+ } else if (Date.now() - this.sentTime > 5000) {
230
238
  debug(`Did not receive expected: ${command[1]}, retrying...`)
231
239
  this.sendString(command[0])
232
240
  this.sentTime = Date.now()
@@ -235,11 +243,8 @@ iKonvertStream.prototype._transform = function (chunk, encoding, done) {
235
243
  } else {
236
244
  this.push(line)
237
245
  }
238
-
239
- done()
240
- }
241
246
 
242
- iKonvertStream.prototype.end = function () {
247
+ done()
243
248
  }
244
249
 
245
- module.exports = iKonvertStream
250
+ iKonvertStream.prototype.end = function () {}
package/lib/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Copyright 2019 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
+ export { Parser as FromPgn } from './fromPgn'
18
+ export { CanbusStream as canbus } from './canbus'
19
+ export {
20
+ addCustomPgns,
21
+ lookupEnumerationValue,
22
+ lookupEnumerationName
23
+ } from './pgns'
24
+ export {
25
+ parseN2kString,
26
+ isN2KString,
27
+ toActisenseSerialFormat
28
+ } from './stringMsg'
29
+ export {
30
+ toPgn,
31
+ pgnToActisenseSerialFormat,
32
+ pgnToActisenseN2KAsciiFormat,
33
+ pgnToiKonvertSerialFormat,
34
+ pgnToYdgwRawFormat,
35
+ pgnToYdgwFullRawFormat,
36
+ pgnToPCDIN,
37
+ pgnToMXPGN
38
+ } from './toPgn'
39
+ export { Ydgw02Stream as Ydwg02 } from './ydgw02'
40
+ export { Ydgw02Stream as Ydgw02 } from './ydgw02'
41
+ export { W2K01Stream as W2k01 } from './w2k01'
42
+ export { iKonvertStream as iKonvert } from './ikonvert'
43
+ export { VenusStream as Venus } from './venus'
44
+ export { VenusMQTT } from './venus-mqtt'
45
+ export { discover } from './discovery'
46
+ export { SimpleCan } from './simpleCan'
47
+ export { YdDevice } from './yddevice'
48
+ export { ActisenseStream as serial } from './actisense-serial'
@@ -1,59 +1,58 @@
1
1
  const { readN2KActisense, encodeN2KActisense } = require('./n2k-actisense')
2
2
 
3
-
4
3
  describe('readN2KActisense', () => {
5
4
  test('basic msg', () => {
6
- const buffer = Buffer.from('1002d01500ff0502f809004c86fe00fffccba56800ffff7310031002d01500ff0501f809004c86fe000d474717e2da69d29c1003', 'hex')
5
+ const buffer = Buffer.from(
6
+ '1002d01500ff0502f809004c86fe00fffccba56800ffff7310031002d01500ff0501f809004c86fe000d474717e2da69d29c1003',
7
+ 'hex'
8
+ )
7
9
  const res = readN2KActisense(buffer, false, {})
8
10
  delete res.pgn.timestamp
9
11
  expect(res).toEqual({
10
- "coalesced": true,
11
- "data": Buffer.from('0d474717e2da69d2', 'hex'),
12
- "length": 8,
13
- "pgn": {
14
- "canId": 167248133,
15
- "dst": 255,
16
- "pgn": 129025,
17
- "prio": 2,
18
- "src": 5,
12
+ coalesced: true,
13
+ data: Buffer.from('0d474717e2da69d2', 'hex'),
14
+ length: 8,
15
+ pgn: {
16
+ canId: 167248133,
17
+ dst: 255,
18
+ pgn: 129025,
19
+ prio: 2,
20
+ src: 5
19
21
  }
20
22
  })
21
23
  })
22
24
  })
23
25
 
24
-
25
26
  describe('encodeN2KActisense', () => {
26
27
  test('basic msg', () => {
27
28
  const expected = '1002d01500ff0501f80900000000000d474717e2da69d2001003'
28
29
  const pgn = {
29
- "data": Buffer.from('0d474717e2da69d2', 'hex'),
30
- "dst": 255,
31
- "pgn": 129025,
32
- "prio": 2,
33
- "src": 5,
30
+ dst: 255,
31
+ pgn: 129025,
32
+ prio: 2,
33
+ src: 5
34
34
  }
35
35
 
36
- const encoded = encodeN2KActisense(pgn)
36
+ const encoded = encodeN2KActisense(
37
+ pgn,
38
+ Buffer.from('0d474717e2da69d2', 'hex')
39
+ )
37
40
  expect(encoded).toEqual(Buffer.from(expected, 'hex'))
38
41
 
39
42
  const read = readN2KActisense(encoded, false, {})
40
43
  delete read.pgn.timestamp
41
-
44
+
42
45
  expect(read).toEqual({
43
- "coalesced": true,
44
- "data": Buffer.from('0d474717e2da69d2', 'hex'),
45
- "length": 8,
46
- "pgn": {
47
- "canId": 167248133,
48
- "dst": 255,
49
- "pgn": 129025,
50
- "prio": 2,
51
- "src": 5,
46
+ coalesced: true,
47
+ data: Buffer.from('0d474717e2da69d2', 'hex'),
48
+ length: 8,
49
+ pgn: {
50
+ canId: 167248133,
51
+ dst: 255,
52
+ pgn: 129025,
53
+ prio: 2,
54
+ src: 5
52
55
  }
53
56
  })
54
-
55
-
56
57
  })
57
58
  })
58
-
59
-
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Copyright 2025 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 { PGN } from '@canboat/ts-pgns'
18
+ import { createDebug } from './utilities'
19
+ import { parseCanId, encodeCanId } from './canId'
20
+ import { BitStream } from 'bit-buffer'
21
+ import { binToActisense } from './utilities'
22
+
23
+ const debug = createDebug('canboatjs:w2k01')
24
+ const debugData = createDebug('canboatjs:w2k01-data')
25
+
26
+ export const readN2KActisense = (
27
+ data: Buffer,
28
+ plainText: boolean,
29
+ context: any,
30
+ cb: (data: any) => void
31
+ ) => {
32
+ const inBuf = Buffer.from(data)
33
+ let inOffset = 0
34
+ let last
35
+
36
+ if (debugData.enabled) {
37
+ debugData(
38
+ 'Received: (' + data.length + ') ' + Buffer.from(data).toString('hex')
39
+ )
40
+ }
41
+
42
+ try {
43
+ while (true) {
44
+ const len = inBuf.readUInt16LE(inOffset + 3)
45
+
46
+ if (inBuf.length < inOffset + 5 + len) {
47
+ /*
48
+ I've never seen this happen
49
+ context.lastChunk = Buffer.alloc(inBuf.length - inOffset)
50
+ inBuf.copy(context.lastChunk, 0, inOffset, inBuf.length-1)
51
+ */
52
+
53
+ if (debug.enabled) {
54
+ debug(
55
+ 'incomplete packet: (' +
56
+ len +
57
+ ') ' +
58
+ inBuf.toString('hex', inOffset)
59
+ )
60
+ }
61
+
62
+ return
63
+ } else if (
64
+ inBuf[inOffset + 5 + len - 1] != 0x03 ||
65
+ inBuf[inOffset + 5 + len - 2] != 0x10
66
+ ) {
67
+ if (debug.enabled) {
68
+ debug('bad packet: (' + len + ') ' + inBuf.toString('hex', inOffset))
69
+ }
70
+ //context.lastChunk = null
71
+ return
72
+ }
73
+
74
+ const buf = Buffer.alloc(len)
75
+ inBuf.copy(buf, 0, inOffset + 5, inOffset + len + 5)
76
+
77
+ //console.log('NextBuf: (' + buf.length + ') ' + buf.toString('hex'))
78
+
79
+ let offset = 0
80
+ const _dst = buf.readUInt8(offset)
81
+ offset += 1
82
+ const canid = buf.readUInt32LE(offset)
83
+ offset += 4
84
+ const _timestamp = buf.readUInt32LE(offset)
85
+ offset += 4
86
+ const _mhs = buf.readUInt8(offset)
87
+ offset += 1
88
+
89
+ const info = parseCanId(canid)
90
+
91
+ //console.log(`${len} ${mhs} ${dst} (${info.src}, ${info.dst}) ${info.pgn} ${timestamp}`)
92
+
93
+ const pgnData = Buffer.alloc(len - offset - 3)
94
+ buf.copy(pgnData, 0, offset, len - 3)
95
+ const timestamp = new Date().toISOString()
96
+
97
+ if (plainText) {
98
+ last = binToActisense(info, timestamp, pgnData, pgnData.length)
99
+ cb && cb(last)
100
+ } else {
101
+ last = {
102
+ pgn: info,
103
+ length: pgnData.length,
104
+ data: pgnData,
105
+ coalesced: true
106
+ }
107
+ cb && cb(last)
108
+ }
109
+
110
+ inOffset += len + 5
111
+ if (inOffset == inBuf.length) {
112
+ return last
113
+ }
114
+ }
115
+ } catch (error) {
116
+ debug(`[error] ${error}`)
117
+ //context.lastChunk = null
118
+ return
119
+ }
120
+ }
121
+
122
+ export const encodeN2KActisense = (pgn: PGN, data: Buffer) => {
123
+ const bs = new BitStream(Buffer.alloc(18 + data.length))
124
+
125
+ bs.writeUint8(0x10) //BST Message ID
126
+ bs.writeUint8(0x02)
127
+ bs.writeUint8(0xd0)
128
+
129
+ bs.writeUint16(13 + data.length) //len
130
+ bs.writeUint8(pgn.dst)
131
+ bs.writeUint32(
132
+ encodeCanId({
133
+ pgn: pgn.pgn,
134
+ src: pgn.src || 0,
135
+ prio: pgn.prio || 2,
136
+ dst: pgn.dst
137
+ })
138
+ )
139
+ bs.writeUint32(0) //timestamp
140
+ bs.writeUint8(0) //mhs
141
+ data.copy(bs.view.buffer, bs.byteIndex, 0)
142
+ bs.byteIndex += data.length
143
+ bs.writeUint8(0) // ??
144
+ bs.writeUint8(0x10)
145
+ bs.writeUint8(0x03)
146
+
147
+ if (debugData.enabled) {
148
+ debugData('encoded: ' + bs.view.buffer.toString('hex'))
149
+ }
150
+
151
+ return bs.view.buffer
152
+ }