Cross-board information acquisition method and device
The signal wait mechanism for cross-board card information collection simplifies and enhances efficiency, reducing complexity and coupling in code modules, addressing the inefficiencies of existing methods.
Patent Information
- Application Number
- CN202210178734.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-02-25
AI Technical Summary
The information collection steps of the existing technology are complicated, and asynchronous communication lead to high coupling of code modules, large development volume, and complex control process.
The message channel using the semaphore wait mechanism is used to achieve synchronous collection of information across board cards by sending messages carrying the target task index, modifying the semaphore, receiving and verifying the timestamp.
The cross-border information collection process is simplified, the code module coupling is reduced, the development workload is reduced, and the code quality and communication efficiency are improved.
Smart Images

Figure CN114721999B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and particularly to a method and device for cross-board information acquisition. Background Art
[0002] In scenarios such as intelligent manufacturing, for an embedded system that requires multiple boards to work collaboratively, cross-board information acquisition is needed. For example, taking the monitoring and management system of an intelligent factory or intelligent manufacturing as an example, a system is constituted as Figure 1 shown. As Figure 1 shown, board A serves as a human-machine interaction board for human-machine interaction; board B serves as a monitoring board for device 1 to monitor the working condition of device 1; board C serves as a monitoring board for device 2 to monitor the working condition of device 2. Boards A, B, and C can all perform message interaction between boards and can achieve the acquisition of local board information. The information acquisition functions can be as shown in Table 1 and Table 2.
[0003] Table 1 Local board information acquisition functions implemented by board B
[0004]
[0005] Table 2 Local board information acquisition functions implemented by board C
[0006]
[0007] Based on board A, the information acquisition process as Figure 2 shown can be set through human-machine interaction. For a single-board environment, Figure 2 the information acquisition process shown is very easy to implement. However, for a multi-board environment, general cross-board information acquisition methods include: the requesting party sends a request message through inter-board communication; the responding party calls the local board information acquisition function to obtain information, and then sends the response message back to the requesting party through inter-board communication. Usually, inter-board communication is asynchronous, that is, two tasks are respectively responsible for sending and receiving messages. The requesting party must go through special processing to know which request message the received response message corresponds to, and also has to handle the timeout problem additionally. As Figure 2 in the case where the input of "status comprehensive processing 1" is the status 1 of device 1 and the status 3 of device 2 obtained at this time, in order to complete information acquisition, the asynchronous inter-board communication is extremely complex, which in turn causes deficiencies such as the complexity of the overall information acquisition process, an increase in the coupling degree between code modules, and a significant increase in code development volume. Summary of the Invention
[0008] The present invention provides a method and device for cross-board information acquisition to solve the defect of complex cross-board information acquisition steps in the prior art and achieve simple and efficient cross-board information synchronous acquisition.
[0009] The present invention provides a cross-board information acquisition method, which is applied to a first board and includes:
[0010] Sending a first message carrying an index of a target task to a second board, and modifying the semaphore of the target task to an occupied state, so that the second board acquires target information based on the index of the target task;
[0011] When receiving a second message carrying the index of the target task sent by the second board within a desired time period, obtaining the acquisition result of the target information carried by the second message, and releasing the semaphore of the target task.
[0012] According to the cross-board information acquisition method provided by the present invention, the obtaining the acquisition result of the target information carried by the second message specifically includes:
[0013] Obtaining a second timestamp carried by the second message;
[0014] When the second timestamp is the same as the first timestamp of the target task, obtaining the acquisition result of the target information carried by the second message.
[0015] According to the cross-board information acquisition method provided by the present invention, after obtaining the second timestamp carried by the second message, it further includes:
[0016] When the second timestamp is different from the first timestamp of the target task, determining the acquisition result of the target information as invalid acquisition.
[0017] According to the cross-board information acquisition method provided by the present invention, after sending a first message carrying an index of a target task to a second board and modifying the semaphore of the target task to an occupied state, it further includes:
[0018] When not receiving the second message sent by the second board within the desired time period, determining the acquisition result of the target information as acquisition timeout, and releasing the semaphore of the target task.
[0019] The present invention also provides a cross-board information acquisition method, which is applied to a second board and includes:
[0020] Receiving a first message carrying an index of a target task sent by a first board; the first message is sent by the first board when the semaphore of the target task is in a released state, and after sending the first message, the first board modifies the semaphore of the target task to an occupied state;
[0021] Based on the index of the target task, obtaining the type of the target information;
[0022] Collect the target information based on the type of the target information;
[0023] Return a second message carrying the index of the target task and the acquisition result of the target information to the first board card, so that when the first board card receives the second message within the expected time period, it releases the semaphore of the target task.
[0024] The present invention also provides a cross-board information acquisition device, including:
[0025] A first sending module, configured to send a first message carrying the index of a target task to a second board card, and modify the semaphore of the target task to an occupied state, so that the second board card collects target information based on the index of the target task;
[0026] A first receiving module, configured to obtain the acquisition result of the target information carried by the second message when receiving a second message carrying the index of the target task sent by the second board card within the expected time period, and release the semaphore of the target task.
[0027] The present invention also provides a cross-board information acquisition device, including:
[0028] A second receiving module, configured to receive a first message carrying the index of a target task sent by a first board card; the first message is sent by the first board card when the semaphore of the target task is in a released state, and after sending the first message, the first board card modifies the semaphore of the target task to an occupied state;
[0029] A type acquisition module, configured to obtain the type of the target information based on the index of the target task;
[0030] An information acquisition module, configured to collect the target information based on the type of the target information;
[0031] A second sending module, configured to return a second message carrying the index of the target task and the acquisition result of the target information to the first board card, so that when the first board card receives the second message within the expected time period, it releases the semaphore of the target task.
[0032] The present invention also provides a cross-board information acquisition system, including: any one of the above-mentioned cross-board information acquisition devices and any one of the above-mentioned cross-board information acquisition devices.
[0033] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where when the processor executes the program, the cross-board information acquisition method described in any one of the above is implemented.
[0034] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the cross-board information acquisition method described in any one of the above is implemented.
[0035] The present invention also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the cross-board information acquisition method described in any one of the above is implemented.
[0036] The cross-board information acquisition method and device provided by the present invention can achieve simple and efficient cross-board information synchronous acquisition by establishing a message channel based on a semaphore waiting mechanism, can solve the problem of complex control processes brought by ordinary inter-board communication, enable the upper-layer process control not to perceive the underlying implementation of cross-board information acquisition, have good scalability, can reduce the coupling degree between code modules, greatly reduce the design complexity of the upper-layer control process, reduce the code development workload, and improve the code quality. Further, in the environment of intelligent manufacturing or the need for multi-board collaborative work, the advantages of the embodiments in this aspect are particularly prominent. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0038] Figure 1 is a schematic structural diagram of a cross-board information acquisition system provided by the prior art;
[0039] Figure 2 is a schematic flowchart of an information acquisition method provided by the prior art;
[0040] Figure 3 is one of the schematic flowcharts of the cross-board information acquisition method provided by the present invention;
[0041] Figure 4 is another schematic flowchart of the cross-board information acquisition method provided by the present invention;
[0042] Figure 5 is still another schematic flowchart of the cross-board information acquisition method provided by the present invention;
[0043] Figure 6 It is the fourth schematic flow chart of the cross-board information acquisition method provided by the present invention;
[0044] Figure 7 It is one of the schematic structural diagrams of the cross-board information acquisition device provided by the present invention;
[0045] Figure 8 It is the second schematic structural diagram of the cross-board information acquisition device provided by the present invention;
[0046] Figure 9 It is the schematic structural diagram of the electronic device provided by the present invention. Detailed implementation manners
[0047] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below with reference to the accompanying drawings in the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without making creative efforts based on the embodiments in the present invention belong to the scope of protection of the present invention.
[0048] In the description of the embodiments of the present invention, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance, and do not involve order.
[0049] In the description of the embodiments of the present invention, it should be noted that unless otherwise clearly defined and limited, the terms "installed", "connected", and "coupled" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the embodiments of the present invention can be understood according to specific situations.
[0050] Next, with reference to Figures 3 to 9 the cross-board information acquisition method and device provided by the present invention will be described.
[0051] Figure 3 It is one of the schematic flow charts of the cross-board information acquisition method provided by the present invention. Next, with reference to Figure 3 the cross-board information acquisition method of the embodiments of the present invention will be described. This method is applied to the first board card. As Figure 3 shown, this method includes: step 301 and step 302.
[0052] Specifically, the execution entity of the cross-board information acquisition method provided by the embodiments of the present invention is a cross-board information acquisition device, which may be a first board. The cross-board information acquisition method provided by the embodiments of the present invention is used for the first board to acquire information through the second board.
[0053] Step 301: Send a first message carrying the index of the target task to the second board, and modify the semaphore of the target task to the occupied state, so that the second board acquires the target information based on the index of the target task.
[0054] The first board may be an embedded board provided with a processor. The second board may be an embedded board provided with a processor. The first board and the second board are communicatively connected.
[0055] The target task is a task with a need for cross-board information acquisition. Exemplarily, the target task may be a task for the first board to acquire the status information of a device electrically connected to the second board through the second board.
[0056] Optionally, a global data structure can be initialized for the target task, denoted as BOARD_INFO_PIPE. The data structure BOARD_INFO_PIPE may include the following fields: the index task_cb_p of the target task, the semaphore pipe_sem of the target task, the first timestamp time_stamp, the identifier dst_boardid of the target board, the type req_type of the target information to be acquired, the success or failure result resp_ret of the acquisition operation, and the acquired information (i.e., the target information) u_pipe.
[0057] The index task_cb_p of the target task is the identifier of the task, which is different from the index of any other task. Based on the index task_cb_p of the target task, the global data structure BOARD_INFO_PIPE of the target task can be accessed.
[0058] A semaphore, also known as a signal lamp, is a facility used in a multi-threaded environment and can be used to ensure that two or more critical code segments are not called concurrently. Before entering a critical code segment, a thread must acquire a semaphore; once the critical code segment is completed, the thread must release the semaphore; other threads that want to enter the critical code segment must wait until the thread releases the semaphore.
[0059] The semaphore pipe_sem of the target task is a semaphore for acquisition waiting.
[0060] The identifier of the target board, dst_boardid, is different from the identifiers of any other boards. In the embodiments of the present invention, the target board is the second board. Correspondingly, the source board is the first board.
[0061] The target information is the information that needs to be collected by the second board. Exemplarily, the type req_type of the target information may include the statuses of various devices that the second board can collect.
[0062] The success or failure result resp_ret of the collection operation refers to whether the second board successfully collects the target information. Exemplarily, resp_ret being 1 indicates that the collection operation is successful and the second board successfully collects the target information; resp_ret being 0 indicates that the collection operation fails and the second board does not collect the target information.
[0063] Initializing the global data structure BOARD_INFO_PIPE may include: obtaining the current time and assigning it to the first timestamp time_stamp field therein; assigning the index of the target task to the task_cb_p field; assigning the type of the target information to the req_type field; assigning the identifier of the second board to the dst_boardid field; and assigning the corresponding value of the occupancy status to the pipe_sem field.
[0064] The first message can be referred to as the "off-board request event for the cross-board collection channel" message. Based on the identifier dst_boardid of the target board, the first board sends the first message to the second board and changes the semaphore of the target task from the released state to the occupied state. The first message may carry the index task_cb_p of the target task. The first message may also carry all the parameters required for the information of the type req_type of collecting the target information.
[0065] After receiving the first message, the second board can find the global data structure BOARD_INFO_PIPE of the target task according to the index task_cb_p of the target task, obtain the type req_type of the target information and all the parameters required for collecting the information of this type therefrom; can call the information collection function corresponding to the type req_type of the target information (such as a certain status acquisition function, etc.) to perform information collection, form a data stream according to the message format with the collection result, and return a second message to the first board.
[0066] The second message can be referred to as the "off-board response event for the cross-board collection channel" message.
[0067] In addition to the collection result of the target task, the second message may also carry the index of the target task.
[0068] Step 302: When a second message carrying the index of the target task is received within the expected time period, obtain the acquisition result of the target information carried in the second message, and release the semaphore of the target task.
[0069] Specifically, after sending the first message, the first board can start a timer inner_timer_id with a preset duration. The expected time period can be a time period starting from the sending time of the first message and with a duration of the above preset duration.
[0070] The preset duration can be set according to the actual situation. The specific value of the preset duration is not specifically limited in the embodiments of the present invention. Exemplarily, the preset duration can be 2 seconds.
[0071] If the first board receives the second message before the timer inner_timer_id ends, it can determine whether the second message is a response of the second board to the first message based on the index of the target task carried in the second message; after determining that the second message is a response of the second board to the first message, it can obtain the acquisition result of the target information carried in the second message, complete cross-board information acquisition, stop the timer inner_timer_id, and change the semaphore pipe_sem of the target task from the occupied state to the released state, so as to execute the next cross-board information acquisition task.
[0072] The acquisition result of the target information carried in the second message can include the success or failure result resp_ret of the acquisition operation and the acquired information u_pipe.
[0073] It can be understood that in the case of a successful acquisition operation, the acquired information u_pipe carried in the second message is the target information; in the case of a failed acquisition operation, the acquired information u_pipe carried in the second message can be empty.
[0074] It should be noted that a dedicated message channel can be established for the transmission of messages such as the first message and the second message used to implement the target task. Optionally, when there are different priorities in the message channel, the dedicated message channel can be set to the highest priority. By encapsulating it into a dedicated information acquisition channel, the upper-layer process control does not need to perceive the underlying implementation.
[0075] It can be understood that in the embodiments of the present invention, information synchronous acquisition can be achieved without blocking the message sending and receiving tasks, which can improve the communication efficiency.
[0076] In the embodiment of the present invention, by establishing a message channel based on a semaphore waiting mechanism, simple and efficient cross-board information synchronous acquisition can be achieved, the problem of complex control processes brought about by using ordinary inter-board communication can be solved, so that the upper-layer process control does not need to perceive the underlying implementation of cross-board information acquisition, enabling it to have good scalability, reducing the coupling degree between code modules, greatly reducing the design complexity of the upper-layer control process, reducing the code development workload, and improving the code quality. Further, in the environment of intelligent manufacturing or where multi-board collaborative work is required, the advantages of the embodiments in this aspect are particularly prominent.
[0077] Based on the content of any of the above embodiments, obtaining the acquisition result of the target information carried by the second message specifically includes: obtaining the second timestamp carried by the second message.
[0078] Specifically, the second message may further carry a second timestamp.
[0079] Correspondingly, after the first board receives the second message, it may also obtain the second timestamp.
[0080] When the second timestamp is the same as the first timestamp of the target task, obtain the acquisition result of the target information carried by the second message.
[0081] Specifically, after the first board obtains the second timestamp, it can compare whether the first timestamp and the second timestamp are the same, and further perform verification based on the timestamps.
[0082] Under normal circumstances, the second board can obtain the first timestamp from the data structure BOARD_INFO_PIPE that receives the first message and use it as the second timestamp carried by the second message; if an exception occurs, such as the second message being illegally tampered with during transmission or an error occurring in the processing of the second board, etc., the second timestamp carried by the second message received by the first board is inconsistent with the first timestamp of the target task.
[0083] When the second timestamp is the same as the first timestamp of the target task, it indicates that the second message is a valid response to the first message, that is, the second message is valid, and thus the acquisition result of the target information carried by the second message can be obtained.
[0084] The embodiment of the present invention can improve the reliability of communication and the security of cross-board information acquisition through a timestamp verification mechanism, ensure the effectiveness of cross-board information acquisition, avoid invalid acquisitions, and improve efficiency.
[0085] Based on the content of any of the above embodiments, after obtaining the second timestamp carried by the second message, it further includes: when the second timestamp is different from the first timestamp of the target task, determining the acquisition result of the target information as invalid acquisition.
[0086] Specifically, when the second timestamp is different from the first timestamp of the target task, it indicates that the second message is not a valid response to the first message, that is, the second message is invalid and can be not processed. The acquisition result of the target information is determined to be acquisition invalid.
[0087] Through the timestamp verification mechanism, the embodiments of the present invention can improve the reliability of communication and the security of cross-board information acquisition, ensure the effectiveness of cross-board information acquisition, avoid invalid acquisition, and improve efficiency.
[0088] Based on the content of any of the above embodiments, after sending the first message carrying the index of the target task to the second board and modifying the semaphore of the target task to the occupied state, it further includes: when the second message sent by the second board is not received within the expected time period, determining the acquisition result of the target information as acquisition timeout and releasing the semaphore of the target task.
[0089] Specifically, if the timer inner_timer_id expires and the first board still does not receive the second message, it indicates that a timer timeout event occurs. The acquisition result of the target information can be directly determined as acquisition timeout, that is, the value of resp_ret, the success or failure result of the acquisition operation in the global data structure BOARD_INFO_PIPE of the target task, can be modified to a value indicating that the acquisition operation fails, and the semaphore pipe_sem of the target task is modified from the occupied state to the released state, so as to execute the next cross-board information acquisition task.
[0090] Through the timeout mechanism, the embodiments of the present invention can avoid long-term task waiting, so as to release the semaphore more timely for the next information acquisition task, and improve the efficiency of cross-board information acquisition.
[0091] Figure 4 is the second flowchart of the cross-board information acquisition method provided by the present invention. The following combines Figure 4 Describe the cross-board information acquisition method of the embodiments of the present invention. Based on the content of any of the above embodiments, this method is applied to the second board, as Figure 4 shown, this method includes: step 401, step 402, step 403 and step 404.
[0092] Specifically, the execution subject of the cross-board information acquisition method provided by the embodiments of the present invention is a cross-board information acquisition device, and this device can be the second board. The cross-board information acquisition method provided by the embodiments of the present invention is used for the first board to acquire information through the second board.
[0093] Step 401: Receive a first message sent by a first board card, which carries the index of a target task. The first message is sent by the first board card when the semaphore of the target task is in a released state. After sending the first message, the first board card changes the semaphore of the target task to an occupied state.
[0094] Specifically, after initializing the global data structure BOARD_INFO_PIPE of the target task, the first board card sends the first message to the second board card and changes the semaphore of the target task from the released state to the occupied state. The first message may carry the index task_cb_p of the target task. The first message may also carry all the parameters required for collecting information of the type req_type of the target information.
[0095] The second board card can receive the first message.
[0096] Step 402: Based on the index of the target task, obtain the type of the target information.
[0097] Specifically, after receiving the first message, the second board card can find the global data structure BOARD_INFO_PIPE of the target task according to the index task_cb_p of the target task, and obtain the type req_type of the target information and all the parameters required for collecting information of this type from it.
[0098] Step 403: Collect the target information based on the type of the target information.
[0099] Specifically, after obtaining the type req_type of the target information, the second board card can call the function corresponding to the type req_type of the target information to collect information in order to collect the target information.
[0100] Step 404: Return a second message to the first board card, which carries the index of the target task and the collection result of the target information, so that when the first board card receives the second message within the expected time period, it releases the semaphore of the target task.
[0101] Specifically, the second board card can form a data stream of the collection result in the message format and return the second message to the first board card.
[0102] In addition to the collection result of the target task, the second message may also carry the index of the target task.
[0103] After sending the first message, the first board card can start a timer inner_timer_id with a preset duration. The expected time period can be a time period starting from the sending moment of the first message and with a duration of the above preset duration.
[0104] When the first board card receives the second message within the expected time period, it can obtain the acquisition result of the target information carried in the second message, complete the cross-board card information acquisition, and release the semaphore of the target task, so as to execute the next cross-board card information acquisition task.
[0105] By establishing a message channel based on the semaphore waiting mechanism, the embodiments of the present invention can achieve simple and efficient cross-board card information synchronous acquisition, solve the problem of complex control processes brought by ordinary inter-board card communication, enable the upper-layer process control not to perceive the underlying implementation of cross-board information acquisition, have good scalability, reduce the coupling degree between code modules, greatly reduce the design complexity of the upper-layer control process, reduce the code development workload, and improve the code quality. Further, in the environment of intelligent manufacturing or where multi-board card collaborative work is required, the advantages of the embodiments in this aspect are particularly prominent.
[0106] To facilitate the understanding of the above embodiments of the present invention, the following describes the complete process of cross-board card information acquisition through an example.
[0107] The target task task_A is a cross-board card information acquisition task for board card A to collect the status 1 of device 1 monitored by board card B. The index task_cb_p of the target task is denoted as task_cb_p_A. Through task_cb_p_A, all global variables of the target task task_A can be obtained, including the global data structure BOARD_INFO_PIPE allocated during the initialization of the target task task_A.
[0108] As Figure 5 and Figure 6 shown, the execution process of this target task may include the following steps:
[0109] a) The task task_A of board card A calls the information acquisition interface module, and inputs the ID of board card B, the type of information to be collected, and all parameters required for collecting this type of information.
[0110] b) The information acquisition interface module obtains the index of the target task, i.e., task_cb_p_A, and then locates the initialized global data structure BOARD_INFO_PIPE. It assigns task_cb_p_A to task_cb_p in the data structure, fills in the ID of board B, the type of the acquired information (i.e., the target information), and all the parameters required for acquiring this information type into the corresponding fields, clears the result areas resp_ret and u_pipe, obtains the current time and assigns it to the timestamp time_stamp. Then it converts BOARD_INFO_PIPE into a data stream, sends a "local board request event for cross-board acquisition channel" message to the TASK_BOARD_PIPE task of this board, and finally waits for the release of the semaphore pipe_sem.
[0111] c) After receiving the "local board request event for cross-board acquisition channel" message, the information acquisition task TASK_BOARD_PIPE of board A obtains the data structure BOARD_INFO_PIPE by parsing the message data stream. It accesses the global data structure of the target task through task_cb_p_A recorded in task_cb_p of this data structure, then starts the 2-second timeout timer inner_timer_id created during task initialization, and then sends a "remote board request event for cross-board acquisition channel" message to the information acquisition task TASK_BOARD_PIPE of board B.
[0112] d) When the information acquisition task TASK_BOARD_PIPE of board B receives the "remote board request event for cross-board acquisition channel" message, it indicates that a cross-board request has been received. It parses the data structure BOARD_INFO_PIPE carried in the message data stream, knows the information type to be acquired according to the type req_type of the target information, and then calls the corresponding status acquisition function to acquire the required information "status 1 of device 1". After that, it forms the information into a data stream according to the message format and sends a "remote board response event for cross-board acquisition channel" message to the information acquisition task TASK_BOARD_PIPE of board A.
[0113] e) The information acquisition task TASK_BOARD_PIPE of board A receives the "remote board response event for cross-board acquisition channel" message, parses the data stream, obtains the data structure BOARD_INFO_PIPE, thereby getting the task index task_cb_p_A of the target task and the timestamp time_stamp. Through the task index task_cb_p_A of the target task, it can find the global variables of this task and obtain the timestamp when this action was initiated at that time; if the two timestamps are the same, it determines that this response message is valid, otherwise it directly exits if it is invalid. Figure 5As shown, when it is valid, the acquisition results resp_ret and u_pipe in the data structure BOARD_INFO_PIPE are stored in the global data structure of the target task task_A, then the 2S timeout timer inner_timer_id of the task task_A that initiated the request is stopped, and finally the acquisition waiting semaphore pipe_sem is released; when it is invalid, the processing flow is directly exited and new messages are continued to be waited for.
[0114] f) When the information acquisition task TASK_BOARD_PIPE of board A receives the "2S timer timeout event" message, it means that board B has not sent back the information to be acquired within the specified time. So, "acquisition timeout" is stored in resp_ret of the global variable of the target task, and then the acquisition waiting semaphore pipe_sem is released. The process is as Figure 6 shown.
[0115] g) After the information acquisition interface module of board A waits until the semaphore pipe_sem is released, it clears the timestamp in the global data structure of task task_A and the index task_cb_p of the target task, and returns the acquisition result.
[0116] The cross-board information acquisition device provided by the present invention is described below. The cross-board information acquisition device described below can be correspondingly referred to the cross-board information acquisition method described above.
[0117] Figure 7 One of the structural schematic diagrams of the cross-board information acquisition device provided by the present invention. Based on the content of any of the above embodiments, as Figure 7 shown, the device includes a first sending module 701 and a first receiving module 702, where:
[0118] The first sending module 701 is configured to send a first message carrying the index of the target task to the second board, and modify the semaphore of the target task to an occupied state, so that the second board acquires the target information based on the index of the target task;
[0119] The first receiving module 702 is configured to obtain the acquisition result of the target information carried by the second message and release the semaphore of the target task when the second message carrying the index of the target task sent by the second board is received within the expected time period.
[0120] Specifically, the cross-board information acquisition device provided by the embodiments of the present invention can be the first board.
[0121] The first sending module 701 and the first receiving module 702 are electrically connected.
[0122] The first sending module 701 can send a first message to the second board card based on the identifier dst_boardid of the target board card, and modify the semaphore of the target task from the released state to the occupied state. The first message can carry the index task_cb_p of the target task. The first message can also carry all the parameters required for the information of the type req_type for collecting the target information.
[0123] After receiving the first message, the second board card can, according to the index task_cb_p of the target task, find the global data structure BOARD_INFO_PIPE of the target task, obtain the type req_type of the target information and all the parameters required for collecting the information of this type therefrom; it can call the function corresponding to the type req_type of the target information to collect the information, form a data stream according to the message format for the collection result, and return a second message to the first board card.
[0124] Before the timer inner_timer_id ends, if the first receiving module 702 receives the second message, it can determine whether the second message is a response of the second board card to the first message based on the index of the target task carried by the second message; after determining that the second message is a response of the second board card to the first message, it can obtain the collection result of the target information carried by the second message, complete the cross-board information collection, stop the timer inner_timer_id and modify the semaphore pipe_sem of the target task from the occupied state to the released state, so as to execute the next cross-board information collection task.
[0125] Optionally, the first receiving module 702 may include:
[0126] A time acquisition unit for acquiring the second timestamp carried by the second message;
[0127] A result acquisition unit for acquiring the collection result of the target information carried by the second message when the second timestamp is the same as the first timestamp of the target task.
[0128] Optionally, the result acquisition unit may also be used to determine that the collection result of the target information is invalid when the second timestamp is different from the first timestamp of the target task.
[0129] Optionally, the cross-board information collection device may further include:
[0130] An information acquisition module for determining that the collection result of the target information is a collection timeout and releasing the semaphore of the target task when the second message sent by the second board card is not received within the expected time period.
[0131] The cross-board information acquisition device provided by an embodiment of the present invention is used to execute the above-mentioned cross-board information acquisition method of the present invention. Its implementation manner is consistent with that of the cross-board information acquisition method provided by the present invention and can achieve the same beneficial effects, which will not be elaborated here.
[0132] This cross-board information acquisition device is used for the cross-board information acquisition methods in the foregoing embodiments. Therefore, the descriptions and definitions in the cross-board information acquisition methods in the foregoing embodiments can be used to understand each execution module in the embodiments of the present invention.
[0133] By establishing a message channel based on a semaphore waiting mechanism, the embodiment of the present invention can realize simple and efficient cross-board information synchronous acquisition, solve the problem of complex control flow brought by ordinary inter-board communication, enable the upper-layer process control not to perceive the underlying implementation of cross-board information acquisition, have good scalability, reduce the coupling degree between code modules, greatly reduce the design complexity of the upper-layer control process, reduce the code development workload, and improve the code quality. Further, in the environment of intelligent manufacturing or where multi-board cooperation is required, the advantages of the embodiments in this aspect are particularly prominent.
[0134] Figure 8 The second structural schematic diagram of the cross-board information acquisition device provided by the present invention. Based on the content of any of the foregoing embodiments, as Figure 8 shown, the device includes a second receiving module 801, a type obtaining module 802, an information acquisition module 803, and a second sending module 804, where:
[0135] The second receiving module 801 is configured to receive a first message carrying the index of a target task sent by a first board; the first message is sent by the first board when the semaphore of the target task is in a released state, and after sending the first message, the first board modifies the semaphore of the target task to an occupied state;
[0136] The type obtaining module 802 is configured to obtain the type of target information based on the index of the target task;
[0137] The information acquisition module 803 is configured to acquire target information based on the type of target information;
[0138] The second sending module 804 is configured to return a second message carrying the index of the target task and the acquisition result of the target information to the first board, so that the first board releases the semaphore of the target task when receiving the second message within the expected time period.
[0139] Specifically, the cross-board information acquisition device provided by the embodiment of the present invention is the second board.
[0140] The second receiving module 801, the type obtaining module 802, the information collecting module 803, and the second sending module 804 are electrically connected in sequence.
[0141] The second receiving module 801 can receive a first message.
[0142] The type obtaining module 802 can, according to the index task_cb_p of the target task, find the global data structure BOARD_INFO_PIPE of the target task, and obtain the type req_type of the target information and all parameters required for collecting information of this type therefrom.
[0143] The information collecting module 803 can call the function corresponding to the type req_type of the target information to collect information so as to collect the target information.
[0144] The second sending module 804 can form a data stream according to the message format with the collection result and return a second message to the first board.
[0145] The cross-board information collection device provided by an embodiment of the present invention is used to execute the above cross-board information collection method of the present invention. Its implementation manner is consistent with the implementation manner of the cross-board information collection method provided by the present invention, and the same beneficial effects can be achieved, which will not be elaborated here.
[0146] This cross-board information collection device is used for the cross-board information collection method in the foregoing embodiments. Therefore, the descriptions and definitions in the cross-board information collection method in the foregoing embodiments can be used for the understanding of each execution module in the embodiments of the present invention.
[0147] By establishing a message channel based on a semaphore waiting mechanism, the embodiment of the present invention can realize simple and efficient cross-board information synchronous collection, can solve the problem of complex control processes brought by using ordinary inter-board communication, enable the upper-layer process control not to perceive the underlying implementation of cross-board information collection, make it have good scalability, can reduce the coupling degree between code modules, greatly reduce the design complexity of the upper-layer control process, reduce the code development workload, and improve the code quality. Further, in an environment of intelligent manufacturing or where multi-board cooperation is required, the advantages of the embodiments in this aspect are particularly prominent.
[0148] Based on the content of any of the foregoing embodiments, the cross-board information collection system includes: a first board and a second board.
[0149] Figure 9 An example of a schematic physical structure diagram of an electronic device is shown as Figure 9As shown, the electronic device may include: a processor 910, a communications interface 920, a memory 930, and a communication bus 940. Among them, the processor 910, the communications interface 920, and the memory 930 communicate with each other through the communication bus 940. The processor 910 may call the logical instructions in the memory 930 to execute the cross-board information acquisition method, which includes: sending a first message carrying the index of the target task to the second board and modifying the semaphore of the target task to the occupied state, so that the second board acquires the target information based on the index of the target task; in the case of receiving a second message carrying the index of the target task sent by the second board within the expected time period, obtaining the acquisition result of the target information carried by the second message and releasing the semaphore of the target task; or, the method includes: receiving a first message carrying the index of the target task sent by the first board; the first message is sent by the first board when the semaphore of the target task is in the released state, and after sending the first message, the first board modifies the semaphore of the target task to the occupied state; based on the index of the target task, obtaining the type of the target information; based on the type of the target information, acquiring the target information; returning a second message carrying the index of the target task and the acquisition result of the target information to the first board, so that the first board releases the semaphore of the target task in the case of receiving the second message within the expected time period.
[0150] In addition, when the logical instructions in the above-mentioned memory 930 are implemented in the form of software functional units and sold or used as an independent product, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.
[0151] The processor 910 in the electronic device provided in the embodiments of the present invention may call the logical instructions in the memory 930. Its implementation manner is consistent with the implementation manner of the cross-board information acquisition method provided by the present invention and can achieve the same beneficial effects, which will not be elaborated here.
[0152] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the cross-board information acquisition method provided by each of the above methods. The method includes: sending a first message carrying an index of a target task to a second board, and modifying the semaphore of the target task to an occupied state, so that the second board acquires target information based on the index of the target task; when receiving a second message carrying the index of the target task sent by the second board within a desired time period, obtaining the acquisition result of the target information carried in the second message, and releasing the semaphore of the target task; or, the method includes: receiving a first message carrying an index of a target task sent by a first board; the first message is sent by the first board when the semaphore of the target task is in a released state, and after sending the first message, the first board modifies the semaphore of the target task to an occupied state; obtaining the type of the target information based on the index of the target task; acquiring the target information based on the type of the target information; returning a second message carrying the index of the target task and the acquisition result of the target information to the first board, so that the first board releases the semaphore of the target task when receiving the second message within a desired time period.
[0153] When the computer program product provided by the embodiment of the present invention is executed, the above cross-board information acquisition method is implemented. Its specific implementation manner is consistent with the implementation manner described in the embodiment of the foregoing method, and the same beneficial effects can be achieved, which will not be elaborated here.
[0154] In another aspect, the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is configured to execute the cross-board information acquisition method provided above. The method includes: sending a first message carrying an index of a target task to a second board, and modifying the semaphore of the target task to an occupied state, so that the second board acquires target information based on the index of the target task; in the case of receiving a second message carrying the index of the target task sent by the second board within a desired time period, obtaining the acquisition result of the target information carried by the second message, and releasing the semaphore of the target task; or, the method includes: receiving a first message carrying an index of a target task sent by a first board; the first message is sent by the first board when the semaphore of the target task is in a released state, and after sending the first message, the first board modifies the semaphore of the target task to an occupied state; obtaining the type of the target information based on the index of the target task; acquiring the target information based on the type of the target information; returning a second message carrying the index of the target task and the acquisition result of the target information to the first board, so that the first board releases the semaphore of the target task in the case of receiving the second message within a desired time period.
[0155] When the computer program stored on the non-transitory computer-readable storage medium provided by the embodiment of the present invention is executed, it implements the above cross-board information acquisition method. The specific implementation manner is consistent with the implementation manner described in the embodiment of the foregoing method, and the same beneficial effects can be achieved, which will not be elaborated here.
[0156] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative labor.
[0157] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, also by hardware. Based on such an understanding, the above technical solution, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0158] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A cross-board information acquisition method, applied to a first board, characterized in that, Including: Sending a first message carrying the index of the target task to the second board card, and modifying the semaphore of the target task to the occupied state, so that the second board card acquires target information based on the index of the target task; The target task is a task for cross-board card information acquisition requirements; When receiving a second message carrying the index of the target task sent by the second board card within the expected time period, obtaining the acquisition result of the target information carried by the second message, and releasing the semaphore of the target task.
2. The cross-board information acquisition method according to claim 1, wherein The obtaining the acquisition result of the target information carried by the second message specifically includes: Obtaining the second timestamp carried by the second message; When the second timestamp is the same as the first timestamp of the target task, obtaining the acquisition result of the target information carried by the second message.
3. The cross-board information acquisition method according to claim 2, wherein After obtaining the second timestamp carried by the second message, it further includes: When the second timestamp is different from the first timestamp of the target task, determining the acquisition result of the target information as invalid acquisition.
4. The cross-board information acquisition method according to claim 1, wherein After sending a first message carrying the index of the target task to the second board card and modifying the semaphore of the target task to the occupied state, it further includes: When not receiving the second message sent by the second board card within the expected time period, determining the acquisition result of the target information as acquisition timeout, and releasing the semaphore of the target task.
5. A cross-board information acquisition method, applied to a second board, characterized in that, Including: Receiving a first message carrying the index of the target task sent by the first board card; The first message is sent by the first board card when the semaphore of the target task is in the released state, and after sending the first message, the first board card modifies the semaphore of the target task to the occupied state; the target task is a task for cross-board card information acquisition requirements; Based on the index of the target task, obtaining the type of the target information; Based on the type of the target information, acquiring the target information; Returning a second message carrying the index of the target task and the acquisition result of the target information to the first board card, so that the first board card releases the semaphore of the target task when receiving the second message within the expected time period.
6. A cross-board information acquisition device, characterized in that Including: A first sending module, configured to send a first message carrying the index of the target task to the second board card, and modify the semaphore of the target task to the occupied state, so that the second board card acquires target information based on the index of the target task; The target task is a task for cross-board card information acquisition requirements; A first receiving module, configured to obtain the acquisition result of the target information carried by the second message and release the semaphore of the target task when receiving a second message carrying the index of the target task sent by the second board card within the expected time period.
7. A cross-board information acquisition device, characterized in that, Including: A second receiving module, configured to receive a first message carrying the index of the target task sent by the first board card; The first message is sent when the semaphore of the target task is in a released state by the first board, and after sending the first message, the first board modifies the semaphore of the target task to an occupied state; the target task is a task with a cross-board information acquisition requirement. A type acquisition module, configured to acquire the type of target information based on the index of the target task. An information acquisition module, configured to acquire the target information based on the type of the target information. A second sending module, configured to return a second message carrying the index of the target task and the acquisition result of the target information to the first board, so that when the first board receives the second message within a desired time period, it releases the semaphore of the target task.
8. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the cross-board information acquisition method according to any one of claims 1 to 5.
9. A non-transitory 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 cross-board information acquisition method according to any one of claims 1 to 5.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the cross-board information acquisition method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Multitask communication system and method of optical access multiuser residential unit embedded device
CN101702784A
First integrated circuit board, second integrated circuit board and equipment
CN107025203A