/*
 * exo_ahw_vdp_linux_thruster.c
 *
 *  @brief This file contains the vendor driver porting function of ADM1176 hot swap controller
 *
 * @copyright Copyright 2024 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.
 */

#include "exo_ahw_vdp_linux_thruster.h"
#include "thruster_simu.h"

#ifdef LINUX_TEMP_PORT
#include "exo_thruster_linux_sim_skt.h"
#endif

extern ahw_io_map *ahw_io_lookup_tble[MAX_AH_INST_ID];
extern void *intf_inst_hdle_ptr[MAX_IO_INST_ID];

extern thruster_write_fptr_t thrstr_write;
extern thruster_read_fptr_t  thrstr_read;

hal_ret_sts ahw_vdp_linux_thruster_init()
{
#ifdef LINUX_TEMP_PORT
    thrstr_write = thr_simu_data_write;
    thrstr_read  = thr_simu_data_read;
#endif
    return 0;
}

/*!
 *  @brief This VDP API get thruster mode 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_operating_mode(uint8_t thruster_id, uint8_t* get_mde)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_operating_mode(thruster_id,get_mde);
    return sts;
}

/*!
 *  @brief This VDP API set thruster mode 
 */
hal_ret_sts ahw_vdp_linux_thruster_set_operating_mode(uint8_t thruster_id, uint8_t set_mde)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_set_operating_mode(thruster_id,set_mde);
    return sts;
}

/*!
 *  @brief This VDP API set thruster firing duration 
 */
hal_ret_sts ahw_vdp_linux_thruster_set_firing_duration(uint8_t thruster_id, uint32_t thr_st_firng_dur)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_set_firing_duration(thruster_id,thr_st_firng_dur);
    return sts;
}

/*!
 *  @brief This VDP API get thruster firing duration 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_firing_duration(uint8_t thruster_id, uint32_t* thr_gt_firng_dur)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_firing_duration(thruster_id,thr_gt_firng_dur);
    return sts;
}

/*!
 *  @brief This VDP API set thruster onboard temperature
 */
hal_ret_sts ahw_vdp_linux_thruster_get_on_board_temperature(uint8_t thruster_id,float* get_onbrd_temp)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_onbrd_temperature(thruster_id,get_onbrd_temp);
    return sts;
}

/*!
 *  @brief This VDP API set radiator low temp threshold 
 */
hal_ret_sts ahw_vdp_linux_thruster_set_radiator_low_temp_threshold(uint8_t thruster_id, float thr_set_rad_lw_temp)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_set_radiator_low_temp_threshold(thruster_id,thr_set_rad_lw_temp);
    return sts;
}

/*!
 *  @brief This VDP API get radiator low temp threshold 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_radiator_low_temp_threshold(uint8_t thruster_id, float* thr_get_rad_lw_temp)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_radiator_low_temp_threshold(thruster_id,thr_get_rad_lw_temp);
    return sts;
}

/*!
 *  @brief This VDP API set radiator high temp threshold 
 */
hal_ret_sts ahw_vdp_linux_thruster_set_radiator_high_temp_threshold(uint8_t thruster_id, float thr_set_rad_hg_temp)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_set_radiator_high_temp_threshold(thruster_id,thr_set_rad_hg_temp);
    return sts;
}

/*!
 *  @brief This VDP API get radiator high temp threshold 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_radiator_high_temp_threshold(uint8_t thruster_id, float* thr_get_rad_hg_temp)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_radiator_high_temp_threshold(thruster_id,thr_get_rad_hg_temp);
    return sts;
}

/*!
 *  @brief This VDP API get remaining propellant level 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_remaining_propellant_level(uint8_t thruster_id, float* get_rmg_prplnt_lvl)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_remaining_propellant_level(thruster_id,get_rmg_prplnt_lvl);
    return sts;
}

/*!
 *  @brief This VDP API get input power voltage consmp 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_input_power_voltage_consmp(uint8_t thruster_id, float* get_voltage)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_input_power_voltage_consmp(thruster_id,get_voltage);
    return sts;
}

/*!
 *  @brief This VDP API get input power current consmp
 */
hal_ret_sts ahw_vdp_linux_thruster_get_input_power_current_consmp(uint8_t thruster_id, float* get_current)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_input_power_current_consmp(thruster_id,get_current);
    return sts;
}

/*!
 *  @brief This VDP API set min tank pressure limit 
 */
hal_ret_sts ahw_vdp_linux_thruster_set_min_tank_pressure_limit(uint8_t thruster_id, float set_min_tnk_prs)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_set_min_tank_pressure_limit(thruster_id,set_min_tnk_prs);
    return sts;
}

/*!
 *  @brief This VDP API set max tank pressure limit 
 */
hal_ret_sts ahw_vdp_linux_thruster_set_max_tank_pressure_limit(uint8_t thruster_id, float set_max_tnk_prs)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_set_max_tank_pressure_limit(thruster_id,set_max_tnk_prs);
    return sts;
}

/*!
 *  @brief This VDP API get min tank pressure limit 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_min_tank_pressure_limit(uint8_t thruster_id, float* get_min_tnk_prs)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_min_tank_pressure_limit(thruster_id,get_min_tnk_prs);
    return sts;
}

/*!
 *  @brief This VDP API get max tank pressure limit 
 */
hal_ret_sts ahw_vdp_linux_thruster_get_max_tank_pressure_limit(uint8_t thruster_id, float* get_max_tnk_prs)
{
    hal_ret_sts sts = HAL_MAX_ERR;
    sts = thruster_simu_get_max_tank_pressure_limit(thruster_id,get_max_tnk_prs);
    return sts;
}
