This folder contains several code examples of how to use python4yahdlc.
The code examples work in pairs: send_data_frame.py works with receive_data_frame.py and fsm_endpoint_1.py works with fsm_endpoint_2.py.
To make the two code examples of each pair work together, you need a serial bus of communication. The easiest way to set up a serial bus is to use a virtual one. socat is a great tool for carrying out this task:
socat -d -d pty,raw,echo=0 pty,raw,echo=0This command will create two virtual devices (e.g. /dev/pts/5 and
/dev/pts/6). Everything you write in one will be echoed in the other and
vice versa.
These two code examples need pyserial as dependency:
pip install --upgrade pyserialThese two code examples need pyserial and fysom as dependencies:
pip install --upgrade pyserial fysomfysom is used to define the Finite-State Machines (FSM) of the two
endpoints.
The sending FSM endpoint:
stateDiagram-v2
init --> send_data: connection_ok
init --> init: connection_ko
send_data --> wait_ack: send_ok
wait_ack --> pause: ack_received
wait_ack --> send_data: nack_received
wait_ack --> send_data: timeout
wait_ack --> pause: bad_frame_received
pause --> send_data: timeup
The receiving FSM endpoint:
stateDiagram-v2
init --> wait_data: connection_ok
init --> init: connection_ko
wait_data --> send_ack: data_ok
wait_data --> send_nack: data_ko
send_ack --> wait_data: ack_sent
send_nack --> wait_data: nack_sent