Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 5d98e3e

Browse files
author
Jarkko Paso
committed
FHSS: Added support for TR51 channel function
1 parent c8a9c7c commit 5d98e3e

File tree

6 files changed

+47
-5
lines changed

6 files changed

+47
-5
lines changed

source/Service_Libs/fhss/channel_functions.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,16 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n
180180
channel_number = dh1cf_hashword(key, 3, 0) % number_of_channels;
181181
return channel_number;
182182
}
183+
184+
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
185+
{
186+
uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels);
187+
int32_t channel_table[nearest_prime];
188+
int32_t output_table[number_of_channels];
189+
uint8_t first_element;
190+
uint8_t step_size;
191+
tr51_calculate_channel_table(number_of_channels, nearest_prime, channel_table);
192+
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);
194+
return output_table[slot_number];
195+
}

source/Service_Libs/fhss/channel_functions.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table);
2525

2626
/**
27-
* @brief Calculate hopping sequence for a specific peer.
27+
* @brief Calculate hopping sequence for a specific peer using tr51 channel function.
2828
* @param channel_table Used channel table.
2929
* @param channel_table_length Length of the used channel table.
3030
* @param first_element Start generated by CFD function.
@@ -37,7 +37,16 @@ void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_
3737
uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channel_table_length, uint8_t first_element, uint8_t step_size, int32_t *output_table, uint16_t *excluded_channels, uint16_t number_of_excluded_channels);
3838

3939
/**
40-
* @brief Compute the unicast schedule channel index.
40+
* @brief Compute the unicast schedule channel index using tr51 channel function.
41+
* @param slot_number Current slot number.
42+
* @param mac MAC address of the node for which the index is calculated.
43+
* @param number_of_channels Number of channels.
44+
* @return Channel index.
45+
*/
46+
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);
47+
48+
/**
49+
* @brief Compute the unicast schedule channel index using direct hash channel function.
4150
* @param slot_number Current slot number.
4251
* @param mac MAC address of the node for which the index is calculated.
4352
* @param number_of_channels Number of channels.
@@ -46,7 +55,7 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe
4655
int32_t dh1cf_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);
4756

4857
/**
49-
* @brief Compute the broadcast schedule channel index.
58+
* @brief Compute the broadcast schedule channel index using direct hash channel function.
5059
* @param slot_number Current slot number.
5160
* @param bsi Broadcast schedule identifier of the node for which the index is calculated.
5261
* @param number_of_channels Number of channels.

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
5050
if (fhss_structure->ws->channel_function == WS_FIXED_CHANNEL) {
5151

5252
} else if (fhss_structure->ws->channel_function == WS_TR51CF) {
53-
53+
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->slot, mac_address, fhss_structure->number_of_channels);
54+
if (++fhss_structure->ws->slot == fhss_structure->number_of_channels) {
55+
fhss_structure->ws->slot = 0;
56+
}
5457
} else if (fhss_structure->ws->channel_function == WS_DH1CF) {
5558
next_channel = fhss_structure->rx_channel = dh1cf_get_uc_channel_index(fhss_structure->ws->slot, mac_address, fhss_structure->number_of_channels);
59+
fhss_structure->ws->slot++;
5660
} else if (fhss_structure->ws->channel_function == WS_VENDOR_DEF_CF) {
5761
//TODO: Callback to get channel schedule from application
5862
}
59-
fhss_structure->ws->slot++;
6063
#ifdef FHSS_CHANNEL_DEBUG
6164
tr_info("%"PRIu32" UC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel);
6265
#endif /*FHSS_CHANNEL_DEBUG*/

test/nanostack/unittest/service_libs/channel_functions/channelfunctest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ TEST(channel_functions, test_tr51_calc_nearest_prime_number)
6363
{
6464
CHECK(test_tr51_calc_nearest_prime_number());
6565
}
66+
67+
TEST(channel_functions, test_tr51_get_uc_channel_index)
68+
{
69+
CHECK(test_tr51_get_uc_channel_index());
70+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ bool test_tr51_calculate_hopping_sequence()
162162
return true;
163163
}
164164

165+
bool test_tr51_get_uc_channel_index()
166+
{
167+
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]) {
170+
return false;
171+
}
172+
}
173+
return true;
174+
}
175+
165176
bool test_dh1cf_get_uc_channel_index()
166177
{
167178
int32_t test_dh1cf_channel_table_1[10] = {19, 128, 3, 53, 79, 24, 68, 118, 7, 51};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ bool test_tr51_calculate_hopping_sequence();
3030
bool test_dh1cf_get_uc_channel_index();
3131
bool test_dh1cf_get_bc_channel_index();
3232
bool test_tr51_calc_nearest_prime_number();
33+
bool test_tr51_get_uc_channel_index();
3334

3435
#ifdef __cplusplus
3536
}

0 commit comments

Comments
 (0)