slave-testbench-23/tempTest.py

68 lines
1.6 KiB
Python
Raw Normal View History

2023-04-01 18:53:28 +02:00
import time
import can
import canTest
import struct
2023-04-01 18:55:55 +02:00
bustype = "socketcan"
channel = "can0"
2023-04-01 18:53:28 +02:00
def getTempOverCan():
bus = can.Bus(channel=channel, interface=bustype)
2023-04-01 18:55:55 +02:00
message = can.Message(
arbitration_id=0x002, data=[3, 0, 0, 0, 0, 0, 0], is_extended_id=False
)
2023-04-01 18:53:28 +02:00
bus.send(message)
voltages = []
2023-04-01 18:55:55 +02:00
runtime = 2
2023-04-01 18:53:28 +02:00
begin = 0
for msg in bus:
print(msg.data)
voltages.append(msg.data)
print("begin {}".format(begin))
begin = begin + 1
2023-04-01 18:55:55 +02:00
if begin > runtime:
2023-04-01 18:53:28 +02:00
return voltages
2023-04-01 18:55:55 +02:00
2023-04-01 18:53:28 +02:00
def verifyNumbers(numberListList):
zeroCount = 0
max = 0
min = 1000000
2023-04-01 18:55:55 +02:00
for numberList in numberListList:
print("Temperatures {}".format(numberList))
for number in numberList:
2023-04-01 18:53:28 +02:00
if number < min:
min = number
2023-04-01 18:55:55 +02:00
elif number > max:
2023-04-01 18:53:28 +02:00
max = number
print("Temperatures {}".format())
print("The biggest difference tmep was max{} and min{}".format((max), (min)))
2023-04-01 18:55:55 +02:00
def tempTest():
while True:
print("====================")
print("starting temperature test ")
canTest.waitForUserInput(True)
Temps = getTempOverCan()
allTemp = []
changed = []
2023-04-01 18:53:28 +02:00
for temp in Temps:
allTemp += struct.unpack("<HHHH", temp) # Format anpassen
2023-04-01 18:53:28 +02:00
print("Raw temperatures:")
print(allTemp)
2023-04-01 18:53:28 +02:00
for te in allTemp:
changed.append(((te >> 4) * 0.0625))
print("Interpreted temperatures:")
print(changed)
if canTest.waitForUserInput(True, "Repeat temperature test?") != 0:
break
2023-04-01 18:53:28 +02:00
print("I am done with this shit")