|
|
|
@ -35,7 +35,7 @@ def send_compare(s, dat, ret, timeout=4):
|
|
|
|
|
break;
|
|
|
|
|
res += s.recv(1000)
|
|
|
|
|
#print("final recv data: '%s'" % repr(res))
|
|
|
|
|
assert ret == res#, "Data does not agree (%s) (%s)"%(repr(ret), repr(res))
|
|
|
|
|
assert ret == res # , "Data does not agree (%s) (%s)"%(repr(ret), repr(res))
|
|
|
|
|
|
|
|
|
|
def sync_reset(s):
|
|
|
|
|
s.send("ATZ\r")
|
|
|
|
@ -63,7 +63,7 @@ def test_elm_cli():
|
|
|
|
|
|
|
|
|
|
#Test Echo Off
|
|
|
|
|
#Expected to be misimplimentation, but this is how the reference device behaved.
|
|
|
|
|
send_compare(s, b'ATE0\r', b'ATE0\rOK\r\r>') #Here is the odd part
|
|
|
|
|
send_compare(s, b'ATE0\r', b'ATE0\rOK\r\r>') # Here is the odd part
|
|
|
|
|
send_compare(s, b'ATE0\r', b'OK\r\r>') #Should prob show this immediately
|
|
|
|
|
send_compare(s, b'ATI\r', b'ELM327 v1.5\r\r>')
|
|
|
|
|
|
|
|
|
@ -73,17 +73,17 @@ def test_elm_cli():
|
|
|
|
|
send_compare(s, b'ATL0\r', b'OK\r\r>')
|
|
|
|
|
send_compare(s, b'ATI\r', b'ELM327 v1.5\r\r>')
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'ATI\r', b'ELM327 v1.5\r\r>') #Test repeat command no echo
|
|
|
|
|
send_compare(s, b'ATI\r', b'ELM327 v1.5\r\r>') # Test repeat command no echo
|
|
|
|
|
send_compare(s, b'\r', b'ELM327 v1.5\r\r>')
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'aTi\r', b'ELM327 v1.5\r\r>') #Test different case
|
|
|
|
|
send_compare(s, b'aTi\r', b'ELM327 v1.5\r\r>') # Test different case
|
|
|
|
|
|
|
|
|
|
send_compare(s, b' a T i\r', b'ELM327 v1.5\r\r>') #Test with white space
|
|
|
|
|
send_compare(s, b' a T i\r', b'ELM327 v1.5\r\r>') # Test with white space
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'ATCATHAT\r', b'?\r\r>') #Test Invalid AT command
|
|
|
|
|
send_compare(s, b'ATCATHAT\r', b'?\r\r>') # Test Invalid AT command
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'01 00 00 00 00 00 00 00\r', b'?\r\r>') #Test Invalid (too long) OBD command
|
|
|
|
|
send_compare(s, b'01 GZ\r', b'?\r\r>') #Test Invalid (Non hex chars) OBD command
|
|
|
|
|
send_compare(s, b'01 00 00 00 00 00 00 00\r', b'?\r\r>') # Test Invalid (too long) OBD command
|
|
|
|
|
send_compare(s, b'01 GZ\r', b'?\r\r>') # Test Invalid (Non hex chars) OBD command
|
|
|
|
|
finally:
|
|
|
|
|
s.close()
|
|
|
|
|
|
|
|
|
@ -108,7 +108,7 @@ def test_elm_setget_protocol():
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'ATSP7\r', b"OK\r\r>")
|
|
|
|
|
send_compare(s, b'ATDP\r', b"ISO 15765-4 (CAN 29/500)\r\r>")
|
|
|
|
|
send_compare(s, b'ATDPN\r', b"7\r\r>") #Test Does not accept invalid protocols
|
|
|
|
|
send_compare(s, b'ATDPN\r', b"7\r\r>") # Test Does not accept invalid protocols
|
|
|
|
|
send_compare(s, b'ATSPD\r', b"?\r\r>")
|
|
|
|
|
send_compare(s, b'ATDP\r', b"ISO 15765-4 (CAN 29/500)\r\r>")
|
|
|
|
|
send_compare(s, b'ATDPN\r', b"7\r\r>")
|
|
|
|
@ -166,7 +166,7 @@ def test_elm_protocol_failure():
|
|
|
|
|
def test_elm_protocol_autodetect_ISO14230_KWP_FAST():
|
|
|
|
|
s = elm_connect()
|
|
|
|
|
serial = os.getenv("CANSIMSERIAL") if os.getenv("CANSIMSERIAL") else None
|
|
|
|
|
sim = elm_car_simulator.ELMCarSimulator(serial, can=False)#, silent=True)
|
|
|
|
|
sim = elm_car_simulator.ELMCarSimulator(serial, can=False) # , silent=True)
|
|
|
|
|
sim.start()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -186,7 +186,7 @@ def test_elm_protocol_autodetect_ISO14230_KWP_FAST():
|
|
|
|
|
def test_elm_basic_send_lin():
|
|
|
|
|
s = elm_connect()
|
|
|
|
|
serial = os.getenv("CANSIMSERIAL") if os.getenv("CANSIMSERIAL") else None
|
|
|
|
|
sim = elm_car_simulator.ELMCarSimulator(serial, can=False)#, silent=True)
|
|
|
|
|
sim = elm_car_simulator.ELMCarSimulator(serial, can=False) # , silent=True)
|
|
|
|
|
sim.start()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -332,13 +332,13 @@ def test_elm_panda_safety_mode_KWPFast():
|
|
|
|
|
return False
|
|
|
|
|
return timed_recv_check(p_car, bus, msgout)
|
|
|
|
|
|
|
|
|
|
assert not did_send(0xC0, 0x33, 0xF1, b'\x01\x0F', bus=3) #wrong bus
|
|
|
|
|
assert not did_send(0xC0, 0x33, 0xF1, b'') #wrong length
|
|
|
|
|
assert not did_send(0xB0, 0x33, 0xF1, b'\x01\x0E') #bad priority
|
|
|
|
|
assert not did_send(0xC0, 0x00, 0xF1, b'\x01\x0D') #bad addr
|
|
|
|
|
assert not did_send(0xC0, 0x33, 0x00, b'\x01\x0C') #bad addr
|
|
|
|
|
assert not did_send(0xC0, 0x33, 0xF1, b'\x01\x0F', bus=3) # wrong bus
|
|
|
|
|
assert not did_send(0xC0, 0x33, 0xF1, b'') # wrong length
|
|
|
|
|
assert not did_send(0xB0, 0x33, 0xF1, b'\x01\x0E') # bad priority
|
|
|
|
|
assert not did_send(0xC0, 0x00, 0xF1, b'\x01\x0D') # bad addr
|
|
|
|
|
assert not did_send(0xC0, 0x33, 0x00, b'\x01\x0C') # bad addr
|
|
|
|
|
|
|
|
|
|
assert did_send(0xC0, 0x33, 0xF1, b'\x01\x0B') #good! (obd func req)
|
|
|
|
|
assert did_send(0xC0, 0x33, 0xF1, b'\x01\x0B') # good! (obd func req)
|
|
|
|
|
|
|
|
|
|
def test_elm_lin_keepalive():
|
|
|
|
|
s = elm_connect()
|
|
|
|
@ -358,7 +358,7 @@ def test_elm_lin_keepalive():
|
|
|
|
|
time.sleep(6)
|
|
|
|
|
assert sim.lin_active
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'ATPC\r', b"OK\r\r>") #STOP KEEPALIVE
|
|
|
|
|
send_compare(s, b'ATPC\r', b"OK\r\r>") # STOP KEEPALIVE
|
|
|
|
|
assert sim.lin_active
|
|
|
|
|
time.sleep(6)
|
|
|
|
|
assert not sim.lin_active
|
|
|
|
@ -456,7 +456,7 @@ def test_elm_send_can_multimsg():
|
|
|
|
|
send_compare(s, b'ATH1\r', b'OK\r\r>') # Headers ON
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'ATSP6\r', b"OK\r\r>") # Set Proto ISO 15765-4 (CAN 11/500)
|
|
|
|
|
sim.can_add_extra_noise(b'\x03\x41\x0D\xFA', addr=0x7E9)# Inject message into the stream
|
|
|
|
|
sim.can_add_extra_noise(b'\x03\x41\x0D\xFA', addr=0x7E9) # Inject message into the stream
|
|
|
|
|
send_compare(s, b'010D\r',
|
|
|
|
|
b"7E8 03 41 0D 53 \r"
|
|
|
|
|
b"7E9 03 41 0D FA \r\r>") # Check it was ignored.
|
|
|
|
@ -480,7 +480,7 @@ def test_elm_can_check_mode_pid():
|
|
|
|
|
send_compare(s, b'ATH0\r', b'OK\r\r>') # Headers OFF
|
|
|
|
|
|
|
|
|
|
send_compare(s, b'ATSP6\r', b"OK\r\r>") # Set Proto ISO 15765-4 (CAN 11/500)
|
|
|
|
|
sim.can_add_extra_noise(b'\x03\x41\x0E\xFA')# Inject message into the stream
|
|
|
|
|
sim.can_add_extra_noise(b'\x03\x41\x0E\xFA') # Inject message into the stream
|
|
|
|
|
send_compare(s, b'010D\r', b"410D53\r\r>") # Check it was ignored.
|
|
|
|
|
send_compare(s, b'0100\r', b"4100FFFFFFFE\r\r>") # Check it was ignored again.
|
|
|
|
|
finally:
|
|
|
|
@ -643,25 +643,25 @@ def test_elm_panda_safety_mode_ISO15765():
|
|
|
|
|
sync_reset(s) # Reset elm (which requests the ELM327 safety mode)
|
|
|
|
|
|
|
|
|
|
#29 bit
|
|
|
|
|
assert not did_send(p_elm, 0x18DB33F1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 1) #wrong canid
|
|
|
|
|
assert not did_send(p_elm, 0x18DB33F1, b'\x02\x01\x00', 0) #wrong length
|
|
|
|
|
assert not did_send(p_elm, 0x10000000, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr
|
|
|
|
|
assert not did_send(p_elm, 0x18DAF133, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr (phy addr)
|
|
|
|
|
assert not did_send(p_elm, 0x18DAF000, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr
|
|
|
|
|
assert not did_send(p_elm, 0x18DAF1F3, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr! (phys rsp to elm)
|
|
|
|
|
assert not did_send(p_elm, 0x18DB33F1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 1) # wrong canid
|
|
|
|
|
assert not did_send(p_elm, 0x18DB33F1, b'\x02\x01\x00', 0) # wrong length
|
|
|
|
|
assert not did_send(p_elm, 0x10000000, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr
|
|
|
|
|
assert not did_send(p_elm, 0x18DAF133, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr (phy addr)
|
|
|
|
|
assert not did_send(p_elm, 0x18DAF000, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr
|
|
|
|
|
assert not did_send(p_elm, 0x18DAF1F3, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr! (phys rsp to elm)
|
|
|
|
|
|
|
|
|
|
assert did_send(p_elm, 0x18DB33F1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #good! (obd func req)
|
|
|
|
|
assert did_send(p_elm, 0x18DA10F1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #good! (phys response)
|
|
|
|
|
assert did_send(p_elm, 0x18DB33F1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # good! (obd func req)
|
|
|
|
|
assert did_send(p_elm, 0x18DA10F1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # good! (phys response)
|
|
|
|
|
|
|
|
|
|
#11 bit
|
|
|
|
|
assert not did_send(p_elm, 0X7DF, b'\x02\x01\x00\x00\x00\x00\x00\x00', 1) #wrong canid
|
|
|
|
|
assert not did_send(p_elm, 0X7DF, b'\x02\x01\x00', 0) #wrong length
|
|
|
|
|
assert not did_send(p_elm, 0xAA, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr
|
|
|
|
|
assert not did_send(p_elm, 0x7DA, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr (phy addr)
|
|
|
|
|
assert not did_send(p_elm, 0x7E8, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #bad addr (sending 'response')
|
|
|
|
|
assert not did_send(p_elm, 0X7DF, b'\x02\x01\x00\x00\x00\x00\x00\x00', 1) # wrong canid
|
|
|
|
|
assert not did_send(p_elm, 0X7DF, b'\x02\x01\x00', 0) # wrong length
|
|
|
|
|
assert not did_send(p_elm, 0xAA, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr
|
|
|
|
|
assert not did_send(p_elm, 0x7DA, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr (phy addr)
|
|
|
|
|
assert not did_send(p_elm, 0x7E8, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # bad addr (sending 'response')
|
|
|
|
|
|
|
|
|
|
assert did_send(p_elm, 0x7DF, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #good! (obd func req)
|
|
|
|
|
assert did_send(p_elm, 0x7E1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) #good! (phys response)
|
|
|
|
|
assert did_send(p_elm, 0x7DF, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # good! (obd func req)
|
|
|
|
|
assert did_send(p_elm, 0x7E1, b'\x02\x01\x00\x00\x00\x00\x00\x00', 0) # good! (phys response)
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
s.close()
|
|
|
|
|