forked from KristianJerpetjon/nke-topline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·63 lines (53 loc) · 1.41 KB
/
main.py
File metadata and controls
executable file
·63 lines (53 loc) · 1.41 KB
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
#!/usr/bin/env python
import serial
import datetime
import time
import binascii
import numpy as np
from topline import ToplineDecoder
#ms = time.time_ns() // 1_000_000
ser = serial.Serial(
port="/dev/ttyUSB3",
baudrate=9600,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
timeout=60)
#ser2 = serial.Serial(
# port="/dev/ttyUSB1",
# baudrate=9600,
# bytesize=serial.EIGHTBITS,
# stopbits=serial.STOPBITS_ONE,
# parity=serial.PARITY_NONE,
# timeout=60)
prev1='00'
prev2='00'
last_ms=time.time_ns() // 1_000_000
commands={
"19": "Compass",
"73": "Trim",
"2b": "Heal",
}
def hex_to_float16(a_hex_str):
a_hex_byte = bytes.fromhex(a_hex_str)
print("A hex_string ",a_hex_str)
a_int16 = struct.unpack('>H', h_hex_byte) # sometimes you need h_hex_byte[::-1] because of big/little endian
a_np_int16 = np.int16(a_int16)
return a_np_int16.view(np.float16)
tp=ToplineDecoder()
with open("dump_remote_handler.hex","w") as file:
while True:
c=ser.read()
if len(c) == 0:
break
tp.recieve(c)
file.write(str(c.hex()))
exit
with open("dump.bin","rb") as file:
while True:
c=file.read(1)
if len(c)==0:
break
tp.recieve(c)
#print(prev2.hex()+prev1.hex()+b.hex())
#print(b.hex()+" " + b.decode("utf-8",errors="replace"),)