-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathacks.py
398 lines (331 loc) · 10.1 KB
/
acks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
from .utils import signed_int
# Errors messages
def motomed_error_values(error_code: int):
"""
Handles the Motomed errors
Parameters
----------
error_code: int
Motomed code error
Returns
-------
Returns the string corresponding to the information contain in the 'MotomedError' packet.
"""
if error_code == -1:
return "Transfer error"
elif error_code == -2:
return "Parameter error"
elif error_code == -3:
return "Wrong mode error"
elif error_code == -4:
return "Motomed connection error"
elif error_code == -7:
return "Motomed busy error"
elif error_code == -8:
return "Busy error"
else:
return f"Unknown error. Error code : {str(error_code)}"
def rehastim_error(error_code: int) -> str:
"""
Handles the Rehastim2 errors
Parameters
----------
error_code: int
Rehastim2 code error
Returns
-------
Returns the string corresponding to the information contain in the 'StimulationError' packet.
"""
if error_code == -1:
return "Emergency switch activated/not connected"
elif error_code == -2:
return "Electrode error"
elif error_code == -3:
return "Stimulation module error"
def stimulation_error(error_code: int) -> str:
"""
Parameters
----------
error_code: int
Rehastim2 code error
Returns
-------
Returns the string corresponding to the information contain in the 'StimulationError' packet.
"""
if error_code == -1:
return "Transfer error"
elif error_code == -2:
return "Parameter error"
elif error_code == -3:
return "Wrong mode error"
elif error_code == -8:
return " Busy error"
# Acks Motomed
def get_motomed_mode_ack(packet: (list, str)) -> str:
"""
Parameters
----------
packet: (list, str)
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'InitPhaseTrainingAck' packet.
"""
if packet[7] == 0:
if packet[8] == 0:
return "Start mode"
elif packet[8] == 1:
return "Phase training initialized"
elif packet[8] == 2:
return "Phase training started"
elif packet[8] == 3:
return "Phase training break"
elif packet[8] == 4:
return "Basic training started"
elif packet[8] == 5:
return "Basic training pause"
elif packet[8] == 6:
return "Motomed busy"
elif signed_int(packet[8:9]) == -1:
return "Motomed connection error"
elif signed_int(packet[7:8]) == -1:
return "Transfer error"
elif signed_int(packet[7:8]) == -8:
return "Busy error"
def init_phase_training_ack(packet: bytes) -> str:
"""
This function processes a packet received from the Motomed and returns a string
corresponding to the information contained in the 'InitPhaseTrainingAck' packet
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'InitPhaseTrainingAck' packet.
"""
if str(packet[7]) == "0":
return "Phase training initialized"
else:
return motomed_error_values(signed_int(packet[7:8]))
def start_phase_ack(packet: bytes) -> str:
"""
This function processes a packet received from the Motomed and returns a string
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
Else, returns the error message corresponding to the error code
"""
if str(packet[7]) == "0":
return "Start phase training / change phase sent to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def pause_phase_ack(packet: bytes) -> str:
"""
This function processes a packet received from the Motomed and returns a string
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
Else, returns the error message corresponding to the error code
"""
if str(packet[7]) == "0":
return "Start pause sent to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def stop_phase_training_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Stop phase training sent to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def set_rotation_direction_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Sent rotation direction to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def set_speed_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Sent speed to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def set_gear_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Set Gear to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def start_basic_training_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Sent start basic training to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def pause_basic_training_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Sent basic pause to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def continue_basic_training_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Sent continue basic training to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def stop_basic_training_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'StartPhaseAck' packet.
"""
if str(packet[7]) == "0":
return "Sent stop basic training to MOTOmed"
else:
return motomed_error_values(signed_int(packet[7:8]))
def motomed_error_ack(packet: int) -> str:
"""
This function processes a packet received from the Motomed and returns a string corresponding to the error code
Parameters
----------
packet: int
Packet received from the Motomed
Returns
-------
Returns the string corresponding to the information contain in the 'MotomedError' packet.
"""
if packet == -4:
return "Motomed connection error"
elif packet == -6:
return "Invalid Motomed trainer"
# Acks Stimulators
def get_mode_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Rehastim
Returns
-------
Returns the string corresponding to the information contain in the 'getModeAck' packet.
"""
if packet[7] == 0:
if packet[8] == 0:
return "Start Mode"
elif packet[8] == 1:
return "Stimulation initialized"
elif packet[8] == 2:
return "Stimulation started"
else:
return stimulation_error(signed_int(packet[7:8]))
def init_stimulation_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Rehastim
Returns
-------
Returns the string corresponding to the information contain in the 'InitChannelListModeAck' packet.
"""
if packet[7] == 0:
return "Stimulation initialized"
else:
return stimulation_error(signed_int(packet[7:8]))
def start_stimulation_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Rehastim
Returns
-------
Returns the string corresponding to the information contain in the 'StartChannelListModeAck' packet.
"""
if packet[7] == 0:
return "Stimulation started"
else:
return stimulation_error(signed_int(packet[7:8]))
def stop_stimulation_ack(packet: bytes) -> str:
"""
Parameters
----------
packet: bytes
Packet received from the Rehastim
Returns
-------
Returns the string corresponding to the information contain in the 'StopChannelListModeAck' packet.
"""
if packet[7] == 0:
return "Stimulation stopped"
else:
return stimulation_error(signed_int(packet[7:8]))