@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,30 +14,37 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const { keys, map, padCharsStart, trimChars } = require('lodash/fp')
17
+ import { debug } from 'debug'
18
18
 
19
- function getPlainPGNs(buffer) {
20
- var res = []
21
- var bucket = 0x40 // 64
19
+ import { CanID } from './canId'
20
+ import { map, padCharsStart, trimChars } from 'lodash/fp'
22
21
 
23
- var first = Buffer.alloc(8)
22
+ export const createDebug = (name: string) => {
23
+ return debug(name)
24
+ }
25
+
26
+ export function getPlainPGNs(buffer: Buffer) {
27
+ const res = []
28
+ let bucket = 0x40 // 64
29
+
30
+ const first = Buffer.alloc(8)
24
31
  first.writeUInt8(bucket++, 0)
25
32
  first.writeUInt8(buffer.length, 1)
26
33
  buffer.copy(first, 2, 0, 6)
27
34
  res.push(first)
28
35
 
29
- for ( var index = 6; index < buffer.length; index += 7 ) {
30
- var next = Buffer.alloc(8)
36
+ for (let index = 6; index < buffer.length; index += 7) {
37
+ const next = Buffer.alloc(8)
31
38
  next.writeUInt8(bucket++, 0)
32
- var end = index+7
33
- var fill = 0
34
- if ( end > buffer.length ) {
39
+ let end = index + 7
40
+ let fill = 0
41
+ if (end > buffer.length) {
35
42
  fill = end - buffer.length
36
43
  end = buffer.length
37
44
  }
38
45
  buffer.copy(next, 1, index, end)
39
- if ( fill > 0 ) {
40
- for ( var i = end-index+1; i < 8; i++ ) {
46
+ if (fill > 0) {
47
+ for (let i = end - index + 1; i < 8; i++) {
41
48
  next.writeUInt8(0xff, i)
42
49
  }
43
50
  }
@@ -45,8 +52,6 @@ function getPlainPGNs(buffer) {
45
52
  }
46
53
  return res
47
54
  }
48
- exports.getPlainPGNs = getPlainPGNs
49
-
50
55
 
51
56
  const m_hex = [
52
57
  '0',
@@ -67,13 +72,13 @@ const m_hex = [
67
72
  'F'
68
73
  ]
69
74
 
70
- function toHexString (v) {
71
- let msn = (v >> 4) & 0x0f
72
- let lsn = (v >> 0) & 0x0f
75
+ function toHexString(v: number) {
76
+ const msn = (v >> 4) & 0x0f
77
+ const lsn = (v >> 0) & 0x0f
73
78
  return m_hex[msn] + m_hex[lsn]
74
79
  }
75
80
 
76
- function compute0183Checksum (sentence) {
81
+ export function compute0183Checksum(sentence: string) {
77
82
  // skip the $
78
83
  let i = 1
79
84
  // init to first character
@@ -85,27 +90,33 @@ function compute0183Checksum (sentence) {
85
90
  return '*' + toHexString(c1)
86
91
  }
87
92
 
88
- function binToActisense(pgn, data, length) {
93
+ export function binToActisense(
94
+ pgn: CanID,
95
+ timestamp: string,
96
+ data: Buffer,
97
+ length: number
98
+ ) {
99
+ const arr: string[] = []
89
100
  return (
90
- pgn.timestamp +
91
- `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
92
- new Uint32Array(data)
93
- .reduce(function(acc, i) {
94
- acc.push(i.toString(16));
95
- return acc;
96
- }, [])
97
- .map(x => (x.length === 1 ? "0" + x : x))
98
- .join(",")
99
- );
101
+ timestamp +
102
+ `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
103
+ new Uint32Array(data)
104
+ .reduce(function (acc, i) {
105
+ acc.push(i.toString(16))
106
+ return acc
107
+ }, arr)
108
+ .map((x) => (x.length === 1 ? '0' + x : x))
109
+ .join(',')
110
+ )
100
111
  }
101
112
 
102
- exports.binToActisense = binToActisense
103
- exports.compute0183Checksum = compute0183Checksum
104
- exports.trimWrap = trimChars('()<>[]')
105
- exports.rmChecksum = str => str.includes('*') ? str.split('*', 1)[0] : str
106
- exports.arrBuff = (arr, encoding = 'hex') => Buffer.from(arr.join(''), encoding)
107
- exports.hexByte = x => padCharsStart('0', 2, Number(x).toString(16))
108
- exports.byteString = (data, separator = ',') => (
113
+ export const trimWrap = trimChars('()<>[]')
114
+ export const rmChecksum = (str: string) =>
115
+ str.includes('*') ? str.split('*', 1)[0] : str
116
+ export const arrBuff = (arr: string[], encoding: BufferEncoding = 'hex') =>
117
+ Buffer.from(arr.join(''), encoding)
118
+ export const hexByte = (x: number) =>
119
+ padCharsStart('0', 2, Number(x).toString(16))
120
+ export const byteString = (data: Buffer, separator = ',') =>
109
121
  // Uint32Array map method doesn't work as expect. _.map does.
110
122
  map(exports.hexByte, new Uint32Array(data)).join(separator)
111
- )
package/lib/venus-mqtt.js CHANGED
@@ -1,11 +1,10 @@
1
-
2
1
  const Transform = require('stream').Transform
3
- const mqtt = require('mqtt');
2
+ const mqtt = require('mqtt')
4
3
  const debug = require('debug')('venus-mqtt')
5
4
  //const pgns = require('./fromPgn').pgns
6
5
  const _ = require('lodash')
7
6
 
8
- function MQTTStream (options) {
7
+ function MQTTStream(options) {
9
8
  Transform.call(this, {
10
9
  objectMode: true
11
10
  })
@@ -14,109 +13,106 @@ function MQTTStream (options) {
14
13
 
15
14
  require('util').inherits(MQTTStream, Transform)
16
15
 
17
- MQTTStream.prototype.discoveryAvailable = function() {
18
- return moduleAvailable('md' + 'ns');
19
- };
20
-
21
- function mysleep(millis) {
22
- return new Promise(resolve => setTimeout(resolve, millis));
16
+ MQTTStream.prototype.discoveryAvailable = function () {
17
+ return moduleAvailable('md' + 'ns')
23
18
  }
24
19
 
25
20
  MQTTStream.prototype.pipe = function (pipeTo) {
26
21
  const that = this
27
- this.startDiscovery().then(service => {
28
- let url = service.txtRecord.mqtt_broker
29
- var client = mqtt.connect(url)
30
- client.on('connect', function () {
31
- debug(`connected to ${url}`)
32
-
33
- client.subscribe('n2k/mqtt_n2k/self')
34
- //client.subscribe('n2k/mqtt_n2k/listenpgns')
35
- client.publish('n2k/mqtt_n2k/getself')
36
- client.publish('n2k/mqtt_n2k/addpgn', '129026')
37
- client.publish('n2k/mqtt_n2k/addpgn', '129025')
38
- //client.publish('n2k/mqtt_n2k/getlistenpgns')
39
- client.subscribe('n2k/mqtt_n2k/bus/#')
40
-
41
- /*
22
+ this.startDiscovery()
23
+ .then((service) => {
24
+ let url = service.txtRecord.mqtt_broker
25
+ var client = mqtt.connect(url)
26
+ client.on('connect', function () {
27
+ debug(`connected to ${url}`)
28
+
29
+ client.subscribe('n2k/mqtt_n2k/self')
30
+ //client.subscribe('n2k/mqtt_n2k/listenpgns')
31
+ client.publish('n2k/mqtt_n2k/getself')
32
+ client.publish('n2k/mqtt_n2k/addpgn', '129026')
33
+ client.publish('n2k/mqtt_n2k/addpgn', '129025')
34
+ //client.publish('n2k/mqtt_n2k/getlistenpgns')
35
+ client.subscribe('n2k/mqtt_n2k/bus/#')
36
+
37
+ /*
42
38
  pgns.forEach(key => {
43
39
  debug(`adding pgn ${key}`)
44
40
  client.publish('n2k/mqtt_n2k/addpgn', key)
45
41
  //require('sleep').msleep(100)
46
42
  })
47
43
  */
48
-
49
- })
44
+ })
50
45
 
51
- client.on('error', error => {
52
- this.options.app.setProviderError(`error connecting to mqtt ${error}`)
53
- })
46
+ client.on('error', (error) => {
47
+ this.options.app.setProviderError(`error connecting to mqtt ${error}`)
48
+ })
54
49
 
55
- client.on('close', () => {
56
- this.options.app.setProviderError(`mqtt close`)
57
- });
50
+ client.on('close', () => {
51
+ this.options.app.setProviderError(`mqtt close`)
52
+ })
58
53
 
59
- client.on('reconnect', () => {
60
- //this.(`mqtt reconnect`)
61
- });
54
+ client.on('reconnect', () => {
55
+ //this.(`mqtt reconnect`)
56
+ })
62
57
 
63
- client.on('message', (topic, json) => {
64
- debug(`${topic}: '${json}'`)
65
- const pgn = JSON.parse(json);
66
- if ( topic.startsWith('n2k/mqtt_n2k/bus/') ) {
67
- that.push(pgn)
68
- }
58
+ client.on('message', (topic, json) => {
59
+ debug(`${topic}: '${json}'`)
60
+ const pgn = JSON.parse(json)
61
+ if (topic.startsWith('n2k/mqtt_n2k/bus/')) {
62
+ that.push(pgn)
63
+ }
64
+ })
69
65
  })
70
- }).catch(error => {
71
- debug(error)
72
- this.options.app.setProviderStatus(error.msg)
73
- })
74
-
66
+ .catch((error) => {
67
+ debug(error)
68
+ this.options.app.setProviderStatus(error.msg)
69
+ })
70
+
75
71
  Transform.prototype.pipe.call(this, pipeTo)
76
72
  }
77
73
 
78
- MQTTStream.prototype.startDiscovery = function() {
79
- var that = this;
80
- return new Promise(function(resolve, reject) {
74
+ MQTTStream.prototype.startDiscovery = function () {
75
+ var that = this
76
+ return new Promise(function (resolve, reject) {
81
77
  if (!that.discoveryAvailable()) {
82
- console.log(
83
- "Discovery requires mdns or specify hostname and port"
84
- );
85
- reject('Discovery requires mdns');
78
+ console.log('Discovery requires mdns or specify hostname and port')
79
+ reject('Discovery requires mdns')
86
80
  }
87
-
88
- var mdns = require('md' + 'ns');
89
-
81
+
82
+ var mdns = require('md' + 'ns')
83
+
90
84
  function doStart(serviceName) {
91
85
  let browser = mdns.createBrowser(mdns.tcp(serviceName), {
92
- resolverSequence: [mdns.rst.DNSServiceResolve()],
93
- });
94
- browser.on('serviceUp', function(service) {
95
- debug(`Discovered ${serviceName}:` + JSON.stringify(service, null, 2));
86
+ resolverSequence: [mdns.rst.DNSServiceResolve()]
87
+ })
88
+ browser.on('serviceUp', function (service) {
89
+ debug(`Discovered ${serviceName}:` + JSON.stringify(service, null, 2))
96
90
  //that.get('/signalk', service.host, service.port, isHttps ? 'https' : 'http').then(function(response) {
97
- debug(`Service at ${service.host}:${service.port} ${service.txtRecord.base_topic}`)
91
+ debug(
92
+ `Service at ${service.host}:${service.port} ${service.txtRecord.base_topic}`
93
+ )
98
94
  resolve(service)
99
- });
100
- debug(`Starting ${serviceName} discovery`);
101
- browser.start();
95
+ })
96
+ debug(`Starting ${serviceName} discovery`)
97
+ browser.start()
102
98
  return browser
103
99
  }
104
-
100
+
105
101
  this.browser = doStart('mqtt-n2k')
106
102
  })
107
103
  }
108
-
109
104
 
110
- MQTTStream.prototype._transform = function (data, encoding, callback) {}
105
+ MQTTStream.prototype._transform = function (_data, _encoding, _callback) {}
111
106
 
112
107
  function moduleAvailable(name) {
113
108
  try {
114
- require.resolve(name);
115
- return true;
116
- } catch (e) {}
117
- return false;
109
+ require.resolve(name)
110
+ return true
111
+ // eslint-disable-next-line no-empty
112
+ } catch (_e) {}
113
+ return false
118
114
  }
119
115
 
120
- module.exports = MQTTStream
116
+ module.exports.VenusMQTT = MQTTStream
121
117
 
122
- const pgns = [ '126992','127505','129029','129291','130312','127245','127506','129038','129793','130314','127250','127508','129039','129794','130577','127251','128259','129040','129809','130842','127257','128267','129041','129810','127258','128275','129283','130306','127488','129025','129284','130310','127489','129026','129285','130311']
118
+ //const pgns = [ '126992','127505','129029','129291','130312','127245','127506','129038','129793','130314','127250','127508','129039','129794','130577','127251','128259','129040','129809','130842','127257','128267','129041','129810','127258','128275','129283','130306','127488','129025','129284','130310','127489','129026','129285','130311']
package/lib/venus.js CHANGED
@@ -19,7 +19,7 @@ const Transform = require('stream').Transform
19
19
  const FromPgn = require('./fromPgn').Parser
20
20
  const _ = require('lodash')
21
21
 
22
- function VenusStream (options) {
22
+ function VenusStream(options) {
23
23
  if (!(this instanceof VenusStream)) {
24
24
  return new VenusStream(options)
25
25
  }
@@ -47,7 +47,6 @@ function VenusStream (options) {
47
47
  debug(`[error] ${pgn.pgn} ${error}`)
48
48
  })
49
49
 
50
-
51
50
  /*
52
51
  if ( this.options.app ) {
53
52
  options.app.on('nmea2000out', (msg) => {
@@ -67,22 +66,23 @@ function VenusStream (options) {
67
66
 
68
67
  require('util').inherits(VenusStream, Transform)
69
68
 
70
-
71
69
  VenusStream.prototype._transform = function (pgn, encoding, done) {
72
70
  //let line = chunk.toString().trim()
73
71
  //line = line.substring(0, line.length) // take off the \r
74
72
 
75
73
  this.fromPgn.parseVenusMQTT(pgn, (error, pgn) => {
76
- if ( !error ) {
74
+ if (!error) {
77
75
  this.push(pgn)
78
- this.options.app.emit(this.options.analyzerOutEvent || 'N2KAnalyzerOut', pgn)
76
+ this.options.app.emit(
77
+ this.options.analyzerOutEvent || 'N2KAnalyzerOut',
78
+ pgn
79
+ )
79
80
  }
80
81
 
81
82
  done()
82
83
  })
83
84
  }
84
85
 
85
- VenusStream.prototype.end = function () {
86
- }
86
+ VenusStream.prototype.end = function () {}
87
87
 
88
- module.exports = VenusStream
88
+ module.exports.VenusStream = VenusStream
@@ -14,21 +14,34 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const debug = require('debug')('canboatjs:w2k01')
18
- const debugData = require('debug')('canboatjs:w2k01-data')
19
- const Transform = require('stream').Transform
20
- const _ = require('lodash')
21
- const { pgnToActisenseN2KAsciiFormat, actisenseToN2KAsciiFormat, pgnToN2KActisenseFormat, actisenseToN2KActisenseFormat } = require('./toPgn')
22
- const { readN2KActisense, encodeN2KActisense } = require('./n2k-actisense')
23
-
24
- const pgnsSent = {}
17
+ import { PGN } from '@canboat/ts-pgns'
18
+ import { createDebug } from './utilities'
19
+ import { Transform } from 'stream'
20
+ import {
21
+ pgnToActisenseN2KAsciiFormat,
22
+ actisenseToN2KAsciiFormat,
23
+ pgnToN2KActisenseFormat,
24
+ actisenseToN2KActisenseFormat
25
+ } from './toPgn'
26
+ import { readN2KActisense } from './n2k-actisense'
27
+ import util from 'util'
28
+
29
+ const debug = createDebug('canboatjs:w2k01')
30
+ const debugData = createDebug('canboatjs:w2k01-data')
31
+
32
+ //const pgnsSent = {}
25
33
 
26
34
  const N2K_ASCII = 0
27
35
  const N2K_ACTISENSE = 1
28
36
 
29
- function W2K01Stream (options, type, outEvent) {
30
- if (!(this instanceof W2K01Stream)) {
31
- return new W2K01Stream(options)
37
+ export function W2K01Stream(
38
+ this: any,
39
+ options: any,
40
+ type: string,
41
+ outEvent: string
42
+ ) {
43
+ if (this === undefined) {
44
+ return new (W2K01Stream as any)(options, type, outEvent)
32
45
  }
33
46
 
34
47
  Transform.call(this, {
@@ -41,18 +54,18 @@ function W2K01Stream (options, type, outEvent) {
41
54
 
42
55
  this.format = type === 'ascii' ? N2K_ASCII : N2K_ACTISENSE
43
56
 
44
- if ( this.format === N2K_ASCII ) {
45
- if ( options.app ) {
46
- options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
47
- if ( typeof msg === 'string' ) {
57
+ if (this.format === N2K_ASCII) {
58
+ if (options.app) {
59
+ options.app.on(this.options.outEevent || 'nmea2000out', (msg: string) => {
60
+ if (typeof msg === 'string') {
48
61
  this.sendW2KPGN(msg)
49
62
  } else {
50
63
  this.sendPGN(msg)
51
64
  }
52
65
  options.app.emit('connectionwrite', { providerId: options.providerId })
53
66
  })
54
-
55
- options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
67
+
68
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
56
69
  this.sendPGN(msg)
57
70
  options.app.emit('connectionwrite', { providerId: options.providerId })
58
71
  })
@@ -62,68 +75,68 @@ function W2K01Stream (options, type, outEvent) {
62
75
  debug('started')
63
76
  }
64
77
 
65
- W2K01Stream.prototype.send = function (msg) {
78
+ W2K01Stream.prototype.send = function (msg: string | Buffer) {
66
79
  debug('sending %s', msg)
67
80
  this.options.app.emit(this.outEvent, msg)
68
81
  }
69
82
 
70
- W2K01Stream.prototype.sendPGN = function (pgn) {
71
- let now = Date.now()
72
- let lastSent = pgnsSent[pgn.pgn]
73
- if ( this.format === N2K_ASCII ) {
74
- let ascii = pgnToActisenseN2KAsciiFormat(pgn)
83
+ W2K01Stream.prototype.sendPGN = function (pgn: PGN) {
84
+ //const now = Date.now()
85
+ //let lastSent = pgnsSent[pgn.pgn]
86
+ if (this.format === N2K_ASCII) {
87
+ const ascii = pgnToActisenseN2KAsciiFormat(pgn)
75
88
  this.send(ascii + '\r\n')
76
89
  } else {
77
- let buf = pgnToN2KActisenseFormat(pgn)
90
+ const buf = pgnToN2KActisenseFormat(pgn)
78
91
  this.send(buf)
79
92
  }
80
- pgnsSent[pgn.pgn] = now
93
+ //pgnsSent[pgn.pgn] = now
81
94
  }
82
95
 
83
- W2K01Stream.prototype.sendW2KPGN = function (msg) {
84
- if ( this.format === N2K_ASCII ) {
85
- let ascii = actisenseToN2KAsciiFormat(msg)
96
+ W2K01Stream.prototype.sendW2KPGN = function (msg: string) {
97
+ if (this.format === N2K_ASCII) {
98
+ const ascii = actisenseToN2KAsciiFormat(msg)
86
99
  this.send(ascii + '\r\n')
87
100
  } else {
88
- let buf = actisenseToN2KActisenseFormat
101
+ const buf = actisenseToN2KActisenseFormat
89
102
  this.send(buf)
90
103
  }
91
104
  }
92
105
 
93
- require('util').inherits(W2K01Stream, Transform)
106
+ util.inherits(W2K01Stream, Transform)
94
107
 
95
- W2K01Stream.prototype._transform = function (chunk, encoding, done) {
96
- if ( !this.sentAvailable && this.format === N2K_ASCII ) {
108
+ W2K01Stream.prototype._transform = function (
109
+ chunk: any,
110
+ encoding: string,
111
+ done: any
112
+ ) {
113
+ if (!this.sentAvailable && this.format === N2K_ASCII) {
97
114
  debug('emit nmea2000OutAvailable')
98
115
  this.options.app.emit('nmea2000OutAvailable')
99
116
  this.sentAvailable = true
100
117
  }
101
118
 
102
- if ( this.format === N2K_ASCII ) {
103
- if ( debugData.enabled ) {
119
+ if (this.format === N2K_ASCII) {
120
+ if (debugData.enabled) {
104
121
  debugData('Received: ' + chunk)
105
122
  }
106
123
  this.push(chunk)
107
124
  } else {
108
- readN2KActisense(chunk, this.plainText, this, (data) => {
125
+ readN2KActisense(chunk, this.plainText, this, (data: any) => {
109
126
  this.push(data)
110
127
  })
111
128
  }
112
-
129
+
113
130
  done()
114
131
  }
115
132
 
116
- W2K01Stream.prototype.pipe = function (pipeTo) {
117
- if ( !pipeTo.fromPgn ) {
133
+ W2K01Stream.prototype.pipe = function (pipeTo: any) {
134
+ if (!pipeTo.fromPgn) {
118
135
  this.plainText = true
119
136
  } else {
120
137
  this.plainText = false
121
138
  }
122
- return W2K01Stream.super_.prototype.pipe.call(this, pipeTo)
123
- }
124
-
125
-
126
- W2K01Stream.prototype.end = function () {
139
+ return (W2K01Stream as any).super_.prototype.pipe.call(this, pipeTo)
127
140
  }
128
141
 
129
- module.exports = W2K01Stream
142
+ W2K01Stream.prototype.end = function () {}
@@ -14,33 +14,38 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { PGN } from '@canboat/ts-pgns'
18
+ import { N2kDevice } from './n2kDevice'
19
+ import { actisenseToYdgwFullRawFormat } from './toPgn'
20
+ import { createDebug } from './utilities'
17
21
 
18
- const debug = require('debug')('canboatjs:n2kdevice')
19
- const N2kDevice = require('./n2kDevice')
22
+ const debug = createDebug('canboatjs:n2kdevice')
20
23
 
21
- const { actisenseToYdgwFullRawFormat } = require('./toPgn')
24
+ export class YdDevice extends N2kDevice {
25
+ app: any
26
+ n2kOutEvent: string
22
27
 
23
- class YdDevice extends N2kDevice {
24
- constructor (options) {
28
+ constructor(options: any) {
25
29
  super(options)
26
30
  this.app = options.app
27
31
  this.n2kOutEvent = options.jsonOutEvent || 'nmea2000JsonOut'
28
-
32
+
29
33
  const analyzerOutEvent = options.analyzerOutEvent || 'N2KAnalyzerOut'
30
-
31
- this.app.on(options.analyzerOutEvent || 'N2KAnalyzerOut', this.n2kMessage.bind(this))
34
+
35
+ this.app.on(analyzerOutEvent, this.n2kMessage.bind(this))
32
36
  }
33
37
 
34
- sendPGN(pgn, src) {
38
+ sendPGN(pgn: PGN, src: number | undefined = undefined) {
35
39
  pgn.src = src || this.address
36
- pgn.ydFullFormat = true
40
+
41
+ const ppgn = pgn as any //FIXME??
42
+ ppgn.ydFullFormat = true
43
+
37
44
  debug('Sending PGN %j', pgn)
38
45
  this.app.emit(this.n2kOutEvent, pgn)
39
46
  }
40
47
 
41
- sendActisenseFormat(msg) {
48
+ sendActisenseFormat(msg: string) {
42
49
  this.app.emit('ydFullRawOut', actisenseToYdgwFullRawFormat(msg))
43
50
  }
44
51
  }
45
-
46
- module.exports = YdDevice