Embedded device data transmission management method and system
By introducing embedded device data transmission management methods between terminal devices, the problem of low data communication efficiency and reliability in the prior art is solved, and functions such as data subcontracting, error frame retransmission and automatic resolution are realized, and communication efficiency and data integrity are improved.
Patent Information
- Application Number
- CN202411777643.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-04-25
AI Technical Summary
The data communication efficiency and data reliability between existing terminal equipment and its modules are low, and long data sub-packages, message responses and data packet retransmission cannot be effectively handled, resulting in low communication efficiency and easy data loss.
A method for data transmission management of embedded equipment is proposed, including system power-up and resource initialization, data subcontracting judgment and frame formation, data transmission and response processing, and automatic analysis and verification of the receiver. This method supports data sub-channel transmission, error frame retransmission and automatic adaptation to data length changes, ensuring data integrity and correctness through frame header, end of frame and verification code.
It improves the efficiency and reliability of data communication between terminal devices, supports long data subcontracting and message response, ensures data integrity and correctness, and reduces the risk of communication errors and data loss.
Smart Images

Figure CN119892292A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data transmission, and in particular to a method and system for managing data transmission of an embedded device. Background Art
[0002] There is usually a need for data communication between terminal devices and modules. Serial communication is usually used in short-distance scenarios. When data is communicated between devices, a simple CRC check or even no check is generally used. The data message has no frame header or uses a simple frame header for synchronization. When data identical to the frame header appears in the data, it cannot be distinguished. When sending long data, data subpackaging is not supported. All transmission errors require retransmission. Both the sender and the receiver need a large enough data cache space. The data receiver needs to wait for the data to be received, and it is usually blind. After receiving the data, it is difficult for the application to determine whether the reception is complete and correct. The data content is complex to parse, and the communication efficiency and reliability are not guaranteed, which increases the difficulty of application development. At present, most of the terminal devices do not perform data encapsulation when communicating with each other. The sender directly sends the data content, and the receiver does not perform data verification. After receiving the data, it is directly parsed according to the agreed format. In this way, the receiver cannot verify when an error occurs. Even if it is judged as an error frame with the help of other business logic, the sender cannot perceive it. It does not support retransmission, and the receiver can only discard the data or re-request; or the SLIP protocol is used to encapsulate the data before communication, and the data frame is simply added with a frame header, a frame tail and FCS verification information before sending. The receiving end breaks the frame through the frame header and the frame tail, and uses FCS for validity verification. This method does not support channel transmission, different types of data cannot be isolated, does not support TLV format data packets, long data packetization, message response and data packet retransmission, is not conducive to data content extraction, wastes cache space, retransmits all data when an error occurs, reduces communication efficiency, does not support data packet caching mechanism, and data packets are lost when tasks cannot be processed in time. Therefore, it is urgent to propose a data transmission management method and system for embedded devices to solve the technical problems of low data communication efficiency and data reliability between existing terminal devices and their modules. Summary of the invention
[0003] The main purpose of the present invention is to provide an embedded device data transmission management method and system, aiming to solve the technical problems of low data communication efficiency and data reliability between existing terminal devices and their modules.
[0004] To achieve the above object, the present invention provides an embedded device data transmission management method, wherein the embedded device data transmission management method comprises the following steps:
[0005] S1, the system is powered on, and the serial port peripherals and management module resources are initialized;
[0006] S2, determine whether the data needs to be sub-packetized, and frame the data packets;
[0007] S3, the sending end calls the driver interface to send data, and determines whether it needs to wait for response information according to the sending type;
[0008] S4, the receiving end receives the data packet and stores it, reads the data of the data packet for automatic analysis, verifies the legitimacy of the data, and sends a response signal to the sending end if the verification is legal;
[0009] S5. The sending end receives the response signal and continues to send the next frame of data. Otherwise, it resends the current data frame.
[0010] In one of the preferred solutions, in step S2, the embedded device determines whether the data needs to be sub-packeted, specifically:
[0011] Set subcontracting thresholds;
[0012] The data length of the sent data is compared with the packetization threshold. If the length of the sent data is greater than the packetization threshold, the data is packetized and transmitted, and the data is encapsulated and escaped according to the data frame format agreed upon by the transmission protocol.
[0013] In one of the preferred solutions, the data frame format of the data packet includes:
[0014] Frame header, sequence number, packet number, data distribution channel, command code, data length, data content, generated checksum information and frame tail.
[0015] In one of the preferred solutions, before the sending end calls the driver interface to send data in step S3, the step further includes:
[0016] According to the data content of the data packet, the characters of the data that are the same as the frame header and frame tail are escaped.
[0017] In one of the preferred solutions, the receiving end receives and stores the data packet in step S4, specifically:
[0018] The receiving end receives the data packet, restores the data with character escapes in the data packet, stores the data items in the data packet into the circular buffer, breaks the frame according to the frame tail, and saves the storage address and length information of the received data packet into the SKB circular array in sequence.
[0019] In one of the preferred solutions, the data of the data packet is read and automatically parsed in step S4, specifically:
[0020] The receiving end reads the storage address and length information of the data packet from the SKB ring array, and then copies the data items of the data packet from the ring buffer area, and automatically parses the data distribution channel, sequence number, command code, data length, data content and check code of the data packet according to the state machine.
[0021] In one of the preferred solutions, the step S4 further includes:
[0022] If the data to be sent is identified as multi-packet data, storage space is requested based on the length of the sent data and the length of the currently received data is calculated. The data frame that needs a response is responded to. After all the data is received, the multi-packet reception is exited. If an error occurs during the reception process, the state machine receives again.
[0023] An embedded device data transmission management system comprises a management module, a metering module, an electric meter module and a Bluetooth module; the management module is connected to the metering module, the electric meter module and the Bluetooth module respectively; the metering module is used to collect voltage and current data; the electric meter module is used to collect user power consumption; the Bluetooth module is used to communicate with a handheld terminal device.
[0024] In one of the preferred solutions, the management module is connected to the Bluetooth module by using a UART serial port, the management module is connected to the electric meter module by using a 485 communication method, and the management module is connected to the metering module by using an SPI bus method.
[0025] In one of the preferred solutions, the Bluetooth module adopts one or more of a SWKY-BTO2 Bluetooth module, a NB-IOT module, a 4G module or a GPRS module.
[0026] In the above technical solution of the present invention, the embedded device data transmission management method includes the following steps: power on the system, initialize the serial port peripherals and management module resources; determine whether the data needs to be sub-packetized, and frame the data packet; the sending end calls the driver interface to send data, and determines whether it is necessary to wait for the response information according to the sending type; the receiving end receives the data packet and stores it, reads the data of the data packet for automatic analysis, verifies the legality of the data, and sends a response signal to the sending end if the verification is legal; the sending end receives the response signal and continues to send the next frame of data, otherwise, resends the current data frame. The present invention can automatically adapt to changes in data length, the length of single-time data transmission is not limited, and supports response and error frame retransmission, retransmits error frames when sending sub-packets, and has high communication efficiency, which solves the technical problems of low data communication efficiency and data reliability between existing terminal devices and their modules. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0028] Figure 1 A schematic diagram of a method for managing data transmission of an embedded device according to an embodiment of the present invention;
[0029] Figure 2 A schematic diagram of an embedded device data transmission management system according to an embodiment of the present invention;
[0030] Figure 3 This is a schematic diagram of data frame storage according to an embodiment of the present invention.
[0031] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with the implementation methods and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] Furthermore, the technical solutions between the various embodiments of the present invention may be combined with each other, but this must be based on the fact that they can be implemented by ordinary technicians in the field. When the combination of technical solutions is mutually contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0034] See also Figure 1-Figure 3 According to one aspect of the present invention, the present invention provides an embedded device data transmission management method, wherein the embedded device data transmission management method comprises the following steps:
[0035] S1, the system is powered on, and the serial port peripherals and management module resources are initialized;
[0036] S2, determine whether the data needs to be sub-packetized, and frame the data packets;
[0037] S3, the sending end calls the driver interface to send data, and determines whether it needs to wait for response information according to the sending type;
[0038] S4, the receiving end receives the data packet and stores it, reads the data of the data packet for automatic analysis, verifies the legitimacy of the data, and sends a response signal to the sending end if the verification is legal;
[0039] S5. The sending end receives the response signal and continues to send the next frame of data. Otherwise, it resends the current data frame.
[0040] Specifically, in this embodiment, in step S2, the embedded device determines whether the data needs to be subpacketized, specifically: setting a subpacketization threshold, comparing the data length of the sent data with the subpacketization threshold, if the length of the sent data is greater than the subpacketization threshold, the data is subpacketized and transmitted, and the data is encapsulated and escaped according to the data frame format agreed upon in the transmission protocol.
[0041] Specifically, in this embodiment, the data frame format of the data packet includes: a frame header, a sequence number, a packet number, a data distribution channel, a command code, a data length, a data content, a generated check code information and a frame tail; the data frame format of the data packet is not specifically limited by the present invention, and fields can be added or deleted as needed.
[0042] Specifically, in this embodiment, the data packet supports data transmission in different channels, isolation of different channels, supports data caching to avoid data loss, supports command parsing function, and automatically calls back the processing function of command registration, thereby improving communication security and ease of use.
[0043] Specifically, in this embodiment, before the sending end calls the driver interface to send data in step S3, the method further includes: performing character escape on the data identical to the frame header and the frame tail according to the data content of the data packet.
[0044] Specifically, in the present embodiment, in the step S4, the receiving end receives and stores a data packet, specifically, the receiving end receives the data packet, restores the data with character escapes in the data packet, stores the data items in the data packet into a circular buffer, breaks the frame according to the frame tail, and sequentially saves the storage address and length information of the received data packet into the SKB circular array; the data items include a frame header, a sequence number, a packet number, a data distribution channel, a command code, a data length, a data content, a generated checksum information and a frame tail; wherein the length information is the length of the entire data packet, and the data length is the length of the data content; the present invention adopts a dual circular buffer to cache the data and the SKB information separately, so that the receiving end can read the required data faster, save space and have higher reading efficiency.
[0045] Specifically, in this embodiment, the data of the data packet is read in step S4 for automatic parsing, specifically: the receiving end reads the storage address and length information of the data packet from the SKB ring array, and then copies the data items of the data packet from the ring buffer area, and automatically parses the data distribution channel, sequence number, command code, data length, data content and check code of the data packet according to the state machine.
[0046] Specifically, in this embodiment, the step S4 also includes: if the sent data is identified as multi-packet data, applying for storage space according to the length of the sent data and calculating the length of the currently received data, responding to the data frames that require a response, and exiting the multi-packet reception after all reception is completed. If an error occurs in the receiving process, the state machine receives again.
[0047] Specifically, in the present embodiment, the transmitting end waits for the response signal from the receiving end, and after confirming that a legal response signal has been received, continues to send the next frame of data; otherwise, the current data frame will be retransmitted if the waiting timeout expires, and the number of retransmissions will be set. If the number of retransmissions is exceeded, the transmission failure is returned. The present invention supports the function of retransmitting error frames during the communication process, thereby avoiding blind waiting and improving communication efficiency.
[0048] Specifically, in the present embodiment, the system is powered on, the management module, the system kernel and the peripheral module are initialized, the application program calls the data transmission interface, determines whether the data is transmitted in packets according to the length of the transmitted data and the set packetization threshold, and encapsulates and escapes the data according to the data frame format agreed upon in the transmission protocol; after receiving the data, the receiving end stores it in the circular buffer area, restores the escaped data, packets the received data according to the frame header and frame tail flags, stores the entire packet of data in the SKB circular array, performs parsing and rationality verification when reading the data, responds or does not respond according to the data frame type and the verification result, and then calls back to process the received command and data; after receiving the response data, the sending end continues to send the next data packet or repeats the sending of the current data packet; the sending end application is not limited in the length of data sent at a time, can automatically adapt to changes in data length, automatically completes packetization and receiving merging, and meets the requirements of different scenarios; the present invention supports multiple verification methods, and ensures the integrity and correctness of the data by verifying the legitimacy of the data.
[0049] According to another aspect of the present invention, the present invention provides an embedded device data transmission management system, comprising a management module, a metering module, an electric meter module and a Bluetooth module; the management module is connected to the metering module, the electric meter module and the Bluetooth module respectively; the metering module is used to collect voltage and current data; the electric meter module is used to collect user power consumption; the Bluetooth module is used to communicate with a handheld terminal device.
[0050] Specifically, in this embodiment, the management module is connected to the Bluetooth module using a UART serial port, the management module is connected to the electric meter module using a 485 communication method, and the management module is connected to the metering module using an SPI bus method.
[0051] Specifically, in this embodiment, the Bluetooth module adopts one or more of a SWKY-BTO2 Bluetooth module, a NB-IOT module, a 4G module or a GPRS module.
[0052] Specifically, in this embodiment, in the present invention, the management module adopts an MCU module of model HC32F460JETA, the metering module adopts a metering chip of model RN7032, and the power module adopts a two-box power meter. The present invention does not make specific limitations and can be set according to needs.
[0053] In order to facilitate the understanding of the relevant terms of the present invention, an explanation is given here:
[0054] SLIP: SLIP protocol refers to Serial Line Internet Protocol, which is the earliest and one of the only two serial IP protocols.
[0055] Communication protocol: Communication protocol refers to the rules and agreements that two entities must follow to complete communication or service. In order for multiple data communication systems in different geographical locations to be able to work together to achieve information exchange and resource sharing, they must have a common language. What to communicate, how to communicate, and when to communicate must follow certain mutually acceptable rules, which are communication protocols.
[0056] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. All equivalent structural changes made using the contents of the present invention's specification and drawings, or directly / indirectly applied in other related technical fields, are included in the patent protection scope of the present invention.
Claims
1. A method for managing data transmission of an embedded device, characterized in that: The following steps are involved: S1, the system is powered on, and the serial port peripherals and management module resources are initialized; S2, determine whether the data needs to be sub-packetized, and frame the data packets; S3, the sending end calls the driver interface to send data, and determines whether it needs to wait for response information according to the sending type; S4, the receiving end receives the data packet and stores it, reads the data of the data packet for automatic analysis, verifies the legitimacy of the data, and sends a response signal to the sending end if the verification is legal; S5. The sending end receives the response signal and continues to send the next frame of data. Otherwise, it resends the current data frame.
2. The method for managing data transmission of an embedded device according to claim 1, characterized in that: In step S2, the embedded device determines whether the data needs to be sub-packed, specifically: Set subcontracting thresholds; The data length of the sent data is compared with the packetization threshold. If the length of the sent data is greater than the packetization threshold, the data is packetized and transmitted, and the data is encapsulated and escaped according to the data frame format agreed upon by the transmission protocol.
3. A method for managing data transmission of an embedded device according to any one of claims 1 to 2, characterized in that: The data frame format of the data packet includes: Frame header, sequence number, packet number, data distribution channel, command code, data length, data content, generated checksum information and frame tail.
4. The method for managing data transmission of an embedded device according to claim 3, characterized in that: Before the sending end calls the driver interface to send data in step S3, the method further includes: According to the data content of the data packet, the characters of the data that are the same as the frame header and frame tail are escaped.
5. The method for managing data transmission of an embedded device according to claim 3, characterized in that: In step S4, the receiving end receives and stores the data packet, specifically: The receiving end receives a data packet, restores the data with character escapes in the data packet, stores the data items in the data packet into a circular buffer, breaks the frame according to the frame tail, and saves the storage address and length information of the received data packet into the SKB circular array in sequence; the data items include a frame header, a sequence number, a packet number, a data distribution channel, a command code, a data length, a data content, a generated checksum information and a frame tail.
6. The method for managing data transmission of an embedded device according to claim 5, characterized in that: The data of the data packet is read and automatically parsed in step S4, specifically: The receiving end reads the storage address and length information of the data packet from the SKB ring array, and then copies the data items of the data packet from the ring buffer area, and automatically parses the data distribution channel, sequence number, command code, data length, data content and check code of the data packet according to the state machine.
7. The method for managing data transmission of an embedded device according to any one of claims 1 to 2, characterized in that: The step S4 further includes: If the data to be sent is identified as multi-packet data, storage space is requested based on the length of the sent data and the length of the currently received data is calculated. The data frame that needs a response is responded to. After all the data is received, the multi-packet reception is exited. If an error occurs during the reception process, the state machine receives again.
8. A system comprising the embedded device data transmission management method according to any one of claims 1 to 7, characterized in that: Including management module, metering module, electric meter module and Bluetooth module; The management module is connected to the metering module, the electric meter module and the Bluetooth module respectively; the metering module is used to collect voltage and current data; the electric meter module is used to collect user power consumption; and the Bluetooth module is used to communicate with a handheld terminal device.
9. The embedded device data transmission management system according to claim 8, characterized in that: The management module is connected to the Bluetooth module by using a UART serial port, the management module is connected to the electric meter module by using a 485 communication method, and the management module is connected to the metering module by using an SPI bus method.
10. The method for managing data transmission of an embedded device according to claim 8, characterized in that: The Bluetooth module adopts one or more of SWKY-BTO2 Bluetooth module, NB-IOT module, 4G module or GPRS module.