From 30075ddcdc1cc53b8d96756af8c237c5abcbf096 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Thu, 1 Feb 2018 14:18:33 +0200 Subject: [PATCH] FHSS: TR51 channel function updated (bug in the spec?) --- source/Service_Libs/fhss/channel_functions.c | 8 ++-- .../test_channel_functions.c | 44 +++++++++++++++++-- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/source/Service_Libs/fhss/channel_functions.c b/source/Service_Libs/fhss/channel_functions.c index a293803916c..da9df1b3f75 100644 --- a/source/Service_Libs/fhss/channel_functions.c +++ b/source/Service_Libs/fhss/channel_functions.c @@ -129,9 +129,7 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe } } index += step_size; - while (index >= channel_table_length) { - index -= channel_table_length; - } + index %= channel_table_length; } return slot; } @@ -190,6 +188,8 @@ int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t nu uint8_t step_size; tr51_calculate_channel_table(number_of_channels, nearest_prime, channel_table); tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime); - tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0); +// Not sure yet which one is the correct second parameter +// tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0); + tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, NULL, 0); return output_table[slot_number]; } diff --git a/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c b/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c index ee885b83fca..2e734082748 100644 --- a/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c +++ b/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c @@ -53,6 +53,23 @@ const int32_t test_HopSequenceTable[129] = { 4,93,31,84,55,3,116,123, 49,110,44,97,29,43,79,67, 77,48,100,51,14,21,94,23, 22 }; +const int32_t test_HopSequenceTable2[129] = { 4, 42, 85, 0, 32, 116, 19, 17, + 119, 44, 25, 71, 95, 37, 75, 48, + 125, 106, 92, 39, 23, 78, 56, 10, + 127, 27, 3, 87, 76, 5, 110, 28, + 57, 61, 70, 101, 77, 112, 13, 40, + 58, 94, 128, 15, 34, 121, 55, 114, + 60, 83, 49, 105, 104, 2, 9, 67, + 20, 99, 12, 24, 21, 89, 16, 8, + 63, 115, 84, 64, 36, 107, 111, 68, + 53, 98, 113, 108, 79, 122, 45, 96, + 126, 14, 69, 6, 102, 120, 50, 31, + 30, 91, 72, 38, 41, 47, 117, 86, + 82, 43, 66, 81, 7, 103, 51, 11, + 46, 74, 90, 52, 93, 124, 109, 73, + 88, 123, 65, 62, 1, 97, 29, 33, + 18, 59, 35, 100, 118, 54, 80, 26, + 22 }; const uint16_t prime_number_table[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, @@ -141,8 +158,8 @@ bool test_tr51_calculate_hopping_sequence() int32_t outtable[129]; tr51_calculate_channel_table(129, 131, chantable); // Test generating hopping sequence table of specific peer - tr51_calculate_hopping_sequence(chantable, 129, 122, 119, outtable, NULL, 0); - if (memcmp(outtable, test_HopSequenceTable, 129*4)) { + tr51_calculate_hopping_sequence(chantable, 131, 122, 119, outtable, NULL, 0); + if (memcmp(outtable, test_HopSequenceTable2, 129*4)) { return false; } // Test that every channel exists once and only once. @@ -164,11 +181,30 @@ bool test_tr51_calculate_hopping_sequence() bool test_tr51_get_uc_channel_index() { + uint16_t number_of_channels = 129; + int32_t channel; + int32_t test_table[number_of_channels]; uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8}; - for (int i=0; i<129; i++) { - if (tr51_get_uc_channel_index(i, mac, 129) != test_HopSequenceTable[i]) { + for (int i=0; i