A CAN signal encapsulation and data analysis method
By using Boolean arrays and conditional structure processing methods in CAN signal packaging and data analysis, the problems of cumbersome, time-consuming and lack of universality in the prior art are solved, and a simplified operation process, time-saving and adaptability to different protocols are achieved.
Patent Information
- Application Number
- CN202411638657.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-11-18
AI Technical Summary
The existing CAN signal packaging and data analysis methods have cumbersome computing processes, long time and lack universality, resulting in high risk of errors and being unable to adapt to changes in different DBC protocols.
By creating a Boolean array and conditional structure, the start bit of the CAN signal is repositioned, and the CAN signal is processed using Boolean operation logic to generate frame data. This method encapsulates the entire processing process into a sub-VI, supports series processing of multiple CAN signals, and adapts to changes in different protocols.
The computing process of CAN signal packaging and data analysis is simplified, which significantly saves computing time, improves packaging efficiency, and realizes universality for different DBC protocols, reducing the risk of errors.
Smart Images

Figure CN119155357B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of CAN bus, and in particular to a CAN signal encapsulation and data analysis method. Background Art
[0002] CAN communication is the preferred communication method in the automotive industry. The motor controller of the power system of new energy vehicles also uses CAN communication. In the motor bench test, the motor needs to be controlled, and the host computer needs to be programmed with software according to the CAN protocol. The DBC format CAN protocol is currently the most widely used general protocol format. The object is CAN Signal, and the information objects provided are Startbit, Length, Offset, and Factor. The Startbit and Length can be used to determine the position of the CAN Signal in the 64-bit arrangement, and the start and end positions of the H-Byte and L-Byte of each CAN Signal in the 8-Byte can be seen.
[0003] CAN communication is divided into sending and receiving, which correspond to the two processes of packaging and parsing. For the application scenario of multiple CAN signals, the existing packaging technology writes two inputs to control the operation input process of CAN Signal to DATA. The positions of CAN Signal1 and CAN Signal2 in DBC and the program operation logic are as follows:
[0004] (CAN Signal1-Offset1) / Factor1 / 16=IQ1(quotient)......R1(remainder);
[0005] IQ1=CAN Signal1 H_Byte;
[0006] R1=CAN Signal1 L_Byte;
[0007] (CAN Signal2-Offset2) / Factor2 / 8=IQ2(quotient)......R2(remainder);
[0008] IQ2=CAN Signal2 H_Byte;
[0009] R2=CAN Signal2 L_Byte;
[0010] So: Byte2=IQ1
[0011] Byte3=R1*16+IQ2
[0012] Byte4=R2*8
[0013] Byte0-Byte7 should be operated in the same way according to the protocol, and then the 8 bytes should be combined into the array DATA and bundled with ID, MSG Type, and Length to output the result output cluster. The receiving and parsing is the opposite operation process, which is to unbundle the received output cluster and split it into ID, MSG Type, Length, and DATA. The DATA should be parsed according to the object position provided by the DBC protocol to display the CAN Signal. This operation process is extremely cumbersome, and each time the DBC protocol is changed, the operation must be re-performed according to the protocol. The operation process is complex and intertwined, with a high risk of error. The operation consumes a lot of time and has no universality. Summary of the invention
[0014] The technical problem to be solved by the present invention is to provide a CAN signal encapsulation and data analysis method, which can simplify the calculation process, save calculation time and has high versatility.
[0015] The technical solution adopted by the present invention to solve the technical problem is: to provide a CAN signal encapsulation method, comprising the following steps:
[0016] S0. Get the start bit, length, physical value, offset and transfer factor of the CAN signal to be packaged;
[0017] S1. Create an input array as a first array, wherein the first array is a Boolean array of a set size;
[0018] S2. Establish a conditional structure to reposition the start bit of the CAN signal to be packaged in the first array according to Boolean logic;
[0019] S3. Subtract the length of the CAN signal to be packaged from the output result of the conditional structure and add 1 to obtain the starting position of the CAN signal to be packaged in the first array as the target position;
[0020] S4. Calculate the original value of the CAN signal to be packaged according to the physical value, offset and transfer factor, and convert the calculated original value into a Boolean array to obtain a second array;
[0021] S5. Using the length of the CAN signal to be packaged as an index, calling the array element deletion function to delete the second array, and inverting the Boolean array of the deleted part to obtain a third array;
[0022] S6. Using the first array as the total array, the target position as the index, and the third array as the subarray, a function for replacing array subsets is called to generate a fourth array;
[0023] S7. Convert the fourth array into frame data of the CAN signal to be encapsulated.
[0024] Furthermore, the method further includes the step of encapsulating steps S0 to S7 into a sub-VI; the input of the sub-VI includes the start bit, length, physical value, offset and transfer factor of the CAN signal to be encapsulated, and the output of the sub-VI includes the frame data of the CAN signal to be encapsulated.
[0025] Furthermore, it also includes:
[0026] If there is more than one CAN signal to be packaged, the corresponding number of sub-VIs are connected in series, and a Boolean array is initialized as the input array of the first sub-VI, and the input arrays of other sub-VIs are set to the output of the previous sub-VI, and the frame data of the CAN signal to be packaged is obtained as the output of the last sub-VI.
[0027] Further, converting the fourth array into frame data of the CAN signal to be packaged includes:
[0028] Divide the fourth array into a plurality of subsets in sequence, with 8 elements as a group;
[0029] Each of the subsets is inverted respectively, and each of the inverted subsets is converted into numerical bytes according to Boolean operation logic to obtain frame data of the CAN signal to be encapsulated.
[0030] Furthermore, the second array is equal to the first array in size.
[0031] Furthermore, the original value of the CAN signal to be packaged is calculated by the following formula:
[0032]
[0033] The present invention also provides a CAN data parsing method, comprising the following steps:
[0034] S0. Get the frame data, start bit, length, offset and transfer factor of the CAN signal to be parsed;
[0035] S1. Convert each numerical byte of the frame data of the CAN signal to be analyzed into an array according to Boolean operation logic, and invert each array obtained by the conversion to obtain a first array, wherein the first array is a two-dimensional array of a set size;
[0036] S2. Calling the array dimension rearrangement function to rearrange the two-dimensional array to obtain a one-dimensional second array;
[0037] S3. Establish a conditional structure to reposition the start bit of the CAN signal to be parsed in the second array according to Boolean logic;
[0038] S4. Subtract the length of the CAN signal to be parsed from the output result of the conditional structure and add 1 to obtain the starting position of the CAN signal to be parsed in the second array as the target position;
[0039] S5. Using the target position as an index, calling an array subset function to extract a subset of the size equal to the length of the CAN signal to be parsed from the second array to obtain a third array;
[0040] S6. Inverting the third array to obtain a fourth array, and then converting the fourth array into a numerical value according to Boolean operation logic to obtain the original value of the CAN signal to be analyzed;
[0041] S7. Calculate and obtain the physical value of the CAN signal to be analyzed according to the original value, offset and transfer factor.
[0042] Furthermore, the physical value of the CAN signal to be analyzed is calculated by the following formula:
[0043]
[0044] Furthermore, the method further includes encapsulating steps S0 to S7 into a sub-VI; the input of the sub-VI includes the frame data, start bit, length, offset and transfer factor of the CAN signal to be analyzed, and the output of the sub-VI includes the physical value of the CAN signal to be analyzed.
[0045] Furthermore, it also includes:
[0046] If there is more than one CAN signal to be parsed, a corresponding number of the sub-VIs are connected in parallel, and the physical value of each CAN signal to be parsed is obtained as the output of the corresponding sub-VI.
[0047] Due to the adoption of the above-mentioned technical scheme, the present invention has the following advantages and positive effects compared with the prior art: the present invention generates corresponding frame data by performing Boolean operation logic processing on the received CAN signal, and encapsulates the entire processing process into a sub-VI. It only needs to input the start bit, length, offset and transfer factor corresponding to the CAN signal to obtain the required frame data; if multiple CAN signals are needed, it only needs to connect multiple sub-VIs in series, and finally output an 8-frame data, which is bundled to obtain the required output cluster, avoiding the risk of errors and serious time-consuming situations in the operation of multiple variables, while saving the operation time, improving the packaging efficiency, and being universal for the DBC protocol, even if other protocols are changed, there is no need to re-operate one by one; after the entire processing steps are encapsulated into a sub-VI, the program flowchart is also much simpler. For graphical programming environments such as LabVIEW, this formula is applicable to the operation of all hardware, and it also has higher versatility in hardware. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 is a schematic diagram of Boolean permutation operation according to the first embodiment of the present invention;
[0049] Figure 2 is a schematic diagram of the operation logic of the first embodiment of the present invention;
[0050] Figure 3 It is a schematic diagram of the CAN signal encapsulation process of the first embodiment of the present invention;
[0051] Figure 4 is a schematic diagram of the operation logic of the second embodiment of the present invention;
[0052] Figure 5 It is a schematic diagram of the CAN data analysis process of the second embodiment of the present invention. DETAILED DESCRIPTION
[0053] The present invention will be further described below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not intended to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms fall within the scope limited by the appended claims of the application equally.
[0054] The specific terms involved in this implementation are:
[0055] ID: frame name
[0056] MSG Type: frame type
[0057] LEN: Byte length
[0058] DATA: frame data
[0059] Byte: Byte
[0060] Bit: bit
[0061] DBC: A format of communication protocol files
[0062] CAN Signal: variable flag (object)
[0063] H_Byte: High Byte
[0064] L_Byte: low byte
[0065] Startbit: start bit
[0066] Length: bit length
[0067] Offset: offset
[0068] Factor: coefficient accuracy
[0069] Motorola: A type of variable flag, with the high byte on top and the low byte on the bottom
[0070] Intel: A type of variable flag, with the high byte at the bottom and the low byte at the top
[0071] The first embodiment of the present invention relates to a CAN signal encapsulation method, such as Figure 1 As shown, 64-bit data can be arranged and operated using Boolean in LabVIEW. The bit arrangement of the DBC protocol is from right to left, with the starting data being 0, while the Boolean operation is from left to right, with the starting data being 1. The regular arrangement layout and sequence mark of the 64-bit data composed of CAN DATA in the DBC protocol can be used to write formula logic operations, and finally encapsulated into a general operation logic formula. Only the CAN signal Startbit (start bit), Length (length), Offset (offset), and Factor (transfer factor) provided by DBC can accurately obtain the analysis results.
[0072] like Figure 2 As shown in the figure, the operation process of encapsulating the CAN Signal into 8 Byte DATA includes:
[0073] (1) Input array, the purpose is to initialize a 64-bit Boolean array to locate the entire logic;
[0074] (2) Create a conditional structure with the input condition as Startbit. The bit arrangement of the DBC protocol is from right to left. The CAN Signal in Motorola format has the high byte first and the low byte last, which means the starting order is from bottom to top, which is exactly the opposite of the Boolean order from left to right and from top to bottom. Therefore, the purpose of creating a conditional structure is to reposition the Startbit in the DBC format according to the logic in the Boolean array.
[0075] (3) The result of the case structure output minus Length plus 1 (the starting bit of the DBC array is 0) is to convert the DBC format Startbit to the Startbit in the Boolean array;
[0076] (4) The value obtained by (CAN Signal-Offset) / Factor is converted into a Boolean array, and the Boolean array of the deleted part is inverted by deleting the array elements with Length as the index;
[0077] (5) Using the array of step (1) as the total array, the result of step (3) as the index, and the result of step (4) as the sub-array, replace the array subset to obtain the arrangement layout of CAN Signal in the Boolean array. At this time, (CAN Signal-Offset) / Factor is a one-dimensional array result in the Boolean array;
[0078] (6) Arrange the one-dimensional array result into 8-bit groups by Byte;
[0079] (7) Use a For loop (loop the input result conditionally) to arrange the output array into groups of 8, then reverse it, and then convert it into a numerical value to obtain 8 Byte DATA.
[0080] The above operation process is encapsulated as follows Figure 3 In the subVI method shown in the figure, CAN Signal, Startbit, Length, Offset, and Factor are used as input objects, and DATA is used as the output object. After encapsulation, it is used as a formula type subVI. You only need to input the Startbit, Length, Offset, and Factor corresponding to the CAN Signal to get the required 8ByteDATA. If you need to encapsulate multiple CAN Signals, you only need to connect multiple subVIs in series and finally output an 8ByteDATA. After bundling, you can get the required output cluster.
[0081] A second embodiment of the present invention relates to a CAN data parsing method, such as Figure 4As shown in the figure, the operation process of parsing the received 8 ByteDATA into CAN Signal includes:
[0082] (1) DATA converts 8Byte into total data through array size, For loop, and index array, and then converts it into data, and then reverses it to obtain a two-dimensional array in DBC protocol format;
[0083] (2) The two-dimensional array is rearranged according to the array dimension to obtain a sub-array for Boolean array operation, which serves as the input end of the array subset;
[0084] (3) Create a conditional structure with the input condition as Startbit. The bit arrangement of the DBC protocol is from right to left. The CAN Signal in Motorola format has the high byte first and the low byte last, which means the starting order is from bottom to top, which is exactly the opposite of the Boolean order from left to right and from top to bottom. Therefore, the purpose of creating a conditional structure is to reposition the Startbit in the DBC format according to the logic in the Boolean array.
[0085] (4) The result of the case structure output minus Length plus 1 (the starting bit of the DBC array is 0) is the DBC format Startbit converted to the Startbit in the Boolean array, which is used as the index item of the array;
[0086] (5) Length is used as the length of the sub-array, and the array result intercepted by the Startbit and Length of the CAN Signal in the sub-array is obtained;
[0087] (6) The array result is inverted and converted into data;
[0088] (7) Multiply the data by the Factor and add the Offset to obtain the final CAN Signal that needs to be analyzed.
[0089] The above operation process is encapsulated as follows Figure 5 The subVI shown in the figure unbinds the received cluster, uses ID as the condition of the input conditional structure, uses DATA as the corresponding parsing input, and inputs the Startbit, Length, Offset, and Factor corresponding to the CAN Signal. Then, the CAN Signal result to be displayed can be prepared. If multiple CANSignal results need to be displayed, simply parse the DATA in parallel to obtain the required data.
Claims
1. A CAN signal encapsulation method, characterized in that: The following steps are involved: S0. Get the start bit, length, physical value, offset and transfer factor of the CAN signal to be packaged; S1. Create an input array as a first array, wherein the first array is a Boolean array of a set size; S2. Establish a conditional structure to reposition the start bit of the CAN signal to be packaged in the first array according to Boolean logic; S3. Subtract the length of the CAN signal to be packaged from the output result of the conditional structure and add 1 to obtain the starting position of the CAN signal to be packaged in the first array as the target position; S4. Calculate the original value of the CAN signal to be packaged according to its physical value, offset and transfer factor, and convert the calculated original value into a Boolean array to obtain a second array; the original value of the CAN signal to be packaged is calculated by the following formula: ; S5. Using the length of the CAN signal to be packaged as an index, calling the array element deletion function to delete the second array, and inverting the Boolean array of the deleted part to obtain a third array; S6. Using the first array as the total array, the target position as the index, and the third array as the subarray, a function for replacing array subsets is called to generate a fourth array; S7. Converting the fourth array into frame data of the CAN signal to be packaged; S8. Encapsulate steps S0 to S7 into a sub-VI, wherein the input of the sub-VI includes the start bit, length, physical value, offset and transfer factor of the CAN signal to be encapsulated, and the output of the sub-VI includes the frame data of the CAN signal to be encapsulated; if there is more than one CAN signal to be encapsulated, connect the corresponding number of sub-VIs in series, initialize a Boolean array as the input array of the first sub-VI, and set the input arrays of the other sub-VIs to the output of the previous sub-VI, and obtain the frame data of the CAN signal to be encapsulated as the output of the last sub-VI.
2. The method according to claim 1, characterized in that: The converting the fourth array into the frame data of the CAN signal to be packaged includes: Divide the fourth array into a plurality of subsets in sequence, with 8 elements as a group; Each of the subsets is inverted respectively, and each of the inverted subsets is converted into numerical bytes according to Boolean operation logic to obtain frame data of the CAN signal to be encapsulated.
3. The method according to claim 1, characterized in that The second array is equal to the first array in size.
4. A CAN data analysis method, characterized in that: The following steps are involved: S0. Get the frame data, start bit, length, offset and transfer factor of the CAN signal to be parsed; S1. Convert each numerical byte of the frame data of the CAN signal to be analyzed into an array according to Boolean operation logic, and invert each array obtained by the conversion to obtain a first array, wherein the first array is a two-dimensional array of a set size; S2. Calling the array dimension rearrangement function to rearrange the two-dimensional array to obtain a one-dimensional second array; S3. Establish a conditional structure to reposition the start bit of the CAN signal to be parsed in the second array according to Boolean logic; S4. Subtract the length of the CAN signal to be parsed from the output result of the conditional structure and add 1 to obtain the starting position of the CAN signal to be parsed in the second array as the target position; the physical value of the CAN signal to be parsed is calculated by the following formula: The physical value of the CAN signal to be packaged = the original value of the CAN signal to be packaged × the transfer factor of the CAN signal to be packaged + the offset of the CAN signal to be packaged; S5. Using the target position as an index, calling an array subset function to extract a subset of the size equal to the length of the CAN signal to be parsed from the second array to obtain a third array; S6. Inverting the third array to obtain a fourth array, and then converting the fourth array into a numerical value according to Boolean operation logic to obtain the original value of the CAN signal to be analyzed; S7. Calculate the physical value of the CAN signal to be analyzed based on the original value, offset and transfer factor; S8. Encapsulate steps S0 to S7 into a sub-VI, wherein the input of the sub-VI includes the frame data, start bit, length, offset and transfer factor of the CAN signal to be analyzed, and the output of the sub-VI includes the physical value of the CAN signal to be analyzed; if there is more than one CAN signal to be analyzed, a corresponding number of the sub-VIs are connected in parallel, and the physical value of each CAN signal to be analyzed is obtained as the output of the corresponding sub-VI.
Citation Information
Patent Citations
Message analysis method and system based on LabVIEW, electronic equipment and medium
CN110769002A
Controller platformization software calibratable CAN design method
CN112422391A