Can message analysis method and device, intelligent terminal and storage medium
By using relative and absolute time to parse CAN messages in smart terminals, the problems of large CAN message storage space and low parsing efficiency are solved, achieving more efficient storage and operation.
Patent Information
- Application Number
- CN202211505626.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-28
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2042-11-28
AI Technical Summary
In existing technologies, the CAN message ASCII format file is large, occupies a lot of storage space, resulting in low parsing efficiency and inconvenient operation.
By setting both relative and absolute time types in the smart terminal, the CAN message is parsed to calculate the message transmission time and perform data parsing to obtain the message type and CAN information, thus reducing storage space requirements.
It reduces the storage space occupied by CAN messages, improves parsing efficiency, and simplifies the operation process.
Smart Images

Figure CN115801929B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, and more specifically, to a CAN message parsing method, apparatus, smart terminal, and storage medium. Background Technology
[0002] The CAN (Controller Area Network) protocol is used for communication between various components in a vehicle, enabling data transmission between them. To monitor and predict the status of these components, the collected CAN messages need to be stored. Currently, the Vector tool is commonly used to store CAN messages as ASCII files. However, these files are large and consume a lot of storage space, resulting in low message parsing efficiency and inconvenience for loading and copying messages. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a CAN message parsing method, apparatus, smart terminal and storage medium.
[0004] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows:
[0005] In a first aspect, the present invention provides a CAN message parsing method applied to a smart terminal, wherein the smart terminal stores a configuration file, the configuration file including multiple frames of CAN messages arranged in the message transmission order, and the method includes:
[0006] The CAN message to be parsed is obtained from the configuration file to obtain the CAN message to be processed.
[0007] The initial message transmission time is obtained by performing time parsing on the CAN message to be processed.
[0008] If the initial message transmission time is a relative time, then the message transmission time of the previous CAN message frame is obtained, and the message transmission time of the CAN message to be processed is calculated based on the initial message transmission time and the message transmission time of the previous CAN message frame.
[0009] If the initial message transmission time is an absolute time, then the initial message transmission time is used as the message transmission time of the CAN message to be processed.
[0010] The CAN message to be processed is parsed to obtain the message type and CAN information of the CAN message to be processed, and thus obtain the message information of the CAN message to be processed.
[0011] In an optional implementation, the CAN message includes multiple bytes, and the message structure of the CAN message includes a time field;
[0012] The step of performing time parsing on the CAN message to be processed to obtain the initial message transmission time includes:
[0013] Read the value of the most significant bit in the first byte of the CAN message to be processed to obtain the first target value;
[0014] If the first target value is a first preset value, then the first byte and the second byte of the CAN message to be processed represent the value of the time field;
[0015] The first and second bytes of the CAN message to be processed are parsed to obtain the initial message transmission time; wherein, the initial message transmission time is a relative time and belongs to a first preset interval.
[0016] In an optional implementation, the method further includes:
[0017] If the first target value is the second preset value, then read the value of the second highest bit in the first byte of the CAN message to be processed to obtain the second target value;
[0018] If the second target value is the first preset value, then the first to fourth bytes of the CAN message to be processed represent the value of the time field;
[0019] The first to fourth bytes of the CAN message to be processed are parsed to obtain the initial message transmission time; wherein the initial message transmission time is a relative time and belongs to a second preset interval.
[0020] In an optional implementation, the method further includes:
[0021] If the second target value is the second preset value, then the first to sixth bytes of the CAN message to be processed represent the value of the time field;
[0022] The first to sixth bytes of the CAN message to be processed are parsed to obtain the initial message transmission time; wherein, the initial message transmission time is an absolute time.
[0023] In an optional implementation, the CAN message includes multiple bytes, and the message structure of the CAN message includes a type field and a CAN information field;
[0024] The step of parsing the CAN message to be processed to obtain the message type and CAN information of the CAN message includes:
[0025] Obtain the byte to be processed from the CAN message to be processed, wherein the byte to be processed represents the value of the type field;
[0026] The bytes to be processed are parsed to obtain the message type of the CAN message to be processed;
[0027] Each target byte is obtained from the CAN message to be processed, and all target bytes represent the value of the CAN information field;
[0028] The target bytes are parsed according to the message type of the CAN message to be processed to obtain the channel number, CAN identifier and CAN data of the CAN message to be processed, and thus obtain the CAN information of the CAN message to be processed.
[0029] In an optional implementation, the message type includes a frame type;
[0030] The step of parsing the bytes to be processed to obtain the message type of the CAN message to be processed includes:
[0031] Read the value of the highest bit in the byte to be processed to obtain the third target value;
[0032] If the third target value is the first preset value, then the frame type of the CAN message to be processed is an extended frame;
[0033] If the third target value is the second preset value, then the frame type of the CAN message to be processed is a standard frame.
[0034] In an optional implementation, the step of parsing all target bytes according to the message type of the CAN message to be processed to obtain the channel number, CAN identifier, and CAN data of the CAN message to be processed includes:
[0035] If the frame type of the CAN message to be processed is an extended frame, then the first to fourth target bytes in all target bytes are parsed to obtain the channel number and CAN identifier of the CAN message to be processed, and each other target byte is parsed to obtain the CAN data of the CAN message to be processed.
[0036] If the frame type of the CAN message to be processed is a standard frame, then the first and second target bytes in all target bytes are parsed to obtain the channel number and CAN identifier of the CAN message to be processed, and each other target byte is parsed to obtain the CAN data of the CAN message to be processed.
[0037] Secondly, the present invention provides a CAN message parsing device applied to a smart terminal, wherein the smart terminal stores a configuration file, the configuration file including multiple frames of CAN messages arranged in the message transmission order, and the device includes:
[0038] The message acquisition module is used to acquire the currently parsed CAN message from the configuration file to obtain the CAN message to be processed;
[0039] The time parsing module is used to parse the CAN message to be processed to obtain the initial message transmission time.
[0040] If the initial message transmission time is a relative time, then the message transmission time of the previous CAN message frame is obtained, and the message transmission time of the CAN message to be processed is calculated based on the initial message transmission time and the message transmission time of the previous CAN message frame.
[0041] If the initial message transmission time is an absolute time, then the initial message transmission time is used as the message transmission time of the CAN message to be processed.
[0042] The data parsing module is used to parse the CAN message to be processed, obtain the message type and CAN information of the CAN message to be processed, and obtain the message information of the CAN message to be processed.
[0043] Thirdly, the present invention provides a smart terminal, including a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the method described in any of the foregoing embodiments.
[0044] Fourthly, the present invention provides a storage medium storing a computer program, which, when executed by a processor, implements the method described in any one of the foregoing embodiments.
[0045] The CAN message parsing method, apparatus, smart terminal, and storage medium provided in this invention embodiment include: a smart terminal storing a configuration file containing multiple frames of CAN messages arranged in the message transmission order; obtaining the currently parsed CAN message from the configuration file to obtain the CAN message to be processed; performing time parsing on the CAN message to be processed to obtain the initial message transmission time; if the initial message transmission time is a relative time, obtaining the message transmission time of the previous frame of CAN messages, and calculating the message transmission time of the CAN message to be processed based on the initial message transmission time and the message transmission time of the previous frame of CAN messages; if the initial message transmission time is an absolute time, using the initial message transmission time as the message transmission time of the CAN message to be processed; and performing data parsing on the CAN message to be processed to obtain the message type and CAN information of the CAN message to be processed, thus obtaining the message information of the CAN message to be processed. By setting relative and absolute times to obtain the message transmission time, and using relative time to reduce the space required to store time information, thereby reducing the space occupied by the CAN message, the size of the configuration file is reduced, the message parsing efficiency is improved, and the operation is simplified.
[0046] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0047] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1 A schematic diagram of a smart terminal provided in an embodiment of the present invention is shown;
[0049] Figure 2 This invention illustrates a flowchart of a CAN message parsing method provided in an embodiment of the present invention.
[0050] Figure 3 This illustration shows another flowchart of the CAN message parsing method provided in an embodiment of the present invention;
[0051] Figure 4 An example diagram of the CAN message parsing method provided in an embodiment of the present invention is shown;
[0052] Figure 5 This diagram illustrates yet another example of the CAN message parsing method provided in an embodiment of the present invention;
[0053] Figure 6 This diagram illustrates yet another example of the CAN message parsing method provided in an embodiment of the present invention;
[0054] Figure 7 This illustration shows another flowchart of the CAN message parsing method provided in an embodiment of the present invention;
[0055] Figure 8 This diagram illustrates yet another example of the CAN message parsing method provided in an embodiment of the present invention;
[0056] Figure 9 This diagram illustrates yet another example of the CAN message parsing method provided in an embodiment of the present invention;
[0057] Figure 10 This diagram illustrates yet another example of the CAN message parsing method provided in an embodiment of the present invention;
[0058] Figure 11 A functional block diagram of a CAN message parsing device provided in an embodiment of the present invention is shown.
[0059] Icons: 110-Bus; 120-Processor; 130-Memory; 150-I / O Module; 170-Communication Interface; 300-CAN Message Parsing Device; 310-Message Acquisition Module; 330-Time Parsing Module; 350-Data Parsing Module. Detailed Implementation
[0060] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0061] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0062] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0063] The CAN (Controller Area Network) protocol is used for communication between various components in a vehicle, enabling data transmission between them. To monitor and predict the status of these components, the collected CAN messages need to be stored. Currently, the Vector tool is typically used to store CAN messages as ASCII format files. However, these files are large and consume significant storage space, resulting in low parsing efficiency and inconvenience for loading and copying messages. Therefore, this invention provides a CAN message parsing method to solve these problems.
[0064] Please see Figure 1 This is a block diagram of a smart terminal provided in an embodiment of the present invention. The smart terminal includes a bus 110, a processor 120, a memory 130, an I / O module 150, and a communication interface 170.
[0065] Bus 110 may be a circuit that interconnects the aforementioned components and transmits communication (e.g., control messages) between them.
[0066] The processor 120 can receive commands from the other components (such as memory 130, I / O module 150, communication interface 170, etc.) via bus 110, interpret the received commands, and perform calculations or data processing according to the interpreted commands.
[0067] The processor 120 can be an integrated circuit chip with signal processing capabilities. The processor 120 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0068] The memory 130 can store commands or data received from the processor 120 or other components (such as I / O module 150, communication interface 170, etc.) or commands or data generated by the processor 120 or other components.
[0069] The memory 130 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), or electrically erasable programmable read-only memory (EEPROM).
[0070] The I / O module 150 can receive commands or data input by the user via input-output means (e.g., sensors, keyboard, touch screen, etc.), and can transmit the received commands or data to the processor 120 or memory 130 via the bus 110. It is also used to display various information received, stored, and processed from the aforementioned components (e.g., multimedia data, text data), and can display video, images, data, etc., to the user.
[0071] Communication interface 170 can be used to communicate with other node devices for signaling or data.
[0072] Understandable, Figure 1 The structure shown is only a schematic diagram of a smart terminal; the smart terminal may also include components that are larger than those shown. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0073] The smart terminal provided in this embodiment of the invention can be a smartphone, personal computer, tablet computer, wearable device, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc. This embodiment of the invention does not impose any limitations on this.
[0074] The following will use the aforementioned smart terminal as the execution subject to execute the various steps in the methods provided in the embodiments of the present invention and achieve the corresponding technical effects.
[0075] Please see Figure 2 , Figure 2 This is a flowchart illustrating a CAN message parsing method provided in an embodiment of the present invention.
[0076] Step S202: Obtain the CAN message to be parsed from the configuration file to obtain the CAN message to be processed;
[0077] In this embodiment, the smart terminal stores a configuration file, which can be understood as a pre-set file specifically for storing CAN messages. The configuration file includes multiple CAN message frames, and these CAN messages are arranged in the order of message transmission.
[0078] It is understood that the smart terminal processes each CAN message frame sequentially according to the order of the CAN messages in the configuration file, and the processing method of each CAN message frame is similar. For the sake of brevity, this embodiment of the invention uses the CAN message to be parsed as the CAN message to be processed as an example. That is, the CAN message to be parsed is obtained from the configuration file, and the CAN message to be processed is obtained.
[0079] Step S204: Perform time parsing on the CAN message to be processed to obtain the initial message transmission time;
[0080] It is understandable that CAN messages have a defined message structure, which includes a time field, a type field, and a CAN information field. The message content of a CAN message includes multiple bytes used to represent these three fields.
[0081] In this embodiment, time parsing is performed on the CAN message to be processed, that is, the byte representing the time field in the CAN message to be processed is determined and parsed to obtain the initial message transmission time.
[0082] Step S206: If the initial message transmission time is a relative time, obtain the message transmission time of the previous CAN message frame, and calculate the message transmission time of the CAN message to be processed based on the initial message transmission time and the message transmission time of the previous CAN message frame.
[0083] Step S208: If the initial message transmission time is an absolute time, then the initial message transmission time is used as the message transmission time of the CAN message to be processed.
[0084] In this embodiment, different time types are set for different message transmission scenarios. For example, when the message transmission frequency is high and the transmission interval between two adjacent messages is short, relative time can be used to represent the message transmission time; when the message transmission frequency is low and the transmission interval between two adjacent messages is long, absolute time can be used to represent the message transmission time. Therefore, CAN messages have both relative and absolute time types, so when parsing CAN messages, it is necessary to obtain the message transmission time based on the time type.
[0085] If the initial message transmission time is a relative time, then the transmission time of the previous CAN message frame is obtained, and the transmission time of the CAN message to be processed is calculated based on the initial message transmission time and the transmission time of the previous CAN message frame. This can be understood as the relative time representing the time interval between the CAN message to be processed and its previous CAN message frame; therefore, the initial message transmission time needs to be time-converted based on the transmission time of the previous CAN message frame to obtain the transmission time of the CAN message to be processed.
[0086] If the initial message transmission time is an absolute time, then the initial message transmission time will be used as the transmission time of the CAN message to be processed. This can be understood as follows: absolute time is used to represent a precise message transmission time, such as including the year, date, and time; therefore, the initial message transmission time can be directly used as the transmission time of the CAN message to be processed.
[0087] It is understood that the embodiments of the present invention obtain the message transmission time by setting two time types, namely relative time and absolute time, and based on these two time types. Since relative time represents the time interval between two adjacent CAN messages, less space can be used to store time information, thereby reducing the space occupied by CAN messages and the size of the setting file, and improving message parsing efficiency and simplifying operation.
[0088] Step S210: Parse the CAN message to be processed to obtain the message type and CAN information of the CAN message to be processed, and obtain the message information of the CAN message to be processed.
[0089] In this embodiment, the message structure of the CAN message includes a type field and a CAN information field. Data parsing of the CAN message to be processed involves determining and parsing the bytes representing the type field and the bytes representing the CAN information field in the message to be processed, thereby obtaining the message type and CAN information of the CAN message to be processed, and obtaining the message information of the CAN message to be processed, wherein the message information includes the message transmission time, message type and CAN information.
[0090] As can be seen from the above steps, the smart terminal stores a configuration file containing multiple frames of CAN messages arranged in the order of message transmission. The current CAN message to be parsed is obtained from the configuration file to obtain the CAN message to be processed. Time parsing is performed on the CAN message to be processed to obtain the initial message transmission time. If the initial message transmission time is a relative time, the message transmission time of the previous CAN message frame is obtained, and the message transmission time of the CAN message to be processed is calculated based on the initial message transmission time and the message transmission time of the previous CAN message frame. If the initial message transmission time is an absolute time, it is used as the message transmission time of the CAN message to be processed. Data parsing is performed on the CAN message to be processed to obtain the message type and CAN information of the CAN message to be processed, thus obtaining the message information of the CAN message to be processed. By setting relative and absolute times to obtain the message transmission time, and using relative time to reduce the space required to store time information, the space occupied by the CAN message is reduced, thereby reducing the size of the configuration file, improving message parsing efficiency, and simplifying the operation.
[0091] Optionally, for step S204 above, this embodiment of the invention provides a possible implementation method, please refer to [link to relevant documentation]. Figure 3 .
[0092] Step S204-1: Read the value of the most significant bit in the first byte of the CAN message to be processed to obtain the first target value;
[0093] Step S204-3: If the first target value is the first preset value, then the first byte and the second byte of the CAN message to be processed represent the value of the time field;
[0094] Step S204-5: Parse the first and second bytes of the CAN message to be processed to obtain the initial message transmission time; wherein, the initial message transmission time is a relative time and belongs to the first preset interval.
[0095] In this embodiment, the CAN message includes multiple bytes, so the CAN message is a sequence of 0s and 1s. To distinguish between relative time and absolute time, two values can be preset, namely a first preset value and a second preset value. The first preset value can be set to 0 and the second preset value can be set to 1.
[0096] Understandably, using relative time to represent time information can reduce the space occupied by CAN messages. To further reduce the space occupied by CAN messages, relative time can be divided into short and long times to represent different time interval ranges. For example, the time interval represented by the short time is a first preset interval, and the time interval represented by the long time is a second preset interval. Optionally, the first preset interval is 0 to 32767 μs; the second preset interval is 32768 μs to 1000 s.
[0097] For ease of understanding, this embodiment of the invention provides a short-time format example diagram, please refer to [reference needed]. Figure 4 The following will combine Figure 4 The steps S204-1 to S204-5 above will be explained.
[0098] Obtain the value of the most significant bit in the first byte of the CAN message to be processed, i.e. Figure 4 The value of the 7th bit of Byte1 is used to obtain the first target value. If the first target value is the first preset value, i.e., 0, it indicates that the initial message transmission time is a short time within a relative time, meaning the time interval represented by the initial message transmission time belongs to the first preset interval. Since the first preset interval is 0 to 32767us, it requires 2 bytes to represent. Therefore, the first and second bytes of the CAN message to be processed represent the value of the time field. Parsing the first and second bytes of the CAN message to be processed yields the initial message transmission time.
[0099] It can be understood that in this embodiment of the invention, the highest bit of the first byte in the CAN message is 0 as the identifier of a short time, and two bytes are used to represent a short time. Except for the highest bit of the first byte, the remaining 15 bits are used to represent the range of time interval, i.e., 0 to 32767us.
[0100] Optionally, after step S204-1 above, this embodiment of the invention provides a possible implementation method, please refer to the following: Figure 3 .
[0101] Step S204-7: If the first target value is the second preset value, then read the value of the second highest bit in the first byte of the CAN message to be processed to obtain the second target value;
[0102] Step S204-7-1a: If the second target value is the first preset value, then the first to fourth bytes of the CAN message to be processed represent the value of the time field;
[0103] Step S204-7-3a: Parse the first to fourth bytes of the CAN message to be processed to obtain the initial message transmission time; wherein, the initial message transmission time is a relative time and belongs to the second preset interval.
[0104] For ease of understanding, this embodiment of the invention provides an example diagram of a long-time format. Please refer to [the provided diagram]. Figure 5 The following will combine Figure 5 The steps S204-7 to S204-7-3a above will be explained.
[0105] If the first target value is the second preset value, i.e., 1, then read the value of the second most significant bit in the first byte of the CAN message to be processed. Figure 5 The value of the 6th bit of Byte1 is used to obtain the second target value. If the second target value is the first preset value, i.e., 0, it indicates that the initial message transmission time is a long time relative to the total time, meaning the time interval represented by the initial message transmission time belongs to the second preset interval. Since the second preset interval is 32768us to 1000s, it requires 4 bytes to represent. Therefore, the first to fourth bytes of the CAN message to be processed represent the value of the time field. Parsing the first to fourth bytes of the CAN message to be processed yields the initial message transmission time.
[0106] It can be understood that in this embodiment of the invention, the highest bit of the first byte in the CAN message is 1 and the second highest bit is 0 as the identifier of a long time, and 4 bytes are used to represent a long time. Apart from the highest bit and the second highest bit of the first byte, the remaining 30 bits are used to represent the range of time interval, i.e., 32768us to 1000s.
[0107] Optionally, after steps S204-7 above, this embodiment of the invention provides a possible implementation method, please refer to the following: Figure 3 .
[0108] Step S204-7-1b: If the second target value is the second preset value, then the first to sixth bytes of the CAN message to be processed represent the value of the time field;
[0109] Step S204-7-3b: Parse the first to sixth bytes of the CAN message to be processed to obtain the initial message transmission time; wherein, the initial message transmission time is an absolute time.
[0110] It is understood that absolute time is used to represent precise message transmission times, such as in a format like year, date, and time. For ease of understanding, this embodiment of the invention provides an example diagram of an absolute time format; please refer to it. Figure 6 The following will combine Figure 6The steps S204-7-1b to S204-7-3b above will be explained.
[0111] If the first target value is the second preset value, i.e., 1, then read the value of the second most significant bit in the first byte of the CAN message to be processed. Figure 6 The value of the 6th bit of Byte1 is used to obtain the second target value. If the second target value is the second preset value, i.e., 1, it indicates that the initial message transmission time is an absolute time, that is, the initial message transmission time includes the year, date, and time. Since absolute time requires 6 bytes to represent, the first to sixth bytes of the CAN message to be processed represent the value of the time field. Therefore, parsing the first to sixth bytes of the CAN message to be processed yields the initial message transmission time.
[0112] It can be understood that in this embodiment of the invention, the highest and second highest bits of the first byte in the CAN message are both 1 as the identifier of absolute time, and 6 bytes are used to represent absolute time. Apart from the highest and second highest bits of the first byte, the remaining 46 bits are used to represent the year, date and time.
[0113] Optionally, for step S210 above, this embodiment of the invention provides a possible implementation method, please refer to [link to relevant documentation]. Figure 7 .
[0114] Step S210-1: Obtain the byte to be processed from the CAN message to be processed. The byte to be processed represents the value of the type field.
[0115] Step S210-3: Parse the bytes to be processed to obtain the message type of the CAN message to be processed;
[0116] Step S210-5: Obtain each target byte from the CAN message to be processed. All target bytes represent the value of the CAN information field.
[0117] Step S210-7: Parse all target bytes according to the message type of the CAN message to be processed to obtain the channel number, CAN identifier and CAN data of the CAN message to be processed, and obtain the CAN information of the CAN message to be processed.
[0118] In this embodiment, the message structure of the CAN message includes a time field, a type field, and a CAN information field in sequence. The type field is represented by one byte. The byte after the byte representing the time field is obtained from the CAN message to be processed, which is the byte to be processed. This byte to be processed represents the value of the type field. Then, the byte to be processed is parsed to obtain the message type of the CAN message to be processed.
[0119] In the CAN message to be processed, every byte except for the time field and the type field is a target byte. Each target byte is obtained from the CAN message to be processed. All the target bytes obtained represent the value of the CAN information field. Then, according to the message type of the CAN message to be processed, all the target bytes are parsed to obtain the CAN information of the CAN message to be processed. The CAN information includes the channel number, CAN identifier and CAN data.
[0120] Optionally, for steps S210-3 above, this embodiment of the invention provides a possible implementation, namely:
[0121] Step S210-3-1: Read the value of the highest bit in the byte to be processed to obtain the third target value;
[0122] Step S210-3-3A: If the third target value is the first preset value, then the frame type of the CAN message to be processed is an extended frame.
[0123] Step S210-3-3B: If the third target value is the second preset value, then the frame type of the CAN message to be processed is a standard frame.
[0124] For ease of understanding, this embodiment of the invention provides a format example diagram of a type field. Please refer to [link / reference]. Figure 8 The type field is represented by one byte, or 8 bits. The high three bits of this byte represent the message type, the low four bits represent the data length of the CAN data, and the remaining bit is a reserved bit.
[0125] The three higher digits are Figure 8 Bits 7 through 5 of Byte 1 are used to represent the frame type, data type, and transmit / receive type, respectively. If the highest bit of the three higher bits is... Figure 8 If the 7th bit of Byte1 is 0, it indicates that the CAN message is an extended frame; if it is 1, it indicates that the CAN message is a standard frame. If the second highest bit of the three highest bits... Figure 8 If the 6th bit of Byte1 is 0, it indicates that the CAN message is a data frame; if it is 1, it indicates that the CAN message is a remote frame. If the last bit of the three higher bits... Figure 8 If the value of the 5th bit of Byte1 is 0, it indicates that the CAN message is a receive frame; if it is 1, it indicates that the CAN message is a send frame.
[0126] The lower four bits are Figure 8Bits 3 through 0 of Byte1 are used to represent the data length, which ranges from 0 to 8. If the lower four bits are 0000, the data length is 0; if they are 0001, the data length is 1; if they are 0010, the data length is 2; if they are 0011, the data length is 3; if they are 0100, the data length is 4; if they are 0101, the data length is 5; if they are 0110, the data length is 6; if they are 0111, the data length is 7; and if they are 1000, the data length is 8.
[0127] In this embodiment, the third target value is obtained by reading the highest bit of the byte to be processed. If the third target value is the first preset value (0), the frame type of the CAN message to be processed is an extended frame; if the third target value is the second preset value (1), the frame type of the CAN message to be processed is a standard frame. It can be understood that by reading the three highest bits of the byte to be processed, the frame type, data type, and transmit / receive type of the CAN message to be processed can be obtained; by reading the four lowest bits of the byte to be processed, the data length of the CAN data in the CAN message to be processed can be obtained.
[0128] Optionally, for steps S210-7 above, the embodiments of the present invention provide two possible implementations, namely:
[0129] If the frame type of the CAN message to be processed is an extended frame, then the first to fourth target bytes in all target bytes are parsed to obtain the channel number and CAN identifier of the CAN message to be processed, and each other target byte is parsed to obtain the CAN data of the CAN message to be processed.
[0130] If the frame type of the CAN message to be processed is a standard frame, then the first and second target bytes of all target bytes are parsed to obtain the channel number and CAN identifier of the CAN message to be processed, and each other target byte is parsed to obtain the CAN data of the CAN message to be processed.
[0131] For ease of understanding, this embodiment of the invention provides example diagrams of the format of two CAN information fields. For example... Figure 9 This indicates the format of the CAN information field when the CAN message is an extended frame. The channel number ranges from 0 to 7, which occupies 3 bits, and the CAN identifier, or CANID, occupies 29 bits. Therefore, the channel number and CAN identifier together occupy 4 bytes.
[0132] If the CAN message to be processed is an extended frame, the channel number and CAN identifier occupy a total of 4 bytes. Then, the first to fourth target bytes in all target bytes are parsed to obtain the channel number and CAN identifier of the CAN message to be processed. Then, the remaining bytes in all target bytes, i.e., each other target byte, are parsed according to the data length to obtain the CAN data of the CAN message to be processed.
[0133] like Figure 10 This indicates the format of the CAN information field when the CAN message is a standard frame. The channel number ranges from 0 to 31, which occupies 5 bits, and the CAN identifier, or CAN ID, occupies 11 bits. Therefore, the channel number and CAN identifier together occupy 2 bytes.
[0134] If the CAN message to be processed is a standard frame, the channel number and CAN identifier occupy a total of 2 bytes. Then, the first and second target bytes in all target bytes are parsed to obtain the channel number and CAN identifier of the CAN message to be processed. Then, the remaining bytes in all target bytes, i.e., each other target byte, are parsed according to the data length to obtain the CAN data of the CAN message to be processed.
[0135] For ease of understanding, an example is provided in this embodiment of the invention. For instance, a CAN message is a standard frame with a data length of 8 bytes. If an ASCII format file is used, a single CAN message occupies 64 bytes of space. If the configuration file provided in this embodiment of the invention is used, a single CAN message using a long-time format occupies 17 bytes of space; a single CAN message using a short-time format occupies 13 bytes of space. Furthermore, in data monitoring applications, the proportion of CAN messages using the short-time format exceeds 95%, while the proportion using the absolute-time format does not exceed 0.5%. In other words, compared to using the ASCII format, the method provided in this embodiment of the invention can reduce file size to save approximately 80% of storage space.
[0136] To perform the corresponding steps in the above embodiments and various possible methods, an implementation of a CAN message parsing device is given below. Please refer to... Figure 11 , Figure 11 This is a functional block diagram of a CAN message parsing device 300 provided in an embodiment of the present invention. It should be noted that the CAN message parsing device 300 provided in this embodiment has the same basic principle and technical effects as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments. The CAN message parsing device 300 includes:
[0137] The message acquisition module 310 is used to obtain the CAN message to be parsed from the configuration file and obtain the CAN message to be processed.
[0138] The time parsing module 330 is used to parse the CAN message to be processed to obtain the initial message transmission time.
[0139] If the initial message transmission time is a relative time, then obtain the message transmission time of the previous CAN message frame, and calculate the message transmission time of the CAN message to be processed based on the initial message transmission time and the message transmission time of the previous CAN message frame.
[0140] If the initial message transmission time is an absolute time, then the initial message transmission time will be used as the message transmission time of the CAN message to be processed.
[0141] The data parsing module 350 is used to parse the CAN message to be processed, obtain the message type and CAN information of the CAN message to be processed, and obtain the message information of the CAN message to be processed.
[0142] Optionally, the time parsing module 330 is further configured to: read the value of the highest bit in the first byte of the CAN message to be processed to obtain a first target value; if the first target value is a first preset value, then the first byte and the second byte of the CAN message to be processed represent the value of the time field; parse the first byte and the second byte of the CAN message to be processed to obtain the initial message transmission time; wherein the initial message transmission time is a relative time and belongs to the first preset interval.
[0143] Optionally, the time parsing module 330 is further configured to: if the first target value is a second preset value, read the value of the second highest bit in the first byte of the CAN message to be processed to obtain the second target value; if the second target value is a first preset value, the first to fourth bytes of the CAN message to be processed represent the value of the time field; parse the first to fourth bytes of the CAN message to be processed to obtain the initial message transmission time; wherein the initial message transmission time is a relative time and belongs to the second preset interval.
[0144] Optionally, the time parsing module 330 is further configured to: if the second target value is a second preset value, then the first to sixth bytes of the CAN message to be processed represent the value of the time field; parse the first to sixth bytes of the CAN message to be processed to obtain the initial message transmission time; wherein the initial message transmission time is an absolute time.
[0145] Optionally, the data parsing module 350 is further configured to: obtain the bytes to be processed from the CAN message to be processed, wherein the bytes to be processed represent the value of the type field; parse the bytes to be processed to obtain the message type of the CAN message to be processed; obtain each target byte from the CAN message to be processed, wherein all target bytes represent the value of the CAN information field; parse all target bytes according to the message type of the CAN message to be processed to obtain the channel number, CAN identifier, and CAN data of the CAN message to be processed, thereby obtaining the CAN information of the CAN message to be processed.
[0146] Optionally, the data parsing module 350 is further configured to: read the value of the highest bit in the byte to be processed to obtain a third target value; if the third target value is a first preset value, then the frame type of the CAN message to be processed is an extended frame; if the third target value is a second preset value, then the frame type of the CAN message to be processed is a standard frame.
[0147] Optionally, the data parsing module 350 is further configured to: if the frame type of the CAN message to be processed is an extended frame, parse the first to fourth target bytes of all target bytes to obtain the channel number and CAN identifier of the CAN message to be processed, and parse each other target byte to obtain the CAN data of the CAN message to be processed; if the frame type of the CAN message to be processed is a standard frame, parse the first and second target bytes of all target bytes to obtain the channel number and CAN identifier of the CAN message to be processed, and parse each other target byte to obtain the CAN data of the CAN message to be processed.
[0148] This invention also provides a smart terminal, including a processor and a memory. The memory stores a computer program, and when the processor executes the computer program, it implements the CAN message parsing method disclosed in the above embodiments.
[0149] This invention also provides a storage medium storing a computer program that, when executed by a processor, implements the CAN message parsing method disclosed in this invention.
[0150] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0151] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0152] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0153] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A CAN message parsing method, characterized in that, The method is applied to an intelligent terminal, the intelligent terminal stores a setting file, the setting file includes multiple CAN messages arranged in a message transmission order, and the method includes the following steps: obtaining a CAN message to be currently parsed from the setting file, the CAN message including a time field, and obtaining a CAN message to be processed; performing time analysis on the CAN message to be processed to obtain an initial message transmission time, including reading a value of a highest bit and a value of a second highest bit in a first byte of the CAN message to be processed to obtain a first target value and a second target value respectively; if the first target value is a first preset value, a first byte and a second byte of the CAN message to be processed represent a value of the time field, and the initial message transmission time is a relative time; if the first target value and the second target value are second preset values, a first byte to a sixth byte of the CAN message to be processed represent the value of the time field, and the initial message transmission time is an absolute time; if the initial message transmission time is the relative time, obtaining a message transmission time of a previous CAN message, and calculating a message transmission time of the CAN message to be processed according to the initial message transmission time and the message transmission time of the previous CAN message; if the initial message transmission time is the absolute time, taking the initial message transmission time as the message transmission time of the CAN message to be processed; performing data analysis on the CAN message to be processed to obtain a message type and CAN information of the CAN message to be processed, and obtaining message information of the CAN message to be processed.
2. The method of claim 1, wherein, The method further includes: if the first target value is the second preset value and the second target value is the first preset value, a first byte to a fourth byte of the CAN message to be processed represent the value of the time field, and the initial message transmission time is the relative time.
3. The method of claim 1, wherein, The CAN message includes multiple bytes, and a message structure of the CAN message includes a type field and a CAN information field; the step of performing data analysis on the CAN message to be processed to obtain a message type and CAN information of the CAN message to be processed includes: obtaining a processing byte from the CAN message to be processed, the processing byte representing a value of the type field; performing analysis on the processing byte to obtain the message type of the CAN message to be processed; obtaining each target byte from the CAN message to be processed, all target bytes representing a value of the CAN information field, and the target byte being a byte in the CAN message to be processed other than the time field and the type field; performing analysis on all target bytes according to the message type of the CAN message to be processed to obtain a channel number, a CAN identifier and CAN data of the CAN message to be processed, and obtaining the CAN information of the CAN message to be processed.
4. The method of claim 3, wherein, The message type includes a frame type; the step of performing analysis on the processing byte to obtain the message type of the CAN message to be processed includes: reading a value of a highest bit in the processing byte to obtain a third target value; If the third target value is a first preset value, the frame type of the CAN message to be processed is an extended frame; If the third target value is a second preset value, the frame type of the CAN message to be processed is a standard frame.
5. The method of claim 4, wherein, The step of analyzing all target bytes according to the message type of the CAN message to be processed to obtain the channel number, CAN identifier and CAN data of the CAN message to be processed, comprises: If the frame type of the CAN message to be processed is an extended frame, the first target byte to the fourth target byte in all target bytes are analyzed to obtain the channel number and CAN identifier of the CAN message to be processed, and each other target byte is analyzed to obtain the CAN data of the CAN message to be processed; If the frame type of the CAN message to be processed is a standard frame, the first target byte and the second target byte in all target bytes are analyzed to obtain the channel number and CAN identifier of the CAN message to be processed, and each other target byte is analyzed to obtain the CAN data of the CAN message to be processed.
6. A CAN message parsing device, characterized by The device is applied to an intelligent terminal, the intelligent terminal stores a setting file, the setting file comprises a plurality of CAN messages arranged in a message transmission sequence, and the device comprises: A message acquisition module is configured to acquire a CAN message to be analyzed currently from the setting file, the CAN message comprises a time field, and a CAN message to be processed is obtained. A time analysis module is configured to perform time analysis on the CAN message to be processed to obtain an initial message transmission time, which comprises: reading a value of a highest bit and a value of a second highest bit in a first byte of the CAN message to be processed to obtain a first target value and a second target value respectively; if the first target value is a first preset value, a first byte and a second byte of the CAN message to be processed represent a value of the time field, and the initial message transmission time is a relative time; if the first target value and the second target value are a second preset value, a first byte to a sixth byte of the CAN message to be processed represent the value of the time field, and the initial message transmission time is an absolute time; If the initial message transmission time is the relative time, a message transmission time of a previous CAN message is acquired, and the message transmission time of the CAN message to be processed is calculated according to the initial message transmission time and the message transmission time of the previous CAN message; If the initial message transmission time is the absolute time, the initial message transmission time is taken as the message transmission time of the CAN message to be processed; A data analysis module is configured to perform data analysis on the CAN message to be processed to obtain a message type and CAN information of the CAN message to be processed, and message information of the CAN message to be processed is obtained.
7. A smart terminal, characterized by The device comprises a processor and a memory, the memory stores a computer program, and the processor implements the method in any one of claims 1 to 5 when executing the computer program.
8. A storage medium, characterized by The storage medium has stored thereon a computer program which, when executed by the processor, implements the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Method for compressing can-bus data
US20220303362A1