Format everything
This commit is contained in:
10
Test.py
10
Test.py
@ -1,17 +1,21 @@
|
|||||||
import time
|
import time
|
||||||
import can
|
import can
|
||||||
|
|
||||||
bustype = 'socketcan'
|
bustype = "socketcan"
|
||||||
channel = 'can0' #echten can nutzen
|
channel = "can0" # echten can nutzen
|
||||||
|
|
||||||
|
|
||||||
def producer(id):
|
def producer(id):
|
||||||
""":param id: Spam the bus with messages including the data id."""
|
""":param id: Spam the bus with messages including the data id."""
|
||||||
bus = can.Bus(channel=channel, interface=bustype)
|
bus = can.Bus(channel=channel, interface=bustype)
|
||||||
for i in range(10):
|
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)
|
bus.send(msg)
|
||||||
|
|
||||||
time.sleep(1)
|
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")
|
print("I am done with this shit")
|
||||||
|
|||||||
@ -3,13 +3,12 @@ import can
|
|||||||
|
|
||||||
input("startReading")
|
input("startReading")
|
||||||
|
|
||||||
can_interface = 'can0' #echten can nutzen
|
can_interface = "can0" # echten can nutzen
|
||||||
bus = can.interface.Bus(can_interface, bustype='socketcan')
|
bus = can.interface.Bus(can_interface, bustype="socketcan")
|
||||||
message = bus.recv(5.0)
|
message = bus.recv(5.0)
|
||||||
|
|
||||||
if message is None:
|
if message is None:
|
||||||
print('Timeout occurred, no message.')
|
print("Timeout occurred, no message.")
|
||||||
else:
|
else:
|
||||||
print('We got a message hell yeah')
|
print("We got a message hell yeah")
|
||||||
print("{}".format(message.data)) # hat gesendete data von can benutzen
|
print("{}".format(message.data)) # hat gesendete data von can benutzen
|
||||||
|
|
||||||
|
|||||||
36
canTest.py
36
canTest.py
@ -5,23 +5,24 @@ import can
|
|||||||
waitForUserInput = True
|
waitForUserInput = True
|
||||||
bus = None
|
bus = None
|
||||||
|
|
||||||
def sendMessageOnCan(message, bustype='socketcan',channel='can0'):
|
|
||||||
|
|
||||||
|
def sendMessageOnCan(message, bustype="socketcan", channel="can0"):
|
||||||
global bus
|
global bus
|
||||||
if bus is None:
|
if bus is None:
|
||||||
bus = can.interface.Bus(channel, bustype='socketcan')
|
bus = can.interface.Bus(channel, bustype="socketcan")
|
||||||
busEnabled = True
|
busEnabled = True
|
||||||
|
|
||||||
msg = can.Message(arbitration_id=0x002, data=message, is_extended_id=False)
|
msg = can.Message(arbitration_id=0x002, data=message, is_extended_id=False)
|
||||||
bus.send(msg)
|
bus.send(msg)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def recive(bustype='socketcan',channel='can0'):
|
|
||||||
|
def recive(bustype="socketcan", channel="can0"):
|
||||||
global bus
|
global bus
|
||||||
message = bus.recv()
|
message = bus.recv()
|
||||||
|
|
||||||
if message is None:
|
if message is None:
|
||||||
print('Timeout occurred, no message.')
|
print("Timeout occurred, no message.")
|
||||||
# timeOut
|
# timeOut
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -29,27 +30,29 @@ def recive(bustype='socketcan',channel='can0'):
|
|||||||
print(message)
|
print(message)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
def waitForUserInput(waitForUserInput):
|
def waitForUserInput(waitForUserInput):
|
||||||
if(waitForUserInput):
|
if waitForUserInput:
|
||||||
readInput = "n"
|
readInput = "n"
|
||||||
print("Ready to start ? ")
|
print("Ready to start ? ")
|
||||||
while('y' not in readInput):
|
while "y" not in readInput:
|
||||||
print("Enter y to start or c to cancel ")
|
print("Enter y to start or c to cancel ")
|
||||||
readInput = input(" ")
|
readInput = input(" ")
|
||||||
if(readInput == 'c'):
|
if readInput == "c":
|
||||||
return -1
|
return -1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def CanTest(bustype='socketcan',channel='can0'):
|
|
||||||
|
def CanTest(bustype="socketcan", channel="can0"):
|
||||||
# -----------------------------------------------------------------------------------------------------#
|
# -----------------------------------------------------------------------------------------------------#
|
||||||
print("Start testing the can bus connectivity ")
|
print("Start testing the can bus connectivity ")
|
||||||
global waitForUserInput
|
global waitForUserInput
|
||||||
if (waitForUserInput(waitForUserInput) != 0):
|
if waitForUserInput(waitForUserInput) != 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
print("testing can for a single message")
|
print("testing can for a single message")
|
||||||
messageType = 1
|
messageType = 1
|
||||||
testMessage = [messageType, 0xc, 0, 0xf, 0xf, 0xe, 0xe]
|
testMessage = [messageType, 0xC, 0, 0xF, 0xF, 0xE, 0xE]
|
||||||
testMessageData = [1, 12, 0, 15, 15, 14, 14, 0]
|
testMessageData = [1, 12, 0, 15, 15, 14, 14, 0]
|
||||||
|
|
||||||
sendMessageOnCan(testMessage)
|
sendMessageOnCan(testMessage)
|
||||||
@ -70,24 +73,25 @@ def CanTest(bustype='socketcan',channel='can0'):
|
|||||||
# -----------------------------------------------------------------------------------------------------#
|
# -----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
print("testing for multiple sends")
|
print("testing for multiple sends")
|
||||||
if (waitForUserInput(waitForUserInput) != 0):
|
if waitForUserInput(waitForUserInput) != 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
packete = []
|
packete = []
|
||||||
sendCountFinally = 0
|
sendCountFinally = 0
|
||||||
trials = 12
|
trials = 12
|
||||||
for sendCount in range(trials):
|
for sendCount in range(trials):
|
||||||
sendMessageOnCan([1, 0xc, 0, 0xf, 0xf, 0xe, 0xe, sendCount])
|
sendMessageOnCan([1, 0xC, 0, 0xF, 0xF, 0xE, 0xE, sendCount])
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
packete.append(recive())
|
packete.append(recive())
|
||||||
|
|
||||||
for packet in packete:
|
for packet in packete:
|
||||||
print(packet.data)
|
print(packet.data)
|
||||||
|
|
||||||
print("Sending multiple testmessages test with answer result {}".format(len(packete) == len(range(trials))))
|
print(
|
||||||
|
"Sending multiple testmessages test with answer result {}".format(
|
||||||
|
len(packete) == len(range(trials))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------#
|
# -----------------------------------------------------------------------------------------------------#
|
||||||
print("I am done with this shit")
|
print("I am done with this shit")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
4
eProm.py
4
eProm.py
@ -1,12 +1,12 @@
|
|||||||
import canTest
|
import canTest
|
||||||
|
|
||||||
|
|
||||||
def ePromTest():
|
def ePromTest():
|
||||||
print("start eprom test")
|
print("start eprom test")
|
||||||
message = [4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
|
message = [4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
|
||||||
canTest.waitForUserInput(True)
|
canTest.waitForUserInput(True)
|
||||||
canTest.sendMessageOnCan(message)
|
canTest.sendMessageOnCan(message)
|
||||||
answer = canTest.recive();
|
answer = canTest.recive()
|
||||||
print("ePromTest reult {}".format(str(answer.data) == "bytearray(b'iiiiBiii')"))
|
print("ePromTest reult {}".format(str(answer.data) == "bytearray(b'iiiiBiii')"))
|
||||||
|
|
||||||
|
|
||||||
print("I am done with this shit")
|
print("I am done with this shit")
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import eProm
|
|||||||
|
|
||||||
|
|
||||||
def startBalancingTest():
|
def startBalancingTest():
|
||||||
message = [5, 0xc, 0, 0xf, 0xf, 0xe, 0xe]
|
message = [5, 0xC, 0, 0xF, 0xF, 0xE, 0xE]
|
||||||
print("startBalancing")
|
print("startBalancing")
|
||||||
canTest.waitForUserInput(True)
|
canTest.waitForUserInput(True)
|
||||||
canTest.sendMessageOnCan(message)
|
canTest.sendMessageOnCan(message)
|
||||||
@ -33,5 +33,3 @@ canTest.sendMessageOnCan(message)
|
|||||||
answer = canTest.recive();
|
answer = canTest.recive();
|
||||||
print(answer.data)
|
print(answer.data)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
tempTest.py
15
tempTest.py
@ -3,12 +3,15 @@ import can
|
|||||||
import canTest
|
import canTest
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
bustype = 'socketcan'
|
bustype = "socketcan"
|
||||||
channel = 'can0'
|
channel = "can0"
|
||||||
|
|
||||||
|
|
||||||
def getTempOverCan():
|
def getTempOverCan():
|
||||||
bus = can.Bus(channel=channel, interface=bustype)
|
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)
|
bus.send(message)
|
||||||
voltages = []
|
voltages = []
|
||||||
runtime = 2
|
runtime = 2
|
||||||
@ -19,9 +22,10 @@ def getTempOverCan():
|
|||||||
voltages.append(msg.data)
|
voltages.append(msg.data)
|
||||||
print("begin {}".format(begin))
|
print("begin {}".format(begin))
|
||||||
begin = begin + 1
|
begin = begin + 1
|
||||||
if(begin > runtime):
|
if begin > runtime:
|
||||||
return voltages
|
return voltages
|
||||||
|
|
||||||
|
|
||||||
def verifyNumbers(numberListList):
|
def verifyNumbers(numberListList):
|
||||||
zeroCount = 0
|
zeroCount = 0
|
||||||
max = 0
|
max = 0
|
||||||
@ -29,7 +33,6 @@ def verifyNumbers(numberListList):
|
|||||||
for numberList in numberListList:
|
for numberList in numberListList:
|
||||||
print("Temperatures {}".format(numberList))
|
print("Temperatures {}".format(numberList))
|
||||||
for number in numberList:
|
for number in numberList:
|
||||||
|
|
||||||
if number < min:
|
if number < min:
|
||||||
min = number
|
min = number
|
||||||
|
|
||||||
@ -39,6 +42,7 @@ def verifyNumbers(numberListList):
|
|||||||
print("Temperatures {}".format())
|
print("Temperatures {}".format())
|
||||||
print("The biggest difference tmep was max{} and min{}".format((max), (min)))
|
print("The biggest difference tmep was max{} and min{}".format((max), (min)))
|
||||||
|
|
||||||
|
|
||||||
def tempTest():
|
def tempTest():
|
||||||
print("starting temperature test ")
|
print("starting temperature test ")
|
||||||
canTest.waitForUserInput(True)
|
canTest.waitForUserInput(True)
|
||||||
@ -57,4 +61,3 @@ def tempTest():
|
|||||||
changed.append(((con / 16) * 0.0625))
|
changed.append(((con / 16) * 0.0625))
|
||||||
print(changed)
|
print(changed)
|
||||||
print("I am done with this shit")
|
print("I am done with this shit")
|
||||||
|
|
||||||
|
|||||||
@ -3,12 +3,15 @@ import can
|
|||||||
import canTest
|
import canTest
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
bustype = 'socketcan'
|
bustype = "socketcan"
|
||||||
channel = 'can0'
|
channel = "can0"
|
||||||
|
|
||||||
|
|
||||||
def getBatteryVoltageOverCan():
|
def getBatteryVoltageOverCan():
|
||||||
bus = can.Bus(channel=channel, interface=bustype)
|
bus = can.Bus(channel=channel, interface=bustype)
|
||||||
message = can.Message(arbitration_id=0x002, data=[2, 0, 0, 0, 0, 0, 0], is_extended_id=False)
|
message = can.Message(
|
||||||
|
arbitration_id=0x002, data=[2, 0, 0, 0, 0, 0, 0], is_extended_id=False
|
||||||
|
)
|
||||||
bus.send(message)
|
bus.send(message)
|
||||||
voltages = []
|
voltages = []
|
||||||
runtime = 3
|
runtime = 3
|
||||||
@ -19,9 +22,10 @@ def getBatteryVoltageOverCan():
|
|||||||
voltages.append(msg.data)
|
voltages.append(msg.data)
|
||||||
# print("begin {}".format(begin))
|
# print("begin {}".format(begin))
|
||||||
begin = begin + 1
|
begin = begin + 1
|
||||||
if(begin > 4):
|
if begin > 4:
|
||||||
return voltages
|
return voltages
|
||||||
|
|
||||||
|
|
||||||
def verifyNumbers(numberListList):
|
def verifyNumbers(numberListList):
|
||||||
zeroCount = 0
|
zeroCount = 0
|
||||||
max = 0
|
max = 0
|
||||||
@ -38,7 +42,12 @@ def verifyNumbers(numberListList):
|
|||||||
max = number
|
max = number
|
||||||
|
|
||||||
print("There were 3 expected Zeros and {} detected".format(zeroCount))
|
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")
|
print("starting voltage test pls but 3.500 as reference value")
|
||||||
@ -50,4 +59,3 @@ def voltagesTest():
|
|||||||
|
|
||||||
verifyNumbers(allVoltages)
|
verifyNumbers(allVoltages)
|
||||||
print("I am done with this shit")
|
print("I am done with this shit")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user