Disclosure of Invention
The invention aims to provide a method capable of simulating each communication node and bottom layer communication among the nodes, so that the cost of upper layer software in development is reduced, and the high controllability of testing is improved.
The method for simulating the communication between the nodes comprises the following steps:
setting a virtual concentrator which can simulate the functions of the concentrator for sending operation commands and receiving operation results;
the method comprises the steps that a plurality of hardware simulators which can simulate the message receiving and sending functions of a certain communication node of a power line carrier communication network and are controlled by an upper-layer module are arranged, wherein the hardware simulators at least comprise a first hardware simulator used for simulating a central controller and a second hardware simulator used for simulating a common slave node or a collector;
setting a plurality of virtual data acquisition terminals which can simulate the message generation function and the message receiving and sending function of the data acquisition terminals;
setting a control unit for configuring the hardware simulator, the virtual concentrator and the virtual data acquisition terminal;
configuring the virtual concentrator, the hardware simulator and the virtual data acquisition terminal by using the control unit so as to connect the virtual concentrator, the hardware simulator and the virtual data acquisition terminal into a simulated power carrier communication network;
and enabling the virtual concentrator, the hardware simulator and the virtual data acquisition terminal to simulate the communication behavior in the power carrier communication network according to respective set scripts.
The upper layer module in the patent refers to a module for executing upper layer software such as protocol layer software and application layer software.
The scheme utilizes the virtual concentrator, the hardware simulator and the virtual data acquisition terminal which only realize the functions related to the message, and utilizes the control unit to carry out the configuration of the virtual concentrator, the hardware simulator and the virtual data acquisition terminal, thereby being very convenient to realize; because the software only aims at the analysis and the receiving and sending control of the message, the scheme realizes the simulated power carrier communication network which can sufficiently support the test and the development of the software, and does not need to adopt entity equipment; meanwhile, the virtual concentrator and the virtual data acquisition terminal can be controlled randomly to realize functions necessary for testing and developing software in a mode of parameter configuration by the control unit, a virtual network required by testing is formed, and the defects that the functions supported by the concentrators and the electric meters of different manufacturers are incomplete, manual operation is basically only available, and controllability is weak are overcome. The scale of the network is conveniently realized by means of increasing and reducing hardware simulators and virtual data acquisition terminals, the software development period can be greatly shortened, the debugging difficulty is reduced, the scheme is flexible in networking, various application scenes can be quickly realized, and the operation is stable because all the aspects are controllable, so that the condition that completeness test cannot be carried out due to various abnormal conditions and different application scenes is avoided.
And further, a general hardware simulator with changeable functions is adopted to simulate any one of the central controller, the common slave nodes and the collector according to the configuration of the control unit.
Therefore, an independent hardware simulator is not needed to be designed for each type of node, and different required nodes can be obtained only by utilizing the configuration of the control unit, so that the network is greatly convenient to establish, change and adjust.
Further, the hardware simulator executes a corresponding message sending mode according to the message type sent by the upper layer module; the message sending mode comprises a time division multiplexing mode and a carrier monitoring mode.
The system can deal with different message sending modes and has wider adaptability.
Further, when a message packet sent by an upper layer module is a carrier monitoring type message packet, the hardware simulator requests a semaphore parameter from the control unit, and the message packet is sent until the semaphore parameter sent by the control unit indicates that a channel is available, or the message packet is not sent;
when the message packet is sent, the hardware simulator informs the control unit to enable the control unit to quantitatively change the semaphore parameter to the direction indicating that the channel is unavailable, and when the message packet is sent, the hardware simulator informs the control unit to quantitatively change the semaphore parameter to the direction indicating that the channel is available.
The scheme establishes a channel model equivalent to real carrier monitoring, and can quickly, simply and conveniently simulate the carrier monitoring of a real channel. The carrier monitoring process can be simulated without using a physical channel, the simulation effect of the whole communication process can not be influenced, the simulation truth degree is further improved, and the cost is reduced.
In a real power line carrier communication network, due to the problems of line attenuation and the like, whether a node in a channel is sending a message or not can not be absolutely monitored actually, so that the situation of message collision often occurs, namely two nodes send messages at the same time; that is, in a simulation environment, the channel is simply set to two states (in an extreme case of the scheme, the semaphore parameter has only two values, one represents occupied and the other represents unoccupied), which is far from the real channel condition; therefore, the scheme allows a certain number of nodes to simultaneously report at the same time point through the setting of the semaphore parameter, namely, the collision condition is allowed to occur, and a real channel is simply and effectively simulated.
Further, when a message packet sent by the upper layer module is a multiplexing type message packet, the hardware simulator appoints to send the message within preset time according to the time slot information carried in the message packet.
The time division multiplexing scene in a real network is simulated, and the simulation effect is better.
Further, a communication success rate script defining the communication success rate between every two communication nodes is obtained, and a channel communication success rate simulation module of the hardware simulator corresponding to each communication node is configured according to the communication success rate script;
the channel communication success rate simulation module randomly discards message packets from other nodes according to the configured communication success rate, so that the communication success rate between the node and other nodes specified in the communication success rate script is realized.
The method has the advantages that the signal-to-noise ratio of signal transmission is reduced and the signal quality is poor due to the fact that the real channel has noise, signal attenuation and the like, and accordingly communication failure with certain probability is caused. Moreover, if the communication success rate can be reduced according to the maximum value of the semaphore parameter, messages colliding with each other are simulated into system noise, the simulation degree of the system noise with a real network is higher, but the system overhead is not increased.
Further, the method comprises the steps of running a plurality of virtual machines on the physical machine; and arranging the hardware simulator on each virtual machine.
Further, the virtual machine adopts an embedded real-time operating system, and the hardware simulator is set to work based on the embedded real-time operating system.
Most of software needing to be developed is loaded in an embedded real-time operating system (such as freertos), and the scheme is adopted as a basis to provide simple sending and receiving interfaces for the development of upper-layer software to be tested, so that the interface function of the upper-layer software does not need to be changed to adapt to the system, the upper-layer software is convenient to call each module of the operating system, and the upper-layer software can be transplanted to real chip hardware without any redundant change;
further, a plurality of physical machines are adopted;
when the hardware simulator is configured as a central controller, the hardware simulator reads the time tick value of the physical machine where the hardware simulator is located, and sends the time tick value to the newly started hardware simulator through a clock synchronization message; when the hardware simulator is configured as a slave node, the hardware simulator parses the time tick value in the clock synchronization message from the central controller and calibrates the time at which the slave node performs various types of operations to be consistent with the central controller.
The clock synchronization message is used, the clock synchronization of each node is adjusted on the bottom layer, and the clock synchronization is completed by means of direct message packets among the nodes.
Detailed Description
The following is further detailed by way of specific embodiments:
the method for simulating communication between nodes in the embodiment includes the following steps:
setting a virtual concentrator which can simulate the functions of the concentrator for sending operation commands and receiving operation results;
the method comprises the following steps that a plurality of hardware simulators which can simulate the message receiving and sending functions of a certain communication node of a power line carrier communication network and are controlled by an upper-layer module are arranged;
the system comprises a central controller, a first hardware simulator, a second hardware simulator and a control module, wherein the first hardware simulator is used for simulating the central controller, and the second hardware simulator is used for simulating a common slave node or a collector;
setting a plurality of virtual data acquisition terminals which can simulate the message generation function and the message receiving and sending function of the data acquisition terminals;
setting a control unit for configuring the hardware simulator, the virtual concentrator and the virtual data acquisition terminal;
configuring the virtual concentrator, the hardware simulator and the virtual data acquisition terminal by using the control unit so as to connect the virtual concentrator, the hardware simulator and the virtual data acquisition terminal into a simulated power carrier communication network;
and enabling the virtual concentrator, the hardware simulator and the virtual data acquisition terminal to simulate the communication behavior in the power carrier communication network according to respective set scripts.
And the system also comprises a general hardware simulator with changeable functions, and the general hardware simulator is used for simulating any one of the central controller, the common slave nodes and the collector according to the configuration of the control unit.
Therefore, an independent hardware simulator is not needed to be designed for each type of node, and different required nodes can be obtained only by utilizing the configuration of the control unit, so that the network is greatly convenient to establish, change and adjust.
The hardware simulator executes a corresponding message sending mode according to the message type sent by the upper layer module; the message sending mode comprises a time division multiplexing mode and a carrier monitoring mode.
The system can deal with different message sending modes and has wider adaptability.
When a message packet sent by an upper layer module is a carrier monitoring type message packet, the hardware simulator requests a semaphore parameter from the control unit, and the message packet is sent when the semaphore parameter sent by the control unit indicates that a channel is available, or the message packet is not sent;
when the message packet is sent, the hardware simulator informs the control unit to enable the control unit to quantitatively change the semaphore parameter to the direction indicating that the channel is unavailable, and when the message packet is sent, the hardware simulator informs the control unit to quantitatively change the semaphore parameter to the direction indicating that the channel is available.
The scheme establishes a channel model equivalent to real carrier monitoring, and can quickly, simply and conveniently simulate the carrier monitoring of a real channel. The carrier monitoring process can be simulated without using a physical channel, the simulation effect of the whole communication process can not be influenced, the simulation truth degree is further improved, and the cost is reduced.
For example, the semaphore parameter indicates that the channel is completely occupied at 0, indicates that the channel is completely available at 5, and the current semaphore parameter is 3, so if a node obtains the parameter from the control unit at this time, the node starts to send a message, and simultaneously informs the control unit that it is sending, so the control unit reduces the semaphore parameter to 2; because the parameter is not 0 at present, other nodes can also send messages, and when the messages start, the parameter is reduced to 1; by analogy, when the parameter is reduced to 0, the rest nodes cannot perform message processing at this time until a certain node completes the message and notifies the control unit, the parameter is increased to 1, the certain node can perform message processing after obtaining the semaphore parameter, the initial parameter value is set to be 5, namely, the parameter when the channel is completely available can limit that only 5 nodes perform message processing simultaneously.
And when the message packet sent by the upper layer module is the multiplexing type message packet, the hardware simulator appoints to send the message within preset time according to the time slot information carried in the message packet.
The method also comprises the steps of obtaining a communication success rate script which defines the communication success rate between every two communication nodes, and configuring a channel communication success rate simulation module of the hardware simulator corresponding to each communication node according to the communication success rate script;
the channel communication success rate simulation module randomly discards message packets from other nodes according to the configuration of the channel communication success rate simulation module, so that the communication success rate between the node and other nodes specified in the communication success rate script is realized.
The signal-to-noise ratio of signal transmission is reduced and the signal quality is deteriorated due to the conditions of noise, signal attenuation and the like of a real channel, so that communication failure with a certain probability is caused. The influence of the channel quality on the communication can be simulated without using a physical channel, the simulation effect of the whole communication process can not be influenced, the simulation truth degree is further improved, and the cost is reduced.
The method also comprises the steps of adopting a plurality of physical machines, and running a plurality of virtual machines on each physical machine; and arranging the hardware simulator on each virtual machine. The virtual machine adopts an embedded real-time operating system, and the hardware simulator is set to work based on the embedded real-time operating system; when the hardware simulator is configured as a central controller, the hardware simulator reads the time tick value of the physical machine where the hardware simulator is located, and sends the time tick value to the newly started hardware simulator through a clock synchronization message; when the hardware simulator is configured as a slave node, the hardware simulator parses the time tick value in the clock synchronization message from the central controller and calibrates the time at which the slave node performs various types of operations to be consistent with the central controller. Most of software needing to be developed is loaded in an embedded real-time operating system (such as freertos), and the scheme is adopted as a basis to provide simple sending and receiving interfaces for the development of upper-layer software to be tested, so that the interface function of the upper-layer software does not need to be changed to adapt to the system, the upper-layer software is convenient to call each module of the operating system, and the upper-layer software can be transplanted to real chip hardware without any redundant change.
In the embodiment, the virtual concentrator, the hardware simulator and the virtual data acquisition terminal which only realize the functions related to the message are utilized, and the configuration of the virtual concentrator, the hardware simulator and the virtual data acquisition terminal is carried out by utilizing the control unit, so that the implementation is very convenient; because the software only aims at the analysis and the receiving and sending control of the message, the scheme realizes the simulated power carrier communication network which can sufficiently support the test and the development of the software, and does not need to adopt entity equipment; meanwhile, the virtual concentrator and the virtual data acquisition terminal can be controlled randomly in a mode of configuring the control unit to realize functions necessary for testing and developing software, and the defects that the functions supported by the concentrators and the electric meters of different manufacturers are incomplete, manual operation is basically realized, and controllability is weak are overcome. The scale of the network is conveniently realized by means of increasing and reducing hardware simulators and virtual data acquisition terminals, the software development period can be greatly shortened, the debugging difficulty is reduced, the scheme is flexible in networking, various application scenes can be quickly realized, and the operation is stable because all the aspects are controllable, so that the condition that completeness test cannot be carried out due to various abnormal conditions and different application scenes is avoided.
FIG. 2 illustrates a system constructed using the method of the present embodiment for simulating communication between nodes, the system comprising a control unit, a virtual concentrator, a hardware simulator and a virtual electric meter;
the specific composition of the system and its operation are described below;
the control unit is respectively connected with the virtual concentrator, the hardware simulator and the virtual data acquisition terminal one by one; the hardware simulator is also connected with an upper layer module for loading protocol layer and application layer software;
the hardware simulator is a general hardware simulator, can simulate the data transceiving function of a certain communication node of the power line carrier communication network, and is controlled by the upper module; the hardware simulator is configured into a first hardware simulator through the configuration of the control module and used for simulating a node of a central controller in a power grid, and the hardware simulator is configured into a second simulator and used for simulating nodes such as a common slave node and a collector according to the difference of the number of configured interfaces and the number of lower-hanging virtual data acquisition terminals; each node has its own IP address; according to respective IP addresses of the nodes, the nodes realize communication among the nodes by using UDP message interaction;
all the configurations are recorded in a configuration file, and the control module implements the specific configurations by reading the configuration file; in this embodiment, the control module is not actually part of the power carrier communications network that we are trying to simulate, and it acts as a control for each virtual unit or simulator in the network, so its connection to each virtual unit or simulator is referred to as a command channel in this embodiment.
The virtual data acquisition terminal in this implementation is a virtual ammeter: the virtual electric meter is realized by a Python script, realizes a complete 645 protocol and a 698 protocol, can simulate a real electric meter, realizes interaction with a common slave node/collector through a serial port (UART), and has various table item functions specified by a meter searching protocol and a reading protocol. Similarly, the central controller and the virtual concentrator are communicated through a serial port;
through the control unit, the user can configure the MAC address, the work baud rate and the serial port number of the virtual electric meter.
The virtual concentrator is also realized by Python script, the script realizes the complete protocol of the national network 376.2 when running under the Windows operating system, and the communication with the central controller is realized through a serial port.
The virtual concentrator can communicate with the hardware simulator block through a serial port, is configured with a serial port number, and has various table item functions specified by a table searching and reading protocol.
After the configuration is completed, each node completely follows the working mode of the real power line carrier communication network to perform networking, so as to form a power line carrier communication network basically as shown in fig. 1, which is relatively conventional and is not described herein again.
In this embodiment, the hardware simulator runs in the Windows operating system of the physical computer in a process manner, and is integrated with the simulator of the Freertos operating system, the simulator is used for establishing a simulator adopting the Freertos operating system on the physical computer, the hardware simulator runs on the simulator, and each hardware simulator can be regarded as running on a virtual machine using the Freertos operating system; a plurality of processes can be run on one physical computer in parallel, and more processes can be deployed on a plurality of physical computers simultaneously and in parallel, and all the processes are controlled by the control unit.
A simple sending and receiving interface is provided for upper-layer software development on a virtual machine using a Freetos operating system; the modules of the operating system can be conveniently called by upper-layer software, and can be transplanted to real chip hardware without any redundant change.
As known from the foregoing, UDP packets are used between nodes, and actually, each node is a process on a physical computer, and a virtual electricity meter and a virtual concentrator are also processes on the physical computer; the communication between processes is a socket communication in this embodiment.
Therefore, under this framework, the IP address allocated to the node actually belongs to a virtual IP address, and each virtual electric meter uses the same packet based on the MAC address as the real electric meter, and during networking, the process of matching the national network protocol by the serial number is simulated between the hardware simulator and the virtual electric meter (the serial number of the contact is issued through the configuration of the control unit), and further, in this virtual environment of this embodiment, the mapping relationship occurs between the virtual IP address of the node and the virtual electric meter.
Therefore, the IP network simulation power line transmission is realized through the mapping of the IP address and the MAC address of the virtual electric meter, and the communication (including the communication of a UART serial port and the communication of a UDP interface) is realized through the inter-process reuse socket so as to simulate the communication of the IP network; therefore, in the whole simulation network, the original appearance of the ammeter message is kept, the sending and receiving of the power line carrier communication network are simulated, and the software after the test can be very quickly transplanted to a real chip without great change (such as changing an interface function) when upper-layer software is tested.
As shown in fig. 3, the hardware simulator supports both TDMA and CSMA data transmission modes;
the method comprises the steps that a transmission management module is used for identifying a message packet, when the message packet sent by an upper layer module (upper level) is a time division multiplexing (TDMA DATA) message packet, a time division multiplexing (TDMA scheduling) module is used for appointing a sending module (TX) to send the message in preset time according to time slot information carried in the message packet, and the method can be realized by the following modes:
the time division multiplexing module comprises a plurality of hw queues, and each queue has the following properties:
id: unique identification queue
Enabled: whether enabled, only the queue of enabled can be used, which is configured by the upper layer;
priority: when the queue is generated, determining that the higher the priority, the more priority is to transmit the packet in the queue;
the time division multiplexing module is used for establishing two scheduling queues as ping-pong, one scheduling queue is used for being configured by upper-layer software during execution, 1000 cmdlist can be stored in each queue, and the format of each cmdlist is roughly as follows:
TABLE 1 cmdlist field Format
Enable_bitmap
|
Start_time
|
End_time |
Enable _ bitmap specifying hw queue to send
Start _ time the Start time when this cmd is to be executed refers to the system time.
End _ time the time when this cmd stops executing refers to the system time.
The upper layer mounts the message into a corresponding queue according to the priority of the message to be sent, and sets the queue as enabled; the upper layer will complete the corresponding cmdlist configuration and inform the time division multiplexing module.
After receiving cmdlist, the time division multiplexing module starts a timer according to start _ time in the cmdlist, and sends out messages in the cmdlist according to the hw queue priority in enable _ bitmap when the timer reaches the set time; and the reciprocating is executed until the End _ time is up.
The transmission management module comprises a carrier sense module (CSMA scheduling) to realize a carrier sense transmission mode.
Correspondingly, a semaphore parameter representing the channel occupation condition is stored in the control unit;
the carrier monitoring module is used for requesting a semaphore parameter to the control unit when a message packet sent by an upper layer module (upper level) is a carrier monitoring type message packet (non-TDMA DATA), and sending the message packet by the sending module (TX) until the semaphore parameter sent by the control unit indicates that a channel is available, or not sending the message packet;
and when the message packet is transmitted, the notification control unit enables the semaphore parameter to quantitatively develop towards the direction of indicating that the channel is unavailable, and when the message packet is transmitted, the notification control unit enables the semaphore parameter to quantitatively develop towards the direction of indicating that the channel is available.
A channel model equivalent to real carrier monitoring is established, and the carrier monitoring of a real channel can be simulated quickly, simply and conveniently. The carrier monitoring process can be simulated without using a physical channel, the simulation effect of the whole communication process can not be influenced, the simulation truth degree is further improved, the cost is reduced, and the system overhead of the algorithm is very small.
For example, the semaphore parameter indicates that the channel is completely occupied at 0, indicates that the channel is completely available at 5, and the current semaphore parameter is 3, so if a node obtains the parameter from the control unit at this time, the node starts to send a message, and simultaneously informs the control unit that it is sending, so the control unit reduces the semaphore parameter to 2; because the parameter is not 0 at present, other nodes can also send messages, and when the messages start, the parameter is reduced to 1; by analogy, when the parameter is reduced to 0, the rest nodes cannot perform message processing at this time until a certain node completes the message and notifies the control unit, the parameter is increased to 1, the certain node can perform message processing after obtaining the semaphore parameter, the initial parameter value is set to be 5, namely, the parameter when the channel is completely available can limit that only 5 nodes perform message processing simultaneously. A certain number of nodes are allowed to simultaneously report at the same time point, namely, the collision condition is allowed to occur, and a real channel is simply and effectively simulated.
The hardware simulator has the function of synchronizing the system clock and realizes barrier-free communication with the physical computer and the simulator on the cross-physical computer; when the hardware simulator is configured as a central controller, a synchronization module on the hardware simulator reads a time tick value of a physical machine where the hardware simulator is located, and sends the time tick value to the newly started hardware simulator through a clock synchronization message; when the hardware simulator is configured as a slave node, the time tick value in the clock synchronization message from the central controller is parsed and the time at which the slave node performs various types of operations is thereby calibrated to be consistent with the central controller.
The clock synchronization message is used, the clock synchronization of each node is adjusted on the bottom layer, and the clock synchronization is completed by means of direct message packets among the nodes.
In this embodiment, the control unit further includes a channel communication success rate simulation module, which provides an interface operation as shown in fig. 4, so that the control unit obtains a communication success rate script defining a communication success rate (success rate) between each two communication nodes, and configures the channel communication success rate simulation module of the hardware simulator corresponding to each communication node according to the communication success rate script;
after the receiving module (RX) receives the message, the channel communication success rate simulation module first determines which node the message is from according to its configuration, and randomly discards (drop) the message packets from other nodes, so that not all the received message packets are sent to the receive queue (RX queue), thereby implementing different communication success rates between the node and other nodes specified in the communication success rate script.
The signal-to-noise ratio of signal transmission is reduced and the signal quality is deteriorated due to the conditions of noise, signal attenuation and the like of a real channel, so that communication failure with a certain probability is caused. The influence of the channel quality on the communication can be simulated without using a physical channel, the simulation effect of the whole communication process can not be influenced, the simulation truth degree is further improved, and the cost is reduced.
The success rate of communication between any two nodes in the network is issued by the control unit through the command channel of the node, so as to realize the function of dynamically configuring the network topology. And, with the aid of the mathematical relationship between the maximum value of the semaphore parameter and the success rate of communication, the messages colliding with each other are simulated into the noise of the system, i.e. the semaphore parameter is increased, the success rate of communication is reduced, the simulation degree of the real network is higher, but the overhead of the system is not increased.
The foregoing is merely an example of the present invention, and common general knowledge in the field of known specific structures and characteristics is not described herein in any greater extent than that known in the art at the filing date or prior to the priority date of the application, so that those skilled in the art can now appreciate that all of the above-described techniques in this field and have the ability to apply routine experimentation before this date can be combined with one or more of the present teachings to complete and implement the present invention, and that certain typical known structures or known methods do not pose any impediments to the implementation of the present invention by those skilled in the art. It should be noted that, for those skilled in the art, without departing from the structure of the present invention, several changes and modifications can be made, which should also be regarded as the protection scope of the present invention, and these will not affect the effect of the implementation of the present invention and the practicability of the patent. The scope of the claims of the present application shall be determined by the contents of the claims, and the description of the embodiments and the like in the specification shall be used to explain the contents of the claims.