Skip to content

Commit 9a98177

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1552 from ARMmbed/cf_update
FHSS: TR51 channel function updated (bug in the spec?)
2 parents 6b04d5a + 30075dd commit 9a98177

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

source/Service_Libs/fhss/channel_functions.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe
129129
}
130130
}
131131
index += step_size;
132-
while (index >= channel_table_length) {
133-
index -= channel_table_length;
134-
}
132+
index %= channel_table_length;
135133
}
136134
return slot;
137135
}
@@ -190,6 +188,8 @@ int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t nu
190188
uint8_t step_size;
191189
tr51_calculate_channel_table(number_of_channels, nearest_prime, channel_table);
192190
tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime);
193-
tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0);
191+
// Not sure yet which one is the correct second parameter
192+
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0);
193+
tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, NULL, 0);
194194
return output_table[slot_number];
195195
}

test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ const int32_t test_HopSequenceTable[129] = { 4,93,31,84,55,3,116,123,
5353
49,110,44,97,29,43,79,67,
5454
77,48,100,51,14,21,94,23,
5555
22 };
56+
const int32_t test_HopSequenceTable2[129] = { 4, 42, 85, 0, 32, 116, 19, 17,
57+
119, 44, 25, 71, 95, 37, 75, 48,
58+
125, 106, 92, 39, 23, 78, 56, 10,
59+
127, 27, 3, 87, 76, 5, 110, 28,
60+
57, 61, 70, 101, 77, 112, 13, 40,
61+
58, 94, 128, 15, 34, 121, 55, 114,
62+
60, 83, 49, 105, 104, 2, 9, 67,
63+
20, 99, 12, 24, 21, 89, 16, 8,
64+
63, 115, 84, 64, 36, 107, 111, 68,
65+
53, 98, 113, 108, 79, 122, 45, 96,
66+
126, 14, 69, 6, 102, 120, 50, 31,
67+
30, 91, 72, 38, 41, 47, 117, 86,
68+
82, 43, 66, 81, 7, 103, 51, 11,
69+
46, 74, 90, 52, 93, 124, 109, 73,
70+
88, 123, 65, 62, 1, 97, 29, 33,
71+
18, 59, 35, 100, 118, 54, 80, 26,
72+
22 };
5673

5774
const uint16_t prime_number_table[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
5875
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
@@ -141,8 +158,8 @@ bool test_tr51_calculate_hopping_sequence()
141158
int32_t outtable[129];
142159
tr51_calculate_channel_table(129, 131, chantable);
143160
// Test generating hopping sequence table of specific peer
144-
tr51_calculate_hopping_sequence(chantable, 129, 122, 119, outtable, NULL, 0);
145-
if (memcmp(outtable, test_HopSequenceTable, 129*4)) {
161+
tr51_calculate_hopping_sequence(chantable, 131, 122, 119, outtable, NULL, 0);
162+
if (memcmp(outtable, test_HopSequenceTable2, 129*4)) {
146163
return false;
147164
}
148165
// Test that every channel exists once and only once.
@@ -164,11 +181,30 @@ bool test_tr51_calculate_hopping_sequence()
164181

165182
bool test_tr51_get_uc_channel_index()
166183
{
184+
uint16_t number_of_channels = 129;
185+
int32_t channel;
186+
int32_t test_table[number_of_channels];
167187
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
168-
for (int i=0; i<129; i++) {
169-
if (tr51_get_uc_channel_index(i, mac, 129) != test_HopSequenceTable[i]) {
188+
for (int i=0; i<number_of_channels; i++) {
189+
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels);
190+
// Not sure yet which one is correct since there might be bug in spec
191+
// if (channel != test_HopSequenceTable[i]) {
192+
if (channel != test_HopSequenceTable2[i]) {
193+
return false;
194+
}
195+
}
196+
// Test that every channel exists once and only once.
197+
int k=0;
198+
for (int h=0; h<number_of_channels; h++) {
199+
for (int j=0; j<number_of_channels; j++) {
200+
if (test_table[j] == h) {
201+
k++;
202+
}
203+
}
204+
if (k != 1) {
170205
return false;
171206
}
207+
k=0;
172208
}
173209
return true;
174210
}

0 commit comments

Comments
 (0)