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 AirDataRate : uint8_t {
AIR_2_4kb = 0b000,
AIR_4_8kb = 0b011,
AIR_9_6kb = 0b100,
AIR_19_2kb = 0b101,
AIR_38_4kb = 0b110,
AIR_62_5kb = 0b111
AIR_2_4KB = 0b000,
AIR_4_8KB = 0b011,
AIR_9_6KB = 0b100,
AIR_19_2KB = 0b101,
AIR_38_4KB = 0b110,
AIR_62_5KB = 0b111
};
enum UartBpsSpeed : uint8_t {
UART_1200 = 0b000,
@ -35,7 +35,7 @@ enum TransmissionPower : uint8_t {
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
enum TransmissionMode { TRANSPARENT = 0b0, FIXED = 0b1 };
@ -52,36 +52,39 @@ enum WorPeriod : uint8_t {
};
// reverse order on the data sheet
struct RegisterConfig {
uint8_t command : 8;
uint8_t starting_address : 8;
uint8_t length : 8;
uint8_t addh : 8;
uint8_t addl : 8;
union RegisterConfig {
uint8_t raw[35];
struct {
uint8_t air_data_rate : 3;
uint8_t parity : 2;
uint8_t uart_baud : 3;
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 reserve1 : 1;
uint8_t enable_lbt : 1;
uint8_t reserve2 : 1;
uint8_t transmission_mode : 1;
uint8_t enable_rssi : 1;
} reg_3;
uint8_t crypt_h : 8;
uint8_t crypt_l : 8;
} 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 reserve1 : 1;
uint8_t enable_lbt : 1;
uint8_t reserve2 : 1;
uint8_t transmission_mode : 1;
uint8_t enable_rssi : 1;
} reg_3;
uint8_t crypt_h : 8;
uint8_t crypt_l : 8;
};
} __attribute__((packed));
} // namespace ebyte_lora

View file

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