diff --git a/BaseStation/Backend/db.sqlite3 b/BaseStation/Backend/db.sqlite3 index 91c4d07b..21d8233c 100644 Binary files a/BaseStation/Backend/db.sqlite3 and b/BaseStation/Backend/db.sqlite3 differ diff --git a/BaseStation/Backend/podconnect/data_logic.py b/BaseStation/Backend/podconnect/data_logic.py index ec34aa80..c5ba5cc2 100644 --- a/BaseStation/Backend/podconnect/data_logic.py +++ b/BaseStation/Backend/podconnect/data_logic.py @@ -22,6 +22,7 @@ def battery(request): toReturn = { "value": can_data.pack_soc } + print(can_data.pack_soc) return JsonResponse(toReturn) def position(request): diff --git a/BaseStation/Backend/podconnect/stats_helper.py b/BaseStation/Backend/podconnect/stats_helper.py index 760499fc..e5ab873e 100644 --- a/BaseStation/Backend/podconnect/stats_helper.py +++ b/BaseStation/Backend/podconnect/stats_helper.py @@ -32,7 +32,7 @@ def getStats(): { "name": "Watchdog", "value": str(connected_data.tcp_connected), - "color": "linmegreen", + "color": "limegreen", "low": 1, "high": 1, "units":"N/A" @@ -652,14 +652,6 @@ def getStats(): "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": "Pre-Charge counter", "value": motion_data.p_counter, @@ -753,7 +745,7 @@ def getRanges(): toRet["Accel_2 z"] = [-1.5, 1.5, "m/s^2"] toRet["Internal_Relay_State"] = [0, 1, "m"] toRet["Relay_State"] = [0, 1, "m"] - toRet["Rolling_Counter"] = [0, 1, "m"] + toRet["Rolling_Counter"] = [0, 256, "m"] toRet["Fail_Safe_State"] = [0, 1, "m"] toRet["Peak_Current"] = [0, 544, "A"] toRet["Pack_Voltage_Inst"] = [0, 1, "m"] @@ -820,6 +812,8 @@ def getRanges(): def getColor(range, val): if range[0] == "N/A" or range[1] == "N/A": return "limegreen" + if range[0] == '' or range[1] == '' or val == '': + return "limegreen" if range[0] <= int(val) and int(val) <= range[1]: return "limegreen" else: diff --git a/BaseStation/Backend/podconnect/tcphelper.py b/BaseStation/Backend/podconnect/tcphelper.py index 60ed72c5..06625885 100644 --- a/BaseStation/Backend/podconnect/tcphelper.py +++ b/BaseStation/Backend/podconnect/tcphelper.py @@ -33,4 +33,11 @@ def bytes_to_char(bytes, length): for x in range(0, length): new_bytes.append(int.from_bytes( bytes[(x):(x+1)], byteorder='little')) + return new_bytes + +def bytes_to_uint8(bytes, length): + new_bytes = [] + for x in range(0, length): + new_bytes.append(int.from_bytes( + bytes[(x):(x+1)], byteorder='little', signed=False)) return new_bytes \ No newline at end of file diff --git a/BaseStation/Backend/podconnect/tcpserver.py b/BaseStation/Backend/podconnect/tcpserver.py index f1e8b9ea..39d5b85a 100644 --- a/BaseStation/Backend/podconnect/tcpserver.py +++ b/BaseStation/Backend/podconnect/tcpserver.py @@ -64,12 +64,12 @@ def serve(): if tcpsaver.saveCANData(data) == -1: print("CAN data failure") elif id == 2: # I2C Data - data = conn.recv(12*2) - data = tcphelper.bytes_to_int16(data, 12) + data = conn.recv(16*2 + 2*4) + data = tcphelper.bytes_to_int16(data, 16) if tcpsaver.saveI2CData(data) == -1: print("I2C data failure") elif id == 3: # PRU Data - data = conn.recv(4*4) + data = conn.recv(5*4) data = tcphelper.bytes_to_signed_int32(data, 4) if tcpsaver.savePRUData(data) == -1: print("PRU data failure") @@ -94,20 +94,6 @@ def serve(): 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") @@ -132,20 +118,6 @@ 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/battery/battery.component.ts b/BaseStation/frontend/src/app/components/battery/battery.component.ts index 7dc8c506..65028c69 100644 --- a/BaseStation/frontend/src/app/components/battery/battery.component.ts +++ b/BaseStation/frontend/src/app/components/battery/battery.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { interval } from 'rxjs'; import { BatteryService } from '../../services/battery.service'; import { Battery } from '../../models/battery'; @@ -11,7 +12,11 @@ import { Battery } from '../../models/battery'; export class BatteryComponent implements OnInit { battery:Battery = { "value": 0 }; - constructor(private batteryService: BatteryService) { } + constructor(private batteryService: BatteryService) { + interval(50).subscribe(x => { + this.getValue(); + }) + } ngOnInit() { this.getValue(); diff --git a/BaseStation/tools/bms_readout.py b/BaseStation/tools/bms_readout.py index 148f60b5..877fbe8c 100644 --- a/BaseStation/tools/bms_readout.py +++ b/BaseStation/tools/bms_readout.py @@ -3,6 +3,7 @@ import socket import queue import time +import binascii import numpy as np # TCP IDs: @@ -53,42 +54,36 @@ 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) - readCell(data[:30*(1 + 3*2 + 1)]) + for i in range(30): + readCell(data[i*(1 + 3*2 + 1):(i+1)*(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]) + print("num_therms_enabled: " + str(data_int8[0])) + print("highest_therm_value: " + str(data_int8[2])) + print("highest_therm_id: " + str(data_int8[3])) + print("lowest_therm_value: " + str(data_int8[1])) + print("lowest_therm_id: " + str(data_int8[4])) + print("PADDING: " + str(data_int8[5])) + print("PADDING2: " + str(data_int8[6])) + print("PADDING3: " + str(data_int8[7])) data_int8 = tcphelper.bytes_to_int8(data[-40:], 40) for i in range(40): - print("Therm " + i + ": " + data_int8[i]) + print("Therm " + str(i) + ": " + str(data_int8[i])) except Exception as e: print(e) print("Error in TCP Received message") @@ -102,13 +97,13 @@ def readCell(data): 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=" ") + print("Cell: " + str(cell_id),end=" ") + voltage_stuff = tcphelper.bytes_to_uint16(data[1:6], 3) + print("Instant_Voltage: " + str(voltage_stuff[0]/10000),end=" ") + print("Instant_Resistance: " + str(voltage_stuff[1]/10000),end=" ") + print("Open_Voltage: " + str(voltage_stuff[2]/10000),end=" ") checksum = int.from_bytes(data[-1:], byteorder='little', signed=True) - print("Checksum: " + checksum) + print("Checksum: " + str(checksum)) return if __name__ == "__main__":