This commit is contained in:
Daniël Koek 2024-04-09 11:58:54 +01:00
parent 1f2c779bd5
commit 9912056808
2 changed files with 60 additions and 46 deletions

View file

@ -10,12 +10,12 @@ namespace ebyte_lora {
enum EnableByte : uint8_t { EBYTE_ENABLED = 0b1, EBYTE_DISABLED = 0b0 }; enum EnableByte : uint8_t { EBYTE_ENABLED = 0b1, EBYTE_DISABLED = 0b0 };
enum AirDataRate : uint8_t { enum AirDataRate : 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,
AIR_19_2kb = 0b101, AIR_19_2KB = 0b101,
AIR_38_4kb = 0b110, AIR_38_4KB = 0b110,
AIR_62_5kb = 0b111 AIR_62_5KB = 0b111
}; };
enum UartBpsSpeed : uint8_t { enum UartBpsSpeed : uint8_t {
UART_1200 = 0b000, UART_1200 = 0b000,
@ -35,7 +35,7 @@ enum TransmissionPower : uint8_t {
TX_LOWEST = 0b11 TX_LOWEST = 0b11
}; };
enum SubPacketSetting : uint8_t { SUB_200b = 0b00, SUB_128b = 0b01, SUB_64b = 0b10, SUB_32b = 0b11 }; enum SubPacketSetting : 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
enum TransmissionMode { TRANSPARENT = 0b0, FIXED = 0b1 }; enum TransmissionMode { TRANSPARENT = 0b0, FIXED = 0b1 };
@ -52,7 +52,9 @@ enum WorPeriod : uint8_t {
}; };
// reverse order on the data sheet // reverse order on the data sheet
struct RegisterConfig { union RegisterConfig {
uint8_t raw[35];
struct {
uint8_t command : 8; uint8_t command : 8;
uint8_t starting_address : 8; uint8_t starting_address : 8;
uint8_t length : 8; uint8_t length : 8;
@ -82,6 +84,7 @@ struct RegisterConfig {
} reg_3; } reg_3;
uint8_t crypt_h : 8; uint8_t crypt_h : 8;
uint8_t crypt_l : 8; uint8_t crypt_l : 8;
};
} __attribute__((packed)); } __attribute__((packed));
} // namespace ebyte_lora } // namespace ebyte_lora

View file

@ -11,25 +11,36 @@ void EbyteLoraComponent::update() {
return; return;
} else { } else {
ESP_LOGD(TAG, "Current config:"); 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, "addh: %u", this->config.addh);
ESP_LOGD(TAG, "addl: %u", this->config.addl); ESP_LOGD(TAG, "addl: %u", this->config.addl);
switch (this->config.reg_0.air_data_rate) { switch (this->config.reg_0.air_data_rate) {
case AIR_2_4kb: case AIR_2_4KB:
ESP_LOGD(TAG, "air_data_rate: 2.4kb"); ESP_LOGD(TAG, "air_data_rate: 2.4kb");
break; break;
case AIR_4_8kb: case AIR_4_8KB:
ESP_LOGD(TAG, "air_data_rate: 4.8kb"); ESP_LOGD(TAG, "air_data_rate: 4.8kb");
break; break;
case AIR_9_6kb: case AIR_9_6KB:
ESP_LOGD(TAG, "air_data_rate: 9.6kb"); ESP_LOGD(TAG, "air_data_rate: 9.6kb");
break; break;
case AIR_19_2kb: case AIR_19_2KB:
ESP_LOGD(TAG, "air_data_rate: 19.2kb"); ESP_LOGD(TAG, "air_data_rate: 19.2kb");
break; break;
case AIR_38_4kb: case AIR_38_4KB:
ESP_LOGD(TAG, "air_data_rate: 38.4kb"); ESP_LOGD(TAG, "air_data_rate: 38.4kb");
break; break;
case AIR_62_5kb: case AIR_62_5KB:
ESP_LOGD(TAG, "air_data_rate: 62.5kb"); ESP_LOGD(TAG, "air_data_rate: 62.5kb");
break; break;
} }
@ -79,16 +90,16 @@ void EbyteLoraComponent::update() {
break; break;
} }
switch (this->config.reg_1.sub_packet) { switch (this->config.reg_1.sub_packet) {
case SUB_200b: case SUB_200B:
ESP_LOGD(TAG, "sub_packet: 200 bytes"); ESP_LOGD(TAG, "sub_packet: 200 bytes");
break; break;
case SUB_128b: case SUB_128B:
ESP_LOGD(TAG, "sub_packet: 128 bytes"); ESP_LOGD(TAG, "sub_packet: 128 bytes");
break; break;
case SUB_64b: case SUB_64B:
ESP_LOGD(TAG, "sub_packet: 64 bytes"); ESP_LOGD(TAG, "sub_packet: 64 bytes");
break; break;
case SUB_32b: case SUB_32B:
ESP_LOGD(TAG, "sub_packet: 32 bytes"); ESP_LOGD(TAG, "sub_packet: 32 bytes");
break; break;
} }
@ -351,7 +362,7 @@ void EbyteLoraComponent::loop() {
if (data[0] == PROGRAM_CONF) { if (data[0] == PROGRAM_CONF) {
ESP_LOGD(TAG, "GOT PROGRAM_CONF"); ESP_LOGD(TAG, "GOT PROGRAM_CONF");
memset(&this->config, 0, sizeof(RegisterConfig)); memset(&this->config, 0, sizeof(RegisterConfig));
memcpy(&this->config, &data[0], sizeof(RegisterConfig)); memcpy(&this->config, &data, sizeof(RegisterConfig));
set_mode_(NORMAL); set_mode_(NORMAL);
} }
} }