Skip to content

Commit

Permalink
added new tm values to test server
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardclifford committed Dec 6, 2022
1 parent aa454f8 commit b04ba06
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions backend/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
max_cell = 0
dc_amps = 0

acc_temp = 0
inv_temp = 0
mtr_temp = 0

rtd = False
fault = False

odometer = 0
trip = 0

Expand Down Expand Up @@ -81,7 +88,7 @@ async def send_tm(websocket):
Maintain telemetry connection with client
"""
global rpm, speed, inv_voltage, avg_cell, min_cell, max_cell, dc_amps, \
odometer, trip
odometer, trip, acc_temp, inv_temp, mtr_temp, rtd, fault

i = 0

Expand All @@ -92,22 +99,28 @@ async def send_tm(websocket):
if (i % 2 == 0):
pkt = {**pkt, **{'rpm': rpm,
'speed': speed,
'inv_volts': inv_voltage,
'odometer': round(odometer, 1),
'trip': round(trip, 3)}}
elif (i % 2 == 1):
'inv_volts': inv_voltage,
'dc_amps': dc_amps
}}
elif (i == 1):
pkt = {**pkt, **{'avg_cell': avg_cell,
'min_cell': min_cell,
'max_cell': max_cell,
'dc_amps': dc_amps}}
'acc_temp': acc_temp,
'inv_temp': inv_temp,
'mtr_temp': mtr_temp,
'odometer': round(odometer, 1),
'trip': round(trip, 3),
'rtd': rtd,
'fault': fault}}

if (i >= 9):
if (i >= 99):
i = 0
else:
i += 1

await websocket.send(json.dumps(pkt))
await asyncio.sleep(1) # Define frontend refresh rate
await asyncio.sleep(.01) # Define frontend refresh rate


#######
Expand All @@ -121,7 +134,8 @@ async def poll_tm():
# Read message from can bus, update internal state,
async def get_tm():
global rpm, speed, inv_voltage, avg_cell, min_cell, max_cell, dc_amps, \
odometer, trip, last_time, dc_amps_dir
odometer, trip, last_time, dc_amps_dir, acc_temp, inv_temp, mtr_temp, \
rtd, fault

# Simulate waiting for message
# Each message type 'read' every .1s avg
Expand Down Expand Up @@ -160,6 +174,13 @@ async def get_tm():
if dc_amps < -50:
dc_amps_dir = 1

acc_temp = 90
inv_temp = 110
mtr_temp = 74

rtd = True
fault = False

# BMS_Information
elif rand_msg_type == 2:
avg_cell = round(((random.randint(0, 10)) * 0.01) + 2, 2)
Expand Down

0 comments on commit b04ba06

Please sign in to comment.