3.5. Level 4
Level4 defines UART communication routines.
3.5.1. PC -> Reader
Incoming bytes are stored in a circular buffer. Function CheckIncommingMessage (see Figure 2 Check Incoming Message) analyses the content of incoming circular buffer which contains incoming bytes. This function loop implements a final state machine with following states: UART_EMPTY - no bytes are pending, UART_READ_SIZE - analysing incoming message size from pending bytes, UART_READ_BYTES - analysing body and ETX of message from pending bytes,
UART_WAIT_ERROR_SENT - error state, UART_VALID - valid message format is found.
Wrong start message symbol (byte ≠ STX = 02h) causes immediate error response. Zero bytes received prior the valid STX byte are ignored. Thus, if no response occurs by defined time-out, by means of sending zero bytes to the reader the internal buffer can be forced to overflow to detect any possible firmware lock-up.
Valid message is parsed in function level4/ParseMessage() (see Figure 3 Parse Message (level4.c)). Valid message length is checked and message useful information is copied into appropriate variables.