#ifndef __CONSOLE_CUSTOM_H_
#define __CONSOLE_CUSTOM_H_

#include "types.h"
#include "al_basictypes.h"
#include "customize.h"

#define CMD_ECHO			0x0
#define CMD_MMIOWRITE		0x1
#define CMD_MMIOREAD		0x2
#define CMD_MULTIPLE_READ	0x10
#define CMD_LEAVECONSOLE	0x0100
#define CMD_WHITEBALANCE	0x0101
#define CMD_GAMMACORRECTION	0x0102
#define CMD_SAVEGAMMA		0x0103
#define CMD_CHANGESOURCE	0x0104
#define CMD_MULTIWRITE		0x0105
#define CMD_READMMIOMASK	0x0200
#define CMD_WRITEMMIOMASK	0x0201
#define CMD_GPIOREAD		0x0202
#define CMD_GPIOWRITE		0x0203
#define CMD_I2CREAD			0x0204
#define CMD_I2CWRITE		0x0205
#define CMD_REBOOT			0x0300
#define CMD_WRITEFLASH		0x0301
#define CMD_READFLASH		0x0302
#define CMD_PQ_TOOL_SYNC	0x0401

#define CMD_SIS_SYNC			0xFA
#define CMD_PQ_Leave			0x00
#define CMD_PQ_Echo				0x01
#define CMD_PQ_Reboot			0x02
#define CMD_PQ_Read_Flash		0x10
#define CMD_PQ_Write_Flash		0x11
#define CMD_PQ_MMIO_Read		0x12
#define CMD_PQ_MMIO_Write		0x13
#define CMD_PQ_Set_GammaTab		0x14
#define CMD_PQ_Cmd_Set			0x15
#define CMD_PQ_Read_Table_Info	0x16
#define CMD_SIS_HDCP_Read		0x20
#define CMD_SIS_HDCP_Write		0x21
#define CMD_Audio_SetEffectExt  0x30
#define CMD_Audio_GetEffectExt  0x31
#define CMD_Audio_SetNRExt     	0x32
#define CMD_Audio_GetNRExt	    0x33
#define CMD_PQ_Read_DynXastInfo	    0x40
#define CMD_PQ_Write_DynXastInfo	0x41
#define CMD_System_Call     0x60

#define CMD_SFU_Set_TvConnenction		0xA9
#define CMD_SFU_Set_SymbolRate			0xC9
#define CMD_SFU_Set_SpecifiedChannel	0xE9
#define CMD_SFU_Get_MosaicStatus		0x89
#define	CMD_DBX_Audio	0x64
#define AutoTest_CMD_VoltageCheck	0x81
#define AutoTest_CMD_SourceCheck		0x82
#define	AutoTest_CMD_KeyCheck			0x83
#define	AutoTest_CMD_Reset					0x84
#define	AutoTest_CMD_CIInfoCheck		0x85
#define	AutoTest_CMD_UpdateKey			0x86
#define	AutoTest_CMD_NetCheck			0x87
#define	AutoTest_CMD_WifiCheck			0x88
#define	AutoTest_CMD_LNBCheck			0x89
#define	AutoTest_CMD_USBCheck			0x8a
#define	AutoTest_CMD_UpdateSW			0x8b
#define	AutoTest_CMD_IRCheck				0x8c

#define	AutoTest_CMD_NotSupport				0xfe

#define TOOL_DEFAULT_TYPE1_KEY			0xABCD5678
#define RESERVED_C__KEY_TOOL_TYPE_SIT	488
#define C_KEY_VALUE_BYTE				512
#define V_KEY_VALUE_BYTE				32
#define R_KEY_VALUE_BYTE				40
#define CRC_KEY_VALUE_BYTE				4

#define CMD_AUTOTEST_SYNC_AA			0xAA
#define CMD_AUTOTEST_SYNC_AB			0xAB

#define CMD_HK_SYNC_80			0x80


#define BUFFER_MAX 1500

typedef struct
{
	UINT32 CMD_ID;
	void (*FactoryFun)(pCON_DEV pcon, UINT8 *pValue);
}Factory_CMD;

enum {
	QSD_fail,
	QSD_success,
	QSD_done,
};

enum{
	RS232_SERIAL_MODE,
	RS232_USB_MODE
};

enum {
	MEDIA_JPEG,
	MEDIA_MPEG,
};


enum{
	Index_Console_Leave,
	Index_Console_Echo,
	Index_Console_Reboot,
	Index_Console_Read_Flash,
	Index_Console_Write_Flash,
	Index_Console_MMIO_Read,
	Index_Console_MMIO_Write,
	Index_Console_Set_GammaTab,
	Index_Max,
};

enum{
		DBXTV_LoadPresetsFile,
		DBXTV_GetParamCoeff,
		DBXTV_SetParamCoeff,
};

typedef enum{
	AutoTest_CMD_SetVoltageCheck,
	AutoTest_CMD_SetSourceCheck,
	AutoTest_CMD_SetKeyCheck,
	AutoTest_CMD_SetReset,
	AutoTest_CMD_SetCIInfoCheck,
	AutoTest_CMD_SetHDCPKeyUpdate,
	AutoTest_CMD_SetCIPKeyUpdate,
	AutoTest_CMD_SetMACAddr,
	AutoTest_CMD_SetNetCheck,
	AutoTest_CMD_SetWifiCheck,
	AutoTest_CMD_SetLNBCheck,
	AutoTest_CMD_SetUSBCheck,
	AutoTest_CMD_SetUpdateSW,
	AutoTest_CMD_SetIRCheck,
	AutoTest_CMD_SetNotSupport,
}AutoTest_SET_CMD;

typedef enum{
	AutoTest_ack_none=0,
	AutoTest_ack_source=0x01,
	AutoTest_ack_key=0x02,
	AutoTest_ack_reset=0x04,
	AutoTest_ack_usb_check=0x08,
	AutoTest_ack_ir=0x10,
	AutoTest_ack_update_sw = 0x20,
	AutoTest_ack_update_hdcp = 0x40,
	AutoTest_ack_not_support = 0x80,
}AutoTest_ACK_TYPE;

typedef enum{
	AutoTest_usb_none = 0,
	AutoTest_usb_success = 1,
	AutoTest_usb_no_device = 2,
	AutoTest_usb_no_file = 3,
	AutoTest_usb_init_fail = 4,
	AutoTest_usb_error = 5,
}AutoTest_USB_RESULT;

typedef bool (*Console_sfu_Cbk_pf)(pCON_DEV pcon, UINT8 *msg);

typedef struct Console_sfu_Cbk_t_
{
	Console_sfu_Cbk_pf		pfCallBack;
} Console_sfu_Cbk_t;

typedef	void (* con_CallBack_t)(al_uint8 eventID, al_uint8 data1, al_uint8 data2);

void al_console_sfu_init(Console_sfu_Cbk_t *pConsole_Sfu_Cfg);
bool con_suf_parser(pCON_DEV pcon, UINT8 *msg);
void con_echo_sfu(UINT32 count, UINT8 *pdata);
void con_echo_sfu_Save2Usb(UINT32 count, UINT8 *pdata);

typedef int (*Console_ats_Cbk_pf)(pCON_DEV pcon, UINT8 *msg);

typedef struct Console_ats_Cbk_t_
{
	Console_ats_Cbk_pf		pfCallBack;
} Console_ats_Cbk_t;

typedef bool (*Console_autotest_Cbk_pf)(pCON_DEV pcon, UINT8 *msg);

typedef struct Console_autoest_Cbk_t_
{
	Console_autotest_Cbk_pf		pfCallBack;
} Console_autotest_Cbk_t;

void al_console_ats_init(Console_ats_Cbk_t *pConsole_ats_Cfg);
int con_ats_parser(pCON_DEV pcon, UINT8 *msg);

void con_print(/*pCON_DEV pcon,*/char* str ,int size);
void con_echo(pCON_DEV pcon, unsigned int parm);
pCON_DEV get_pCON_DEV(void);
bool con_parser(pCON_DEV pcon, UINT32 *msg);
bool con_SIS_parser(pCON_DEV pcon, UINT8 *msg);
void con_echo1(pCON_DEV pcon, UINT8 data1, UINT8 data2);
void con_ShowHexValuetoOSD(UINT8 bTx, UINT8 len, UINT8 *pStr);
void con_SaveDbgMsgtoUSB(UINT8 bTx, short len, UINT8 *pStr);
extern bool con_src_parser(pCON_DEV pcon,unsigned char *msg);
extern bool con_new_src_parser(pCON_DEV pcon,unsigned char *msg);
void con_RegCallBackFunc(con_CallBack_t pCallBackFunc);
void con_mmiotest_status(UINT8 status);

void con_echo_respond_message(UINT16 count, UINT8 *pdata);
void con_autotest_HeaderParse(unsigned char* buff, unsigned int bufflen, unsigned int *commandlen);
void al_console_autotest_init(Console_autotest_Cbk_t *pConsole_autotest_Cfg);
bool con_autotest_parser(pCON_DEV pcon, UINT8 *msg);
#if defined(SUPPORT_FACTORY_AUTO_TEST_MODE4)
UINT32 AutoTest_TransTVSource(UINT8 cmdSrc, UINT32 srcID);
void AutoTest_SendCommand(AutoTest_SET_CMD cmd, UINT8 *pValue);
unsigned int AutoTest_crc_check(unsigned char *fp_CRC,int count);
bool con_AutoTestCMD_parser(pCON_DEV pcon,unsigned char *msg);
int AutoTest_GetUsbPathWithPort(int port, char *usbPath);
AutoTest_USB_RESULT AutoTest_USB_Test(UINT8 devNum);
void AutoTest_SetSendAck(AutoTest_ACK_TYPE SendAck);
AutoTest_ACK_TYPE AutoTest_GetSendAck(void);
void AutoTest_SetReceiveIRTest(UINT8 ReceiveIRTest);
UINT8 AutoTest_GetReceiveIRTest(void);
#endif

#ifdef CONFIG_SUPPORT_DBX
void al_DBXTV_echo(UINT8 count, UINT8 * pdata);
al_uint8 al_DBXTV_loadPresetFile();
al_uint8 al_DBXTV_SetParamCoeff(al_uint32 ParamCoeff, al_uint32 ParamCoeffOffset, al_uint32 ParamCoeffValue);
al_uint8 al_DBXTV_GetParamCoeff(al_uint32 ParamCoeff, al_uint32 ParamCoeffOffset);
#endif

#endif


