From c28b45914792452796801cebb2fba35018791211 Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Mon, 5 Aug 2024 11:43:45 +0200 Subject: [PATCH] fix unit test --- src/sx127x.c | 10 +++++++--- test/test_sx127x.c | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sx127x.c b/src/sx127x.c index f01a3d1..1c613e3 100644 --- a/src/sx127x.c +++ b/src/sx127x.c @@ -266,14 +266,18 @@ int sx127x_shadow_spi_write_buffer(int reg, const uint8_t *buffer, size_t buffer int sx127x_read_register(int reg, shadow_spi_device_t *spi_device, uint8_t *result) { if (spi_device->shadow_registers_sync[reg] == SHADOW_IGNORE) { - ERROR_CHECK(sx127x_spi_read_registers(reg, spi_device->spi_device, 1, (uint32_t *) result)); + uint32_t value; + ERROR_CHECK(sx127x_spi_read_registers(reg, spi_device->spi_device, 1, &value)); + *result = (uint8_t) value; return SX127X_OK; } if (spi_device->shadow_registers_sync[reg] == SHADOW_CACHED) { *result = spi_device->shadow_registers[reg]; return SX127X_OK; } - ERROR_CHECK(sx127x_spi_read_registers(reg, spi_device->spi_device, 1, (uint32_t *) result)); + uint32_t value; + ERROR_CHECK(sx127x_spi_read_registers(reg, spi_device->spi_device, 1, &value)); + *result = (uint8_t) value; spi_device->shadow_registers_sync[reg] = SHADOW_CACHED; spi_device->shadow_registers[reg] = *result; return SX127X_OK; @@ -846,7 +850,7 @@ int sx127x_lora_rx_get_packet_snr(sx127x *device, float *snr) { CHECK_MODULATION(device, SX127x_MODULATION_LORA); uint8_t value; ERROR_CHECK(sx127x_read_register(REG_PKT_SNR_VALUE, &device->spi_device, &value)); - *snr = ((int8_t) value) * 0.25f; + *snr = (float) ((int8_t) value) * 0.25f; return SX127X_OK; } diff --git a/test/test_sx127x.c b/test/test_sx127x.c index c0bd657..4411360 100644 --- a/test/test_sx127x.c +++ b/test/test_sx127x.c @@ -319,7 +319,7 @@ void test_lora_tx() { spi_assert_write(payload, sizeof(payload)); TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_set_opmod(SX127x_MODE_TX, SX127x_MODULATION_LORA, device)); - TEST_ASSERT_EQUAL_INT(registers[0x40], 0b01000000); + TEST_ASSERT_EQUAL_INT(registers[0x40], 0b01010000); // simulate interrupt registers[0x12] = 0b00001000; // tx done