mirror of
https://github.com/esphome/esphome.git
synced 2024-12-26 23:41:45 +01:00
this should work
This commit is contained in:
parent
6664333e31
commit
c8f5420218
3 changed files with 92 additions and 119 deletions
|
@ -4,7 +4,7 @@
|
|||
#include "esphome/core/log.h"
|
||||
namespace esphome {
|
||||
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
|
||||
|
||||
enum ENABLE_BYTE { ENABLED = 0b1, DISABLED = 0b0 };
|
||||
|
@ -30,75 +30,58 @@ enum UART_BPS_SPEED {
|
|||
enum UART_PARITY { _8N1 = 0b00, _8O1 = 0b01, _8E1 = 0b10 };
|
||||
struct REG0 {
|
||||
uint8_t air_data_rate : 3;
|
||||
void air_data_rate_description_() {
|
||||
std::string air_data_rate_description_() {
|
||||
switch (this->air_data_rate) {
|
||||
case _2_4kb:
|
||||
ESP_LOGD(TAG, "air_data_rate: 2.4kb");
|
||||
break;
|
||||
return "air_data_rate: 2.4kb";
|
||||
case _4_8kb:
|
||||
ESP_LOGD(TAG, "air_data_rate: 4.8kb");
|
||||
break;
|
||||
return "air_data_rate: 4.8kb";
|
||||
case _9_6kb:
|
||||
ESP_LOGD(TAG, "air_data_rate: 9.6kb");
|
||||
break;
|
||||
return "air_data_rate: 9.6kb";
|
||||
case _19_2kb:
|
||||
ESP_LOGD(TAG, "air_data_rate: 19.2kb");
|
||||
break;
|
||||
return "air_data_rate: 19.2kb";
|
||||
case _38_4kb:
|
||||
ESP_LOGD(TAG, "air_data_rate: 38.4kb");
|
||||
break;
|
||||
return "air_data_rate: 38.4kb";
|
||||
case _62_5kb:
|
||||
ESP_LOGD(TAG, "air_data_rate: 62.5kb");
|
||||
break;
|
||||
return "air_data_rate: 62.5kb";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
uint8_t parity : 2;
|
||||
void parity_description_() {
|
||||
std::string parity_description_() {
|
||||
switch (this->parity) {
|
||||
case _8N1:
|
||||
ESP_LOGD(TAG, "uart_parity: 8N1");
|
||||
break;
|
||||
return "uart_parity: 8N1";
|
||||
case _8O1:
|
||||
ESP_LOGD(TAG, "uart_parity: 8O1");
|
||||
break;
|
||||
return "uart_parity: 8O1";
|
||||
case _8E1:
|
||||
ESP_LOGD(TAG, "uart_parity: 8E1");
|
||||
break;
|
||||
return "uart_parity: 8E1";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
uint8_t uart_baud : 3;
|
||||
void uart_baud_description_() {
|
||||
std::string uart_baud_description_() {
|
||||
switch (this->uart_baud) {
|
||||
case _1200:
|
||||
ESP_LOGD(TAG, "uart_baud: 1200");
|
||||
break;
|
||||
return "uart_baud: 1200";
|
||||
case _2400:
|
||||
ESP_LOGD(TAG, "uart_baud: 2400");
|
||||
break;
|
||||
return "uart_baud: 2400";
|
||||
case _4800:
|
||||
ESP_LOGD(TAG, "uart_baud: 4800");
|
||||
break;
|
||||
return "uart_baud: 4800";
|
||||
case _9600:
|
||||
ESP_LOGD(TAG, "uart_baud: 9600");
|
||||
break;
|
||||
return "uart_baud: 9600";
|
||||
case _19200:
|
||||
ESP_LOGD(TAG, "uart_baud: 19200");
|
||||
break;
|
||||
return "uart_baud: 19200";
|
||||
case _38400:
|
||||
ESP_LOGD(TAG, "uart_baud: 38400");
|
||||
break;
|
||||
return "uart_baud: 38400";
|
||||
case _57600:
|
||||
ESP_LOGD(TAG, "uart_baud: 57600");
|
||||
break;
|
||||
return "uart_baud: 57600";
|
||||
case _115200:
|
||||
ESP_LOGD(TAG, "uart_baud: 115200");
|
||||
break;
|
||||
return "uart_baud: 115200";
|
||||
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
|
||||
struct REG1 {
|
||||
uint8_t transmission_power : 2;
|
||||
void transmission_power_description_() {
|
||||
std::string transmission_power_description_() {
|
||||
switch (this->transmission_power) {
|
||||
case _DEFAULT_MAX:
|
||||
ESP_LOGD(TAG, "transmission_power: default or max");
|
||||
break;
|
||||
return "transmission_power: default or max";
|
||||
case _LOWER:
|
||||
ESP_LOGD(TAG, "transmission_power: lower");
|
||||
break;
|
||||
return "transmission_power: lower";
|
||||
case _EVEN_LOWER:
|
||||
ESP_LOGD(TAG, "transmission_power: even lower");
|
||||
break;
|
||||
return "transmission_power: even lower";
|
||||
case _LOWEST:
|
||||
ESP_LOGD(TAG, "transmission_power: Lowest");
|
||||
break;
|
||||
return "transmission_power: Lowest";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
uint8_t reserve : 3;
|
||||
uint8_t rssi_noise : 1;
|
||||
void rssi_noise_description_() {
|
||||
std::string rssi_noise_description_() {
|
||||
switch (this->rssi_noise) {
|
||||
case ENABLED:
|
||||
ESP_LOGD(TAG, "rssi_noise: ENABLED");
|
||||
break;
|
||||
return "rssi_noise: ENABLED";
|
||||
case DISABLED:
|
||||
ESP_LOGD(TAG, "rssi_noise: DISABLED");
|
||||
break;
|
||||
return "rssi_noise: DISABLED";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
uint8_t sub_packet : 2;
|
||||
void sub_packet_description_() {
|
||||
std::string sub_packet_description_() {
|
||||
switch (this->sub_packet) {
|
||||
case _200b:
|
||||
ESP_LOGD(TAG, "sub_packet: 200 bytes");
|
||||
break;
|
||||
return "sub_packet: 200 bytes";
|
||||
|
||||
case _128b:
|
||||
ESP_LOGD(TAG, "sub_packet: 128 bytes");
|
||||
break;
|
||||
return "sub_packet: 128 bytes";
|
||||
|
||||
case _64b:
|
||||
ESP_LOGD(TAG, "sub_packet: 64 bytes");
|
||||
break;
|
||||
return "sub_packet: 64 bytes";
|
||||
|
||||
case _32b:
|
||||
ESP_LOGD(TAG, "sub_packet: 32 bytes");
|
||||
break;
|
||||
return "sub_packet: 32 bytes";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -180,75 +156,71 @@ enum WOR_PERIOD {
|
|||
// reverse order on the data sheet
|
||||
struct REG3 {
|
||||
uint8_t wor_period : 3;
|
||||
void wor_period_description_() {
|
||||
std::string wor_period_description_() {
|
||||
switch (this->wor_period) {
|
||||
case _500:
|
||||
ESP_LOGD(TAG, "wor_period: 500");
|
||||
break;
|
||||
return "wor_period: 500";
|
||||
|
||||
case _1000:
|
||||
ESP_LOGD(TAG, "wor_period: 1000");
|
||||
break;
|
||||
return "wor_period: 1000";
|
||||
|
||||
case _1500:
|
||||
ESP_LOGD(TAG, "wor_period: 1500");
|
||||
break;
|
||||
return "wor_period: 1500";
|
||||
|
||||
case _2000:
|
||||
ESP_LOGD(TAG, "wor_period: 2000");
|
||||
break;
|
||||
return "wor_period: 2000";
|
||||
|
||||
case _2500:
|
||||
ESP_LOGD(TAG, "wor_period: 2500");
|
||||
break;
|
||||
return "wor_period: 2500";
|
||||
|
||||
case _3000:
|
||||
ESP_LOGD(TAG, "wor_period: 3000");
|
||||
break;
|
||||
return "wor_period: 3000";
|
||||
|
||||
case _3500:
|
||||
ESP_LOGD(TAG, "wor_period: 3500");
|
||||
break;
|
||||
return "wor_period: 3500";
|
||||
|
||||
case _4000:
|
||||
ESP_LOGD(TAG, "wor_period: 4000");
|
||||
break;
|
||||
return "wor_period: 4000";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
uint8_t reserve1 : 1;
|
||||
uint8_t enable_lbt : 1;
|
||||
void enable_lbt_description_() {
|
||||
std::string enable_lbt_description_() {
|
||||
switch (this->enable_lbt) {
|
||||
case ENABLED:
|
||||
ESP_LOGD(TAG, "enable_lbt: ENABLED");
|
||||
break;
|
||||
return "enable_lbt: ENABLED";
|
||||
|
||||
case DISABLED:
|
||||
ESP_LOGD(TAG, "enable_lbt: DISABLED");
|
||||
break;
|
||||
return "enable_lbt: DISABLED";
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint8_t reserve2 : 1;
|
||||
uint8_t transmission_mode : 1;
|
||||
void transmission_type_description_() {
|
||||
std::string transmission_type_description_() {
|
||||
switch (this->transmission_mode) {
|
||||
case TRANSPARENT:
|
||||
ESP_LOGD(TAG, "transmission_type: TRANSPARENT");
|
||||
break;
|
||||
return "transmission_type: TRANSPARENT";
|
||||
|
||||
case FIXED:
|
||||
ESP_LOGD(TAG, "transmission_type: FIXED");
|
||||
break;
|
||||
return "transmission_type: FIXED";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
uint8_t enable_rssi : 1;
|
||||
void enable_rssi_description_() {
|
||||
std::string enable_rssi_description_() {
|
||||
switch (this->enable_rssi) {
|
||||
case ENABLED:
|
||||
ESP_LOGD(TAG, "enable_rssi: ENABLED");
|
||||
break;
|
||||
return "enable_rssi: ENABLED";
|
||||
|
||||
case DISABLED:
|
||||
ESP_LOGD(TAG, "enable_rssi: DISABLED");
|
||||
break;
|
||||
return "enable_rssi: DISABLED";
|
||||
default:
|
||||
break;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -258,14 +230,14 @@ struct RegisterConfig {
|
|||
uint8_t starting_address = 0;
|
||||
uint8_t length = 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;
|
||||
void addl_description_() { ESP_LOGD(TAG, "addl: %u", this->addh); }
|
||||
std::string addl_description_() { return "addl:" + this->addh; }
|
||||
struct REG0 reg_0;
|
||||
struct REG1 reg_1;
|
||||
// reg2
|
||||
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;
|
||||
uint8_t crypt_h;
|
||||
uint8_t crypt_l;
|
||||
|
|
|
@ -21,19 +21,19 @@ void EbyteLoraComponent::get_current_config_() {
|
|||
}
|
||||
if (read_array((uint8_t *) &buffer, sizeof(buffer))) {
|
||||
ESP_LOGD(TAG, "Found config");
|
||||
buffer.addh_description_();
|
||||
buffer.addl_description_();
|
||||
buffer.reg_0.air_data_rate_description_();
|
||||
buffer.reg_0.uart_baud_description_();
|
||||
buffer.reg_0.parity_description_();
|
||||
buffer.reg_1.rssi_noise_description_();
|
||||
buffer.reg_1.sub_packet_description_();
|
||||
buffer.reg_1.transmission_power_description_();
|
||||
buffer.channel_description_();
|
||||
buffer.reg_3.enable_lbt_description_();
|
||||
buffer.reg_3.wor_period_description_();
|
||||
buffer.reg_3.enable_rssi_description_();
|
||||
buffer.reg_3.transmission_type_description_();
|
||||
ESP_LOGD(TAG, buffer.addh_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.addl_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_0.air_data_rate_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_0.uart_baud_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_0.parity_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_1.rssi_noise_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_1.sub_packet_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_1.transmission_power_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.channel_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_3.enable_lbt_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_3.wor_period_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_3.enable_rssi_description_().c_str());
|
||||
ESP_LOGD(TAG, buffer.reg_3.transmission_type_description_().c_str());
|
||||
set_mode_(NORMAL);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace esphome {
|
||||
namespace ebyte_lora {
|
||||
static const char *const TAG = "ebyte_lora";
|
||||
static const uint8_t MAX_SIZE_TX_PACKET = 200;
|
||||
|
||||
// the mode the receiver is in
|
||||
|
|
Loading…
Reference in a new issue