/**
 * @file ft_sender.c
 *
 * @brief This file contains functions that provides demonstration of
 *        usage of state machine APIs for sender operation
 *
 * The functions provided in the file provides demonstration on
 * usage of state machine APIs
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *        usage of TC TM Library APIs
 */
#include <stdio.h>


/******************************************************************************/
/*                      Include headers of the component                      */
/******************************************************************************/


#include "ft_sender.h"
#include "ft_receiver.h"
#include "file_transfer.h"
#include "ftci.h"
#include "ftds.h"
#include "ftsr_decode.h"
#include "ft_config.h"
#include "segmentation.h"
#include "suspend_resume.h"
#include "exo_common.h"



/******************************************************************************/
/*                      Definition of exported functions                      */
/******************************************************************************/


/**
 *@brief State Machine :Function that handles data transmission and input collecting
 *
 */
void ft_statemachine_upload(void)
{
	eSystemState currentState;

  	if(tx_info.seq_loss_detect_enable != SEQ_LOSS_DETECTION_OFF)
  	{
  		ft_sus_res_handler();
  	}
 	else
 	{
 		/* packet loss detection will not work */
 	}
	currentState = ft_fsm_read_state();
	switch (currentState)
	{

		case FT_Init:
			break;

		case FT_Idle_State:
			break;

		case FT_Send_Upload_Request:
			ftci();
			break;

		case FT_Wait_for_2sec:
			ftds_waitfor2seconds();
			break;

		case FT_Segmentation:
			segmentation();
			break;

		case FT_Sequence_Transmission:
			ftds();
			break;

		case FT_Waitfor_FTSR:
			ftds();
			break;

		case FT_Suspended:
			break;

		case FT_Resumed:
			break;

		default:
			break;
	}
}
/**
 *@brief State Machine :Function that use to update the session id
 *
 */
void ft_tx_session_id_update(uint8 option)
{
	if(option == FT_SESSION_ID_INC)
	{
		if(tx_info.session_id < FT_SESSION_ID_MAX)
		{
			tx_info.session_id++;
		}
		else
		{
			tx_info.session_id = 1;
		}
	}
	else if(option == FT_SESSION_ID_DEC)
	{
		if(session_id > 0)
		{
			tx_info.session_id--;
		}
		else
		{
		}
	}
	else if(option == FT_SESSION_ID_CLR)
	{
		tx_info.session_id = 0;
	}
	else
	{
		DEBUG_CPRINT(("INVALID OPTION\n"));
	}
}

/**
 *@brief State Machine :Function that use to read session id
 *
 */
uint8_t ft_tx_session_id_read(void)
{
	return tx_info.session_id;
}




