EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Espnow_halClass Class Reference

Definition for ESP-NOW hardware abstraction layer. More...

#include <espnow_hal.h>

Inheritance diagram for Espnow_halClass:
Comms_halClass

Public Member Functions

 Espnow_halClass ()
 Class constructor. More...
 
void begin (uint8_t *gateway, uint8_t channel=0, peerType_t peerType=COMM_NODE) override
 Setup communication environment and establish the connection from node to gateway. More...
 
void stop () override
 Terminates communication and closes all connectrions. More...
 
int32_t send (uint8_t *da, uint8_t *data, int len) override
 Sends data to the other peer. More...
 
void onDataRcvd (comms_hal_rcvd_data dataRcvd) override
 Attach a callback function to be run on every received message. More...
 
void onDataSent (comms_hal_sent_data dataRcvd) override
 Attach a callback function to be run after sending a message to receive its status. More...
 
uint8_t getAddressLength () override
 Get address length used on ESP-NOW subsystem. More...
 
size_t getMaxMessageLength ()
 Get maximum message length on ESP-NOW subsystem. More...
 
void enableTransmit (bool enable) override
 Enables or disables transmission of queued messages. Used to disable communication during wifi scan. More...
 
void handle () override
 Sends next message in the queue. More...
 
- Public Member Functions inherited from Comms_halClass
 Comms_halClass ()
 

Static Public Member Functions

static void runHandle (void *param)
 Static function that calls handle inside task. More...
 

Static Public Attributes

static const size_t COMMS_HAL_MAX_MESSAGE_LENGTH = 250
 Maximum message length for ESP-NOW. More...
 
static const uint8_t COMMS_HAL_ADDR_LEN = 6
 Address length for ESP-NOW. Correspond to mac address. More...
 
- Static Public Attributes inherited from Comms_halClass
static const size_t COMMS_HAL_MAX_MESSAGE_LENGTH = 0
 Maximum message length. More...
 
static const uint8_t COMMS_HAL_ADDR_LEN = 1
 Address length. More...
 

Protected Member Functions

void initComms (peerType_t peerType) override
 Communication subsistem initialization. More...
 
bool addPeer (const uint8_t *da)
 Adds a peer to esp-now peer list. More...
 
int32_t sendEspNowMessage (comms_queue_item_t *message)
 
comms_queue_item_tgetCommsQueue ()
 
void popCommsQueue ()
 

Static Protected Member Functions

static void ICACHE_FLASH_ATTR rx_cb (uint8_t *mac_addr, uint8_t *data, uint8_t len)
 Function that processes incoming messages and passes them to upper layer. More...
 
static void ICACHE_FLASH_ATTR tx_cb (uint8_t *mac_addr, uint8_t status)
 Function that gets sending status. More...
 

Protected Attributes

EnigmaIOTRingBuffer< comms_queue_item_tout_queue
 
bool readyToSend = true
 
ETSTimer espnowLoopTask
 
- Protected Attributes inherited from Comms_halClass
uint8_t gateway [COMMS_HAL_ADDR_LEN]
 Gateway address. More...
 
uint8_t channel
 Comms channel to be used. More...
 
comms_hal_rcvd_data dataRcvd = 0
 Pointer to a function to be called on every received message. More...
 
comms_hal_sent_data sentResult = 0
 Pointer to a function to be called to notify last sending status. More...
 
peerType_t _ownPeerType
 Stores peer type, node or gateway. More...
 

Detailed Description

Definition for ESP-NOW hardware abstraction layer.

Definition at line 31 of file espnow_hal.h.

Constructor & Destructor Documentation

◆ Espnow_halClass()

Espnow_halClass::Espnow_halClass ( )
inline

Class constructor.

Definition at line 81 of file espnow_hal.h.

Member Function Documentation

◆ addPeer()

bool Espnow_halClass::addPeer ( const uint8_t *  da)
protected

Adds a peer to esp-now peer list.

Parameters
daPeer address to be added to peer list

Definition at line 93 of file espnow_hal.cpp.

◆ begin()

void Espnow_halClass::begin ( uint8_t *  gateway,
uint8_t  channel = 0,
peerType_t  peerType = COMM_NODE 
)
overridevirtual

Setup communication environment and establish the connection from node to gateway.

Parameters
gatewayAddress of gateway. It may be NULL in case this is used in the own gateway
channelEstablishes a channel for the communication. Its use depends on actual communications subsystem
peerTypeRole that peer plays into the system, sensor node or gateway.

Implements Comms_halClass.

Definition at line 78 of file espnow_hal.cpp.

◆ enableTransmit()

void Espnow_halClass::enableTransmit ( bool  enable)
inlineoverridevirtual

Enables or disables transmission of queued messages. Used to disable communication during wifi scan.

Parameters
enabletrue to enable transmission, false to disable it

Implements Comms_halClass.

Definition at line 139 of file espnow_hal.h.

◆ getAddressLength()

uint8_t Espnow_halClass::getAddressLength ( )
inlineoverridevirtual

Get address length used on ESP-NOW subsystem.

Returns
Always returns the sice of 802.11 MAC address, equals to 6

Implements Comms_halClass.

Definition at line 123 of file espnow_hal.h.

◆ getCommsQueue()

comms_queue_item_t * Espnow_halClass::getCommsQueue ( )
protected

Definition at line 152 of file espnow_hal.cpp.

◆ getMaxMessageLength()

size_t Espnow_halClass::getMaxMessageLength ( )
inline

Get maximum message length on ESP-NOW subsystem.

Returns
Always returns a value equal to 250

Definition at line 131 of file espnow_hal.h.

◆ handle()

void Espnow_halClass::handle ( )
overridevirtual

Sends next message in the queue.

Implements Comms_halClass.

Definition at line 212 of file espnow_hal.cpp.

◆ initComms()

void Espnow_halClass::initComms ( peerType_t  peerType)
overrideprotectedvirtual

Communication subsistem initialization.

Parameters
peerTypeRole that peer plays into the system, sensor node or gateway.

Implements Comms_halClass.

Definition at line 24 of file espnow_hal.cpp.

◆ onDataRcvd()

void Espnow_halClass::onDataRcvd ( comms_hal_rcvd_data  dataRcvd)
overridevirtual

Attach a callback function to be run on every received message.

Parameters
dataRcvdPointer to the callback function

Implements Comms_halClass.

Definition at line 204 of file espnow_hal.cpp.

◆ onDataSent()

void Espnow_halClass::onDataSent ( comms_hal_sent_data  dataRcvd)
overridevirtual

Attach a callback function to be run after sending a message to receive its status.

Parameters
dataRcvdPointer to the callback function

Implements Comms_halClass.

Definition at line 208 of file espnow_hal.cpp.

◆ popCommsQueue()

void Espnow_halClass::popCommsQueue ( )
protected

Definition at line 160 of file espnow_hal.cpp.

◆ runHandle()

void Espnow_halClass::runHandle ( void *  param)
static

Static function that calls handle inside task.

Definition at line 230 of file espnow_hal.cpp.

◆ rx_cb()

void ICACHE_FLASH_ATTR Espnow_halClass::rx_cb ( uint8_t *  mac_addr,
uint8_t *  data,
uint8_t  len 
)
staticprotected

Function that processes incoming messages and passes them to upper layer.

Parameters
mac_addrDestination address to send the message to
dataData buffer that contain the message to be sent
lenData length in number of bytes

Definition at line 64 of file espnow_hal.cpp.

◆ send()

int32_t Espnow_halClass::send ( uint8_t *  da,
uint8_t *  data,
int  len 
)
overridevirtual

Sends data to the other peer.

Parameters
daDestination address to send the message to
dataData buffer that contain the message to be sent
lenData length in number of bytes
Returns
Returns sending status. 0 for success, 1 to indicate an error.

Implements Comms_halClass.

Definition at line 122 of file espnow_hal.cpp.

◆ sendEspNowMessage()

int32_t Espnow_halClass::sendEspNowMessage ( comms_queue_item_t message)
protected

Definition at line 173 of file espnow_hal.cpp.

◆ stop()

void Espnow_halClass::stop ( )
overridevirtual

Terminates communication and closes all connectrions.

Implements Comms_halClass.

Definition at line 115 of file espnow_hal.cpp.

◆ tx_cb()

void ICACHE_FLASH_ATTR Espnow_halClass::tx_cb ( uint8_t *  mac_addr,
uint8_t  status 
)
staticprotected

Function that gets sending status.

Parameters
mac_addrDestination address to send the message to
statusSending status

Definition at line 70 of file espnow_hal.cpp.

Member Data Documentation

◆ COMMS_HAL_ADDR_LEN

const uint8_t Espnow_halClass::COMMS_HAL_ADDR_LEN = 6
static

Address length for ESP-NOW. Correspond to mac address.

Definition at line 34 of file espnow_hal.h.

◆ COMMS_HAL_MAX_MESSAGE_LENGTH

const size_t Espnow_halClass::COMMS_HAL_MAX_MESSAGE_LENGTH = 250
static

Maximum message length for ESP-NOW.

Definition at line 33 of file espnow_hal.h.

◆ espnowLoopTask

ETSTimer Espnow_halClass::espnowLoopTask
protected

Definition at line 43 of file espnow_hal.h.

◆ out_queue

EnigmaIOTRingBuffer<comms_queue_item_t> Espnow_halClass::out_queue
protected

Definition at line 38 of file espnow_hal.h.

◆ readyToSend

bool Espnow_halClass::readyToSend = true
protected

Definition at line 39 of file espnow_hal.h.


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