Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Aug 5, 2024
1 parent 1385702 commit c28b459
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c28b459

Please sign in to comment.