CN117097814B - Asynchronous communication method between simulation model and terminal - Google Patents
Asynchronous communication method between simulation model and terminal Download PDFInfo
- Publication number
- CN117097814B CN117097814B CN202311219860.XA CN202311219860A CN117097814B CN 117097814 B CN117097814 B CN 117097814B CN 202311219860 A CN202311219860 A CN 202311219860A CN 117097814 B CN117097814 B CN 117097814B
- Authority
- CN
- China
- Prior art keywords
- block
- data
- terminal
- simulation model
- receiving
- 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
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/544—Buffers; Shared memory; Pipes
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Communication Control (AREA)
Abstract
The invention relates to an asynchronous communication method between a simulation model and a terminal, which comprises the following steps: configuring at least one control module for each terminal in the simulation model, wherein the control module is used for configuring communication parameters and controlling communication application programs; configuring a receiving module or/and a sending module for each terminal, and binding the receiving module or/and the sending module with a control module of each terminal; each control module creates independent control blocks in the shared memory, and distributes independent transmission blocks or/and receiving blocks for the corresponding bound transmission modules or/and receiving modules in the control blocks; when the simulation model is started, the control module starts a communication application program, a corresponding sending module or/and receiving module is called according to communication parameters, and the sending module writes data of the simulation model into a corresponding sending block and sends the data to the terminal; the receiving module reads the data written in the corresponding receiving block by the terminal and updates the data to the simulation model; and stopping the communication application program and cleaning the shared memory when the simulation model is stopped.
Description
Technical Field
The invention relates to the field of simulation control, in particular to an asynchronous communication method between a simulation model and a terminal.
Background
In the field of semi-physical simulation control, a simulation model often has an application scene for communication with a third party terminal, and relates to a communication technology between the simulation model and the third party terminal. In the prior art, the communication modes of the simulation model and the third party terminal are as follows: both synchronous and asynchronous modes.
For synchronous communication mode, the requirement on performance is extremely high, after the model simulation step length is set, all data interaction must be completed between one step length, otherwise, normal simulation of the model is affected. Thus: unless the model is small, the data volume required to be communicated is small, or when the experimental scene requires synchronization, an asynchronous communication mode is generally adopted.
In the asynchronous communication mode, shared memory, socket communication and the like are commonly used. When the shared memory is adopted, the simulation model and the third party terminal are required to be located in the same server, and the use scene is single. The Socket communication needs to simulate the connection between the model and each third party terminal, define the message packet of the communication, maintain the stable and normal communication, etc., if the simulation model is completed by the model, the model is too heavy. For example, tcp protocol communication is to deal with the problem of sticking packets, while udp protocol is prone to the problem of packet loss in simulation with high real-time requirements. Secondly, during data interaction, operations such as resource protection are involved, and improper processing often causes large coupling of data processing logic of different terminals, so that problems such as data disorder or data receiving and transmitting blockage are caused; or the running state of one communication task can influence the running state of another communication task, for example, when one party operates a resource, the other party waits for a long time because the operation authority of the resource is not obtained; or the resource is destroyed due to the access of multiple parties to the same resource; or severe conditions such as deadlock and the like caused by improper protection of resources occur, and adverse effects are caused to simulation results and stable execution of the model.
Specifically, as shown in fig. 1, a schematic structure diagram of conventional socket communication is shown, and a data storage unit and a data transceiver controller are respectively responsible for storing data and managing socket connection with terminals. As shown in fig. 2, which is a schematic structural diagram of conventional shared memory communication, a data read-write controller is arranged in the model and is responsible for reading and writing data from the shared memory; and each terminal interacts data with the model through the shared memory.
In the two modes, only Socket communication is adopted, the model function is heavy, the connection with multiple terminals needs to be managed, data disorder or data receiving and transmitting blocking are easy to cause, and the real-time performance of the model simulation result is affected; and secondly, the flexibility is poor, and the communication mode is dead, so that the expansion of multiple application scenes is not facilitated. Only sharing memory communication requires that the terminal and the model are located in the same server, and the scene is simplified; and the unified memory management of the data is realized, so that various locks are necessarily added for guaranteeing the synchronization of the data, the performance is reduced, and the real-time simulation performance is affected.
Therefore, how to integrate the two, and improve the communication connection between the simulation model and the terminal in the prior art is a technical problem to be solved in the art.
Disclosure of Invention
In order to solve at least one of the above technical problems, the present invention provides an asynchronous communication method between a simulation model and a terminal, including:
according to the number of terminals and the communication protocol, configuring at least one control module for each terminal in the simulation model, and setting a unique identifier for configuring communication parameters and controlling a communication application program;
according to the communication requirement, configuring a receiving module or/and a sending module for each terminal in the simulation model, setting a unique identifier, storing communication parameters to a corresponding control module, and binding the communication parameters with the control module configured for each terminal;
each control module creates independent control blocks in the shared memory, and distributes independent transmission blocks or/and receiving blocks for the corresponding bound transmission modules or/and receiving modules in the control blocks;
when the simulation model is started, the control module starts a communication application program, and calls a corresponding sending module or/and receiving module according to communication parameters; in each step of simulation, the sending module writes the data of the simulation model into the corresponding sending block, and the communication application program reads the data from the sending block and sends the data to the corresponding terminal; the communication application program receives the terminal data and writes the terminal data into the corresponding receiving block, and then the corresponding receiving module reads the data from the receiving block and updates the data to the simulation model;
and stopping the communication application program and cleaning the shared memory when the simulation model is stopped.
Further, the communication application program includes:
when the communication application program is initialized, mapping a corresponding control block according to the starting parameters;
reading communication parameters in a control block, comprising: control block, receiving block, unique identification of sending block and mapping address corresponding to the same; reading frequency, writing frequency;
according to the communication parameters, the simulation model corresponds to the unique identifiers of the control block and the sending block, and the communication application program reads out the data of the simulation model from the mapping address of the corresponding sending block according to the reading frequency and sends the data to the corresponding terminal; or/and according to the unique identification of the corresponding control block and the receiving block of the terminal, the communication application program writes the data of the terminal into the mapping address of the corresponding receiving block according to the writing frequency, and updates the data to the simulation model.
Further, the specific steps of the communication application program include:
mapping a corresponding control block according to the unique identification of the control block, and acquiring communication parameters from the control block;
a connection terminal;
data interaction is carried out with the terminal;
updating the sending block or/and the receiving block data;
and (5) disconnecting all the mappings and ending.
Further, the specific steps of the control module include:
creating an independent control block in the shared memory;
in the control block, an independent sending block or/and a receiving block is allocated for the bound sending module or/and receiving module;
writing communication parameters into a control block;
starting and monitoring a communication application program when the simulation model starts;
and when the simulation model is finished, the communication application program is killed, and the shared memory is cleaned.
Further, the specific steps of the sending module include:
reading the mapping address of the sending block from the control block according to the unique identification mapping of the control block;
mapping the corresponding data block according to the mapping address of the sending block;
and according to the simulation step length, model data are continuously written into the corresponding sending block until the simulation model is ended, and mapping is disconnected.
Further, the specific steps of the receiving module include:
reading the mapping address of the receiving block from the control block according to the unique identification of the control block;
mapping the corresponding data block according to the mapping address of the receiving block;
and continuously reading data from the receiving block according to the simulation step length, updating the data to the simulation model, and disconnecting the mapping until the simulation model is finished.
Further, a control block storing communication parameters, transmission block information, and reception block information;
before mapping, a sending module firstly goes to a control block to inquire the starting address of the current sending block, and then maps the sending block with the length according to the total length of the mapped sending block as a mapping offset; after mapping, adding the mapping address and the length information of the transmission block into the information of the transmission block in the control block, and updating the total length of the mapped transmission block in the control block;
before the receiving module maps, firstly, the control block inquires the initial address of the current receiving block, and then, the receiving block with the length of itself is mapped according to the total length of the mapped receiving block as the mapping offset; after mapping, the mapping address and the receiving block length information are added to the receiving block information in the control block, and the total length of the mapped receiving block in the control block is updated.
Further, the sending block and the receiving block comprise a reading mark, a reading repetition number, a writing mark, a writing repetition number and a data section;
wherein the data segment is a queue structure; reading a position of the mark record which is read by the current reader; the read repetition times record the times that the reader has circularly read the data queue; writing a mark record of the written position of the current writing party; the number of write repetitions records the number of times the writer has cyclically written the data queue.
Further, the logic of the read data is:
firstly judging whether the read repetition number is equal to the write repetition number;
if the number of read repetitions < the number of write repetitions:
read data segment= (total length of data queue-read tag) + (write tag-0);
after the reading is finished, the reading repetition number is +1, and the reading mark is equal to the writing mark;
if read repetition number = write repetition number:
read data segment = write-read;
and updating the reading mark into a mark writing position after the reading is finished.
Further, the logic for writing data is:
firstly judging whether the writing mark position is the tail of the queue;
if yes, writing repetition times +1, writing data to the queue head, and updating a writing index value to be 0;
if not, the data is written to the write tag location and then the tag +1 is written.
The invention provides an asynchronous communication method between a simulation model and a terminal, which is characterized in that only the configuration in the simulation model is needed in the whole communication: the control module, the sending module, the receiving module and the communication application program module, namely the manual packaging module, have small workload; on the other hand, for each terminal, an independent control module, a sending module and a receiving module are configured according to the communication condition, a dynamic blocking mode is designed for storing data, and an independent storage block is allocated for the control module, the sending module and the receiving module by adopting a dynamic memory block allocation mode, so that when the simulation model needs to send communication data to the terminal or the terminal needs to send the communication data to the simulation model, the independent control module, the sending module and the receiving module can be called to store the communication data to the corresponding storage block (the sending block or the receiving block), and when the simulation model stops, the shared memory is cleared for being allocated again for use in the next simulation or other simulation model simulation. The asynchronous communication method can be used for realizing asynchronous communication by combining various communication modes (such as socket, serial port and the like) optionally but not exclusively. Based on the scheme, simulation technicians can complete asynchronous communication between the model and the terminal only by adding the control module, the sending module, the receiving module and the communication application program into the model, the terminal and the model are not required to be in a unified server, the terminal is not required to adopt a unified communication mode, the user can conveniently define and expand the communication mode, the interaction instantaneity is high, and the data accuracy is high.
Drawings
FIG. 1 is a schematic diagram of one embodiment of a conventional socket communication;
FIG. 2 is a schematic diagram of one embodiment of conventional shared memory communication;
FIG. 3 is a flow chart of one embodiment of a method of asynchronous communication between a simulation model and a terminal in accordance with the present invention;
FIG. 4 is a schematic diagram illustrating an embodiment of an apparatus for implementing an asynchronous communication method between a simulation model and a terminal according to the present invention;
FIG. 5 is a schematic diagram of one embodiment of a control block created by the control module of the present invention;
FIG. 6 is a flow chart of one embodiment of a communication application of the present invention;
FIG. 7 is a flow chart of another embodiment of a communication application of the present invention;
FIG. 8 is a flow chart of one embodiment of a control module of the present invention;
FIG. 9 is a flow chart of one embodiment of a transmit module of the present invention;
FIG. 10 is a flow chart of one embodiment of a receiving module of the present invention;
fig. 11 is a schematic diagram illustrating the structure of one embodiment of a transmitting block or a receiving block of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be noted that, in the embodiment of the present invention, directional indications such as up, down, left, right, front, and rear … … are referred to, and the directional indications are merely used to explain the relative positional relationship, movement conditions, and the like between the components in a specific posture, and if the specific posture is changed, the directional indications are correspondingly changed. In addition, if there are descriptions of "first, second", "S1, S2", "step one, step two", etc. in the embodiments of the present invention, the descriptions are only for descriptive purposes, and are not to be construed as indicating or implying relative importance or implying that the number of technical features indicated or indicating the execution sequence of the method, etc. it will be understood by those skilled in the art that all matters in the technical concept of the present invention are included in the scope of this invention without departing from the gist of the present invention.
As shown in fig. 3-4, the present invention provides a method of asynchronous communication between a simulation model and a terminal, which is exemplified by, but not limited to, any port, such as a terminal device, hardware, network software, even another simulation model, etc., that receives the simulation model signal. Specifically, the asynchronous communication method optionally but not limited to includes:
s1: according to the number of terminals and the communication protocol, configuring at least one control module for each terminal in the simulation model, and setting a unique identifier for configuring communication parameters and controlling a communication application program;
specifically, assuming that the number of the terminals is 5, configuring at least one control module for each terminal; more specifically, the number of independent control modules of each terminal can be determined according to the number of communication protocols adopted by the terminal, and in the 5 terminals, only one independent control module is required to be configured if some terminals adopt one communication protocol, and two independent control modules are required to be configured to control if some terminals adopt multiple communication protocols, such as a network protocol and an industrial protocol. In summary, each terminal is provided with at least one independent control module for controlling its signal transmission.
More specifically, the communication parameters, optionally but not limited to, include: unique identification of the control module, unique identification, number and the like of the subsequently bound receiving module and transmitting module, terminal connection mode, terminal connection parameters, reading frequency, writing frequency, name paths of subsequent communication application programs and the like.
More specifically, the control module controls the communication application program, optionally but not limited to, when the simulation model is started, the shared memory is created first, and parameters of the control module are written into control blocks corresponding to the control modules in the shared memory. And starting the communication application program, monitoring the running state of the communication application program at fixed time, and when the simulation model stops, stopping the communication application program and cleaning the shared memory.
S2: according to the communication requirement, configuring a receiving module or/and a sending module for each terminal in the simulation model, setting a unique identifier, storing communication parameters to a corresponding control module, and binding the communication parameters with the control module configured for each terminal; specifically, according to the communication requirement of each terminal, receiving signals of a simulation model, and configuring a sending module for the terminal in the simulation model; a signal is sent to the simulation model, and a receiving module is configured for the terminal in the simulation model; the method comprises the steps of receiving signals of the simulation model and sending the signals to the simulation model, and configuring a sending module and a receiving module for the terminal in the simulation model. More specifically, the specific number of the receiving modules and the sending modules configured for each terminal in the simulation model is optionally but not limited to be set according to the data type requirement of the terminal to be sent or received, if there are multiple data types, multiple sending modules or/and receiving modules are configured, and unique identifiers, such as sending ID and receiving ID, are configured for each sending module and each receiving module, and binding is performed with the corresponding control module.
On the basis of the configuration, the simulation model configures at least one independent control module and an independent sending module or/and receiving module bound with the control module for each terminal, and can be mapped and corresponding to a communication application program according to communication parameters such as ID so as to realize the sending and receiving functions of data.
S3: each control module creates independent control blocks in the shared memory, and distributes independent transmission blocks or/and receiving blocks for the corresponding bound transmission modules or/and receiving modules in the control blocks.
Specifically, taking a certain terminal 1 as an example, assuming that it adopts a network protocol and an industrial protocol, 2 control modules are configured for it in step S1, then 2 independent control blocks need to be created for it in a shared memory at this time, and optionally, but not limited to, a first memory block of the control blocks is used for storing communication parameters of the terminal adopting the protocol, such as a unique identifier of the control module, a unique identifier, number, etc. of a bound receiving module, a bound sending module, a terminal connection mode, a terminal connection parameter, a name path of a subsequent communication application program, etc.; more specifically, if the terminal needs to adopt a network protocol to receive and send two data types, a control module corresponding to the network protocol needs to be configured and bound with 2 receiving modules and 2 sending modules in step S2; at this time, according to the unique identifiers of the receiving module and the transmitting module, such as a receiving ID and a transmitting ID, corresponding mapped receiving blocks and transmitting blocks are allocated in the bound control blocks, and then the receiving data and the transmitting data are stored; for example, as shown in fig. 5, a schematic structural diagram of a control block created by a control module is provided, where a unique identifier of the control block, such as the control block ID, is mapped first, control parameters are stored first, and then, according to a sending module and a receiving module bound thereto, the sending block and the receiving block are mapped and allocated, and a sending data block ID and a receiving data block ID are marked, so that sending data and receiving data are used for subsequent storage for model writing-communication application reading-or communication application writing-model reading-and communication application writing-model reading.
S4: when the simulation model is started, the control module starts a communication application program, and calls a corresponding sending module or/and receiving module according to communication parameters; in each step of simulation, the sending module writes the data of the simulation model into the corresponding sending block, and the communication application program reads the data from the sending block and sends the data to the corresponding terminal; the communication application program receives the terminal data to write into the corresponding receiving block, and then the corresponding receiving module reads the data from the receiving block and updates the data to the simulation model;
specifically, when the simulation model is started, optionally but not limited to in millisecond order, continuously according to the communication parameters, under the control of the control module, circularly writing the data of the simulation model into the corresponding sending block according to the unique identifier of the sending block, such as the ID of the sending block, and sending the data from the sending block to the terminal by the communication application program according to the reading frequency; meanwhile, the communication application program receives the terminal data, writes the corresponding receiving block according to the writing frequency, reads the data from the corresponding receiving block and updates the data to the simulation model. Meanwhile, the control module monitors the running state of the communication application program at regular time until the simulation is finished.
S5: and stopping the communication application program and cleaning the shared memory when the simulation model is stopped.
In this embodiment, an asynchronous communication method between the simulation model and the terminal is provided, on the one hand, only configuration in the simulation model is needed in the whole communication: the control module, the sending module, the receiving module and the communication application program module, namely the manual packaging module, have small workload; on the other hand, for each terminal, an independent control module, a sending module and a receiving module are configured in the simulation model according to the communication condition, a dynamic blocking mode is designed for storing data, and an independent storage block is allocated for the control module, the sending module and the receiving module by adopting a dynamic memory block allocation mode, so that when the simulation model needs to send communication data to the terminal or the terminal needs to send communication data to the simulation model, the independent control module, the sending module and the receiving module can be called to store the communication data to the corresponding storage block (the sending block or the receiving block), and when the simulation model stops, the shared memory is cleared again for being allocated again for use in the next simulation or other simulation model simulation. The asynchronous communication method can be used for realizing asynchronous communication by combining various communication modes (such as socket, serial port and the like) optionally but not exclusively. Based on the scheme, simulation technicians can complete asynchronous communication between the model and the terminal only by adding the control module, the sending module, the receiving module and the communication application program into the model, the terminal and the model are not required to be in a unified server, the terminal is not required to adopt a unified communication mode, the user can conveniently define and expand the communication mode, the interaction instantaneity is high, and the data accuracy is high.
1, communication application:
as shown in fig. 6, the communication applications may optionally, but not exclusively, include:
when the communication application program is initialized, mapping a corresponding control block according to the starting parameters;
reading communication parameters in a control block, comprising: control block, receiving block, unique identification of sending block and mapping address corresponding to the same; read frequency, write frequency.
According to the communication parameters, the simulation model corresponds to the unique identifiers of the control block and the sending block, the data of the simulation model is written into the mapping address of the corresponding sending block, the communication application program corresponds to the mapping address of the sending block, and the data of the simulation model is read out according to the reading frequency and sent to the corresponding terminal; or/and the unique identifier of the corresponding control block and the receiving block of the terminal, the communication application program writes the data of the terminal into the mapping address of the corresponding receiving block according to the writing frequency, and updates the data to the simulation model.
In this embodiment, a preferred embodiment of the communication application is provided, which is actually responsible for the interaction between the simulation model and the terminal, and optionally but not exclusively, mapping the corresponding control block according to the start-up parameter, preferably mapping the corresponding control block ID, i.e. the whole memory block corresponding to the corresponding terminal, during initialization. Then, all communication information between the simulation model and the terminal, namely communication parameters, are read from corresponding control blocks of the shared memory, and the communication parameters comprise unique identifiers of the control blocks, the receiving blocks and the sending blocks and corresponding mapping addresses; read frequency, write frequency, such as: the number of the sending modules, the ID of each sending module, the mapping offset address corresponding to each sending module, the unique identification of the sending block, the frequency of each sending module and other parameters are obtained; the number of the receiving modules, the IDs of the receiving modules, the mapping offset addresses corresponding to the receiving modules, the displacement representation of the receiving blocks, the time interval and other parameters of the receiving modules, the terminal connection information and the like are obtained. And establishing connection between the simulation model and the terminal according to the terminal connection information, and performing data interaction with the terminal. Reading data in a transmission block corresponding to the transmission module according to the time interval, and transmitting the data to the terminal; or when the terminal data is received, writing the data into a receiving block corresponding to the corresponding receiving module according to the time interval, and updating the data to the simulation model.
More specifically, as shown in fig. 7, the specific steps of the communication application may optionally, but not exclusively, include:
mapping a corresponding control block according to the unique identification of the control block, and acquiring communication parameters from the control block; alternatively but not exclusively: and mapping the shared memory according to the control block ID, and acquiring the required information from the control block.
A connection terminal;
data interaction is carried out with the terminal;
updating the sending block or/and the receiving block data; namely updating the shared memory data;
and (5) disconnecting all the mappings and ending.
2, a control module:
specifically, the control module is mainly used for creating and distributing shared memory-control blocks, sending blocks and receiving blocks, and storing communication parameters in the control blocks; and controlling the entire communication process.
More specifically, as shown in fig. 8, the specific steps of the control module may optionally include, but are not limited to:
creating an independent control block in the shared memory; namely, creating a shared memory;
in the control block, an independent sending block or/and a receiving block is allocated for the bound sending module or/and receiving module; namely, memory is allocated;
writing communication parameters into a control block; namely, corresponding to the shared memory;
starting and monitoring a communication application program when the simulation model starts;
and when the simulation model is finished, the communication application program is killed, and the shared memory is cleaned.
And 3, a sending module:
specifically, the sending module is mainly responsible for sending out the data of the simulation model. The sending module, optionally but not limited to, configures the control module ID of the binding, and sends the unique ID of the module. The input of the transmitting module is data to be transmitted and the transmitting frequency data, and the transmitting module outputs error code information to be transmitted. The sending module maps the corresponding shared memory according to the configured control block ID, namely, the sending block. The data block mapping information is read from the transmission block, and optionally but not limited to including a mapping address, mapping is performed. After the mapping is successful, along with the running of the model simulation, the model data to be transmitted is written into the data block according to the transmission frequency and is transmitted to the terminal. All mappings are disconnected when the simulation model stops.
Specifically, as shown in fig. 9, the specific steps of the sending module may optionally include, but are not limited to:
reading the mapping address of the sending block from the control block according to the unique identification mapping of the control block;
mapping the corresponding data block according to the mapping address of the sending block;
and according to the simulation step length, model data are continuously written into corresponding data blocks and are sent to corresponding terminals, and mapping is disconnected until the simulation model is ended.
4, a receiving module:
specifically, the receiving module: is mainly responsible for receiving terminal data and updating the terminal data into the model. The receiving module also needs to configure the bound control module ID, the unique ID of the receiving module. The input of the receiving module receives the time interval data and outputs the time interval data as received error code information and received data. The receiving module firstly maps the corresponding shared memory according to the configured control block ID. The mapping information (including the mapping address) of the data block is read from the control block and mapped. And after the mapping is successful, reading terminal data from the data block according to the receiving time interval, and outputting the terminal data to other modules of the model. All mappings are broken when the model stops.
More specifically, as shown in fig. 10, the specific steps of the receiving module may optionally include, but are not limited to:
reading the mapping address of the receiving block from the control block according to the unique identification of the control block;
mapping the corresponding data block according to the mapping address of the receiving block;
and continuously reading data from the receiving block according to the simulation step length, updating the data to the simulation model, and disconnecting the mapping until the simulation model is finished.
5 about shared memory
In order to avoid data disorder and ensure data interaction performance, the key of the method is as follows: and adopting the shared memory as a data cache region, and dynamically partitioning the memory. Specific: at least one independent control module is allocated to each terminal, and the control module creates an initial shared memory: control block, transmitting block, receiving block:
control block: the size has been determined at the time of initialization, including the communication parameters, namely: the public information portion, optionally but not limited to, includes: terminal connection information, the number of sending modules, the number of receiving modules, the total length of sending data blocks, the total length of receiving data blocks and the like); and m pieces of transmission block information, optionally but not limited to, each of which is fixed in size, the content including a transmission block ID, a transmission block offset address, a transmission block size, a transmission time interval, etc.; the n pieces of receiving block information, optionally but not limited to each information block is fixed in size, and the content includes a receiving block ID, a receiving block offset address, a receiving block size, a receiving time interval, and the like.
Transmitting block: the initialization is just creation, with size 0. Before mapping, a sending module firstly goes to a control block to inquire the starting address of the current sending block, and then maps the sending block with the length according to the total length of the mapped sending block as a mapping offset; after mapping, the mapping address and the length information of the transmission block are added to the information of the transmission block in the control block, and the total length of the mapped transmission block in the control block is updated. In addition, the send block only allows model writes, communication applications read.
Receiving a data block: the initialization is just creation, with size 0. Before the receiving module maps, firstly, the control block inquires the initial address of the current receiving block, and then, the receiving block with the length of itself is mapped according to the total length of the mapped receiving block as the mapping offset; after mapping, the mapping address and the receiving block length information are added to the receiving block information in the control block, and the total length of the mapped receiving block in the control block is updated. In addition, the receiving block only allows the communication application to write, model read.
More specifically:
each of the transmission block and the reception block has the same data structure although the read/write objects of the two blocks are opposite. Each small data block comprises a read mark, read repetition number, a write mark, write repetition number and a data segment, wherein the data segment is in a queue structure, as shown in fig. 11; the reading mark records the read position of the current reader; the read repetition number records the number of times that the reader has circularly read the data queue; the write mark records the written position of the current write party; the number of write repetitions records the number of times the writer has cycled the write data queue.
Thus, the logic to read the data is:
it is first determined whether the read repetition number is equal to the write repetition number. If the number of read repetitions < the number of write repetitions:
read data segment= (total length of data queue-read tag) + (write tag-0)
After the reading is finished, the reading repetition number is +1, and the reading mark is equal to the writing mark.
If read repetition number = write repetition number:
read data segment = write-read-mark
And updating the reading mark into a mark writing position after the reading is finished.
The logic for writing data is:
firstly judging whether the writing mark position is the tail of the queue, if so, writing the repetition number +1, writing the data to the head of the queue, and updating the writing mark value to 0; if the tag is not a tail, then the data is written to the tag location and then tag +1 is written.
Compared with the prior art, the scheme has the following advantages:
simplified model: decoupling the communication protocol and the receiving and transmitting of the model data, decoupling the data receiving and transmitting of the model and the interaction with the terminal, simplifying the model function, enabling the model to only be responsible for reading and writing the data, and enabling the communication with the terminal to be handed to a communication application program module, so that the extra functions of the model are reduced, and only the data processing and the simulation calculation are needed to be focused;
the application scene is various: although shared memory is also used, the simulation model and the terminal are not required to be in a unified server; and as the communication application program can expand the communication protocol along with the actual use of the scene, only the control module is required to be provided with the expanded communication application program. The semi-physical simulation in different application scenes is greatly facilitated;
the shared memory used as the data cache area is dynamically segmented, namely, the data of different receiving and transmitting modules are separated by adopting a dynamic blocking mode, the different data are not interfered with each other, the stability of the simulation system is enhanced, and the correctness of the data is improved;
the real-time performance of the model simulation is effectively ensured. Besides the protection of locking the parameters of the common part of the read-write control block during initialization, the data transmission is realized in a queue mode, no locking is needed, the data transmission performance is improved, and the real-time performance of simulation is ensured.
In a word, aiming at the defects of the prior art, the innovative technical scheme designs a mode of dynamic block storage of data and dynamic allocation of memory blocks, and realizes asynchronous communication between a model and multiple terminals by decoupling the receiving and transmitting of model data and the interaction of terminals. According to the scheme, the shared memory is used as a buffer area of data, the communication application program is used as a bridge between the model and the third party terminal, and the dynamic expansion of the asynchronous communication use scene is supported by an interactive decoupling mode of receiving and transmitting model data and the terminal. The method adopts a mode of dynamic memory partitioning and dynamic memory block allocation, and realizes efficient and stable data transceiving under the condition of no locking.
In another aspect, the present invention also provides a computer storage medium storing executable program code; the executable program code is configured to execute any of the above-described asynchronous communication methods between the simulation model and the terminal.
In another aspect, the present invention also provides a computer device comprising a memory and a processor; the memory stores program code executable by the processor; the program code is configured to execute any of the above-described methods of asynchronous communication between the simulation model and the terminal.
For example, the program code may be partitioned into one or more modules/units that are stored in the memory and executed by the processor to perform the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing the specified functions, which instruction segments describe the execution of the program code in a computer device.
The computer equipment can be a desktop computer, a notebook computer, a palm computer, a cloud server and other computing equipment. Computer devices may include, but are not limited to, processors, memory. Those skilled in the art will appreciate that computer devices may also include input and output devices, network access devices, buses, and the like.
The processor may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage may be an internal storage unit of the computer device, such as a hard disk or a memory. The memory may also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the computer device. Further, the memory may also include both internal storage units and external storage devices of the computer device. The memory is used to store the program code and other programs and data required by the computer device. The memory may also be used to temporarily store data that has been output or is to be output.
The technical effects and advantages of the computer storage medium and the computer device created based on the asynchronous communication method between the simulation model and the terminal are not repeated herein, and each technical feature of the above embodiment may be arbitrarily combined, so that the description is concise, and all possible combinations of each technical feature in the above embodiment are not described, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope described in the present specification.
The above examples illustrate only a few embodiments of the invention, which are described in detail and are not to be construed as limiting the scope of the invention. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the invention, which are all within the scope of the invention. Accordingly, the scope of protection of the present invention is to be determined by the appended claims.
Claims (9)
1. An asynchronous communication method between a simulation model and a terminal, comprising:
according to the number of terminals and the communication protocol, configuring at least one control module for each terminal in the simulation model, and setting a unique identifier for configuring communication parameters and controlling a communication application program;
according to the communication requirement, configuring a receiving module or/and a sending module for each terminal in the simulation model, setting a unique identifier, storing communication parameters to a corresponding control module, and binding the communication parameters with the control module configured for each terminal;
each control module creates independent control blocks in the shared memory, and distributes independent transmission blocks or/and receiving blocks for the corresponding bound transmission modules or/and receiving modules in the control blocks;
when the simulation model is started, the control module starts a communication application program, and calls a corresponding sending module or/and receiving module according to communication parameters; in each step of simulation, the sending module writes the data of the simulation model into the corresponding sending block, and the communication application program reads the data from the sending block and sends the data to the corresponding terminal; the communication application program receives the terminal data and writes the terminal data into the corresponding receiving block, and then the corresponding receiving module reads the data from the receiving block and updates the data to the simulation model;
stopping the communication application program and cleaning the shared memory when the simulation model is stopped;
a control block storing communication parameters, transmission block information, and reception block information;
before mapping, a sending module firstly goes to a control block to inquire the starting address of the current sending block, and then maps the sending block with the length according to the total length of the mapped sending block as a mapping offset; after mapping, adding the mapping address and the length information of the transmission block into the information of the transmission block in the control block, and updating the total length of the mapped transmission block in the control block;
before the receiving module maps, firstly, the control block inquires the initial address of the current receiving block, and then, the receiving block with the length of itself is mapped according to the total length of the mapped receiving block as the mapping offset; after mapping, the mapping address and the receiving block length information are added to the receiving block information in the control block, and the total length of the mapped receiving block in the control block is updated.
2. The method of asynchronous communication between a simulation model and a terminal according to claim 1, wherein the communication application comprises:
when the communication application program is initialized, mapping a corresponding control block according to the starting parameters;
reading communication parameters in a control block, comprising: control block, receiving block, unique identification of sending block and mapping address corresponding to the same; reading frequency, writing frequency;
according to the communication parameters, the simulation model corresponds to the unique identifiers of the control block and the sending block, the communication application program corresponds to the mapping address of the sending block, and the data of the simulation model are read out according to the reading frequency and sent to the corresponding terminal; or/and the unique identifier of the corresponding control block and the receiving block of the terminal, the communication application program writes the data of the terminal into the mapping address of the corresponding receiving block according to the writing frequency, and updates the data to the simulation model.
3. The method for asynchronous communication between a simulation model and a terminal according to claim 2, wherein the specific step of the communication application program comprises:
mapping a corresponding control block according to the unique identification of the control block, and acquiring communication parameters from the control block;
a connection terminal;
data interaction is carried out with the terminal;
updating the sending block or/and the receiving block data;
and (5) disconnecting all the mappings and ending.
4. The method of asynchronous communication between a simulation model and a terminal according to claim 1, wherein the specific step of the control module comprises:
creating an independent control block in the shared memory;
in the control block, an independent sending block or/and a receiving block is allocated for the bound sending module or/and receiving module;
writing communication parameters into a control block;
starting and monitoring a communication application program when the simulation model starts;
and when the simulation model is finished, the communication application program is killed, and the shared memory is cleaned.
5. The method for asynchronous communication between a simulation model and a terminal according to claim 1, wherein the specific step of transmitting the module comprises:
reading the mapping address of the sending block from the control block according to the unique identification mapping of the control block;
mapping the corresponding data block according to the mapping address of the sending block;
and according to the simulation step length, model data are continuously written into the corresponding sending block until the simulation model is ended, and mapping is disconnected.
6. The method of asynchronous communication between a simulation model and a terminal according to claim 1, wherein the specific step of receiving the module comprises:
reading the mapping address of the receiving block from the control block according to the unique identification of the control block;
mapping the corresponding data block according to the mapping address of the receiving block;
and continuously reading data from the receiving block according to the simulation step length, updating the data to the simulation model, and disconnecting the mapping until the simulation model is finished.
7. The method for asynchronous communication between a simulation model and a terminal according to any one of claims 1 to 6, wherein the transmitting block and the receiving block include a read tag, a read repetition number, a write tag, a write repetition number, and a data segment;
wherein the data segment is a queue structure; reading a position of the mark record which is read by the current reader; the read repetition times record the times that the reader has circularly read the data queue; writing a mark record of the written position of the current writing party; the number of write repetitions records the number of times the writer has cyclically written the data queue.
8. The method of asynchronous communication between a simulation model and a terminal of claim 7,
the logic for reading the data is:
firstly judging whether the read repetition number is equal to the write repetition number;
if the number of read repetitions < the number of write repetitions:
read data segment= (total length of data queue-read tag) + (write tag-0);
after the reading is finished, the reading repetition number is +1, and the reading mark is equal to the writing mark;
if read repetition number = write repetition number:
read data segment = write-read;
and updating the reading mark into a mark writing position after the reading is finished.
9. The method of asynchronous communication between a simulation model and a terminal of claim 8,
the logic for writing data is:
firstly judging whether the writing mark position is the tail of the queue;
if yes, writing repetition times +1, writing data to the queue head, and updating a writing index value to be 0;
if not, the data is written to the write tag location and then the tag +1 is written.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311219860.XA CN117097814B (en) | 2023-09-21 | 2023-09-21 | Asynchronous communication method between simulation model and terminal |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311219860.XA CN117097814B (en) | 2023-09-21 | 2023-09-21 | Asynchronous communication method between simulation model and terminal |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN117097814A CN117097814A (en) | 2023-11-21 |
| CN117097814B true CN117097814B (en) | 2023-12-29 |
Family
ID=88782873
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202311219860.XA Active CN117097814B (en) | 2023-09-21 | 2023-09-21 | Asynchronous communication method between simulation model and terminal |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN117097814B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117742984A (en) * | 2023-11-28 | 2024-03-22 | 海目星激光科技集团股份有限公司 | Software communication method, device and equipment |
Citations (13)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CA1293817C (en) * | 1986-04-28 | 1991-12-31 | Perry A. Caro | Data processing system emulation |
| JPH09233121A (en) * | 1996-02-23 | 1997-09-05 | Nippon Telegr & Teleph Corp <Ntt> | VC path connection control method and test equipment |
| JP2005010915A (en) * | 2003-06-17 | 2005-01-13 | Toshiba Corp | Parallel controller and parallel controller system simulator |
| CN101378573A (en) * | 2007-08-31 | 2009-03-04 | 中兴通讯股份有限公司 | System and method for testing access gateway performance |
| WO2012044262A1 (en) * | 2010-09-30 | 2012-04-05 | The Thailand Research Fund | Embedded system design, programming, and simulation architecture |
| CN103995777A (en) * | 2014-05-29 | 2014-08-20 | 上海科梁信息工程有限公司 | Automatic embedded software block box testing system and method |
| CN104537908A (en) * | 2014-12-17 | 2015-04-22 | 国电南瑞科技股份有限公司 | Multi-stage scheduling integrated simulation system based on model sharing and method |
| US9268670B1 (en) * | 2013-08-08 | 2016-02-23 | Google Inc. | System for module selection in software application testing including generating a test executable based on an availability of root access |
| CN105843693A (en) * | 2016-03-22 | 2016-08-10 | 同济大学 | High-speed maglev transportation simulation oriented memory sharing method |
| CN107169168A (en) * | 2017-04-18 | 2017-09-15 | 北京科东电力控制系统有限责任公司 | The front end processor simulation model and implementation method emulated for power information physical system |
| CN112395736A (en) * | 2020-10-09 | 2021-02-23 | 北京仿真中心 | Parallel simulation job scheduling method of distributed interactive simulation system |
| WO2022228528A1 (en) * | 2021-04-29 | 2022-11-03 | 华人运通(上海)云计算科技有限公司 | Simulation method and apparatus for vehicle simulation system, device and storage medium |
| WO2023124424A1 (en) * | 2021-12-31 | 2023-07-06 | 深圳市兆珑科技有限公司 | In-memory database access method and apparatus, system, server, and storage medium |
Family Cites Families (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7050962B2 (en) * | 2000-03-28 | 2006-05-23 | Zeidman Robert M | Method for connecting a hardware emulator to a network |
| US20080198742A1 (en) * | 2007-02-18 | 2008-08-21 | Gideon Kaempfer | Method and system for testing stateful network communications devices |
| US8073674B2 (en) * | 2008-09-23 | 2011-12-06 | Oracle America, Inc. | SCSI device emulation in user space facilitating storage virtualization |
-
2023
- 2023-09-21 CN CN202311219860.XA patent/CN117097814B/en active Active
Patent Citations (13)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CA1293817C (en) * | 1986-04-28 | 1991-12-31 | Perry A. Caro | Data processing system emulation |
| JPH09233121A (en) * | 1996-02-23 | 1997-09-05 | Nippon Telegr & Teleph Corp <Ntt> | VC path connection control method and test equipment |
| JP2005010915A (en) * | 2003-06-17 | 2005-01-13 | Toshiba Corp | Parallel controller and parallel controller system simulator |
| CN101378573A (en) * | 2007-08-31 | 2009-03-04 | 中兴通讯股份有限公司 | System and method for testing access gateway performance |
| WO2012044262A1 (en) * | 2010-09-30 | 2012-04-05 | The Thailand Research Fund | Embedded system design, programming, and simulation architecture |
| US9268670B1 (en) * | 2013-08-08 | 2016-02-23 | Google Inc. | System for module selection in software application testing including generating a test executable based on an availability of root access |
| CN103995777A (en) * | 2014-05-29 | 2014-08-20 | 上海科梁信息工程有限公司 | Automatic embedded software block box testing system and method |
| CN104537908A (en) * | 2014-12-17 | 2015-04-22 | 国电南瑞科技股份有限公司 | Multi-stage scheduling integrated simulation system based on model sharing and method |
| CN105843693A (en) * | 2016-03-22 | 2016-08-10 | 同济大学 | High-speed maglev transportation simulation oriented memory sharing method |
| CN107169168A (en) * | 2017-04-18 | 2017-09-15 | 北京科东电力控制系统有限责任公司 | The front end processor simulation model and implementation method emulated for power information physical system |
| CN112395736A (en) * | 2020-10-09 | 2021-02-23 | 北京仿真中心 | Parallel simulation job scheduling method of distributed interactive simulation system |
| WO2022228528A1 (en) * | 2021-04-29 | 2022-11-03 | 华人运通(上海)云计算科技有限公司 | Simulation method and apparatus for vehicle simulation system, device and storage medium |
| WO2023124424A1 (en) * | 2021-12-31 | 2023-07-06 | 深圳市兆珑科技有限公司 | In-memory database access method and apparatus, system, server, and storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN117097814A (en) | 2023-11-21 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US12425268B2 (en) | Data transmission method, processor system, and memory access system | |
| US20190196989A1 (en) | Method, Apparatus, and System for Accessing Memory Device | |
| US12321635B2 (en) | Method for accessing solid state disk and storage device | |
| US8199648B2 (en) | Flow control in a variable latency system | |
| CN110119304A (en) | A kind of interruption processing method, device and server | |
| CN105993148B (en) | Network Interface | |
| CN104657690A (en) | External equipment control method and device | |
| CN113014662A (en) | Data processing method and storage system based on NVMe-oF protocol | |
| CN113971138A (en) | Data access method and related equipment | |
| CN117097814B (en) | Asynchronous communication method between simulation model and terminal | |
| CN109639665B (en) | Method for expanding transmission protocol of publish-subscribe system based on multiple communication media | |
| CN115080479B (en) | Transmission method, server, device, bare metal instance and baseboard management controller | |
| CN113422669A (en) | Data transmission method, device and system, electronic equipment and computer readable storage medium | |
| CN112422485A (en) | Communication method and device of transmission control protocol | |
| WO2026016562A1 (en) | Data transmission method and computing device | |
| US11106359B1 (en) | Interconnection of peripheral devices on different electronic devices | |
| CN115733707A (en) | Data transmission method and system based on ARINC659 bus, electronic equipment and storage medium | |
| CN114978950B (en) | Network algorithm calling method and system based on FPGA and CPU cooperation | |
| JP7363344B2 (en) | Memory control device and control method | |
| CN116244249A (en) | Method, device, device and storage medium for multi-control board data communication | |
| CN120492369B (en) | Data processing system, method, device, medium and program product | |
| CN120407496B (en) | Host partition management architecture, server and method | |
| CN115687223A (en) | Method and device for serial port communication of embedded equipment, embedded equipment and storage medium | |
| JP7687745B2 (en) | Method and system for implementing virtual channels for automobile buses | |
| CN114422353B (en) | Multi-client data processing system, method and storage medium |
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 |