Skip to content

Commit

Permalink
add test for FHSS
Browse files Browse the repository at this point in the history
+ update documentation
  • Loading branch information
dernasherbrezon committed Aug 5, 2024
1 parent 5a4701c commit eb0ba86
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This library supports all standard LoRa features:
* TX with +20dbm power
* Explicit and implicit headers
* Granular sx127x register configuration
* Frequency hopping spread spectrum (FHSS)

And FSK/OOK features:

Expand Down Expand Up @@ -113,6 +114,7 @@ Where:

* ```receive_lora``` - RX in LoRa mode and explicit header. Uses CAD to quickly detect presence of the message and switch into RX mode.
* ```receive_lora_deepsleep``` - RX in LoRa mode while in the deep sleep
* ```receive_lora_fhss``` - RX in LoRa mode with FHSS enabled
* ```receive_lora_implicit_header``` - RX in LoRa mode and implicit header (without header)
* ```receive_lora_raspberrypi``` - RX in LoRa mode on RaspberryPI via GPIO pins and onboard SPI. Tested on module RA-02
* ```receive_fsk``` - RX in FSK mode. Variable packet length, NRZ encoding, CRC, AFC on.
Expand All @@ -121,6 +123,7 @@ Where:
* ```receive_fsk_raspberry``` - RX in FSK mode on RaspberryPI via GPIO pins and onboard SPI. Variable packet length, NRZ encoding, CRC, AFC on.
* ```receive_ook``` - RX in OOK mode. Variable packet length, NRZ encoding, CRC, AFC on.
* ```transmit_lora``` - TX in LoRa mode and explicit header. Several messages of different sizes and at all supported power levels
* ```transmit_lora_fhss``` - TX in LoRa mode with FHSS enabled
* ```transmit_lora_implicit_header``` - TX in LoRa mode and implicit header (without header)
* ```transmit_lora_raspberrypi``` - TX messages using LoRa mode from RaspberryPI. Tested on module RA-02
* ```transmit_fsk``` - TX in FSK mode. Variable packet length, NRZ encoding, CRC, AFC on. Sending several messages: small 2 byte, messages that can fit into FIFO fully, max messages for variable packet type - 255 bytes and same messages, but for node address 0x11 and 0x00.
Expand Down
2 changes: 2 additions & 0 deletions examples/transmit_lora_fhss/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void tx_callback(sx127x *device) {
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, device));
ESP_ERROR_CHECK(sx127x_lora_tx_set_for_transmission(data, sizeof(data), device));
} else if (messages_sent == 1) {
vTaskDelay(pdMS_TO_TICKS(1000));
// 200 bytes
uint8_t data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,
Expand All @@ -52,6 +53,7 @@ void tx_callback(sx127x *device) {
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, device));
ESP_ERROR_CHECK(sx127x_lora_tx_set_for_transmission(data, sizeof(data), device));
} else if (messages_sent == 2) {
vTaskDelay(pdMS_TO_TICKS(1000));
// 255 bytes
uint8_t data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,
Expand Down
21 changes: 20 additions & 1 deletion test/test_app/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uint8_t fsk_max_variable[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x
0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0,
0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe};

uint64_t frequencies[] = {437700000, 438200000, 437200012};

int message_counter = 0;

Expand Down Expand Up @@ -366,6 +366,25 @@ TEST_CASE("sx127x_test_lora_tx_implicit_header", "[lora]") {
xSemaphoreTake(fixture->tx_done, TIMEOUT);
}

TEST_CASE("sx127x_test_lora_rx_fhss", "[lora]") {
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fixture_create(&rx_fixture_config, SX127x_MODULATION_LORA, &fixture));
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_lora_set_frequency_hopping(5, frequencies, sizeof(frequencies) / sizeof(uint64_t), fixture->device));
sx127x_rx_set_callback(rx_callback, fixture->device);
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_LORA, fixture->device));
wait_for_rx_done();
TEST_ASSERT_EQUAL_UINT16(sizeof(lora_small_message), fixture->rx_data_length);
TEST_ASSERT_EQUAL_UINT8_ARRAY(lora_small_message, fixture->rx_data, sizeof(lora_small_message));
}

TEST_CASE("sx127x_test_lora_tx_fhss", "[lora]") {
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fixture_create(&rx_fixture_config, SX127x_MODULATION_LORA, &fixture));
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_lora_set_frequency_hopping(5, frequencies, sizeof(frequencies) / sizeof(uint64_t), fixture->device));
sx127x_tx_set_callback(tx_callback, fixture->device);
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_lora_tx_set_for_transmission(lora_small_message, sizeof(lora_small_message), fixture->device));
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_set_opmod(SX127x_MODE_TX, SX127x_MODULATION_LORA, fixture->device));
xSemaphoreTake(fixture->tx_done, TIMEOUT);
}

TEST_CASE("sx127x_test_ook_rx_variable_length", "[ook]") {
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fixture_create(&rx_fixture_config, SX127x_MODULATION_OOK, &fixture));
sx127x_rx_set_callback(rx_callback, fixture->device);
Expand Down
21 changes: 19 additions & 2 deletions test/test_app/pytest_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def test_explicit_header(dut: Tuple[Dut, Dut]) -> None:

dut_tx.expect('Press ENTER to see the list of tests')
dut_tx.write('"sx127x_test_lora_tx_explicit_header"')
dut_tx.expect_unity_test_output()

dut_tx.expect_unity_test_output()
dut_rx.expect_unity_test_output()

@pytest.mark.parametrize('count', [
Expand All @@ -32,8 +32,25 @@ def test_implicit_header(dut: Tuple[Dut, Dut]) -> None:

dut_tx.expect('Press ENTER to see the list of tests')
dut_tx.write('"sx127x_test_lora_tx_implicit_header"')

dut_tx.expect_unity_test_output()
dut_rx.expect_unity_test_output()

@pytest.mark.parametrize('count', [
2,
], indirect=True)
def test_fhss(dut: Tuple[Dut, Dut]) -> None:
dut_rx = dut[0]
dut_tx = dut[1]

dut_rx.expect('Press ENTER to see the list of tests')
dut_rx.write('"sx127x_test_lora_rx_fhss"')
dut_rx.expect('RX started')

dut_tx.expect('Press ENTER to see the list of tests')
dut_tx.write('"sx127x_test_lora_tx_fhss"')

dut_tx.expect_unity_test_output()
dut_rx.expect_unity_test_output()

@pytest.mark.parametrize('count', [
Expand All @@ -48,8 +65,8 @@ def test_rx_after_cad(dut: Tuple[Dut, Dut]) -> None:

dut_tx.expect('Press ENTER to see the list of tests')
dut_tx.write('"sx127x_test_lora_tx_explicit_header"')
dut_tx.expect_unity_test_output()

dut_tx.expect_unity_test_output()
dut_rx.expect_unity_test_output()

@pytest.mark.parametrize('count', [
Expand Down

0 comments on commit eb0ba86

Please sign in to comment.