@@ -4,10 +4,12 @@ const assert = require("assert").strict;
4
4
5
5
let devices = [ ] ;
6
6
7
+ const canBridge = new addon . CanBridge ( ) ;
8
+
7
9
async function testGetDevices ( ) {
8
- assert ( addon . getDevices , "getDevices is undefined" ) ;
10
+ assert ( canBridge . getDevices , "getDevices is undefined" ) ;
9
11
try {
10
- devices = await addon . getDevices ( ) ;
12
+ devices = await canBridge . getDevices ( ) ;
11
13
console . log ( devices ) ;
12
14
console . log ( `Found ${ devices . length } device(s)` ) ;
13
15
devices . forEach ( ( device ) => {
@@ -23,19 +25,19 @@ async function testGetDevices() {
23
25
24
26
async function testConcurrentGetDevices ( ) {
25
27
try {
26
- await Promise . all ( [ addon . getDevices ( ) , addon . getDevices ( ) , addon . getDevices ( ) ,
27
- addon . getDevices ( ) , addon . getDevices ( ) , addon . getDevices ( ) ] ) ;
28
+ await Promise . all ( [ canBridge . getDevices ( ) , canBridge . getDevices ( ) , canBridge . getDevices ( ) ,
29
+ canBridge . getDevices ( ) , canBridge . getDevices ( ) , canBridge . getDevices ( ) ] ) ;
28
30
} catch ( error ) {
29
31
assert . fail ( error . toString ( ) ) ;
30
32
}
31
33
}
32
34
33
35
async function testRegisterDeviceToHAL ( ) {
34
- assert ( addon . registerDeviceToHAL , "registerDeviceToHAL is undefined" ) ;
36
+ assert ( canBridge . registerDeviceToHAL , "registerDeviceToHAL is undefined" ) ;
35
37
try {
36
38
if ( devices . length > 0 ) {
37
39
console . log ( `Registering device ${ devices [ 0 ] . descriptor } to HAL` ) ;
38
- const status = addon . registerDeviceToHAL ( devices [ 0 ] . descriptor , 0 , 0 ) ;
40
+ const status = canBridge . registerDeviceToHAL ( devices [ 0 ] . descriptor , 0 , 0 ) ;
39
41
console . log ( `Device registered with status code ${ status } ` ) ;
40
42
assert . equal ( status , 0 , "Registering device failed" ) ;
41
43
}
@@ -46,12 +48,12 @@ async function testRegisterDeviceToHAL() {
46
48
}
47
49
48
50
async function testUnregisterDeviceFromHAL ( ) {
49
- assert ( addon . unregisterDeviceFromHAL , "unregisterDeviceFromHAL is undefined" ) ;
51
+ assert ( canBridge . unregisterDeviceFromHAL , "unregisterDeviceFromHAL is undefined" ) ;
50
52
51
53
try {
52
54
if ( devices . length > 0 ) {
53
55
console . log ( `Unregistering device ${ devices [ 0 ] . descriptor } from HAL` ) ;
54
- const status = await addon . unregisterDeviceFromHAL ( devices [ 0 ] . descriptor ) ;
56
+ const status = await canBridge . unregisterDeviceFromHAL ( devices [ 0 ] . descriptor ) ;
55
57
console . log ( `Device unregistered with status code ${ status } ` ) ;
56
58
assert . equal ( status , 0 , "unregisterDeviceFromHAL device failed" ) ;
57
59
}
@@ -61,22 +63,22 @@ async function testUnregisterDeviceFromHAL() {
61
63
}
62
64
63
65
async function testReceiveMessage ( ) {
64
- assert ( addon . receiveMessage , "receiveMessage is undefined" ) ;
66
+ assert ( canBridge . receiveMessage , "receiveMessage is undefined" ) ;
65
67
try {
66
68
if ( devices . length === 0 ) return ;
67
69
await new Promise ( resolve => { setTimeout ( resolve , 200 ) } ) ;
68
- const message = addon . receiveMessage ( devices [ 0 ] . descriptor , 0 , 0 ) ;
70
+ const message = canBridge . receiveMessage ( devices [ 0 ] . descriptor , 0 , 0 ) ;
69
71
console . log ( "Got message" , message ) ;
70
72
} catch ( error ) {
71
73
assert . fail ( error ) ;
72
74
}
73
75
}
74
76
75
77
async function testOpenStreamSession ( ) {
76
- assert ( addon . openStreamSession , "openStreamSession is undefined" ) ;
78
+ assert ( canBridge . openStreamSession , "openStreamSession is undefined" ) ;
77
79
try {
78
80
if ( devices . length === 0 ) return ;
79
- const sessionHandle = addon . openStreamSession ( devices [ 0 ] . descriptor , 0 , 0 , 4 ) ;
81
+ const sessionHandle = canBridge . openStreamSession ( devices [ 0 ] . descriptor , 0 , 0 , 4 ) ;
80
82
console . log ( "Started stream session with handle" , sessionHandle ) ;
81
83
return sessionHandle ;
82
84
} catch ( error ) {
@@ -85,11 +87,11 @@ async function testOpenStreamSession() {
85
87
}
86
88
87
89
async function testReadStreamSession ( sessionHandle ) {
88
- assert ( addon . readStreamSession , "readStreamSession is undefined" ) ;
90
+ assert ( canBridge . readStreamSession , "readStreamSession is undefined" ) ;
89
91
if ( devices . length === 0 ) return ;
90
92
try {
91
93
await new Promise ( resolve => { setTimeout ( resolve , 200 ) } ) ;
92
- const data = addon . readStreamSession ( devices [ 0 ] . descriptor , sessionHandle , 4 ) ;
94
+ const data = canBridge . readStreamSession ( devices [ 0 ] . descriptor , sessionHandle , 4 ) ;
93
95
console . log ( "Got stream:" , data ) ;
94
96
return sessionHandle ;
95
97
} catch ( error ) {
@@ -98,45 +100,45 @@ async function testReadStreamSession(sessionHandle) {
98
100
}
99
101
100
102
async function testCloseStreamSession ( sessionHandle ) {
101
- assert ( addon . closeStreamSession , "closeStreamSession is undefined" ) ;
103
+ assert ( canBridge . closeStreamSession , "closeStreamSession is undefined" ) ;
102
104
try {
103
105
if ( devices . length === 0 ) return ;
104
- const status = addon . closeStreamSession ( devices [ 0 ] . descriptor , sessionHandle ) ;
106
+ const status = canBridge . closeStreamSession ( devices [ 0 ] . descriptor , sessionHandle ) ;
105
107
assert . equal ( status , 0 , "Closing stream failed" ) ;
106
108
} catch ( error ) {
107
109
assert . fail ( error ) ;
108
110
}
109
111
}
110
112
111
113
async function testGetCANDetailStatus ( ) {
112
- assert ( addon . getCANDetailStatus , "getCANDetailStatus is undefined" ) ;
114
+ assert ( canBridge . getCANDetailStatus , "getCANDetailStatus is undefined" ) ;
113
115
try {
114
116
if ( devices . length === 0 ) return ;
115
- const status = addon . getCANDetailStatus ( devices [ 0 ] . descriptor ) ;
117
+ const status = canBridge . getCANDetailStatus ( devices [ 0 ] . descriptor ) ;
116
118
console . log ( "CAN Status:" , status ) ;
117
119
} catch ( error ) {
118
120
assert . fail ( error ) ;
119
121
}
120
122
}
121
123
122
124
async function testSendCANMessage ( ) {
123
- assert ( addon . sendCANMessage , "sendCANMessage is undefined" ) ;
125
+ assert ( canBridge . sendCANMessage , "sendCANMessage is undefined" ) ;
124
126
try {
125
127
if ( devices . length === 0 ) return ;
126
128
// Send identify to SparkMax #1
127
- const status = addon . sendCANMessage ( devices [ 0 ] . descriptor , 0x2051D81 , [ ] , 0 ) ;
129
+ const status = canBridge . sendCANMessage ( devices [ 0 ] . descriptor , 0x2051D81 , [ ] , 0 ) ;
128
130
console . log ( "CAN Status:" , status ) ;
129
131
} catch ( error ) {
130
132
assert . fail ( error ) ;
131
133
}
132
134
}
133
135
134
136
async function testSendHALMessage ( ) {
135
- assert ( addon . sendCANMessage , "sendCANMessage is undefined" ) ;
137
+ assert ( canBridge . sendCANMessage , "sendCANMessage is undefined" ) ;
136
138
try {
137
139
if ( devices . length === 0 ) return ;
138
140
// Send identify to SparkMax #1
139
- const status = addon . sendHALMessage ( 0x2051D81 , [ ] , 500 ) ;
141
+ const status = canBridge . sendHALMessage ( 0x2051D81 , [ ] , 500 ) ;
140
142
await new Promise ( resolve => { setTimeout ( resolve , 2000 ) } ) ;
141
143
console . log ( "Status:" , status ) ;
142
144
} catch ( error ) {
@@ -145,18 +147,18 @@ async function testSendHALMessage() {
145
147
}
146
148
147
149
async function testSetThreadPriority ( ) {
148
- assert ( addon . setThreadPriority , "setThreadPriority is undefined" ) ;
150
+ assert ( canBridge . setThreadPriority , "setThreadPriority is undefined" ) ;
149
151
try {
150
152
if ( devices . length === 0 ) return ;
151
- addon . setThreadPriority ( devices [ 0 ] . descriptor , 4 ) ;
153
+ canBridge . setThreadPriority ( devices [ 0 ] . descriptor , 4 ) ;
152
154
} catch ( error ) {
153
155
assert . fail ( error ) ;
154
156
}
155
157
}
156
158
157
159
function testInitializeNotifier ( ) {
158
160
try {
159
- addon . initializeNotifier ( ) ;
161
+ canBridge . initializeNotifier ( ) ;
160
162
} catch ( error ) {
161
163
assert . fail ( error ) ;
162
164
}
@@ -165,7 +167,7 @@ function testInitializeNotifier() {
165
167
async function testWaitForNotifierAlarm ( ) {
166
168
try {
167
169
const start = Date . now ( ) ;
168
- await addon . waitForNotifierAlarm ( 1000 ) ;
170
+ await canBridge . waitForNotifierAlarm ( 1000 ) ;
169
171
console . log ( "Time passed:" , Date . now ( ) - start ) ;
170
172
} catch ( error ) {
171
173
assert . fail ( error ) ;
@@ -174,15 +176,15 @@ async function testWaitForNotifierAlarm() {
174
176
175
177
function testStopNotifier ( ) {
176
178
try {
177
- addon . stopNotifier ( ) ;
179
+ canBridge . stopNotifier ( ) ;
178
180
} catch ( error ) {
179
181
assert . fail ( error ) ;
180
182
}
181
183
}
182
184
183
185
async function testOpenHALStreamSession ( ) {
184
186
try {
185
- const handle = addon . openHALStreamSession ( 0 , 0 , 8 ) ;
187
+ const handle = canBridge . openHALStreamSession ( 0 , 0 , 8 ) ;
186
188
return handle ;
187
189
} catch ( error ) {
188
190
assert . fail ( error ) ;
@@ -192,7 +194,7 @@ async function testOpenHALStreamSession() {
192
194
async function testReadHALStreamSession ( handle ) {
193
195
try {
194
196
await new Promise ( resolve => { setTimeout ( resolve , 200 ) } ) ;
195
- const data = addon . readHALStreamSession ( handle , 8 ) ;
197
+ const data = canBridge . readHALStreamSession ( handle , 8 ) ;
196
198
console . log ( "Got stream from HAL:" , data ) ;
197
199
return handle ;
198
200
} catch ( error ) {
@@ -202,7 +204,7 @@ async function testReadHALStreamSession(handle) {
202
204
203
205
async function testCloseHALStreamSession ( handle ) {
204
206
try {
205
- addon . closeHALStreamSession ( handle ) ;
207
+ canBridge . closeHALStreamSession ( handle ) ;
206
208
console . log ( "Closed HAL stream" ) ;
207
209
} catch ( error ) {
208
210
assert . fail ( error ) ;
@@ -212,13 +214,13 @@ async function testCloseHALStreamSession(handle) {
212
214
async function testHeartbeat ( ) {
213
215
try {
214
216
if ( devices . length === 0 ) return ;
215
- await addon . sendCANMessage ( devices [ 0 ] . descriptor , 33882241 , [ 10 , 215 , 163 , 60 , 0 , 0 , 0 , 0 ] , 0 ) ;
216
- await addon . setSparkMaxHeartbeatData ( devices [ 0 ] . descriptor , Array ( 8 ) . fill ( 0xFF ) ) ;
217
- const interval = setInterval ( addon . ackSparkMaxHeartbeat , 900 ) ;
217
+ await canBridge . sendCANMessage ( devices [ 0 ] . descriptor , 33882241 , [ 10 , 215 , 163 , 60 , 0 , 0 , 0 , 0 ] , 0 ) ;
218
+ await canBridge . setSparkMaxHeartbeatData ( devices [ 0 ] . descriptor , Array ( 8 ) . fill ( 0xFF ) ) ;
219
+ const interval = setInterval ( canBridge . ackSparkMaxHeartbeat , 900 ) ;
218
220
await new Promise ( resolve => { setTimeout ( resolve , 6000 ) } ) ;
219
221
clearInterval ( interval ) ;
220
222
console . log ( "STOPPING" ) ;
221
- await addon . setSparkMaxHeartbeatData ( devices [ 0 ] . descriptor , Array ( 8 ) . fill ( 0x00 ) ) ;
223
+ await canBridge . setSparkMaxHeartbeatData ( devices [ 0 ] . descriptor , Array ( 8 ) . fill ( 0x00 ) ) ;
222
224
await new Promise ( resolve => { setTimeout ( resolve , 2000 ) } ) ;
223
225
} catch ( error ) {
224
226
assert . fail ( error ) ;
0 commit comments