-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog_body.py
executable file
·176 lines (126 loc) · 6.38 KB
/
log_body.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
#!/usr/bin/env python3
import sys
#import pickle
import serial
import time
#import datetime
def readPacket(ser, readtime=1):
#looks for a 0x55 followed by a 0xaa to get synced, then expects 94 more bytes afterwards
#byte1 = ser.read(1)
#if(byte1 != bytes(b'\x55')):
#print("Not synced yet " + byte1.hex())
#return
#byte2 = ser.read(1)
#if(byte2 != bytes(b'\xaa')):
#print("Syncing... " + byte2.hex())
#return
packetbytes = ser.read(372)
if(len(packetbytes) < 372):
sys.exit(0)
while(packetbytes[6] != 0x75):
print("syncing... " + str(packetbytes[0:20]))
packetbytes = ser.read(373)
#packetbytes = bytes(b'\x55\xaa') + packetbytes
#should be 96 bytes in total
return packetbytes
def printpacket(pktbytes):
if pktbytes:
statusbytes = pktbytes[0:20]
cwbytes = pktbytes[20:47]
fftbytes = pktbytes[48:368]
checksumbytes = pktbytes[368:372]
for idx in range(len(statusbytes)):
print("{:>3} ".format(idx), end="")
print()
for idx in range(len(statusbytes)):
print(" {:02x}".format(pktbytes[idx]), end="")
print()
print("Checksum: " + hex(checksumbytes[0] + (checksumbytes[1]<<8) + (checksumbytes[2]<<16) + (checksumbytes[3]<<24)))
cwstring = cwbytes.decode()
if cwstring.isprintable():
print("CW bytes " + cwstring)
for idx in range(len(fftbytes)//2):
val = fftbytes[idx*2] #values are from 0-32, I think
charval = val//4 #map to 0-8 for unicode blocks
if charval == 0:
outchr = " "
else:
outchr = chr(0x2580 + charval)
print(outchr, end="")
#print("{:>2}".format(fftbytes[idx*2]), end="")
print()
print("Level: " + str(-(255-statusbytes[0])))
print("TX power: " + str( (statusbytes[1]) / 10 )) #watts
print("Battery: " + str( (statusbytes[3]) / 10 )) #volts
#4 and 5 somehow involved in tuning - maybe reflected power?
print("5/10: " + str( (statusbytes[5]) / 10 )) #watts
print("Tuning?: " + str(True if (statusbytes[11]&0x40) else False))
#print()
#print("Freq A: " + str(pktbytes[4] + (pktbytes[5]<<8) + (pktbytes[6]<<16) + (pktbytes[7]<<24)))
#print("Freq B: " + str(pktbytes[20] + (pktbytes[21]<<8) + (pktbytes[22]<<16) + (pktbytes[23]<<24)))
#print("Pre/ATT: " + str(pktbytes[8])) # none, pre, att
#print("Mode: " + str(pktbytes[9])) # lsb, USB, CW, CWR, NFM, AM
#print("AGC: " + str(pktbytes[10])) # AGC--, AGC-S, AGC-F, AGC-A
##when sweeping, filters go to 650 and 4800 hz
#print("Filter low : " + str(100 + (pktbytes[13]*25))) #audio filter cut-off in hz
#print("Filter high: " + str(125 + (pktbytes[12]*25))) #audio filter cut-off in hz
#print("FFT gain: " + str(pktbytes[19])) #1=auto, 2-10 direct
#print("Panel lock: " + str(True if (pktbytes[36]&0x01) else False))
#print("Split : " + str(True if (pktbytes[36]&0x02) else False))
#print("Output : " + str("headphones "if (pktbytes[36]&0x04) else "speaker"))
#print("Mic compression : " + str(True if (pktbytes[36]&0x08) else False))
#print("NB : " + str("on" if (pktbytes[36]&0x10) else "off"))
#print("Tuner enabled : " + str(True if (pktbytes[36]&0x20) else False))
#print("V/M : " + str("VFO" if (pktbytes[36]&0x40) else "MEM"))
#print("Transmiting: " + str(True if (pktbytes[36]&0x80) else False))
#print("Tuning: " + str(True if (pktbytes[37]&0x20) else False)) #also throws transmit high
#print("CW QSK : " + str(True if (pktbytes[38]&0x01) else False))
#print("TX disable? : " + str(False if (pktbytes[38]&0x02) else True)) #from being out of band?
#print("Audio Input : " + str("Line" if (pktbytes[38]&0x04) else "Mic"))
#print("VOX : " + str(True if (pktbytes[38]&0x08) else False))
#print("CW disp: " + str(True if (pktbytes[38]&0x10) else False))
#print("RCLK Tune: " + str(((pktbytes[38] + (pktbytes[39]<<8) ) >> 5 ) -1000)) #in setting menu, -1000 to 1000 hz
#print("VOC Gain: " + str(pktbytes[40] & 0x7F)) # 1-100
#print("VOC Anti-gain: " + str(((pktbytes[40] & 0x80) >> 7) + ((pktbytes[41] & 0x3F) << 1) )) # 1-100
#print("VOC Delay: " + str((((pktbytes[41] & 0xC0) >> 6) + ((pktbytes[42] & 0x07) << 2)) / 10.)) # 0-2 seconds.
#print("Gain: " + str( (pktbytes[42] + ((pktbytes[43] & 0x03) <<8)) >> 3 )) # in %
#print("Band stack: " + str("Full" if (pktbytes[43]&0x04) else "Ham")) #in setting menu
#print("Beep enable: " + str(True if (pktbytes[43]&0x08) else False)) #in setting menu
#print("RF Power: " + str(pktbytes[44])) # 1-20 watts
##power gets set to 7w when tuning
#print("NB level: " + str( ((pktbytes[46] & 0xF0) >> 4 )))
#print("NB width: " + str( (pktbytes[46] & 0x0F )))
#print("Sql level: " + str(pktbytes[45])) # 0-9
#print("Volume: " + str(pktbytes[48])) # 0-28
#print("Mic Gain: " + str(pktbytes[49])) # 0-20
#print("CW QSK time: " + str(pktbytes[51] * 100 )) #ms
#print("Mem CH: " + str(pktbytes[53])) #memory writes and clears don't appear to cross the bus though
#print("VFO : " + str("B" if (pktbytes[54]&0x01) else "A"))
#print("CW WPM: " + str(pktbytes[60])) # 5-50 wpm
#print("CW M/L/R: " + str( ((pktbytes[61] & 0x03) ))) # man, autio-l, auti-r
#print("CW Mode : " + str("B" if (pktbytes[61]&0x04) else "A"))
#print("CW Ratio: " + str( 2 + 0.1 * (pktbytes[61] >>4 ) ))
#print("SWR Threshold: " + str( ((pktbytes[82] & 0x0F ) * 0.2 ) + 1.8)) #0-9 maps to 1.8-3.6 for protection
##SWR threashold also gets set to 1.8 when sweeping
#print("Aux in vol: " + str( (pktbytes[83] & 0x0F ))) #0-15
#print("Aux out vol: " + str( (pktbytes[83] & 0xF0 ) >> 4)) #0-15
#ritval = (pktbytes[84] + ((pktbytes[85] & 0x03) <<8))
#if ritval > 500:
#ritval -= 1024
#print("RIT: " + str( ritval )) # 0-500
#print("Checksum: " + hex(pktbytes[92] + (pktbytes[93]<<8) + (pktbytes[94]<<16) + (pktbytes[95]<<24)))
#72 and 80 are used for reading the version somehow
def logFrom(ser):
iteration = 0
ser.timeout = 0.1
try:
while(1):
rxPacket = readPacket(ser,100)
if(rxPacket):
print("Got a packet: ")
printpacket(rxPacket)
print()
except KeyboardInterrupt:
print("got interrupt, exiting")
with serial.Serial(sys.argv[1], 115200, timeout=1) as ser:
logFrom(ser)