CN114650217A - Serial port received data processing method, device, equipment and medium - Google Patents

Serial port received data processing method, device, equipment and medium Download PDF

Info

Publication number
CN114650217A
CN114650217A CN202210544545.3A CN202210544545A CN114650217A CN 114650217 A CN114650217 A CN 114650217A CN 202210544545 A CN202210544545 A CN 202210544545A CN 114650217 A CN114650217 A CN 114650217A
Authority
CN
China
Prior art keywords
data
received
length
framing area
updated
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210544545.3A
Other languages
Chinese (zh)
Inventor
朱印
曹湘飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Changsha Bamboo Leaf Electronic Technology Co ltd
Original Assignee
Changsha Bamboo Leaf Electronic Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Changsha Bamboo Leaf Electronic Technology Co ltd filed Critical Changsha Bamboo Leaf Electronic Technology Co ltd
Priority to CN202210544545.3A priority Critical patent/CN114650217A/en
Publication of CN114650217A publication Critical patent/CN114650217A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0677Localisation of faults
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Communication Control (AREA)

Abstract

The application relates to a serial port received data processing method and device, computer equipment and a storage medium. The method comprises the following steps: acquiring data to be received; the data to be received comprises a frame header, a payload length and other data; judging the current state of the data to be received, and storing the data to be received into a framing area according to a judgment result to obtain an updated framing area and the received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data; verifying the received data by using the checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port. By adopting the method, the serial port data processing efficiency can be improved.

Description

Serial port received data processing method, device, equipment and medium
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a method and an apparatus for processing serial received data, a computer device, and a storage medium.
Background
With the development of serial communication technology, in order to improve the reliability of a serial port receiving program, the most common practice at present is to add a data frame header before the sent effective serial port data content and add a data frame tail or a data checksum after the sent effective serial port data content when a serial port protocol message is prepared. In the process of serial communication, a receiver of serial data must analyze the received serial data, namely, find a data frame header and a data frame tail from the received serial data, calculate a data checksum, and finally extract the effective serial data content of each frame.
However, most of the current serial port receiving functions directly judge that the receiving is completed after capturing the frame head and the frame tail when processing data, the existing serial port data processing has extremely low portability and maintainability, when the frame head and the frame tail change in length and content, the serial port receiving functions have huge workload for processing data, and have the risk of causing other bugs at the same time of low efficiency.
Disclosure of Invention
Therefore, it is necessary to provide a serial received data processing method, device, computer device and storage medium capable of improving the efficiency of serial data processing.
A serial port received data processing method comprises the following steps:
acquiring data to be received; the data to be received comprises a frame header, a payload length and other data;
judging the current state of the data to be received, and storing the data to be received into a framing area according to a judgment result to obtain an updated framing area and the received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
verifying the received data by using the checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port.
In one embodiment, the determining the current state of the data to be received, and storing the data to be received in the framing area according to the determination result to obtain the updated framing area and the received data includes:
respectively receiving the data to be received according to the current state of the data to be received to obtain an updated framing area and the received data;
if the current state of the data to be received is a waiting frame head and the frame head is equal to the data of the receiving buffer area, the frame head in the data to be received is received, the frame head is stored in a framing area, the pointer address and the number of the received bytes in the framing area are respectively added by one, and the data of the updated framing area and the received frame head are obtained.
In one embodiment, if the current state of the data to be received is the waiting frame header and the frame header is not equal to the data in the receiving buffer, the data to be received is discarded, the data in the framing area is cleared, the framing function is reset, and the next time the frame header data is received, the method starts to be performed.
In one embodiment, the length of the frame header in the updated framing area is determined, and if the length of the bytes received in the updated framing area is greater than the length of the frame header, the state of the data to be received is switched to the length of the payload.
In one embodiment, if the current state of the data to be received is the received payload length, the payload length in the data to be received is received, the payload length is stored in a framing area, and the pointer address and the number of the received bytes in the framing area are respectively added by one to obtain the updated framing area and the data of the received payload length;
judging the length of a frame header in the updated framing area, and if the length of a received byte in the updated framing area is the same as the length of a payload and the length of the payload is the same as two bits behind the frame header, switching the state of data to be received into the state of receiving other data; if the payload length is different from the two bits behind the frame header, discarding the data to be received, resetting the framing area data, resetting the framing function, and starting to wait for the next time of receiving the frame header data; other data includes end of frame and real data.
In one embodiment, if the current state of the data to be received is to receive other data, receiving a frame tail and real data in the data to be received, storing the frame tail and the real data into a framing area, and adding one to each of an address of a pointer and the number of bytes received in the framing area to obtain an updated framing area and the received data;
and judging the length of the received bytes in the updated framing area, and if the length of the received bytes is equal to that of the data to be received, switching the state of the data to be received into data verification.
In one embodiment, verifying the received data by using a checksum in the updated framing area, and determining whether the received data is normally received according to a verification result to obtain the normally received data includes:
and verifying the received data by using a checksum in the updated framing area, if the length of the tail of the received data is effective, adding the length of the received data after removing the frame head, the frame tail and all values except the checksum, comparing the summed low eight bits with the checksum, and if the checksum is equal to the summed low eight bits, judging that the received data is normally received to obtain normally received data.
A serial port reception data processing apparatus, the apparatus comprising:
the data acquisition module is used for acquiring data to be received; the data to be received comprises a frame header, a payload length and other data;
the data processing module is used for judging the current state of the data to be received and storing the data to be received into the framing area according to the judgment result to obtain an updated framing area and the received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
the data verification module is used for verifying the received data by using the checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port.
A computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
acquiring data to be received; the data to be received comprises a frame header, a payload length and other data;
judging the current state of the data to be received, and storing the data to be received into a framing area according to a judgment result to obtain an updated framing area and the received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
verifying the received data by using the checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
acquiring data to be received; the data to be received comprises a frame header, a payload length and other data;
judging the current state of the data to be received, and storing the data to be received into a framing area according to a judgment result to obtain an updated framing area and the received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
verifying the received data by using the checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port.
According to the serial port received data processing method, the serial port received data processing device, the computer equipment and the storage medium, firstly, data to be received are obtained, the current state of the data to be received is judged, the data to be received is stored in a framing area according to the judgment result, and an updated framing area and the received data are obtained; the current state comprises waiting for frame header, receiving payload length, receiving other data and data verification, verifying the received data by using a checksum in the updated framing area, and judging whether the received data is normally received according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port. The method has the advantages that the received data are subjected to state division, data are received and stored in the framing area according to the state of the data to be received independently, all links are mutually independent, only the corresponding links need to be modified according to the current state of the data when the data are transplanted, integral modification is not needed, the workload is reduced, the serial port data processing efficiency is improved, meanwhile, when the program is transplanted and maintained, faults in the positioning data can be located and checked quickly and effectively, the development time is greatly shortened, the data are subjected to state division, all links are mutually independent, and when the transplanting work is carried out, the generation of BUG can be greatly reduced.
Drawings
Fig. 1 is a schematic flow chart of a serial port received data processing method in an embodiment;
FIG. 2 is a block diagram illustrating an exemplary serial port received data processing apparatus;
FIG. 3 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
In one embodiment, as shown in fig. 1, a serial port received data processing method is provided, which includes the following steps:
step 102, acquiring data to be received; the data to be received includes a frame header, a payload length, and other data.
The other data comprises a frame tail and real data, the beginning of a section of data is called a frame head, the end of the section of data is called a frame tail, the beginning of the section of data is called a frame head, the end of the section of data is called a frame tail, the section of data and the frame tail are both customized by two communication parties, the length and the content are both customized, as long as the two communication parties can keep the same, the payload length represents the sum of the lengths of the section of data except the frame head, the frame tail and the real data, and the real data refers to data which the two communication parties need to interact.
Step 104, judging the current state of the data to be received, and storing the data to be received into a framing area according to a judgment result to obtain an updated framing area and received data; the current state includes waiting for the frame header, receiving the payload length, receiving other data, and data verification.
The current state of the data to be received comprises four states of waiting for a frame head, receiving payload length, receiving other data and data verification, the data processing process corresponding to each state is different, when the data to be received is processed, firstly judging whether the frame head is correct or not, storing the data into a framing area, when the content and the length of the frame head are correct, the data starts to enter the next step, receiving the payload length, storing the payload length into the framing area, after the payload length is received, receiving other data such as a check code and a frame tail, storing the other data into the framing area, finally, after the receiving is finished, calculating the checksum and verifying whether the frame tail is correct or not, when any link is abnormal, discarding the data, clearing the data in the framing area, resetting a framing function, and starting to wait for next receiving the frame head data. The method has the advantages that data are received and stored in the framing area independently according to the state of data to be received, all links are independent, only the corresponding links need to be modified according to the current state of the data when data are transplanted, integral modification is not needed, workload is reduced, serial port data processing efficiency is improved, meanwhile, faults in the data can be located and checked quickly and effectively by using the method when program transplanting and maintaining work is carried out, development time is greatly shortened, the data are divided into states, all links are independent, and generation of BUG can be greatly reduced when transplanting work is carried out.
Step 106, verifying the received data by using a checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port.
The checksum represents a piece of data that verifies whether the data is correct, and is used in the field of data processing and data communication to verify the sum of a set of data items at a destination. It is usually in the form of a hexadecimal system. If the checksum value exceeds hexadecimal FF, i.e., 255, the complement of the checksum is required, often to ensure data integrity and accuracy in communications, especially over long distances.
In the method for processing the serial port received data, firstly, data to be received is obtained, the current state of the data to be received is judged, the data to be received is stored in a framing area according to the judgment result, and an updated framing area and the received data are obtained; the current state comprises waiting for frame header, receiving payload length, receiving other data and data verification, verifying the received data by using a checksum in the updated framing area, and judging whether the received data is normally received according to a verification result to obtain normally received data; and receiving normal data as a data processing result received by the serial port. According to the method, the received data are subjected to state division, data are received and stored in the framing area according to the state of the data to be received, all links are mutually independent, only the corresponding links need to be modified according to the current state of the data when the data are transplanted, the whole modification is not needed, the workload is reduced, the serial port data processing efficiency is improved, meanwhile, when the program is transplanted and maintained, faults in the positioning data can be found and checked quickly and effectively by using the method, the development time is greatly shortened, the data are subjected to state division, all links are mutually independent, and when the transplanting work is carried out, the generation of BUG can be greatly reduced.
In one embodiment, the determining the current state of the data to be received, and storing the data to be received in the framing area according to the determination result to obtain the updated framing area and the received data includes:
respectively receiving the data to be received according to the current state of the data to be received to obtain an updated framing area and the received data;
and if the current state of the data to be received is the waiting frame head and the data of the frame head is equal to the data of the receiving buffer area, receiving the frame head in the data to be received, storing the frame head into a framing area, and adding one to each of the pointer address and the number of the received bytes in the framing area to obtain the updated data of the framing area and the received frame head. The receiving buffer area is a place where the program automatically stores the received data every time, is realized through a library function of the program, does not need manual processing, judges the data to be received, receives a frame header in the data to be received if the current state of the data to be received is a waiting frame header and the frame header is equal to the data of the receiving buffer area, stores the frame header into the framing area, and directly discards the section of data if not.
In one embodiment, if the current state of the data to be received is the waiting frame header and the frame header is not equal to the data in the receiving buffer, the data to be received is discarded, the data in the framing area is cleared, the framing function is reset, and the next time the frame header data is received, the method starts to be performed.
The framing function is used for framing the data in the framing area, and the process of resetting the framing function comprises the steps of clearing the data in the framing area and clearing the pointer address in the framing area.
In the specific embodiment, each time data of one byte is received, judgment is carried out, the data is put into the cache array when the conditions are met, if the transmission of the whole data section is completed, the data stored in the cache array is taken out, if a certain byte does not meet the requirements, the framing function is reset, the cache array is cleared, meanwhile, the pointer of the array is also cleared, the next received data meeting the requirement of the starting signal can be stored in the head of the cache array, compared with the advantage that the whole data is stored in the array, resources are saved, and meanwhile when the data is abnormal, the abnormal data can be timely discarded, and the normal data can be automatically intercepted. For example, if a 3-byte data AA 00 BB frame header is AA, a frame tail is BB, and the data length is 3, if the transmission is abnormal at this time and becomes AA 00 BB, a whole storage mode will store AA 00 AA in the array, then determine that the data is abnormal, discard the data, then store 00 BB in the array, find that the frame header is not satisfied, discard the data, so that the whole segment is not available, automatically remove the first AA 00 through a framing function, and read the AA 00 BB.
In one embodiment, the length of the frame header in the updated framing area is determined, and if the length of the bytes received in the updated framing area is greater than the length of the frame header, the state of the data to be received is switched to the length of the payload.
In one embodiment, if the current state of the data to be received is the received payload length, the payload length in the data to be received is received, the payload length is stored in a framing area, and the pointer address and the number of the received bytes in the framing area are respectively added by one to obtain the updated framing area and the data of the received payload length;
judging the length of a frame header in the updated framing area, and if the length of a received byte in the updated framing area is the same as the length of a payload and the length of the payload is the same as two bits behind the frame header, switching the state of data to be received into the state of receiving other data; if the payload length is different from the two bits behind the frame header, discarding the data to be received, resetting the framing area data, resetting the framing function, and starting to wait for next frame header data reception; other data includes end of frame and real data.
In a specific embodiment, the length of a frame header in an updated framing area is judged, if the length of a received byte in the updated framing area is the same as that of a payload, the received length of the payload is proved, if the length of the payload is the same as two bits behind the frame header, the length of the received payload is proved to be correct, the data is judged to be correct, other data can be continuously received, the state of the data to be received is switched, and if the length of the payload is not the same as the two bits behind the frame header, the data is incorrect, a framing function is reset, and the next time of receiving frame header data is waited.
In one embodiment, if the current state of the data to be received is to receive other data, receiving a frame tail and real data in the data to be received, and storing the frame tail and the real data into a framing area, wherein the pointer address and the number of received bytes in the framing area are respectively added by one to obtain an updated framing area and the received data;
and judging the length of the received bytes in the updated framing area, and if the length of the received bytes is equal to that of the data to be received, switching the state of the data to be received into data verification.
In a specific embodiment, if the length of the received byte is equal to the length of the data to be received, the data received this time is proved to be complete data to be received, and data verification can be directly performed to determine whether the received data is correct.
In one embodiment, verifying the received data by using a checksum in the updated framing area, and determining whether the received data is normally received according to a verification result to obtain the normally received data includes:
and verifying the received data by using a checksum in the updated framing area, if the length of the tail of the received data is effective, adding the length of the received data after removing the frame head, the frame tail and all values except the checksum, comparing the summed low eight bits with the checksum, and if the checksum is equal to the summed low eight bits, judging that the received data is normally received to obtain normally received data.
If the checksum and the low eight bits of the summation are not equal, discarding the received data, clearing the data in the framing area, resetting the framing function, and starting to wait for the next frame header data reception.
In the specific embodiment, only real data are left after the length of the received data is removed from a frame head, a frame tail and all values except a checksum, the lower eight bits of the real data are taken to be compared with the checksum, and if the checksum is equal to the summed lower eight bits, the received data is judged to be normally received, and the normally received data is obtained. The check sum is higher in digit, the error is less prone to occur, when data are sent, the check sum is sent by taking one byte as a unit, 2 bytes and 3 bytes or even 7-8 bytes can be used for calculation, resources are wasted by the method, the check sum is found to be most reasonable by taking 8 bits through experiments under the condition that the load of a computer is not increased, the low eight bits are selected to be more reasonable than the high eight bits when the digit is selected, for example, the data to be received are 16 bits, the check sum is 10, if the high eight bits are taken, the low eight bits are 00000000, and the low eight bits are 00000010.
In one embodiment, the tail length in the received data is verified in the updated framing area, and the tail [ x ] array and the tail array are compared to determine whether they are consistent, and if so, the tail length is valid. If the frame head data is inconsistent with the frame tail data, the frame tail length is invalid, the data to be received is discarded, the framing area data is cleared, the framing function is reset, and the next time the frame head data is received, the frame tail length is invalid. the tail [ x ] array is preset as a verification code according to the specific verification requirement in the example, when the received data is the same as the received data, the data is valid, otherwise, the data is invalid.
It should be understood that, although the steps in the flowchart of fig. 1 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 1 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in fig. 2, there is provided a serial port reception data processing apparatus including: a data acquisition module 202, a data processing module 204, and a data verification module 206, wherein:
a data obtaining module 202, configured to obtain data to be received; the data to be received comprises a frame header, a payload length and other data;
the data processing module 204 is configured to determine a current state of the data to be received, and store the data to be received in the framing area according to a determination result, so as to obtain an updated framing area and received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
a data verification module 206, configured to verify the received data with a checksum in the updated framing area, and determine whether the received data is received normally according to a verification result, so as to obtain normally received data; and receiving normal data as a data processing result received by the serial port.
In one embodiment, the data processing module 204 is further configured to determine a current state of the data to be received, and store the data to be received in the framing area according to a determination result, so as to obtain an updated framing area and received data, including:
respectively receiving the data to be received according to the current state of the data to be received to obtain an updated framing area and the received data;
and if the current state of the data to be received is the waiting frame head and the data of the frame head is equal to the data of the receiving buffer area, receiving the frame head in the data to be received, storing the frame head into a framing area, and adding one to each of the pointer address and the number of the received bytes in the framing area to obtain the updated data of the framing area and the received frame head.
In one embodiment, if the current state of the data to be received is the waiting frame header and the frame header is not equal to the data in the receiving buffer, the data to be received is discarded, the data in the framing area is cleared, the framing function is reset, and the next time the frame header data is received, the method starts to be performed.
In one embodiment, the length of the frame header in the updated framing area is determined, and if the length of the bytes received in the updated framing area is greater than the length of the frame header, the state of the data to be received is switched to the length of the payload.
In one embodiment, if the current state of the data to be received is the received payload length, the payload length in the data to be received is received, the payload length is stored in a framing area, and the pointer address and the number of the received bytes in the framing area are respectively added by one to obtain the updated framing area and the data of the received payload length;
judging the length of a frame header in the updated framing area, and if the length of a received byte in the updated framing area is the same as the length of a payload and the length of the payload is the same as two bits behind the frame header, switching the state of data to be received into the state of receiving other data; if the payload length is different from the two bits behind the frame header, discarding the data to be received, resetting the framing area data, resetting the framing function, and starting to wait for next frame header data reception; other data includes end of frame and real data.
In one embodiment, if the current state of the data to be received is to receive other data, receiving a frame tail and real data in the data to be received, storing the frame tail and the real data into a framing area, and adding one to each of an address of a pointer and the number of bytes received in the framing area to obtain an updated framing area and the received data;
and judging the length of the received bytes in the updated framing area, and if the length of the received bytes is equal to that of the data to be received, switching the state of the data to be received into data verification.
In one embodiment, the data verification module 206 is further configured to verify the received data with a checksum in the updated framing area, and determine whether the received data is received normally according to a verification result, so as to obtain normally received data, including:
and verifying the received data by using a checksum in the updated framing area, if the length of the tail of the received data is effective, adding the length of the received data after removing the frame head, the frame tail and all values except the checksum, comparing the summed low eight bits with the checksum, and if the checksum is equal to the summed low eight bits, judging that the received data is normally received to obtain normally received data.
For specific limitation of a serial received data processing apparatus, refer to the above limitation on a serial received data processing method, which is not described herein again. All modules in the serial port receiving data processing device can be completely or partially realized through software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 3. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a serial received data processing method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on a shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 3 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In an embodiment, a computer device is provided, comprising a memory storing a computer program and a processor implementing the steps of the method in the above embodiments when the processor executes the computer program.
In an embodiment, a computer storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, is adapted to carry out the steps of the method of the above embodiments.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (9)

1. A serial port received data processing method is characterized by comprising the following steps:
acquiring data to be received; the data to be received comprises a frame header, a payload length and other data;
judging the current state of the data to be received, and storing the data to be received into a framing area according to a judgment result to obtain an updated framing area and received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
verifying the received data by using a checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; the normally received data is a serial port received data processing result;
if the current state of the data to be received is the length of the received payload, receiving the length of the payload in the data to be received, and storing the length of the payload into a framing area, wherein the number of pointer addresses and the number of received bytes in the framing area are respectively added by one to obtain the data of the updated framing area and the length of the received payload;
judging the length of the frame header in the updated framing area, and if the length of the received bytes in the updated framing area is the same as the length of the bytes of the payload and the length of the payload is the same as the last two bits of the frame header, switching the state of the data to be received to the state of receiving other data; if the payload length is different from the two bits behind the frame header, discarding the data to be received, resetting the framing area data, resetting the framing function, and starting to wait for next frame header data reception; other data includes end of frame and real data.
2. The method of claim 1, wherein determining the current status of the data to be received, and storing the data to be received in a framing area according to the determination result to obtain an updated framing area and received data comprises:
respectively receiving the data to be received according to the current state of the data to be received to obtain an updated framing area and the received data;
and if the current state of the data to be received is a waiting frame header and the data of the frame header is equal to the data of the receiving buffer area, receiving the frame header in the data to be received, storing the frame header into a framing area, and adding one to each of the pointer address and the number of the received bytes in the framing area to obtain the updated data of the framing area and the received frame header.
3. The method of claim 2, further comprising:
and if the current state of the data to be received is the frame header waiting state and the data of the frame header and the receiving buffer area are not equal, discarding the data to be received, resetting the framing area data, resetting the framing function, and starting to wait for the next time of receiving the data of the frame header.
4. The method of claim 2, further comprising:
and judging the length of the frame header in the updated framing area, and if the length of the received bytes in the updated framing area is greater than the length of the frame header, switching the state of the data to be received to the length of the received payload.
5. The method of claim 1, further comprising:
if the current state of the data to be received is other data, receiving a frame tail and real data in the data to be received, and storing the frame tail and the real data into a framing area, wherein the number of pointer addresses and received bytes in the framing area is respectively increased by one to obtain an updated framing area and the received data;
and judging the length of the received bytes in the updated framing area, and if the length of the received bytes is equal to the length of the data to be received, switching the state of the data to be received into data verification.
6. The method according to claim 5, wherein verifying the received data by using a checksum in the updated framing area, and determining whether the received data is received normally according to a verification result to obtain normally received data comprises:
and verifying the received data by using a checksum in the updated framing area, if the length of the tail of the received data is effective, adding the length of the received data after removing the frame head, the frame tail and all values except the checksum, comparing the summed low eight bits with the checksum, and if the checksum is equal to the summed low eight bits, judging that the received data is normally received to obtain normally received data.
7. A serial port receiving data processing device is characterized by comprising:
the data acquisition module is used for acquiring data to be received; the data to be received comprises a frame header, a payload length and other data;
the data processing module is used for judging the current state of the data to be received and storing the data to be received into the framing area according to a judgment result to obtain an updated framing area and received data; the current state comprises waiting for a frame header, receiving payload length, receiving other data and verifying the data;
the data verification module is used for verifying the received data by using a checksum in the updated framing area, and judging whether the received data is normally received or not according to a verification result to obtain normally received data; the normally received data is a serial port received data processing result;
the data processing module is further used for receiving the payload length in the data to be received if the current state of the data to be received is the received payload length, and storing the payload length into a framing area, wherein the pointer address and the number of the received bytes in the framing area are respectively added by one to obtain the updated data of the framing area and the received payload length; judging the length of the frame header in the updated framing area, and if the length of the received bytes in the updated framing area is the same as the length of the bytes of the payload and the length of the payload is the same as the last two bits of the frame header, switching the state of the data to be received to the state of receiving other data; if the payload length is different from the two bits behind the frame header, discarding the data to be received, resetting the framing area data, resetting the framing function, and starting to wait for next frame header data reception; other data includes end of frame and real data.
8. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.
CN202210544545.3A 2022-05-19 2022-05-19 Serial port received data processing method, device, equipment and medium Pending CN114650217A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210544545.3A CN114650217A (en) 2022-05-19 2022-05-19 Serial port received data processing method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210544545.3A CN114650217A (en) 2022-05-19 2022-05-19 Serial port received data processing method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN114650217A true CN114650217A (en) 2022-06-21

Family

ID=81997349

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210544545.3A Pending CN114650217A (en) 2022-05-19 2022-05-19 Serial port received data processing method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN114650217A (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5721891A (en) * 1995-12-15 1998-02-24 International Business Machines Corporation Detection of N length bit serial communication stream
CN102098131A (en) * 2009-12-15 2011-06-15 航天科工惯性技术有限公司 Dynamic parameter configuration-based general framing and de-framing method for serial port data frames
CN104008078A (en) * 2014-05-27 2014-08-27 安徽中兴继远信息技术股份有限公司 Method for high-speed transmission between data transmission boards based on FPGA
CN104765573A (en) * 2015-04-10 2015-07-08 中国船舶重工集团公司第七一0研究所 Serial communication data processing analysis method
CN107302531A (en) * 2017-06-19 2017-10-27 青岛华潞佳电子科技有限公司 A kind of serial port command analytic method based on state machine and circle queue
CN111290305A (en) * 2018-12-06 2020-06-16 航天科工惯性技术有限公司 Multi-channel digital quantity acquisition and processing anti-collision method and system for multiple sets of inertial navigation systems
CN111651256A (en) * 2020-05-31 2020-09-11 西安爱生技术集团公司 Serial communication data synchronization method based on FreeRTOS
CN111858447A (en) * 2020-07-13 2020-10-30 深圳市集贤科技有限公司 Method for receiving data from serial port and processing data frame
CN113392060A (en) * 2021-06-16 2021-09-14 天津津航计算技术研究所 Universal serial port data receiving and processing method
CN113904741A (en) * 2021-10-08 2022-01-07 天津津航计算技术研究所 Signal-to-noise ratio dynamic judgment method based on verification assistance

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5721891A (en) * 1995-12-15 1998-02-24 International Business Machines Corporation Detection of N length bit serial communication stream
CN102098131A (en) * 2009-12-15 2011-06-15 航天科工惯性技术有限公司 Dynamic parameter configuration-based general framing and de-framing method for serial port data frames
CN104008078A (en) * 2014-05-27 2014-08-27 安徽中兴继远信息技术股份有限公司 Method for high-speed transmission between data transmission boards based on FPGA
CN104765573A (en) * 2015-04-10 2015-07-08 中国船舶重工集团公司第七一0研究所 Serial communication data processing analysis method
CN107302531A (en) * 2017-06-19 2017-10-27 青岛华潞佳电子科技有限公司 A kind of serial port command analytic method based on state machine and circle queue
CN111290305A (en) * 2018-12-06 2020-06-16 航天科工惯性技术有限公司 Multi-channel digital quantity acquisition and processing anti-collision method and system for multiple sets of inertial navigation systems
CN111651256A (en) * 2020-05-31 2020-09-11 西安爱生技术集团公司 Serial communication data synchronization method based on FreeRTOS
CN111858447A (en) * 2020-07-13 2020-10-30 深圳市集贤科技有限公司 Method for receiving data from serial port and processing data frame
CN113392060A (en) * 2021-06-16 2021-09-14 天津津航计算技术研究所 Universal serial port data receiving and processing method
CN113904741A (en) * 2021-10-08 2022-01-07 天津津航计算技术研究所 Signal-to-noise ratio dynamic judgment method based on verification assistance

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
张爱卿等: "VxWorks中基于RS485总线的串口通信协议及实现", 《微计算机信息》 *
王斌等: "一种基于高速串口通信的高效数据处理方法", 《自动化技术与应用》 *
赵京: "采用ADuC7026的网络分布式数据采集系统", 《武汉理工大学学报(信息与管理工程版)》 *

Similar Documents

Publication Publication Date Title
CN110377454B (en) Data verification method and device, computer equipment and storage medium
CN110647490B (en) Data transmission method, device, equipment and computer storage medium
CN111506335A (en) DSP + FPGA-based program online upgrading method and system
US20240354021A1 (en) Data processing method and system, device and medium
CN113489570A (en) Data transmission method, device and equipment for PCIe link
CN111539683A (en) Contract signing method, device, equipment and medium
CN114385485A (en) Interface test method, device, equipment and storage medium
CN114337915A (en) Serial communication-based private protocol fault-tolerant processing method and device and storage medium
CN116743619B (en) Network service testing method, device, equipment and storage medium
CN114650217A (en) Serial port received data processing method, device, equipment and medium
US7062677B1 (en) Method for capturing core dump of a service module
CN109889418B (en) Data transmission method and device based on CAN bus
CN115878351B (en) Message transmission method and device, storage medium and electronic device
CN111522571A (en) Equipment upgrading method and device, terminal equipment and storage medium
CN115729477A (en) Distributed storage IO path data writing and reading method, device and equipment
WO2023123910A1 (en) Fault processing method and apparatus, and device and storage medium
CN112511522B (en) Method, device and equipment for reducing memory occupation in detection scanning
CN113535646A (en) Mirror image file uploading method, device, equipment and medium based on cloud platform
CN113556331A (en) TCP sticky package processing method, system and storage medium
CN110661887B (en) Method and device for establishing communication link, communication system and server
CN113708978A (en) Network availability test method and device, computer equipment and storage medium
CN111049877B (en) Big data external output method and device and data open platform
CN109871277B (en) Inter-process multi-request management method and device, terminal equipment and readable storage medium
CN114679425B (en) Message processing method, network equipment and storage medium under 5G network
CN116346958A (en) Data packet analysis method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20220621