loads more changes

This commit is contained in:
Daniël Koek 2024-01-30 19:14:44 +00:00
parent b70d44e6c2
commit 7b55449229
4 changed files with 1246 additions and 1361 deletions

View file

@ -4,15 +4,18 @@
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "lora_e220.h" #include "lora_e220.h"
#include "esphome/components/uart/uart.h"
namespace esphome { namespace esphome {
namespace ebyte_lora_e220 { namespace ebyte_lora_e220 {
static const char *const TAG = "ebyte_lora_e220";
// there are 3 UART ports, we are going to be using 0, which is D6 and D7 // there are 3 UART ports, we are going to be using 0, which is D6 and D7
HardwareSerial LoraSerial(0); HardwareSerial LoraSerial(0);
LoRa_E220 e220ttl(&LoraSerial, D2, D0, D1); // SERIAL AUX M0 M1 LoRa_E220 e220ttl(&LoraSerial, D2, D0, D1); // SERIAL AUX M0 M1
class LoRaSensors : public text_sensor::TextSensor, public PollingComponent { class LoRaSensors : public text_sensor::TextSensor, public PollingComponent, public uart::UARTDevice {
public: public:
LoRaSensors() : PollingComponent(4000) {} LoRaSensors() : PollingComponent(4000) {}

File diff suppressed because it is too large Load diff

View file

@ -1,360 +1,290 @@
#ifndef LoRa_E220_h #ifndef LoRa_E220_h
#define LoRa_E220_h #define LoRa_E220_h
#if !USE_ESP32 && !defined(__STM32F1__) && !defined(__STM32F4__)
#define ACTIVATE_SOFTWARE_SERIAL
#endif
#ifdef USE_ESP32 #ifdef USE_ESP32
#define HARDWARE_SERIAL_SELECTABLE_PIN #define HARDWARE_SERIAL_SELECTABLE_PIN
#endif
#ifdef ACTIVATE_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
#endif #endif
#include "state_naming.h" #include "state_naming.h"
#include "Arduino.h" #include "Arduino.h"
#define MAX_SIZE_TX_PACKET 200 #define MAX_SIZE_TX_PACKET 200
// Uncomment to enable printing out nice debug messages. // Uncomment to enable printing out nice debug messages.
//#define LoRa_E220_DEBUG // #define LoRa_E220_DEBUG
// Define where debug output will be printed. // Define where debug output will be printed.
#define DEBUG_PRINTER Serial #define DEBUG_PRINTER Serial
// Setup debug printing macros. static const char *const TAG = "ebyte_lora_e220";
#ifdef LoRa_E220_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {}
#define DEBUG_PRINTLN(...) {}
#endif
enum MODE_TYPE { enum MODE_TYPE {
MODE_0_NORMAL = 0, MODE_0_NORMAL = 0,
MODE_0_TRANSMISSION = 0, MODE_0_TRANSMISSION = 0,
MODE_1_WOR_TRANSMITTER = 1, MODE_1_WOR_TRANSMITTER = 1,
MODE_1_WOR = 1, MODE_1_WOR = 1,
MODE_2_WOR_RECEIVER = 2, MODE_2_WOR_RECEIVER = 2,
MODE_2_POWER_SAVING = 2, MODE_2_POWER_SAVING = 2,
MODE_3_CONFIGURATION = 3, MODE_3_CONFIGURATION = 3,
MODE_3_PROGRAM = 3, MODE_3_PROGRAM = 3,
MODE_3_SLEEP = 3, MODE_3_SLEEP = 3,
MODE_INIT = 0xFF MODE_INIT = 0xFF
}; };
enum PROGRAM_COMMAND { enum PROGRAM_COMMAND {
WRITE_CFG_PWR_DWN_SAVE = 0xC0, WRITE_CFG_PWR_DWN_SAVE = 0xC0,
READ_CONFIGURATION = 0xC1, READ_CONFIGURATION = 0xC1,
WRITE_CFG_PWR_DWN_LOSE = 0xC2, WRITE_CFG_PWR_DWN_LOSE = 0xC2,
WRONG_FORMAT = 0xFF, WRONG_FORMAT = 0xFF,
RETURNED_COMMAND = 0xC1, RETURNED_COMMAND = 0xC1,
SPECIAL_WIFI_CONF_COMMAND = 0xCF SPECIAL_WIFI_CONF_COMMAND = 0xCF
}; };
enum REGISTER_ADDRESS { enum REGISTER_ADDRESS {
REG_ADDRESS_CFG = 0x00, REG_ADDRESS_CFG = 0x00,
REG_ADDRESS_SPED = 0x02, REG_ADDRESS_SPED = 0x02,
REG_ADDRESS_TRANS_MODE = 0x03, REG_ADDRESS_TRANS_MODE = 0x03,
REG_ADDRESS_CHANNEL = 0x04, REG_ADDRESS_CHANNEL = 0x04,
REG_ADDRESS_OPTION = 0x05, REG_ADDRESS_OPTION = 0x05,
REG_ADDRESS_CRYPT = 0x06, REG_ADDRESS_CRYPT = 0x06,
REG_ADDRESS_PID = 0x08 REG_ADDRESS_PID = 0x08
}; };
enum PACKET_LENGHT { enum PACKET_LENGHT {
PL_CONFIGURATION = 0x08, PL_CONFIGURATION = 0x08,
PL_SPED = 0x01, PL_SPED = 0x01,
PL_OPTION = 0x01, PL_OPTION = 0x01,
PL_TRANSMISSION_MODE= 0x01, PL_TRANSMISSION_MODE = 0x01,
PL_CHANNEL = 0x01, PL_CHANNEL = 0x01,
PL_CRYPT = 0x02, PL_CRYPT = 0x02,
PL_PID = 0x03 PL_PID = 0x03
}; };
#pragma pack(push, 1) #pragma pack(push, 1)
struct Speed { struct Speed {
uint8_t airDataRate :3; //bit 0-2 uint8_t airDataRate : 3; // bit 0-2
std::string getAirDataRateDescription() { std::string getAirDataRateDescription() { return getAirDataRateDescriptionByParams(this->airDataRate); }
return getAirDataRateDescriptionByParams(this->airDataRate);
}
uint8_t uartParity :2; //bit 3-4 uint8_t uartParity : 2; // bit 3-4
std::string getUARTParityDescription() { std::string getUARTParityDescription() { return getUARTParityDescriptionByParams(this->uartParity); }
return getUARTParityDescriptionByParams(this->uartParity);
}
uint8_t uartBaudRate :3; //bit 5-7
std::string getUARTBaudRateDescription() {
return getUARTBaudRateDescriptionByParams(this->uartBaudRate);
}
uint8_t uartBaudRate : 3; // bit 5-7
std::string getUARTBaudRateDescription() { return getUARTBaudRateDescriptionByParams(this->uartBaudRate); }
}; };
struct TransmissionMode { struct TransmissionMode {
byte WORPeriod :3; //bit 2,1,0 byte WORPeriod : 3; // bit 2,1,0
std::string getWORPeriodByParamsDescription() { std::string getWORPeriodByParamsDescription() { return getWORPeriodByParams(this->WORPeriod); }
return getWORPeriodByParams(this->WORPeriod); byte reserved2 : 1; // bit 3
} byte enableLBT : 1; // bit 4
byte reserved2 :1; //bit 3 std::string getLBTEnableByteDescription() { return getLBTEnableByteByParams(this->enableLBT); }
byte enableLBT :1; //bit 4 byte reserved : 1; // bit 5
std::string getLBTEnableByteDescription() {
return getLBTEnableByteByParams(this->enableLBT);
}
byte reserved :1; //bit 5
byte fixedTransmission :1; //bit 6 byte fixedTransmission : 1; // bit 6
std::string getFixedTransmissionDescription() { std::string getFixedTransmissionDescription() {
return getFixedTransmissionDescriptionByParams(this->fixedTransmission); return getFixedTransmissionDescriptionByParams(this->fixedTransmission);
} }
byte enableRSSI :1; //bit 7 byte enableRSSI : 1; // bit 7
std::string getRSSIEnableByteDescription() { std::string getRSSIEnableByteDescription() { return getRSSIEnableByteByParams(this->enableRSSI); }
return getRSSIEnableByteByParams(this->enableRSSI);
}
}; };
struct Option { struct Option {
uint8_t transmissionPower :2; //bit 0-1 uint8_t transmissionPower : 2; // bit 0-1
std::string getTransmissionPowerDescription() { std::string getTransmissionPowerDescription() {
return getTransmissionPowerDescriptionByParams(this->transmissionPower); return getTransmissionPowerDescriptionByParams(this->transmissionPower);
} }
uint8_t reserved :3; //bit 2-4 uint8_t reserved : 3; // bit 2-4
uint8_t RSSIAmbientNoise :1; //bit 5 uint8_t RSSIAmbientNoise : 1; // bit 5
std::string getRSSIAmbientNoiseEnable() { std::string getRSSIAmbientNoiseEnable() { return getRSSIAmbientNoiseEnableByParams(this->RSSIAmbientNoise); }
return getRSSIAmbientNoiseEnableByParams(this->RSSIAmbientNoise);
}
uint8_t subPacketSetting :2; //bit 6-7
std::string getSubPacketSetting() {
return getSubPacketSettingByParams(this->subPacketSetting);
}
uint8_t subPacketSetting : 2; // bit 6-7
std::string getSubPacketSetting() { return getSubPacketSettingByParams(this->subPacketSetting); }
}; };
struct Crypt { struct Crypt {
byte CRYPT_H = 0; byte CRYPT_H = 0;
byte CRYPT_L = 0; byte CRYPT_L = 0;
}; };
struct Configuration { struct Configuration {
byte COMMAND = 0; byte COMMAND = 0;
byte STARTING_ADDRESS = 0; byte STARTING_ADDRESS = 0;
byte LENGHT = 0; byte LENGHT = 0;
byte ADDH = 0; byte ADDH = 0;
byte ADDL = 0; byte ADDL = 0;
struct Speed SPED; struct Speed SPED;
struct Option OPTION; struct Option OPTION;
byte CHAN = 0; byte CHAN = 0;
std::string getChannelDescription() { std::string getChannelDescription() { return std::string(this->CHAN + OPERATING_FREQUENCY) + F("MHz"); }
return std::string(this->CHAN + OPERATING_FREQUENCY) + F("MHz");
}
struct TransmissionMode TRANSMISSION_MODE; struct TransmissionMode TRANSMISSION_MODE;
struct Crypt CRYPT; struct Crypt CRYPT;
}; };
struct ModuleInformation { struct ModuleInformation {
byte COMMAND = 0; byte COMMAND = 0;
byte STARTING_ADDRESS = 0; byte STARTING_ADDRESS = 0;
byte LENGHT = 0; byte LENGHT = 0;
byte model = 0; byte model = 0;
byte version = 0; byte version = 0;
byte features = 0; byte features = 0;
}; };
struct ResponseStatus { struct ResponseStatus {
std::std::string code; std::std::string code;
std::std::string getResponseDescription() { std::std::string getResponseDescription() { return getResponseDescriptionByParams(this->code); }
return getResponseDescriptionByParams(this->code);
}
}; };
struct ResponseStructContainer { struct ResponseStructContainer {
void *data; void *data;
byte rssi; byte rssi;
ResponseStatus status; ResponseStatus status;
void close() { void close() { free(this->data); }
free(this->data);
}
}; };
struct ResponseContainer { struct ResponseContainer {
std::string data; std::string data;
byte rssi; byte rssi;
ResponseStatus status; ResponseStatus status;
}; };
struct ConfigurationMessage struct ConfigurationMessage {
{ byte specialCommand1 = 0xCF;
byte specialCommand1 = 0xCF; byte specialCommand2 = 0xCF;
byte specialCommand2 = 0xCF;
unsigned char message[]; unsigned char message[];
}; };
//struct FixedStransmission { // struct FixedStransmission {
// byte ADDL = 0; // byte ADDL = 0;
// byte ADDH = 0; // byte ADDH = 0;
// byte CHAN = 0; // byte CHAN = 0;
// void *message; // void *message;
//}; // };
#pragma pack(pop) #pragma pack(pop)
class LoRa_E220 { class LoRa_E220 {
public: public:
#ifdef ACTIVATE_SOFTWARE_SERIAL LoRa_E220(HardwareSerial *serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E220(byte txE220pin, byte rxE220pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600); LoRa_E220(HardwareSerial *serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E220(byte txE220pin, byte rxE220pin, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600); LoRa_E220(HardwareSerial *serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E220(byte txE220pin, byte rxE220pin, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600); #ifdef HARDWARE_SERIAL_SELECTABLE_PIN
LoRa_E220(byte txE220pin, byte rxE220pin, HardwareSerial *serial, UART_BPS_RATE bpsRate,
uint32_t serialConfig = SERIAL_8N1);
LoRa_E220(byte txE220pin, byte rxE220pin, HardwareSerial *serial, byte auxPin, UART_BPS_RATE bpsRate,
uint32_t serialConfig = SERIAL_8N1);
LoRa_E220(byte txE220pin, byte rxE220pin, HardwareSerial *serial, byte auxPin, byte m0Pin, byte m1Pin,
UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1);
#endif #endif
bool begin();
Status setMode(MODE_TYPE mode);
MODE_TYPE getMode();
LoRa_E220(HardwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600); ResponseStructContainer getConfiguration();
LoRa_E220(HardwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600); ResponseStatus setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType = WRITE_CFG_PWR_DWN_LOSE);
LoRa_E220(HardwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
ResponseStructContainer getModuleInformation();
ResponseStatus resetModule();
ResponseStatus sendMessage(const void *message, const uint8_t size);
ResponseContainer receiveMessageUntil(char delimiter = '\0');
ResponseStructContainer receiveMessage(const uint8_t size);
ResponseStructContainer receiveMessageRSSI(const uint8_t size);
ResponseStructContainer receiveMessageComplete(const uint8_t size, bool enableRSSI);
ResponseContainer receiveMessageComplete(bool enableRSSI);
ResponseStatus sendMessage(const std::string message);
ResponseContainer receiveMessage();
ResponseContainer receiveMessageRSSI();
ResponseStatus sendFixedMessage(byte ADDH, byte ADDL, byte CHAN, const std::string message);
ResponseStatus sendFixedMessage(byte ADDH, byte ADDL, byte CHAN, const void *message, const uint8_t size);
ResponseStatus sendBroadcastFixedMessage(byte CHAN, const void *message, const uint8_t size);
ResponseStatus sendBroadcastFixedMessage(byte CHAN, const std::string message);
ResponseContainer receiveInitialMessage(const uint8_t size);
ResponseStatus sendConfigurationMessage(byte ADDH, byte ADDL, byte CHAN, Configuration *configuration,
PROGRAM_COMMAND programCommand = WRITE_CFG_PWR_DWN_SAVE);
int available();
private:
HardwareSerial *hs;
bool isSoftwareSerial = true;
int8_t txE220pin = -1;
int8_t rxE220pin = -1;
int8_t auxPin = -1;
#ifdef HARDWARE_SERIAL_SELECTABLE_PIN #ifdef HARDWARE_SERIAL_SELECTABLE_PIN
LoRa_E220(byte txE220pin, byte rxE220pin, HardwareSerial* serial, UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1); uint32_t serialConfig = SERIAL_8N1;
LoRa_E220(byte txE220pin, byte rxE220pin, HardwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1);
LoRa_E220(byte txE220pin, byte rxE220pin, HardwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate, uint32_t serialConfig = SERIAL_8N1);
#endif #endif
#ifdef ACTIVATE_SOFTWARE_SERIAL int8_t m0Pin = -1;
LoRa_E220(SoftwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600); int8_t m1Pin = -1;
LoRa_E220(SoftwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
LoRa_E220(SoftwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
#endif
// LoRa_E220(byte txE220pin, byte rxE220pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, MODE_TYPE mode = MODE_0_NORMAL); unsigned long halfKeyloqKey = 0x06660708;
// LoRa_E220(HardwareSerial* serial = &Serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, MODE_TYPE mode = MODE_0_NORMAL); unsigned long encrypt(unsigned long data);
// LoRa_E220(SoftwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, MODE_TYPE mode = MODE_0_NORMAL); unsigned long decrypt(unsigned long data);
bool begin(); UART_BPS_RATE bpsRate = UART_BPS_RATE_9600;
Status setMode(MODE_TYPE mode);
MODE_TYPE getMode();
ResponseStructContainer getConfiguration(); struct NeedsStream {
ResponseStatus setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType = WRITE_CFG_PWR_DWN_LOSE); template<typename T> void begin(T &t, uint32_t baud) {
ESP_LOGD(TAG, "Begin ");
ResponseStructContainer getModuleInformation(); t.setTimeout(500);
ResponseStatus resetModule(); t.begin(baud);
stream = &t;
ResponseStatus sendMessage(const void *message, const uint8_t size); }
ResponseContainer receiveMessageUntil(char delimiter = '\0');
ResponseStructContainer receiveMessage(const uint8_t size);
ResponseStructContainer receiveMessageRSSI(const uint8_t size);
ResponseStructContainer receiveMessageComplete(const uint8_t size, bool enableRSSI);
ResponseContainer receiveMessageComplete(bool enableRSSI);
ResponseStatus sendMessage(const std::string message);
ResponseContainer receiveMessage();
ResponseContainer receiveMessageRSSI();
ResponseStatus sendFixedMessage(byte ADDH, byte ADDL, byte CHAN, const std::string message);
ResponseStatus sendFixedMessage(byte ADDH,byte ADDL, byte CHAN, const void *message, const uint8_t size);
ResponseStatus sendBroadcastFixedMessage(byte CHAN, const void *message, const uint8_t size);
ResponseStatus sendBroadcastFixedMessage(byte CHAN, const std::string message);
ResponseContainer receiveInitialMessage(const uint8_t size);
ResponseStatus sendConfigurationMessage( byte ADDH,byte ADDL, byte CHAN, Configuration *configuration, PROGRAM_COMMAND programCommand = WRITE_CFG_PWR_DWN_SAVE);
int available();
private:
HardwareSerial* hs;
#ifdef ACTIVATE_SOFTWARE_SERIAL
SoftwareSerial* ss;
#endif
bool isSoftwareSerial = true;
int8_t txE220pin = -1;
int8_t rxE220pin = -1;
int8_t auxPin = -1;
#ifdef HARDWARE_SERIAL_SELECTABLE_PIN #ifdef HARDWARE_SERIAL_SELECTABLE_PIN
uint32_t serialConfig = SERIAL_8N1; template<typename T> void begin(T &t, uint32_t baud, uint32_t config) {
ESP_LOGD(TAG, "Begin ");
t.setTimeout(500);
t.begin(baud, config);
stream = &t;
}
template<typename T> void begin(T &t, uint32_t baud, uint32_t config, int8_t txE220pin, int8_t rxE220pin) {
ESP_LOGD(TAG, "Begin ");
t.setTimeout(500);
t.begin(baud, config, txE220pin, rxE220pin);
stream = &t;
}
#endif #endif
int8_t m0Pin = -1; void listen() {}
int8_t m1Pin = -1;
unsigned long halfKeyloqKey = 0x06660708; Stream *stream;
unsigned long encrypt(unsigned long data); };
unsigned long decrypt(unsigned long data); NeedsStream serialDef;
UART_BPS_RATE bpsRate = UART_BPS_RATE_9600; MODE_TYPE mode = MODE_0_NORMAL;
struct NeedsStream { void managedDelay(unsigned long timeout);
template<typename T> Status waitCompleteResponse(unsigned long timeout = 1000, unsigned int waitNoAux = 100);
void begin(T &t, uint32_t baud) { void flush();
DEBUG_PRINTLN("Begin "); void cleanUARTBuffer();
t.setTimeout(500);
t.begin(baud);
stream = &t;
}
#ifdef HARDWARE_SERIAL_SELECTABLE_PIN Status sendStruct(void *structureManaged, uint16_t size_);
// template< typename T > Status receiveStruct(void *structureManaged, uint16_t size_);
// void begin( T &t, uint32_t baud, SerialConfig config ){ bool writeProgramCommand(PROGRAM_COMMAND cmd, REGISTER_ADDRESS addr, PACKET_LENGHT pl);
// DEBUG_PRINTLN("Begin ");
// t.setTimeout(500);
// t.begin(baud, config);
// stream = &t;
// }
//
template< typename T >
void begin( T &t, uint32_t baud, uint32_t config ) {
DEBUG_PRINTLN("Begin ");
t.setTimeout(500);
t.begin(baud, config);
stream = &t;
}
template< typename T > RESPONSE_STATUS checkUARTConfiguration(MODE_TYPE mode);
void begin( T &t, uint32_t baud, uint32_t config, int8_t txE220pin, int8_t rxE220pin ) {
DEBUG_PRINTLN("Begin ");
t.setTimeout(500);
t.begin(baud, config, txE220pin, rxE220pin);
stream = &t;
}
#endif
void listen() {}
Stream *stream;
};
NeedsStream serialDef;
MODE_TYPE mode = MODE_0_NORMAL;
void managedDelay(unsigned long timeout);
Status waitCompleteResponse(unsigned long timeout = 1000, unsigned int waitNoAux = 100);
void flush();
void cleanUARTBuffer();
Status sendStruct(void *structureManaged, uint16_t size_);
Status receiveStruct(void *structureManaged, uint16_t size_);
bool writeProgramCommand(PROGRAM_COMMAND cmd, REGISTER_ADDRESS addr, PACKET_LENGHT pl);
RESPONSE_STATUS checkUARTConfiguration(MODE_TYPE mode);
#ifdef LoRa_E220_DEBUG #ifdef LoRa_E220_DEBUG
void printParameters(struct Configuration *configuration); void printParameters(struct Configuration *configuration);
#endif #endif
}; };

View file

@ -1,19 +1,19 @@
#include "Arduino.h" #include "Arduino.h"
#ifdef FREQUENCY_433 #ifdef FREQUENCY_433
#define OPERATING_FREQUENCY 410 #define OPERATING_FREQUENCY 410
#elif defined(FREQUENCY_400) #elif defined(FREQUENCY_400)
#define OPERATING_FREQUENCY 410 #define OPERATING_FREQUENCY 410
#elif defined(FREQUENCY_230) #elif defined(FREQUENCY_230)
#define OPERATING_FREQUENCY 220 #define OPERATING_FREQUENCY 220
#elif defined(FREQUENCY_868) #elif defined(FREQUENCY_868)
#define OPERATING_FREQUENCY 850 #define OPERATING_FREQUENCY 850
#elif defined(FREQUENCY_900) #elif defined(FREQUENCY_900)
#define OPERATING_FREQUENCY 850 #define OPERATING_FREQUENCY 850
#elif defined(FREQUENCY_915) #elif defined(FREQUENCY_915)
#define OPERATING_FREQUENCY 900 #define OPERATING_FREQUENCY 900
#else #else
#define OPERATING_FREQUENCY 410 #define OPERATING_FREQUENCY 410
#endif #endif
#define BROADCAST_ADDRESS 255 #define BROADCAST_ADDRESS 255
@ -23,7 +23,7 @@ typedef enum RESPONSE_STATUS {
SUCCESS = 1, SUCCESS = 1,
#endif #endif
E220_SUCCESS = 1, E220_SUCCESS = 1,
ERR_E220_UNKNOWN, /* something shouldn't happened */ ERR_E220_UNKNOWN, /* something shouldn't happened */
ERR_E220_NOT_SUPPORT, ERR_E220_NOT_SUPPORT,
ERR_E220_NOT_IMPLEMENT, ERR_E220_NOT_IMPLEMENT,
ERR_E220_NOT_INITIAL, ERR_E220_NOT_INITIAL,
@ -39,86 +39,77 @@ typedef enum RESPONSE_STATUS {
ERR_E220_PACKET_TOO_BIG ERR_E220_PACKET_TOO_BIG
} Status; } Status;
static String getResponseDescriptionByParams(byte status){ static std::string getResponseDescriptionByParams(byte status) {
switch (status) switch (status) {
{ case E220_SUCCESS:
case E220_SUCCESS: return "Success";
return F("Success"); break;
break; case ERR_E220_UNKNOWN:
case ERR_E220_UNKNOWN: return "Unknown";
return F("Unknown"); break;
break; case ERR_E220_NOT_SUPPORT:
case ERR_E220_NOT_SUPPORT: return "Not support!";
return F("Not support!"); break;
break; case ERR_E220_NOT_IMPLEMENT:
case ERR_E220_NOT_IMPLEMENT: return "Not implement";
return F("Not implement"); break;
break; case ERR_E220_NOT_INITIAL:
case ERR_E220_NOT_INITIAL: return "Not initial!";
return F("Not initial!"); break;
break; case ERR_E220_INVALID_PARAM:
case ERR_E220_INVALID_PARAM: return "Invalid param!";
return F("Invalid param!"); break;
break; case ERR_E220_DATA_SIZE_NOT_MATCH:
case ERR_E220_DATA_SIZE_NOT_MATCH: return "Data size not match!";
return F("Data size not match!"); break;
break; case ERR_E220_BUF_TOO_SMALL:
case ERR_E220_BUF_TOO_SMALL: return "Buff too small!";
return F("Buff too small!"); break;
break; case ERR_E220_TIMEOUT:
case ERR_E220_TIMEOUT: return "Timeout!!";
return F("Timeout!!"); break;
break; case ERR_E220_HARDWARE:
case ERR_E220_HARDWARE: return "Hardware error!";
return F("Hardware error!"); break;
break; case ERR_E220_HEAD_NOT_RECOGNIZED:
case ERR_E220_HEAD_NOT_RECOGNIZED: return "Save mode returned not recognized!";
return F("Save mode returned not recognized!"); break;
break; case ERR_E220_NO_RESPONSE_FROM_DEVICE:
case ERR_E220_NO_RESPONSE_FROM_DEVICE: return "No response from device! (Check wiring)";
return F("No response from device! (Check wiring)"); break;
break; case ERR_E220_WRONG_UART_CONFIG:
case ERR_E220_WRONG_UART_CONFIG: return "Wrong UART configuration! (BPS must be 9600 for configuration)";
return F("Wrong UART configuration! (BPS must be 9600 for configuration)"); break;
break; case ERR_E220_PACKET_TOO_BIG:
case ERR_E220_PACKET_TOO_BIG: return "The device support only 200byte of data transmission!";
return F("The device support only 200byte of data transmission!"); break;
break; default:
default: return "Invalid status!";
return F("Invalid status!"); }
}
} }
enum E220_UART_PARITY enum E220_UART_PARITY { MODE_00_8N1 = 0b00, MODE_01_8O1 = 0b01, MODE_10_8E1 = 0b10, MODE_11_8N1 = 0b11 };
{
MODE_00_8N1 = 0b00,
MODE_01_8O1 = 0b01,
MODE_10_8E1 = 0b10,
MODE_11_8N1 = 0b11
};
static String getUARTParityDescriptionByParams(byte uartParity){ static std::string getUARTParityDescriptionByParams(byte uartParity) {
switch (uartParity) switch (uartParity) {
{ case MODE_00_8N1:
case MODE_00_8N1: return "8N1 (Default)";
return F("8N1 (Default)"); break;
break; case MODE_01_8O1:
case MODE_01_8O1: return "8O1";
return F("8O1"); break;
break; case MODE_10_8E1:
case MODE_10_8E1: return "8E1";
return F("8E1"); break;
break; case MODE_11_8N1:
case MODE_11_8N1: return "8N1 (equal to 00";
return F("8N1 (equal to 00"); break;
break; default:
default: return "Invalid UART Parity!";
return F("Invalid UART Parity!"); }
}
} }
enum UART_BPS_TYPE enum UART_BPS_TYPE {
{
UART_BPS_1200 = 0b000, UART_BPS_1200 = 0b000,
UART_BPS_2400 = 0b001, UART_BPS_2400 = 0b001,
UART_BPS_4800 = 0b010, UART_BPS_4800 = 0b010,
@ -129,8 +120,7 @@ enum UART_BPS_TYPE
UART_BPS_115200 = 0b111 UART_BPS_115200 = 0b111
}; };
enum UART_BPS_RATE enum UART_BPS_RATE {
{
UART_BPS_RATE_1200 = 1200, UART_BPS_RATE_1200 = 1200,
UART_BPS_RATE_2400 = 2400, UART_BPS_RATE_2400 = 2400,
UART_BPS_RATE_4800 = 4800, UART_BPS_RATE_4800 = 4800,
@ -141,41 +131,38 @@ enum UART_BPS_RATE
UART_BPS_RATE_115200 = 115200 UART_BPS_RATE_115200 = 115200
}; };
static String getUARTBaudRateDescriptionByParams(byte uartBaudRate) static std::string getUARTBaudRateDescriptionByParams(byte uartBaudRate) {
{ switch (uartBaudRate) {
switch (uartBaudRate) case UART_BPS_1200:
{ return "1200bps";
case UART_BPS_1200: break;
return F("1200bps"); case UART_BPS_2400:
break; return "2400bps";
case UART_BPS_2400: break;
return F("2400bps"); case UART_BPS_4800:
break; return "4800bps";
case UART_BPS_4800: break;
return F("4800bps"); case UART_BPS_9600:
break; return "9600bps (default)";
case UART_BPS_9600: break;
return F("9600bps (default)"); case UART_BPS_19200:
break; return "19200bps";
case UART_BPS_19200: break;
return F("19200bps"); case UART_BPS_38400:
break; return "38400bps";
case UART_BPS_38400: break;
return F("38400bps"); case UART_BPS_57600:
break; return "57600bps";
case UART_BPS_57600: break;
return F("57600bps"); case UART_BPS_115200:
break; return "115200bps";
case UART_BPS_115200: break;
return F("115200bps"); default:
break; return "Invalid UART Baud Rate!";
default: }
return F("Invalid UART Baud Rate!");
}
} }
enum AIR_DATA_RATE enum AIR_DATA_RATE {
{
AIR_DATA_RATE_000_24 = 0b000, AIR_DATA_RATE_000_24 = 0b000,
AIR_DATA_RATE_001_24 = 0b001, AIR_DATA_RATE_001_24 = 0b001,
AIR_DATA_RATE_010_24 = 0b010, AIR_DATA_RATE_010_24 = 0b010,
@ -186,278 +173,240 @@ enum AIR_DATA_RATE
AIR_DATA_RATE_111_625 = 0b111 AIR_DATA_RATE_111_625 = 0b111
}; };
static std::string getAirDataRateDescriptionByParams(byte airDataRate) {
static String getAirDataRateDescriptionByParams(byte airDataRate) switch (airDataRate) {
{ case AIR_DATA_RATE_000_24:
switch (airDataRate) return "2.4kbps";
{ break;
case AIR_DATA_RATE_000_24: case AIR_DATA_RATE_001_24:
return F("2.4kbps"); return "2.4kbps";
break; break;
case AIR_DATA_RATE_001_24: case AIR_DATA_RATE_010_24:
return F("2.4kbps"); return "2.4kbps (default)";
break; break;
case AIR_DATA_RATE_010_24: case AIR_DATA_RATE_011_48:
return F("2.4kbps (default)"); return "4.8kbps";
break; break;
case AIR_DATA_RATE_011_48: case AIR_DATA_RATE_100_96:
return F("4.8kbps"); return "9.6kbps";
break; break;
case AIR_DATA_RATE_100_96: case AIR_DATA_RATE_101_192:
return F("9.6kbps"); return "19.2kbps";
break; break;
case AIR_DATA_RATE_101_192: case AIR_DATA_RATE_110_384:
return F("19.2kbps"); return "38.4kbps";
break; break;
case AIR_DATA_RATE_110_384: case AIR_DATA_RATE_111_625:
return F("38.4kbps"); return "62.5kbps";
break; break;
case AIR_DATA_RATE_111_625: default:
return F("62.5kbps"); return "Invalid Air Data Rate!";
break; }
default:
return F("Invalid Air Data Rate!");
}
} }
enum SUB_PACKET_SETTING { enum SUB_PACKET_SETTING {
SPS_200_00 = 0b00, SPS_200_00 = 0b00,
SPS_128_01 = 0b01, SPS_128_01 = 0b01,
SPS_064_10 = 0b10, SPS_064_10 = 0b10,
SPS_032_11 = 0b11 SPS_032_11 = 0b11
}; };
static String getSubPacketSettingByParams(byte subPacketSetting) static std::string getSubPacketSettingByParams(byte subPacketSetting) {
{ switch (subPacketSetting) {
switch (subPacketSetting) case SPS_200_00:
{ return "200bytes (default)";
case SPS_200_00: break;
return F("200bytes (default)"); case SPS_128_01:
break; return "128bytes";
case SPS_128_01: break;
return F("128bytes"); case SPS_064_10:
break; return "64bytes";
case SPS_064_10: break;
return F("64bytes"); case SPS_032_11:
break; return "32bytes";
case SPS_032_11: break;
return F("32bytes"); default:
break; return "Invalid Sub Packet Setting!";
default: }
return F("Invalid Sub Packet Setting!");
}
} }
enum RSSI_AMBIENT_NOISE_ENABLE { enum RSSI_AMBIENT_NOISE_ENABLE { RSSI_AMBIENT_NOISE_ENABLED = 0b1, RSSI_AMBIENT_NOISE_DISABLED = 0b0 };
RSSI_AMBIENT_NOISE_ENABLED = 0b1, static std::string getRSSIAmbientNoiseEnableByParams(byte rssiAmbientNoiseEnabled) {
RSSI_AMBIENT_NOISE_DISABLED = 0b0 switch (rssiAmbientNoiseEnabled) {
}; case RSSI_AMBIENT_NOISE_ENABLED:
static String getRSSIAmbientNoiseEnableByParams(byte rssiAmbientNoiseEnabled) return "Enabled";
{ break;
switch (rssiAmbientNoiseEnabled) case RSSI_AMBIENT_NOISE_DISABLED:
{ return "Disabled (default)";
case RSSI_AMBIENT_NOISE_ENABLED: break;
return F("Enabled"); default:
break; return "Invalid RSSI Ambient Noise enabled!";
case RSSI_AMBIENT_NOISE_DISABLED: }
return F("Disabled (default)");
break;
default:
return F("Invalid RSSI Ambient Noise enabled!");
}
} }
enum WOR_PERIOD { enum WOR_PERIOD {
WOR_500_000 = 0b000, WOR_500_000 = 0b000,
WOR_1000_001 = 0b001, WOR_1000_001 = 0b001,
WOR_1500_010 = 0b010, WOR_1500_010 = 0b010,
WOR_2000_011 = 0b011, WOR_2000_011 = 0b011,
WOR_2500_100 = 0b100, WOR_2500_100 = 0b100,
WOR_3000_101 = 0b101, WOR_3000_101 = 0b101,
WOR_3500_110 = 0b110, WOR_3500_110 = 0b110,
WOR_4000_111 = 0b111 WOR_4000_111 = 0b111
}; };
static String getWORPeriodByParams(byte WORPeriod) static std::string getWORPeriodByParams(byte WORPeriod) {
{ switch (WORPeriod) {
switch (WORPeriod) case WOR_500_000:
{ return "500ms";
case WOR_500_000: break;
return F("500ms"); case WOR_1000_001:
break; return "1000ms";
case WOR_1000_001: break;
return F("1000ms"); case WOR_1500_010:
break; return "1500ms";
case WOR_1500_010: break;
return F("1500ms"); case WOR_2000_011:
break; return "2000ms (default)";
case WOR_2000_011: break;
return F("2000ms (default)"); case WOR_2500_100:
break; return "2500ms";
case WOR_2500_100: break;
return F("2500ms"); case WOR_3000_101:
break; return "3000ms";
case WOR_3000_101: break;
return F("3000ms"); case WOR_3500_110:
break; return "3500ms";
case WOR_3500_110: break;
return F("3500ms"); case WOR_4000_111:
break; return "4000ms";
case WOR_4000_111: break;
return F("4000ms"); default:
break; return "Invalid WOR period!";
default: }
return F("Invalid WOR period!");
}
} }
enum LBT_ENABLE_BYTE { enum LBT_ENABLE_BYTE { LBT_ENABLED = 0b1, LBT_DISABLED = 0b0 };
LBT_ENABLED = 0b1, static std::string getLBTEnableByteByParams(byte LBTEnableByte) {
LBT_DISABLED = 0b0 switch (LBTEnableByte) {
}; case LBT_ENABLED:
static String getLBTEnableByteByParams(byte LBTEnableByte) return "Enabled";
{ break;
switch (LBTEnableByte) case LBT_DISABLED:
{ return "Disabled (default)";
case LBT_ENABLED: break;
return F("Enabled"); default:
break; return "Invalid LBT enable byte!";
case LBT_DISABLED: }
return F("Disabled (default)");
break;
default:
return F("Invalid LBT enable byte!");
}
} }
enum RSSI_ENABLE_BYTE { enum RSSI_ENABLE_BYTE { RSSI_ENABLED = 0b1, RSSI_DISABLED = 0b0 };
RSSI_ENABLED = 0b1, static std::string getRSSIEnableByteByParams(byte RSSIEnableByte) {
RSSI_DISABLED = 0b0 switch (RSSIEnableByte) {
}; case RSSI_ENABLED:
static String getRSSIEnableByteByParams(byte RSSIEnableByte) return "Enabled";
{ break;
switch (RSSIEnableByte) case RSSI_DISABLED:
{ return "Disabled (default)";
case RSSI_ENABLED: break;
return F("Enabled"); default:
break; return "Invalid RSSI enable byte!";
case RSSI_DISABLED: }
return F("Disabled (default)");
break;
default:
return F("Invalid RSSI enable byte!");
}
} }
enum FIDEX_TRANSMISSION enum FIDEX_TRANSMISSION { FT_TRANSPARENT_TRANSMISSION = 0b0, FT_FIXED_TRANSMISSION = 0b1 };
{
FT_TRANSPARENT_TRANSMISSION = 0b0,
FT_FIXED_TRANSMISSION = 0b1
};
static std::string getFixedTransmissionDescriptionByParams(byte fixedTransmission) {
static String getFixedTransmissionDescriptionByParams(byte fixedTransmission) switch (fixedTransmission) {
{ case FT_TRANSPARENT_TRANSMISSION:
switch (fixedTransmission) return "Transparent transmission (default)";
{ break;
case FT_TRANSPARENT_TRANSMISSION: case FT_FIXED_TRANSMISSION:
return F("Transparent transmission (default)"); return "Fixed transmission (first three bytes can be used as high/low address and channel)";
break; break;
case FT_FIXED_TRANSMISSION: default:
return F("Fixed transmission (first three bytes can be used as high/low address and channel)"); return "Invalid fixed transmission param!";
break; }
default:
return F("Invalid fixed transmission param!");
}
} }
#ifdef E220_22 #ifdef E220_22
enum TRANSMISSION_POWER enum TRANSMISSION_POWER {
{ POWER_22 = 0b00,
POWER_22 = 0b00, POWER_17 = 0b01,
POWER_17 = 0b01, POWER_13 = 0b10,
POWER_13 = 0b10, POWER_10 = 0b11
POWER_10 = 0b11
}; };
static String getTransmissionPowerDescriptionByParams(byte transmissionPower) static std::string getTransmissionPowerDescriptionByParams(byte transmissionPower) {
{ switch (transmissionPower) {
switch (transmissionPower) case POWER_22:
{ return "22dBm (Default)";
case POWER_22: break;
return F("22dBm (Default)"); case POWER_17:
break; return "17dBm";
case POWER_17: break;
return F("17dBm"); case POWER_13:
break; return "13dBm";
case POWER_13: break;
return F("13dBm"); case POWER_10:
break; return "10dBm";
case POWER_10: break;
return F("10dBm"); default:
break; return "Invalid transmission power param";
default: }
return F("Invalid transmission power param"); }
}
}
#elif defined(E220_30) #elif defined(E220_30)
enum TRANSMISSION_POWER enum TRANSMISSION_POWER {
{ POWER_30 = 0b00,
POWER_30 = 0b00, POWER_27 = 0b01,
POWER_27 = 0b01, POWER_24 = 0b10,
POWER_24 = 0b10, POWER_21 = 0b11
POWER_21 = 0b11
}; };
static String getTransmissionPowerDescriptionByParams(byte transmissionPower) static std::string getTransmissionPowerDescriptionByParams(byte transmissionPower) {
{ switch (transmissionPower) {
switch (transmissionPower) case POWER_30:
{ return "30dBm (Default)";
case POWER_30: break;
return F("30dBm (Default)"); case POWER_27:
break; return "27dBm";
case POWER_27: break;
return F("27dBm"); case POWER_24:
break; return "24dBm";
case POWER_24: break;
return F("24dBm"); case POWER_21:
break; return "21dBm";
case POWER_21: break;
return F("21dBm"); default:
break; return "Invalid transmission power param";
default: }
return F("Invalid transmission power param"); }
}
}
#else #else
enum TRANSMISSION_POWER enum TRANSMISSION_POWER {
{ POWER_22 = 0b00,
POWER_22 = 0b00, POWER_17 = 0b01,
POWER_17 = 0b01, POWER_13 = 0b10,
POWER_13 = 0b10, POWER_10 = 0b11
POWER_10 = 0b11
}; };
static String getTransmissionPowerDescriptionByParams(byte transmissionPower) static std::string getTransmissionPowerDescriptionByParams(byte transmissionPower) {
{ switch (transmissionPower) {
switch (transmissionPower) case POWER_22:
{ return "22dBm (Default)";
case POWER_22: break;
return F("22dBm (Default)"); case POWER_17:
break; return "17dBm";
case POWER_17: break;
return F("17dBm"); case POWER_13:
break; return "13dBm";
case POWER_13: break;
return F("13dBm"); case POWER_10:
break; return "10dBm";
case POWER_10: break;
return F("10dBm"); default:
break; return "Invalid transmission power param";
default: }
return F("Invalid transmission power param"); }
}
}
#endif #endif