Skip to content

Commit

Permalink
FHSS: Added support for TR51 channel function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jan 25, 2018
1 parent c8a9c7c commit 5d98e3e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
13 changes: 13 additions & 0 deletions source/Service_Libs/fhss/channel_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,16 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n
channel_number = dh1cf_hashword(key, 3, 0) % number_of_channels;
return channel_number;
}

int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
{
uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels);
int32_t channel_table[nearest_prime];
int32_t output_table[number_of_channels];
uint8_t first_element;
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);
return output_table[slot_number];
}
15 changes: 12 additions & 3 deletions source/Service_Libs/fhss/channel_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table);

/**
* @brief Calculate hopping sequence for a specific peer.
* @brief Calculate hopping sequence for a specific peer using tr51 channel function.
* @param channel_table Used channel table.
* @param channel_table_length Length of the used channel table.
* @param first_element Start generated by CFD function.
Expand All @@ -37,7 +37,16 @@ void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_
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);

/**
* @brief Compute the unicast schedule channel index.
* @brief Compute the unicast schedule channel index using tr51 channel function.
* @param slot_number Current slot number.
* @param mac MAC address of the node for which the index is calculated.
* @param number_of_channels Number of channels.
* @return Channel index.
*/
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);

/**
* @brief Compute the unicast schedule channel index using direct hash channel function.
* @param slot_number Current slot number.
* @param mac MAC address of the node for which the index is calculated.
* @param number_of_channels Number of channels.
Expand All @@ -46,7 +55,7 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe
int32_t dh1cf_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);

/**
* @brief Compute the broadcast schedule channel index.
* @brief Compute the broadcast schedule channel index using direct hash channel function.
* @param slot_number Current slot number.
* @param bsi Broadcast schedule identifier of the node for which the index is calculated.
* @param number_of_channels Number of channels.
Expand Down
7 changes: 5 additions & 2 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
if (fhss_structure->ws->channel_function == WS_FIXED_CHANNEL) {

} else if (fhss_structure->ws->channel_function == WS_TR51CF) {

next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->slot, mac_address, fhss_structure->number_of_channels);
if (++fhss_structure->ws->slot == fhss_structure->number_of_channels) {
fhss_structure->ws->slot = 0;
}
} else if (fhss_structure->ws->channel_function == WS_DH1CF) {
next_channel = fhss_structure->rx_channel = dh1cf_get_uc_channel_index(fhss_structure->ws->slot, mac_address, fhss_structure->number_of_channels);
fhss_structure->ws->slot++;
} else if (fhss_structure->ws->channel_function == WS_VENDOR_DEF_CF) {
//TODO: Callback to get channel schedule from application
}
fhss_structure->ws->slot++;
#ifdef FHSS_CHANNEL_DEBUG
tr_info("%"PRIu32" UC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel);
#endif /*FHSS_CHANNEL_DEBUG*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ TEST(channel_functions, test_tr51_calc_nearest_prime_number)
{
CHECK(test_tr51_calc_nearest_prime_number());
}

TEST(channel_functions, test_tr51_get_uc_channel_index)
{
CHECK(test_tr51_get_uc_channel_index());
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ bool test_tr51_calculate_hopping_sequence()
return true;
}

bool test_tr51_get_uc_channel_index()
{
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]) {
return false;
}
}
return true;
}

bool test_dh1cf_get_uc_channel_index()
{
int32_t test_dh1cf_channel_table_1[10] = {19, 128, 3, 53, 79, 24, 68, 118, 7, 51};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bool test_tr51_calculate_hopping_sequence();
bool test_dh1cf_get_uc_channel_index();
bool test_dh1cf_get_bc_channel_index();
bool test_tr51_calc_nearest_prime_number();
bool test_tr51_get_uc_channel_index();

#ifdef __cplusplus
}
Expand Down

0 comments on commit 5d98e3e

Please sign in to comment.