18
18
#include "Service_Libs/fhss/channel_functions.h"
19
19
#include "test_channel_functions.h"
20
20
21
- const int32_t test_channel_table [131 ] = { 57 ,78 ,25 ,22 ,97 ,90 ,86 ,102 ,
22
- 98 ,16 ,104 ,128 ,28 ,23 ,44 ,26 ,
23
- 1 ,74 ,117 ,6 ,53 ,89 ,105 ,94 ,
24
- 110 ,39 ,119 ,80 ,62 ,46 ,47 ,69 ,
25
- 68 ,21 ,49 ,58 ,5 ,92 ,17 ,54 ,
26
- 65 ,11 ,41 ,14 ,111 ,24 ,83 ,40 ,
27
- 76 ,106 ,19 ,118 ,123 ,51 ,38 ,126 ,
28
- 107 ,12 ,60 ,13 ,87 ,125 ,116 ,100 ,
29
- 88 ,103 ,72 ,96 ,36 ,99 ,114 ,112 ,
30
- 3 ,48 ,32 ,35 ,73 ,7 ,91 ,45 ,
31
- 64 ,20 ,55 ,77 ,27 ,75 ,0 ,59 ,
32
- 109 ,81 ,30 ,122 ,84 ,67 ,121 ,101 ,
33
- 127 ,37 ,85 ,18 ,124 ,66 ,31 ,79 ,
34
- 115 ,9 ,34 ,70 ,10 ,95 ,42 ,33 ,
35
- 93 ,43 ,50 ,108 ,63 ,2 ,15 ,61 ,
36
- 56 ,71 ,4 ,29 ,52 ,82 ,120 ,113 ,
37
- 8 ,-1 ,-1 };
38
-
39
21
const int32_t test_HopSequenceTable [129 ] = { 4 ,93 ,31 ,84 ,55 ,3 ,116 ,123 ,
40
22
41 ,68 ,105 ,28 ,25 ,71 ,33 ,66 ,
41
23
122 ,20 ,112 ,125 ,118 ,11 ,69 ,89 ,
@@ -71,102 +53,44 @@ const int32_t test_HopSequenceTable2[129] = { 4, 42, 85, 0, 32, 116, 19, 17,
71
53
18 , 59 , 35 , 100 , 118 , 54 , 80 , 26 ,
72
54
22 };
73
55
74
- const uint16_t prime_number_table [ ] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 ,
75
- 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 ,
76
- 73 , 79 , 83 , 89 , 97 , 101 , 103 , 107 , 109 , 113 ,
77
- 127 , 131 , 137 , 139 , 149 , 151 , 157 , 163 , 167 , 173 ,
78
- 179 , 181 , 191 , 193 , 197 , 199 , 211 , 223 , 227 , 229 ,
79
- 233 , 239 , 241 , 251 , 257 , 263 , 269 , 271 , 277 , 281 ,
80
- 283 , 293 , 307 , 311 , 313 , 317 , 331 , 337 , 347 , 349 ,
81
- 353 , 359 , 367 , 373 , 379 , 383 , 389 , 397 , 401 , 409 ,
82
- 419 , 421 , 431 , 433 , 439 , 443 , 449 , 457 , 461 , 463 ,
83
- 467 , 479 , 487 , 491 , 499 , 503 , 509 , 521 , 523 , 541 ,
84
- 547 , 557 , 563 , 569 , 571 , 577 , 587 , 593 , 599 , 601 ,
85
- 607 , 613 , 617 , 619 , 631 , 641 , 643 , 647 , 653 , 659 ,
86
- 661 , 673 , 677 , 683 , 691 , 701 , 709 , 719 , 727 , 733 ,
87
- 739 , 743 , 751 , 757 , 761 , 769 , 773 , 787 , 797 , 809 ,
88
- 811 , 821 , 823 , 827 , 829 , 839 , 853 , 857 , 859 , 863 ,
89
- 877 , 881 , 883 , 887 , 907 , 911 , 919 , 929 , 937 , 941 ,
90
- 947 , 953 , 967 , 971 , 977 , 983 , 991 , 997 , 1009 };
56
+ const int32_t test_HopSequenceTable3 [ 129 ] = { 124 , 114 , 65 , 104 , 33 , 20 , 118 , 89 ,
57
+ 4 , 84 , 116 , 68 , 25 , 79 , 48 , 14 ,
58
+ 23 , 50 , 27 , 38 , 110 , 82 , 101 , 103 ,
59
+ 58 , 90 , 34 , 73 , 83 , 1 , 2 , 59 ,
60
+ 12 , 80 , 8 , 85 , 36 , 17 , 98 , 95 ,
61
+ 45 , 106 , 6 , 56 , 30 , 87 , 47 , 57 ,
62
+ 66 , 112 , 11 , 128 , 93 , 55 , 123 , 105 ,
63
+ 29 , 67 , 100 , 21 , 22 , 115 , 32 , 111 ,
64
+ 44 , 108 , 75 , 126 , 39 , 120 , 127 , 72 ,
65
+ 5 , 86 , 70 , 7 , 40 , 74 , 15 , 109 ,
66
+ 60 , 62 , 18 , 99 , 54 , 16 , 42 , 64 ,
67
+ 19 , 53 , 71 , 122 , 125 , 69 , 78 , 31 ,
68
+ 3 , 41 , 28 , 43 , 77 , 51 , 94 , 52 ,
69
+ 121 , 88 , 49 , 97 , 9 , 35 , 24 , 26 ,
70
+ 63 , 0 , 107 , 119 , 113 , 37 , 96 , 92 ,
71
+ 102 , 10 , 91 , 76 , 117 , 61 , 81 , 13 ,
72
+ 46 };
91
73
92
- bool test_tr51_get_rand ()
93
- {
94
- tr51_seed_rand (1 );
95
- // Test first few random values
96
- if (1103527590 != tr51_get_rand ()) {
97
- return false;
98
- }
99
- if (377401575 != tr51_get_rand ()) {
100
- return false;
101
- }
102
- if (662824084 != tr51_get_rand ()) {
103
- return false;
104
- }
105
- if (1147902781 != tr51_get_rand ()) {
106
- return false;
107
- }
108
- if (2035015474 != tr51_get_rand ()) {
109
- return false;
110
- }
111
- return true;
112
- }
113
-
114
- bool test_tr51_calculate_channel_table ()
74
+ bool test_tr51_get_uc_channel_index ()
115
75
{
116
- int32_t chantable [131 ];
117
- // Test generating channel table
118
- tr51_calculate_channel_table (129 , 131 , chantable );
119
- if (memcmp (chantable , test_channel_table , 131 * 4 )) {
120
- return false;
121
- }
122
-
123
- // Test that every channel exists once and only once.
124
- int k = 0 ;
125
- for (int i = 0 ; i < 129 ; i ++ ) {
126
- for (int j = 0 ; j < 131 ; j ++ ) {
127
- if (chantable [j ] == i ) {
128
- k ++ ;
129
- }
130
- }
131
- if (k != 1 ) {
76
+ int i ;
77
+ uint16_t number_of_channels = 129 ;
78
+ int32_t channel ;
79
+ int32_t test_table [number_of_channels ];
80
+ uint8_t mac [8 ] = {0x00 , 0x13 , 0x50 , 0x04 , 0x00 , 0x00 , 0x05 , 0xf8 };
81
+ for (i = 0 ; i < number_of_channels ; i ++ ) {
82
+ test_table [i ] = channel = tr51_get_uc_channel_index (i , mac , number_of_channels , NULL , 0 );
83
+ // Not sure yet which one is correct since there might be bug in spec
84
+ // if (channel != test_HopSequenceTable[i]) {
85
+ if (channel != test_HopSequenceTable2 [i ]) {
132
86
return false;
133
87
}
134
- k = 0 ;
135
- }
136
- return true;
137
- }
138
-
139
- bool test_tr51_compute_cfd ()
140
- {
141
- uint8_t first_element ;
142
- uint8_t step_size ;
143
- uint8_t mac [8 ] = {0x00 , 0x13 , 0x50 , 0x04 , 0x00 , 0x00 , 0x05 , 0xf8 };
144
- // Test generating first element and step size
145
- tr51_compute_cfd (mac , & first_element , & step_size , 131 );
146
- if (122 != first_element ) {
147
- return false;
148
- }
149
- if (119 != step_size ) {
150
- return false;
151
- }
152
- return true;
153
- }
154
-
155
- bool test_tr51_calculate_hopping_sequence ()
156
- {
157
- int32_t chantable [131 ];
158
- int32_t outtable [129 ];
159
- tr51_calculate_channel_table (129 , 131 , chantable );
160
- // Test generating hopping sequence table of specific peer
161
- tr51_calculate_hopping_sequence (chantable , 131 , 122 , 119 , outtable , NULL , 0 );
162
- if (memcmp (outtable , test_HopSequenceTable2 , 129 * 4 )) {
163
- return false;
164
88
}
165
89
// Test that every channel exists once and only once.
166
90
int k = 0 ;
167
- for (int i = 0 ; i < 129 ; i ++ ) {
168
- for (int j = 0 ; j < 129 ; j ++ ) {
169
- if (outtable [j ] == i ) {
91
+ for (int h = 0 ; h < number_of_channels ; h ++ ) {
92
+ for (int j = 0 ; j < number_of_channels ; j ++ ) {
93
+ if (test_table [j ] == h ) {
170
94
k ++ ;
171
95
}
172
96
}
@@ -179,17 +103,15 @@ bool test_tr51_calculate_hopping_sequence()
179
103
return true;
180
104
}
181
105
182
- bool test_tr51_get_uc_channel_index ()
106
+ bool test_tr51_get_bc_channel_index ()
183
107
{
184
108
uint16_t number_of_channels = 129 ;
185
109
int32_t channel ;
110
+ uint16_t bsi = 100 ;
186
111
int32_t test_table [number_of_channels ];
187
- uint8_t mac [8 ] = {0x00 , 0x13 , 0x50 , 0x04 , 0x00 , 0x00 , 0x05 , 0xf8 };
188
112
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 ]) {
113
+ test_table [i ] = channel = tr51_get_bc_channel_index (i , bsi , number_of_channels , NULL , 0 );
114
+ if (channel != test_HopSequenceTable3 [i ]) {
193
115
return false;
194
116
}
195
117
}
@@ -258,21 +180,3 @@ bool test_dh1cf_get_bc_channel_index()
258
180
}
259
181
return true;
260
182
}
261
-
262
- bool test_tr51_calc_nearest_prime_number ()
263
- {
264
- uint16_t prime_number ;
265
- int j ;
266
- for (int i = 2 ; i < 1000 ; i ++ ) {
267
- prime_number = tr51_calc_nearest_prime_number (i );
268
- for (j = 0 ; j < sizeof (prime_number_table ); j ++ ) {
269
- if (prime_number == prime_number_table [j ]) {
270
- break ;
271
- }
272
- }
273
- if (j >= sizeof (prime_number_table )) {
274
- return false;
275
- }
276
- }
277
- return true;
278
- }
0 commit comments