#ifdef LINUX_TEMP_PORT
#include "exo_ahw_al_linux_wrpr.h"
#include "exo_hal_common.h"
#include "exo_io_al_i2c_common.h"
#include <stdlib.h>
#include <string.h>
uint8_t sns_simu_data_write(uint8_t* buff, uint16_t length);
uint8_t sns_simu_data_read(uint8_t* buff, uint16_t length);

typedef struct
{ 
    uint16_t length;
    uint8_t rsp_flag;
    uint8_t io_intf_id;
    uint16_t  register_addr;
    uint16_t slave_addr;

}__attribute__((packed))sns_skt_intf_data_hdr;

uint8_t skt_intf_write_pca9673(void* intf_hdl, uint16_t reg_addr, uint8_t *data, uint16_t len)
{
	return 0;
}

uint8_t skt_intf_write(void* intf_hdl, uint16_t slv_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    uint8_t ret;
    sns_skt_intf_data_hdr skt_data_header;
    uint8_t hdr_len = sizeof(sns_skt_intf_data_hdr);
    uint16_t frame_len = hdr_len+len;
    ioal_i2c_hdle *hi2c = (ioal_i2c_hdle*)intf_hdl;
    skt_data_header.io_intf_id = hi2c->intf_gen_info.io_id;
    skt_data_header.slave_addr = slv_addr;
    skt_data_header.register_addr = reg_addr;
    skt_data_header.length = len;
    skt_data_header.rsp_flag = 0;
    uint8_t* ptr = malloc(frame_len);
    memcpy(ptr,&skt_data_header,hdr_len);
    if(len!=0)
    {
    memcpy(ptr+hdr_len,data,len);
    }
    ret=sns_simu_data_write(ptr,frame_len);
    free(ptr);
    return ret;
}

uint8_t skt_intf_read_pca9673(void* intf_hdl, uint16_t reg_addr, uint8_t *data, uint16_t len)
{
	return 0;
}

uint8_t skt_intf_read(void* intf_hdl, uint16_t slv_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    uint8_t ret;
    sns_skt_intf_data_hdr skt_data_header;
    sns_skt_intf_data_hdr skt_data_rcv_header;
    uint8_t hdr_len = sizeof(sns_skt_intf_data_hdr);
    uint16_t frame_len = hdr_len+len;
    ioal_i2c_hdle *hi2c = (ioal_i2c_hdle*)intf_hdl;
    skt_data_header.io_intf_id = hi2c->intf_gen_info.io_id;
    skt_data_header.slave_addr = slv_addr;
    skt_data_header.register_addr = reg_addr;
    skt_data_header.length = len;
    skt_data_header.rsp_flag = 1;
   // DEBUG_CPRINT(("skt intf read IO ID=%d,slaveaddr=0x%x,reg_addr=%d, lengh=%d \n",skt_data_header.io_intf_id,skt_data_header.slave_addr,skt_data_header.register_addr,skt_data_header.length));
    uint8_t* w_ptr = malloc(hdr_len);
    uint8_t* r_ptr = malloc(frame_len);
    memcpy(w_ptr,&skt_data_header,hdr_len);
    
    if(sns_simu_data_write(w_ptr,hdr_len)==0)
    {
        if(sns_simu_data_read(r_ptr,frame_len)==0)
        {
            memcpy(&skt_data_rcv_header,r_ptr,hdr_len);
            if(slv_addr==skt_data_rcv_header.slave_addr && hi2c->intf_gen_info.io_id==skt_data_rcv_header.io_intf_id)
            {
                memcpy(data,r_ptr+hdr_len,len);
                ret=0;
            }
            else
            {
                ret=1;
            }
        }
        else
        {
            ret=1;
        }
    }
    else
    {
        ret=1;
    }
    free(w_ptr);
    free(r_ptr);

    return ret;
}
#endif
