Skip to content

Commit

Permalink
FHSS: TR51 channel function updated (bug in the spec?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Feb 1, 2018
1 parent 6b04d5a commit 30075dd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
8 changes: 4 additions & 4 deletions source/Service_Libs/fhss/channel_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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<number_of_channels; i++) {
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels);
// Not sure yet which one is correct since there might be bug in spec
// if (channel != test_HopSequenceTable[i]) {
if (channel != test_HopSequenceTable2[i]) {
return false;
}
}
// Test that every channel exists once and only once.
int k=0;
for (int h=0; h<number_of_channels; h++) {
for (int j=0; j<number_of_channels; j++) {
if (test_table[j] == h) {
k++;
}
}
if (k != 1) {
return false;
}
k=0;
}
return true;
}
Expand Down

0 comments on commit 30075dd

Please sign in to comment.