Commit b02bc808 authored by Marlene Böhmer's avatar Marlene Böhmer

adapt scripts for new serial Uri

parent 7897e18b
......@@ -123,7 +123,7 @@ if __name__ == '__main__':
bridge.stop()
sys.exit(0)
serial_uri = 'serial://pi'
serial_uri = 'serial://ttyAMA0'
prrt_uri = 'prrt://' + sys.argv[1] + ':5000'
bridge = Bridge(serial_uri, prrt_uri)
......
......@@ -17,7 +17,7 @@ if len(sys.argv) >= 2:
ip = sys.argv[2]
URI = 'prrt://' + ip + ':5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
URI = 'serial://ttyAMA0'
else:
sys.exit('Give a valid argument.')
else:
......
......@@ -17,7 +17,7 @@ if len(sys.argv) >= 2:
ip = sys.argv[2]
URI = 'prrt://' + ip + ':5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
URI = 'serial://ttyAMA0'
else:
sys.exit('Give a valid argument.')
else:
......
......@@ -17,7 +17,7 @@ if len(sys.argv) >= 2:
ip = sys.argv[2]
URI = 'prrt://' + ip + ':5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
URI = 'serial://ttyAMA0'
else:
sys.exit('Give a valid argument.')
else:
......
......@@ -17,7 +17,7 @@ if len(sys.argv) >= 2:
ip = sys.argv[2]
URI = 'prrt://' + ip + ':5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
URI = 'serial://ttyAMA0'
else:
sys.exit('Give a valid argument.')
else:
......
......@@ -17,7 +17,7 @@ if len(sys.argv) >= 2:
ip = sys.argv[2]
URI = 'prrt://' + ip + ':5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
URI = 'serial://ttyAMA0'
else:
sys.exit('Give a valid argument.')
else:
......
#!/usr/bin/python
import serial
MTU = 32
START_BYTE1 = 0xbc
START_BYTE2 = 0xcf
SYSLINK_RADIO_RAW = 0x00
received_data = []
ser = serial.Serial(port="/dev/ttyS0", baudrate=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 = bytearray()
received_data += ser.read_until(bytes([START_BYTE1]))[-1:]
received_data += ser.read(1)
if received_data[1] != START_BYTE2:
print("ERROR START")
continue
received_data += ser.read(2)
if received_data[3] > MTU:
print("ERROR LENGTH")
continue
received_data += ser.read(received_data[3]+2)
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))
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(bytes(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