MeshNet  1.0.0
Public Member Functions | Protected Member Functions
MeshNetGateway Class Reference

#include <meshNetGateway.h>

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

Public Member Functions

 MeshNetGateway ()
 
virtual bool begin (MeshMAC mac, RFInterface &RFI, const char *SSID_)
 Starts MeshNet instance as gateway for current node. More...
 
bool begin (MeshMAC mac, RFInterface &RFI) override
 This method cannot be used with gateway, that's why it always returns false. More...
 
bool begin () override
 Starts MeshNet gateway instance for current node with last setings. More...
 
bool end () override
 Disables mesh node. It is recommended to drop network before calling this method to get know to nodes, that they are no longer connected. If this node is main gateway, network is forcibly dropped. More...
 
bool dropNetwork (bool forced)
 Drops whole network, all nodes will be disconnected when they receive this packet. This packet is sent immediatelly and network is dropped immediatelly too. More...
 
bool requestNodeDisconnect (uint8_t address)
 Request node disconnection from network. Node may ignore this request or may not receive this request. If response is received callback set using setOnRemoteNodeDisconnectedCallback() is called. If response is not received until timeout, callback set using setDiscRequestFailedCallback() is called. More...
 
bool requestNodeDisconnect (MeshMAC mac)
 Request node disconnection from network. Node may ignore this request or may not hear this request. More...
 
void setDiscRequestFailedCallback (bool(*callback)(MeshNet *, uint8_t))
 This timeout is called, when requestNodeDisconnect() failed, because response was not received until specified timeout. More...
 
void setOnConnectionPermissionCallback (bool(*callback)(MeshNetGateway *, uint16_t, uint16_t, MeshMAC))
 Sets pointer to function, which is called when gateway has to decide, if node can be connected to network. If no callback function is set, all conections are permitted. More...
 
bool printDHCPTable (OSTREAM *stream)
 
void handle () override
 This method has to be called in main program loop as often as possible. More...
 
- Public Member Functions inherited from MeshNet
 MeshNet ()
 Constructor without arguments. More...
 
virtual ~MeshNet ()
 Virtual destructor. 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...
 
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...
 

Protected Member Functions

void processPacket (MeshPacket &packet, MeshMAC BSSID) override
 Processed received packet. Called in processReceived() method. More...
 
virtual void onPacketError (MeshPacketError error, uint8_t packetID, uint8_t packetDest, SystemPacketType packetType, const MeshPacket *packet_ptr) override
 This method is called when some error happened to any packet created by current node. More...
 
void routeTableUpdate (const MeshPacketHeader &header, MeshMAC BSSID, int8_t rssi) override
 Updates route table when valid packet from node with same network is received.ň More...
 
void onNodeLost (uint8_t address, bool nodeLostForever) override
 This method is called, when some node is disconnected from network or does not responds to sent packet. More...
 
void makeInvalidDHCPRow (uint8_t address)
 Makes invalid row in DHCP table by assigned address. More...
 
void onDHCPValidityChanged (int16_t index, bool valid, bool removed)
 This method is called when DHCP row validity has changed. There can be 3 states of validity: More...
 
- Protected Member Functions inherited from MeshNet
 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...
 
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...
 
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...
 
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...
 
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...
 

Additional Inherited Members

- Static Public Member Functions inherited from MeshNet
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 inherited from MeshNet
const static MeshVersion Version = MESHNET_VERSION
 Version of MeshNet protocol. More...
 
- Static Protected Member Functions inherited from MeshNet
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 inherited from MeshNet
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...
 

Constructor & Destructor Documentation

◆ MeshNetGateway()

MeshNetGateway::MeshNetGateway ( )
inline

Member Function Documentation

◆ begin() [1/3]

bool MeshNetGateway::begin ( )
overridevirtual

Starts MeshNet gateway instance for current node with last setings.

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

Reimplemented from MeshNet.

◆ begin() [2/3]

bool MeshNetGateway::begin ( MeshMAC  mac,
RFInterface RFI 
)
inlineoverridevirtual

This method cannot be used with gateway, that's why it always returns false.

Returns
Returns false.

Reimplemented from MeshNet.

◆ begin() [3/3]

bool MeshNetGateway::begin ( MeshMAC  mac,
RFInterface RFI,
const char *  SSID_ 
)
virtual

Starts MeshNet instance as gateway 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.
SSID_Network SSID including terminator. The maximum length of SSID is 64 without terminator.
Returns
Returns true when instance started successfully.

◆ dropNetwork()

bool MeshNetGateway::dropNetwork ( bool  forced)

Drops whole network, all nodes will be disconnected when they receive this packet. This packet is sent immediatelly and network is dropped immediatelly too.

Parameters
forcedIf true and packet sending fails, current node will be disconnected. If false and sending fails, current node won't be disconnected.
Returns
Returns true if packet was successfully send.

◆ end()

bool MeshNetGateway::end ( )
overridevirtual

Disables mesh node. It is recommended to drop network before calling this method to get know to nodes, that they are no longer connected. If this node is main gateway, network is forcibly dropped.

Reimplemented from MeshNet.

◆ handle()

void MeshNetGateway::handle ( )
overridevirtual

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

Reimplemented from MeshNet.

◆ makeInvalidDHCPRow()

void MeshNetGateway::makeInvalidDHCPRow ( uint8_t  address)
protected

Makes invalid row in DHCP table by assigned address.

Parameters
addressAddress to make invalid.

◆ onDHCPValidityChanged()

void MeshNetGateway::onDHCPValidityChanged ( int16_t  index,
bool  valid,
bool  removed 
)
protected

This method is called when DHCP row validity has changed. There can be 3 states of validity:

  1. Valid (rawLifeTime > DHCPTABLE_ROW_RAW_LIFETIME_RESERVED): valid = true, removed = false
  2. Invalid (rawLifeTime <= DHCPTABLE_ROW_RAW_LIFETIME_RESERVED && rawLifeTime > 0): valid = false, removed = false
  3. Blank (rawLifeTime == 0) valid = false, removed = true
    Parameters
    indexIndex of row which changed.
    validTrue if row is valid.
    removedTrue if row is removed.

◆ onNodeLost()

void MeshNetGateway::onNodeLost ( uint8_t  address,
bool  nodeLostForever 
)
overrideprotectedvirtual

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 from MeshNet.

◆ onPacketError()

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

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 from MeshNet.

◆ printDHCPTable()

bool MeshNetGateway::printDHCPTable ( OSTREAM stream)

◆ processPacket()

void MeshNetGateway::processPacket ( MeshPacket packet,
MeshMAC  BSSID 
)
overrideprotectedvirtual

Processed received packet. Called in processReceived() method.

Parameters
packetReference to received packet.
BSSIDBSSID of network, which sent packet.
Returns
Returns true, if packet was processed and ACK has to be send. Returns false, if packet has to be ignored, no ACK is sent.

Reimplemented from MeshNet.

◆ requestNodeDisconnect() [1/2]

bool MeshNetGateway::requestNodeDisconnect ( MeshMAC  mac)

Request node disconnection from network. Node may ignore this request or may not hear this request.

Parameters
macMAC address of node to disconnect.
Returns
Returns true if packet was sent successfully.

◆ requestNodeDisconnect() [2/2]

bool MeshNetGateway::requestNodeDisconnect ( uint8_t  address)

Request node disconnection from network. Node may ignore this request or may not receive this request. If response is received callback set using setOnRemoteNodeDisconnectedCallback() is called. If response is not received until timeout, callback set using setDiscRequestFailedCallback() is called.

Parameters
addressAddress of node to disconnect.
Returns
Returns true if packet was sent successfully.

◆ routeTableUpdate()

void MeshNetGateway::routeTableUpdate ( const MeshPacketHeader header,
MeshMAC  BSSID,
int8_t  rssi 
)
overrideprotectedvirtual

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 from MeshNet.

◆ setDiscRequestFailedCallback()

void MeshNetGateway::setDiscRequestFailedCallback ( bool(*)(MeshNet *, uint8_t)  callback)
inline

This timeout is called, when requestNodeDisconnect() failed, because response was not received until specified timeout.

Parameters
callbackCallback function, which will be called. It's parameter is set to address of node, which has to be disconnected.

◆ setOnConnectionPermissionCallback()

void MeshNetGateway::setOnConnectionPermissionCallback ( bool(*)(MeshNetGateway *, uint16_t, uint16_t, MeshMAC callback)
inline

Sets pointer to function, which is called when gateway has to decide, if node can be connected to network. If no callback function is set, all conections are permitted.

Parameters
callbackCallback funtion called when gateway has to decide, if node can be connected to network. This function has to return true if node can connect to network.

Parameters


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