mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 16:08:10 +01:00
Trial this
This commit is contained in:
parent
17887c6191
commit
42cde4e7e2
2 changed files with 37 additions and 161 deletions
|
@ -9,165 +9,6 @@ void EbyteLoraComponent::update() {
|
|||
ESP_LOGD(TAG, "Config not set yet!, gonna request it now!");
|
||||
this->get_current_config_();
|
||||
return;
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Current config:");
|
||||
std::string res;
|
||||
size_t len = sizeof(this->config.raw);
|
||||
char buf[20];
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (i > 0) {
|
||||
res += ';';
|
||||
}
|
||||
sprintf(buf, "0b" BYTE_TO_BINARY_PATTERN " (0x%02X)", BYTE_TO_BINARY(this->config.raw[i]), this->config.raw[i]);
|
||||
res += buf;
|
||||
}
|
||||
ESP_LOGD(TAG, "%s", res.c_str());
|
||||
ESP_LOGD(TAG, "addh: %u", this->config.addh);
|
||||
ESP_LOGD(TAG, "addl: %u", this->config.addl);
|
||||
switch (this->config.reg_0.air_data_rate) {
|
||||
case AIR_2_4KB:
|
||||
ESP_LOGD(TAG, "air_data_rate: 2.4kb");
|
||||
break;
|
||||
case AIR_4_8KB:
|
||||
ESP_LOGD(TAG, "air_data_rate: 4.8kb");
|
||||
break;
|
||||
case AIR_9_6KB:
|
||||
ESP_LOGD(TAG, "air_data_rate: 9.6kb");
|
||||
break;
|
||||
case AIR_19_2KB:
|
||||
ESP_LOGD(TAG, "air_data_rate: 19.2kb");
|
||||
break;
|
||||
case AIR_38_4KB:
|
||||
ESP_LOGD(TAG, "air_data_rate: 38.4kb");
|
||||
break;
|
||||
case AIR_62_5KB:
|
||||
ESP_LOGD(TAG, "air_data_rate: 62.5kb");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_0.uart_baud) {
|
||||
case UART_1200:
|
||||
ESP_LOGD(TAG, "uart_baud: 1200");
|
||||
break;
|
||||
case UART_2400:
|
||||
ESP_LOGD(TAG, "uart_baud: 2400");
|
||||
break;
|
||||
case UART_4800:
|
||||
ESP_LOGD(TAG, "uart_baud: 4800");
|
||||
break;
|
||||
case UART_9600:
|
||||
ESP_LOGD(TAG, "uart_baud: 9600");
|
||||
break;
|
||||
case UART_19200:
|
||||
ESP_LOGD(TAG, "uart_baud: 19200");
|
||||
break;
|
||||
case UART_38400:
|
||||
ESP_LOGD(TAG, "uart_baud: 38400");
|
||||
break;
|
||||
case UART_57600:
|
||||
ESP_LOGD(TAG, "uart_baud: 57600");
|
||||
break;
|
||||
case UART_115200:
|
||||
ESP_LOGD(TAG, "uart_baud: 115200");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_0.parity) {
|
||||
case EBYTE_UART_8N1:
|
||||
ESP_LOGD(TAG, "uart_parity: 8N1");
|
||||
break;
|
||||
case EBYTE_UART_8O1:
|
||||
ESP_LOGD(TAG, "uart_parity: 8O1");
|
||||
break;
|
||||
case EBYTE_UART_8E1:
|
||||
ESP_LOGD(TAG, "uart_parity: 8E1");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_1.rssi_noise) {
|
||||
case EBYTE_ENABLED:
|
||||
ESP_LOGD(TAG, "rssi_noise: ENABLED");
|
||||
break;
|
||||
case EBYTE_DISABLED:
|
||||
ESP_LOGD(TAG, "rssi_noise: DISABLED");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_1.sub_packet) {
|
||||
case SUB_200B:
|
||||
ESP_LOGD(TAG, "sub_packet: 200 bytes");
|
||||
break;
|
||||
case SUB_128B:
|
||||
ESP_LOGD(TAG, "sub_packet: 128 bytes");
|
||||
break;
|
||||
case SUB_64B:
|
||||
ESP_LOGD(TAG, "sub_packet: 64 bytes");
|
||||
break;
|
||||
case SUB_32B:
|
||||
ESP_LOGD(TAG, "sub_packet: 32 bytes");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_1.transmission_power) {
|
||||
case TX_DEFAULT_MAX:
|
||||
ESP_LOGD(TAG, "transmission_power: default or max");
|
||||
break;
|
||||
case TX_LOWER:
|
||||
ESP_LOGD(TAG, "transmission_power: lower");
|
||||
break;
|
||||
case TX_EVEN_LOWER:
|
||||
ESP_LOGD(TAG, "transmission_power: even lower");
|
||||
break;
|
||||
case TX_LOWEST:
|
||||
ESP_LOGD(TAG, "transmission_power: Lowest");
|
||||
break;
|
||||
}
|
||||
ESP_LOGD(TAG, "channel: %u", this->config.channel);
|
||||
switch (this->config.reg_3.enable_lbt) {
|
||||
case EBYTE_ENABLED:
|
||||
ESP_LOGD(TAG, "enable_lbt: ENABLED");
|
||||
break;
|
||||
case EBYTE_DISABLED:
|
||||
ESP_LOGD(TAG, "enable_lbt: DISABLED");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_3.transmission_mode) {
|
||||
case TRANSPARENT:
|
||||
ESP_LOGD(TAG, "transmission_type: TRANSPARENT");
|
||||
break;
|
||||
case FIXED:
|
||||
ESP_LOGD(TAG, "transmission_type: FIXED");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_3.enable_rssi) {
|
||||
case EBYTE_ENABLED:
|
||||
ESP_LOGD(TAG, "enable_rssi: ENABLED");
|
||||
break;
|
||||
case EBYTE_DISABLED:
|
||||
ESP_LOGD(TAG, "enable_rssi: DISABLED");
|
||||
break;
|
||||
}
|
||||
switch (this->config.reg_3.wor_period) {
|
||||
case WOR_500:
|
||||
ESP_LOGD(TAG, "wor_period: 500");
|
||||
break;
|
||||
case WOR_1000:
|
||||
ESP_LOGD(TAG, "wor_period: 1000");
|
||||
break;
|
||||
case WOR_1500:
|
||||
ESP_LOGD(TAG, "wor_period: 1500");
|
||||
break;
|
||||
case WOR_2000:
|
||||
ESP_LOGD(TAG, "wor_period: 2000");
|
||||
break;
|
||||
case WOR_2500:
|
||||
ESP_LOGD(TAG, "wor_period: 2500");
|
||||
break;
|
||||
case WOR_3000:
|
||||
ESP_LOGD(TAG, "wor_period: 3000");
|
||||
break;
|
||||
case WOR_3500:
|
||||
ESP_LOGD(TAG, "wor_period: 3500");
|
||||
break;
|
||||
case WOR_4000:
|
||||
ESP_LOGD(TAG, "wor_period: 4000");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this->get_mode_() != NORMAL) {
|
||||
ESP_LOGD(TAG, "Mode was not set right");
|
||||
|
@ -361,11 +202,45 @@ void EbyteLoraComponent::loop() {
|
|||
}
|
||||
if (data[0] == PROGRAM_CONF) {
|
||||
ESP_LOGD(TAG, "GOT PROGRAM_CONF");
|
||||
memset(&this->config, 0, sizeof(RegisterConfig));
|
||||
memcpy(&this->config, &data, data.size());
|
||||
this->setup_conf_(data);
|
||||
this->set_mode_(NORMAL);
|
||||
}
|
||||
}
|
||||
void EbyteLoraComponent::setup_conf_(std::vector<uint8_t> data) {
|
||||
ESP_LOGD(TAG, "Current config:");
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
// 3 is addh
|
||||
if (i == 3) {
|
||||
ESP_LOGD(TAG, "addh: %u", data[i]);
|
||||
}
|
||||
// 4 is addl
|
||||
if (i == 4) {
|
||||
ESP_LOGD(TAG, "addl: %u", data[i]);
|
||||
}
|
||||
// 5 is reg0, which is air_data for first 3 bits, then parity for 2, uart_baud for 3
|
||||
if (i == 5) {
|
||||
ESP_LOGD(TAG, "reg0: %c%c%c%c%c%c%c%c", BYTE_TO_BINARY(data[i]));
|
||||
uint8_t air_data = data[i] & 0b111;
|
||||
uint8_t parity = data[i] & 0b00011;
|
||||
uint8_t uart_baud = data[i] & 0b00000111;
|
||||
ESP_LOGD(TAG, "air_data: %u", air_data);
|
||||
ESP_LOGD(TAG, "parity: %u", parity);
|
||||
ESP_LOGD(TAG, "uart_baud: %u", uart_baud);
|
||||
}
|
||||
// 6 is reg1; transmission_power : 2, reserve : 3, rssi_noise : 1, sub_packet : 2
|
||||
if (i == 6) {
|
||||
ESP_LOGD(TAG, "reg1: %c%c%c%c%c%c%c%c", BYTE_TO_BINARY(data[i]));
|
||||
}
|
||||
// 7 is reg2; channel
|
||||
if (i == 7) {
|
||||
ESP_LOGD(TAG, "channel: %u", data[i]);
|
||||
}
|
||||
// 8 is reg3; wor_period:3, reserve:1, enable_lbt:1, reserve:1, transmission_mode:1, enable_rssi:1
|
||||
if (i == 7) {
|
||||
ESP_LOGD(TAG, "reg3: %c%c%c%c%c%c%c%c", BYTE_TO_BINARY(data[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
void EbyteLoraComponent::send_switch_info_() {
|
||||
if (!this->can_send_message_()) {
|
||||
return;
|
||||
|
|
|
@ -48,6 +48,7 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
|
|||
void get_current_config_();
|
||||
void send_switch_push_(uint8_t pin, bool value);
|
||||
void send_switch_info_();
|
||||
void setup_conf_(std::vector<uint8_t> data);
|
||||
|
||||
protected:
|
||||
bool update_needed_ = false;
|
||||
|
|
Loading…
Reference in a new issue