forked from Overdrivr/DistantIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_Protocol_only_example.py
73 lines (57 loc) · 1.48 KB
/
01_Protocol_only_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright (C) 2014 Rémi Bèges
# For conditions of distribution and use, see copyright notice in the LICENSE file
# Test of the protocol algorithm with dummy frames
from API.Protocol import Protocol
def build_rx_value():
print("RX test started.")
c = bytearray()
#SOF
c.append(int('f7',16))
#CMD
c.append(int('00',16))
#DATATYPE
c.append(int('00',16))
#DATAID
c.append(int('00',16))
c.append(int('7D',16))#ESC EOF char
c.append(int('7f',16))
#VALUE
c.append(int('05',16))
c.append(int('7D',16))#ESC SOF char
c.append(int('f7',16))
c.append(int('E4',16))
c.append(int('7D',16))#ESC ESC char
c.append(int('7D',16))
#EOF
c.append(int('7f',16))
print("RX :",c)
return c
def build_tx_value():
print("TX test started.")
c = bytearray()
#CMD
c.append(int('00',16))
#DATATYPE
c.append(int('00',16))
#DATAID
c.append(int('00',16))
c.append(int('7f',16))
#VALUE
c.append(int('05',16))
c.append(int('f7',16))
c.append(int('E4',16))
c.append(int('7D',16))
return c
def on_new_payload(rxpayload):
print("TX :",rxpayload)
if __name__ == '__main__':
# Create protocol and give callback function
protocol = Protocol(on_new_payload)
# Test to decode
for c in build_rx_value():
protocol.decode(c)
# Test to encode
tx = protocol.encode(build_tx_value())
build_rx_value()
print("TX :",tx)
print("Done.")