CN112769816B - Power supply monitoring high-speed CAN message processing method and system - Google Patents

Power supply monitoring high-speed CAN message processing method and system Download PDF

Info

Publication number
CN112769816B
CN112769816B CN202110004996.3A CN202110004996A CN112769816B CN 112769816 B CN112769816 B CN 112769816B CN 202110004996 A CN202110004996 A CN 202110004996A CN 112769816 B CN112769816 B CN 112769816B
Authority
CN
China
Prior art keywords
message
hash table
perfect hash
perfect
power supply
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110004996.3A
Other languages
Chinese (zh)
Other versions
CN112769816A (en
Inventor
林飞浪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fiberhome Telecommunication Technologies Co Ltd
Original Assignee
Fiberhome Telecommunication Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fiberhome Telecommunication Technologies Co Ltd filed Critical Fiberhome Telecommunication Technologies Co Ltd
Priority to CN202110004996.3A priority Critical patent/CN112769816B/en
Publication of CN112769816A publication Critical patent/CN112769816A/en
Application granted granted Critical
Publication of CN112769816B publication Critical patent/CN112769816B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9014Indexing; Data structures therefor; Storage structures hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/40006Architecture of a communication node
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40215Controller Area Network CAN

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention discloses a power supply monitoring high-speed CAN message processing method and a system thereof.A perfect hash table is constructed for caching CAN messages, each hash table row corresponds to a message ID, and a corresponding analytic function inlet is assigned to the CAN message of each ID in the perfect hash table; after the power supply monitors and receives the CAN message, the position of the CAN message in the perfect hash table is positioned according to the message ID, and the CAN message is cached to the corresponding position in the perfect hash table; traversing the perfect hash table after the message reception in the current round is finished, and calling corresponding analysis functions in sequence according to the message ID to finish the analysis processing of each CAN message in the perfect hash table. The scheme solves the problems of message receiving and caching during the impact of a large number of messages, solves the problem of excessive branch structures during the message analysis, and improves the message analysis processing capacity.

Description

Power supply monitoring high-speed CAN message processing method and system
Technical Field
The invention belongs to the technical field of CAN communication, and particularly relates to a power supply monitoring high-speed CAN message processing method and system.
Background
A Controller Area Network (CAN) belongs to the field of field bus, is a serial communication Network which effectively supports a distributed control system, and is also a serial communication bus developed specially for the automobile industry in the 80 s of the 20 th century. The automobile engine has been widely applied to the fields of automobile industry, aviation industry, industrial control, safety protection and the like at present due to the fact that the automobile engine is more and more emphasized by people due to high performance, high reliability and unique design.
The power supply system is equipment for converting high-voltage alternating current or high-voltage direct current into low-voltage direct current for operation of communication equipment. The power supply system is generally composed of a power supply monitor and a plurality of rectifier modules, wherein the power supply monitor is used for monitoring the running condition of the whole power supply, controlling and adjusting the whole power supply system, and reporting various environmental parameters, performances, states, alarms and other data of the system; the rectifier module is used to convert high-voltage ac or high-voltage dc into low-voltage dc, typically 220V ac into 48V dc, or 220V dc into 48V dc.
The power supply monitoring and rectifying modules communicate through a CAN bus, namely, a protocol of a user is added in the definition of a CAN basic frame structure to form CAN messages of an application layer, and meanings and formats of different messages are specified according to different definitions of CAN message IDs so as to provide the application layer for effective communication. As shown in fig. 1, for a power supply system, one power supply monitor is usually used to manage a plurality of rectifier modules, and at most, there may be several tens of rectifier modules, where the power supply monitor is a request node and the rectifier modules are response nodes, and the number of rectifier modules is represented by n in the figure. Because the power monitoring uses the broadcast command query, a plurality of rectifier modules simultaneously return a plurality of messages to the power monitoring, and under the condition of the CAN bus bandwidth of 1M, the power monitoring CAN receive a large number of messages in a short time (usually within a few milliseconds). If the message receiving capability monitored by the power supply is insufficient, a large amount of message impact is easily formed, and message loss is caused.
At present, the power supply monitoring mainly performs the CAN message processing by the following means:
1) receiving one strip, saving one strip and analyzing one strip. Because a relatively long time is usually required for analyzing the message, when a large number of messages need to be received in a short time, the receiving and analyzing processes of all the messages cannot be completed in time, and thus a packet loss phenomenon is generated.
2) And a receiving queue is used for caching the messages, and the messages are taken out from the receiving queue by the analysis process to be analyzed one by one. The method can solve the problem of instantly receiving a large number of messages, but a large queue needs to be preset, the occupied space of the queue is large, and the phenomenon of packet loss can occur when the receiving queue is full.
3) Analyzing the messages by using a branch structure, and respectively processing each CAN message according to the message ID; specifically, if the message ID is 1, finding the parsing function of the message 1 according to the ID and executing; if the message ID is 2, finding the analytic function of the message 2 according to the ID and executing, and so on. When the number of the message IDs to be analyzed is large, the branch structure becomes huge and bloated, the execution efficiency is low, and more time is required for message analysis.
Based on the defects of the three methods, the problems to be solved by the scheme mainly have two aspects: on one hand, the problem of receiving and caching a large number of messages during impact is solved, and on the other hand, the problem of excessive branch structures during message analysis is solved. In summary, that is, how to timely perform message receiving, caching and parsing processing when a large number of messages are impacted in power supply monitoring, it is ensured that the messages are not lost.
Disclosure of Invention
Aiming at the defects or the improvement requirements of the prior art, the invention provides a power supply monitoring high-speed CAN message processing scheme, aiming at improving the message processing capability of power supply monitoring and avoiding packet loss, thereby solving the technical problem that the power supply monitoring cannot timely receive, cache and analyze messages when a large number of messages are impacted in the traditional scheme.
In order to achieve the above object, according to an aspect of the present invention, there is provided a power monitoring high-speed CAN packet processing method, including:
constructing a perfect hash table for caching CAN messages, enabling each hash table row to correspond to one message ID, and assigning a corresponding analysis function inlet for the CAN message of each ID in the perfect hash table;
after the power supply monitors and receives the CAN message, the position of the CAN message in the perfect hash table is positioned according to the message ID, and the CAN message is cached to the corresponding position in the perfect hash table;
traversing the perfect hash table after the message reception in the current round is finished, and calling corresponding analysis functions in sequence according to the message ID to finish the analysis processing of each CAN message in the perfect hash table.
Preferably, the constructing of the perfect hash table is used for caching the CAN packet, so that each hash table row corresponds to one packet ID, and a corresponding parsing function entry is formulated for the CAN packet of each ID in the perfect hash table, specifically:
establishing a hash table row for each CAN message needing to be received based on the message ID, and distributing a data field for the corresponding message ID in each hash table row;
creating an analytic function for each message ID, and filling an inlet address of the analytic function into a corresponding hash table row;
and establishing a mapping relation between the message ID and the hash code in a mapping array form.
Preferably, the establishing a mapping relationship between the packet ID and the hash code in the form of a mapping array specifically includes:
and taking the low m bits of the message ID as a reference object, and establishing a mapping relation between the low m bits of the message ID and the hash code to form a mapping array.
Preferably, after the power supply monitors and receives the CAN packet, the position of the CAN packet in the perfect hash table is located according to the packet ID, and the CAN packet is cached to the corresponding position in the perfect hash table, specifically:
reading a message ID after the power supply monitors that a CAN message is received;
based on the message ID, acquiring a corresponding hash code through a mapping array;
according to the hash code, positioning the cache position of the CAN message in the perfect hash table;
and copying the message ID and the data field of the CAN message to the corresponding position in the perfect hash table.
Preferably, the power supply monitoring receives the messages through interruption, an interruption is generated when a CAN message is received, and the reading and the caching of the message are completed in the interruption.
Preferably, traversing the perfect hash table, sequentially calling corresponding parsing functions according to the packet IDs, and completing parsing processing of each CAN packet in the perfect hash table, specifically:
initializing the value of the hash code i to 0;
judging whether the current hash code i is smaller than the total row number N of the perfect hash table;
if so, calling an analytic function of the ith row in the perfect hash table to analyze the CAN message of the ith row, adding 1 to the value of the hash code i, and continuously judging whether the current hash code i is smaller than N or not until the current hash code i is equal to N and stopping traversing.
Preferably, after the parsing processing of each CAN packet in the perfect hash table is completed, the method further includes:
the power supply monitoring sends out a broadcast query command so as to query the information of each rectifier module;
and after delaying preset time and waiting for the next round of message reception, continuously traversing the perfect hash table, and sequentially calling corresponding analysis functions according to the message ID to complete the analysis processing of each CAN message in the current perfect hash table.
Preferably, the preset time ranges from 1s to 5 s.
According to another aspect of the invention, a power supply monitoring high-speed CAN message processing system is provided, which comprises a power supply monitor and a plurality of rectifier modules, wherein the power supply monitor is communicated with the plurality of rectifier modules through a CAN bus;
a perfect hash table, an information polling module and a CAN receiving interruption module are arranged in the power supply monitoring;
the perfect hash table is used for storing the CAN messages, enabling each hash table row to correspond to one message ID, and assigning a corresponding analysis function inlet for the CAN message of each ID;
the information polling module is used for sending a broadcast query command to the plurality of rectifying modules so as to query the information of each rectifying module; traversing the perfect hash table, and calling corresponding analysis functions in sequence according to the message ID to complete analysis processing of each CAN message in the perfect hash table;
the CAN receiving interruption module is used for receiving the CAN messages returned by the plurality of rectification modules, positioning the position of the CAN message in the perfect hash table according to the message ID, and further caching the CAN message to the corresponding position in the perfect hash table.
Preferably, a CAN module is further arranged in the power supply monitoring, and the CAN module is configured to send a broadcast query command sent by the information polling module to the plurality of rectifier modules through a CAN bus, receive and store CAN messages returned by the plurality of rectifier modules in a register, and trigger the calling of the CAN reception interrupt module.
Generally, compared with the prior art, the technical scheme of the invention has the following beneficial effects: in the power supply monitoring high-speed CAN message processing scheme provided by the invention, a perfect hash table is created to cache the message, the CAN message CAN be positioned at the position in the hash table directly according to the message ID after being received, and then the CAN message is cached to the corresponding position in the hash table, so that the message receiving and caching problems when a large number of messages impact are solved; in addition, a method of caching and then analyzing is adopted, an entry of an analysis function is established for each message in a perfect hash table by using a strategy mode, and the corresponding analysis functions can be sequentially called to analyze and process each message by traversing the hash table, so that the problem of excessive branch structures during message analysis is solved, and the message analysis and processing capacity is improved.
Drawings
Fig. 1 is a schematic diagram of a CAN communication model between a power supply monitoring and rectifying module according to an embodiment of the present invention;
fig. 2 is a schematic flow chart of a power supply monitoring high-speed CAN message processing method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a perfect hash table according to an embodiment of the present invention;
fig. 4 is a schematic diagram illustrating a mapping between a message ID and a hash code in a perfect hash table according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of an execution policy of parsing and then querying according to an embodiment of the present invention;
fig. 6 is a timing diagram of a power monitoring polling arrangement module and a message receiving process according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a power monitoring high-speed CAN message processing system according to an embodiment of the present invention;
fig. 8 is a flowchart of a polling task processing of an information polling module according to an embodiment of the present invention;
fig. 9 is a flowchart of receiving and processing a message by a CAN receive interrupt module according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. In addition, the technical features involved in the respective embodiments of the present invention described below may be combined with each other as long as they do not conflict with each other.
Example 1
In order to solve the technical problem that the power monitoring cannot timely receive, cache and analyze the message when a large number of messages are impacted in the conventional scheme, an embodiment of the invention provides a power monitoring high-speed CAN message processing method, as shown in FIG. 2, which mainly comprises the following steps:
and step 10, constructing a perfect hash table for caching the CAN messages, enabling each hash table row to correspond to one message ID, and assigning a corresponding analysis function inlet for the CAN message of each message ID in the perfect hash table.
The invention mainly solves the problem of packet loss caused by impact of a large number of messages, so that a data structure capable of being accessed quickly is required to be used for caching the messages. The perfect hash table is also called an ideal hash table, and refers to a hash table without hash code collision, namely each hash code is unique; the complexity of the access time of the perfect hash table is O (1), that is, the time required for access is constant no matter how large the hash table is, how many messages are, and where the message to be stored is in the hash table, and is a small constant, similar to accessing an element of a certain specified subscript of the integer array, thereby meeting the requirement of quick access. In the embodiment of the invention, the message ID types of the CAN messages required to be received by the power supply monitoring are clear, the number of the message IDs is limited, and each message ID CAN be mapped to a unique hash code (namely, a hash subscript) to meet the condition of creating a perfect hash table, so that the power supply monitoring CAN cache the messages by constructing the perfect hash table.
It should be noted that the message ID identifies a type of message rather than a specific message, and the message ID may identify various information, such as a protocol version, an equipment address, a message type, and the like; the message ID in the hash table mainly intercepts the device address and the message type therein, so as to distinguish different devices and different information types. Each row of the hash table comprises a message ID, a data field and a pointer of an analytic function, and the specific construction process is as follows:
1) when the system is initialized, a hash table row is established for each CAN message needing to be received based on the message ID, and a data field is distributed for the corresponding message ID in each hash table row. The purpose of constructing the perfect hash table is to store the CAN packet, and each packet is an object in units of the CAN packet, so each line of the perfect hash table is used to represent a packet, and the unique identifier of the packet is a packet ID, such as x, y, z, etc. in fig. 3, so that in practice, a hash table line is created for each packet ID and a data field is allocated to the hash table line.
2) And when the system is designed, an analytic function is established for each message ID, and when the system is initialized, the inlet address of the analytic function is filled into the corresponding hash table row.
In order to solve the problem of excessive branch structure during message parsing, the invention uses a policy mode, the policy mode is one of design modes, the design mode is usually applied to object-oriented programming, although the C language is not the object-oriented programming language, the C language can also imitate the realization idea of the policy mode: declaring a function pointer in a structure body, wherein the function pointer is used for specifying a strategy function (namely an analytic function in a text) of a structure body variable; when the message structure needs to be analyzed, the corresponding strategy function can be called through the strategy function pointer in the structure. The advantage of this is that when a structure variable array needs to be processed, a loop can be used to sequentially call the policy functions of all the structure variables to complete the analysis of all the message structures. In view of the above principle, the present invention uses a policy model to assign a parsing function entry to each packet in the hash table, i.e. to fill a parsing function entry address (also called a function pointer) into a corresponding hash table row, such as parsing function x, parsing function y, parsing function z, etc. in fig. 3, so as to parse the packet through function call in the following.
3) When the system is initialized, the mapping relation between the message ID and the hash code is established in a mapping array mode.
The use of a hash table requires a hash function to uniquely map the packet ID to a hash index, i.e., a hash code. In the scene of the invention, the perfect hash table is static and is clear when the system is constructed, and the hash table has no addition or deletion of elements in the operation process, so a mapping array can be used for recording the hash code corresponding to each message ID when the system is initialized, and the hash code can be directly obtained through the message ID in the operation process of the system. Referring to FIG. 4, as the mapping array declares short id _ to _ hash _ code [256 ]; traversing the packet ID of the perfect hash table during initialization, where the packet ID is used as a subscript of the mapping array, and the hash code is used as a value of a corresponding position of the mapping array, then the initialization will be performed, for example: id _ to _ hash _ code [11] ═ 0; id _ to _ hash _ code [35] ═ 1; ... ID _ to _ hash _ code [ z ] ═ n, thereby establishing a mapping relationship between the packet ID and the hash code.
The length of the mapping array is required to be greater than or equal to the maximum message ID, so that the lower m bits of the message ID are usually taken as a reference object, and the mapping relationship between the lower m bits of the message ID and the hash code is established to form the mapping array. For example, the lower 8 bits of the packet ID (i.e. m is 8) are taken as a reference object, and a mapping relationship between the lower 8 bits of the packet ID and the hash code is established to form a mapping array, so that the size of the mapping array is 0 XFF. After the mapping relation between the message ID and the hash code is formed by using the mapping array, the hash table only needs a plurality of rows according to the number of the message IDs and does not need to realize the hash table according to the largest message ID in a redundant mode, so that the system memory is saved.
And 20, after the power supply monitors and receives the CAN message, positioning the position of the CAN message in the perfect hash table according to the message ID, and then caching the CAN message to the corresponding position in the perfect hash table.
Referring to fig. 1, after the power supply monitor sends out the broadcast query command, a large number of CAN messages returned by the plurality of rectifier modules are received in a short time, so as to query the performance, state, alarm and other information of each rectifier module. In the present invention, if the CAN message receiving mode is configured to be an interrupt receiving mode, the power supply monitors that a message is received by interrupt, and an interrupt is generated when a CAN message is received, and the reading and the buffering of the message are completed in the interrupt, that is, the step 20 is completed in the interrupt. The specific process is as follows: reading a message ID after a CAN message is received by the power supply monitoring through interruption each time; then based on the message ID, acquiring a corresponding hash code through a mapping array; further positioning the cache position of the CAN message in the perfect hash table according to the hash code; and finally, copying the message ID and the data field of the CAN message to the corresponding position in the perfect hash table to finish the cache of the CAN message to the perfect hash table.
Taking fig. 4 as an example, when the ID of the received packet is 11, by taking the ID _ to _ hash _ code [11] corresponding to the mapping array, it is known that the hash code 0 CAN be taken out when the ID _ to _ hash _ code [11] is 0, so that the CAN packet is cached to the 0 th line of the perfect hash table; when the ID of the received message is 35, the ID _ to _ hash _ code [35] of the corresponding position of the mapping array is taken to know that the ID _ to _ hash _ code [35] is 1, namely the hash code 1 CAN be taken out, so that the CAN message is cached to the 1 st line of the perfect hash table; by analogy, all the received CAN messages CAN be cached in the perfect hash table. Because the message is cached by using the perfect hash table, and the access time complexity of the perfect hash table is O (1), the processing time of receiving and caching all messages is a very small constant no matter what kinds of the messages need to be received, so that the cache address CAN be quickly positioned in the hash table when the CAN message is received, and the CAN message is written into the corresponding cache space, thereby realizing quick access and solving the problem of packet loss caused by impact of a large number of messages.
And step 30, traversing the perfect hash table after the message reception in the current round is finished, and calling corresponding analysis functions in sequence according to the message ID to finish the analysis processing of each CAN message in the perfect hash table.
Because the invention uses the strategy mode, a strategy function inlet is assigned to each message in the hash table in advance, so that the analysis of all messages can be completed by traversing the perfect hash table and calling each strategy function in the perfect hash table in sequence during the analysis, and the branch structure of the analyzed messages is removed. The strategy function is characterized in that the function prototype is the same, but the logic inside the function is different, so that the analysis of different messages can be completed by using a uniform calling form.
In order to receive all messages when a large number of messages are impacted, analysis operation must be abandoned first, and the receiving is focused on; and after one round of message receiving is finished, uniformly analyzing the messages. Since in the case of broadcast polling, the power supply monitoring typically polls the rectifier module once in 1 or a few seconds, whereas data messages may return centrally within a few milliseconds. Therefore, the time for receiving the message is only a few milliseconds, while the time for analyzing the message is more than one second, and the message receiving and the time-consuming analysis are separately processed, so that the analysis process can be prevented from influencing the receiving, and all returned messages are ensured to be received.
Based on the principle, the invention adopts a strategy of 'caching before analyzing', and can complete all message analysis in the hash table shown in fig. 3 by using a cycle after the message reception in the current round is finished. The specific traversal analysis process is as follows: firstly, initializing the value of a hash code i to 0; then, judging whether the current hash code i is smaller than the total row number N of the perfect hash table; if so, calling an analytic function of the ith row in the perfect hash table to analyze the CAN message of the ith row, adding 1 to the value of the hash code i, continuously judging whether the current hash code i is smaller than N, and circularly judging and executing until the current hash code i is equal to N and stopping traversing. The loop statements used correspondingly are as follows:
for(i=0;i<N;i++)
{
hash_table[i].handler(data);
}
further, in the conventional scheme, a "query first and then parse" strategy is usually used, that is, after the power supply monitors and sends out a broadcast query command, the message parsing is performed on the received CAN message, but this cannot ensure that the parsing is already started if all the response messages are returned, and cannot start new query immediately after the message parsing is completed. To this end, in a preferred embodiment, the present invention uses a "parse-then-query" strategy, specifically a "parse-then-query, delay wait, parse-then-query" loop process, as shown in fig. 5. The method comprises the following specific steps:
after step 30, that is, after the parsing process of each CAN packet in the round of perfect hash table is completed, the method further includes: the power supply monitoring sends out a broadcast query command so as to query the information of the performance, the state, the alarm and the like of each rectifier module; then, delaying preset time for waiting for the next round of message reception, then continuously traversing the perfect hash table, and sequentially calling corresponding analysis functions according to the message ID to complete analysis processing of each CAN message (namely all messages cached in the next round) in the current perfect hash table; the value range of the preset time is 1s to 5s, and the value of the preset time is 1s in fig. 5 as an example.
Since the receiving and buffering of the message are implemented in the interruption, it is necessary to perform parsing after a certain delay after the query, which is equivalent to completing the receiving and buffering of the message of the query within the preset time, i.e. completing step 20. Although the message is returned in milliseconds under normal conditions, the response message can be ensured to be returned completely by matching with the duration of the query period, delaying for 1 second or several seconds or analyzing again for the robustness and expansibility of the system; after analysis, time delay is not needed, and the next round of inquiry is carried out immediately, so that the inquiry efficiency can be improved, and unnecessary time delay waiting is reduced.
It should be noted that when the "parse-before-query" strategy is used, the first round of parsing after system initialization is actually meaningless because: firstly, analyzing and then inquiring, wherein each time of analysis is actually the result of the inquiry of the previous round; and because the system executes the analysis before being electrified without query operation, and the perfect hash table does not cache normal messages at the moment, the analysis has no substantial significance and is only an execution process.
Based on the policy of "buffer first and then analysis, analysis first and then query" in the embodiment of the present invention, the timing chart of the power monitoring polling arrangement module and the message receiving and processing may refer to fig. 6, and the power monitoring module needs to query various information of the rectifier module, such as output voltage, current, power, temperature, and the like of the rectifier module, every 1 second or several seconds. After the power supply monitoring sends out the broadcast inquiry command, the power supply monitoring can carry out time delay of preset time, and within the time delay, the power supply monitoring can finish message receiving interruption and message caching; the time for interrupting the message reception is millisecond, and after the message is received and buffered, a certain idle time usually exists. After the delay is over, all response messages are ensured to be completely returned and received, so that the CAN messages in the hash table CAN be uniformly analyzed, and the message receiving and analyzing separation is realized; wherein, the message analysis time is millisecond level. After the analysis is finished, a broadcast query command can be sent out immediately, and the next round of query is continued.
In summary, the message processing method provided in the embodiments of the present invention not only solves the problems of receiving and caching when a large number of messages are impacted, but also solves the problem of excessive branch structures when the messages are analyzed. Wherein:
the problems of receiving and caching when a large number of messages are impacted are mainly solved based on the following steps: firstly, a CAN message is cached by using a perfect hash table, the complexity of access time is O (1), and quick access CAN be realized no matter how large the hash table is and how many messages are; secondly, a strategy of 'caching first and then analyzing' is used, message receiving and message analyzing are separately processed, the cached message is received quickly first, and then the message is analyzed uniformly, so that the receiving influence of an analysis flow can be avoided, and the message receiving capacity of power supply monitoring is improved; thirdly, a strategy of 'analyzing first and then inquiring' is used, enough time is left to ensure that the message is completely returned, and new inquiry can be started immediately after the analysis is finished. By the method, the problem that the information of the rectifier module cannot be received and analyzed in time due to the impact of a large number of instant CAN messages when the power supply monitors, broadcasts and inquires the information of the rectifier module is solved, and the phenomenon of packet loss is avoided. In addition, when the hash table is created, a mapping array is used for storing the mapping relation from the message ID to the hash code, so that the method is efficient and saves memory.
The problem of excessive branch structure in message parsing is mainly solved based on the following steps: and (3) using a strategy mode, making a strategy function inlet for each message in the cache hash table in advance, traversing the hash table through a cycle after receiving all response messages in the round, and calling the strategy functions in the hash table in sequence to finish the analysis of all messages. Through the strategy mode, a branch structure of the traditional message analysis processing is removed, the code is simpler, and the expandability is better.
Example 2
In order to solve the technical problem that the power monitoring cannot timely perform message receiving, caching and parsing when a large number of messages are impacted in the conventional scheme, an embodiment of the present invention provides a power monitoring high-speed CAN message processing system, which is used for implementing the message processing method in embodiment 1.
As shown in fig. 7, the message processing system provided in the embodiment of the present invention mainly includes a power supply monitor and a plurality of rectifier modules (i.e., the rectifier modules 1 to n in the figure), and the power supply monitor communicates with the plurality of rectifier modules through a CAN bus. The power supply monitoring can issue a broadcast query command to the plurality of rectifier modules, and all the rectifier modules can immediately return data frame messages, so that the power supply monitoring can receive a large number of messages in a short time.
A perfect hash table, an information polling module and a CAN receiving interruption module are arranged in the power supply monitoring, and the perfect hash table, the information polling module and the CAN receiving interruption module are also main modules related to the CAN processing of an internal program of the power supply monitoring. Wherein:
the perfect hash table is used for storing the CAN messages, each hash table row corresponds to one message ID, and a corresponding analysis function inlet is assigned to the CAN message of each ID. In a perfect hash table, each hash table row includes a packet ID, a corresponding data field, and a pointer to a parsing function, and the packet ID is uniquely mapped to a hash code in the form of a mapping array, as shown in fig. 3, 4, and 7. The specific process of constructing the perfect hash table may refer to the related description of step 10 in embodiment 1, which is not described herein again.
The information polling module is used for sending a broadcast query command to the plurality of rectifying modules so as to query the information of each rectifying module; and on the other hand, the method is used for traversing the perfect hash table, and sequentially calling corresponding analysis functions according to the message ID to finish the analysis processing of each CAN message in the perfect hash table. The information polling module adopts an execution mode of 'analysis before query', sends out a broadcast query command after the analysis is finished, and continues traversing the hash table for the next round of message analysis after delaying preset time after sending out the broadcast query command each time.
The CAN receiving interruption module is used for receiving and caching messages, and specifically comprises the following steps: and receiving the CAN messages returned by the plurality of rectifier modules, positioning the position of the CAN message in the perfect hash table according to the message ID, and caching the CAN message to the corresponding position in the perfect hash table.
Continuing to refer to fig. 7, the power supply monitoring device is further provided with a CAN module, and the CAN module is configured to send a broadcast query command sent by the information polling module to the plurality of rectifier modules through a CAN bus, receive and store CAN messages returned by the plurality of rectifier modules in a register, and trigger the calling of the CAN reception interrupt module. The CAN module comprises a CAN controller on the single chip microcomputer and a CAN transceiver outside the single chip microcomputer, a register is arranged on the CAN controller, and the CAN module receives CAN messages returned by the rectifier modules through the CAN transceiver and the CAN controller and temporarily stores message IDs on the register.
The following describes the function implementation of the information polling module and the CAN reception interruption module in detail with reference to the accompanying drawings.
As shown in fig. 8, the information polling module mainly performs the following operations according to the illustrated flow:
1) and initializing the system and constructing a perfect hash table. Each row of the hash table is an object, wherein the object comprises a message ID, a data field and a pointer of an analytic function; during initialization, a hash table row is created for each CAN message ID needing to be received, and a data field and an analytic function pointer are distributed for the hash table row; and meanwhile, establishing a mapping relation between the message ID and the subscript of the hash table to form a mapping array. The specific construction process may refer to the related description of step 10 in embodiment 1, and is not described herein again.
2) And starting to analyze the messages, namely traversing the hash table, and sequentially calling the analysis functions of all the messages according to the message IDs to finish the analysis of all the messages. Because the strategy of 'analyzing first and then inquiring' is used, each analysis is actually the result of the last round of inquiry; and when the system is just powered on, the analysis is executed firstly without query operation, and at the moment, normal messages are not cached in the perfect hash table, so that the first analysis after the system initialization is meaningless in practice and is only an execution process. Traversal resolution process referring to fig. 8: initializing the value of a hash code i to 0; then judging whether the current hash code i is smaller than the total row number N of the perfect hash table; if so, calling an analytic function of the ith row in the perfect hash table to analyze the CAN message of the ith row, adding 1 to the value of the hash code i, continuously judging whether the current hash code i is smaller than N, and circularly judging and executing until the current hash code i is equal to N and stopping traversing.
3) And after traversing analysis is finished, namely judging whether the current hash code i is less than the total line number N of the perfect hash table or not, and sending a broadcast query command to query information such as performance, state, alarm and the like of the rectification module if the judgment result is negative.
4) Delaying for a preset time, for example, 1s, and then repeatedly performing the above steps 2) to 4).
The implementation of the method uses implicit processing skills, the information polling task is only responsible for sending out a broadcast query command, and after the delay waiting of the preset time, the hash table is traversed to call the analysis function to realize the analysis of each message, so that the cyclic processing flow of 'message receiving and analysis separation', 'firstly analysis, then query, then delay and then analysis' is realized. Because the message is received and cached in the interrupt, although the message is returned in a few milliseconds under normal conditions, for the robustness and expansibility of the system, the duration of the query period is matched, and the message is necessary to be analyzed after a certain delay, so that all the messages are returned completely, and then the next round of query is immediately carried out.
And the CAN receiving interruption module generates an interruption when receiving a message, and finishes reading and caching the message in the interruption. As shown in fig. 9, when receiving one message, the message reception interruption mainly executes the following operations according to the flow shown in the figure:
1) entering CAN message receiving interruption;
2) reading a message ID from a register of the CAN module;
3) taking specific m bits in the message ID, and acquiring a hash code based on the message ID through a mapping array;
4) according to the hash code, positioning the cache position of the message in the perfect hash table;
5) and copying the message ID and the data field to the corresponding position of the perfect hash table. And receiving and caching the CAN message.
In the message processing system provided by the embodiment of the invention, the power supply monitoring caches the CAN message by using the perfect hash table, the strategy of caching firstly and then analyzing is used for separately processing the message receiving and message analyzing, and the strategy of analyzing firstly and then inquiring is used for reserving enough time to ensure that the message is completely returned, so that the problem that the message cannot be received and analyzed in time due to the impact of a large amount of instant CAN messages when the power supply monitors, broadcasts and inquires information of a rectifier module is solved, and the phenomenon of packet loss is avoided. In addition, a policy function inlet is made in the cache hash table for each message in advance by using a policy mode, after all response messages in the round are received, the policy functions in the hash table can be called in sequence by traversing the hash table in a circulating way, the analysis of all messages is completed, and the problem of excessive branch structures in the message analysis is solved.
It will be understood by those skilled in the art that the foregoing is only a preferred embodiment of the present invention, and is not intended to limit the invention, and that any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (10)

1. A power supply monitoring high-speed CAN message processing method is characterized by comprising the following steps:
constructing a perfect hash table for caching CAN messages, enabling each hash table row to correspond to one message ID, and assigning a corresponding analysis function inlet for the CAN message of each ID in the perfect hash table;
after the power supply monitors and receives the CAN message, the position of the CAN message in the perfect hash table is positioned according to the message ID, and the CAN message is cached to the corresponding position in the perfect hash table;
traversing the perfect hash table after the message reception in the current round is finished, and calling corresponding analysis functions in sequence according to the message ID to finish the analysis processing of each CAN message in the perfect hash table.
2. The method according to claim 1, wherein the building of the perfect hash table is used for caching CAN packets, so that each hash table row corresponds to one packet ID, and a corresponding parsing function entry is formulated for each ID CAN packet in the perfect hash table, specifically:
establishing a hash table row for each CAN message to be received based on the message ID, and distributing a data field for the corresponding message ID in each hash table row;
creating an analytic function for each message ID, and filling an inlet address of the analytic function into a corresponding hash table row;
and establishing a mapping relation between the message ID and the hash code in a mapping array form.
3. The method for processing the power monitoring high-speed CAN packet according to claim 2, wherein the mapping relationship between the packet ID and the hash code is established in a form of a mapping array, specifically:
and taking the low m bits of the message ID as a reference object, and establishing a mapping relation between the low m bits of the message ID and the hash code to form a mapping array.
4. The method according to claim 2, wherein after the power supply monitor receives the CAN packet, the power supply monitor locates the position of the CAN packet in the perfect hash table according to the packet ID, and further caches the CAN packet to the corresponding position in the perfect hash table, specifically:
reading a message ID after the power supply monitors that a CAN message is received;
based on the message ID, acquiring a corresponding hash code through a mapping array;
according to the hash code, positioning the cache position of the CAN message in the perfect hash table;
and copying the message ID and the data field of the CAN message to the corresponding position in the perfect hash table.
5. The power-monitoring high-speed CAN message processing method of claim 4, wherein the power monitoring receives messages by interrupting, generating an interrupt every time a CAN message is received, and completing reading and buffering of the message in the interrupt.
6. The power monitoring high-speed CAN packet processing method according to claim 2, wherein traversing the perfect hash table, sequentially calling corresponding parsing functions according to packet IDs, and completing parsing processing of each CAN packet in the perfect hash table, specifically:
initializing the value of the hash code i to 0;
judging whether the current hash code i is smaller than the total row number N of the perfect hash table;
if so, calling an analytic function of the ith row in the perfect hash table to analyze the CAN message of the ith row, adding 1 to the value of the hash code i, and continuously judging whether the current hash code i is smaller than N or not until the current hash code i is equal to N and stopping traversing.
7. The power-monitoring high-speed CAN packet processing method according to any of claims 1-6, wherein after said completion of the parsing process of each CAN packet in the perfect hash table, the method further comprises:
the power supply monitoring sends out a broadcast query command so as to query the information of each rectifier module;
and after delaying the preset time and waiting for the next round of message reception, continuously traversing the perfect hash table, and sequentially calling corresponding analysis functions according to the message ID to complete the analysis processing of each CAN message in the current perfect hash table.
8. The power supply monitoring high-speed CAN message processing method according to claim 7, wherein the preset time is in a range of 1 s-5 s.
9. A power supply monitoring high-speed CAN message processing system is characterized by comprising a power supply monitor and a plurality of rectifier modules, wherein the power supply monitor is communicated with the plurality of rectifier modules through a CAN bus;
a perfect hash table, an information polling module and a CAN receiving interruption module are arranged in the power supply monitoring;
the perfect hash table is used for storing the CAN messages, enabling each hash table row to correspond to one message ID, and assigning a corresponding analysis function inlet for the CAN message of each ID;
the information polling module is used for sending a broadcast query command to the plurality of rectifying modules so as to query the information of each rectifying module; traversing the perfect hash table after the message in the current round is received by the CAN receiving interruption module, and calling corresponding analysis functions in sequence according to the message ID to complete the analysis processing of each CAN message in the perfect hash table;
the CAN receiving interruption module is used for receiving the CAN messages returned by the plurality of rectification modules, positioning the position of the CAN message in the perfect hash table according to the message ID, and further caching the CAN message to the corresponding position in the perfect hash table.
10. The power monitoring high-speed CAN message processing system according to claim 9, wherein a CAN module is further provided in the power monitoring, and the CAN module is configured to send a broadcast query command sent by the information polling module to the plurality of rectifier modules through a CAN bus, store CAN message reception returned by the plurality of rectifier modules in a register, and trigger invocation of the CAN reception interrupt module.
CN202110004996.3A 2021-01-04 2021-01-04 Power supply monitoring high-speed CAN message processing method and system Active CN112769816B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110004996.3A CN112769816B (en) 2021-01-04 2021-01-04 Power supply monitoring high-speed CAN message processing method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110004996.3A CN112769816B (en) 2021-01-04 2021-01-04 Power supply monitoring high-speed CAN message processing method and system

Publications (2)

Publication Number Publication Date
CN112769816A CN112769816A (en) 2021-05-07
CN112769816B true CN112769816B (en) 2022-06-21

Family

ID=75699092

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110004996.3A Active CN112769816B (en) 2021-01-04 2021-01-04 Power supply monitoring high-speed CAN message processing method and system

Country Status (1)

Country Link
CN (1) CN112769816B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6714553B1 (en) * 1998-04-15 2004-03-30 Top Layer Networks, Inc. System and process for flexible queuing of data packets in network switching
CN101924769A (en) * 2010-08-24 2010-12-22 无锡开创信息技术有限公司 Payload characteristic identification based method for identifying Sohu dragon oath game service
CN105812266A (en) * 2014-12-31 2016-07-27 北京东土科技股份有限公司 Hardware configuration processing method and device for request message

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7337241B2 (en) * 2002-09-27 2008-02-26 Alacritech, Inc. Fast-path apparatus for receiving data corresponding to a TCP connection
CN103248726B (en) * 2013-05-23 2015-09-16 中国科学院计算机网络信息中心 A kind of many reciprocity Internet of Things identification analytic method
CN104750758B (en) * 2013-12-31 2018-07-03 深圳航天东方红海特卫星有限公司 A kind of general parsing processing method and system of microsatellite test data bag

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6714553B1 (en) * 1998-04-15 2004-03-30 Top Layer Networks, Inc. System and process for flexible queuing of data packets in network switching
CN101924769A (en) * 2010-08-24 2010-12-22 无锡开创信息技术有限公司 Payload characteristic identification based method for identifying Sohu dragon oath game service
CN105812266A (en) * 2014-12-31 2016-07-27 北京东土科技股份有限公司 Hardware configuration processing method and device for request message

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Key-Value型NoSQL本地存储***研究;马文龙等;《计算机学报》;20170601(第08期);全文 *

Also Published As

Publication number Publication date
CN112769816A (en) 2021-05-07

Similar Documents

Publication Publication Date Title
CN111580995B (en) Synchronous communication method and system of distributed cloud platform and Internet of things intelligent terminal based on MQTT asynchronous communication scene
US20010010052A1 (en) Method for controlling multithreading
WO2021238248A1 (en) Network traffic classification processing method and apparatus, device, and medium
CN108123820B (en) Network equipment information acquisition method and device
CN104158699B (en) A kind of collecting method based on priority and segmentation
CN109547162B (en) Data communication method based on two sets of one-way boundaries
CN114389955A (en) Embedded platform heterogeneous resource pooling management method
CN111865809B (en) Equipment state sensing method, system and switch based on protocol non-sensing forwarding
CN112769816B (en) Power supply monitoring high-speed CAN message processing method and system
CN105049162A (en) Public network information high-efficiency transmission method based on Epoll model
CN112866339B (en) Data transmission method and device, computer equipment and storage medium
WO2019029721A1 (en) Task scheduling method, apparatus and device, and storage medium
CN115827285A (en) Cross-platform communication method, system, device, equipment and medium
JPH09319597A (en) Scheduling method for cyclic process
CN116132369A (en) Flow distribution method of multiple network ports in cloud gateway server and related equipment
CN102999390B (en) Rear-end resource control method under a kind of cloud computing environment and device
JP3387464B2 (en) Communication control system and its control method
CN113485749A (en) Data management and control system and data management and control method
CN109600189B (en) Time slot scheduling method based on time division multiple access TDMA protocol and self-organizing network control system
CN106453656A (en) Cluster host selection method and device
Geng et al. Research on high speed data distribution technology based on kernel state of domestic operating system
CN112433840A (en) Dynamic storage resource partitioning method for high-performance computing
CN111258937A (en) Transmission method and system of ring type linked list DMA
Zhao et al. A multi-access window protocol for transmission of time constrained messages
CN112199205B (en) Program communication method between heterogeneous platforms

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant