diff --git a/BaseStation/Backend/db.sqlite3 b/BaseStation/Backend/db.sqlite3 index ce3aaeb2..91c4d07b 100644 Binary files a/BaseStation/Backend/db.sqlite3 and b/BaseStation/Backend/db.sqlite3 differ diff --git a/BaseStation/Backend/podconnect/migrations/0010_connecteddata.py b/BaseStation/Backend/podconnect/migrations/0010_connecteddata.py new file mode 100644 index 00000000..2defdd5b --- /dev/null +++ b/BaseStation/Backend/podconnect/migrations/0010_connecteddata.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.3 on 2019-07-20 17:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('podconnect', '0009_auto_20190718_0022'), + ] + + operations = [ + migrations.CreateModel( + name='ConnectedData', + fields=[ + ('date_time', models.DateTimeField(auto_now=True, primary_key=True, serialize=False)), + ('tcp_connected', models.IntegerField(default=0)), + ('udp_connected', models.IntegerField(default=0)), + ], + ), + ] diff --git a/BaseStation/Backend/podconnect/models.py b/BaseStation/Backend/podconnect/models.py index a7bfafa1..6b29415a 100644 --- a/BaseStation/Backend/podconnect/models.py +++ b/BaseStation/Backend/podconnect/models.py @@ -2,6 +2,11 @@ # Create your models here. +class ConnectedData(models.Model): + date_time = models.DateTimeField(auto_now=True,primary_key=True) + tcp_connected = models.IntegerField(default=0) + udp_connected = models.IntegerField(default=0) + class MotionData(models.Model): date_time = models.DateTimeField(auto_now=True,primary_key=True) position = models.IntegerField(default=0) diff --git a/BaseStation/Backend/podconnect/stats_helper.py b/BaseStation/Backend/podconnect/stats_helper.py index 460e965b..760499fc 100644 --- a/BaseStation/Backend/podconnect/stats_helper.py +++ b/BaseStation/Backend/podconnect/stats_helper.py @@ -8,6 +8,7 @@ def getStats(): pru_data = models.PRUData.objects.latest("date_time") motion_data = models.MotionData.objects.latest("date_time") adc_data = models.ADCData.objects.latest("date_time") + connected_data = models.ConnectedData.objects.latest("date_time") ranges = getRanges() can_data_motor = { @@ -20,6 +21,94 @@ def getStats(): "high": ranges["State_Number"][1], "units":ranges["State_Number"][2] }, + { + "name": "TCP_On", + "value": str(connected_data.tcp_connected), + "color": getColor(ranges["TCP_On"], connected_data.tcp_connected), + "low": ranges["TCP_On"][0], + "high": ranges["TCP_On"][1], + "units":ranges["TCP_On"][2] + }, + { + "name": "Watchdog", + "value": str(connected_data.tcp_connected), + "color": "linmegreen", + "low": 1, + "high": 1, + "units":"N/A" + }, + { + "name": "Wheel Distance", + "value": str(pru_data.wheel_distance), + "color": getColor(ranges["Wheel Distance"], pru_data.wheel_distance), + "low": ranges["Wheel Distance"][0], + "high": ranges["Wheel Distance"][1], + "units":ranges["Wheel Distance"][2] + }, + { + "name": "Wheel Velocity", + "value": str(pru_data.wheel_velocity), + "color": getColor(ranges["Wheel Velocity"], pru_data.wheel_velocity), + "low": ranges["Wheel Velocity"][0], + "high": ranges["Wheel Velocity"][1], + "units":ranges["Wheel Velocity"][2] + }, + { + "name": "Acceleration", + "value": str(motion_data.acceleration), + "color": getColor(ranges["Acceleration"], motion_data.acceleration), + "low": ranges["Acceleration"][0], + "high": ranges["Acceleration"][1], + "units":ranges["Acceleration"][2] + }, + { + "name": "Motor_State", + "value": str(motion_data.motor_state), + "color": getColor(ranges["Motor_State"], motion_data.motor_state), + "low": ranges["Motor_State"][0], + "high": ranges["Motor_State"][1], + "units":ranges["Motor_State"][2] + }, + { + "name": "Brake_State", + "value": str(motion_data.brake_state), + "color": getColor(ranges["Brake_State"], motion_data.brake_state), + "low": ranges["Brake_State"][0], + "high": ranges["Brake_State"][1], + "units":ranges["Brake_State"][2] + }, + { + "name": "Motor_Target_Torque", + "value": str(motion_data.motor_target_torque), + "color": getColor(ranges["Motor_Target_Torque"], motion_data.motor_target_torque), + "low": ranges["Motor_Target_Torque"][0], + "high": ranges["Motor_Target_Torque"][1], + "units":ranges["Motor_Target_Torque"][2] + }, + { + "name": "Pre-Charge Relay Status", + "value": motion_data.relay_state_buff_0, + "color": getColor(ranges["Pre-Charge Relay Status"], motion_data.relay_state_buff_0), + "low": ranges["Pre-Charge Relay Status"][0], + "high": ranges["Pre-Charge Relay Status"][1], + "units":ranges["Pre-Charge Relay Status"][2] + }, + { + "name": "LV Relay Status", + "value": motion_data.relay_state_buff_1, + "color": getColor(ranges["LV Relay Status"], motion_data.relay_state_buff_1), + "low": ranges["LV Relay Status"][0], + "high": ranges["LV Relay Status"][1], + "units":ranges["LV Relay Status"][2] + }, + { + "name": "HV Relay Status", + "value": motion_data.relay_state_buff_2, + "color": getColor(ranges["HV Relay Status"], motion_data.relay_state_buff_2), + "low": ranges["HV Relay Status"][0], + "high": ranges["HV Relay Status"][1], + "units":ranges["HV Relay Status"][2] + }, { "name": "Status_Word", "value": str(hex(can_data.status_word)), @@ -115,54 +204,6 @@ def getStats(): "low": ranges["Phase_B_Current"][0], "high": ranges["Phase_B_Current"][1], "units":ranges["Phase_B_Current"][2] - }, - { - "name": "Accel_1 x", - "value": str(adc_data.data_5), - "color": getColor(ranges["Accel_1 x"], adc_data.data_5), - "low": ranges["Accel_1 x"][0], - "high": ranges["Accel_1 x"][1], - "units":ranges["Accel_1 x"][2] - }, - { - "name": "Accel_1 y", - "value": str(adc_data.data_6), - "color": getColor(ranges["Accel_1 y"], adc_data.data_6), - "low": ranges["Accel_1 y"][0], - "high": ranges["Accel_1 y"][1], - "units":ranges["Accel_1 y"][2] - }, - { - "name": "Accel_1 z", - "value": str(adc_data.data_4), - "color": getColor(ranges["Accel_1 z"], adc_data.data_4), - "low": ranges["Accel_1 z"][0], - "high": ranges["Accel_1 z"][1], - "units":ranges["Accel_1 z"][2] - }, - { - "name": "Accel_2 x", - "value": str(adc_data.data_1), - "color": getColor(ranges["Accel_2 x"], adc_data.data_1), - "low": ranges["Accel_2 x"][0], - "high": ranges["Accel_2 x"][1], - "units":ranges["Accel_2 x"][2] - }, - { - "name": "Accel_2 y", - "value": str(adc_data.data_3), - "color": getColor(ranges["Accel_2 y"], adc_data.data_3), - "low": ranges["Accel_2 y"][0], - "high": ranges["Accel_2 y"][1], - "units":ranges["Accel_2 y"][2] - }, - { - "name": "Accel_2 z", - "value": str(adc_data.data_2), - "color": getColor(ranges["Accel_2 z"], adc_data.data_2), - "low": ranges["Accel_2 z"][0], - "high": ranges["Accel_2 z"][1], - "units":ranges["Accel_2 z"][2] } ] } @@ -281,60 +322,60 @@ def getStats(): "units":ranges["Max_Pack_DCL"][2] }, { - "name": "Motor_State", - "value": str(motion_data.motor_state), - "color": getColor(ranges["Motor_State"], motion_data.motor_state), - "low": ranges["Motor_State"][0], - "high": ranges["Motor_State"][1], - "units":ranges["Motor_State"][2] + "name": "Relay State Buff 3", + "value": motion_data.relay_state_buff_3, + "color": getColor(ranges["Relay State Buff 3"], motion_data.relay_state_buff_3), + "low": ranges["Relay State Buff 3"][0], + "high": ranges["Relay State Buff 3"][1], + "units":ranges["Relay State Buff 3"][2] }, { - "name": "Brake_State", - "value": str(motion_data.brake_state), - "color": getColor(ranges["Brake_State"], motion_data.brake_state), - "low": ranges["Brake_State"][0], - "high": ranges["Brake_State"][1], - "units":ranges["Brake_State"][2] + "name": "Accel_1 x", + "value": str(adc_data.data_5), + "color": getColor(ranges["Accel_1 x"], adc_data.data_5), + "low": ranges["Accel_1 x"][0], + "high": ranges["Accel_1 x"][1], + "units":ranges["Accel_1 x"][2] }, { - "name": "Motor_Target_Torque", - "value": str(motion_data.motor_target_torque), - "color": getColor(ranges["Motor_Target_Torque"], motion_data.motor_target_torque), - "low": ranges["Motor_Target_Torque"][0], - "high": ranges["Motor_Target_Torque"][1], - "units":ranges["Motor_Target_Torque"][2] + "name": "Accel_1 y", + "value": str(adc_data.data_6), + "color": getColor(ranges["Accel_1 y"], adc_data.data_6), + "low": ranges["Accel_1 y"][0], + "high": ranges["Accel_1 y"][1], + "units":ranges["Accel_1 y"][2] }, { - "name": "Pre-Charge Relay Status", - "value": motion_data.relay_state_buff_0, - "color": getColor(ranges["Pre-Charge Relay Status"], motion_data.relay_state_buff_0), - "low": ranges["Pre-Charge Relay Status"][0], - "high": ranges["Pre-Charge Relay Status"][1], - "units":ranges["Pre-Charge Relay Status"][2] + "name": "Accel_1 z", + "value": str(adc_data.data_4), + "color": getColor(ranges["Accel_1 z"], adc_data.data_4), + "low": ranges["Accel_1 z"][0], + "high": ranges["Accel_1 z"][1], + "units":ranges["Accel_1 z"][2] }, { - "name": "LV Relay Status", - "value": motion_data.relay_state_buff_1, - "color": getColor(ranges["LV Relay Status"], motion_data.relay_state_buff_1), - "low": ranges["LV Relay Status"][0], - "high": ranges["LV Relay Status"][1], - "units":ranges["LV Relay Status"][2] + "name": "Accel_2 x", + "value": str(adc_data.data_1), + "color": getColor(ranges["Accel_2 x"], adc_data.data_1), + "low": ranges["Accel_2 x"][0], + "high": ranges["Accel_2 x"][1], + "units":ranges["Accel_2 x"][2] }, { - "name": "HV Relay Status", - "value": motion_data.relay_state_buff_2, - "color": getColor(ranges["HV Relay Status"], motion_data.relay_state_buff_2), - "low": ranges["HV Relay Status"][0], - "high": ranges["HV Relay Status"][1], - "units":ranges["HV Relay Status"][2] + "name": "Accel_2 y", + "value": str(adc_data.data_3), + "color": getColor(ranges["Accel_2 y"], adc_data.data_3), + "low": ranges["Accel_2 y"][0], + "high": ranges["Accel_2 y"][1], + "units":ranges["Accel_2 y"][2] }, { - "name": "Relay State Buff 3", - "value": motion_data.relay_state_buff_3, - "color": getColor(ranges["Relay State Buff 3"], motion_data.relay_state_buff_3), - "low": ranges["Relay State Buff 3"][0], - "high": ranges["Relay State Buff 3"][1], - "units":ranges["Relay State Buff 3"][2] + "name": "Accel_2 z", + "value": str(adc_data.data_2), + "color": getColor(ranges["Accel_2 z"], adc_data.data_2), + "low": ranges["Accel_2 z"][0], + "high": ranges["Accel_2 z"][1], + "units":ranges["Accel_2 z"][2] } ] } @@ -690,6 +731,7 @@ def getStats(): def getRanges(): toRet = {} + toRet["TCP_On"] = [1, 1, "N/A"] toRet["State_Number"] = [0, 7, "N/A"] toRet["Status_Word"] = [0, 1, "m"] toRet["Position_Val"] = [0, 1, "m"] @@ -764,14 +806,14 @@ def getRanges(): toRet["Wheel Distance"] = [0, 1, "m"] toRet["Wheel Velocity"] = [0, 1, "m"] toRet["Acceleration"] = [0, 1, "m"] - toRet["Pre-Charge counter"] = [0, 1, "m"] - toRet["Pre-Charge timeout"] = [0, 1, "m"] - toRet["Acceleration counter"] = [0, 1, "m"] - toRet["Acceleration timeout"] = [0, 1, "m"] - toRet["Coast counter"] = [0, 1, "m"] - toRet["Coast timeout"] = [0, 1, "m"] - toRet["Brake counter"] = [0, 1, "m"] - toRet["Brake timeout"] = [0, 1, "m"] + toRet["Pre-Charge counter"] = [0, 1, "s"] + toRet["Pre-Charge timeout"] = [0, 1, "s"] + toRet["Acceleration counter"] = [0, 1, "s"] + toRet["Acceleration timeout"] = [0, 1, "s"] + toRet["Coast counter"] = [0, 1, "s"] + toRet["Coast timeout"] = [0, 1, "s"] + toRet["Brake counter"] = [0, 1, "s"] + toRet["Brake timeout"] = [0, 1, "s"] return toRet diff --git a/BaseStation/Backend/podconnect/tcpsaver.py b/BaseStation/Backend/podconnect/tcpsaver.py index 5b46af2e..c6131201 100644 --- a/BaseStation/Backend/podconnect/tcpsaver.py +++ b/BaseStation/Backend/podconnect/tcpsaver.py @@ -174,3 +174,19 @@ def saveCANData(data): can_model.save() return 1 + +def saveTCPStatus(status): + connected_data = models.ConnectedData.objects.latest("date_time") + models.ConnectedData( + tcp_connected=status, + udp_connected=connected_data.udp_connected + ).save() + return 1 + +def saveUDPStatus(status): + connected_data = models.ConnectedData.objects.latest("date_time") + models.ConnectedData( + tcp_connected=connected_data.tcp_connected, + udp_connected=status + ).save() + return 1 \ No newline at end of file diff --git a/BaseStation/Backend/podconnect/tcpserver.py b/BaseStation/Backend/podconnect/tcpserver.py index 015b76b6..f1e8b9ea 100644 --- a/BaseStation/Backend/podconnect/tcpserver.py +++ b/BaseStation/Backend/podconnect/tcpserver.py @@ -39,10 +39,12 @@ def serve(): TCP_PORT = TCP_PORT + 1 print("TCP Port = {port}".format(port=TCP_PORT)) s.listen(1) + tcpsaver.saveTCPStatus(0) while (True): conn, addr = s.accept() print('Connection address:', addr) + tcpsaver.saveTCPStatus(1) while (True): # Receiving data try: @@ -90,11 +92,28 @@ def serve(): data = tcphelper.bytes_to_int(data, 1) if tcpsaver.saveStateData(data) == -1: print("State data failure") + elif id == 9: + data = conn.recv(30*(1 + 3*2 + 1) + 48) + readCell(data[:30*(1 + 3*2 + 1)]) + data_int8 = tcphelper.bytes_to_uint8(data[30*(1+3*2+1):-40], 8) + print("num_therms_enabled: " + data_int8[0]) + print("highest_therm_value: " + data_int8[2]) + print("highest_therm_id: " + data_int8[3]) + print("lowest_therm_value: " + data_int8[1]) + print("lowest_therm_id: " + data_int8[4]) + print("PADDING: " + data_int8[5]) + print("PADDING2: " + data_int8[6]) + print("PADDING3: " + data_int8[7]) + + data_int8 = tcphelper.bytes_to_int8(data[-40:], 40) + for i in range(40): + print("Therm " + i + ": " + data_int8[i]) except Exception as e: print(e) print("Error in TCP Received message") break print("Disconnected from Pod!!") + tcpsaver.saveTCPStatus(0) # Add this to event logger import binascii @@ -113,6 +132,20 @@ def sendData(): #COMMAND_QUEUE.put(command) time.sleep(0.2) +def readCell(data): + if len(data) != 1 + 3*2 + 1: + print("Failure") + return + cell_id = int.from_bytes(data[0:1], byteorder='little', signed=True) + print("Cell: " + cell_id,end=" ") + voltage_stuff = tcphelper.bytes_to_uint16(data[1:6]) + print("Instant_Voltage: " + cell_id,end=" ") + print("Instant_Resistance: " + cell_id,end=" ") + print("Open_Voltage: " + cell_id,end=" ") + checksum = int.from_bytes(data[-1:], byteorder='little', signed=True) + print("Checksum: " + checksum) + return + # Starts thread for tcp server and processor def start(): t1 = Thread(target=serve) diff --git a/BaseStation/frontend/src/app/components/stats/stats.component.css b/BaseStation/frontend/src/app/components/stats/stats.component.css index cdcd843b..e7b01e90 100644 --- a/BaseStation/frontend/src/app/components/stats/stats.component.css +++ b/BaseStation/frontend/src/app/components/stats/stats.component.css @@ -16,7 +16,7 @@ border-collapse: collapse; position: absolute; top: 10%; - left: 48%; + left: 47.5%; } .table4 { diff --git a/BaseStation/tools/bms_readout.py b/BaseStation/tools/bms_readout.py index da6a64f5..148f60b5 100644 --- a/BaseStation/tools/bms_readout.py +++ b/BaseStation/tools/bms_readout.py @@ -1,5 +1,5 @@ from threading import Thread -from . import tcpsaver, tcphelper +import tcphelper import socket import queue import time @@ -53,18 +53,25 @@ def serve(): id = int(h[0]) if id == 7: # ADC Data data = conn.recv(7*4) + print("ADC") elif id == 1: # CAN Data data = conn.recv(45*4) + print("CAN") elif id == 2: # I2C Data data = conn.recv(12*2) + print("I2C") elif id == 3: # PRU Data data = conn.recv(4*4) + print("PRU") elif id == 4: # Motion Data data = conn.recv(6*4 + 8*8 + 4) + print("Motion") elif id == 5: # Error Data data = conn.recv(6*4) + print("Error") elif id == 6: # State Data data = conn.recv(4) + print("State") elif id == 9: input("Press enter to get next:") data = conn.recv(30*(1 + 3*2 + 1) + 48) @@ -103,3 +110,6 @@ def readCell(data): checksum = int.from_bytes(data[-1:], byteorder='little', signed=True) print("Checksum: " + checksum) return + +if __name__ == "__main__": + serve()