@@ -728,12 +728,16 @@ void fhss_failed_list_free(fhss_structure_t *fhss_structure)
728728 }
729729}
730730
731- static int fhss_handle_state_set (fhss_structure_t * fhss_structure , fhss_states fhss_state , uint16_t pan_id )
731+ static void fhss_handle_state_set (const fhss_api_t * api , fhss_states fhss_state , uint16_t pan_id )
732732{
733+ fhss_structure_t * fhss_structure = fhss_get_object_with_api (api );
734+ if (!fhss_structure ) {
735+ return ;
736+ }
733737 // State is already set
734738 if (fhss_structure -> fhss_state == fhss_state ) {
735739 tr_debug ("Synch same state %u" , fhss_state );
736- return -1 ;
740+ return ;
737741 }
738742
739743 if (fhss_state == FHSS_UNSYNCHRONIZED ) {
@@ -747,12 +751,12 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
747751 // Do not synchronize to current pan
748752 if (fhss_structure -> synch_panid == pan_id ) {
749753 tr_debug ("Synch same panid %u" , pan_id );
750- return -1 ;
754+ return ;
751755 }
752756 if (fhss_structure -> fhss_scramble_table == NULL ) {
753757 if (fhss_generate_scramble_table (fhss_structure )) {
754758 tr_error ("Failed to generate scramble table" );
755- return -1 ;
759+ return ;
756760 }
757761 }
758762 uint32_t datarate = fhss_structure -> callbacks .read_datarate (fhss_structure -> fhss_api );
@@ -778,10 +782,11 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
778782 fhss_start_timer (fhss_structure , fhss_structure -> synch_configuration .fhss_superframe_length , fhss_superframe_handler );
779783 } else {
780784 tr_error ("Synch info not found" );
781- return -1 ;
785+ return ;
782786 }
783787 }
784- return 0 ;
788+ fhss_structure -> fhss_state = fhss_state ;
789+ return ;
785790}
786791
787792static void fhss_destroy_scramble_table (fhss_structure_t * fhss_structure )
@@ -914,6 +919,42 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
914919 }
915920}
916921
922+ static int16_t fhss_write_synch_info_callback (const fhss_api_t * api , uint8_t * info_ptr , int info_type , int frame_type_id , uint32_t tx_time )
923+ {
924+ fhss_structure_t * fhss_structure = fhss_get_object_with_api (api );
925+ (void ) frame_type_id ;
926+ (void ) tx_time ;
927+ if (!fhss_structure ) {
928+ return -1 ;
929+ }
930+ if (info_type == FHSS_PLAIN_SYNCH_INFO ) {
931+ if (!info_ptr ) {
932+ return -1 ;
933+ }
934+ fhss_beacon_build (fhss_structure , info_ptr );
935+ return FHSS_SYNCH_INFO_LENGTH ;
936+ }
937+ return -1 ;
938+ }
939+
940+ static void fhss_data_tx_done_callback (const fhss_api_t * api , bool waiting_ack , bool tx_completed , uint8_t handle )
941+ {
942+ fhss_structure_t * fhss_structure = fhss_get_object_with_api (api );
943+ if (!fhss_structure ) {
944+ return ;
945+ }
946+ if (waiting_ack == false) {
947+ fhss_change_to_rx_channel (fhss_structure );
948+ }
949+ // Buffer was successfully transmitted. Remove stored failure handle if exists.
950+ if (tx_completed == true) {
951+ fhss_failed_tx_t * fhss_failed_tx = fhss_failed_handle_find (fhss_structure , handle );
952+ if (fhss_failed_tx ) {
953+ fhss_failed_handle_remove (fhss_structure , handle );
954+ }
955+ }
956+ }
957+
917958int fhss_set_callbacks (fhss_structure_t * fhss_structure )
918959{
919960 // Set external API
@@ -922,17 +963,16 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure)
922963 fhss_structure -> fhss_api -> tx_handle = & fhss_tx_handle_callback ;
923964 fhss_structure -> fhss_api -> check_tx_conditions = & fhss_check_tx_conditions_callback ;
924965 fhss_structure -> fhss_api -> receive_frame = & fhss_receive_frame_cb ;
925- fhss_structure -> fhss_api -> data_tx_done = & fhss_data_tx_done_cb ;
966+ fhss_structure -> fhss_api -> data_tx_done = & fhss_data_tx_done_callback ;
926967 fhss_structure -> fhss_api -> data_tx_fail = & fhss_data_tx_fail_cb ;
927- fhss_structure -> fhss_api -> synch_state_set = & fhss_synch_state_set_cb ;
968+ fhss_structure -> fhss_api -> synch_state_set = & fhss_handle_state_set ;
928969 fhss_structure -> fhss_api -> read_timestamp = & fhss_read_timestamp_cb ;
929970 fhss_structure -> fhss_api -> get_retry_period = & fhss_get_retry_period_cb ;
930- fhss_structure -> fhss_api -> write_synch_info = & fhss_write_synch_info_cb ;
971+ fhss_structure -> fhss_api -> write_synch_info = & fhss_write_synch_info_callback ;
931972 fhss_structure -> fhss_api -> init_callbacks = & fhss_init_callbacks_cb ;
932973 // Set internal API
933974 fhss_structure -> update_channel = fhss_update_channel_callback ;
934975 fhss_structure -> update_superframe = fhss_superframe_callback ;
935976 fhss_structure -> read_superframe_timeout = fhss_get_sf_timeout_callback ;
936- fhss_structure -> handle_state_set = fhss_handle_state_set ;
937977 return 0 ;
938978}
0 commit comments