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 getBatteryVoltageOverCan():
|
|
|
|
bus = can.Bus(channel=channel, interface=bustype)
|
2023-04-01 18:55:55 +02:00
|
|
|
message = can.Message(
|
|
|
|
arbitration_id=0x002, data=[2, 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 = 3
|
2023-04-01 18:53:28 +02:00
|
|
|
begin = 0
|
|
|
|
|
|
|
|
for msg in bus:
|
2023-04-01 18:55:55 +02:00
|
|
|
# print(msg.data)
|
2023-04-01 18:53:28 +02:00
|
|
|
voltages.append(msg.data)
|
2023-04-01 18:55:55 +02:00
|
|
|
# print("begin {}".format(begin))
|
2023-04-01 18:53:28 +02:00
|
|
|
begin = begin + 1
|
2023-04-01 18:55:55 +02:00
|
|
|
if begin > 4:
|
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:
|
2023-04-01 18:53:28 +02:00
|
|
|
for number in numberList:
|
|
|
|
if number == 0:
|
2023-04-01 18:55:55 +02:00
|
|
|
zeroCount += 1
|
2023-04-01 18:53:28 +02:00
|
|
|
|
|
|
|
elif 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("There were 3 expected Zeros and {} detected".format(zeroCount))
|
2023-04-01 18:55:55 +02:00
|
|
|
print(
|
|
|
|
"The biggest difference were over {} and under {}".format(
|
|
|
|
(max - 35000), (35000 - min)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-04-01 18:53:28 +02:00
|
|
|
|
2023-04-01 18:55:55 +02:00
|
|
|
def voltagesTest():
|
2023-04-01 20:35:33 +02:00
|
|
|
print("====================")
|
2023-04-01 18:53:28 +02:00
|
|
|
print("starting voltage test pls but 3.500 as reference value")
|
2023-04-01 20:51:35 +02:00
|
|
|
while True:
|
|
|
|
canTest.waitForUserInput(True)
|
|
|
|
voltages = getBatteryVoltageOverCan() # rausfinden welche id der Slave hat
|
|
|
|
allVoltages = []
|
|
|
|
for volt in voltages:
|
|
|
|
allVoltages.append(struct.unpack("<HHHH", volt))
|
|
|
|
|
|
|
|
verifyNumbers(allVoltages)
|
|
|
|
print("I am done with this shit")
|
|
|
|
if canTest.waitForUserInput(True, "Repeat voltage test?") != 0:
|
|
|
|
break
|