Modularized fieldbus message frame recording method
By setting the receiving and sending buffer on the node device, and using the timestamp timer and write thread, the difficulty of realizing CAN message frame recording on the node device is solved, automatic recording and storage is realized, and the composition of the control system is simplified and the reduction of the cost.
Patent Information
- Application Number
- CN202411515732.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-25
AI Technical Summary
There are difficulties in realizing CAN message frame recording on node devices, including taking into account the original functions and adding the function of recording CAN message frames sent by itself.
Set the receiving buffer and send buffer in the memory of the node device. Use the timestamp timer and write thread in the embedded real-time operating system to read the CAN message frame from the buffer and compare its time stamps, from small to small Write to the SSD in a large order.
It realizes automatic recording and storing of CAN message frames without affecting the original functions on the node device, simplifying the composition of the control system and reducing the power consumption and cost of the system power supply.
Smart Images

Figure CN119512453A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of embedded real-time operating systems, in particular to the technical field of CAN (Controller Area Network) field buses, and specifically to a modular field bus message frame recording method. Background Art
[0002] CAN (Controller Area Network) is a commonly used fieldbus technology. Connecting multiple devices with CAN interfaces (also called "node devices") on a twisted pair cable can form a bus network. Using CAN to build a control system can reduce the cost of the communication system and improve system reliability.
[0003] By monitoring and recording the transmission of CAN message frames and relative time on the CAN network, the CAN system can be debugged and the status monitored. A dedicated CAN bus recorder is generally connected to the system CAN bus test interface, and manual control is required to start and stop data recording; after the CAN bus recorder stops data recording, the memory card is removed, the stored data is read and analyzed. When the CAN bus recorder is recording data, it is generally impossible to read the data being stored. This commonly used method requires a separate CAN bus data recorder to be configured in the system, and power cables and signal cables are laid out, resulting in additional system costs and power consumption.
[0004] With the development of computer technology, in many systems, after node devices realize the functions specified by the system, the surplus computing power and storage space can be used to realize the CAN message frame data recording function.
[0005] However, recording CAN message frames on node devices is more difficult than using a dedicated CAN bus recorder:
[0006] a) The node device developed using an embedded real-time operating system needs to complete certain functions. Adding the CAN message frame recording function needs to ensure that the original functions are not affected;
[0007] b) A CAN bus data recorder only needs to monitor and read the receive buffer of the CAN controller or the receive first-in-first-out buffer (RXFIFO) of some CAN controllers (such as SJA1000) to obtain the CAN message frame data transmitted on the CAN bus. However, for common CAN controllers, the CAN message frames sent by this controller do not enter the controller's own receive buffer, so it is necessary to add a function to record the CAN message frames sent by itself. Summary of the invention
[0008] The purpose of the present invention is to provide a modular field bus message frame recording method to solve the problems existing when implementing CAN message frame recording on a node.
[0009] In order to achieve the above tasks, the present invention adopts the following technical solutions:
[0010] A modular fieldbus message frame recording method is deployed as a functional module in at least one node device in a CAN control system, comprising: setting a receiving buffer and a sending buffer in the memory of the node device, respectively used to cache CAN message frames from the CAN bus when receiving successfully and sending successfully;
[0011] A timestamp timer is set in the embedded real-time operating system of the node device to read the timestamp information when caching the CAN message frame; an independent periodically executed write thread is set, and the period of the write thread is greater than the period of the sending and receiving threads of the CAN message frame; the write thread is used to read the CAN message frame from the receiving buffer and the sending buffer and compare their timestamps, and write them into the solid-state hard disk of the node device in ascending order of time.
[0012] Furthermore, both the receiving buffer and the sending buffer can accommodate at least 2k CAN message frames.
[0013] Furthermore, the timestamp timer sets its count value to 0 when the node device is turned on, and continuously accumulates it at intervals of 1 ms; the count value of the timestamp timer is used to timestamp the CAN message frames that are successfully received or sent, and the marked CAN message frames are recorded in the corresponding receive buffer or send buffer.
[0014] Furthermore, the write thread is used to set a "read" pointer in the receive buffer and the send buffer in the node device memory, and CAN message frames are read from the receive buffer and the send buffer respectively. Then, the timestamp sizes are compared, and according to the rule that the CAN message frames with smaller timestamp values are written to the solid-state hard disk first, the timestamps and CAN message frames in the receive buffer and the send buffer are written alternately to the solid-state hard disk.
[0015] Furthermore, the received CAN message frames are traversed in the receiving buffer in the memory, and at the same time, the CAN message frames in the sending buffer in the memory are checked. If the timestamp of the CAN message frame in the sending buffer indicates that the time when the CAN message frame is successfully transmitted on the CAN bus is later than the CAN message frame in the receiving buffer, the CAN message frame and the timestamp in the receiving buffer are written as records into the buffer of the solid-state hard disk until the timestamp of the CAN message frame in the sending buffer indicates that the time when the CAN message frame is successfully transmitted on the CAN bus is no later than the CAN message frame in the receiving buffer, and then the CAN message frame and the timestamp in the sending buffer are written as records into the buffer of the solid-state hard disk.
[0016] Furthermore, a sending and receiving thread of a CAN message frame is set in the node device to implement the following functions:
[0017] When the node device successfully receives a CAN message frame, it reads the count value of the timestamp timer, and saves the count value and the CAN message frame in the receive buffer in the memory; only this thread can perform write operations on the receive buffer in the memory; when the node device successfully sends a CAN message frame, it reads the count value of the timestamp timer, and saves the count value and the CAN message frame in the send buffer in the memory; only when the CAN message frame is sent successfully, the write operation is performed on the send buffer in the memory.
[0018] Furthermore, when the node device is powered on, the node device automatically generates a file name for storing the CAN message frame in the solid state drive according to the date and time, and automatically starts recording the CAN message frame.
[0019] Furthermore, the message frame record file is read and the historical message frame record file is cleared through the built-in FTP function of the embedded real-time operating system.
[0020] Furthermore, the CAN message frames recorded by the solid-state hard disk of each node device are used for subsequent data playback, analysis and system health management.
[0021] Compared with the prior art, the present invention has the following technical features:
[0022] The method of the present invention is deployed in the CAN control function node with computing power and storage space capacity in the system, without affecting the original function of the node. The present invention can replace the field bus data recorder, simplify the control system composition, and has the characteristics of automatic recording when the machine is turned on and no interruption of recording is required when exporting data files. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is a schematic diagram of the buffer in memory;
[0024] Figure 2This is the flow chart of buffer record merging and writing. DETAILED DESCRIPTION
[0025] The present invention is based on a general embedded real-time operating system (operating system inside a node) and proposes a modular field bus message frame recording method. The method is incorporated into a node device with storage space (the original function is not affected after the functional module is loaded) in a CAN control system as a functional module. The method does not affect the original function of the node device, simplifies the composition of the control system, reduces system power consumption and cost, and has the functions of automatic recording and no interruption of recording when exporting data files.
[0026] Referring to the accompanying drawings, the present invention provides a modular fieldbus message frame recording method, which is deployed as a functional module in at least one node device in a CAN control system, comprising: setting a receiving buffer and a sending buffer in the memory of the node device, respectively used to cache CAN message frames from the CAN bus when receiving successfully and sending successfully;
[0027] A timestamp timer is set in the embedded real-time operating system of the node device to read the timestamp information when caching the CAN message frame; an independent periodically executed write thread is set, and the period of the write thread is greater than the period of the sending and receiving threads of the CAN message frame; the write thread is used to read the CAN message frame from the receiving buffer and the sending buffer and compare their timestamps, and write them to the solid state disk (SSD) of the node device in order from small to large time.
[0028] Among them, by setting up a receiving buffer and a sending buffer in the memory that can accommodate at least 2k (thousand) CAN message frames, the amount of data that can be used for one write to the solid-state hard disk is increased, and the frequency of intermittent data streams submitting solid-state hard disk write operation requests is reduced, thereby achieving the purpose of significantly improving the solid-state hard disk write efficiency.
[0029] The timestamp timer set in the embedded real-time operating system has a resolution of 1ms. When the node device is turned on, its count value is set to 0 and continuously accumulated at intervals of 1ms. The count value of the timestamp timer is used to timestamp the CAN message frames that are successfully received or sent. The marked CAN message frames are recorded in the corresponding receive buffer or send buffer, which is used to determine the order when writing the CAN message frames to the solid-state hard disk.
[0030] The write thread is adopted to set a "read" pointer in the receiving buffer and the sending buffer in the memory of the node device, read the CAN message frames from the receiving buffer and the sending buffer respectively, and then compare the timestamp sizes thereof. According to the rule that the CAN message frames with smaller timestamp values are written into the solid state hard disk first, the timestamps and CAN message frames in the receiving buffer and the sending buffer are alternately written into the solid state hard disk; specifically, the received CAN message frames are traversed in the receiving buffer in the memory, and at the same time, the CAN message frames in the sending buffer in the memory are checked. If the timestamp of the CAN message frame in the sending buffer indicates that the CAN message frame is successfully transmitted on the CAN bus later than the CAN message frame in the receiving buffer, the CAN message frame and the timestamp in the receiving buffer are written as records into the buffer of the solid state hard disk until the timestamp of the CAN message frame in the sending buffer indicates that the CAN message frame is successfully transmitted on the CAN bus no later than the CAN message frame in the receiving buffer, and then the CAN message frame and the timestamp in the sending buffer are written as records into the buffer of the solid state hard disk, so as to realize the merging of the receiving buffer and the sending buffer data in the memory.
[0031] Set up the sending and receiving threads of CAN message frames in the node device to implement the following functions:
[0032] When the node device successfully receives the CAN message frame, the count value of the timestamp timer is read, and the count value and the CAN message frame are saved in the receiving buffer in the memory; an independent thread is used to improve the CAN message frame receiving performance and avoid frame loss; only this thread performs write operations on the receiving buffer in the memory to ensure that the data in the receiving buffer in the memory is reliable and complete; when the node device successfully sends a CAN message frame, the count value of the timestamp timer is read, and the count value and the CAN message frame are saved in the sending buffer in the memory; only when the CAN message frame is successfully sent, the send buffer in the memory is written to ensure that the data in the send buffer in the memory is reliable and complete.
[0033] When the node device is powered on, the node device automatically generates a file name for storing CAN message frames in the solid state drive according to the date and time, and automatically starts recording the CAN message frames.
[0034] The message frame record file is read and the historical message frame record file is cleaned up through the built-in FTP (File Transfer Protocol) function of the embedded real-time operating system; therefore, there is no need to interrupt the data recording operation when exporting the data file.
[0035] The CAN message frames recorded by the solid-state hard disk of each node device are used for subsequent data playback and analysis, and can be used for system health management; there is at least one node device in the entire system.
[0036] Example:
[0037] A node device deploys the LoongOS embedded real-time operating system, and the interface chip of the node device is the stand-alone CAN controller SJA1000.
[0038] Add an embedded system timer (resolution of 1ms, set the value to 0 when powered on) as a timestamp timer. The count width of the timer is 32 bits. Therefore, the count range of the timestamp timer is [0,2 31 ], that is, the count value range:
[0039] 2 32 ms=4294967296ms≈1193hrs
[0040] The counting value range of the timer can meet the needs of continuous operation of the commonly used CAN control system after being turned on once.
[0041] The receive buffer (RECEIVE BUFFER, RXB, RXFIFO) of SJA1000 is the interface between the receive filter and the CPU, storing the message frames received and filtered from the CAN bus. The receive buffer (RXB) of SJA1000 is readable by the CPU. The receive first-in-first-out buffer (RXFIFO) has the full length of bytes. The receive buffer (RXB) of SJA1000 is a byte window of 13 bytes of the receive first-in-first-out buffer (RXFIFO); using the first-in-first-out buffer, the CPU can receive other message frames while processing one message frame.
[0042] Check the status register (STATUS REGISTER, SR) of SJA1000. Bit SR.4 is the receive status bit (Receive Status, RS). When the receive status bit is read as 1, it means that SJA1000 has received a CAN message frame and read the receive buffer of SJA1000. Set the command register (COMMAND REGISTER, CMR) of SJA1000. Bit CMR.2 is the release receive buffer bit (Release Receive Buffer, RRB). When writing the command register of SJA1000 and setting the release receive buffer bit to 1, it means that the receive buffer of SJA1000 has been read. If there are still received message frames in the receive first-in-first-out buffer (RXFIFO) of SJA1000, the receive buffer of SJA1000 is mapped to the next byte window with a length of 13 bytes in the receive first-in-first-out buffer (RXFIFO). At this time, the status register (STATUS REGISTER, SR) of SJA1000, bit SR.4 is the receive status bit (Receive Status, RS) is set to 1.
[0043] Design a thread to transfer all CAN message frames in the SJA1000's receive first-in-first-out buffer (RXFIFO) to the software's receive buffer through the SJA1000's receive buffer (RXB).
[0044] The SJA1000's TRANSMIT BUFFER (TXB) is the interface between the CPU and the CAN interface chip stream processor. In order to complete the sending operation through the CAN network, the send buffer stores the complete message frame. The buffer length is 13 bytes, written by the CPU and read by the stream processor.
[0045] When sending a CAN message frame through SJA1000, if the sending is successful, the sent CAN message frame will be pushed into the software sending buffer.
[0046] like Figure 1 As shown in the figure, the software's receive buffer and send buffer are two independent memory areas. Only the thread that reads the SJA1000's receive buffer executes the write operation to the software's receive buffer; and only the thread that writes to the SJA1000's send buffer executes the write operation to the software's send buffer.
[0047] like Figure 2As shown, the received CAN message frames are traversed in the receiving buffer in the memory, and at the same time, the CAN message frames in the sending buffer in the memory are checked. If the timestamp of the CAN message frame in the sending buffer indicates that the CAN message frame is successfully transmitted on the CAN bus later than the CAN message frame in the receiving buffer, the CAN message frame and the timestamp in the receiving buffer are written as records to the solid state drive (sent to the solid state drive "write" buffer), until the timestamp of the CAN message frame in the sending buffer indicates that the CAN message frame is successfully transmitted on the CAN bus no later than the CAN message frame in the receiving buffer, the CAN message frame and the timestamp in the sending buffer are written as records to the solid state drive (sent to the solid state drive "write" buffer), thereby realizing the merging of the two buffers in the memory.
[0048] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A modular fieldbus message frame recording method, characterized in that: The method is deployed as a functional module in at least one node device in a CAN control system, and includes: setting a receiving buffer and a sending buffer in the memory of the node device, respectively used to cache CAN message frames from the CAN bus when receiving successfully and sending successfully; A timestamp timer is set in the embedded real-time operating system of the node device to read the timestamp information when caching the CAN message frame; an independent periodically executed write thread is set, and the period of the write thread is greater than the period of the sending and receiving threads of the CAN message frame; the write thread is used to read the CAN message frame from the receiving buffer and the sending buffer and compare their timestamps, and write them into the solid-state hard disk of the node device in ascending order of time.
2. The modular fieldbus message frame recording method according to claim 1, characterized in that: Both the receive buffer and the transmit buffer can accommodate at least 2k CAN message frames.
3. The modular fieldbus message frame recording method according to claim 1, characterized in that: The timestamp timer sets its count value to 0 when the node device is turned on, and continuously accumulates it at intervals of 1ms; the count value of the timestamp timer is used to timestamp the successfully received and successfully sent CAN message frames, and the marked CAN message frames are recorded in the corresponding receive buffer or send buffer.
4. The modular fieldbus message frame recording method according to claim 1, characterized in that: The write thread is used to set a "read" pointer in the receiving buffer and the sending buffer in the memory of the node device, and CAN message frames are read from the receiving buffer and the sending buffer respectively. Then, the timestamp sizes are compared, and according to the rule that the CAN message frames with smaller timestamp values are written to the solid-state hard disk first, the timestamps and CAN message frames in the receiving buffer and the sending buffer are alternately written to the solid-state hard disk.
5. The modular fieldbus message frame recording method according to claim 1, characterized in that: The received CAN message frames are traversed in the receiving buffer in the memory, and at the same time, the CAN message frames in the sending buffer in the memory are checked. If the timestamp of the CAN message frame in the sending buffer indicates that the CAN message frame is successfully transmitted on the CAN bus later than the CAN message frame in the receiving buffer, the CAN message frame and the timestamp in the receiving buffer are written as records to the buffer of the solid-state drive until the timestamp of the CAN message frame in the sending buffer indicates that the CAN message frame is successfully transmitted on the CAN bus no later than the CAN message frame in the receiving buffer, and then the CAN message frame and the timestamp in the sending buffer are written as records to the buffer of the solid-state drive.
6. The modular fieldbus message frame recording method according to claim 1, characterized in that: Set up the sending and receiving threads of CAN message frames in the node device to implement the following functions: When the node device successfully receives a CAN message frame, it reads the count value of the timestamp timer, and saves the count value and the CAN message frame in the receive buffer in the memory; only this thread can perform write operations on the receive buffer in the memory; when the node device successfully sends a CAN message frame, it reads the count value of the timestamp timer, and saves the count value and the CAN message frame in the send buffer in the memory; only when the CAN message frame is sent successfully, the write operation is performed on the send buffer in the memory.
7. The modular fieldbus message frame recording method according to claim 1, characterized in that: When the node device is powered on, the node device automatically generates a file name for storing CAN message frames in the solid state drive according to the date and time, and automatically starts recording the CAN message frames.
8. The modular fieldbus message frame recording method according to claim 1, characterized in that: The message frame record files are read and the historical message frame record files are cleared through the built-in FTP function of the embedded real-time operating system.
9. The modular fieldbus message frame recording method according to claim 1, characterized in that: The CAN message frames recorded by the solid-state hard disk of each node device are used for subsequent data playback, analysis and system health management.