@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,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,33 +14,32 @@
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 pgnsSent = {}
27
+
28
+ export function iKonvertStream(this: any, options: any) {
29
+ if (this == undefined) {
30
+ return new (iKonvertStream as any)(options)
34
31
  }
35
32
 
33
+ this.debug = createDebug('canboatjs:ikonvert', options)
34
+
36
35
  Transform.call(this, {
37
36
  objectMode: true
38
37
  })
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
  })
@@ -88,50 +89,50 @@ function iKonvertStream (options) {
88
89
  this.setupCommands = this.getSetupCommands()
89
90
  this.expecting = false
90
91
 
91
- debug('started')
92
+ this.debug('started')
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) {
101
- debug('sending %s', msg)
102
- if ( this.isTcp ) {
103
- msg = msg + "\n\r"
100
+ iKonvertStream.prototype.sendString = function (msg: string) {
101
+ this.debug('sending %s', msg)
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,23 +141,23 @@ 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
- debug('sending pgn tx list')
147
+ this.debug('sending pgn tx list')
147
148
  this.sendString(txPgns)
148
149
  }
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') ) {
174
- debug(line)
175
- } else if ( line.startsWith('$PDGY,000000,') ) {
176
- let parts = line.split(',')
178
+ if (line.startsWith('$PDGY,TEXT')) {
179
+ this.debug(line)
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,50 +190,52 @@ 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 ) {
206
- debug(line)
213
+ if (!this.isSetup) {
214
+ this.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
- debug(`Waiting for ${command[1]}`)
220
+ this.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')
221
- debug('Setup completed')
229
+ this.debug('Setup completed')
222
230
  } else {
223
231
  command = this.setupCommands[this.state].split(':')
224
232
  this.sendString(command[0])
225
233
  this.expecting = true
226
234
  this.sentTime = Date.now()
227
- debug(`Waiting for ${command[1]}`)
235
+ this.debug(`Waiting for ${command[1]}`)
228
236
  }
229
- } else if ( Date.now() - this.sentTime > 5000 ) {
230
- debug(`Did not receive expected: ${command[1]}, retrying...`)
237
+ } else if (Date.now() - this.sentTime > 5000) {
238
+ this.debug(`Did not receive expected: ${command[1]}, retrying...`)
231
239
  this.sendString(command[0])
232
240
  this.sentTime = Date.now()
233
241
  }
@@ -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
+ }