Skip to content

Commit 8709602

Browse files
committed
Add unit test for peer list class
1 parent 979cfa7 commit 8709602

File tree

10 files changed

+576
-352
lines changed

10 files changed

+576
-352
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
lib
2-
test
31
include
42
.pio
53
.vscode
Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
1-
/**
2-
* @file Comms_hal.h
3-
* @version 0.9.8
4-
* @date 15/07/2021
5-
* @author German Martin
6-
* @brief Generic communication system abstraction layer
7-
*
8-
* This is the interface that communication definition should implement to be used as layer 1 on EnigmaIoT
9-
*/
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-
19-
typedef void (*comms_hal_rcvd_data)(uint8_t* address, uint8_t* data, uint8_t len, signed int rssi);
20-
typedef void (*comms_hal_sent_data)(uint8_t* address, uint8_t status);
21-
22-
/**
23-
* @brief Interface for communication subsystem abstraction layer definition
24-
*/
25-
class Comms_halClass {
26-
protected:
27-
//uint8_t gateway[ESPNOW_ADDR_LEN]; ///< @brief Gateway address
28-
uint8_t channel; ///< @brief Comms channel to be used
29-
30-
comms_hal_rcvd_data dataRcvd = 0; ///< @brief Pointer to a function to be called on every received message
31-
comms_hal_sent_data sentResult = 0; ///< @brief Pointer to a function to be called to notify last sending status
32-
//peerType_t _ownPeerType; ///< @brief Stores peer type, node or gateway
33-
34-
/**
35-
* @brief Communication subsistem initialization
36-
* @param peerType Role that peer plays into the system, node or gateway.
37-
*/
38-
virtual void initComms () = 0;
39-
40-
41-
public:
42-
Comms_halClass () {}
43-
44-
/**
45-
* @brief Setup communication environment and establish the connection from node to gateway
46-
* @param gateway Address of gateway. It may be `NULL` in case this is used in the own gateway
47-
* @param channel Establishes a channel for the communication. Its use depends on actual communications subsystem
48-
* @param peerType Role that peer plays into the system, node or gateway.
49-
*/
50-
virtual bool begin (uint8_t channel, uint32_t interface = 0) = 0;
51-
52-
/**
53-
* @brief Terminates communication and closes all connectrions
54-
*/
55-
virtual void stop () = 0;
56-
57-
/**
58-
* @brief Sends data to the other peer
59-
* @param da Destination address to send the message to
60-
* @param data Data buffer that contain the message to be sent
61-
* @param len Data length in number of bytes
62-
* @return Returns sending status. 0 for success, any other value to indicate an error.
63-
*/
64-
virtual int32_t send (uint8_t* da, uint8_t* data, size_t len) = 0;
65-
66-
/**
67-
* @brief Attach a callback function to be run on every received message
68-
* @param dataRcvd Pointer to the callback function
69-
*/
70-
virtual void onDataRcvd (comms_hal_rcvd_data dataRcvd) = 0;
71-
72-
/**
73-
* @brief Attach a callback function to be run after sending a message to receive its status
74-
* @param dataRcvd Pointer to the callback function
75-
*/
76-
virtual void onDataSent (comms_hal_sent_data dataRcvd) = 0;
77-
78-
/**
79-
* @brief Get address length that a specific communication subsystem uses
80-
* @return Returns number of bytes that is used to represent an address
81-
*/
82-
virtual uint8_t getAddressLength () = 0;
83-
84-
/**
85-
* @brief Get max message length for a specific communication subsystems
86-
* @return Returns number of bytes of longer supported message
87-
*/
88-
virtual uint8_t getMaxMessageLength () = 0;
89-
90-
/**
91-
* @brief Sends next message in the queue
92-
*/
93-
virtual void handle () = 0;
94-
95-
/**
96-
* @brief Enables or disables transmission of queued messages. Used to disable communication during wifi scan
97-
* @param enable `true` to enable transmission, `false` to disable it
98-
*/
99-
virtual void enableTransmit (bool enable) = 0;
100-
};
101-
102-
#endif
103-
1+
/**
2+
* @file Comms_hal.h
3+
* @version 0.9.8
4+
* @date 15/07/2021
5+
* @author German Martin
6+
* @brief Generic communication system abstraction layer
7+
*
8+
* This is the interface that communication definition should implement to be used as layer 1 on EnigmaIoT
9+
*/
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+
19+
typedef void (*comms_hal_rcvd_data)(uint8_t* address, uint8_t* data, uint8_t len, signed int rssi);
20+
typedef void (*comms_hal_sent_data)(uint8_t* address, uint8_t status);
21+
22+
/**
23+
* @brief Interface for communication subsystem abstraction layer definition
24+
*/
25+
class Comms_halClass {
26+
protected:
27+
//uint8_t gateway[ESPNOW_ADDR_LEN]; ///< @brief Gateway address
28+
uint8_t channel; ///< @brief Comms channel to be used
29+
30+
comms_hal_rcvd_data dataRcvd = 0; ///< @brief Pointer to a function to be called on every received message
31+
comms_hal_sent_data sentResult = 0; ///< @brief Pointer to a function to be called to notify last sending status
32+
//peerType_t _ownPeerType; ///< @brief Stores peer type, node or gateway
33+
34+
/**
35+
* @brief Communication subsistem initialization
36+
* @param peerType Role that peer plays into the system, node or gateway.
37+
*/
38+
virtual void initComms () = 0;
39+
40+
41+
public:
42+
Comms_halClass () {}
43+
44+
/**
45+
* @brief Setup communication environment and establish the connection from node to gateway
46+
* @param gateway Address of gateway. It may be `NULL` in case this is used in the own gateway
47+
* @param channel Establishes a channel for the communication. Its use depends on actual communications subsystem
48+
* @param peerType Role that peer plays into the system, node or gateway.
49+
*/
50+
virtual bool begin (uint8_t channel, uint32_t interface = 0) = 0;
51+
52+
/**
53+
* @brief Terminates communication and closes all connectrions
54+
*/
55+
virtual void stop () = 0;
56+
57+
/**
58+
* @brief Sends data to the other peer
59+
* @param da Destination address to send the message to
60+
* @param data Data buffer that contain the message to be sent
61+
* @param len Data length in number of bytes
62+
* @return Returns sending status. 0 for success, any other value to indicate an error.
63+
*/
64+
virtual int32_t send (uint8_t* da, uint8_t* data, size_t len) = 0;
65+
66+
/**
67+
* @brief Attach a callback function to be run on every received message
68+
* @param dataRcvd Pointer to the callback function
69+
*/
70+
virtual void onDataRcvd (comms_hal_rcvd_data dataRcvd) = 0;
71+
72+
/**
73+
* @brief Attach a callback function to be run after sending a message to receive its status
74+
* @param dataRcvd Pointer to the callback function
75+
*/
76+
virtual void onDataSent (comms_hal_sent_data dataRcvd) = 0;
77+
78+
/**
79+
* @brief Get address length that a specific communication subsystem uses
80+
* @return Returns number of bytes that is used to represent an address
81+
*/
82+
virtual uint8_t getAddressLength () = 0;
83+
84+
/**
85+
* @brief Get max message length for a specific communication subsystems
86+
* @return Returns number of bytes of longer supported message
87+
*/
88+
virtual uint8_t getMaxMessageLength () = 0;
89+
90+
/**
91+
* @brief Sends next message in the queue
92+
*/
93+
virtual void handle () = 0;
94+
95+
/**
96+
* @brief Enables or disables transmission of queued messages. Used to disable communication during wifi scan
97+
* @param enable `true` to enable transmission, `false` to disable it
98+
*/
99+
virtual void enableTransmit (bool enable) = 0;
100+
};
101+
102+
#endif
103+
Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
1-
/**
2-
* @brief Auxiliary functions for debugging over Serial
3-
*
4-
* Format used on debug functions is the same as `printf()`. Check source code for usage examples
5-
* Debug calls will be enabled or disabled automatically before compiling according defined `DEBUG_LEVEL`.
6-
*
7-
* If `DEBUG_ESP_PORT` is not defined library will give no debug output at all
8-
*
9-
* @file EnigmaIOTdebug.h
10-
* @version 0.9.8
11-
* @date 15/07/2021
12-
* @author German Martin
13-
*/
14-
15-
#ifndef _DEBUG_h
16-
#define _DEBUG_h
17-
18-
#include <Arduino.h>
19-
#ifdef ESP32
20-
#include <esp_log.h>
21-
#endif
22-
23-
#define DEBUG_ESP_PORT Serial
24-
25-
#define NO_DEBUG 0 ///< @brief Debug level that will give no debug output
26-
#define ERROR 1 ///< @brief Debug level that will give error messages
27-
#define WARN 2 ///< @brief Debug level that will give error and warning messages
28-
#define INFO 3 ///< @brief Debug level that will give error, warning and info messages
29-
#define DBG 4 ///< @brief Debug level that will give error, warning,info AND dbg messages
30-
#define VERBOSE 5 ///< @brief Debug level that will give all defined messages
31-
32-
#ifdef ESP8266
33-
const char* extractFileName (const char* path);
34-
#define DEBUG_LINE_PREFIX() DEBUG_ESP_PORT.printf_P (PSTR("[%lu][H:%5lu][%s:%d] %s() | "),millis(),(unsigned long)ESP.getFreeHeap(),extractFileName(__FILE__),__LINE__,__FUNCTION__)
35-
#endif
36-
37-
#ifdef DEBUG_ESP_PORT
38-
39-
#ifdef ESP8266
40-
#if DEBUG_LEVEL >= VERBOSE
41-
#define DEBUG_VERBOSE(text,...) DEBUG_ESP_PORT.print("V ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
42-
#else
43-
#define DEBUG_VERBOSE(...)
44-
#endif
45-
46-
#if DEBUG_LEVEL >= DBG
47-
#define DEBUG_DBG(text,...) DEBUG_ESP_PORT.print("D ");DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
48-
#else
49-
#define DEBUG_DBG(...)
50-
#endif
51-
52-
#if DEBUG_LEVEL >= INFO
53-
#define DEBUG_INFO(text,...) DEBUG_ESP_PORT.print("I ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
54-
#else
55-
#define DEBUG_INFO(...)
56-
#endif
57-
58-
#if DEBUG_LEVEL >= WARN
59-
#define DEBUG_WARN(text,...) DEBUG_ESP_PORT.print("W ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
60-
#else
61-
#define DEBUG_WARN(...)
62-
#endif
63-
64-
#if DEBUG_LEVEL >= ERROR
65-
#define DEBUG_ERROR(text,...) DEBUG_ESP_PORT.print("E ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
66-
#else
67-
#define DEBUG_ERROR(...)
68-
#endif
69-
#elif defined ESP32
70-
#define DEFAULT_LOG_TAG "QuickDebug"
71-
#define DEBUG_VERBOSE(format,...) ESP_LOGV (DEFAULT_LOG_TAG,"%d Heap: %6d. " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
72-
#define DEBUG_DBG(format,...) ESP_LOGD (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
73-
#define DEBUG_INFO(format,...) ESP_LOGI (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
74-
#define DEBUG_WARN(format,...) ESP_LOGW (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
75-
#define DEBUG_ERROR(format,...) ESP_LOGE (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
76-
#endif
77-
#else
78-
#define DEBUG_VERBOSE(...)
79-
#define DEBUG_DBG(...)
80-
#define DEBUG_INFO(...)
81-
#define DEBUG_WARN(...)
82-
#define DEBUG_ERROR(...)
83-
#endif
84-
85-
86-
87-
#endif
88-
1+
/**
2+
* @brief Auxiliary functions for debugging over Serial
3+
*
4+
* Format used on debug functions is the same as `printf()`. Check source code for usage examples
5+
* Debug calls will be enabled or disabled automatically before compiling according defined `DEBUG_LEVEL`.
6+
*
7+
* If `DEBUG_ESP_PORT` is not defined library will give no debug output at all
8+
*
9+
* @file EnigmaIOTdebug.h
10+
* @version 0.9.8
11+
* @date 15/07/2021
12+
* @author German Martin
13+
*/
14+
15+
#ifndef _DEBUG_h
16+
#define _DEBUG_h
17+
18+
#include <Arduino.h>
19+
#ifdef ESP32
20+
#include <esp_log.h>
21+
#endif
22+
23+
#define DEBUG_ESP_PORT Serial
24+
25+
#define NO_DEBUG 0 ///< @brief Debug level that will give no debug output
26+
#define ERROR 1 ///< @brief Debug level that will give error messages
27+
#define WARN 2 ///< @brief Debug level that will give error and warning messages
28+
#define INFO 3 ///< @brief Debug level that will give error, warning and info messages
29+
#define DBG 4 ///< @brief Debug level that will give error, warning,info AND dbg messages
30+
#define VERBOSE 5 ///< @brief Debug level that will give all defined messages
31+
32+
#ifdef ESP8266
33+
const char* extractFileName (const char* path);
34+
#define DEBUG_LINE_PREFIX() DEBUG_ESP_PORT.printf_P (PSTR("[%lu][H:%5lu][%s:%d] %s() | "),millis(),(unsigned long)ESP.getFreeHeap(),extractFileName(__FILE__),__LINE__,__FUNCTION__)
35+
#endif
36+
37+
#ifdef DEBUG_ESP_PORT
38+
39+
#ifdef ESP8266
40+
#if DEBUG_LEVEL >= VERBOSE
41+
#define DEBUG_VERBOSE(text,...) DEBUG_ESP_PORT.print("V ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
42+
#else
43+
#define DEBUG_VERBOSE(...)
44+
#endif
45+
46+
#if DEBUG_LEVEL >= DBG
47+
#define DEBUG_DBG(text,...) DEBUG_ESP_PORT.print("D ");DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
48+
#else
49+
#define DEBUG_DBG(...)
50+
#endif
51+
52+
#if DEBUG_LEVEL >= INFO
53+
#define DEBUG_INFO(text,...) DEBUG_ESP_PORT.print("I ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
54+
#else
55+
#define DEBUG_INFO(...)
56+
#endif
57+
58+
#if DEBUG_LEVEL >= WARN
59+
#define DEBUG_WARN(text,...) DEBUG_ESP_PORT.print("W ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
60+
#else
61+
#define DEBUG_WARN(...)
62+
#endif
63+
64+
#if DEBUG_LEVEL >= ERROR
65+
#define DEBUG_ERROR(text,...) DEBUG_ESP_PORT.print("E ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println()
66+
#else
67+
#define DEBUG_ERROR(...)
68+
#endif
69+
#elif defined ESP32
70+
#define DEFAULT_LOG_TAG "QuickDebug"
71+
#define DEBUG_VERBOSE(format,...) ESP_LOGV (DEFAULT_LOG_TAG,"%d Heap: %6d. " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
72+
#define DEBUG_DBG(format,...) ESP_LOGD (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
73+
#define DEBUG_INFO(format,...) ESP_LOGI (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
74+
#define DEBUG_WARN(format,...) ESP_LOGW (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
75+
#define DEBUG_ERROR(format,...) ESP_LOGE (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__)
76+
#endif
77+
#else
78+
#define DEBUG_VERBOSE(...)
79+
#define DEBUG_DBG(...)
80+
#define DEBUG_INFO(...)
81+
#define DEBUG_WARN(...)
82+
#define DEBUG_ERROR(...)
83+
#endif
84+
85+
86+
87+
#endif
88+

0 commit comments

Comments
 (0)