Skip to content

Commit

Permalink
Big fix energy
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan committed Jul 20, 2019
1 parent 5512acd commit 4f80af5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 65 deletions.
Binary file modified BaseStation/Backend/db.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions BaseStation/Backend/podconnect/data_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def battery(request):
toReturn = {
"value": can_data.pack_soc
}
print(can_data.pack_soc)
return JsonResponse(toReturn)

def position(request):
Expand Down
14 changes: 4 additions & 10 deletions BaseStation/Backend/podconnect/stats_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions BaseStation/Backend/podconnect/tcphelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 3 additions & 31 deletions BaseStation/Backend/podconnect/tcpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down
41 changes: 18 additions & 23 deletions BaseStation/tools/bms_readout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import queue
import time
import binascii
import numpy as np

# TCP IDs:
Expand Down Expand Up @@ -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")
Expand All @@ -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__":
Expand Down

0 comments on commit 4f80af5

Please sign in to comment.