this should work

This commit is contained in:
Daniël Koek 2024-03-29 13:15:20 +00:00
parent 6664333e31
commit c8f5420218
3 changed files with 92 additions and 119 deletions

View file

@ -4,7 +4,7 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
namespace esphome { namespace esphome {
namespace ebyte_lora { namespace ebyte_lora {
static const char *const TAG = "ebyte_lora";
// check your data sheet to see what the values are, since each module does it diffrent // check your data sheet to see what the values are, since each module does it diffrent
enum ENABLE_BYTE { ENABLED = 0b1, DISABLED = 0b0 }; enum ENABLE_BYTE { ENABLED = 0b1, DISABLED = 0b0 };
@ -30,75 +30,58 @@ enum UART_BPS_SPEED {
enum UART_PARITY { _8N1 = 0b00, _8O1 = 0b01, _8E1 = 0b10 }; enum UART_PARITY { _8N1 = 0b00, _8O1 = 0b01, _8E1 = 0b10 };
struct REG0 { struct REG0 {
uint8_t air_data_rate : 3; uint8_t air_data_rate : 3;
void air_data_rate_description_() { std::string air_data_rate_description_() {
switch (this->air_data_rate) { switch (this->air_data_rate) {
case _2_4kb: case _2_4kb:
ESP_LOGD(TAG, "air_data_rate: 2.4kb"); return "air_data_rate: 2.4kb";
break;
case _4_8kb: case _4_8kb:
ESP_LOGD(TAG, "air_data_rate: 4.8kb"); return "air_data_rate: 4.8kb";
break;
case _9_6kb: case _9_6kb:
ESP_LOGD(TAG, "air_data_rate: 9.6kb"); return "air_data_rate: 9.6kb";
break;
case _19_2kb: case _19_2kb:
ESP_LOGD(TAG, "air_data_rate: 19.2kb"); return "air_data_rate: 19.2kb";
break;
case _38_4kb: case _38_4kb:
ESP_LOGD(TAG, "air_data_rate: 38.4kb"); return "air_data_rate: 38.4kb";
break;
case _62_5kb: case _62_5kb:
ESP_LOGD(TAG, "air_data_rate: 62.5kb"); return "air_data_rate: 62.5kb";
break;
default: default:
break; return "";
} }
} }
uint8_t parity : 2; uint8_t parity : 2;
void parity_description_() { std::string parity_description_() {
switch (this->parity) { switch (this->parity) {
case _8N1: case _8N1:
ESP_LOGD(TAG, "uart_parity: 8N1"); return "uart_parity: 8N1";
break;
case _8O1: case _8O1:
ESP_LOGD(TAG, "uart_parity: 8O1"); return "uart_parity: 8O1";
break;
case _8E1: case _8E1:
ESP_LOGD(TAG, "uart_parity: 8E1"); return "uart_parity: 8E1";
break;
default: default:
break; return "";
} }
} }
uint8_t uart_baud : 3; uint8_t uart_baud : 3;
void uart_baud_description_() { std::string uart_baud_description_() {
switch (this->uart_baud) { switch (this->uart_baud) {
case _1200: case _1200:
ESP_LOGD(TAG, "uart_baud: 1200"); return "uart_baud: 1200";
break;
case _2400: case _2400:
ESP_LOGD(TAG, "uart_baud: 2400"); return "uart_baud: 2400";
break;
case _4800: case _4800:
ESP_LOGD(TAG, "uart_baud: 4800"); return "uart_baud: 4800";
break;
case _9600: case _9600:
ESP_LOGD(TAG, "uart_baud: 9600"); return "uart_baud: 9600";
break;
case _19200: case _19200:
ESP_LOGD(TAG, "uart_baud: 19200"); return "uart_baud: 19200";
break;
case _38400: case _38400:
ESP_LOGD(TAG, "uart_baud: 38400"); return "uart_baud: 38400";
break;
case _57600: case _57600:
ESP_LOGD(TAG, "uart_baud: 57600"); return "uart_baud: 57600";
break;
case _115200: case _115200:
ESP_LOGD(TAG, "uart_baud: 115200"); return "uart_baud: 115200";
break;
default: default:
break; return "";
} }
} }
}; };
@ -113,55 +96,48 @@ enum SUB_PACKET_SETTING { _200b = 0b00, _128b = 0b01, _64b = 0b10, _32b = 0b11 }
// again in reverse order on the data sheet // again in reverse order on the data sheet
struct REG1 { struct REG1 {
uint8_t transmission_power : 2; uint8_t transmission_power : 2;
void transmission_power_description_() { std::string transmission_power_description_() {
switch (this->transmission_power) { switch (this->transmission_power) {
case _DEFAULT_MAX: case _DEFAULT_MAX:
ESP_LOGD(TAG, "transmission_power: default or max"); return "transmission_power: default or max";
break;
case _LOWER: case _LOWER:
ESP_LOGD(TAG, "transmission_power: lower"); return "transmission_power: lower";
break;
case _EVEN_LOWER: case _EVEN_LOWER:
ESP_LOGD(TAG, "transmission_power: even lower"); return "transmission_power: even lower";
break;
case _LOWEST: case _LOWEST:
ESP_LOGD(TAG, "transmission_power: Lowest"); return "transmission_power: Lowest";
break;
default: default:
break; return "";
} }
} }
uint8_t reserve : 3; uint8_t reserve : 3;
uint8_t rssi_noise : 1; uint8_t rssi_noise : 1;
void rssi_noise_description_() { std::string rssi_noise_description_() {
switch (this->rssi_noise) { switch (this->rssi_noise) {
case ENABLED: case ENABLED:
ESP_LOGD(TAG, "rssi_noise: ENABLED"); return "rssi_noise: ENABLED";
break;
case DISABLED: case DISABLED:
ESP_LOGD(TAG, "rssi_noise: DISABLED"); return "rssi_noise: DISABLED";
break;
default: default:
break; return "";
} }
} }
uint8_t sub_packet : 2; uint8_t sub_packet : 2;
void sub_packet_description_() { std::string sub_packet_description_() {
switch (this->sub_packet) { switch (this->sub_packet) {
case _200b: case _200b:
ESP_LOGD(TAG, "sub_packet: 200 bytes"); return "sub_packet: 200 bytes";
break;
case _128b: case _128b:
ESP_LOGD(TAG, "sub_packet: 128 bytes"); return "sub_packet: 128 bytes";
break;
case _64b: case _64b:
ESP_LOGD(TAG, "sub_packet: 64 bytes"); return "sub_packet: 64 bytes";
break;
case _32b: case _32b:
ESP_LOGD(TAG, "sub_packet: 32 bytes"); return "sub_packet: 32 bytes";
break;
default: default:
break; return "";
} }
} }
}; };
@ -180,75 +156,71 @@ enum WOR_PERIOD {
// reverse order on the data sheet // reverse order on the data sheet
struct REG3 { struct REG3 {
uint8_t wor_period : 3; uint8_t wor_period : 3;
void wor_period_description_() { std::string wor_period_description_() {
switch (this->wor_period) { switch (this->wor_period) {
case _500: case _500:
ESP_LOGD(TAG, "wor_period: 500"); return "wor_period: 500";
break;
case _1000: case _1000:
ESP_LOGD(TAG, "wor_period: 1000"); return "wor_period: 1000";
break;
case _1500: case _1500:
ESP_LOGD(TAG, "wor_period: 1500"); return "wor_period: 1500";
break;
case _2000: case _2000:
ESP_LOGD(TAG, "wor_period: 2000"); return "wor_period: 2000";
break;
case _2500: case _2500:
ESP_LOGD(TAG, "wor_period: 2500"); return "wor_period: 2500";
break;
case _3000: case _3000:
ESP_LOGD(TAG, "wor_period: 3000"); return "wor_period: 3000";
break;
case _3500: case _3500:
ESP_LOGD(TAG, "wor_period: 3500"); return "wor_period: 3500";
break;
case _4000: case _4000:
ESP_LOGD(TAG, "wor_period: 4000"); return "wor_period: 4000";
break;
default: default:
break; return "";
} }
} }
uint8_t reserve1 : 1; uint8_t reserve1 : 1;
uint8_t enable_lbt : 1; uint8_t enable_lbt : 1;
void enable_lbt_description_() { std::string enable_lbt_description_() {
switch (this->enable_lbt) { switch (this->enable_lbt) {
case ENABLED: case ENABLED:
ESP_LOGD(TAG, "enable_lbt: ENABLED"); return "enable_lbt: ENABLED";
break;
case DISABLED: case DISABLED:
ESP_LOGD(TAG, "enable_lbt: DISABLED"); return "enable_lbt: DISABLED";
break;
default: default:
break;
} }
} }
uint8_t reserve2 : 1; uint8_t reserve2 : 1;
uint8_t transmission_mode : 1; uint8_t transmission_mode : 1;
void transmission_type_description_() { std::string transmission_type_description_() {
switch (this->transmission_mode) { switch (this->transmission_mode) {
case TRANSPARENT: case TRANSPARENT:
ESP_LOGD(TAG, "transmission_type: TRANSPARENT"); return "transmission_type: TRANSPARENT";
break;
case FIXED: case FIXED:
ESP_LOGD(TAG, "transmission_type: FIXED"); return "transmission_type: FIXED";
break;
default: default:
break; return "";
} }
} }
uint8_t enable_rssi : 1; uint8_t enable_rssi : 1;
void enable_rssi_description_() { std::string enable_rssi_description_() {
switch (this->enable_rssi) { switch (this->enable_rssi) {
case ENABLED: case ENABLED:
ESP_LOGD(TAG, "enable_rssi: ENABLED"); return "enable_rssi: ENABLED";
break;
case DISABLED: case DISABLED:
ESP_LOGD(TAG, "enable_rssi: DISABLED"); return "enable_rssi: DISABLED";
break;
default: default:
break; return "";
} }
} }
}; };
@ -258,14 +230,14 @@ struct RegisterConfig {
uint8_t starting_address = 0; uint8_t starting_address = 0;
uint8_t length = 0; uint8_t length = 0;
uint8_t addh = 0; uint8_t addh = 0;
void addh_description_() { ESP_LOGD(TAG, "addh: %u", this->addh); } std::string addh_description_() { return "addh:" + this->addh; }
uint8_t addl = 0; uint8_t addl = 0;
void addl_description_() { ESP_LOGD(TAG, "addl: %u", this->addh); } std::string addl_description_() { return "addl:" + this->addh; }
struct REG0 reg_0; struct REG0 reg_0;
struct REG1 reg_1; struct REG1 reg_1;
// reg2 // reg2
uint8_t channel; uint8_t channel;
void channel_description_() { ESP_LOGD(TAG, "channel: %u", this->channel); } std::string channel_description_() { return "channel:" + this->channel; }
struct REG3 reg_3; struct REG3 reg_3;
uint8_t crypt_h; uint8_t crypt_h;
uint8_t crypt_l; uint8_t crypt_l;

View file

@ -21,19 +21,19 @@ void EbyteLoraComponent::get_current_config_() {
} }
if (read_array((uint8_t *) &buffer, sizeof(buffer))) { if (read_array((uint8_t *) &buffer, sizeof(buffer))) {
ESP_LOGD(TAG, "Found config"); ESP_LOGD(TAG, "Found config");
buffer.addh_description_(); ESP_LOGD(TAG, buffer.addh_description_().c_str());
buffer.addl_description_(); ESP_LOGD(TAG, buffer.addl_description_().c_str());
buffer.reg_0.air_data_rate_description_(); ESP_LOGD(TAG, buffer.reg_0.air_data_rate_description_().c_str());
buffer.reg_0.uart_baud_description_(); ESP_LOGD(TAG, buffer.reg_0.uart_baud_description_().c_str());
buffer.reg_0.parity_description_(); ESP_LOGD(TAG, buffer.reg_0.parity_description_().c_str());
buffer.reg_1.rssi_noise_description_(); ESP_LOGD(TAG, buffer.reg_1.rssi_noise_description_().c_str());
buffer.reg_1.sub_packet_description_(); ESP_LOGD(TAG, buffer.reg_1.sub_packet_description_().c_str());
buffer.reg_1.transmission_power_description_(); ESP_LOGD(TAG, buffer.reg_1.transmission_power_description_().c_str());
buffer.channel_description_(); ESP_LOGD(TAG, buffer.channel_description_().c_str());
buffer.reg_3.enable_lbt_description_(); ESP_LOGD(TAG, buffer.reg_3.enable_lbt_description_().c_str());
buffer.reg_3.wor_period_description_(); ESP_LOGD(TAG, buffer.reg_3.wor_period_description_().c_str());
buffer.reg_3.enable_rssi_description_(); ESP_LOGD(TAG, buffer.reg_3.enable_rssi_description_().c_str());
buffer.reg_3.transmission_type_description_(); ESP_LOGD(TAG, buffer.reg_3.transmission_type_description_().c_str());
set_mode_(NORMAL); set_mode_(NORMAL);
} else { } else {
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message"); ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");

View file

@ -11,6 +11,7 @@
namespace esphome { namespace esphome {
namespace ebyte_lora { namespace ebyte_lora {
static const char *const TAG = "ebyte_lora";
static const uint8_t MAX_SIZE_TX_PACKET = 200; static const uint8_t MAX_SIZE_TX_PACKET = 200;
// the mode the receiver is in // the mode the receiver is in