#ifndef LIB_OEM_IPMB_H
#define LIB_OEM_IPMB_H

#include "Types.h"
#include "Debug.h"
//#include "OSPort.h"
#include "PendTask.h"
#include "PEF.h"
#include "SensorAPI.h"
#include "featuredef.h"
#include "BMCInfo.h"
#include "IPMIConf.h"
#include "AMIDevice.h"
#include "ChassisCtrl.h"
#include "NVRAccess.h"
#include "Platform.h"
#include "GUID.h"
#include "SDR.h"
#include "SEL.h"
#include "FRU.h"
#include "Sensor.h"

#ifndef BOOL
#define BOOL unsigned char
#define BOOL_FALSE  0x00
#define BOOL_TRUE   0x01
#endif

#ifndef UCHAR
#define UCHAR unsigned char
#endif

#ifndef USHORT
#define USHORT unsigned char
#endif

#ifndef IN
#define IN
#endif

#ifndef OUT
#define OUT
#endif

#ifndef INOUT
#define INOUT
#endif

#ifndef PACKED
#define PACKED __attribute__((packed))
#endif

#ifndef ERROR_CODE
#define ERROR_SUCCESS   0x0
#define ERROR_FAILED    0xFF
#define ERROR_NOSUPPORT 0x1
#endif

#define BIT0_OEM 0x01
#define BIT1_OEM 0x02
#define BIT2_OEM 0x04
#define BIT3_OEM 0x08

#define NO_SUPPORT         0x0
#define CPU_SUPPORT        BIT0_OEM
#define SWITC1g_SUPPORT    BIT1_OEM
#define SWITC10g_SUPPORT   BIT2_OEM
#define PW_SUPPORT         BIT3_OEM

#define XX_MAX_BOARD_NUM (MAX_BOARD_NUM_PLUS - 1)

#define OEM_IPMB_I2C_BUSNUM     2
#define OEM_IPMB_DEVICE "/dev/i2c2"
#define OEM_IPMB_SECOND_DEVICE "/dev/i2c3"

#define OEM_IPMB_PWRCTL_FIFO  "/var/i2c_task_pwr_ctl_fifo"
#define OEM_IPMB_SENSOR_DIR             "/var/OEMIPMB/"
#define OEM_IPMB_SENSOR_FILENAME_SIZE   32
#define OEM_IPMB_SENSOR_FILE(file,type) (snprintf(file,OEM_IPMB_SENSOR_FILENAME_SIZE,"%s%d",OEM_IPMB_SENSOR_DIR,type))

#define OEM_IPMB_MASTER_ADDR    0x0B

#define OEM_IPMB_SENSOR_NAME_SIZE 255
#define OEM_IPMB_MSG_START  0xA6
#define OEM_IPMB_MSG_END    0x6A

#define OEM_IPMB_MSG_MAXSIZE 255
#define OEM_IPMB_DBG_BUFSIZE 512

#define BOARD_ALIVE 0x1



typedef enum en_BOARD_TYPE
{
	 en_BD_UNKNOWN = 0,
	 en_BD_CPU_BOARD = 1,
    en_BD_1GSW_BOARD,
    en_BD_10GSW_BOARD,
    en_BD_PWR_BOARD,
}EN_BOARD_TYPE;

typedef enum en_OEM_IPMB_CMDTYPE
{
    en_OEMIPMB_GET_ALIVE = 0x1,
    en_OEMIPMB_GET_CPU_SENSORDATA,
    en_OEMIPMB_GET_SW_SENSORDATA,
    en_OEMIPMB_GET_PW_SENSORDATA,
    en_OEMIPMB_SET_POWERON,
    en_OEMIPMB_SET_POWEROFF,
    en_OEMIPMB_SET_POWERESET,
    en_OEMIPMB_SET_DESTORY,
    MAX_OEM_IPMB_CMDNUM,
}EN_OEM_IPMB_CMDTYPE;


// 枚举 定义命令所支持的单板类型 计算mask
typedef enum en_I2C_SEND_CMD_SUPPORT
{
	 en_OEMIPMB_GET_ALIVE_SUPPORT          =   CPU_SUPPORT | SWITC1g_SUPPORT | SWITC10g_SUPPORT | PW_SUPPORT,
    en_OEMIPMB_GET_CPU_SENSORDATA_SUPPORT =   CPU_SUPPORT,
    en_OEMIPMB_GET_SW_SENSORDATA_SUPPORT  =   SWITC1g_SUPPORT | SWITC10g_SUPPORT ,
    en_OEMIPMB_GET_PW_SENSORDATA_SUPPORT  =   PW_SUPPORT,
    en_OEMIPMB_SET_POWERON_SUPPORT        =   CPU_SUPPORT | SWITC1g_SUPPORT | SWITC10g_SUPPORT ,
    en_OEMIPMB_SET_POWEROFF_SUPPORT       =   CPU_SUPPORT | SWITC1g_SUPPORT | SWITC10g_SUPPORT ,
    en_OEMIPMB_SET_POWERESET_SUPPORT      =   CPU_SUPPORT | SWITC1g_SUPPORT | SWITC10g_SUPPORT,
    en_OEMIPMB_SET_DESTORY_SUPPORT        =   CPU_SUPPORT ,
}EN_I2C_SEND_CMD_SUPPORT;

//BOARD SLOT ID
/*
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000111101
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000111011
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000111000
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000110111
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000110100
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000110010
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000110001
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000101111
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000101100
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000101010
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000101001
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000100110
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000100101
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000100011
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000100000
JA[2:0],RA[3:0],GA[4:0]#,GAP# = 0000000011111
*/


//GA equal to i2c addr
typedef enum en_BOARD_SLOT_GA_TYPE
{
    en_PW_BOARD_1 = 0x3d,
    en_10GSW_BOARD_1 =0x3b,
    en_10GSW_BOARD_2 = 0x38 ,
    en_STR_BOARD_1 =0x0,
    en_STR_BOARD_2 =0x0,
    en_STR_BOARD_3 =0x0,
    en_STR_BOARD_4 =0x0,
    en_STRMON_BOARD_1 =0x0,
    en_1GSW_BOARD_1 = 0x2c,
    en_CPU_BOARD_1 = 0x2a,
    en_CPU_BOARD_2 = 0x29,
    en_CPU_BOARD_3 =0x26,
    en_CPU_BOARD_4 = 0x25,
    en_EXT_BOARD_1 =0x0,
    en_EXT_BOARD_2 =0x0,
    en_PW_BOARD_2 = 0x1f,
    MAX_BOARD_NUM_PLUS=17,
}EN_BOARD_SLOT_GA_TYPE;
/*
#define MAX_CARD_NUM  (int)14
const UCHAR g_ucGA_def[] =
{
		0x3e, //s1, pwr
		0x3d, //s2, pwr
		0x1c, //s3
		0x3b, //s4
		0x1a, //s5
		0x19, //s6
		0x38, //s7
		0x37, //s8  10g switcher
		0x16, //s9  1g  switcher
		0x15, //s10
		0x34, //s11
		0x13, //s12
		0x32, //s13
		0x31  //s14
}; 
*/
 //结构体 将单板槽位GA和类型对应起来
typedef struct st_SLOTNUM_CORRESPOND_BOARDTYPE
{
	int num;
	EN_BOARD_SLOT_GA_TYPE enSlotGA;
	EN_BOARD_TYPE enBoardtype;
	EN_I2C_SEND_CMD_SUPPORT enBoardSupport;
}ST_SLOTNUM_CORRESPOND_BOARDTYPE;



/* public msg structs */
/*
typedef struct st_OEM_IPMB_MSG_HEAD
{
    UCHAR msg_start;
    UCHAR msg_source;
    UCHAR msg_target;
    UCHAR msg_cmd;
    UCHAR msg_errcode;
}PACKED ST_OEM_IPMB_MSG_HEAD;
*/

#define	MAX_IPMI_PKG_SIZE	23		///the maximum size command is GetStorageStatus(0xF2)
#define MAX_RES_DATA_SIZE 16
#define MAX_REQ_DATA_SIZE 1


///ipmi command list
typedef enum {
	GetBaseInfo				=	0xF0,	///to all module, scan and get module base status information
	GetCPUStatus			=	0xF1,	///to cpu module, get CPU module working status.
	GetStorageStatus	=	0xF2,	///to storage module, get storage module storing status.
	GetCANStatus			= 0xF3,	///to BUS module, get CAN port communicating status in BUS module.
	GetFlexRayStatus	= 0xF4,	///to BUS module, get FlexRay port communicating status in BUS module.
	SetRapidIOStatus	= 0xF5,	///to all module, set RapidIO port status.
	GetRapidIOStatus	=	0xF6,	///to switch module, get RapidIO port status.
	GetNetStatus			=	0xF7,	///to switch module, get internet port status in switch module.
	Poweron12V1				= 0xF8,	///to all module, turn on 12V1 power, except power module.
	Poweroff12V1			=	0xF9,	///to all module, turn off 12V1 power, except power module.
	GetTemperatue			=	0xFA,	///to all module, get temperature of module.
	GetVoltage12V1		=	0xFB,	///to all module, get 12V1 voltage of module.
	GetCurrent12V1		= 0xFC, ///to all module, get 12V1 current of module.
	GetVoltage28V			= 0xFD,	///to power module, turn on 12V2 power.
	GetCurrent28V			=	0xFE,	///to power module, turn off 12V2 power.
	GetVoltage12V2		=	0xFF	///to power module, get 12V2 voltage of module.
} COMMAND_T;


typedef enum{
	IPMI_SUCCESS	=	0x00,
	IPMI_FAIL			= 0xFF
} IPMI_STATUS_T;

///ipmi request struct
typedef struct{
	uint8_t						rsAddr;
	uint8_t						netFn;					///even
	uint8_t						checksum1;
	uint8_t						rqAddr;
	uint8_t						rqSeq;
	COMMAND_T					cmd;
	uint8_t 				   	data[MAX_REQ_DATA_SIZE];	
	uint8_t						checksum2;
}IPMI_REQUEST_T;

///ipmi response struct
typedef struct{
	uint8_t						rqAddr;
	uint8_t						netFn;						///odd
	uint8_t						checksum1;
	uint8_t						rsAddr;
	uint8_t						rqSeq;
	COMMAND_T					cmd;
	IPMI_STATUS_T			completion_code;
	uint8_t 					data[MAX_RES_DATA_SIZE];							///response data
	uint8_t						checksum2;
}IPMI_RESPONSE_T;


typedef struct st_OEM_IPMB_MSG_HEAD
{
    UCHAR rsAddr;
    UCHAR netFn;
    UCHAR checksum1;
    UCHAR rqAddr;
    UCHAR rqSeq ;
    UCHAR cmd;
    UCHAR checksum2;
}PACKED ST_OEM_IPMB_MSG_HEAD;

typedef struct st_OEM_IPMB_MSG_TAIL
{
    UCHAR msg_chk;
    UCHAR msg_end;
}PACKED ST_OEM_IPMB_MSG_TAIL;

#define OEM_IPMB_REQ_DATASIZE 16

typedef struct st_OEM_IPMB_REQ
{
    ST_OEM_IPMB_MSG_HEAD req_head;
    ST_OEM_IPMB_MSG_TAIL req_tail;
}PACKED ST_OEM_IPMB_REQ;
/* end public msg structs */


typedef enum en_OEM_IPMB_CMDAUOTOORMAN
{
    en_OEM_IPMB_CMD_AUOTO = 0x0,
    en_OEM_IPMB_CMD_MAN,
}EN_OEM_IPMB_CMDAUOTOORMAN;

typedef struct st_OEM_IPMB_CMDHANDLER
{
    EN_OEM_IPMB_CMDTYPE enCmdType;
    EN_OEM_IPMB_CMDAUOTOORMAN enAutoorman;
    EN_I2C_SEND_CMD_SUPPORT enBoardTypeMask;
    UCHAR msgsize;
    UCHAR (*RequestParg) (char *i2cdev, UCHAR slaveaddr, UCHAR cmdtype);
    UCHAR (*ResponseParg) (char *i2cdev, UCHAR ResponseMsgLen, ST_OEM_IPMB_REQ stReq);
}PACKED ST_OEM_IPMB_CMDHANDLER;

/* start define functions */
#define SIZE_ST(x) (sizeof(x))
#define SIZE_STAR(ar,st) (sizeof(ar)/sizeof(st))

#define OEM_IPMB_REQUEST_FUNCTION_START(func)                                   \
    UCHAR func (char *i2cdev, UCHAR slaveaddr, UCHAR cmdtype)                   \
    {                                                                           \
        UCHAR iRet = ERROR_SUCCESS;                                             \

#define OEM_IPMB_REQUEST_FUNCTION_END                                           \
        return iRet;                                                            \
    }                                                                           \

#define OEM_IPMB_REQUEST_FUNCTION_DEC(func)  UCHAR func (char *i2cdev, UCHAR slaveaddr, UCHAR cmdtype);



#define OEM_IPMB_RESPONSE_FUNCTION_START(func,stname)                           \
    UCHAR func(char *i2cdev, UCHAR ResponseMsgLen, ST_OEM_IPMB_REQ stReq)       \
    {                                                                           \
        stname stRes;                                                           \
        memset(&stRes, 0, sizeof(stRes));                                       \
        UCHAR iRet = ERROR_SUCCESS;                                             \
        if(ResponseMsgLen != sizeof(stRes))                                     \
        {                                                                                                  \
            return ERROR_FAILED;                                                \
        }                                                                                                  \
        stRes.msg_head.rsAddr = stReq.req_head.rqAddr;                          \
        stRes.msg_head.netFn = stReq.req_head.netFn;                             \
        stRes.msg_head.checksum1 = (0- (stRes.msg_head.rsAddr+stReq.req_head.netFn)) & 0xff;                             \
        stRes.msg_head.rqAddr = i2c_get_host_address(OEM_IPMB_DEVICE);      \
        stRes.msg_head.rqSeq = stReq.req_head.rqSeq;                        \
        stRes.msg_head.cmd = stReq.req_head.cmd;                            \
        stRes.msg_head.checksum2 = (0-(stRes.msg_head.rqSeq+stReq.req_head.cmd)) & 0xff;                            \
        /* start main logic */

#define OEM_IPMB_RESPONSE_FUNCTION_END                                                              \
        /* end main logic */                                                                        \
        stRes.msg_tail.msg_chk = 0;                                                                 \
        stRes.msg_tail.msg_end = OEM_IPMB_MSG_END;                                                  \
        return iRet;                                                                                \
    }                                                                                               \

#define OEM_IPMB_RESPONSE_FUNCTION_DEC(func) UCHAR func(char *i2cdev, UCHAR ResponseMsgLen, ST_OEM_IPMB_REQ stReq);
/* end define functions */


/* if need, add those */
/* response msg struct, judged by cmdtype */

/* response for alive */
typedef struct st_OEM_IPMB_MSG_ALIVE
{
    ST_OEM_IPMB_MSG_HEAD msg_head;
    UCHAR alive;
    UCHAR GA;
    ST_OEM_IPMB_MSG_TAIL msg_tail;
}PACKED ST_OEM_IPMB_MSG_ALIVE;
/* end */

//cpu board sensor
typedef struct en_OEMSERIAL_CPUBD_BMCI2C_SENSORDATA_FORMAT
{
   // UCHAR oem_i2c_start[2];    //2 BYTE
    UCHAR board_type;                 //1 BYTE
    UCHAR chassis_id;                 //1 BYTE
    UCHAR slot_id;                    //1 BYTE
    UCHAR Manufacture[10];            //10BYTE
    UCHAR serial_id;            			//1BYTE
    UCHAR proc_date[2];            		//2BYTE
    UCHAR hw_version[3];              //3 BYTE
    UCHAR bios_version[3];            //3 BYTE
    UCHAR sys_version[3];            //3 BYTE
    UCHAR cpu_occupy[2];              //2BYTE
    UCHAR ram[4];                     //4 byte                                  
    UCHAR flash[4];                   //4 byte
    UCHAR net1;                       //1 byte
    UCHAR net2;                       //1 byte
    UCHAR net3;                       //1 byte
    UCHAR net4;                       //1 byte
    UCHAR status;                     //1 byte
    
    INT16U oem_sensor_data[12];    //24 byte
   // UCHAR oem_i2c_end[2];      //2 byte
}PACKED EN_OEMSERIAL_CPUBD_BMCI2C_SENSORDATA_FORMAT;


typedef struct st_OEM_IPMB_CPU_MSG_SENSOR
{
    ST_OEM_IPMB_MSG_HEAD msg_head;
    EN_OEMSERIAL_CPUBD_BMCI2C_SENSORDATA_FORMAT msg_sensor;
    ST_OEM_IPMB_MSG_TAIL msg_tail;
}PACKED ST_OEM_IPMB_CPU_MSG_SENSOR;

//switch board sensor
typedef struct en_OEMSERIAL_SWBD_BMCI2C_SENSORDATA_FORMAT
{
   // UCHAR oem_i2c_start[2];    //2 BYTE
    UCHAR board_type;                 //1 BYTE
    UCHAR chassis_id;                 //1 BYTE
    UCHAR slot_id;                    //1 BYTE
    UCHAR Manufacture[10];            //10BYTE
    UCHAR serial_id;            			//1BYTE
    UCHAR proc_date[2];            		//2BYTE
    UCHAR hw_version[3];              //3 BYTE
    UCHAR bios_version[3];            //3 BYTE
    UCHAR sys_version[3];            //3 BYTE
    UCHAR cpu_occupy[2];              //2BYTE
    UCHAR ram[4];                     //4 byte                                  
    UCHAR flash[4];                   //4 byte
    UCHAR net[51];                       //1 byte
    UCHAR status;                     //1 byte
    
    INT16U oem_sensor_data[4];    //8 byte
  //  UCHAR oem_i2c_end[2];      //2 byte
}PACKED EN_OEMSERIAL_SWBD_BMCI2C_SENSORDATA_FORMAT;

typedef struct st_OEM_IPMB_SW_MSG_SENSOR
{
    ST_OEM_IPMB_MSG_HEAD msg_head;
    EN_OEMSERIAL_SWBD_BMCI2C_SENSORDATA_FORMAT msg_sensor;
    ST_OEM_IPMB_MSG_TAIL msg_tail;
}PACKED ST_OEM_IPMB_SW_MSG_SENSOR;

//power board sensor
typedef struct st_OEM_IPMB_PW_MSG_SENSOR
{
  //  ST_OEM_IPMB_MSG_HEAD msg_head;
    UCHAR board_type;                 //1 BYTE
    UCHAR chassis_id;                 //1 BYTE
    UCHAR slot_id;                    //1 BYTE
    UCHAR Manufacture[10];            //10BYTE
    UCHAR serial_id;            			//1BYTE
    UCHAR proc_date[2];            		//2BYTE
    UCHAR hw_version[3];              //3 BYTE
    UCHAR status;                     //1 byte
    INT16U oem_sensor_data[8];
   // ST_OEM_IPMB_MSG_TAIL msg_tail;
}PACKED ST_OEM_IPMB_PW_MSG_SENSOR;



/* respoonse for set power on or off */
typedef struct st_OEM_IPMB_MSG_POWERCTL
{
    ST_OEM_IPMB_MSG_HEAD msg_head;
     UCHAR result;
    ST_OEM_IPMB_MSG_TAIL msg_tail;
}PACKED ST_OEM_IPMB_MSG_POWERCTL;
/* end */


/* end response msg struct */

/* funtions */
extern UCHAR OEM_GET_SENSOR(SensorInfo_T *pSensor, UCHAR sensornum);
extern UCHAR OEM_GET_SENSOR_COUNT(void);

void *COLLECT_TASK(void *pArg);
void *OEMIPMB_TASK(void *pArg);
void *OEMIPMB_HANDLER(void *pArg);
void OEMIPMB_START(int BMCInst);
void *OEMIPMB_ETH_TASK(void *pArg);

extern void OEM_SLEEP(int seconds);
extern void OEM_MSLEEP(int msec);

extern UCHAR OEMIPMB_SET_ADDR(char *i2cdev, UCHAR u7addr);
extern UCHAR OEMIPMB_SET_HOSTADDR(void);

extern void PRINT_DATA(UCHAR *acData, UCHAR uclen);
extern UCHAR OEMIPMB_INIT(void);
extern void OEMDEBUG(UCHAR flag, char *fmt,...);
extern UCHAR OEM_IPMB_REQUEST_SEND(IN char *i2cdev, IN UCHAR slaveaddr, IN UCHAR cmdtype, INOUT UCHAR *stRes, IN UCHAR stResLen);
extern UCHAR OEM_IPMB_REQUEST_SENDCMD_TOSLAVE(char *i2cdev, UCHAR slaveaddr, UCHAR cmdtype);
extern void OEM_WRITE_FILE(UCHAR *acData, UCHAR uclen ,UCHAR slaveaddr);
extern UCHAR OEM_READ_FILE(char *name, char *buf ,int *length,int num);
/* add response function dec */
extern OEM_IPMB_RESPONSE_FUNCTION_DEC(ResGetAlive);
extern OEM_IPMB_RESPONSE_FUNCTION_DEC(ResGetCpuSensor);
extern OEM_IPMB_RESPONSE_FUNCTION_DEC(ResPowerOn);
extern OEM_IPMB_RESPONSE_FUNCTION_DEC(ResPowerOff);
extern OEM_IPMB_RESPONSE_FUNCTION_DEC(ResPowerReset);
extern OEM_IPMB_RESPONSE_FUNCTION_DEC(ResDestory);
/* add request function dec */
extern OEM_IPMB_REQUEST_FUNCTION_DEC(ReqGetAlive);
extern OEM_IPMB_REQUEST_FUNCTION_DEC(ReqGetCpuSensor);
extern OEM_IPMB_REQUEST_FUNCTION_DEC(ReqPowerOn);
extern OEM_IPMB_REQUEST_FUNCTION_DEC(ReqPowerOff);
extern OEM_IPMB_REQUEST_FUNCTION_DEC(ReqPowerReset);
extern OEM_IPMB_REQUEST_FUNCTION_DEC(ReqDestory);
/* global */
extern ST_OEM_IPMB_CMDHANDLER gst_OEM_IPMB_CMD[MAX_OEM_IPMB_CMDNUM];
extern int My_Bd_Solt;
extern UCHAR Board_Alive_status[MAX_BOARD_NUM_PLUS-1];


/* debug */
#define OEMDEBUG_TRUE   1
#define OEMDEBUG_FALSE  0
#define OEMDEBUG_FMT "[OEMIPMB] [%s %d]:"
#define OEM_IPMB_DEBUG(n, fmt, args...)  OEMDEBUG(n, fmt, ##args)
#define IPMBINFO(fmt, args...)   OEM_IPMB_DEBUG(OEMDEBUG_TRUE, OEMDEBUG_FMT fmt, __FUNCTION__, __LINE__, ##args)
#define IPMBDEBG(fmt, args...)   OEM_IPMB_DEBUG(OEMDEBUG_FALSE, OEMDEBUG_FMT fmt, __FUNCTION__, __LINE__, ##args)



/* those are added by cj for ft_cpu and bmc data*/
#define SERIAL_START_1 0xa6
#define SERIAL_START_2 0x6a
#define SERIAL_END_1 0x6a
#define SERIAL_END_2 0xa6
#define OEM_SERIAL_PWRCTL_FIFO   "/var/oem_pwr_ctl_fifo"


//logic command
typedef enum en_OEMSERIAL_CMD_TYPE
{
    en_OEMSERIAL_UNKNOW = 0x0, 
    en_OEMSERIAL_PWOFF,
    en_OEMSERIAL_RESET,
    en_OEMSERIAL_SENSOR,
    en_OEMSERIAL_PWON,
    en_OEMSERIAL_DESTORY,
}EN_OEMSERIAL_CMD_TYPE;

//raw command,just for command polling,because we only have one fifo to read
typedef enum raw_OEMSERIAL_CMD_TYPE
{
    raw_OEMSERIAL_SENSOR = 0x0, 
    raw_OEMSERIAL_PWCTL,
    raw_OEMSERIAL_MAX,
}RAW_OEMSERIAL_CMD_TYPE;

typedef struct st_UART_CMD
{
	 EN_OEMSERIAL_CMD_TYPE    cmdtype;
    UCHAR (*parg)(int fd, char *rx_buff);
}ST_UART_CMD;

//bmc to cpu command
typedef struct en_OEMSERIAL_BTC_CMD_FORMAT
{
    UCHAR oem_btc_serial_start[2];
    UCHAR oem_btc_serial_cmd;
    UCHAR oem_btc_serial_end[2];
    UCHAR oem_btc_serial_checksum;
}PACKED 	EN_OEMSERIAL_BTC_CMD_FORMAT;

//cpu to bmc command
typedef struct en_OEMSERIAL_CTB_DATA_FORMAT
{
    UCHAR oem_ctb_serial_start[2];
    UCHAR oem_ctb_serial_resdata;
    UCHAR oem_ctb_serial_end[2];
    UCHAR oem_ctb_serial_checksum;
}PACKED EN_OEMSERIAL_CTB_CMD_FORMAT;

//cpu to bmc sensor
typedef struct en_OEMSERIAL_CTB_SENSORDATA_FORMAT
{
    UCHAR oem_ctb_serial_start[2];    //2 BYTE
    UCHAR board_type;                 //1 BYTE
    UCHAR chassis_id;                 //1 BYTE
    UCHAR slot_id;                    //1 BYTE
    UCHAR Manufacture[10];            //10BYTE
    UCHAR serial_id;            			//1BYTE
    UCHAR proc_date[2];            		//2BYTE
    UCHAR hw_version[3];              //3 BYTE
    UCHAR bios_version[3];            //3 BYTE
    UCHAR sys_version[3];            //3 BYTE
    UCHAR cpu_occupy[2];              //2BYTE
    UCHAR ram[4];                     //4 byte                                  
    UCHAR flash[4];                   //4 byte
    UCHAR net1;                       //1 byte
    UCHAR net2;                       //1 byte
    UCHAR net3;                       //1 byte
    UCHAR net4;                       //1 byte
    UCHAR status;                     //1 byte
    UCHAR oem_ctb_serial_end[2];      //2 byte
    UCHAR oem_ctb_serial_checksum;    //1 byte
}PACKED EN_OEMSERIAL_CTB_SENSORDATA_FORMAT;

#define max_slot_num (int)14

typedef enum  CardType_e_{
	unknow_type = 0,
	pwr_type ,
	ft_cpu,
	switch_1g,
	switch_10g,
	e5_cpu
}CardType_e;

typedef struct {
	CardType_e eCardType;
	UCHAR ucCardSlot;
	UCHAR ucI2cAddr;
	UCHAR ucSensorData[128];
}PACKED SENSOR_ST;


UCHAR UartSoftPwrControl(int fd, char *rx_buff);
UCHAR UartGetSensor(int fd, char *rx_buff);
void PRINT_SENSOR_DATA(char *acData);

extern EN_OEMSERIAL_CTB_SENSORDATA_FORMAT cpu_global_serial_data;
extern INT16U cpu_global_sensor_data[12];

extern int  OEM_SLOT_GET(void);
extern void OEM_msg_collect(EN_OEMSERIAL_CPUBD_BMCI2C_SENSORDATA_FORMAT *cpu_sensor_data);
extern void PRINT_CPUBD_LOG(char *acData);

//global cpu data
EN_OEMSERIAL_CPUBD_BMCI2C_SENSORDATA_FORMAT cpu_sensor_data;
extern const ST_SLOTNUM_CORRESPOND_BOARDTYPE g_slotnum_correspond_boardtype[MAX_BOARD_NUM_PLUS-1];
extern UCHAR res_powerctl_from_web(char cmd);


/* those are added by cj for  bmc i2c data*/

//#define bmc_log

#endif
