Protocol Design for serial communication engineering notes

Source: Internet
Author: User

The serial communication protocol designed below is used to complete dual-machine InterconnectionProgram(SPCP. The design concept is based on the pillow frame transmission mode, that is, when sending data to the serial port, it is sent one frame at a time. In order to ensure reliable transmission, a connection is established through a handshake. In the transmission of each frame, the transmission, response, reconnection, and failure modes are used.

I. frame format

Dual-host interconnection uses three types of frames: Control Frame, data frame, and phrase frame. Control Frames and data frames are used for file transmission, and phrase frames are used for short message sending.

1.Data Frame

Including frame header, load data, and checksum. The first six bytes of the frame, as shown in. Count indicates the number of bytes of the load data, and check1 indicates the checksum of 2nd and 3rd bytes.

0

1

2

3

4

5

0x00

0x00

Count

Check1

Figure 1 data frame Header

The load data is Count bytes long and cannot exceed 0 x bytes at most. The Checksum occupies 2 bytes, which is the structure for calculating the checksum for the load data.

2.Control Frame

The Control Frame and control signal work together to complete the communication synchronization and control task. It has only the frame header, and the length is 6 bytes.

0

1

2

3

4

5

0x00

0x01

Npack

Check2

Figure 2 transmission Start Control Frame

Npack indicates the total number of frames sent during the transmission, so that the receiver can control the progress. check2 is the checksum of the second and second bytes. When npack = check2 = 0, it indicates that the transmission is complete. When the receiver receives the frame, the transmission ends no matter whether or not it has received the number of frames receivable. If no transmission error occurs, only two Control Frames are displayed for one transmission. The first transmission starts and the second transmission ends.

3.Phrase Frame

The load in the phrase frame is text data. No connection or error control is required for sending and receiving the frame, but a synchronization signal is inserted at the frame header and end.

0x03

Text Data

0x03

Figure 3 phrase Frame Structure

Ii. Control Signals

To improve communication efficiency, SPCP uses control signals for communication synchronization and correction of various control figures. SPCP defines the control signal in 6:

Const byte SYN [1] = {0x1}; // request

Const byte Ack [1] = {0x2}; // response

Const byte resend [1] = {0x4}; // resend

Const byte busy [1] = {0x7}; // busy

Const byte Bye [3] = {6, 0, 6}; // disconnect

Const byte STR [1] = {0x3}; // Short Message synchronization signal

Iii. data frame splitting and data restructuring

The data sent by the application is split into frames by SPCP as a stream. After cutting, the frame header and checksum are added to each frame and placed in the internal buffer zone of SPCP for sending. at the receiving end, frame sharding data removes the frame header and returns it to the receiving buffer stream, which is received by the application.

Figure 4 data frame Splitting Process

Figure 5 data restructuring process

Iv. transmission process

Before sending data, the SPCP sender splits the data that the application wants to send into frames and then communicates according to the following steps.

1.Handshake

    1. The sender sends the SYN signal and waits for feedback;
    2. The receiving end returns an ACK signal after receiving SYN;
    3. After receiving the ACK signal, the sender controls the first frame;
    4. After receiving the first frame of the control, if the checksum is incorrect, the system sends a resend signal and repeats steps C ~ D. If yes, send an ACK signal;
    5. After receiving the ACK signal, the sender forwards it to step a of data transmission 2.

2.Data Transmission

    1. The sender sends the I frame header and waits for feedback. If the sender finds that the frame is an end frame, it is switched to Step 3 to disconnect;
    2. After receiving the frame header, the receiving end sends a resend signal when the frame length checksum is incorrect, and repeat steps a ~ B. If yes, send an ACK signal;
    3. If the sender receives the ACK signal, the data in the sent frame and the checksum are sent;
    4. After receiving the data, the receiving end sends a resend signal when the data checksum is incorrect, and repeat steps C ~ D. If yes, send an ACK signal;
    5. If the sender receives the ACK signal, the frame data is sent successfully. The sender sends a SYN signal to start the handshake of the next frame;
    6. If the receiving end receives the SYN signal, the ACK signal is sent for confirmation;
    7. If the sender receives the ACK signal, repeat ~ Step E: transfer the next frame.

3.Disconnect

    1. The sender controls the end frame and prepares to end the communication;
    2. If the receiving end frame receives the control, an ACK signal is sent to end the communication;
    3. If the sender receives the ACK signal, the bye control signal is sent;
    4. If the receiver receives the bye signal, the connection is removed and the ACK signal is sent;
    5. After the sender receives the ACK signal, the connection is removed.

Note: timeout processing exists in all the steps in the preceding three phases, that is, if a communication party does not receive a response within a limited time period, the connection will be disconnected and the communication will end. In addition, if the number of resends caused by an error exceeds three times, the communication will be interrupted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.