/*
 * csp_if.c
 *
 *  Created on: 29-Aug-2022
 *
 */

#include "csp_if.h"
#include "csp_comms.h"
#include "csp_if_sltcp.h"
#include "csp_if_sludp.h"
#include <errno.h>

int csp_intf_init(io_intf_type intf_type, void* intf_instance_ptr, csp_iface_t** iface)
{
    int ret=0;
    if(intf_instance_ptr==NULL)
    {
        ret =-1;
    }
    else
    {
        switch(intf_type)
        {
#ifdef CSP_FREERTOS
            case UART:
            {
//                int error = csp_usart_open_and_add_kiss_interface(intf_instance_ptr,CSP_IF_KISS_DEFAULT_NAME,iface);
//                if (error != CSP_ERR_NONE)
//                {
//                    DEBUG_CPRINT(("failed to add KISS interface - %d\n", error));
//                    ret =-1;
//                }
//                else
//                {
//                    ret=0;
//                }

                break;
            }
            case CAN:
            {
                *iface =csp_can_init("can_intf",intf_instance_ptr);
                if(iface!=NULL)
                {
                    ret=0;
                }
                else
                {
                    ret=-1;
                    break;
                }

                break;
            }
#endif

            case ETHERNET:
            {
                uint8_t opt = 0;
                memcpy(&opt, intf_instance_ptr,sizeof(uint8_t));

                switch(opt)
                {
#ifdef SDR_HWIL
                    case S1_SBAND_HWIL_GS1:
                    {
                        DEBUG_CPRINT(("S1 init \n"));
                        csp_sltcp_init_gs1("eno1", NULL, iface);
                    }
                    break;
#endif
                    case S2_DEFAULT_SBAND_GS2:
                    {
#ifndef GSOBC_TCP_EN
                        DEBUG_CPRINT(("Ethernet currently handled using UDP\n"));
                        csp_sludp_init("eno1", NULL, iface);
#else

                        DEBUG_CPRINT(("Ethernet currently handled using TCP %d\n", opt));
                        DEBUG_CPRINT(("S2 init \n"));
                        csp_sltcp_init_gs2("eno1", NULL, iface);
#endif
                    }
                    break;
#ifdef LINUX_TEMP_PORT
                    case S3_UHF_HWIL_GS3:
                    {
                        DEBUG_CPRINT(("S3 init \n"));
                        csp_sltcp_init_uhf("eno1", NULL, iface);
                    }
                    break;
#endif
                }
            }
            break;

            default:
            {
                DEBUG_CPRINT(("check interface type %d \n", intf_type));
                ret=-1;
            }
            break;

        }
    }
    return (ret);
}


