-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfd.py
187 lines (167 loc) · 6.76 KB
/
rfd.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
"""
South Side Hackerspace: Chicago
Based on code from RFD900 Balloon Telemetry Senior Capstone Final Project Report(Madison Martinsen, Annie Bachman, Michael Valentino-Manno)
"""
import tkinter as tk
import serial
import time
import csv
packet_count = 0
succ = 0
Decoded_Raw_Data = []
Final_Data = []
# Degree Symbol for GUI
degree_sign = u"\N{DEGREE SIGN}"
fix_sources = {
0: "No Fix",
1: "Dead Reckoning",
2: "2D",
3: "3D",
4: "GNSS + Dead Reckoning",
}
# CSV HEADERS
header = ["Packet Number", "SIV", "FixType", "Latitude", \
"Longitude", "Altitude", "Year", "Month", "Day", \
"Hour", "Min", "Sec", "NNV", "NEV", "NDV", "Battery" ,\
"3v3 Supply", "5v Supply", "Radio Supply", "Analog Internal", \
"Analog External", "Altimeter Temp", "Digital Internal", \
"Digital Eternal", "Pressure", "Accel A", "Accel Y", "Accel z", \
"Pitch", "Roll", "Yaw"]
def Label_Update(serial_port):
packet=lat=lon=0
siv=fix=alt=year=month=day=hour=minute=sec=nedN=nedE=nedD=bat=bat33=bat51=bat52=aint=aext=ptemp=dint=dent=pres=ax=ay=az=pitch=roll=yaw=fixType=string_csv_data=""
serial_port.reset_input_buffer()
source_data = serial_port.readline()
global packet_count
global succ
global Decoded_Raw_Data
global Final_Data
# CSV
Decoded_Raw_Data = source_data.decode("utf-8")
Final_Data = Decoded_Raw_Data.split(",")
string_csv_data = str(Decoded_Raw_Data).split(",")
# write a new line in the csv if there is data
if len(Final_Data) > 10:
with open(fileName, "a", newline = '\n') as f:
csv.writer(f, delimiter=',').writerow(Final_Data)
packet_count += 1
# Save radio data
if len(string_csv_data) >= 31:
try:
packet = int(string_csv_data[0].strip())
except ValueError as ve:
print("Invalid packet number: " + string_csv_data[0])
packet = 1
siv = string_csv_data[1].strip()
fix = string_csv_data[2].strip()
lat = float(string_csv_data[3].strip())
lat = lat * .0000001
lon = float(string_csv_data[4].strip())
lon = lon * .0000001
alt = float(string_csv_data[5].strip())
alt = alt / 1000
year = string_csv_data[6].strip()
month = string_csv_data[7].strip()
day = string_csv_data[8].strip()
hour = string_csv_data[9].strip()
minute = string_csv_data[10].strip()
sec = string_csv_data[11].strip()
nedN = string_csv_data[12].strip()
nedE = string_csv_data[13].strip()
nedD = string_csv_data[14].strip()
bat = string_csv_data[15].strip()
bat33 = string_csv_data[16].strip()
bat51 = string_csv_data[17].strip()
bat52 = string_csv_data[18].strip()
aint = string_csv_data[19].strip()
aext = string_csv_data[20].strip()
ptemp = string_csv_data[21].strip()
dint = string_csv_data[22].strip()
dent = string_csv_data[23].strip()
pres = string_csv_data[24].strip()
ax = string_csv_data[25].strip()
ay = string_csv_data[26].strip()
az = string_csv_data[27].strip()
pitch = string_csv_data[28].strip()
roll = string_csv_data[29].strip()
yaw = string_csv_data[30].strip()
if succ == 0:
succ=packet
if fix != "" and int(fix) in (fix_sources.keys()):
fixType = fix_sources[int(fix)]
else:
if fix != "":
print("Invalid fix: " + fix)
fixType = "No/Invalid Fix Data"
packet = 1 #
lat = 0#
lon = 0#
siv=fix=alt=year=month=day=hour=minute=sec=nedN=nedE=nedD=bat=bat33=bat51=bat52=aint=aext=ptemp=dint=dent=pres=ax=ay=az=pitch=roll=yaw=""
Title = tk.Label(root, font = ("Helvetica", "30"))
Title.grid(row=0,column=0,padx=(0, 0), pady=(0,0))
Title.config(text=('MSGC RDF900x'))
# Col 0
Data1 = tk.Label(root, font = ("Helvetica", "22"))
Data1.grid(row=1,column=0,padx=(5, 15), pady=(0,0))
Data1.config(text=(
'Current Packet #' + str(packet) + "\n" +
'Packets Received: ' + str(packet_count)+ "/" + str(packet-succ+1) + ", " + \
str(round(((packet_count/(packet-succ+1))*100),2))+ "%\n" +
'Date: ' + year + "-" + month +"-" + day + "\n" +
'Time: ' + hour + ":" + minute +":" + sec + "\n\n\n" +
'Battery Voltage: ' + str(bat) + " V\n" +
'3.3 Voltage: ' + str(bat33) + " V\n" +
'5.0 Voltage: ' + str(bat51) + " V\n" +
'Radio Voltage: ' + str(bat52) + " V\n\n\n" +
'Analog Internal Temperature: ' + str(aint)+ degree_sign + "C\n" +
'Analog External Temperature: ' + str(aext) + degree_sign + "C\n" +
'Digital Internal Temperature: ' + str(dint) + degree_sign + "C\n" +
'Digital External Temperature: ' + str(dent) + degree_sign + "C\n" +
'Pressure Sensor Temperature: ' + str(ptemp) + degree_sign + "C\n")
)
# Col 1
xxxx = str(siv)
Data2 = tk.Label(root, font = ("Helvetica", "22"))
Data2.grid(row=1,column=1,padx=(5, 5), pady=(0,0))
Data2.config(text=(
'Satellites In View: ' + str(siv) + "\n" +
'Fix Type: ' + fixType + " (" + str(fix) + ")" + "\n" +
'Latitude: ' + str(round(float(lat), 6)) + "\n" +
'Longitude: ' + str(round(float(lon), 6)) + "\n" +
'Altitude: ' + str(alt) + " m\n" +
'Pressure: ' + str(pres) + " mbar\n\n" +
'NedNorthVel: ' + str(nedN) + " mm/s\n" +
'NedEastVel: ' + str(nedE) + " mm/s\n" +
'NedDownVel: ' + str(nedD) + " mm/s\n\n" +
'Acceleration X: ' + str(ax)+ " m/s\u00b2 \n" +
'Acceleration Y: ' + str(ay)+ " m/s\u00b2 \n" +
'Acceleration Z: ' + str(az)+ " m/s\u00b2 \n" +
'Pitch: ' + str(pitch)+ degree_sign + "\n" +
'Roll: ' + str(roll)+ degree_sign + "\n" +
'Yaw: ' + str(yaw)+ degree_sign + ""
))
##################################################################
# User enter serial port
while True:
# Open Serial Port, if it doesn't work, reprompt user
try:
serial_port = serial.Serial( port = "/dev/cu.usbserial-AB0JNQSY", baudrate = 57600, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, timeout = 1 )
break
except IOError:
print("Device not found in specified COM port. Please try again.\n")
root = tk.Tk()
root.title("MSGC RFD900x")
blank = []
fileName = "RFD900x_Data.csv"
file = open(fileName, "a")
file.close()
with open(fileName, "a", newline = '\n') as f:
writer = csv.writer(f, delimiter=',')
writer.writerow(header)
print(fileName + " created to hold data. If file exists, data will be appended\n")
# MSGC LOGO
while True:
Label_Update(serial_port)
time.sleep(0.5)
root.update_idletasks()
root.update()