From 91f29264f9c2eeaecc08a87ff1d043f1e0eb9649 Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Sat, 1 Apr 2023 18:55:55 +0200 Subject: [PATCH] Format everything --- Test.py | 14 +++-- TestRead.py | 13 ++-- canTest.py | 158 +++++++++++++++++++++++++------------------------ eProm.py | 18 +++--- realTest.py | 20 +++---- tempTest.py | 41 +++++++------ voltageTest.py | 40 ++++++++----- 7 files changed, 160 insertions(+), 144 deletions(-) diff --git a/Test.py b/Test.py index f55de1c..9e8416e 100644 --- a/Test.py +++ b/Test.py @@ -1,17 +1,21 @@ import time import can -bustype = 'socketcan' -channel = 'can0' #echten can nutzen +bustype = "socketcan" +channel = "can0" # echten can nutzen + def producer(id): """:param id: Spam the bus with messages including the data id.""" bus = can.Bus(channel=channel, interface=bustype) for i in range(10): - msg = can.Message(arbitration_id=0x002, data=[id, i, 0, 1, 3, 1, 4, 1], is_extended_id=False) + msg = can.Message( + arbitration_id=0x002, data=[id, i, 0, 1, 3, 1, 4, 1], is_extended_id=False + ) bus.send(msg) time.sleep(1) - -producer(10) # rausfinden welche id der Slave hat + + +producer(10) # rausfinden welche id der Slave hat print("I am done with this shit") diff --git a/TestRead.py b/TestRead.py index 25ae3f6..4490154 100644 --- a/TestRead.py +++ b/TestRead.py @@ -3,13 +3,12 @@ import can input("startReading") -can_interface = 'can0' #echten can nutzen -bus = can.interface.Bus(can_interface, bustype='socketcan') +can_interface = "can0" # echten can nutzen +bus = can.interface.Bus(can_interface, bustype="socketcan") message = bus.recv(5.0) if message is None: - print('Timeout occurred, no message.') -else : - print('We got a message hell yeah') - print("{}".format(message.data)) #hat gesendete data von can benutzen - + print("Timeout occurred, no message.") +else: + print("We got a message hell yeah") + print("{}".format(message.data)) # hat gesendete data von can benutzen diff --git a/canTest.py b/canTest.py index bba53f7..025e1d8 100644 --- a/canTest.py +++ b/canTest.py @@ -5,89 +5,93 @@ import can waitForUserInput = True bus = None -def sendMessageOnCan(message, bustype='socketcan',channel='can0'): - - global bus - if bus is None: - bus = can.interface.Bus(channel, bustype='socketcan') - busEnabled = True - msg = can.Message(arbitration_id=0x002, data=message, is_extended_id=False) - bus.send(msg) - time.sleep(1) +def sendMessageOnCan(message, bustype="socketcan", channel="can0"): + global bus + if bus is None: + bus = can.interface.Bus(channel, bustype="socketcan") + busEnabled = True -def recive(bustype='socketcan',channel='can0'): - global bus - message = bus.recv() + msg = can.Message(arbitration_id=0x002, data=message, is_extended_id=False) + bus.send(msg) + time.sleep(1) - if message is None: - print('Timeout occurred, no message.') - #timeOut - else : - #print('We got a message hell yeah') - print(message) - return message +def recive(bustype="socketcan", channel="can0"): + global bus + message = bus.recv() + + if message is None: + print("Timeout occurred, no message.") + # timeOut + + else: + # print('We got a message hell yeah') + print(message) + return message + def waitForUserInput(waitForUserInput): - if(waitForUserInput): - readInput = "n" - print("Ready to start ? ") - while('y' not in readInput): - print("Enter y to start or c to cancel ") - readInput = input(" ") - if(readInput == 'c'): - return -1 - return 0 - -def CanTest(bustype='socketcan',channel='can0'): -#-----------------------------------------------------------------------------------------------------# - print("Start testing the can bus connectivity ") - global waitForUserInput - if (waitForUserInput(waitForUserInput) != 0): - return - - print("testing can for a single message") - messageType = 1 - testMessage = [messageType, 0xc, 0, 0xf, 0xf, 0xe, 0xe] - testMessageData = [1, 12, 0, 15, 15, 14, 14, 0] - - sendMessageOnCan(testMessage) - recivedMessage = recive().data - - result = True - count = 0 - - for entry in recivedMessage : - if entry != testMessageData[count]: - result = False - break - - count = count + 1 - - print(recivedMessage) - print("Sending a single message test with answer result {}".format(result)) -#-----------------------------------------------------------------------------------------------------# - - print("testing for multiple sends") - if (waitForUserInput(waitForUserInput) != 0): - return - - packete = [] - sendCountFinally = 0 - trials = 12 - for sendCount in range(trials): - sendMessageOnCan([1, 0xc, 0, 0xf, 0xf, 0xe, 0xe, sendCount]) - time.sleep(0.1) - packete.append(recive()) - - for packet in packete: - print(packet.data) - - print("Sending multiple testmessages test with answer result {}".format(len(packete) == len(range(trials)))) - -#-----------------------------------------------------------------------------------------------------# - print("I am done with this shit") + if waitForUserInput: + readInput = "n" + print("Ready to start ? ") + while "y" not in readInput: + print("Enter y to start or c to cancel ") + readInput = input(" ") + if readInput == "c": + return -1 + return 0 +def CanTest(bustype="socketcan", channel="can0"): + # -----------------------------------------------------------------------------------------------------# + print("Start testing the can bus connectivity ") + global waitForUserInput + if waitForUserInput(waitForUserInput) != 0: + return + print("testing can for a single message") + messageType = 1 + testMessage = [messageType, 0xC, 0, 0xF, 0xF, 0xE, 0xE] + testMessageData = [1, 12, 0, 15, 15, 14, 14, 0] + + sendMessageOnCan(testMessage) + recivedMessage = recive().data + + result = True + count = 0 + + for entry in recivedMessage: + if entry != testMessageData[count]: + result = False + break + + count = count + 1 + + print(recivedMessage) + print("Sending a single message test with answer result {}".format(result)) + # -----------------------------------------------------------------------------------------------------# + + print("testing for multiple sends") + if waitForUserInput(waitForUserInput) != 0: + return + + packete = [] + sendCountFinally = 0 + trials = 12 + for sendCount in range(trials): + sendMessageOnCan([1, 0xC, 0, 0xF, 0xF, 0xE, 0xE, sendCount]) + time.sleep(0.1) + packete.append(recive()) + + for packet in packete: + print(packet.data) + + print( + "Sending multiple testmessages test with answer result {}".format( + len(packete) == len(range(trials)) + ) + ) + + # -----------------------------------------------------------------------------------------------------# + print("I am done with this shit") diff --git a/eProm.py b/eProm.py index da2fa94..034f25b 100644 --- a/eProm.py +++ b/eProm.py @@ -1,12 +1,12 @@ import canTest -def ePromTest(): - print("start eprom test") - message = [4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00] - canTest.waitForUserInput(True) - canTest.sendMessageOnCan(message) - answer = canTest.recive(); - print("ePromTest reult {}".format(str(answer.data) == "bytearray(b'iiiiBiii')")) - - print("I am done with this shit") +def ePromTest(): + print("start eprom test") + message = [4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + canTest.waitForUserInput(True) + canTest.sendMessageOnCan(message) + answer = canTest.recive() + print("ePromTest reult {}".format(str(answer.data) == "bytearray(b'iiiiBiii')")) + + print("I am done with this shit") diff --git a/realTest.py b/realTest.py index 61945a1..3806d56 100644 --- a/realTest.py +++ b/realTest.py @@ -5,18 +5,18 @@ import eProm def startBalancingTest(): - message = [5, 0xc, 0, 0xf, 0xf, 0xe, 0xe] - print("startBalancing") - canTest.waitForUserInput(True) - canTest.sendMessageOnCan(message) + message = [5, 0xC, 0, 0xF, 0xF, 0xE, 0xE] + print("startBalancing") + canTest.waitForUserInput(True) + canTest.sendMessageOnCan(message) -#canTest.CanTest() -#eProm.ePromTest() -#voltageTest.voltagesTest() -tempTest.tempTest() +# canTest.CanTest() +# eProm.ePromTest() +# voltageTest.voltagesTest() +tempTest.tempTest() -#startBalancingTest() +# startBalancingTest() """ print("start Temp test") message = [3, 0xc, 0, 0xf, 0xf, 0xe, 0xe] @@ -33,5 +33,3 @@ canTest.sendMessageOnCan(message) answer = canTest.recive(); print(answer.data) """ - - diff --git a/tempTest.py b/tempTest.py index 34c774b..2f57ae9 100644 --- a/tempTest.py +++ b/tempTest.py @@ -3,15 +3,18 @@ import can import canTest import struct -bustype = 'socketcan' -channel = 'can0' +bustype = "socketcan" +channel = "can0" + def getTempOverCan(): bus = can.Bus(channel=channel, interface=bustype) - message = can.Message(arbitration_id=0x002, data=[3, 0, 0, 0, 0, 0, 0], is_extended_id=False) + message = can.Message( + arbitration_id=0x002, data=[3, 0, 0, 0, 0, 0, 0], is_extended_id=False + ) bus.send(message) voltages = [] - runtime = 2 + runtime = 2 begin = 0 for msg in bus: @@ -19,42 +22,42 @@ def getTempOverCan(): voltages.append(msg.data) print("begin {}".format(begin)) begin = begin + 1 - if(begin > runtime): + if begin > runtime: return voltages + def verifyNumbers(numberListList): zeroCount = 0 max = 0 min = 1000000 - for numberList in numberListList: - print("Temperatures {}".format(numberList)) - for number in numberList: - + for numberList in numberListList: + print("Temperatures {}".format(numberList)) + for number in numberList: if number < min: min = number - elif number > max : + elif number > max: max = number print("Temperatures {}".format()) print("The biggest difference tmep was max{} and min{}".format((max), (min))) -def tempTest(): + +def tempTest(): print("starting temperature test ") canTest.waitForUserInput(True) - Temps = getTempOverCan() + Temps = getTempOverCan() allTemp = [] changed = [] for temp in Temps: - allTemp.append(struct.unpack(" 4): + if begin > 4: return voltages + def verifyNumbers(numberListList): zeroCount = 0 max = 0 min = 1000000 - for numberList in numberListList: + for numberList in numberListList: for number in numberList: if number == 0: - zeroCount +=1 + zeroCount += 1 elif number < min: min = number - elif number > max : + elif number > max: max = number print("There were 3 expected Zeros and {} detected".format(zeroCount)) - print("The biggest difference were over {} and under {}".format((max-35000), (35000-min))) + print( + "The biggest difference were over {} and under {}".format( + (max - 35000), (35000 - min) + ) + ) -def voltagesTest(): + +def voltagesTest(): print("starting voltage test pls but 3.500 as reference value") canTest.waitForUserInput(True) - voltages = getBatteryVoltageOverCan() # rausfinden welche id der Slave hat + voltages = getBatteryVoltageOverCan() # rausfinden welche id der Slave hat allVoltages = [] for volt in voltages: allVoltages.append(struct.unpack("