Commit 64f39612 authored by Marlene Böhmer's avatar Marlene Böhmer

Extended Test

parent 947ef15a
......@@ -5,15 +5,22 @@ import serial
MTU = 32
START_BYTE1 = 0xbc
START_BYTE2 = 0xcf
START = [START_BYTE1, START_BYTE2]
SYSLINK_RADIO_RAW = 0x00
received_data = []
ser = serial.Serial("/dev/ttyS0", 115200)
def compute_cksum(list):
cksum0, cksum1 = 0, 0
for i in list:
cksum0 = (cksum0 + i) & 0xff
cksum1 = (cksum1 + cksum0) & 0xff
return [cksum0, cksum1]
while True:
received_data = map(ord, list(ser.read_until(chr(START_BYTE1))))
received_data = map(ord, list(ser.read_until(chr(START_BYTE1)))[-1:])
received_data += map(ord, list(ser.read(1)))
if received_data[1] != START_BYTE2:
print("ERROR START")
......@@ -25,16 +32,20 @@ while True:
continue
received_data += map(ord, list(ser.read(received_data[3]+2)))
cksum0 = 0
cksum1 = 0
for c in received_data[2:-2]:
cksum0 = (cksum0 + c) & 0xff
cksum1 = (cksum1 + cksum0) & 0xff
if cksum0 != received_data[-2] or cksum1 != received_data[-1]:
cksum = compute_cksum(received_data[2:-2])
if cksum[0] != received_data[-2] or cksum[1] != received_data[-1]:
print("ERROR CKSUM")
continue
print(" ".join("{:#04x}".format(n) for n in received_data))
out_data = [1, 2]
pk = [1, 2]
header = [SYSLINK_RADIO_RAW, len(pk)]
out_data = [START_BYTE1, START_BYTE2]
out_data += header
out_data += pk
out_data += compute_cksum(header+pk)
written = ser.write(bytearray(out_data))
print(written)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment