A data parsing method, apparatus, medium, and vehicle
By filtering the received messages and adaptively determining the data length code position, the efficiency and accuracy of CANFD protocol data parsing are improved, solving the limitations of the traditional CAN protocol and the complexity of the CANFD protocol, and realizing efficient and accurate data transmission.
Patent Information
- Application Number
- CN202411568925.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2044-11-05
AI Technical Summary
Traditional CAN protocols have limitations in data transmission rate and data load, making it difficult to meet the high-efficiency data transmission requirements of modern automotive electronic systems. Furthermore, the complexity of the data format of the CANFD protocol leads to high parsing difficulty, low accuracy, and poor compatibility.
By detecting the data status of the message to be parsed, message data in the received state is filtered out for parsing. The presence of a name in the message is detected, the position of the data length code is adaptively determined, and the target data is read, avoiding errors caused by a fixed method.
It improves the efficiency and accuracy of data parsing, enhances compatibility with different data frame formats, is suitable for various application scenarios, and reduces the possibility of data loss and incorrect parsing.
Smart Images

Figure CN119544835B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data communication technology, and in particular to a data parsing method, apparatus, medium, and vehicle. Background Technology
[0002] With the development of automotive electronics technology, the Controller Area Network (CAN) protocol is widely used for data transmission between various controllers within automobiles. However, the traditional CAN protocol has limitations in data transmission rate and data load, making it difficult to meet the high-efficiency data transmission requirements of modern automotive electronic systems. To address this, the CANFD (CAN with Flexible Data-Rate) protocol was developed, providing higher data transmission rates and larger data frame sizes.
[0003] However, in practical applications, the CANFD protocol's data format and transmission mechanism are more complex than traditional CAN, making protocol data parsing increasingly difficult. Therefore, how to efficiently and accurately parse CANFD protocol data has become a pressing problem to be solved. Summary of the Invention
[0004] This application provides a data parsing method, apparatus, medium, and vehicle, which improves the efficiency of data parsing by optimizing the data parsing process.
[0005] The first aspect of this application provides a data parsing method, the method comprising:
[0006] For a message to be parsed that is in the receiving state, determine the end position of the timestamp in the message to be parsed;
[0007] The presence of a message name in the message to be parsed is detected to obtain a first detection result; the first detection result is used to indicate whether a message name exists in the message to be parsed, or whether a message name does not exist in the message to be parsed.
[0008] Based on the end position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, the position of the data length code in the message to be parsed is determined, and the data length code is read.
[0009] Based on the position of the data length code and the data length code, the target data in the message to be parsed is read.
[0010] Optionally, based on the end position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, the position of the data length code in the message to be parsed is determined, including:
[0011] If the first detection result indicates that a message name exists in the message to be parsed, the position of the data length code is determined based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, the length of the message name, and the first fixed length.
[0012] If the first detection result indicates that there is no message name in the message to be parsed, the position of the data length code is determined based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, and the second fixed length.
[0013] Optionally, the method further includes:
[0014] Replace all spaces in the message to be parsed with the target character to obtain the standard message;
[0015] If the standard message satisfies the first preset format, the data status of the message to be parsed is determined to be a receiving status; wherein, the first preset format includes the target character and a first identifier representing the receiving status.
[0016] Optionally, determining the end position of the timestamp in the message to be parsed includes:
[0017] If the standard message satisfies the second preset format, the termination position of the timestamp in the message to be parsed is determined based on the position of the first target character in the second preset format; wherein, the second preset format includes the target character and the adjacent identifier of the timestamp.
[0018] Optionally, the method further includes:
[0019] If the standard message satisfies the third preset format, it is determined that there is a message name in the message to be parsed, and the length of the message name is determined; wherein, the third preset format includes the target character and a second identifier representing the message name.
[0020] Optionally, based on the position of the data length code and the data length code, reading the target data in the message to be parsed includes:
[0021] Based on the data length code, determine the interval length between the data length code and the target data;
[0022] The starting position of the target data is determined based on the position of the data length code and the interval length;
[0023] The target data is read based on the starting position of the target data and the data length code.
[0024] Optionally, the method further includes:
[0025] The target data is then converted to a standard format to obtain standard data.
[0026] Based on the standard data and the description information of the target data, a parsing result for the message to be parsed is generated; the description information includes one or more of the following: timestamp, data status, ID, message name, and data length code of the message to be parsed.
[0027] Output the parsing results.
[0028] Based on the same inventive concept, a second aspect of the present application provides a data parsing apparatus, the apparatus comprising:
[0029] The time parsing module is used to determine the end position of the timestamp in the message to be parsed when the data status is receiving.
[0030] The message name resolution module is used to detect whether a message name exists in the message to be resolved, and obtain a first detection result; the first detection result is used to indicate whether a message name exists in the message to be resolved, or whether a message name does not exist in the message to be resolved.
[0031] The data length code parsing module is used to determine the position of the data length code in the message to be parsed based on the end position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, and to read the data length code.
[0032] The target data parsing module is used to read the target data in the message to be parsed based on the position of the data length code and the data length code.
[0033] Based on the same inventive concept, a third aspect of the present application provides a storage medium storing machine-executable instructions, which, when executed by a processor, implement the data parsing method proposed in the first aspect of the present application.
[0034] Based on the same inventive concept, a fourth aspect of this application provides a vehicle including a processor and a memory; the memory stores machine-executable instructions that can be executed by the processor, and the processor is used to execute the machine-executable instructions to implement the data parsing method proposed in the first aspect of this application.
[0035] Compared with the prior art, this application has the following advantages:
[0036] This application provides a data parsing method that, for a message to be parsed in a receiving state, determines the end position of the timestamp in the message to be parsed; detects whether a message name exists in the message to be parsed, obtaining a first detection result; the first detection result indicates whether a message name exists in the message to be parsed, or whether a message name does not exist in the message to be parsed; based on the end position of the timestamp, the data state, the ID of the message to be parsed, and the first detection result, determines the position of the data length code in the message to be parsed, and reads the data length code; based on the position of the data length code and the data length code, reads the target data in the message to be parsed. Therefore, for a message to be parsed in a receiving state, by detecting whether a message name exists in the message to be parsed, the position of the data length code is adaptively determined, thereby accurately reading the target data. This avoids the problem in the prior art where the position of the data length code is determined in a fixed way, leading to errors in reading the target data, thus improving the efficiency and accuracy of data parsing. Attached Figure Description
[0037] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0038] Figure 1 This is a flowchart of a data parsing method according to an embodiment of this application;
[0039] Figure 2 This is a flowchart of a data parsing method according to an embodiment of this application;
[0040] Figure 3 This is a schematic diagram of the functional modules of a data parsing device according to an embodiment of this application;
[0041] Figure 4 This is a structural schematic diagram of a vehicle according to one embodiment of this application. Detailed Implementation
[0042] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0043] With the development of automotive electronics technology, the Controller Area Network (CAN) protocol is widely used for data transmission between various controllers within automobiles. However, the traditional CAN protocol has limitations in data transmission rate and data load, making it difficult to meet the high-efficiency data transmission requirements of modern automotive electronic systems. To address this, the CANFD (CAN with Flexible Data-Rate) protocol was developed, providing higher data transmission rates and larger data frame sizes.
[0044] Existing technologies typically face the following problems when parsing CANFD data:
[0045] 1. High data parsing complexity: Because the data frame format of the CANFD protocol is more complex than that of the traditional CAN protocol, existing algorithms often require more computing resources and time to parse the data, resulting in low parsing efficiency.
[0046] 2. Inaccurate information extraction: Existing parsing algorithms are prone to data loss or incorrect parsing when dealing with high-frequency data streams, which affects the reliability of the system.
[0047] 3. Poor compatibility: Existing parsing algorithms are usually optimized for specific data frame formats and lack compatibility with multiple data formats, which can easily lead to parsing failures.
[0048] In view of this, this application proposes a data parsing method. On the one hand, by detecting the data status of the message to be parsed, message data in the receiving state is selected for parsing, avoiding meaningless parsing of data in the known sending state and improving the efficiency of data parsing. On the other hand, by detecting whether a message name exists in the message to be parsed, the position of the data length code is adaptively determined, thereby accurately reading the target data. This avoids the problem of incorrect target data reading caused by determining the position of the data length code in a fixed way in the prior art, thus improving the accuracy of data parsing. In addition, by adaptively determining the position of the target data based on the specific value of the data length code, the compatibility with data frame formats is enhanced, making it applicable to various application scenarios.
[0049] Please refer to Figure 1 , Figure 1 This is a flowchart of a data parsing method proposed in one embodiment of this application. For example... Figure 1 As shown, the method includes the following steps:
[0050] S101: For a message to be parsed whose data status is "received", determine the end position of the timestamp in the message to be parsed.
[0051] In this implementation, the data state of a message includes two types: receive state (Rx) and send state (Tx). If a message's data state is receive, it means that the message was received by the current node from elsewhere. If a message's data state is send, it means that the message was sent by the current node to elsewhere. For messages in the send state, since the current node, as the sender, already knows the data content to be sent, there is no need to parse the sent message again. If the current node parses the sent message again, it will lead to unnecessary processing overhead and resource waste. This redundant processing not only reduces the efficiency of the processing system but may also introduce additional errors and complexity.
[0052] To address this, this embodiment first checks whether the data status of a message is in the receiving state when parsing it. If it is, subsequent parsing processing continues; otherwise, the message is skipped, and the data status check proceeds to the next message. This filters out messages in the receiving state for further parsing, improving overall data parsing efficiency. In other words, there may be multiple messages in the receiving state within a batch of messages.
[0053] Furthermore, the timestamp in the message to be parsed represents the time the message was received (or sent), and the timestamp is located at the very beginning of the message. It should be noted that different timestamps may occupy different numbers of bytes, resulting in different timestamp termination positions, which in turn affects the actual location of subsequent target data, especially when the time span is large. For example, a timestamp within 100 milliseconds can be stored using 4 bytes, but a 1-minute timestamp requires 8 bytes.
[0054] S102: Detect whether a message name exists in the message to be parsed, and obtain the first detection result.
[0055] The first detection result is used to indicate whether a message name exists in the message to be parsed, or whether a message name does not exist in the message to be parsed.
[0056] In this implementation, the message name defines the purpose and content of each message in the network protocol. In the DBC file (a file format used to define the CAN bus communication protocol), message names are used to identify different messages that contain communication data between different components in the vehicle system. For example, a message named LOCK_STATUS might contain door lock status information, a message named "Lighting Control" might contain instructions to control the vehicle's lighting system, and another message named "Engine Status" might contain real-time engine data. These names help system designers and maintenance personnel understand and debug communications within the vehicle network.
[0057] The number of bytes occupied differs depending on whether a message name exists in the message to be parsed, thus affecting the actual location of the subsequent target data. Furthermore, even when a message name exists in the message to be parsed, different message names occupy different numbers of bytes.
[0058] In practice, the target name of the message to be parsed can be imported, and the message name can be queried for the multiple messages to be parsed in the above receiving status based on the target name to determine whether a message name exists in the message to be parsed.
[0059] S103: Based on the timestamp's termination position, data status, the ID of the message to be parsed, and the first detection result, determine the position of the data length code in the message to be parsed, and read the data length code.
[0060] The ID of the message to be parsed refers to the message identifier, used to identify the message type in the network. The Data Length Code (DLC) indicates the length of the valid data in the data packet, designed to control the size and format of data transmission. By specifying the length of the data packet, it helps the receiving end identify and process the data, thereby ensuring data integrity and accuracy. For example, a DLC of 0x08 indicates that the data segment contains 8 bytes of data, and a DLC of 0x0A indicates that the data segment contains 10 bytes of data.
[0061] In this embodiment, after determining the end position of the timestamp, the position of the data length code can be deduced based on the data status, the number of bytes occupied by the ID of the message to be parsed, and the presence of the message name in the message to be parsed. Then, the data length code can be read to understand the size of the target data contained in the current message to be parsed.
[0062] Furthermore, different first detection results correspond to different data reading methods. For example, if the first detection result indicates that a message name exists in the message to be parsed, the position of the data length code is determined based on the actual length of the message name, and thus the position of the target data is determined. If the first detection result indicates that a message name does not exist in the message to be parsed, the position of the data length code is determined based on a fixed byte length. Then, for different situations (the presence or absence of a message name), corresponding rules are used to determine the actual position of the subsequent target data and read the target data.
[0063] S104: Based on the position and data length code of the data length code, read the target data in the message to be parsed.
[0064] In this embodiment, the target data in the message to be parsed is stored after the data length code, and there is often a fixed byte interval between the data length code and the target data. Therefore, after determining the position of the data length code, the position of the target data can be calculated based on the position of the data length code and the fixed interval length, and then the target data can be read.
[0065] The interval between the data length code and the target data is affected by the numerical value of the data length code itself; that is, different data length codes may correspond to different interval lengths. For example, when the data length code is 0x08, the interval between the data length code and the target data may be 2, and when the data length code is 0x0A, the interval between the data length code and the target data may be 5.
[0066] This embodiment, on the one hand, detects the data status of the message to be parsed, filtering out message data in the receiving state for parsing, avoiding meaningless parsing of data with known sending states, and improving data parsing efficiency. On the other hand, by detecting the presence of a message name in the message to be parsed, the position of the data length code is adaptively determined, thereby accurately reading the target data. This avoids the problem of incorrect target data reading caused by determining the position of the data length code in a fixed way in the prior art, improving the accuracy of data parsing. In addition, by adaptively determining the position of the target data based on the specific value of the data length code, it enhances compatibility with data frame formats and can be applied to various application scenarios.
[0067] The following uses the parsing of CANFD protocol data as an example to illustrate the practical application of the above method. Please refer to [link / reference needed] for details. Figure 2 The process mainly includes:
[0068] S201: Determine the target CANFD ID and target CANFD Message Name of the data packet to be parsed, and perform a data format check.
[0069] In this embodiment, CANFD ID refers to the identifier of a standard frame in the CANFD network protocol, and CANFD MessageName refers to the message name in the CANFD network protocol. A data packet may contain one or more CANFD IDs, and a CANFD ID may contain multiple message data items, each with a different CANFD MessageName.
[0070] In practice, users can import CANFD protocol data, the target CANFD ID, and the target CANFD Message Name to be parsed into this parsing algorithm for data parsing. The target CANFD Message Name is not mandatory input information. That is, for the message data with the target CANFD ID to be parsed, the message data may or may not contain the target CANFD Message Name.
[0071] Furthermore, the imported CANFD protocol data is formatted. If the imported data packet is in ASCII format (used to store data in ASCII code form), the subsequent step S202 is executed. If it is not in ASCII format, the process exits and reports a format error to inform the upper-layer application that it cannot complete the corresponding parsing work.
[0072] S202: Extract the Nth row of data as the message to be parsed and check its data status.
[0073] In this implementation, each data line can be considered a message to be parsed, and it can be extracted and parsed one by one. For example, when N=1, it means that the raw data in the first line of CANFD protocol data is extracted for subsequent parsing. After the first line of data is parsed, N is set to 2, and the raw data in the second line of CANFD protocol data is extracted and parsed. This process is repeated until all data lines in the data packet have been parsed.
[0074] During the parsing process, the data status of the message to be parsed must first be checked to filter out messages with acceptable reception status for subsequent parsing. Specifically, the data status detection process mainly includes:
[0075] S202-1: Replace all spaces in the message to be parsed with the target character to obtain the standard message.
[0076] In this embodiment, all spaces in the message to be parsed are first replaced with target characters. Target characters are special characters other than letters and numbers, such as "!". The purpose of replacing spaces with target characters is to facilitate more efficient parsing of each field in subsequent parsing and to avoid spaces in the data rows interfering with the parsing process.
[0077] It should be noted that, in cases where there are multiple consecutive spaces, all consecutive spaces are replaced with a single target character to obtain a standard message for subsequent parsing, thereby reducing the detection workload.
[0078] S202-2: If the standard message meets the first preset format, determine the data status of the message to be parsed as the receiving status.
[0079] The first preset format includes target characters and a first identifier indicating the receiving status.
[0080] In this embodiment, the first preset format is a parsing condition pre-constructed based on the target character and a first identifier representing the receiving state. For example, "special character + Rx + special character" is used as the parsing condition, where Rx is the first identifier, indicating that the data state of the message to be parsed is the receiving state.
[0081] The query is performed on the message to be parsed based on the first preset format. If the message to be parsed meets the format conditions, the data status of the message to be parsed is determined to be the receiving state, and the subsequent step S203 is executed. If the format conditions are not met, the data status of the message to be parsed is determined to be the sending state, and N is incremented by 1 to proceed with the parsing of the next data line.
[0082] S203: Parse the timestamp of the message to be parsed and determine the end position of the timestamp.
[0083] In this embodiment, the timestamp represents the reception time of the message to be parsed and is located at the very beginning of the message. Specifically, the timestamp detection process mainly includes:
[0084] If the standard message meets the second preset format, the termination position of the timestamp in the message to be parsed is determined based on the position of the first target character in the second preset format. The second preset format includes the target character and adjacent identifiers of the timestamp.
[0085] In this embodiment, the adjacent identifiers of the timestamp include: an identifier indicating the network protocol type to which the message to be parsed belongs, an identifier indicating the CANFD ID, and a first identifier indicating the reception status.
[0086] The second preset format is a parsing condition pre-constructed based on adjacent identifiers of the target character and timestamp. For example, special character + "canfd" + special character + target CANFD ID + Rx + special character can be used as the parsing condition, where canfd represents the network protocol type of the message to be parsed.
[0087] A query is performed on the message to be parsed based on the second preset format. If a message matching the format is found, it is determined that the data is of type CANFD, with the ID of the target CANFD ID, and the data status is receiving. This means that the part before the first special character is the timestamp of the message to be parsed. Therefore, based on the position of the first target character in the second preset format, the byte length and termination position of the timestamp in the message to be parsed can be determined, thereby obtaining the reception time of the message.
[0088] S204: Detect whether a message name exists in the message to be parsed, and obtain the first detection result.
[0089] In this embodiment, the message name detection process mainly includes: if the standard message meets the third preset format, determining that there is a message name in the message to be parsed, and determining the length of the message name.
[0090] The third preset format includes target characters and a second identifier representing the message name.
[0091] In this embodiment, the third preset format is a parsing condition pre-constructed based on the target character and the second identifier representing the message name. For example, "special character + "LOCK_STATUS" + special character" is used as the parsing condition, where LOCK_STATUS is the second identifier, representing the message name of the message to be parsed.
[0092] A query is performed on the message to be parsed based on a third preset format. If a message to be parsed is found to meet the format conditions, it is determined that the message to be parsed contains a message name; if a message to be parsed does not meet the format conditions, it is determined that the message to be parsed does not contain a message name. The first detection result is then obtained, which indicates whether the message to be parsed contains a message name or not.
[0093] S205: Based on the first detection result, determine the position of the data length code in the message to be parsed.
[0094] As the above analysis shows, the number of bytes occupied differs depending on whether the message to be parsed contains a message name or not, thus affecting the actual location of the subsequent target data. Therefore, it is necessary to design corresponding data reading rules for different situations to correctly read the target data.
[0095] Specifically, the process includes:
[0096] S205-1: If the first detection result indicates that there is a message name in the message to be parsed, the position of the data length code is determined based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, the length of the message name, and the first fixed length.
[0097] In this embodiment, the first fixed length refers to the fixed interval length between the message name and the data length code, for example, 2 bytes. When the first detection result indicates that the message name exists in the message to be parsed, the position of the data length code (DLC) in the message to be parsed can be calculated and the data length code can be read from the end position of the timestamp + the length of the network protocol type + the length of the data status + the length of the ID + the length of the message name + the first fixed length.
[0098] The length of the network protocol type is fixed; for example, the CANFD type occupies 2 bytes. The length of the data status is also fixed; for example, the receive status Rx occupies 2 bytes. The length of the ID and the length of the message name can be determined when the target CANFD ID and target CANFD Message Name are initially entered.
[0099] S205-2: If the first detection result indicates that there is no message name in the message to be parsed, determine the position of the data length code based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, and the second fixed length.
[0100] In this embodiment, when the first detection result indicates that there is no message name in the message to be parsed, the position of the data length code (DLC) in the message to be parsed can be calculated by starting from the end position of the timestamp + the length of the network protocol type + the length of the data state + the length of the ID + the second fixed length, and the data length code can be read.
[0101] The second fixed length is 4 bytes, which means that the message name of the message to be parsed occupies 2 bytes by default, and the fixed interval between the message name and the data length code is 2 bytes.
[0102] This embodiment uses corresponding rules to determine the position of the data length code for different situations (with and without a message name), so that the target data can be read accurately in the future.
[0103] In addition, the read data length code information needs to be checked according to the relevant rules of the CANFD protocol to determine whether the data length code conforms to the CANFD protocol rules, so as to verify the format and content of the data length code.
[0104] Specifically, the CANFD protocol specifies that the maximum value of the DLC is 64 bytes. Therefore, the first step is to check whether the value of the data length code is within the allowed range (0 to 64). If it is, it conforms to the CANFD protocol rules; otherwise, the data is invalid, and no further parsing is needed. The parsing of the next data line can proceed directly. Secondly, based on the data length code value, the actual number of bytes in the data field is verified to match the specified data length code. Especially for cases exceeding 8 bytes, conversion and verification according to the CANFD protocol's encoding rules are required to determine whether the data in the data field conforms to the expected format and content.
[0105] S206: Based on the position and data length code of the data length code, read the target data in the message to be parsed.
[0106] In this embodiment, the interval length (the interval between the data length code and the target data) corresponding to different data length codes may be different, which will affect the actual position of the target data. Therefore, it is necessary to find the position of the target data based on the actual situation of the current data length code. Specifically, this process mainly includes:
[0107] Based on the data length code, determine the interval length between the data length code and the target data; based on the position of the data length code and the interval length, determine the starting position of the target data; based on the starting position of the target data and the data length code, read the target data.
[0108] In this embodiment, when DLC=0x08, meaning the data length code indicates the target data length is 8 bytes, the interval between the data length code and the target data is 2 bytes. In this case, the starting position of the target data in the message to be parsed can be calculated by adding the data length code's length to the starting position and then adding 2 bytes. Reading 8 bytes from this starting position yields the complete target data. The data length code has a fixed length of 4 bytes.
[0109] When DLC=0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, or 0x0F, meaning the data length code indicates the target data length is 9, 10, 11, 12, 13, 14, or 15 bytes, the interval between the data length code and the target data is 5 bytes. In this case, by adding the data length code's length to the starting position and then adding 5 bytes, the starting position of the target data in the parsed message can be calculated. Reading 9, 10, 11, 12, 13, 14, or 15 bytes from that starting position will retrieve the complete target data.
[0110] This embodiment adaptively determines the location of the target data based on the specific value of the data length code, and is compatible with different CANFD data frame formats, exhibiting good versatility and suitability for various application scenarios.
[0111] S207: Summarize the target data and related descriptive information to obtain the parsing results and output them.
[0112] In this embodiment, the description information includes one or more of the following: timestamp, data status, ID, message name, and data length code of the message to be parsed. When summarizing the parsing results corresponding to the messages to be parsed, the target data is first converted to standard data. Then, based on the standard data and the description information of the target data, the parsing results of the messages to be parsed are generated and output.
[0113] Specifically, the extracted text-formatted target data needs to be converted into an array format for temporary storage. At the same time, the standard data in the array format is summarized with the information such as the message reception time, data status, message name, ID, and data length code obtained through the above steps S201-S206 to generate the parsing result corresponding to the message to be parsed, so that the upper-layer application can call the data.
[0114] S208: Extract the data from the (N+1)th row and parse it until all data has been parsed.
[0115] In this implementation, by analyzing the parsed data row information and the current data row position, it can be determined whether there are any unparsed data rows. If there are unparsed data rows, N is incremented by 1 to continue parsing the data of the next data row. If all data rows have been parsed successfully and the parsing process is error-free, a termination message is sent, indicating that the CANFD protocol data parsing was successful and informing the upper-layer application that the relevant parsing work has been successfully completed.
[0116] This embodiment optimizes the data parsing process, improving parsing speed and making it suitable for high-frequency data transmission applications. Furthermore, it boasts good versatility, being compatible with different CANFD data frame formats to meet diverse application needs. Additionally, by introducing error detection and correction mechanisms (replacing spaces in data lines with target characters for corresponding detection and verifying the data length code using CANFD protocol rules), the possibility of data loss and erroneous parsing is significantly reduced, improving the reliability of data parsing.
[0117] Please refer to Figure 3 Based on the same inventive concept, a second aspect of this application provides a data parsing apparatus, the data parsing apparatus 300 comprising:
[0118] The time parsing module 301 is used to determine the end position of the timestamp in the message to be parsed when the data status is receiving.
[0119] The message name resolution module 302 is used to detect whether a message name exists in the message to be resolved and obtain a first detection result; the first detection result is used to indicate whether a message name exists in the message to be resolved or whether a message name does not exist in the message to be resolved.
[0120] The data length code parsing module 303 is used to determine the position of the data length code in the message to be parsed based on the termination position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, and to read the data length code.
[0121] The target data parsing module 304 is used to read the target data in the message to be parsed based on the position and data length code of the data length code.
[0122] Optionally, the data length code parsing module 303 includes:
[0123] The first parsing submodule is used to determine the position of the data length code based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, the length of the message name, and the first fixed length, when the first detection result indicates that there is a message name in the message to be parsed.
[0124] The second parsing submodule is used to determine the position of the data length code based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, and the second fixed length, when the first detection result indicates that there is no message name in the message to be parsed.
[0125] Optionally, the above-mentioned device further includes:
[0126] The replacement module is used to replace all spaces in the message to be parsed with the target character to obtain a standard message.
[0127] The status detection module is used to determine the data status of the message to be parsed as a receiving status when the standard message meets the first preset format; wherein, the first preset format includes target characters and a first identifier representing the receiving status.
[0128] Optionally, the time parsing module 301 mentioned above includes:
[0129] The timestamp detection submodule is used to determine the end position of the timestamp in the message to be parsed based on the position of the first target character in the second preset format, provided that the standard message meets the second preset format; wherein, the second preset format includes the target character and the adjacent identifier of the timestamp.
[0130] Optionally, the above-mentioned device further includes:
[0131] The message name detection module is used to determine whether a message name exists in the message to be parsed and to determine the length of the message name when the standard message meets the third preset format; wherein, the third preset format includes target characters and a second identifier representing the message name.
[0132] Optionally, the target data parsing module 304 includes:
[0133] The interval determination submodule is used to determine the interval length between the data length code and the target data based on the data length code;
[0134] The start determination submodule is used to determine the starting position of the target data based on the position and interval length of the data length code;
[0135] The read submodule is used to read target data based on the starting position and data length code of the target data.
[0136] Optionally, the above-mentioned device further includes:
[0137] The format conversion module is used to convert the target data into standard data.
[0138] The result generation module is used to generate the parsing result of the message to be parsed based on the description information of the standard data and the target data; the description information includes one or more of the following: timestamp, data status, ID, message name, and data length code of the message to be parsed;
[0139] The results output module is used to output the parsing results.
[0140] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0141] Thirdly, based on the same inventive concept, embodiments of this application provide a storage medium storing machine-executable instructions, which, when executed by a processor, implement the data parsing method proposed in the first aspect of this application.
[0142] It should be noted that the specific implementation of the storage medium in this application embodiment refers to the specific implementation of the data parsing method proposed in the first aspect of the above-mentioned application embodiment, and will not be repeated here.
[0143] Fourthly, based on the same inventive concept, referring to Figure 4This application provides a vehicle 400, including a processor 401 and a memory 402; the memory 402 stores machine-executable instructions that can be executed by the processor 401, and the processor 401 is used to execute the machine-executable instructions to implement the data parsing method proposed in the first aspect of this application.
[0144] It should be noted that the specific implementation of the vehicle 400 in this application embodiment refers to the specific implementation of the data parsing method proposed in the first aspect of the above-mentioned application embodiment, and will not be repeated here.
[0145] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0146] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0147] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0148] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0149] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0150] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0151] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only 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 terminal device 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 terminal device. 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 terminal device that includes said element.
[0152] The above provides a detailed description of the data parsing method, apparatus, medium, and vehicle provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A data parsing method, characterized in that, The method includes: For a message to be parsed that is in the receiving state, determine the end position of the timestamp in the message to be parsed; The presence of a message name in the message to be parsed is detected to obtain a first detection result; the first detection result is used to indicate whether a message name exists in the message to be parsed, or whether a message name does not exist in the message to be parsed. Based on the end position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, the position of the data length code in the message to be parsed is determined, and the data length code is read. Based on the position of the data length code and the data length code, the target data in the message to be parsed is read.
2. The method according to claim 1, characterized in that, Based on the end position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, the position of the data length code in the message to be parsed is determined, including: If the first detection result indicates that a message name exists in the message to be parsed, the position of the data length code is determined based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, the length of the message name, and the first fixed length. If the first detection result indicates that there is no message name in the message to be parsed, the position of the data length code is determined based on the end position of the timestamp, the length of the network protocol type to which the message to be parsed belongs, the length of the data state, the length of the ID, and the second fixed length.
3. The method according to claim 2, characterized in that, The method further includes: Replace all spaces in the message to be parsed with the target character to obtain the standard message; If the standard message satisfies the first preset format, the data status of the message to be parsed is determined to be a receiving status; wherein, the first preset format includes the target character and a first identifier representing the receiving status.
4. The method according to claim 3, characterized in that, Determining the end position of the timestamp in the message to be parsed includes: If the standard message satisfies the second preset format, the termination position of the timestamp in the message to be parsed is determined based on the position of the first target character in the second preset format; wherein, the second preset format includes the target character and the adjacent identifier of the timestamp.
5. The method according to claim 3, characterized in that, The method further includes: If the standard message satisfies the third preset format, it is determined that there is a message name in the message to be parsed, and the length of the message name is determined; wherein, the third preset format includes the target character and a second identifier representing the message name.
6. The method according to claim 1, characterized in that, Based on the position of the data length code and the data length code, the target data in the message to be parsed is read, including: Based on the data length code, determine the interval length between the data length code and the target data; The starting position of the target data is determined based on the position of the data length code and the interval length; The target data is read based on the starting position of the target data and the data length code.
7. The method according to claim 1, characterized in that, The method further includes: The target data is then converted to a standard format to obtain standard data. Based on the standard data and the description information of the target data, a parsing result for the message to be parsed is generated; the description information includes one or more of the following: timestamp, data status, ID, message name, and data length code of the message to be parsed. Output the parsing results.
8. A data parsing device, characterized in that, The device includes: The time parsing module is used to determine the end position of the timestamp in the message to be parsed when the data status is receiving. The message name resolution module is used to detect whether a message name exists in the message to be resolved, and obtain a first detection result; the first detection result is used to indicate whether a message name exists in the message to be resolved, or whether a message name does not exist in the message to be resolved. The data length code parsing module is used to determine the position of the data length code in the message to be parsed based on the end position of the timestamp, the data status, the ID of the message to be parsed, and the first detection result, and to read the data length code. The target data parsing module is used to read the target data in the message to be parsed based on the position of the data length code and the data length code.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the data parsing method as described in any one of claims 1 to 7.
10. A vehicle, characterized in that, It includes a processor and a memory; the memory stores machine-executable instructions that can be executed by the processor, and the processor is used to execute the machine-executable instructions to implement the data parsing method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Message analysis method and device, equipment and storage medium
CN113905106A
Message extraction method and device for log file, equipment, medium and program product
CN114661686A