Skip to content

Commit

Permalink
FHSS WS: Get MAC channel from FHSS when starting RF interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Sep 17, 2018
1 parent fe2b448 commit b2e7efc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion nanostack/fhss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_
* @param api FHSS instance.
* @param fhss_state FHSS state (FHSS states are defined by FHSS api).
* @param pan_id PAN id of the network FHSS synchronizes with.
* @return -1 when failed, otherwise current MAC channel.
*/
typedef void fhss_synch_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
typedef int16_t fhss_synch_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);

/**
* @brief Read timestamp.
Expand Down
7 changes: 4 additions & 3 deletions source/MAC/IEEE802_15_4/mac_mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,14 @@ int8_t mac_mlme_start_req(const mlme_start_t *s, struct protocol_interface_rf_ma

tr_debug("MAC: Start network %u channel %x panid", s->LogicalChannel, s->PANId);
mac_mlme_set_panid(rf_mac_setup, s->PANId);

// Synchronize FHSS
if (rf_mac_setup->fhss_api) {
rf_mac_setup->fhss_api->synch_state_set(rf_mac_setup->fhss_api, FHSS_SYNCHRONIZED, s->PANId);
rf_mac_setup->mac_channel = rf_mac_setup->fhss_api->synch_state_set(rf_mac_setup->fhss_api, FHSS_SYNCHRONIZED, s->PANId);
} else {
rf_mac_setup->mac_channel = s->LogicalChannel;
}

rf_mac_setup->mac_channel = s->LogicalChannel;

mac_mlme_start_request(rf_mac_setup);
if (s->PANCoordinator) {
//tr_debug("Cordinator");
Expand Down
12 changes: 6 additions & 6 deletions source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,16 +700,16 @@ static void fhss_update_beacon_info_lifetimes(fhss_structure_t *fhss_structure,
}
}

static void fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
static int16_t fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
return -1;
}
// State is already set
if (fhss_structure->fhss_state == fhss_state) {
tr_debug("Synch same state %u", fhss_state);
return;
return -1;
}

if (fhss_state == FHSS_UNSYNCHRONIZED) {
Expand All @@ -723,7 +723,7 @@ static void fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states fhs
// Do not synchronize to current pan
if (fhss_structure->bs->synch_panid == pan_id) {
tr_debug("Synch same panid %u", pan_id);
return;
return -1;
}
fhss_generate_scramble_table(fhss_structure);

Expand All @@ -748,11 +748,11 @@ static void fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states fhs
fhss_start_timer(fhss_structure, fhss_structure->bs->synch_configuration.fhss_superframe_length, fhss_superframe_handler);
} else {
tr_error("Synch info not found");
return;
return -1;
}
}
fhss_structure->fhss_state = fhss_state;
return;
return fhss_structure->rx_channel;
}

static void fhss_beacon_decode_raw(fhss_synchronization_beacon_payload_s* dest, const uint8_t* buffer)
Expand Down
10 changes: 7 additions & 3 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ static uint32_t fhss_ws_get_sf_timeout_callback(fhss_structure_t *fhss_structure
return fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval * 1000;
}

static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
static int16_t fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
{
(void) pan_id;
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return;
return -1;
}
if (fhss_state == FHSS_SYNCHRONIZED) {
uint32_t fhss_broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;
Expand All @@ -306,7 +306,11 @@ static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states
}

fhss_structure->fhss_state = fhss_state;
return;
int16_t current_channel = fhss_structure->rx_channel;
if (fhss_structure->ws->is_on_bc_channel == true) {
current_channel = fhss_structure->ws->bc_channel;
}
return current_channel;
}

static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
Expand Down

0 comments on commit b2e7efc

Please sign in to comment.