From 62ee963c8ccf669af22eed96250dd0492905780b Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Sat, 27 Jul 2024 14:42:57 +0100 Subject: [PATCH] cleanup max number of registers it's actually 0x70 --- debug_registers/README.md | 2 +- include/sx127x.h | 5 +++-- src/sx127x.c | 10 +++++----- test/test_app/main/main.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/debug_registers/README.md b/debug_registers/README.md index ee674c4..eaec496 100644 --- a/debug_registers/README.md +++ b/debug_registers/README.md @@ -16,7 +16,7 @@ make First, obtain sx127x registers. It can be done using ```sx127x_dump_registers``` function. ```c -uint8_t registers[0x80]; +uint8_t registers[MAX_NUMBER_OF_REGISTERS]; sx127x_dump_registers(registers, device); for (int i = 0; i < sizeof(registers); i++) { if (i != 0) { diff --git a/include/sx127x.h b/include/sx127x.h index 9307d13..391a8dd 100644 --- a/include/sx127x.h +++ b/include/sx127x.h @@ -21,8 +21,9 @@ extern "C" { #include #include -#define MAX_PACKET_SIZE 256 +#define MAX_PACKET_SIZE 255 #define MAX_PACKET_SIZE_FSK_FIXED 2047 +#define MAX_NUMBER_OF_REGISTERS 0x70 #define SX127X_OK 0 /*!< esp_err_t value indicating success (no error) */ #define SX127X_ERR_NO_MEM 0x101 /*!< Out of memory */ @@ -452,7 +453,7 @@ int sx127x_lora_set_implicit_header(sx127x_implicit_header_t *header, sx127x *de * * Output all internal registers in the current mode. Can be useful for debugging and troubleshooting. * - * @param output Pre-allocated array where the values will be written. Should be at least 0x80 length. + * @param output Pre-allocated array where the values will be written. Should be at least MAX_NUMBER_OF_REGISTERS length. * @param device Pointer to variable to hold the device handle * @return * - SX127X_ERR_INVALID_ARG if parameter is invalid diff --git a/src/sx127x.c b/src/sx127x.c index 772210b..208c3ba 100644 --- a/src/sx127x.c +++ b/src/sx127x.c @@ -763,7 +763,7 @@ int sx127x_dump_registers(uint8_t *output, sx127x *device) { //Reading from 0x00 register will actually read from fifo //skip it output[0] = 0x00; - return sx127x_spi_read_buffer(0x01, output + 1, 0x7F, device->spi_device); + return sx127x_spi_read_buffer(0x01, output + 1, MAX_NUMBER_OF_REGISTERS - 1, device->spi_device); } void sx127x_tx_set_callback(void (*tx_callback)(sx127x *), sx127x *device) { @@ -883,7 +883,7 @@ int sx127x_fsk_ook_tx_set_for_transmission_with_remaining(uint16_t data_length, int sx127x_fsk_ook_tx_set_for_transmission(uint8_t *data, uint16_t data_length, sx127x *device) { CHECK_FSK_OOK_MODULATION(device); - if (device->fsk_ook_format == SX127X_VARIABLE && data_length > 255) { + if (device->fsk_ook_format == SX127X_VARIABLE && data_length > MAX_PACKET_SIZE) { return SX127X_ERR_INVALID_ARG; } if (device->fsk_ook_format == SX127X_FIXED && data_length > MAX_PACKET_SIZE_FSK_FIXED) { @@ -902,7 +902,7 @@ int sx127x_fsk_ook_tx_set_for_transmission(uint8_t *data, uint16_t data_length, int sx127x_fsk_ook_tx_set_for_transmission_with_address(uint8_t *data, uint16_t data_length, uint8_t address_to, sx127x *device) { CHECK_FSK_OOK_MODULATION(device); - if (device->fsk_ook_format == SX127X_VARIABLE && data_length > 254) { + if (device->fsk_ook_format == SX127X_VARIABLE && data_length > (MAX_PACKET_SIZE - 1)) { return SX127X_ERR_INVALID_ARG; } if (device->fsk_ook_format == SX127X_FIXED && data_length > (MAX_PACKET_SIZE_FSK_FIXED - 1)) { @@ -1160,11 +1160,11 @@ int sx127x_fsk_ook_set_crc(sx127x_crc_type_t crc_type, sx127x *device) { int sx127x_fsk_ook_set_packet_format(sx127x_packet_format_t format, uint16_t max_payload_length, sx127x *device) { CHECK_FSK_OOK_MODULATION(device); - if (format == SX127X_FIXED && (max_payload_length == 0 || max_payload_length > 2047)) { + if (format == SX127X_FIXED && (max_payload_length == 0 || max_payload_length > MAX_PACKET_SIZE_FSK_FIXED)) { return SX127X_ERR_INVALID_ARG; } // max_payload_length = 2047 in variable packet mode will disable max payload length check - if (format == SX127X_VARIABLE && (max_payload_length == 0 || (max_payload_length > 255 && max_payload_length != 2047))) { + if (format == SX127X_VARIABLE && (max_payload_length == 0 || (max_payload_length > MAX_PACKET_SIZE && max_payload_length != MAX_PACKET_SIZE_FSK_FIXED))) { return SX127X_ERR_INVALID_ARG; } uint8_t msb_bits = ((max_payload_length >> 8) & 0b111); diff --git a/test/test_app/main/main.c b/test/test_app/main/main.c index a2b4d64..9f8a9a2 100644 --- a/test/test_app/main/main.c +++ b/test/test_app/main/main.c @@ -104,7 +104,7 @@ void wait_for_rx_done() { } void print_registers() { - uint8_t registers[0x80]; + uint8_t registers[MAX_NUMBER_OF_REGISTERS]; sx127x_dump_registers(registers, fixture->device); for (int i = 0; i < sizeof(registers); i++) { if (i != 0) { @@ -116,7 +116,7 @@ void print_registers() { } TEST_CASE("sx127x_test_fsk_rx_print_registers", "[fsk]") { TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fixture_create_base(&rx_fixture_config, &fixture)); - uint8_t registers[0x80]; + uint8_t registers[MAX_NUMBER_OF_REGISTERS]; sx127x_dump_registers(registers, fixture->device); for (int i = 0; i < sizeof(registers); i++) { if (i != 0) {