trial this

This commit is contained in:
Daniël Koek 2024-04-08 18:47:58 +01:00
parent 7f047d8bd3
commit 4b5262582c
3 changed files with 148 additions and 201 deletions

View file

@ -7,9 +7,9 @@ namespace 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 { EBYTE_ENABLED = 0b1, EBYTE_DISABLED = 0b0 }; enum ENABLE_BYTE : uint8_t { EBYTE_ENABLED = 0b1, EBYTE_DISABLED = 0b0 };
enum AIR_DATA_RATE { enum AIR_DATA_RATE : uint8_t {
AIR_2_4kb = 0b000, AIR_2_4kb = 0b000,
AIR_4_8kb = 0b011, AIR_4_8kb = 0b011,
AIR_9_6kb = 0b100, AIR_9_6kb = 0b100,
@ -17,7 +17,7 @@ enum AIR_DATA_RATE {
AIR_38_4kb = 0b110, AIR_38_4kb = 0b110,
AIR_62_5kb = 0b111 AIR_62_5kb = 0b111
}; };
enum UART_BPS_SPEED { enum UART_BPS_SPEED : uint8_t {
UART_1200 = 0b000, UART_1200 = 0b000,
UART_2400 = 0b001, UART_2400 = 0b001,
UART_4800 = 0b010, UART_4800 = 0b010,
@ -27,122 +27,19 @@ enum UART_BPS_SPEED {
UART_57600 = 0b110, UART_57600 = 0b110,
UART_115200 = 0b111 UART_115200 = 0b111
}; };
enum UART_PARITY_SETTING { EBYTE_UART_8N1 = 0b00, EBYTE_UART_8O1 = 0b01, EBYTE_UART_8E1 = 0b10 }; enum UART_PARITY_SETTING : uint8_t { EBYTE_UART_8N1 = 0b00, EBYTE_UART_8O1 = 0b01, EBYTE_UART_8E1 = 0b10 };
struct reg_0 { enum TRANSMISSION_POWER : uint8_t {
uint8_t air_data_rate : 3;
std::string air_data_rate_description_() {
switch (this->air_data_rate) {
case AIR_2_4kb:
return "air_data_rate: 2.4kb";
case AIR_4_8kb:
return "air_data_rate: 4.8kb";
case AIR_9_6kb:
return "air_data_rate: 9.6kb";
case AIR_19_2kb:
return "air_data_rate: 19.2kb";
case AIR_38_4kb:
return "air_data_rate: 38.4kb";
case AIR_62_5kb:
return "air_data_rate: 62.5kb";
default:
return "";
}
}
uint8_t parity : 2;
std::string parity_description_() {
switch (this->parity) {
case EBYTE_UART_8N1:
return "uart_parity: 8N1";
case EBYTE_UART_8O1:
return "uart_parity: 8O1";
case EBYTE_UART_8E1:
return "uart_parity: 8E1";
default:
return "";
}
}
uint8_t uart_baud : 3;
std::string uart_baud_description_() {
switch (this->uart_baud) {
case UART_1200:
return "uart_baud: 1200";
case UART_2400:
return "uart_baud: 2400";
case UART_4800:
return "uart_baud: 4800";
case UART_9600:
return "uart_baud: 9600";
case UART_19200:
return "uart_baud: 19200";
case UART_38400:
return "uart_baud: 38400";
case UART_57600:
return "uart_baud: 57600";
case UART_115200:
return "uart_baud: 115200";
default:
return "";
}
}
} __attribute__((packed));
enum TRANSMISSION_POWER {
TX_DEFAULT_MAX = 0b00, TX_DEFAULT_MAX = 0b00,
TX_LOWER = 0b01, TX_LOWER = 0b01,
TX_EVEN_LOWER = 0b10, TX_EVEN_LOWER = 0b10,
TX_LOWEST = 0b11 TX_LOWEST = 0b11
}; };
enum SUB_PACKET_SETTING { SUB_200b = 0b00, SUB_128b = 0b01, SUB_64b = 0b10, SUB_32b = 0b11 }; enum SUB_PACKET_SETTING : uint8_t { SUB_200b = 0b00, SUB_128b = 0b01, SUB_64b = 0b10, SUB_32b = 0b11 };
// again in reverse order on the data sheet // again in reverse order on the data sheet
struct reg_1 {
uint8_t transmission_power : 2;
std::string transmission_power_description_() {
switch (this->transmission_power) {
case TX_DEFAULT_MAX:
return "transmission_power: default or max";
case TX_LOWER:
return "transmission_power: lower";
case TX_EVEN_LOWER:
return "transmission_power: even lower";
case TX_LOWEST:
return "transmission_power: Lowest";
default:
return "";
}
}
uint8_t reserve : 3;
uint8_t rssi_noise : 1;
std::string rssi_noise_description_() {
switch (this->rssi_noise) {
case EBYTE_ENABLED:
return "rssi_noise: ENABLED";
case EBYTE_DISABLED:
return "rssi_noise: DISABLED";
default:
return "";
}
}
uint8_t sub_packet : 2;
std::string sub_packet_description_() {
switch (this->sub_packet) {
case SUB_200b:
return "sub_packet: 200 bytes";
case SUB_128b:
return "sub_packet: 128 bytes";
case SUB_64b:
return "sub_packet: 64 bytes";
case SUB_32b:
return "sub_packet: 32 bytes";
default:
return "";
}
}
} __attribute__((packed));
enum TRANSMISSION_MODE { TRANSPARENT = 0b0, FIXED = 0b1 }; enum TRANSMISSION_MODE { TRANSPARENT = 0b0, FIXED = 0b1 };
enum WOR_PERIOD { enum WOR_PERIOD : uint8_t {
WOR_500 = 0b000, WOR_500 = 0b000,
WOR_1000 = 0b001, WOR_1000 = 0b001,
WOR_1500 = 0b010, WOR_1500 = 0b010,
@ -154,82 +51,40 @@ enum WOR_PERIOD {
}; };
// reverse order on the data sheet // reverse order on the data sheet
struct reg_3 {
struct RegisterConfig {
struct {
uint8_t command : 8;
uint8_t starting_address : 8;
uint8_t length : 8;
uint8_t addh : 8;
uint8_t addl : 8;
struct {
uint8_t air_data_rate : 3;
uint8_t parity : 2;
uint8_t uart_baud : 3;
} reg_0;
struct {
uint8_t transmission_power : 2;
uint8_t reserve : 3;
uint8_t rssi_noise : 1;
uint8_t sub_packet : 2;
} reg_1;
// reg2
uint8_t channel : 8;
struct {
uint8_t wor_period : 3; uint8_t wor_period : 3;
std::string wor_period_description_() {
switch (this->wor_period) {
case WOR_500:
return "wor_period: 500";
case WOR_1000:
return "wor_period: 1000";
case WOR_1500:
return "wor_period: 1500";
case WOR_2000:
return "wor_period: 2000";
case WOR_2500:
return "wor_period: 2500";
case WOR_3000:
return "wor_period: 3000";
case WOR_3500:
return "wor_period: 3500";
case WOR_4000:
return "wor_period: 4000";
default:
return "";
}
}
uint8_t reserve1 : 1; uint8_t reserve1 : 1;
uint8_t enable_lbt : 1; uint8_t enable_lbt : 1;
std::string enable_lbt_description_() {
switch (this->enable_lbt) {
case EBYTE_ENABLED:
return "enable_lbt: ENABLED";
case EBYTE_DISABLED:
return "enable_lbt: DISABLED";
default:
return "";
}
}
uint8_t reserve2 : 1; uint8_t reserve2 : 1;
uint8_t transmission_mode : 1; uint8_t transmission_mode : 1;
std::string transmission_type_description_() {
switch (this->transmission_mode) {
case TRANSPARENT:
return "transmission_type: TRANSPARENT";
case FIXED:
return "transmission_type: FIXED";
default:
return "";
}
}
uint8_t enable_rssi : 1; uint8_t enable_rssi : 1;
std::string enable_rssi_description_() { } reg_3;
switch (this->enable_rssi) { uint8_t crypt_h : 8;
case EBYTE_ENABLED: uint8_t crypt_l : 8;
return "enable_rssi: ENABLED"; };
case EBYTE_DISABLED:
return "enable_rssi: DISABLED";
default:
return "";
}
}
} __attribute__((packed)); } __attribute__((packed));
typedef struct {
uint8_t command = 0;
uint8_t starting_address = 0;
uint8_t length = 0;
uint8_t addh = 0;
std::string addh_description_() { return "addh:" + to_string(this->addh); }
uint8_t addl = 0;
std::string addl_description_() { return "addl:" + to_string(this->addh); }
struct reg_0 reg_0;
struct reg_1 reg_1;
// reg2
uint8_t channel;
std::string channel_description_() { return "channel: " + to_string(this->channel); }
struct reg_3 reg_3;
uint8_t crypt_h;
uint8_t crypt_l;
} __attribute__((packed)) reg_config;
} // namespace ebyte_lora } // namespace ebyte_lora
} // namespace esphome } // namespace esphome

View file

@ -10,20 +10,112 @@ void EbyteLoraComponent::update() {
get_current_config_(); get_current_config_();
return; return;
} else { } else {
ESP_LOGD(TAG, "Current config"); ESP_LOGD(TAG, "Current config:");
ESP_LOGD(TAG, this->config.addh_description_().c_str()); ESP_LOGD(TAG, "addh: %u", this->config.addh);
ESP_LOGD(TAG, this->config.addl_description_().c_str()); ESP_LOGD(TAG, "addl: %u", this->config.addl);
ESP_LOGD(TAG, this->config.reg_0.air_data_rate_description_().c_str()); switch (this->config.reg_0.air_data_rate) {
ESP_LOGD(TAG, this->config.reg_0.uart_baud_description_().c_str()); case AIR_2_4kb:
ESP_LOGD(TAG, this->config.reg_0.parity_description_().c_str()); ESP_LOGD(TAG, "air_data_rate: 2.4kb");
ESP_LOGD(TAG, this->config.reg_1.rssi_noise_description_().c_str()); case AIR_4_8kb:
ESP_LOGD(TAG, this->config.reg_1.sub_packet_description_().c_str()); ESP_LOGD(TAG, "air_data_rate: 4.8kb");
ESP_LOGD(TAG, this->config.reg_1.transmission_power_description_().c_str()); case AIR_9_6kb:
ESP_LOGD(TAG, this->config.channel_description_().c_str()); ESP_LOGD(TAG, "air_data_rate: 9.6kb");
ESP_LOGD(TAG, this->config.reg_3.enable_lbt_description_().c_str()); case AIR_19_2kb:
ESP_LOGD(TAG, this->config.reg_3.wor_period_description_().c_str()); ESP_LOGD(TAG, "air_data_rate: 19.2kb");
ESP_LOGD(TAG, this->config.reg_3.enable_rssi_description_().c_str()); case AIR_38_4kb:
ESP_LOGD(TAG, this->config.reg_3.transmission_type_description_().c_str()); ESP_LOGD(TAG, "air_data_rate: 38.4kb");
case AIR_62_5kb:
ESP_LOGD(TAG, "air_data_rate: 62.5kb");
}
switch (this->config.reg_0.uart_baud) {
case UART_1200:
ESP_LOGD(TAG, "uart_baud: 1200");
case UART_2400:
ESP_LOGD(TAG, "uart_baud: 2400");
case UART_4800:
ESP_LOGD(TAG, "uart_baud: 4800");
case UART_9600:
ESP_LOGD(TAG, "uart_baud: 9600");
case UART_19200:
ESP_LOGD(TAG, "uart_baud: 19200");
case UART_38400:
ESP_LOGD(TAG, "uart_baud: 38400");
case UART_57600:
ESP_LOGD(TAG, "uart_baud: 57600");
case UART_115200:
ESP_LOGD(TAG, "uart_baud: 115200");
}
switch (this->config.reg_0.parity) {
case EBYTE_UART_8N1:
ESP_LOGD(TAG, "uart_parity: 8N1");
case EBYTE_UART_8O1:
ESP_LOGD(TAG, "uart_parity: 8O1");
case EBYTE_UART_8E1:
ESP_LOGD(TAG, "uart_parity: 8E1");
}
switch (this->config.reg_1.rssi_noise) {
case EBYTE_ENABLED:
ESP_LOGD(TAG, "rssi_noise: ENABLED");
case EBYTE_DISABLED:
ESP_LOGD(TAG, "rssi_noise: DISABLED");
}
switch (this->config.reg_1.sub_packet) {
case SUB_200b:
ESP_LOGD(TAG, "sub_packet: 200 bytes");
case SUB_128b:
ESP_LOGD(TAG, "sub_packet: 128 bytes");
case SUB_64b:
ESP_LOGD(TAG, "sub_packet: 64 bytes");
case SUB_32b:
ESP_LOGD(TAG, "sub_packet: 32 bytes");
}
switch (this->config.reg_1.transmission_power) {
case TX_DEFAULT_MAX:
ESP_LOGD(TAG, "transmission_power: default or max");
case TX_LOWER:
ESP_LOGD(TAG, "transmission_power: lower");
case TX_EVEN_LOWER:
ESP_LOGD(TAG, "transmission_power: even lower");
case TX_LOWEST:
ESP_LOGD(TAG, "transmission_power: Lowest");
}
ESP_LOGD(TAG, "channel: %u", this->config.channel);
switch (this->config.reg_3.enable_lbt) {
case EBYTE_ENABLED:
ESP_LOGD(TAG, "enable_lbt: ENABLED");
case EBYTE_DISABLED:
ESP_LOGD(TAG, "enable_lbt: DISABLED");
}
switch (this->config.reg_3.transmission_mode) {
case TRANSPARENT:
ESP_LOGD(TAG, "transmission_type: TRANSPARENT");
case FIXED:
ESP_LOGD(TAG, "transmission_type: FIXED");
}
switch (this->config.reg_3.enable_rssi) {
case EBYTE_ENABLED:
ESP_LOGD(TAG, "enable_rssi: ENABLED");
case EBYTE_DISABLED:
ESP_LOGD(TAG, "enable_rssi: DISABLED");
}
switch (this->config.reg_3.wor_period) {
case WOR_500:
ESP_LOGD(TAG, "wor_period: 500");
case WOR_1000:
ESP_LOGD(TAG, "wor_period: 1000");
case WOR_1500:
ESP_LOGD(TAG, "wor_period: 1500");
case WOR_2000:
ESP_LOGD(TAG, "wor_period: 2000");
case WOR_2500:
ESP_LOGD(TAG, "wor_period: 2500");
case WOR_3000:
ESP_LOGD(TAG, "wor_period: 3000");
case WOR_3500:
ESP_LOGD(TAG, "wor_period: 3500");
case WOR_4000:
ESP_LOGD(TAG, "wor_period: 4000");
}
} }
if (get_mode_() != NORMAL) { if (get_mode_() != NORMAL) {
ESP_LOGD(TAG, "Mode was not set right"); ESP_LOGD(TAG, "Mode was not set right");

View file

@ -55,7 +55,7 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
uint32_t starting_to_check_; uint32_t starting_to_check_;
uint32_t time_out_after_; uint32_t time_out_after_;
std::string raw_message_; std::string raw_message_;
reg_config config; RegisterConfig config;
sensor::Sensor *rssi_sensor_{nullptr}; sensor::Sensor *rssi_sensor_{nullptr};
GPIOPin *pin_aux_; GPIOPin *pin_aux_;
GPIOPin *pin_m0_; GPIOPin *pin_m0_;