-
Notifications
You must be signed in to change notification settings - Fork 0
/
EEPROM_DMB_Test_FRAMEWORK_Revision.py
232 lines (206 loc) · 7.89 KB
/
EEPROM_DMB_Test_FRAMEWORK_Revision.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
from _typeshed import Self
import serial
import time
class AllDataStruct:
# Define a static variable
global size_bytes
size_bytes = 77 # TODO: This should have units (i.e. size_B or size_bytes) --Done
def __init__(self):
self.AGM_accelX = 0
self.AGM_accelY = 0
self.AGM_accelZ = 0
self.AGM_gyroX = 0
self.AGM_gyroY = 0
self.AGM_gyroZ = 0
self.AGM_magnetoX = 0
self.AGM_magnetoY = 0
self.AGM_magnetoZ = 0
self.BAR_pressure = 0
self.BAR_temperature = 0
self.CCP_pressure = 0
self.BAT_voltage = 0
self.GPS_latitude = 0
self.GPS_longitude = 0
self.GPS_altitude = 0
self.OTP_pressure = 0
self.PHS_phase = 0
self.HAL_tick = 0
self.SOF_version = 0
def __init__(self, binArray):
self.AGM_accelX = int(binArray[0:4])
self.AGM_accelY = int(binArray[4:8])
self.AGM_accelZ = int(binArray[8:12])
self.AGM_gyroX = int(binArray[12:16])
self.AGM_gyroY = int(binArray[16:20])
self.AGM_gyroZ = int(binArray[20:24])
self.AGM_magnetoX = int(binArray[24:28])
self.AGM_magnetoY = int(binArray[28:32])
self.AGM_magnetoZ = int(binArray[32:36])
self.BAR_pressure = int(binArray[36:40])
self.BAR_temperature = int(binArray[40:44])
self.CCP_pressure = int(binArray[44:48])
self.BAT_voltage = int(binArray[48:52])
self.GPS_latitude = int(binArray[52:56])
self.GPS_longitude = int(binArray[56:60])
self.GPS_altitude = int(binArray[60:64])
self.OTP_pressure = int(binArray[64:68])
self.PHS_phase = int(binArray[68:72])
self.HAL_tick = int(binArray[72:76])
self.SOF_version = int(binArray[76:77])
def __repr__(self):
# TODO: Format into multiple lines (F"...\n" F"...\n" F"...\n") --Done
return (F"AllData Object: \n"
F"AccelX: {self.AGM_accelX}\n"
F"AccelY: {self.AGM_accelY}\n"
F"AccelZ: {self.AGM_accelZ}\n"
F"GyroX: {self.AGM_gyroX}\n"
F"GyroY: {self.AGM_gyroY}\n"
F"GyroZ: {self.AGM_gyroZ}\n"
F"MagnetoX: {self.AGM_magnetoX}\n"
F"MagnetoY: {self.AGM_magnetoY}\n"
F"MagnetoZ: {self.AGM_magnetoZ}\n"
F"Bar Pressure: {self.BAR_pressure}\n"
F"Bar Temperature: {self.BAR_temperature}\n"
F"CCP Pressure: {self.CCP_pressure}\n"
F"BAT Voltage: {self.BAT_voltage}\n"
F"GPS Latitude: {self.GPS_latitude}\n"
F"GPS Longitude: {self.GPS_longitude}\n"
F"GPS Altitude: {self.GPS_altitude}\n"
F"OTP Pressure: {self.OTP_pressure}\n"
F"PHS Phase: {self.PHS_phase}\n"
F"HAL Tick: {self.HAL_tick}\n"
F"SOF Version: {self.SOF_version}...")
# TODO: Make "print_diff" method to cycle through __dict__ and check changes
def print_diff(self, actual):
for key in self.__dict__:
if self.__getattribute__(key) != actual.__getattribute__(key):
print(F"ATTR: Expected = {self}, "
F"Actual = {actual}")
"""
print_diff(self, actual):
for (key, _) in self.__dict__:
if self.getAttribute(key) != actual.getAttribute(key):
print("ATTR: Expected (self) = X, Actual (actual) = Y")
"""
# TODO: Replace with `return self.__dict__ == other.__dict` --Done
def __eq__(self, other):
# Decide if self == other
return self.__dict__ == other.__dict__
#
# Start of Functions
#
def writeAndReadTestData(ser):
# TODO: Change to check if open (Fail and return if not) --Done
"""This function will write an AllData struct to the EEPROM,
sends a 't' character over the UART connection.
Keyword Arguments:
ser - For serial connection to communicate.
"""
if(ser.isOpen() == True):
#Instantiate the All Data Struct members
adsExpected = AllDataStruct() # TODO: Maybe optimize this? Or maybe not
adsExpected.AGM_accelX = 1
adsExpected.AGM_accelY = 2
adsExpected.AGM_accelZ = 3
adsExpected.AGM_gyroX = 4
adsExpected.AGM_gyroY = 5
adsExpected.AGM_gyroZ = 6
adsExpected.AGM_magnetoX = 7
adsExpected.AGM_magnetoY = 8
adsExpected.AGM_magnetoZ = 9
adsExpected.BAR_pressure = 10
adsExpected.BAR_temperature = 11
adsExpected.CCP_pressure = 12
adsExpected.BAT_voltage = 13
adsExpected.GPS_latitude = 14
adsExpected.GPS_longitude = 15
adsExpected.GPS_altitude = 16
adsExpected.OTP_pressure = 17
adsExpected.PHS_phase = 18
adsExpected.HAL_tick = 19
adsExpected.SOF_version = 20
# Command flight board to run test
#The b' is the byte literal in Python
ser.write(b't')
else:
ser.open()
# TODO: Put remaining code in try/except IndexError to handle timeout https://www.w3schools.com/python/python_try_except.asp --Done
try:
# Read ADS from flight board
adsActual = AllDataStruct(ser.read(size_bytes))
# Compare
if (adsExpected == adsActual):
# Pass
print("All the expected and actual values were the same")
# TODO: Don't need this --Done
else:
# TODO: Else case `print(adsExpects.print_diff(adsActual))` --Done
print(adsExpected.print_diff(adsActual))
except IndexError:
print("An Index Error!")
def dumpCurrentData(ser):
#TODO: Docstrings! https://www.python.org/dev/peps/pep-0257/ Add these to all functions --Done
"""This function will dump the data onto the screen, sends
a 'd' to the flight board to achieve this feaature.
Also ensures that this will dump the most recent
AllData struct from the EEPROM.
Keyword Arguments:
ser - For serial connection to communicate.
"""
# TODO: Change to check if open (Fail and return if not) --Done
if(ser.isOpen() == True):
# TODO: This should just read and print, no need to compare --Done
# Command flight board to dump the data on the screen
#The b' is the byte literal in Python
ser.write(b'd')
# Read ADS from flight board
adsActual = AllDataStruct(ser.read(size_bytes))
print(adsActual)
else:
ser.open()
# TODO: Don't need to compare --Done
# TODO: Doesn't need ser--Done
def printHelp():
"""This function will print the list of commands in a
mannerly form when the user sends a 'h' to ensure this
is displayed.
Keyword Arguments:
None
"""
# TODO: format into one print statement --Done
print("Commands:")
print(" t - Write and read a test value\n"
" d - Dump most recent value\n"
" h - Print help\n"
" q - Quit\n")
#CLosing serial port function
# TODO: Does need ser -- Done
def quit(ser): # TODO: Probably name "quit", and handle ALL cleanup, then exit --Done
"""This function will close the communication between the serial
port when the user sends a 'q'.
Keyword Arguments:
ser - For serial connection to communicate.
"""
ser.close()
print("The serial port is now closed")
exit()
# TODO: exit()--Done
#
# Main
#
# TODO: Make "if main" check up here, and make sure all remaining "main" code is tabbed into it --Done
if __name__ == "__main__":
# TODO: Better command names? Help should be h --Done
commandDictionary = {'t': writeAndReadTestData, 'd': dumpCurrentData, 'h': printHelp, 'q': quit}
ser = None
print("SOAR EEPROM Test Shell")
port = input('Enter a Serial Port to connect to: ') # Linux: /dev/ttyUSBx, Windows: COMx
ser = serial.Serial(port, 9600, timeout=1) # TODO: Set timeout to 1 --Done
ser.open()
while True:
command = input("> ")
if command in commandDictionary.keys():
commandDictionary[command](ser)
else:
print("Command not found!")
printHelp()