@@ -53,6 +53,23 @@ const int32_t test_HopSequenceTable[129] = { 4,93,31,84,55,3,116,123,
53
53
49 ,110 ,44 ,97 ,29 ,43 ,79 ,67 ,
54
54
77 ,48 ,100 ,51 ,14 ,21 ,94 ,23 ,
55
55
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 };
56
73
57
74
const uint16_t prime_number_table [] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 ,
58
75
31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 ,
@@ -141,8 +158,8 @@ bool test_tr51_calculate_hopping_sequence()
141
158
int32_t outtable [129 ];
142
159
tr51_calculate_channel_table (129 , 131 , chantable );
143
160
// 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 )) {
146
163
return false;
147
164
}
148
165
// Test that every channel exists once and only once.
@@ -164,11 +181,30 @@ bool test_tr51_calculate_hopping_sequence()
164
181
165
182
bool test_tr51_get_uc_channel_index ()
166
183
{
184
+ uint16_t number_of_channels = 129 ;
185
+ int32_t channel ;
186
+ int32_t test_table [number_of_channels ];
167
187
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 ) {
170
205
return false;
171
206
}
207
+ k = 0 ;
172
208
}
173
209
return true;
174
210
}
0 commit comments