#ifndef __CONSOLE_H_
#define __CONSOLE_H_
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/file.h>
#include <termios.h>
#include <time.h>
#include <sys/ioctl.h>
#include "types.h"

//#define condbg(fmt,args...) printf("[CONSOLE] " fmt, ## args)
#define condbg(fmt,args...)
#define condbg2(pipe,fmt,args...) fprintf(pipe,fmt,## args)

#define SIG_CONSOLE_ON		47
#define SIG_CONSOLE_OFF		48
#define MAX_CMD_LENGTH		5120
#define GAMMA_TABLE_SIZE	1024
#define TMPBUFSIZE			1024
#define	UART_BUF_SIZE		1024

enum{
	RS_Rx,
	RS_Tx,
	RS_Dx,
	RS_Sx,
};

enum{
	RSDBG_CONSOLE = 1,
	RSDBG_UMF,
	RSDBG_ALL,
};

enum _UPDATE_DETECT
{
	UPDATE_DETECT_OK = 0x0,
	UPDATE_DETECT_NO_DEV,
	UPDATE_DETECT_HAS_USB_DEV,
	UPDATE_DETECT_HAS_SDCARD_DEV,
};

typedef struct _CON_DEV{
	bool			bConnectViaUSB;
	pid_t			pid;
	FILE 			*in;
	FILE 			*out;
	FILE 			*dbg;
	volatile bool	bActive;
	volatile unsigned int	n;
	unsigned int	tmpbuf[TMPBUFSIZE];

}CON_DEV, *pCON_DEV;

typedef struct _CON_DBG{
	bool DbgOSDPos;
	bool DbgEnable;
	unsigned char DbgMsgtoUSB;
	unsigned char Txlen; 
	unsigned char Rxlen;
	unsigned char Tx[16];
	unsigned char Rx[16];
}CON_DBG;

typedef struct _CON_UART{
	unsigned char uartA_Thread;
	unsigned char uartB_Thread;
	unsigned char uartA_Thread_close;
	unsigned char uartB_Thread_close;
	unsigned char uartA_Stop;
	unsigned char uartB_Stop;
	unsigned char UART_UARTA_Listen_Status;
	unsigned char UART_UARTB_Listen_Status;
	unsigned char UART_UARTA_Wait_Status;
	unsigned char UART_UARTB_Wait_Status;
}CON_UART;

typedef void (*con_Header_Parse_t)(unsigned char* buff, unsigned int bufflen, unsigned int *commandlen);

void CONSOLE_INIT(void *arg);
extern void con_SetDbgMsgtoUSB(UINT8 value);
void CONSOLE_UART_START(UINT8 uartType);
INT32 CONSOLE_EXIT(void);

#endif

