MeshNet  1.0.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes
MeshNet Class Reference

This class implements MeshNet protocol for microcontrollers. More...

#include <mesh.h>

Inheritance diagram for MeshNet:
Inheritance graph
[legend]
Collaboration diagram for MeshNet:
Collaboration graph
[legend]

Public Member Functions

 MeshNet ()
 Constructor without arguments. More...
 
virtual ~MeshNet ()
 Virtual destructor. More...
 
virtual bool begin (MeshMAC mac, RFInterface &RFI)
 Starts MeshNet instance for current node. More...
 
virtual bool begin ()
 Starts MeshNet instance for current node with last settings. More...
 
virtual bool end ()
 Disables mesh node. It is recommended to disconnect from network before calling this method, because some packets for another nodes can be lost. If node won't be disconnected before calling this method, it will be disconnected forcibly. More...
 
bool setChannel (uint8_t channel_)
 Sets network channel. More...
 
bool connect (MeshMAC netBSSID, bool autoConnect=false, uint32_t autoConnectInterval=30000)
 Connects to specified network. More...
 
bool directConnect (MeshMAC netBSSID, uint8_t interpreterAddr)
 Connects to specified network, but without scan. In this case, you have to know address of node, you want to connect to. More...
 
bool disconnect ()
 Disconnects current node from mesh network. It is recommended to check isDisconnecting() and isConnected() methods after calling this method. But do not forget, that this method may not immediately disconnect node, because it has to send some remaining packets. That's why it is not recommended to create while loop, where isDisconnecting() and isConnected() will be checked without calling hande() method. More...
 
void setAutoConnect (MeshMAC netBSSID, uint32_t retryInterval=60000)
 Enables auto connect to specified network. If auto connect is enabled and node is not connected to any network, it tries to connect to network, which BSSID is specified in parameter. If network is not found, connection is retried after time specified in retryInterval parameter. More...
 
void disableAutoConnect ()
 Disables auto connection. More...
 
bool startNetScan (void(*responseCallback)(MeshNet *, const MeshNetScanResult &), uint32_t timeout, MeshNetScanFlags flags, MeshMAC ResponderBSSID=0)
 Starts asynchronous network scanning. This function cannot be called when scan is actually running. More...
 
bool startNetScan (void(*responseCallback)(MeshNet *, const MeshNetScanResult &), uint32_t timeout=2000)
 Starts asynchronous network scanning. This function cannot be called when scan is actually running. More...
 
int16_t send (uint8_t addr, const uint8_t *data, uint16_t dataSize)
 Sends data packet to specified node. More...
 
int16_t send (uint8_t addr, const MeshVariableArray< uint8_t > &data)
 Sends data packet to specified node. More...
 
int16_t send (uint8_t addr, MeshVariableArray< uint8_t > &&data)
 Sends data packet to specified node. More...
 
int16_t ping (uint8_t addr, uint32_t timeout, int16_t testDataLength=0)
 Sends ping packet to node with specified address. When ping response is received, callback function set using setOnPingResponseCallback() is called. This is also called, when ping timed out. More...
 
void resetStatistics ()
 Resets statistics data. More...
 
virtual void handle ()
 This method has to be called in main program loop as often as possible. More...
 
uint8_t getMinChannel ()
 Get minimum channel number, that can be set using setChannel() method. More...
 
uint8_t getMaxChannel ()
 Get maximum channel number, that can be set using setChannel() method. More...
 
bool isConnected () const
 Checks if node is connected to any network. More...
 
bool isDisconnecting () const
 Checks if node is disconnecting right now. Node is finally disconnected after disconnect timeout or when no packet for that network is stored in some FIFO on current node. More...
 
MeshConnectionState getConnectionState () const
 Gets connection state of current node. More...
 
bool netScanRunning () const
 Checks if network scan is running. More...
 
bool pathExists (uint8_t address) const
 Checks if path to specified node exists. More...
 
bool pathCreating (uint8_t address) const
 Checks if path to specified node is creating right now. More...
 
uint8_t getNeighborNode (uint8_t address) const
 Gets address of neighbor node, which is next node in path. More...
 
uint8_t availablePacketsToSend (uint8_t destAddress, bool ACK_R=false) const
 Checks how many packet can be sent right now. More...
 
MeshPacketStatus getPacketStatus (uint8_t ID) const
 Tries to check, where is packet, that was sent by it's ID. More...
 
bool canBeGateway () const
 Checks if current node can be used as gateway or is used as gateway. More...
 
bool isMainGateway () const
 Checks if node is main gateway of network. Only main gateway can manage network. Other nodes, which are marked as gateway, but are connected to network are backup gateways. More...
 
bool isBackupGateway () const
 Checks if node is backup gateway of network. Only main gateway can manage network. Other nodes, which are marked as gateway, but are connected to network are backup gateways. Those nodes acts as normal node, but when main gateway is lost, one of backup nodes will act as gateway. More...
 
MeshMAC getNetworkBSSID () const
 Gets BSSID of network, the node is connected to. More...
 
MeshMAC getNodeMAC () const
 Gets current node unique MAC address. More...
 
uint8_t getNodeAddress () const
 Gets address of current node. If node is not connected to any network, 253 is returned. More...
 
RFInterfacegetRadioInterfacePtr () const
 Gets pointer to radio interface. More...
 
uint32_t getLostFramesTotalCnt () const
 Gets total count of lost frames. Frame is marked as lost, when attempt to send false, because of radio error or carriage sense detected interference. Frame is also marked as lost, when it need to be acknowledged, but ACK was not received. This value also includes frames for current network (see getLostFramesInNetworkCnt()). This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getLostFramesInNetworkCnt () const
 Gets count of lost frames for current network. Frame is marked as lost, when attempt to send false, because of radio error or carriage sense detected interference. Frame is also marked as lost, when it need to be acknowledged, but ACK was not received. This value does not include count of lost frames, that are not for current network. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected. More...
 
uint32_t getLostPacketsTotalCnt () const
 Gets total count of lost packets created by current node. This count does not include packet, that was lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout (see getLostRemotePacketsCnt()). This value also includes lost data packets, not only system packets. This value also includes packets for current network (see getLostPacketsTotalCnt()). This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getLostPacketsInNetworkCnt () const
 Gets count of lost packets created by current node for current network. This count does not include packets, that were lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout (see getLostRemotePacketsCnt()). This value also includes lost data packets, not only system packets. This value does not include count of lost packets, that are not for current network. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected. More...
 
uint32_t getLostDataPacketsCnt () const
 Gets count of lost data packets created by current node for current network. This count does not include packets, that were lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout (see getLostRemoteDataPacketsCnt()). This value includes only data packets. This value does not include count of lost packets, that are not for current network. This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getLostRemotePacketsCnt () const
 Gets total count of lost packets outside of current node created by current node. This value includes only packet, that was lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout. To get total lost packets use this formula: getLostPacketsTotalCnt() + getLostRemotePacketsCnt(). This value also includes lost data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getLostRemoteDataPacketsCnt () const
 Gets total count of lost data packets outside of current node created by current node. This value includes only packet, that was lost outside of node and were marked as data packets, for example when response to packet marked with ACK-R was not received until specified timeout. To get total lost packets use this formula: getLostPacketsTotalCnt() + getLostRemotePacketsCnt(). This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getLostRelayiedPacketsCnt () const
 Gets count of lost relayed packets in current node (packets, that were not created by current node). This value also includes data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getSentFramesTotalCnt () const
 Gets total count of successfully sent frames. Frame is successfully sent, when send was successful and frame was acknowledged when ACK was needed. This value also includes frames for current network (see getSentFramesInNetworkCnt()). This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getSentFramesInNetworkCnt () const
 Gets total count of successfully sent frames. Frame is successfully sent, when send was successful and frame was acknowledged when ACK was needed. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected. More...
 
uint32_t getSentPacketsTotalCnt () const
 Gets total count of successfully sent packets created by current node. This value also includes packets, that was lost outside of this node (see getLostRemotePacketsCnt()). This value also includes sent data packets, not only system packets. This value also includes packets for current network (see getSentPacketsInNetworkCnt()). This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getSentPacketsInNetworkCnt () const
 Gets count of successfully sent packets created by current node for current network. This value also includes packets, that was lost outside of this node (see getLostRemotePacketsCnt()). This value also includes sent data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected. More...
 
uint32_t getSentDataPacketsCnt () const
 Gets count of successfully sent data packets created by current node for current network. This value also includes packets, that was lost outside of this node (see getLostRemoteDataPacketsCnt()). This value also includes only data packets. This value is reset when end(), clear() or resetStatistics() is called. More...
 
uint32_t getRelayiedPacketsCnt () const
 Gets count of successfully relayed packets (packets, that were not created by current node). This value also includes data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called. More...
 
bool printRTable (OSTREAM *stream) const
 Prints Route Table in pretty format to stream. More...
 
bool printIDTable (OSTREAM *stream) const
 Prints ID Table in pretty format to stream. More...
 
bool printFIDTable (OSTREAM *stream) const
 Prints FID Table in pretty format to stream. More...
 
bool printOIDTable (OSTREAM *stream) const
 Prints OID Table in pretty format to stream. More...
 
bool printWaitingFIFO (OSTREAM *stream) const
 Prints waiting FIFO buffer in pretty format to stream. More...
 
bool printOutFIFO (OSTREAM *stream) const
 Prints output FIFO buffer in pretty format to stream. More...
 
size_t printMeshNetworkInfo (OSTREAM &stream) const
 Prints informations about network, node is connected to. More...
 
size_t printStatistics (OSTREAM &stream) const
 Prints statistics informations. More...
 
void setOnConnectedCallback (void(*callback)(MeshNet *))
 Sets callback function, which is called when current node is connected to network. More...
 
void setOnDisconnectedCallback (void(*callback)(MeshNet *, MeshDisconnectReason, MeshMAC, uint8_t))
 Sets callback function, which is called when current node is disconnected from network or when connection to network was aborted. More...
 
void setOnRemoteNodeDisconnectedCallback (void(*callback)(MeshNet *, uint8_t))
 This method is called when some node (not current node) is disconnected from network. More...
 
void setOnPingResponseCallback (void(*callback)(MeshNet *, uint8_t, uint8_t, MeshPacketError, uint8_t, uint32_t, const uint8_t *, int16_t))
 Sets callback function, which is called when ping response is received, or when ping timed out. More...
 
void setOnPacketErrorCallback (void(*callback)(MeshNet *, MeshPacketError, uint8_t, uint8_t, const MeshPacket *))
 Sets callback function, which is called when packet timeout happened and packet is removed. More...
 
void setOnReceive (void(*callback)(MeshNet *, MeshPacket &))
 Sets callback function, which is called when data packet is received. More...
 

Static Public Member Functions

static size_t printMeshConnectionState (OSTREAM &stream, MeshConnectionState value)
 Prints MeshConnectionState to stream. More...
 
static size_t printMeshDisconnectReason (OSTREAM &stream, MeshDisconnectReason value)
 Prints MeshDisconnectReason to stream. More...
 
static size_t printMeshPacketError (OSTREAM &stream, MeshPacketError value)
 Prints MeshPacketError to stream. More...
 
static MeshNet ** getInstances ()
 Gets array of all created MeshNet instances. More...
 

Static Public Attributes

const static MeshVersion Version = MESHNET_VERSION
 Version of MeshNet protocol. More...
 

Protected Member Functions

 MeshNet (bool canBeGateway)
 Universal protected constructor. More...
 
uint8_t getNewID ()
 Generates new ID for packet. More...
 
uint8_t getLastID ()
 Gets last generated ID. More...
 
void handleReceivedInterrupt ()
 
void onFrameReceive (MeshPacketBuilder *builder, MeshPacketBuilderStatus status, const MeshFrameHeader &frameHeader, const uint8_t *frameData, uint8_t frameDataSize, int8_t rssi)
 Method, which is called, when new valid frame is received. This method is used to calculate CTS time. More...
 
bool checkPacket (MeshPacketBuilder *builder, const MeshPacketHeader &packetHeader, MeshMAC BSSID, SystemPacketType systemPacketType, const uint8_t *frameData, uint8_t frameDataSize, int8_t rssi)
 This method is called when first frame of packet has been received. It has to decide, if packet has to be processed or ignored. More...
 
void processReceived ()
 Processes received frames. More...
 
virtual void processPacket (MeshPacket &packet, MeshMAC BSSID)
 Processes received packet. Called in processReceived() method. More...
 
void processTransmit ()
 Processes transmission of one frame from output FIFO. More...
 
void abortCurrentPacketTransmission (bool packetLost)
 Aborts splitting and transmission of packet currently loaded in packetSplitter. More...
 
void restartCurrentPacketTransmission ()
 Restarts transmission of current packet. Splitting is restarted. More...
 
void restartCurrentPacketTransmission (uint8_t maxFrameSize)
 Restarts transmission of current packet. Splitting is restarted. More...
 
bool packetTransmitting ()
 Checks if some frame of currently splitting packet has been already transmitted. More...
 
bool packetSplitting ()
 Checks if some packet is loaded in packet splitter. More...
 
bool systemNetworkScan (MeshMAC responderBSSID, MeshNetScanFlags flags)
 Perform network scan invoked by system before connecting to any network. This can be done only when no other scan is running right now and only if node is disconnected. More...
 
bool sendACK (const MeshACKSetup &setup, bool asDisconnected=false, bool asConnectedToOld=false)
 Sends ACK to last received frame. This has to be done when builder returns status MPB_FullPacketOK or MPB_PartPacketOK. More...
 
bool sendERR_ACK (const MeshACKSetup &setup, ERR_ACK_ErrorCode ErrorCode, uint8_t RepairValue, bool asDisconnected=false, bool asConnectedToOld=false)
 Sends ERROR ACK to last received frame. This has to be done when some error happened to last received frame. More...
 
bool PacketToFrame (const MeshPacket &packet, MeshMAC bssid, uint8_t *outBuffer, uint8_t &bufferSize) const
 Converts packet to frame. This can be called only if you are sure, that this packet won't be splitted to multiple frames, but will be converted to only one frame. Routed packets (ROE == 1 && RE == 1) cannot be converted. More...
 
bool SendPacketAsFrame (MeshPacket &packet, MeshMAC bssid)
 Sends packet, which is converted using method PacketToFrame() to frame, which is then sends. Packet is cleared after sending. Only packets, that won't be splitted to multiple frames will be sent, else false is returned. Packet ID is automatically generated here, same as using pushOutPacket() method, also From field is filled by current node address if needed. More...
 
virtual void onNodeLost (uint8_t address, bool nodeLostForever)
 This method is called, when some node is disconnected from network or does not responds to sent packet. More...
 
bool disconnectPriv (MeshDisconnectReason reason, bool doNotDisconnectImmediatelly, bool forceDisconnect=false)
 Disconnects current node from mesh network. It is recommended to check isDisconnecting() and isConnected() methods after calling this method. But do not forget, that this method may not immediately disconnect node, because it has to send some remaining packets. That's why it is not recommended to create while loop, where isDisconnecting() and isConnected() will be checked without calling handle() method. More...
 
bool sendDisconnectPacket (MeshNetDisconnectPacketType type)
 Immediately sends disconnect packet (without pushing to outFIFO), that says current node is disconnecting. OnSystemDisconnect() method is not called here. More...
 
void onSystemDisconnect (MeshDisconnectReason reason)
 Do necessary work after node was disconnected or connection was aborted. onDisconnected method is called here. More...
 
virtual void onOIDTRemove (int16_t index, const MeshOIDTableRow &oldRow, uint8_t oldRawLifeTime, MeshOIDTableRemoveReason reason)
 This method is called when any row from OID table is removed. More...
 
void onNewPath (int16_t index, const MeshRouteTableRow &row)
 This method is called when new path was found (created). It is not called if path is prolonged. More...
 
void onBufferPacketLost (const MeshPacket &packet, MeshPacketError error)
 This method is called when some packet created by this node was lost, because some FIFO, where it has to be stored is full or it was removed from FIFO. This method does some clearing process (clears OIDT row of current packet if exists) and reports error if packet was created by current node. More...
 
void onBufferPacketRemove (const MeshPacket &packet, bool ignoreCurrentNetworkPacket, bool packetLost)
 This method is called when any packet is removed from waitingFIFO or outFIFO. More...
 
virtual void onPacketError (MeshPacketError error, uint8_t packetID, uint8_t packetDest, SystemPacketType packetType, const MeshPacket *packet_ptr)
 This method is called when some error happened to any packet created by current node. More...
 
bool systemPing (uint8_t addr, uint32_t timeout)
 Sends ping packet to node with specified address. When ping response is received, onSystemPingReceived() is called. This is also called, when ping timed out. This can be called only once. More...
 
void onSystemPingReceived (bool valid, uint32_t duration)
 This method is called when system ping packet response was received. More...
 
virtual void routeTableUpdate (const MeshPacketHeader &header, MeshMAC BSSID, int8_t rssi)
 Updates route table when valid packet from node with same network is received.ň More...
 
MeshPacketError pushOutPacket (MeshPacket &packet, uint32_t timeout=0)
 Pushes packet to output FIFO buffer. More...
 
bool createPath (uint8_t address)
 Creates path to specified node. More...
 
void checkWaitingBuffer ()
 Checks if there are some packets in waiting buffer, which can be sent. Those packets will be sent in this method. More...
 

Static Protected Member Functions

static void onFrameReceiveStatic (MeshPacketBuilder *builder, MeshPacketBuilderStatus status, const MeshFrameHeader &frameHeader, const uint8_t *frameData, uint8_t frameDataSize, int8_t rssi)
 Processed received messages. More...
 
static bool checkPacketStatic (MeshPacketBuilder *builder, const MeshPacketHeader &packetHeader, MeshMAC BSSID, SystemPacketType systemPacketType, const uint8_t *frameData, uint8_t frameDataSize, int8_t rssi)
 Static function, which can be used as callback. In this function correct checkPacket() method is called. More...
 
static bool isForeignNetworkPacket (const MeshPacket &packet, MeshMAC bssid)
 Checks if packet is for current network (with specified BSSID in BSSID parameter) or not. More...
 
static void onOIDTRemoveStatic (MeshOIDTable< OIDTABLE_SIZE > *table, int16_t index, const MeshOIDTableRow &oldRow, uint8_t oldRawLifeTime, MeshOIDTableRemoveReason reason)
 Static function, which can be used as callback. In this function correct onOIDTRemove() method is called. More...
 
static void onNewPathStatic (MeshRouteTable< ROUTETABLE_SIZE > *table, int16_t index, const MeshRouteTableRow &row, uint8_t rawLifeTime)
 Static function, which can be used as callback. In this function correct onNewPath() method is called. More...
 

Protected Attributes

const bool canBeGateway_:1
 True if current node can be used as gateway. More...
 
bool sentFrameWasACK:1
 True when sent frame was acknowledged. More...
 
bool packetSplittingStarted:1
 True if packet splitting has started. More...
 
bool sendingPacketIsForeign:1
 True if packet, that is loaded in packetSplitter is for foreign network. More...
 
bool ignoreRSSIThreshold:1
 True to ignore RSSI threshold on received network scan responses during scan. More...
 
bool waitingBufferCheck:1
 True if waitBuffer has to be checked and some packets has to be sent. More...
 
bool beginCalled:1
 True if begin was called. More...
 
bool receiveInterruptEnabled:1
 True if interrupt will be fired when new frame is received. More...
 
uint8_t channel
 Channel number, that will be set or is set. More...
 
uint8_t AddrPriv = UNKNOWN_MESH_ADDRESS
 Address of current node. Can be between 0 - 250 or 254 when disconnected. More...
 
MeshMAC NodeMAC
 Unique node physical MeshMAC address. More...
 
MeshMAC NetworkBSSID
 If node is disconnected, this is same as NodeMAC, else NetworkBSSID equals BSSID address of connected network. More...
 
char SSID [65]
 SSID of network, node is connected to. More...
 
uint32_t AddrReservedUntil = 0
 Time in milliseconds until which address of current node is for sure reserved in main gateway node's DHCP table. Address reservation in DHCP table is prolonged, when gateway receives any packet from current node. More...
 
uint16_t AddrReservationTime = 0
 Time in minutes the address can be reserved for in DHCP table in main gateway. This value is obtained during connection and it cannot change when connected to network. More...
 
uint8_t oldNodeAddress = UNKNOWN_MESH_ADDRESS
 Old node address, that was assigned to node when it has been connected to some network. More...
 
MeshMAC oldBSSID
 Old BSSID of network the node was connected to last time. More...
 
RFInterfacerf
 Pointer to radio interface, that is used by current class. More...
 
uint64_t CTS_until = 0
 Clear to send until this time in microseconds, so node cannot send frames until this time. ACK packets have exception from this rule. More...
 
uint64_t lastReceiveTime = 0
 Time when last frame was received in microseconds. More...
 
uint32_t lastSentTime = 0
 Time, when was last frame sent in milliseconds. More...
 
uint8_t frameTranCnt = 0
 (Re)Transmission count of last sent frame. More...
 
MeshConnectionState connectionState = MeshConnectionState::MeshDisconnected
 Connection state of current node. More...
 
MeshDisconnectReason lastDisconnectReason = MeshDisconnectReason::MDR_None
 Last disconnect or connection fail reason. More...
 
uint8_t currentNetworkPackets = 0
 Count of packets in buffers, that belongs to the current connected network. More...
 
uint32_t scanEndTime = 0
 Time in milliseconds, when network scan ends. More...
 
uint32_t lastScanTime = 0
 Time in milliseconds, when network scan was last time executed. More...
 
uint8_t lowestHopsToGateway = 255
 The smallest count of hops to gateway established during last system network scan. More...
 
uint8_t lowestHopsToGateway_Addr = INVALID_MESH_ADDRESS
 Address of node with the smallest count of hops to gateway established during last system network scan. More...
 
MeshMAC lastScanResponderBSSID
 BSSID of network, the system network scan was assigned to. More...
 
uint32_t connectionStepTime = 0
 Time in milliseconds, when connection state was last changed. More...
 
MeshMAC autoConnectBSSID
 BSSID of network, this node has to automatically connect to. More...
 
uint32_t nextAutoConnectTime = 0
 Time in milliseconds, when auto connection attempt will be invoked. More...
 
uint32_t autoConnectInterval = 0
 Auto connect interval in milliseconds. More...
 
uint32_t disconnectUntil = 0
 Until this time in milliseconds node has to be disconnected. More...
 
int16_t systemPingID = -1
 ID of last system ping packet. More...
 
void(* netScanResponseCallback )(MeshNet *, const MeshNetScanResult &)
 Pointer to callback function called when network scan response was received. More...
 
void(* onConnected )(MeshNet *)
 This method is called when node is connected to network. More...
 
void(* onDisconnected )(MeshNet *, MeshDisconnectReason, MeshMAC, uint8_t)
 This method is called when node is disconnected from network. More...
 
void(* onRemDisconnected )(MeshNet *, uint8_t)
 This method is called when some node from network is disconnected. More...
 
void(* onReceive )(MeshNet *, MeshPacket &)
 Function called when data packet is received. More...
 
void(* onPingResponse )(MeshNet *, uint8_t, uint8_t, MeshPacketError, uint8_t, uint32_t, const uint8_t *, int16_t)
 Function called when ping response is received or when ping timed out. More...
 
void(* onPacketErrorCallback )(MeshNet *, MeshPacketError, uint8_t, uint8_t, const MeshPacket *)
 
uint32_t lostFramesTotal = 0
 
uint32_t lostFramesInNetwork = 0
 
uint32_t lostPacketsTotal = 0
 
uint32_t lostPacketsInNetwork = 0
 
uint32_t lostRemotePackets = 0
 
uint32_t lostRemoteDataPackets = 0
 
uint32_t lostDataPackets = 0
 
uint32_t lostRelayiedPackets = 0
 
uint32_t sentFramesTotal = 0
 
uint32_t sentFramesInNetwork = 0
 
uint32_t sentPacketsTotal = 0
 
uint32_t sentPacketsInNetwork = 0
 
uint32_t sentDataPackets = 0
 
uint32_t relayiedPackets = 0
 
MeshPacketBuilder packetBuilder
 Combines received MeshFrames to MeshPacket. More...
 
MeshPacketSplitter packetSplitter
 Splits MeshPacket to multiple MeshFrames for transmission. More...
 
MeshRouteTable< ROUTETABLE_SIZERTable
 Routing table. More...
 
MeshIDTable< IDTABLE_SIZEIDTable
 Table of received packets ID (ID+Source). This check, if some packet has been received multiple times. More...
 
MeshFIDTable< FIDTABLE_SIZEFIDTable
 
MeshOIDTable< OIDTABLE_SIZEOIDTable
 Table of sent (output) packets ID and destination (source is current node address). Only packet, that was created by current node can be stored here, relayed packet cannot be stored here. This table is for checking, what action was done and what packet is expected (response or ACK-R response). More...
 
MeshPacketPriorityFIFO< MESH_OFIFO_HIGH_SIZE, MESH_OFIFO_LOW_SIZEoutFIFO
 Packets that waits in buffer to be sent. More...
 
MeshPacketFIFO< MESH_WFIFO_SIZEwaitingFIFO
 Packets, that has to be sent as routed packet, but path is not known yet. More...
 

Private Member Functions

void addThisToInstArr ()
 Writes new class instance to the array of all created MeshNet instances. We need to know all created instances to call correct callback method. This method has to be called in constructor. More...
 
void removeThisFromInstArr ()
 Removes this instance from instances array. This method has to be called in destructor. More...
 
void clear (bool disconnecting)
 Clears current class data. More...
 

Private Attributes

uint8_t msgIDPriv = 0xFF
 Last value of packet ID. More...
 

Static Private Attributes

static MeshNetinstances [] = { 0 }
 Array of all created MeshNet instances. Thanks to this array callback functions of MicroTable, PacketSplitter and PacketBuilder classes can be set. If this array is full. New created instances will not work correctly. More...
 
static uint8_t instCount = 0
 Count of created instances of this class. More...
 

Detailed Description

This class implements MeshNet protocol for microcontrollers.

Note
When this class is inherited, base constructor has to be always called.

Constructor & Destructor Documentation

◆ MeshNet() [1/2]

MeshNet::MeshNet ( )
inline

Constructor without arguments.

Note
When this class is inherited, base constructor has to be always called.

◆ ~MeshNet()

MeshNet::~MeshNet ( )
virtual

Virtual destructor.

◆ MeshNet() [2/2]

MeshNet::MeshNet ( bool  canBeGateway)
protected

Universal protected constructor.

Member Function Documentation

◆ abortCurrentPacketTransmission()

void MeshNet::abortCurrentPacketTransmission ( bool  packetLost)
inlineprotected

Aborts splitting and transmission of packet currently loaded in packetSplitter.

Parameters
packetLostTrue when packet was lost.

◆ addThisToInstArr()

void MeshNet::addThisToInstArr ( )
private

Writes new class instance to the array of all created MeshNet instances. We need to know all created instances to call correct callback method. This method has to be called in constructor.

◆ availablePacketsToSend()

uint8_t MeshNet::availablePacketsToSend ( uint8_t  destAddress,
bool  ACK_R = false 
) const

Checks how many packet can be sent right now.

Note
It is recommended to leave at least 1 free space for packet, which can be used for packets, that has to be relayed.
Parameters
destAddressDestination address of receiver node.
ACK_RTrue if ACK response is requested.
Returns
Returns count of packets, that can be sent.

◆ begin() [1/2]

bool MeshNet::begin ( )
virtual

Starts MeshNet instance for current node with last settings.

Note
This method can be called only when begin(MeshMAC mac, RFInterface& RFI) has been called any time before, because parameters of that method are reused.
Returns
Returns true when instance started successfully.

Reimplemented in MeshNetGateway.

◆ begin() [2/2]

bool MeshNet::begin ( MeshMAC  mac,
RFInterface RFI 
)
virtual

Starts MeshNet instance for current node.

Parameters
macNode MAC address.
Note
Node MAC address has to be valid and unique.
Parameters
RFIRadio interface, which is used for radio control.
Returns
Returns true when instance started successfully.

Reimplemented in MeshNetGateway.

◆ canBeGateway()

bool MeshNet::canBeGateway ( ) const
inline

Checks if current node can be used as gateway or is used as gateway.

◆ checkPacket()

bool MeshNet::checkPacket ( MeshPacketBuilder builder,
const MeshPacketHeader packetHeader,
MeshMAC  BSSID,
SystemPacketType  systemPacketType,
const uint8_t *  frameData,
uint8_t  frameDataSize,
int8_t  rssi 
)
protected

This method is called when first frame of packet has been received. It has to decide, if packet has to be processed or ignored.

Parameters
builderPacketBuilder, which called this method.
packetHeaderReceived packet header.
BSSIDof packet transmitter.
systemPacketTypeType of system packet.
frameDataPart of received data from packet payload.
frameDataSizeSize of part of received data from packet payload.
rssiRSSI value of received frame.

◆ checkPacketStatic()

bool MeshNet::checkPacketStatic ( MeshPacketBuilder builder,
const MeshPacketHeader packetHeader,
MeshMAC  BSSID,
SystemPacketType  systemPacketType,
const uint8_t *  frameData,
uint8_t  frameDataSize,
int8_t  rssi 
)
staticprotected

Static function, which can be used as callback. In this function correct checkPacket() method is called.

◆ checkWaitingBuffer()

void MeshNet::checkWaitingBuffer ( )
protected

Checks if there are some packets in waiting buffer, which can be sent. Those packets will be sent in this method.

◆ clear()

void MeshNet::clear ( bool  disconnecting)
private

Clears current class data.

Parameters
disconnectingTrue if clear is called, because node was disconnected

◆ connect()

bool MeshNet::connect ( MeshMAC  netBSSID,
bool  autoConnect = false,
uint32_t  autoConnectInterval = 30000 
)

Connects to specified network.

Connection steps:

  1. Scan is done. Only nodes of network, we want to connect to will respond to that scan. Scan takes time specified by macro: MESH_SYS_NET_SCAN_TIMEOUT. The result of scan is an interpreter node address, which is the gateway or is near gateway.
  2. Connection request is sent to the interpreter node.
  3. If the interpreter node is gateway, this step and step 5 are skipped. Else the interpreter node will send routed packet to the gateway.
  4. Gateway can refuse connection. If connection is granted, gateway will assign new address to the current node using DHCP table.
  5. Gateway will send connection result to the interpreter node.
  6. Current node will receive response to the connection. If connection was not refused, current node is connected to network.
    Parameters
    netBSSIDBSSID of network to connect to.
    autoConnectEnables auto connection to that network. For more see setAutoConnect() method.
    autoConnectIntervalAfter this interval when connection failed, connect() method is called again.
    Returns
    Returns true when connecting process has started.

◆ createPath()

bool MeshNet::createPath ( uint8_t  address)
protected

Creates path to specified node.

Parameters
addressAddress of node, to which path has to be created.
Returns
Returns true if path creation has started.

◆ directConnect()

bool MeshNet::directConnect ( MeshMAC  netBSSID,
uint8_t  interpreterAddr 
)

Connects to specified network, but without scan. In this case, you have to know address of node, you want to connect to.

Connection steps:

  1. Connection request is sent to the interpreter node.
  2. If the interpreter node is gateway, this step and step 4 are skipped. Else the interpreter node will send routed packet to the gateway.
  3. Gateway can refuse connection. If connection is granted, gateway will assign new address to the current node using DHCP table.
  4. Gateway will send connection result to the interpreter node.
  5. Current node will receive response to the connection. If connection was not refused, current node is connected to network.
    Parameters
    netBSSIDBSSID of network to connect to.
    interpreterAddrAddress of interpreter node.
    Returns
    Returns true when connecting process has started.

◆ disableAutoConnect()

void MeshNet::disableAutoConnect ( )

Disables auto connection.

◆ disconnect()

bool MeshNet::disconnect ( )

Disconnects current node from mesh network. It is recommended to check isDisconnecting() and isConnected() methods after calling this method. But do not forget, that this method may not immediately disconnect node, because it has to send some remaining packets. That's why it is not recommended to create while loop, where isDisconnecting() and isConnected() will be checked without calling hande() method.

Disconnection steps

  1. Removing packets created by current node for network from waitingFIFO or outFIFO. isDisconnecting() and isConnected() will return true.
  2. Disconnect packet is created and pushed to outFIFO.
  3. Sending all packets from outFIFO for network until timeout MESH_DISCONNECT_TIMEOUT.
  4. After timeout, or when outFIFO is clear, node is definitely disconnected. isDisconnecting() and isConnected() will return false here.
    Returns
    Returns true if disconnect started or node was immediately disconnected.

◆ disconnectPriv()

bool MeshNet::disconnectPriv ( MeshDisconnectReason  reason,
bool  doNotDisconnectImmediatelly,
bool  forceDisconnect = false 
)
protected

Disconnects current node from mesh network. It is recommended to check isDisconnecting() and isConnected() methods after calling this method. But do not forget, that this method may not immediately disconnect node, because it has to send some remaining packets. That's why it is not recommended to create while loop, where isDisconnecting() and isConnected() will be checked without calling handle() method.

Disconnection steps

  1. Removing packets created by current node for network from waitingFIFO or outFIFO. isDisconnecting() and isConnected() will return true.
  2. Disconnect packet is created and pushed to outFIFO.
  3. Sending all packets from outFIFO for network until timeout MESH_DISCONNECT_TIMEOUT.
  4. After timeout, or when outFIFO is clear, node is definitely disconnected. isDisconnecting() and isConnected() will return false here.
    Parameters
    reasonDisconnect reason;
    doNotDisconnectImmediatellyIf there is possibility to disconnect node immediately, don't do it.
    forceDisconnectTrue to force immediately disconnect from network.
    Returns
    Returns true if disconnect started or node was immediately disconnected.

◆ end()

bool MeshNet::end ( )
virtual

Disables mesh node. It is recommended to disconnect from network before calling this method, because some packets for another nodes can be lost. If node won't be disconnected before calling this method, it will be disconnected forcibly.

Reimplemented in MeshNetGateway.

◆ getConnectionState()

MeshConnectionState MeshNet::getConnectionState ( ) const
inline

Gets connection state of current node.

Returns
Returns connection state of current node.

◆ getInstances()

static MeshNet** MeshNet::getInstances ( )
inlinestatic

Gets array of all created MeshNet instances.

Returns
Returns pointer to array of all created MeshNet instances.

◆ getLastID()

uint8_t MeshNet::getLastID ( )
inlineprotected

Gets last generated ID.

Returns
Returns ID.

◆ getLostDataPacketsCnt()

uint32_t MeshNet::getLostDataPacketsCnt ( ) const
inline

Gets count of lost data packets created by current node for current network. This count does not include packets, that were lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout (see getLostRemoteDataPacketsCnt()). This value includes only data packets. This value does not include count of lost packets, that are not for current network. This value is reset when end(), clear() or resetStatistics() is called.

◆ getLostFramesInNetworkCnt()

uint32_t MeshNet::getLostFramesInNetworkCnt ( ) const
inline

Gets count of lost frames for current network. Frame is marked as lost, when attempt to send false, because of radio error or carriage sense detected interference. Frame is also marked as lost, when it need to be acknowledged, but ACK was not received. This value does not include count of lost frames, that are not for current network. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected.

◆ getLostFramesTotalCnt()

uint32_t MeshNet::getLostFramesTotalCnt ( ) const
inline

Gets total count of lost frames. Frame is marked as lost, when attempt to send false, because of radio error or carriage sense detected interference. Frame is also marked as lost, when it need to be acknowledged, but ACK was not received. This value also includes frames for current network (see getLostFramesInNetworkCnt()). This value is reset when end(), clear() or resetStatistics() is called.

◆ getLostPacketsInNetworkCnt()

uint32_t MeshNet::getLostPacketsInNetworkCnt ( ) const
inline

Gets count of lost packets created by current node for current network. This count does not include packets, that were lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout (see getLostRemotePacketsCnt()). This value also includes lost data packets, not only system packets. This value does not include count of lost packets, that are not for current network. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected.

◆ getLostPacketsTotalCnt()

uint32_t MeshNet::getLostPacketsTotalCnt ( ) const
inline

Gets total count of lost packets created by current node. This count does not include packet, that was lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout (see getLostRemotePacketsCnt()). This value also includes lost data packets, not only system packets. This value also includes packets for current network (see getLostPacketsTotalCnt()). This value is reset when end(), clear() or resetStatistics() is called.

◆ getLostRelayiedPacketsCnt()

uint32_t MeshNet::getLostRelayiedPacketsCnt ( ) const
inline

Gets count of lost relayed packets in current node (packets, that were not created by current node). This value also includes data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called.

◆ getLostRemoteDataPacketsCnt()

uint32_t MeshNet::getLostRemoteDataPacketsCnt ( ) const
inline

Gets total count of lost data packets outside of current node created by current node. This value includes only packet, that was lost outside of node and were marked as data packets, for example when response to packet marked with ACK-R was not received until specified timeout. To get total lost packets use this formula: getLostPacketsTotalCnt() + getLostRemotePacketsCnt(). This value is reset when end(), clear() or resetStatistics() is called.

◆ getLostRemotePacketsCnt()

uint32_t MeshNet::getLostRemotePacketsCnt ( ) const
inline

Gets total count of lost packets outside of current node created by current node. This value includes only packet, that was lost outside of node, for example when response to packet (marked with ACK-R or system packet which need response) was not received until specified timeout. To get total lost packets use this formula: getLostPacketsTotalCnt() + getLostRemotePacketsCnt(). This value also includes lost data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called.

◆ getMaxChannel()

uint8_t MeshNet::getMaxChannel ( )
inline

Get maximum channel number, that can be set using setChannel() method.

◆ getMinChannel()

uint8_t MeshNet::getMinChannel ( )
inline

Get minimum channel number, that can be set using setChannel() method.

◆ getNeighborNode()

uint8_t MeshNet::getNeighborNode ( uint8_t  address) const
inline

Gets address of neighbor node, which is next node in path.

Parameters
addressDestination address - address of node at the end of path.
Returns
Returns address of next node or UNKNOWN_MESH_ADDRESS (253) if no path exists.

◆ getNetworkBSSID()

MeshMAC MeshNet::getNetworkBSSID ( ) const
inline

Gets BSSID of network, the node is connected to.

Returns
Returns BSSID of network, the node is connected to or current node MAC when node is disconnected or node is gateway.

◆ getNewID()

uint8_t MeshNet::getNewID ( )
inlineprotected

Generates new ID for packet.

Returns
Returns generated ID.

◆ getNodeAddress()

uint8_t MeshNet::getNodeAddress ( ) const
inline

Gets address of current node. If node is not connected to any network, 253 is returned.

Parameters
Returnsaddress of current node.

◆ getNodeMAC()

MeshMAC MeshNet::getNodeMAC ( ) const
inline

Gets current node unique MAC address.

Returns
Returns current node unique MAC address.

◆ getPacketStatus()

MeshPacketStatus MeshNet::getPacketStatus ( uint8_t  ID) const

Tries to check, where is packet, that was sent by it's ID.

Parameters
IDID of packet created by current node to check.
Returns
Returns in which buffer is packet located or if it was sent, but acknowledgment by destination node was not received yet.

◆ getRadioInterfacePtr()

RFInterface* MeshNet::getRadioInterfacePtr ( ) const
inline

Gets pointer to radio interface.

◆ getRelayiedPacketsCnt()

uint32_t MeshNet::getRelayiedPacketsCnt ( ) const
inline

Gets count of successfully relayed packets (packets, that were not created by current node). This value also includes data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called.

◆ getSentDataPacketsCnt()

uint32_t MeshNet::getSentDataPacketsCnt ( ) const
inline

Gets count of successfully sent data packets created by current node for current network. This value also includes packets, that was lost outside of this node (see getLostRemoteDataPacketsCnt()). This value also includes only data packets. This value is reset when end(), clear() or resetStatistics() is called.

◆ getSentFramesInNetworkCnt()

uint32_t MeshNet::getSentFramesInNetworkCnt ( ) const
inline

Gets total count of successfully sent frames. Frame is successfully sent, when send was successful and frame was acknowledged when ACK was needed. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected.

◆ getSentFramesTotalCnt()

uint32_t MeshNet::getSentFramesTotalCnt ( ) const
inline

Gets total count of successfully sent frames. Frame is successfully sent, when send was successful and frame was acknowledged when ACK was needed. This value also includes frames for current network (see getSentFramesInNetworkCnt()). This value is reset when end(), clear() or resetStatistics() is called.

◆ getSentPacketsInNetworkCnt()

uint32_t MeshNet::getSentPacketsInNetworkCnt ( ) const
inline

Gets count of successfully sent packets created by current node for current network. This value also includes packets, that was lost outside of this node (see getLostRemotePacketsCnt()). This value also includes sent data packets, not only system packets. This value is reset when end(), clear() or resetStatistics() is called or node is disconnected.

◆ getSentPacketsTotalCnt()

uint32_t MeshNet::getSentPacketsTotalCnt ( ) const
inline

Gets total count of successfully sent packets created by current node. This value also includes packets, that was lost outside of this node (see getLostRemotePacketsCnt()). This value also includes sent data packets, not only system packets. This value also includes packets for current network (see getSentPacketsInNetworkCnt()). This value is reset when end(), clear() or resetStatistics() is called.

◆ handle()

void MeshNet::handle ( )
virtual

This method has to be called in main program loop as often as possible.

Reimplemented in MeshNetGateway.

◆ handleReceivedInterrupt()

void MeshNet::handleReceivedInterrupt ( )
protected

◆ isBackupGateway()

bool MeshNet::isBackupGateway ( ) const
inline

Checks if node is backup gateway of network. Only main gateway can manage network. Other nodes, which are marked as gateway, but are connected to network are backup gateways. Those nodes acts as normal node, but when main gateway is lost, one of backup nodes will act as gateway.

◆ isConnected()

bool MeshNet::isConnected ( ) const
inline

Checks if node is connected to any network.

Returns
Returns true when node is connected to any network.

◆ isDisconnecting()

bool MeshNet::isDisconnecting ( ) const
inline

Checks if node is disconnecting right now. Node is finally disconnected after disconnect timeout or when no packet for that network is stored in some FIFO on current node.

◆ isForeignNetworkPacket()

bool MeshNet::isForeignNetworkPacket ( const MeshPacket packet,
MeshMAC  bssid 
)
staticprotected

Checks if packet is for current network (with specified BSSID in BSSID parameter) or not.

Parameters
[in]packetPacket to check.
bssidNetwork BSSID to check.
Returns
Returns true if packet is for foreign network.

◆ isMainGateway()

bool MeshNet::isMainGateway ( ) const
inline

Checks if node is main gateway of network. Only main gateway can manage network. Other nodes, which are marked as gateway, but are connected to network are backup gateways.

◆ netScanRunning()

bool MeshNet::netScanRunning ( ) const
inline

Checks if network scan is running.

◆ onBufferPacketLost()

void MeshNet::onBufferPacketLost ( const MeshPacket packet,
MeshPacketError  error 
)
protected

This method is called when some packet created by this node was lost, because some FIFO, where it has to be stored is full or it was removed from FIFO. This method does some clearing process (clears OIDT row of current packet if exists) and reports error if packet was created by current node.

Parameters
indexIndex of row, where new path is located.
packetReference to packet, which will be lost.
errorError code indicating, why packet was lost.

◆ onBufferPacketRemove()

void MeshNet::onBufferPacketRemove ( const MeshPacket packet,
bool  ignoreCurrentNetworkPacket,
bool  packetLost 
)
protected

This method is called when any packet is removed from waitingFIFO or outFIFO.

Parameters
packetPacket to be removed.
ignoreCurrentNetworkPacketWhen true, currentNetworkPacket cannot be changed. This can be set
packetLostTrue if packet was lost. to true only in special cases.

◆ onFrameReceive()

void MeshNet::onFrameReceive ( MeshPacketBuilder builder,
MeshPacketBuilderStatus  status,
const MeshFrameHeader frameHeader,
const uint8_t *  frameData,
uint8_t  frameDataSize,
int8_t  rssi 
)
protected

Method, which is called, when new valid frame is received. This method is used to calculate CTS time.

◆ onFrameReceiveStatic()

void MeshNet::onFrameReceiveStatic ( MeshPacketBuilder builder,
MeshPacketBuilderStatus  status,
const MeshFrameHeader frameHeader,
const uint8_t *  frameData,
uint8_t  frameDataSize,
int8_t  rssi 
)
staticprotected

Processed received messages.

Static function, which can be used as callback. In this function correct onFrameReceive() method is called.

◆ onNewPath()

void MeshNet::onNewPath ( int16_t  index,
const MeshRouteTableRow row 
)
protected

This method is called when new path was found (created). It is not called if path is prolonged.

Parameters
indexIndex of row, where new path is located.
rowRow, which contains path informations from route table.

◆ onNewPathStatic()

void MeshNet::onNewPathStatic ( MeshRouteTable< ROUTETABLE_SIZE > *  table,
int16_t  index,
const MeshRouteTableRow row,
uint8_t  rawLifeTime 
)
staticprotected

Static function, which can be used as callback. In this function correct onNewPath() method is called.

◆ onNodeLost()

void MeshNet::onNodeLost ( uint8_t  address,
bool  nodeLostForever 
)
protectedvirtual

This method is called, when some node is disconnected from network or does not responds to sent packet.

Parameters
addressAddress of lost node.
nodeLostForeverTrue when node was lost forever. This has to be set to true if node was disconnected from network.

Reimplemented in MeshNetGateway.

◆ onOIDTRemove()

void MeshNet::onOIDTRemove ( int16_t  index,
const MeshOIDTableRow oldRow,
uint8_t  oldRawLifeTime,
MeshOIDTableRemoveReason  reason 
)
protectedvirtual

This method is called when any row from OID table is removed.

Parameters
indexIndex of removed row.
oldRowOld row.
oldRawLifeTimeOld raw life time of row.
reasonRemove reason.

◆ onOIDTRemoveStatic()

void MeshNet::onOIDTRemoveStatic ( MeshOIDTable< OIDTABLE_SIZE > *  table,
int16_t  index,
const MeshOIDTableRow oldRow,
uint8_t  oldRawLifeTime,
MeshOIDTableRemoveReason  reason 
)
staticprotected

Static function, which can be used as callback. In this function correct onOIDTRemove() method is called.

◆ onPacketError()

void MeshNet::onPacketError ( MeshPacketError  error,
uint8_t  packetID,
uint8_t  packetDest,
SystemPacketType  packetType,
const MeshPacket packet_ptr 
)
protectedvirtual

This method is called when some error happened to any packet created by current node.

Parameters
errorType of error that happened.
packetIDID of packet.
packetDestDestination address of packet.
packetTypeType of packet.
packet_ptrPointer to packet, this may be NULL.

Reimplemented in MeshNetGateway.

◆ onSystemDisconnect()

void MeshNet::onSystemDisconnect ( MeshDisconnectReason  reason)
protected

Do necessary work after node was disconnected or connection was aborted. onDisconnected method is called here.

Parameters
reasonDisconnect reason.

◆ onSystemPingReceived()

void MeshNet::onSystemPingReceived ( bool  valid,
uint32_t  duration 
)
protected

This method is called when system ping packet response was received.

Parameters
validTrue if ping response was valid.
durationPing duration in milliseconds.

◆ packetSplitting()

bool MeshNet::packetSplitting ( )
inlineprotected

Checks if some packet is loaded in packet splitter.

◆ PacketToFrame()

bool MeshNet::PacketToFrame ( const MeshPacket packet,
MeshMAC  bssid,
uint8_t *  outBuffer,
uint8_t &  bufferSize 
) const
protected

Converts packet to frame. This can be called only if you are sure, that this packet won't be splitted to multiple frames, but will be converted to only one frame. Routed packets (ROE == 1 && RE == 1) cannot be converted.

Parameters
[in]packetACK packet, that has to be splitted. This condition has to be valid: ackPackets.Length() <= 11.
bssidBSSID of packet sender.
[out]dataBuffer reserved for frame data. Size of this buffer has to be at least 24 bytes.
[out]dataSizeThe size of data copied to data buffer.
Returns
True packet was successfully converted to frame. False if packet have error or is Routed packet (ROE == 1 && RE == 1) or packet length exceeded.

◆ packetTransmitting()

bool MeshNet::packetTransmitting ( )
inlineprotected

Checks if some frame of currently splitting packet has been already transmitted.

◆ pathCreating()

bool MeshNet::pathCreating ( uint8_t  address) const
inline

Checks if path to specified node is creating right now.

Parameters
addressAddress of node, to which path has to be checked.
Returns
Returns true if path to specified node is creating right now.

◆ pathExists()

bool MeshNet::pathExists ( uint8_t  address) const
inline

Checks if path to specified node exists.

Parameters
addressAddress of node, to which path has to be checked.
Returns
Returns true if path to specified node exists.

◆ ping()

int16_t MeshNet::ping ( uint8_t  addr,
uint32_t  timeout,
int16_t  testDataLength = 0 
)

Sends ping packet to node with specified address. When ping response is received, callback function set using setOnPingResponseCallback() is called. This is also called, when ping timed out.

Parameters
addrAddress of node, the ping packet is for.
timeoutPing timeout value in milliseconds. Minimum value, that can be set is 1 second (1000ms). Error of timeout is +0ms, -500ms.
testDataLengthLength of test data sent with ping packet. Those data are randomly generated. Allowed values: 0-500.
Returns
ID of ping packet is returned, or: Returns:
  • ID of ping packet when ping was successfully sent.
  • MPE_Full_outFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Full_waitingFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Invalid when address is invalid.
  • MPE_NoRoute when route creation to destination has failed.
  • MPE_NoNetwork when node is not connected to any network.
  • MPE_GenErr when node is pinged itself.
  • MPE_AllocErr when ping packet cannot be constructed.

◆ printFIDTable()

bool MeshNet::printFIDTable ( OSTREAM stream) const

Prints FID Table in pretty format to stream.

Parameters
streamOutput stream where to print.
Returns
Returns true if stream was not NULL.

◆ printIDTable()

bool MeshNet::printIDTable ( OSTREAM stream) const

Prints ID Table in pretty format to stream.

Parameters
streamOutput stream where to print.
Returns
Returns true if stream was not NULL.

◆ printMeshConnectionState()

size_t MeshNet::printMeshConnectionState ( OSTREAM stream,
MeshConnectionState  value 
)
static

Prints MeshConnectionState to stream.

Parameters
streamWhere to print.
valueValue to print.
Returns
Returns count of printed characters.

◆ printMeshDisconnectReason()

size_t MeshNet::printMeshDisconnectReason ( OSTREAM stream,
MeshDisconnectReason  value 
)
static

Prints MeshDisconnectReason to stream.

Parameters
streamWhere to print.
valueValue to print.
Returns
Returns count of printed characters.

◆ printMeshNetworkInfo()

size_t MeshNet::printMeshNetworkInfo ( OSTREAM stream) const

Prints informations about network, node is connected to.

Parameters
streamStream where to print.
Returns
Returns count of printed characters.

◆ printMeshPacketError()

size_t MeshNet::printMeshPacketError ( OSTREAM stream,
MeshPacketError  value 
)
static

Prints MeshPacketError to stream.

Parameters
streamWhere to print.
valueValue to print.
Returns
Returns count of printed characters.

◆ printOIDTable()

bool MeshNet::printOIDTable ( OSTREAM stream) const

Prints OID Table in pretty format to stream.

Parameters
streamOutput stream where to print.
Returns
Returns true if stream was not NULL.

◆ printOutFIFO()

bool MeshNet::printOutFIFO ( OSTREAM stream) const

Prints output FIFO buffer in pretty format to stream.

Parameters
streamOutput stream where to print.
Returns
Returns true if stream was not NULL.

◆ printRTable()

bool MeshNet::printRTable ( OSTREAM stream) const

Prints Route Table in pretty format to stream.

Parameters
streamOutput stream where to print.
Returns
Returns true if stream was not NULL.

◆ printStatistics()

size_t MeshNet::printStatistics ( OSTREAM stream) const

Prints statistics informations.

Parameters
streamStream where to print.
Returns
Returns count of printed characters.

◆ printWaitingFIFO()

bool MeshNet::printWaitingFIFO ( OSTREAM stream) const

Prints waiting FIFO buffer in pretty format to stream.

Parameters
streamOutput stream where to print.
Returns
Returns true if stream was not NULL.

◆ processPacket()

void MeshNet::processPacket ( MeshPacket packet,
MeshMAC  BSSID 
)
protectedvirtual

Processes received packet. Called in processReceived() method.

Parameters
packetReference to received packet.
BSSIDBSSID of network, which sent packet.

Reimplemented in MeshNetGateway.

◆ processReceived()

void MeshNet::processReceived ( )
protected

Processes received frames.

◆ processTransmit()

void MeshNet::processTransmit ( )
protected

Processes transmission of one frame from output FIFO.

◆ pushOutPacket()

MeshPacketError MeshNet::pushOutPacket ( MeshPacket packet,
uint32_t  timeout = 0 
)
protected

Pushes packet to output FIFO buffer.

Autofill fields

Those fields should not be set before calling this method, because they are set in this method.

  • ID field is automatically set in this method, so it shouldn't be set before calling this method. ID is generated using getNewID() method. If packet cannot be pushed, new packet ID won't be generated. ID is also not generated, if packet is relaying and current node is not source node (source != from). To get ID of created (not relayed) packet, use getLastID() method.
  • To field is automatically set in this method, so it shouldn't be set before calling this method. Route table is used to fill this field. If path to destination address cannot be found, packet is stored in waitingFIFO and createPath method is called.

FIFO selection

This methods makes decision, where packet will be pushed. If path to packet destination can be found or is not needed, packet is pushed to the outFIFO, where it waits until it will be sent. If path to packet destination cannot be found, packet is pushed to the waitingFIFO, where packet will wait until path is created. If path is successfully created, all related packets from waitingFIFO will be moved to the outFIFO.

Warning
After calling this method and method returns true, packet will be cleared, else packet stays unchanged.
Parameters
packetPacket to push.
timeoutPacket timeout in milliseconds. Value resolution is 500ms, that's why timeout error is (+0ms, -500ms) and that's why it is recommended to set at least 1 second. Maximum value is 127500 milliseconds, which is more than 2 minutes. If 0 is set, packet is not set to OIDTable. After this timeout packet is removed from OIDTable and from waiting or output FIFO buffer. Timeout is ignored (timeout = 0) if packet was not created, but only relayed.
Returns
Returns:
  • MPE_OK when packet was successfully pushed.
  • MPE_Full_outFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Full_waitingFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Invalid when packet is invalid or has zero length payload.
  • MPE_NoRoute when route creation to destination has failed.
  • MPE_NoNetwork when packet with RE == 1 was tried to push, but node is not connected to any network.

◆ removeThisFromInstArr()

void MeshNet::removeThisFromInstArr ( )
private

Removes this instance from instances array. This method has to be called in destructor.

◆ resetStatistics()

void MeshNet::resetStatistics ( )

Resets statistics data.

◆ restartCurrentPacketTransmission() [1/2]

void MeshNet::restartCurrentPacketTransmission ( )
inlineprotected

Restarts transmission of current packet. Splitting is restarted.

◆ restartCurrentPacketTransmission() [2/2]

void MeshNet::restartCurrentPacketTransmission ( uint8_t  maxFrameSize)
inlineprotected

Restarts transmission of current packet. Splitting is restarted.

Parameters
maxFrameSizeNew max frame size for packet splitter.

◆ routeTableUpdate()

void MeshNet::routeTableUpdate ( const MeshPacketHeader header,
MeshMAC  BSSID,
int8_t  rssi 
)
protectedvirtual

Updates route table when valid packet from node with same network is received.ň

Parameters
headerHeader of received packet.
BSSIDBSSID of received packet.
rssiRSSI of first packet frame.
Note
This is called in checkPacket() method.

Reimplemented in MeshNetGateway.

◆ send() [1/3]

int16_t MeshNet::send ( uint8_t  addr,
const MeshVariableArray< uint8_t > &  data 
)

Sends data packet to specified node.

Note
It is recommended to check availablePacketsToSend() method before calling send method. If availablePacketsToSend() returns more than 1, send method can be used.
Parameters
addrAddress of node, where to send message.
[in]dataData, that will be sent. To achieve better performance, use std::move.
Returns
Returns ID of sent packet, it can be used to track packet or -1 when packet was not sent. Returns:
  • ID of sent packet on success.
  • MPE_Full_outFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Full_waitingFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Invalid when address or payload size is invalid.
  • MPE_NoRoute when route creation to destination has failed.
  • MPE_NoNetwork when node is not connected to any network.
  • MPE_AllocErr when packet cannot be constructed.
Note
Packet can be sent only if current node is connected to any network or is main gateway node.

◆ send() [2/3]

int16_t MeshNet::send ( uint8_t  addr,
const uint8_t *  data,
uint16_t  dataSize 
)

Sends data packet to specified node.

Note
It is recommended to check availablePacketsToSend() method before calling send method. If availablePacketsToSend() returns more than 1, send method can be used.
Parameters
addrAddress of node, where to send message.
dataData, that will be sent.
dataSizeSize of data to be sent in bytes.
Returns
Returns ID of sent packet, it can be used to track packet or -1 when packet was not sent. Returns:
  • ID of sent packet on success.
  • MPE_Full_outFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Full_waitingFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Invalid when address or payload size is invalid.
  • MPE_NoRoute when route creation to destination has failed.
  • MPE_NoNetwork when node is not connected to any network.
  • MPE_AllocErr when packet cannot be constructed.
Note
Packet can be sent only if current node is connected to any network or is main gateway node.

◆ send() [3/3]

int16_t MeshNet::send ( uint8_t  addr,
MeshVariableArray< uint8_t > &&  data 
)

Sends data packet to specified node.

Note
It is recommended to check availablePacketsToSend() method before calling send method. If availablePacketsToSend() returns more than 1, send method can be used.
Parameters
addrAddress of node, where to send message.
[in]dataData, that will be sent. Those data will be cleared when send was successful, because std::move is used, which has incredible performance compared to copying data.
Returns
Returns ID of sent packet, it can be used to track packet or -1 when packet was not sent. Returns:
  • ID of sent packet on success.
  • MPE_Full_outFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Full_waitingFIFO when outFIFO is full and packet cannot be pushed.
  • MPE_Invalid when address or payload size is invalid.
  • MPE_NoRoute when route creation to destination has failed.
  • MPE_NoNetwork when node is not connected to any network.
  • MPE_AllocErr when packet cannot be constructed.
Note
Packet can be sent only if current node is connected to any network or is main gateway node.

◆ sendACK()

bool MeshNet::sendACK ( const MeshACKSetup setup,
bool  asDisconnected = false,
bool  asConnectedToOld = false 
)
protected

Sends ACK to last received frame. This has to be done when builder returns status MPB_FullPacketOK or MPB_PartPacketOK.

Parameters
setupStructure, which has data needed for ACK packet creation.
asDisconnectedSend packet as disconnected node (BSSID = NodeMAC and Source == 253)
asConnectedToOldSend packet as connected to old network (BSSID = oldBSSID and Source == oldNodeAddress)
Returns
Returns true when ACK was sent or don't need to be sent.

◆ sendDisconnectPacket()

bool MeshNet::sendDisconnectPacket ( MeshNetDisconnectPacketType  type)
protected

Immediately sends disconnect packet (without pushing to outFIFO), that says current node is disconnecting. OnSystemDisconnect() method is not called here.

Parameters
typeDisconnect type.
Returns
Returns true if disconnect packet was successfully sent.

◆ sendERR_ACK()

bool MeshNet::sendERR_ACK ( const MeshACKSetup setup,
ERR_ACK_ErrorCode  ErrorCode,
uint8_t  RepairValue,
bool  asDisconnected = false,
bool  asConnectedToOld = false 
)
protected

Sends ERROR ACK to last received frame. This has to be done when some error happened to last received frame.

Parameters
setupStructure, which has data needed for ACK packet creation.
ErrorCodeError code.
RepairValueValue, which can be used for repairing this error.
asDisconnectedSend packet as disconnected node (BSSID = NodeMAC and Source == 253)
asConnectedToOldSend packet as connected to old network (BSSID = oldBSSID and Source == oldNodeAddress)
Returns
Returns true when ACK was sent or don't need to be sent.

◆ SendPacketAsFrame()

bool MeshNet::SendPacketAsFrame ( MeshPacket packet,
MeshMAC  bssid 
)
protected

Sends packet, which is converted using method PacketToFrame() to frame, which is then sends. Packet is cleared after sending. Only packets, that won't be splitted to multiple frames will be sent, else false is returned. Packet ID is automatically generated here, same as using pushOutPacket() method, also From field is filled by current node address if needed.

Note
This packet cannot be acknowledged.
Parameters
packet[in]Packet to send. Packet is never cleared.
bssidBSSID of current network.
Returns
Returns true if packet was sent without error.

◆ setAutoConnect()

void MeshNet::setAutoConnect ( MeshMAC  netBSSID,
uint32_t  retryInterval = 60000 
)

Enables auto connect to specified network. If auto connect is enabled and node is not connected to any network, it tries to connect to network, which BSSID is specified in parameter. If network is not found, connection is retried after time specified in retryInterval parameter.

Auto connection is disabled when:

  • node is disconnected from that network using disconnect() method,
  • node is disconnected, because disconnect request was received,
  • node connection is refused,
  • end() method is called,
  • disableAutoConnect() is called.
Parameters
netBSSIDBSSID of network, the node has to connect to.
retryIntervalAuto connect retry interval in milliseconds. Minimum value is 10000ms.

◆ setChannel()

bool MeshNet::setChannel ( uint8_t  channel_)

Sets network channel.

Parameters
channel_Channel to set. This value has to be between or same as getMinChannel() and getMaxChannel() values.
returnReturn true if channel was set.

◆ setOnConnectedCallback()

void MeshNet::setOnConnectedCallback ( void(*)(MeshNet *)  callback)
inline

Sets callback function, which is called when current node is connected to network.

Parameters
callbackCallback function.

◆ setOnDisconnectedCallback()

void MeshNet::setOnDisconnectedCallback ( void(*)(MeshNet *, MeshDisconnectReason, MeshMAC, uint8_t)  callback)
inline

Sets callback function, which is called when current node is disconnected from network or when connection to network was aborted.

Parameters
callbackCallback function.

Parameters

  • MeshNet - Pointer to MeshNet.
  • MeshDisconnectReason - Disconnect reason
  • MeshMAC - Old network BSSID. Invalid if node was not connected yet.
  • uint8_t - Old node address. Set to UNKNOWN_MESH_ADDRESS if node was not connected yet.

◆ setOnPacketErrorCallback()

void MeshNet::setOnPacketErrorCallback ( void(*)(MeshNet *, MeshPacketError, uint8_t, uint8_t, const MeshPacket *)  callback)
inline

Sets callback function, which is called when packet timeout happened and packet is removed.

Parameters
callbackCallback function.

Parameters

  • MeshNet - Pointer to MeshNet.
  • MeshPacketError - Mesh packet error type.
  • uint8_t - ID of packet, which timed out.
  • uint8_t - Address of destination node, which has to receive node. If node is not specified, UNKNOWN_MESH_ADDRESS is set.
  • MeshPacket - Pointer to packet, which timed out. If packet does not exists, NULL is returned.

◆ setOnPingResponseCallback()

void MeshNet::setOnPingResponseCallback ( void(*)(MeshNet *, uint8_t, uint8_t, MeshPacketError, uint8_t, uint32_t, const uint8_t *, int16_t)  callback)
inline

Sets callback function, which is called when ping response is received, or when ping timed out.

Parameters
callbackCallback function.

Parameters

  • MeshNet - Pointer to MeshNet.
  • uint8_t - ID of ping packet.
  • uint8_t - Address of node, which has been pinged.
  • MeshPacketError - Error which happened to ping packet.
  • uint8_t - Response packet hops.
  • uint32_t - Duration in milliseconds
  • const uint8_t - Pointer to test data. This can be NULL.
  • int16_t - Size of test data in bytes.

◆ setOnReceive()

void MeshNet::setOnReceive ( void(*)(MeshNet *, MeshPacket &)  callback)
inline

Sets callback function, which is called when data packet is received.

Parameters
callbackCallback function.

Parameters

  • MeshNet - Pointer to MeshNet.
  • MeshPacket - Reference to received packet. This packet is not marked with const, to make possible to use std::move on this packet.

◆ setOnRemoteNodeDisconnectedCallback()

void MeshNet::setOnRemoteNodeDisconnectedCallback ( void(*)(MeshNet *, uint8_t)  callback)
inline

This method is called when some node (not current node) is disconnected from network.

Parameters

  • MeshNet - Pointer to MeshNet.
  • uint8_t - Address of disconnected node.

◆ startNetScan() [1/2]

bool MeshNet::startNetScan ( void(*)(MeshNet *, const MeshNetScanResult &)  responseCallback,
uint32_t  timeout,
MeshNetScanFlags  flags,
MeshMAC  ResponderBSSID = 0 
)

Starts asynchronous network scanning. This function cannot be called when scan is actually running.

Parameters
responseCallbackFunction, that is called when some node responded to scan request.
timeoutTimeout in milliseconds. After this time, all scan responses are ignored. Min: 500ms, max: 10000ms, recommended: 2000ms.
flagsScan request flags.
ResponderBSSIDThis parameter is optional and when is specified, only nodes connected to network same as ResponserBSSID can respond.
Returns
Returns true when network scan has started.

◆ startNetScan() [2/2]

bool MeshNet::startNetScan ( void(*)(MeshNet *, const MeshNetScanResult &)  responseCallback,
uint32_t  timeout = 2000 
)

Starts asynchronous network scanning. This function cannot be called when scan is actually running.

Parameters
responseCallbackFunction, that is called when some node responded to scan request.
timeoutTimeout in milliseconds. After this time, all scan responses are ignored. Min: 500ms, max: 10000ms, recommended: 2000ms.
Returns
Returns true when network scan has started.

◆ systemNetworkScan()

bool MeshNet::systemNetworkScan ( MeshMAC  responderBSSID,
MeshNetScanFlags  flags 
)
protected

Perform network scan invoked by system before connecting to any network. This can be done only when no other scan is running right now and only if node is disconnected.

Parameters
responderBSSIDBSSID of network, which nodes has to respond to scan request.
flagsScan flags.
Returns
Returns true when system scan was started.

◆ systemPing()

bool MeshNet::systemPing ( uint8_t  addr,
uint32_t  timeout 
)
protected

Sends ping packet to node with specified address. When ping response is received, onSystemPingReceived() is called. This is also called, when ping timed out. This can be called only once.

Parameters
addrAddress of node, the ping packet is for.
timeoutPing timeout value in milliseconds. Minimum value, that can be set is 1 second (1000ms). Error of timeout is +0ms, -500ms.
testDataLengthLength of test data sent with ping packet. Those data are randomly generated. Allowed values: 0-500.
Returns
True if ping was started, false if error happened. If node pings itself, true is returned.

Field Documentation

◆ AddrPriv

uint8_t MeshNet::AddrPriv = UNKNOWN_MESH_ADDRESS
protected

Address of current node. Can be between 0 - 250 or 254 when disconnected.

◆ AddrReservationTime

uint16_t MeshNet::AddrReservationTime = 0
protected

Time in minutes the address can be reserved for in DHCP table in main gateway. This value is obtained during connection and it cannot change when connected to network.

◆ AddrReservedUntil

uint32_t MeshNet::AddrReservedUntil = 0
protected

Time in milliseconds until which address of current node is for sure reserved in main gateway node's DHCP table. Address reservation in DHCP table is prolonged, when gateway receives any packet from current node.

◆ autoConnectBSSID

MeshMAC MeshNet::autoConnectBSSID
protected

BSSID of network, this node has to automatically connect to.

◆ autoConnectInterval

uint32_t MeshNet::autoConnectInterval = 0
protected

Auto connect interval in milliseconds.

◆ beginCalled

bool MeshNet::beginCalled
protected

True if begin was called.

◆ canBeGateway_

const bool MeshNet::canBeGateway_
protected

True if current node can be used as gateway.

◆ channel

uint8_t MeshNet::channel
protected

Channel number, that will be set or is set.

◆ connectionState

MeshConnectionState MeshNet::connectionState = MeshConnectionState::MeshDisconnected
protected

Connection state of current node.

◆ connectionStepTime

uint32_t MeshNet::connectionStepTime = 0
protected

Time in milliseconds, when connection state was last changed.

◆ CTS_until

uint64_t MeshNet::CTS_until = 0
protected

Clear to send until this time in microseconds, so node cannot send frames until this time. ACK packets have exception from this rule.

◆ currentNetworkPackets

uint8_t MeshNet::currentNetworkPackets = 0
protected

Count of packets in buffers, that belongs to the current connected network.

◆ disconnectUntil

uint32_t MeshNet::disconnectUntil = 0
protected

Until this time in milliseconds node has to be disconnected.

◆ FIDTable

MeshFIDTable<FIDTABLE_SIZE> MeshNet::FIDTable
protected

@breif Table of received packets ID (ID+Source+BSSID) from foreign networks. This check, if some packet has been received multiple times.

◆ frameTranCnt

uint8_t MeshNet::frameTranCnt = 0
protected

(Re)Transmission count of last sent frame.

◆ IDTable

MeshIDTable<IDTABLE_SIZE> MeshNet::IDTable
protected

Table of received packets ID (ID+Source). This check, if some packet has been received multiple times.

◆ ignoreRSSIThreshold

bool MeshNet::ignoreRSSIThreshold
protected

True to ignore RSSI threshold on received network scan responses during scan.

◆ instances

MeshNet * MeshNet::instances = { 0 }
staticprivate

Array of all created MeshNet instances. Thanks to this array callback functions of MicroTable, PacketSplitter and PacketBuilder classes can be set. If this array is full. New created instances will not work correctly.

◆ instCount

uint8_t MeshNet::instCount = 0
staticprivate

Count of created instances of this class.

◆ lastDisconnectReason

MeshDisconnectReason MeshNet::lastDisconnectReason = MeshDisconnectReason::MDR_None
protected

Last disconnect or connection fail reason.

◆ lastReceiveTime

uint64_t MeshNet::lastReceiveTime = 0
protected

Time when last frame was received in microseconds.

◆ lastScanResponderBSSID

MeshMAC MeshNet::lastScanResponderBSSID
protected

BSSID of network, the system network scan was assigned to.

◆ lastScanTime

uint32_t MeshNet::lastScanTime = 0
protected

Time in milliseconds, when network scan was last time executed.

◆ lastSentTime

uint32_t MeshNet::lastSentTime = 0
protected

Time, when was last frame sent in milliseconds.

◆ lostDataPackets

uint32_t MeshNet::lostDataPackets = 0
protected

◆ lostFramesInNetwork

uint32_t MeshNet::lostFramesInNetwork = 0
protected

◆ lostFramesTotal

uint32_t MeshNet::lostFramesTotal = 0
protected

◆ lostPacketsInNetwork

uint32_t MeshNet::lostPacketsInNetwork = 0
protected

◆ lostPacketsTotal

uint32_t MeshNet::lostPacketsTotal = 0
protected

◆ lostRelayiedPackets

uint32_t MeshNet::lostRelayiedPackets = 0
protected

◆ lostRemoteDataPackets

uint32_t MeshNet::lostRemoteDataPackets = 0
protected

◆ lostRemotePackets

uint32_t MeshNet::lostRemotePackets = 0
protected

◆ lowestHopsToGateway

uint8_t MeshNet::lowestHopsToGateway = 255
protected

The smallest count of hops to gateway established during last system network scan.

◆ lowestHopsToGateway_Addr

uint8_t MeshNet::lowestHopsToGateway_Addr = INVALID_MESH_ADDRESS
protected

Address of node with the smallest count of hops to gateway established during last system network scan.

◆ msgIDPriv

uint8_t MeshNet::msgIDPriv = 0xFF
private

Last value of packet ID.

◆ netScanResponseCallback

void(* MeshNet::netScanResponseCallback) (MeshNet *, const MeshNetScanResult &)
protected

Pointer to callback function called when network scan response was received.

◆ NetworkBSSID

MeshMAC MeshNet::NetworkBSSID
protected

If node is disconnected, this is same as NodeMAC, else NetworkBSSID equals BSSID address of connected network.

◆ nextAutoConnectTime

uint32_t MeshNet::nextAutoConnectTime = 0
protected

Time in milliseconds, when auto connection attempt will be invoked.

◆ NodeMAC

MeshMAC MeshNet::NodeMAC
protected

Unique node physical MeshMAC address.

◆ OIDTable

MeshOIDTable<OIDTABLE_SIZE> MeshNet::OIDTable
protected

Table of sent (output) packets ID and destination (source is current node address). Only packet, that was created by current node can be stored here, relayed packet cannot be stored here. This table is for checking, what action was done and what packet is expected (response or ACK-R response).

◆ oldBSSID

MeshMAC MeshNet::oldBSSID
protected

Old BSSID of network the node was connected to last time.

◆ oldNodeAddress

uint8_t MeshNet::oldNodeAddress = UNKNOWN_MESH_ADDRESS
protected

Old node address, that was assigned to node when it has been connected to some network.

◆ onConnected

void(* MeshNet::onConnected) (MeshNet *)
protected

This method is called when node is connected to network.

◆ onDisconnected

void(* MeshNet::onDisconnected) (MeshNet *, MeshDisconnectReason, MeshMAC, uint8_t)
protected

This method is called when node is disconnected from network.

Parameters

  • MeshNet - Pointer to MeshNet.
  • MeshDisconnectReason - Disconnect reason
  • MeshMAC - Old network BSSID. Invalid if node was not connected yet.
  • uint8_t - Old node address. Set to UNKNOWN_MESH_ADDRESS if node was not connected yet.

◆ onPacketErrorCallback

void(* MeshNet::onPacketErrorCallback) (MeshNet *, MeshPacketError, uint8_t, uint8_t, const MeshPacket *)
protected

Parameters

  • MeshNet - Pointer to MeshNet
  • MeshPacketError - Error type
  • uint8_t - ID of packet, with error.
  • uint8_t - Address of destination node, which has to receive node. If node is not specified, UNKNOWN_MESH_ADDRESS is set.
  • MeshPacket - Pointer to packet, with error. If packet does not exists, NULL is returned.

◆ onPingResponse

void(* MeshNet::onPingResponse) (MeshNet *, uint8_t, uint8_t, MeshPacketError, uint8_t, uint32_t, const uint8_t *, int16_t)
protected

Function called when ping response is received or when ping timed out.

Parameters

  • MeshNet - Pointer to MeshNet.
  • uint8_t - ID of ping packet.
  • uint8_t - Address of node, which has been pinged.
  • MeshPacketError - Error which happened to ping packet.
  • uint8_t - Response packet hops.
  • uint32_t - Duration in milliseconds
  • const uint8_t - Pointer to test data. This can be NULL.
  • int16_t - Size of test data in bytes.

◆ onReceive

void(* MeshNet::onReceive) (MeshNet *, MeshPacket &)
protected

Function called when data packet is received.

Parameters

◆ onRemDisconnected

void(* MeshNet::onRemDisconnected) (MeshNet *, uint8_t)
protected

This method is called when some node from network is disconnected.

Parameters

  • MeshNet - Pointer to MeshNet.
  • uint8_t - Address of disconnected node.

◆ outFIFO

Packets that waits in buffer to be sent.

◆ packetBuilder

MeshPacketBuilder MeshNet::packetBuilder
protected

Combines received MeshFrames to MeshPacket.

◆ packetSplitter

MeshPacketSplitter MeshNet::packetSplitter
protected

Splits MeshPacket to multiple MeshFrames for transmission.

◆ packetSplittingStarted

bool MeshNet::packetSplittingStarted
protected

True if packet splitting has started.

◆ receiveInterruptEnabled

bool MeshNet::receiveInterruptEnabled
protected

True if interrupt will be fired when new frame is received.

◆ relayiedPackets

uint32_t MeshNet::relayiedPackets = 0
protected

◆ rf

RFInterface* MeshNet::rf
protected

Pointer to radio interface, that is used by current class.

◆ RTable

MeshRouteTable<ROUTETABLE_SIZE> MeshNet::RTable
protected

Routing table.

◆ scanEndTime

uint32_t MeshNet::scanEndTime = 0
protected

Time in milliseconds, when network scan ends.

◆ sendingPacketIsForeign

bool MeshNet::sendingPacketIsForeign
protected

True if packet, that is loaded in packetSplitter is for foreign network.

◆ sentDataPackets

uint32_t MeshNet::sentDataPackets = 0
protected

◆ sentFramesInNetwork

uint32_t MeshNet::sentFramesInNetwork = 0
protected

◆ sentFramesTotal

uint32_t MeshNet::sentFramesTotal = 0
protected

◆ sentFrameWasACK

bool MeshNet::sentFrameWasACK
protected

True when sent frame was acknowledged.

◆ sentPacketsInNetwork

uint32_t MeshNet::sentPacketsInNetwork = 0
protected

◆ sentPacketsTotal

uint32_t MeshNet::sentPacketsTotal = 0
protected

◆ SSID

char MeshNet::SSID[65]
protected

SSID of network, node is connected to.

◆ systemPingID

int16_t MeshNet::systemPingID = -1
protected

ID of last system ping packet.

◆ Version

const MeshVersion MeshNet::Version = MESHNET_VERSION
static

Version of MeshNet protocol.

◆ waitingBufferCheck

bool MeshNet::waitingBufferCheck
protected

True if waitBuffer has to be checked and some packets has to be sent.

◆ waitingFIFO

MeshPacketFIFO<MESH_WFIFO_SIZE> MeshNet::waitingFIFO
protected

Packets, that has to be sent as routed packet, but path is not known yet.


The documentation for this class was generated from the following files: