MeshProtocolSimulator
1.0.0
|
Go to the documentation of this file.
20 #include "meshNetGateway.h"
21 #include "Simulation_interface.h"
26 #include <condition_variable>
55 NodeConnections(MeshMAC node1, MeshMAC node2,
float rssi,
float rssi_tolerance,
float quality) {
128 MeshMAC MACAddress = 0;
133 bool isGateway =
false;
138 std::string SSID =
"";
158 std::chrono::nanoseconds
preSendDelay = std::chrono::nanoseconds(13000);
249 std::chrono::nanoseconds(5000);
267 RawMessage(uint8_t* message, uint8_t messageLength, std::chrono::nanoseconds _sentTime, std::chrono::nanoseconds _sendingDoneTime);
276 void Set(uint8_t* message, uint8_t messageLength, std::chrono::nanoseconds _sentTime, std::chrono::nanoseconds _sendingDoneTime);
283 void Get(uint8_t* message, uint8_t& messageLength)
const;
319 return uniqueIdentifier;
327 inline bool IsTransacting(std::chrono::nanoseconds currentSimulationTime)
const {
328 return currentSimulationTime <
ReceiveTime() && sentTime >= currentSimulationTime && !(sentTime == std::chrono::nanoseconds::zero() || receiveTime == std::chrono::nanoseconds::zero());
348 static void printFrameCompressed(uint64_t uniqueID, MeshFrame& msg);
363 uint8_t payload[MESH_FRAME_SIZE_LIMIT];
365 std::chrono::nanoseconds sentTime = std::chrono::nanoseconds::zero();
366 std::chrono::nanoseconds receiveTime = std::chrono::nanoseconds::zero();
368 uint64_t uniqueIdentifier = 0;
369 static uint64_t globalUniqueIdentifier;
512 bool BeginSimulation(std::chrono::nanoseconds simulationTimeOffset = std::chrono::nanoseconds::zero());
523 void SleepFor(std::chrono::nanoseconds sleepDelay);
587 bool IsFree(std::chrono::nanoseconds time);
595 bool IsFreeEx(std::chrono::nanoseconds time);
620 bool Receive(uint8_t* message, uint8_t& messageLength,
float& RSSI);
629 void Send(uint8_t* message, uint8_t messageLength);
639 void CreateRandomInterference(std::chrono::microseconds interferingDuration);
679 std::chrono::nanoseconds FreeFromTime = std::chrono::nanoseconds::zero();
680 std::chrono::nanoseconds FreeSenderFromTime = std::chrono::nanoseconds::zero();
705 std::chrono::nanoseconds
lastSentTime = std::chrono::nanoseconds::zero();
805 static void OnNodeDisconnectedStatic(MeshNet* mesh, MeshDisconnectReason reason, MeshMAC oldBSSID, uint8_t oldAddress);
814 void OnNodeDisconnected(MeshDisconnectReason reason, MeshMAC oldBSSID, uint8_t oldAddress);
830 static void OnPingRespStatic(MeshNet* mesh, uint8_t pingID, uint8_t pingAddr, MeshPacketError pingStat, uint8_t hops, uint32_t duration,
const uint8_t* testData, int16_t testDataLength);
842 void OnPingResp(uint8_t pingID, uint8_t pingAddr, MeshPacketError pingStat, uint8_t hops, uint32_t duration,
const uint8_t* testData, int16_t testDataLength);
846 friend Simulation_RFI;
Simulation_RFI * currentRFI
Pointer to speficied RF interface.
Definition: Emulator_helpers.h:746
std::chrono::nanoseconds ReceiveTime() const
Gets time, when message will be available to receive.
Definition: Emulator_helpers.h:302
Settings for each node in simulation. Those settings can be get from scenario file.
Definition: Emulator_helpers.h:124
std::chrono::nanoseconds simulationOffset
Simulation start offset.
Definition: Emulator_helpers.h:710
MeshMAC Node2
Second node.
Definition: Emulator_helpers.h:71
uint32_t MCUFrequency
Simulation MCU frequency in Hz. Defaultly set to 16 MHz.
Definition: Emulator_helpers.h:148
const NodeConnections * Link
Pointer to nodes link connection.
Definition: Emulator_helpers.h:117
bool IsInterfering(RawMessage &anotherMessage) const
Checks if two messages are interfering each other.
Definition: Emulator_helpers.cpp:338
std::chrono::nanoseconds preReceiveDelay
Delay before message is received in nanoseconds. Defaultly set to 5µs.
Definition: Emulator_helpers.h:188
Definition: Emulator_helpers.h:102
std::condition_variable_any CycleLockCV
Conditional variable for cycle lock.
Definition: Emulator_helpers.h:720
Class, that holds description of shared pointer to RawMessage instance. This is most effective way,...
Definition: Emulator_helpers.h:380
std::chrono::nanoseconds availableDelay
Delay when checking message avaiability in nanoseconds. Defaultly set to 5µs.
Definition: Emulator_helpers.h:208
std::chrono::nanoseconds getSimulationTime()
Gets current node simulation time.
Definition: Emulator_helpers.cpp:913
static void OnNodeConnectedStatic(MeshNet *mesh)
Static function, which can be used as callback. In this function correct OnNodeConnected() method is ...
Definition: Emulator_helpers.cpp:975
void Get(uint8_t *message, uint8_t &messageLength) const
Gets bytes from message.
Definition: Emulator_helpers.cpp:322
void PauseSimulationTimer()
Call this if cycle is going to be paused. It stops counting instructions done on current thread.
Definition: Emulator_helpers.cpp:953
bool IsSimulationRunning()
Checks if simulation is running for current node.
Definition: Emulator_helpers.h:529
uint32_t sendingSpeed
Speed of send in bits per second. Defaultly set to 1 Mbps.
Definition: Emulator_helpers.h:163
void clear()
Clears settings.
Definition: Emulator_helpers.h:233
TableType
This enum represents type of table of buffer used in MeshNet.
Definition: Emulator_helpers.h:33
Structure, that runs simulation for one node in network and contains some info about that node.
Definition: Emulator_helpers.h:420
uint64_t GetUniqueIdentifier() const
Gets unique identifier of current message.
Definition: Emulator_helpers.h:318
bool IsInterfered
True when message was interfered.
Definition: Emulator_helpers.h:341
uint32_t preSendCyclesDelay
Delay before message sending in cycles. Defaultly set to 50.
Definition: Emulator_helpers.h:153
NodeSimulator * Neighbor
Pointer to neighbor node simulator.
Definition: Emulator_helpers.h:112
std::deque< RawMessageDescriptor > inputFIFO
FIFO, that acts as FIFO on receiver module.
Definition: Emulator_helpers.h:685
int InputFiFoSize
Size of input FiFo on specified radio. Defaultly set to 3.
Definition: Emulator_helpers.h:228
bool BeginSimulation(NodeSettings settings_, std::chrono::nanoseconds simulationTimeOffset=std::chrono::nanoseconds::zero())
Turns on simulation for current node.
Definition: Emulator_helpers.h:500
bool canReceive() const
Returns true if sent frame has to be received and false if not. Decision is made by Quality value.
Definition: Emulator_helpers.cpp:33
float RSSI
RSSI value of received message.
Definition: Emulator_helpers.h:396
uint32_t postReceiveCyclesDelay
Delay after message is received in cycles. Defaultly set to 10.
Definition: Emulator_helpers.h:193
int lastAvailableBytes
Count of bytes, that was returned last time by Available() method.
Definition: Emulator_helpers.h:730
uint32_t postSendCyclesDelay
Delay after message sending in cycles. Defaultly set to 50.
Definition: Emulator_helpers.h:173
~NodeSimulator()
Destructor.
Definition: Emulator_helpers.cpp:360
uint32_t availableCyclesDelay
Delay when checking message avaiability in cycles. Defaultly set to 10.
Definition: Emulator_helpers.h:203
NodeSettings settings
Node settings.
Definition: Emulator_helpers.h:657
bool IsSimulationEnabled()
Checks if simulation has been started, but it does not mean it is currently running.
Definition: Emulator_helpers.h:537
void ReportCollision(RawMessageDescriptor &msg, RawMessage &msg2)
Reports half-duplex collision of message, which was received during sending.
Definition: Emulator_helpers.cpp:843
uint64_t lastCycles
Last count of processor cycles, which are used to calculate properly timing of simulation.
Definition: Emulator_helpers.h:695
std::chrono::nanoseconds getNodeWorkTime()
Gets work time of current node.
Definition: Emulator_helpers.h:551
uint8_t Available()
Checks how many bytes are available to receive.
Definition: Emulator_helpers.cpp:548
std::string ConvertToBase64(const MeshNetScanResult &result)
Converts MeshNetScanResult to Base64. Structure of data is:
Definition: Emulator_helpers.cpp:1075
float getRSSI() const
Gets RSSI from specified range, see RSSI and RSSI_tolerance.
Definition: Emulator_helpers.cpp:7
float RSSI
RSSI of current link connection in dBm. This value has to be negative and in range from 0dBm to -120d...
Definition: Emulator_helpers.h:76
uint32_t preReceiveCyclesDelay
Delay before message is received in cycles. Defaultly set to 10.
Definition: Emulator_helpers.h:183
static void OnReceiveStatic(MeshNet *mesh, MeshPacket &packet)
Static function, which can be used as callback. In this function correct OnReceive() method is called...
Definition: Emulator_helpers.cpp:1001
void ExecuteCycle()
Executes current node's one cycle.
Definition: Emulator_helpers.cpp:485
std::chrono::nanoseconds SentTime() const
Gets time, when message was sent.
Definition: Emulator_helpers.h:294
bool simulationTimerPaused
True if current simulation timer is running (ResumeSimulationTimer() was called) and false if simulat...
Definition: Emulator_helpers.h:736
float RSSI_tolerance
Absolute value, that can be added or subtracted from RSSI during simulation. When set to 0,...
Definition: Emulator_helpers.h:83
void OnReceive(MeshPacket &packet)
This method is called when node has received data packet.
Definition: Emulator_helpers.cpp:1006
NodeSettings GetSettings()
Gets node settings.
Definition: Emulator_helpers.h:573
std::string ConvertToBase64()
Converts raw message to Base64. Structure of data is:
Definition: Emulator_helpers.cpp:249
std::chrono::nanoseconds postReceiveDelay
Delay after message is received in nanoseconds. Defaultly set to 5µs.
Definition: Emulator_helpers.h:198
std::chrono::nanoseconds lastSentTime
Simulation time, when last message was sent.
Definition: Emulator_helpers.h:705
MeshMAC SenderNodeMACAddress
MAC address of current message sender.
Definition: Emulator_helpers.h:346
This structure represents raw message, that was sent between two virtual radios. It has no header and...
Definition: Emulator_helpers.h:262
bool IsInterfered
True if message was interfered yet.
Definition: Emulator_helpers.h:391
This class emulates virtual wireless environment for MeshNet nodes (MNodes) with virtual radios....
Definition: Emulator.h:26
MeshNet * Node()
Gets pointer to node, which is simulated by current NodeSimulator.
Definition: Emulator_helpers.h:463
Emulator * getParentPtr()
Gets pointer to emulator, which owns this instance.
Definition: Emulator_helpers.h:470
void EndSimulation()
Turns off simulation for current node.
Definition: Emulator_helpers.cpp:457
int CheckForSentMessages()
Checks received messages, puts them in FIFO and clears FIFO from interference and overflow messages.
Definition: Emulator_helpers.cpp:504
void ResumeSimulationTimer()
Call this if cycle is going to be resumed. It restarts counting instructions done on current thread.
Definition: Emulator_helpers.cpp:965
void OnNodeDisconnected(MeshDisconnectReason reason, MeshMAC oldBSSID, uint8_t oldAddress)
This method is called when node is disconnected from any network.
Definition: Emulator_helpers.cpp:992
std::chrono::nanoseconds getLastSentTime()
Gets simulation time, when last sent occoured.
Definition: Emulator_helpers.h:559
int getIndex()
Gets index of node in emulator array of nodes.
Definition: Emulator_helpers.h:477
void Send(uint8_t *message, uint8_t messageLength)
Sends data to the environment.
Definition: Emulator_helpers.cpp:618
void OnScanResponse(const MeshNetScanResult &result)
This method is called on every scan response by node.
Definition: Emulator_helpers.cpp:779
std::chrono::nanoseconds simulationOffset
Simulation start offset.
Definition: Emulator_helpers.h:143
uint64_t getCyclesCount()
Gets count of cycles, that were done in infinity loop, where is MeshNet code executed.
Definition: Emulator_helpers.h:484
std::function< void(void)> Interrupt
Function done at interrupt.
Definition: Emulator_helpers.h:458
int index
Index of node in emulator array of nodes.
Definition: Emulator_helpers.h:667
void Clear()
Clears data stored in message.
Definition: Emulator_helpers.cpp:329
NodeSimulator()
Constructor.
Definition: Emulator_helpers.h:426
std::chrono::nanoseconds simulationTime
Simulation time elapsed in nanoseconds.
Definition: Emulator_helpers.h:700
std::atomic< bool > CycleLock
True when current cycle is locked. Cycle can be executed only when it is unlocked.
Definition: Emulator_helpers.h:715
void Set(uint8_t *message, uint8_t messageLength, std::chrono::nanoseconds _sentTime, std::chrono::nanoseconds _sendingDoneTime)
Sets message bytes.
Definition: Emulator_helpers.cpp:308
uint8_t maxFrameSize
Maximum size of frame, that can be sent. Value can be from 24 to 255.
Definition: Emulator_helpers.h:223
MeshMAC Node1
First node.
Definition: Emulator_helpers.h:66
uint32_t interferenceCheckCyclesDelay
Delay when checking interference in cycles. Defaultly set to 10.
Definition: Emulator_helpers.h:213
static void OnNodeDisconnectedStatic(MeshNet *mesh, MeshDisconnectReason reason, MeshMAC oldBSSID, uint8_t oldAddress)
Static function, which can be used as callback. In this function correct OnNodeDisconnected() method ...
Definition: Emulator_helpers.cpp:988
bool Receive(uint8_t *message, uint8_t &messageLength, float &RSSI)
Receives message when available.
Definition: Emulator_helpers.cpp:573
void SleepFor(std::chrono::nanoseconds sleepDelay)
Makes current node sleep for specified delay.
Definition: Emulator_helpers.cpp:901
uint16_t GetLastAvailableBytes()
Gets last available bytes in one frame from Available() method.
Definition: Emulator_helpers.h:608
void OnNodeConnected()
This method is called when node is connected to new network.
Definition: Emulator_helpers.cpp:979
uint64_t numberOfCycles
Number of cycles done from start of the simulation.
Definition: Emulator_helpers.h:672
MeshNet * currentNode
Pointer to speficied node.
Definition: Emulator_helpers.h:741
const std::vector< NeighborNode > & GetNeighborNodes()
Gets reference to vector, which has pointers to all neighbor nodes. This return valid value only when...
Definition: Emulator_helpers.h:566
static void OnPingRespStatic(MeshNet *mesh, uint8_t pingID, uint8_t pingAddr, MeshPacketError pingStat, uint8_t hops, uint32_t duration, const uint8_t *testData, int16_t testDataLength)
Static function, which can be used as callback. In this function correct OnPingResp() method is calle...
Definition: Emulator_helpers.cpp:1028
This structure represents link connection between two nodes. Nodes are indentified by it's MeshMAC ad...
Definition: Emulator_helpers.h:47
std::chrono::nanoseconds preSendDelay
Delay before message sending in nanoseconds. Defaultly set to 13µs.
Definition: Emulator_helpers.h:158
uint32_t Length() const
Gets length of stored message in bytes.
Definition: Emulator_helpers.h:310
float Quality
Link quality, represented as probability, that sent packet through this link will be received....
Definition: Emulator_helpers.h:94
Emulator * em
Pointer to emulator, which owns this instance.
Definition: Emulator_helpers.h:662
std::chrono::nanoseconds postSendDelay
Delay after message sending in nanoseconds. Defaultly set to 13µs.
Definition: Emulator_helpers.h:178
bool simulationStarted
True if BeginSimulation() was called.
Definition: Emulator_helpers.h:725
bool IsFreeEx(std::chrono::nanoseconds time)
Check if node is not receiving at current simulation time. Use this from outside of simulation.
Definition: Emulator_helpers.cpp:936
std::chrono::nanoseconds interferenceCheckDelay
Delay when checking interference in nanoseconds. Defaultly set to 5µs.
Definition: Emulator_helpers.h:218
std::vector< NeighborNode > neighborNodes
Vector with pointers to all neighbor nodes.
Definition: Emulator_helpers.h:677
void ReportMessageLost(RawMessageDescriptor &msg, MeshMAC receiverNode)
Reports, that sent message was lost due to bad link quality.
Definition: Emulator_helpers.cpp:871
bool IsFree(std::chrono::nanoseconds time)
Check if node is not receiving at current simulation time. Use this from inside in simulation.
Definition: Emulator_helpers.cpp:930
std::shared_ptr< RawMessage > Message
Shared pointer to sent message. This acts as pointer to sent message. It is used to prevent copying s...
Definition: Emulator_helpers.h:411
void OnPingResp(uint8_t pingID, uint8_t pingAddr, MeshPacketError pingStat, uint8_t hops, uint32_t duration, const uint8_t *testData, int16_t testDataLength)
This method is called when ping response is received.
Definition: Emulator_helpers.cpp:1032
std::list< RawMessageDescriptor > receivedMessagesList
List of received messages, that was not processed yet.
Definition: Emulator_helpers.h:690
bool BadQuality
True if message cannot be read due to bad quality.
Definition: Emulator_helpers.h:401
bool IsTransacting(std::chrono::nanoseconds currentSimulationTime) const
Checks if message is transacting right now.
Definition: Emulator_helpers.h:327
void ReportInterference(RawMessageDescriptor &msg1, RawMessageDescriptor &msg2, MeshMAC currentNode)
Reports Hidden terminal interference of two messages.
Definition: Emulator_helpers.cpp:810
uint32_t extraBitsSentCount
Count of extra bits sent with message (preamble, CRC, ...)
Definition: Emulator_helpers.h:168