Services - tools - models - for embedded software development
Embecosm divider strip
Prev  Next

4.5.2.  Getting Packets

The packet reading function is get_packet (). It looks for a well formed packet, beginning with '$', with '#' at the end of data and a valid 2 byte checksum (see Figure 2.2 in Section 2.3 for packet representation details).

If a valid packet is found, '+' is returned using put_rsp_char () (see Section 4.5.3.1) and the packet is returned as a pointer to a struct rsp_buf. Otherwise '-' is returned and the loop repeated to get a new packet (presumably retransmitted by the client).

The buffer is statically allocated within get_packet (). This is acceptable, since two received packets cannot be in use simultaneously.

In general errors are silently ignored (the connection could be poor quality). However bad checksums are noted in a warning message. In the event of end of file being encountered, get_packet () returns immediately with NULL as result.

4.5.2.1.  Character Input

The individual characters are read using get_rsp_char (). The result is returned as an int, allowing -1 to be used to indicate end of file, or other error. In the event of end of file, or error, the client connection is closed and rsp.client_fd set to -1.

Embecosm divider strip