EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
Comms_hal.h
Go to the documentation of this file.
1 
10 #ifndef _COMMS_HAL_h
11 #define _COMMS_HAL_h
12 
13 #if defined(ARDUINO) && ARDUINO >= 100
14 #include "Arduino.h"
15 #else
16 #include "WProgram.h"
17 #endif
18 #include "EnigmaIoTconfig.h"
19 
23 enum peerType_t {
24  COMM_NODE = 0,
25  COMM_GATEWAY = 1
26 };
27 
28 typedef struct {
29  uint8_t dstAddress[ENIGMAIOT_ADDR_LEN];
30  uint8_t payload[MAX_MESSAGE_LENGTH];
31  size_t payload_len;
33 
34 
35 typedef void (*comms_hal_rcvd_data)(uint8_t* address, uint8_t* data, uint8_t len);
36 typedef void (*comms_hal_sent_data)(uint8_t* address, uint8_t status);
37 
42 public:
43  static const size_t COMMS_HAL_MAX_MESSAGE_LENGTH = 0;
44  static const uint8_t COMMS_HAL_ADDR_LEN = 1;
45 
46 protected:
48  uint8_t channel;
49 
53 
58  virtual void initComms (peerType_t peerType) = 0;
59 
60 
61 public:
63 
70  virtual void begin (uint8_t* gateway, uint8_t channel, peerType_t peerType = COMM_NODE) = 0;
71 
75  virtual void stop () = 0;
76 
84  virtual int32_t send (uint8_t* da, uint8_t* data, int len) = 0;
85 
91 
97 
102  virtual uint8_t getAddressLength () = 0;
103 
107  virtual void handle () = 0;
108 
113  virtual void enableTransmit (bool enable) = 0;
114 };
115 
116 #endif
117 
Comms_halClass::onDataRcvd
virtual void onDataRcvd(comms_hal_rcvd_data dataRcvd)=0
Attach a callback function to be run on every received message.
peerType_t
peerType_t
Peer role on communication.
Definition: Comms_hal.h:23
comms_queue_item_t
Definition: Comms_hal.h:28
ENIGMAIOT_ADDR_LEN
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
Definition: EnigmaIoTconfigAdvanced.h:23
Comms_halClass::onDataSent
virtual void onDataSent(comms_hal_sent_data dataRcvd)=0
Attach a callback function to be run after sending a message to receive its status.
MAX_MESSAGE_LENGTH
static const uint8_t MAX_MESSAGE_LENGTH
Maximum payload size on ESP-NOW.
Definition: EnigmaIoTconfigAdvanced.h:21
Comms_halClass::begin
virtual void begin(uint8_t *gateway, uint8_t channel, peerType_t peerType=COMM_NODE)=0
Setup communication environment and establish the connection from node to gateway.
Comms_halClass::COMMS_HAL_MAX_MESSAGE_LENGTH
static const size_t COMMS_HAL_MAX_MESSAGE_LENGTH
Maximum message length.
Definition: Comms_hal.h:43
EnigmaIoTconfig.h
Parameter configuration.
Comms_halClass::sentResult
comms_hal_sent_data sentResult
Pointer to a function to be called to notify last sending status.
Definition: Comms_hal.h:51
Comms_halClass::send
virtual int32_t send(uint8_t *da, uint8_t *data, int len)=0
Sends data to the other peer.
comms_queue_item_t::payload_len
size_t payload_len
Definition: Comms_hal.h:31
Comms_halClass::getAddressLength
virtual uint8_t getAddressLength()=0
Get address length that a specific communication subsystem uses.
COMM_NODE
@ COMM_NODE
Definition: Comms_hal.h:24
Comms_halClass::Comms_halClass
Comms_halClass()
Definition: Comms_hal.h:62
Comms_halClass::handle
virtual void handle()=0
Sends next message in the queue.
comms_hal_rcvd_data
void(* comms_hal_rcvd_data)(uint8_t *address, uint8_t *data, uint8_t len)
Definition: Comms_hal.h:35
COMM_GATEWAY
@ COMM_GATEWAY
Definition: Comms_hal.h:25
Comms_halClass::dataRcvd
comms_hal_rcvd_data dataRcvd
Pointer to a function to be called on every received message.
Definition: Comms_hal.h:50
data
@ data
Definition: GwOutput_generic.h:23
Comms_halClass::_ownPeerType
peerType_t _ownPeerType
Stores peer type, node or gateway.
Definition: Comms_hal.h:52
Comms_halClass::enableTransmit
virtual void enableTransmit(bool enable)=0
Enables or disables transmission of queued messages. Used to disable communication during wifi scan.
Comms_halClass::COMMS_HAL_ADDR_LEN
static const uint8_t COMMS_HAL_ADDR_LEN
Address length.
Definition: Comms_hal.h:44
comms_hal_sent_data
void(* comms_hal_sent_data)(uint8_t *address, uint8_t status)
Definition: Comms_hal.h:36
Comms_halClass::initComms
virtual void initComms(peerType_t peerType)=0
Communication subsistem initialization.
Comms_halClass::gateway
uint8_t gateway[COMMS_HAL_ADDR_LEN]
Gateway address.
Definition: Comms_hal.h:47
Comms_halClass::channel
uint8_t channel
Comms channel to be used.
Definition: Comms_hal.h:48
status
@ status
Definition: GwOutput_generic.h:25
Comms_halClass
Interface for communication subsystem abstraction layer definition.
Definition: Comms_hal.h:41
Comms_halClass::stop
virtual void stop()=0
Terminates communication and closes all connectrions.