
#ifndef __AZBOXTVSDK_H_
#define __AZBOXTVSDK_H_

#include "AZBoxTVSDK_DEF.h"
#include "event.h"

typedef struct tvsdk_channel_key_st {
	unsigned char net_index;
	unsigned short net_id;
	unsigned short ts_id;
	unsigned long  freq;
	unsigned char polar;
	unsigned short service_id;
}stTVSDKChannelKey;

int TVSDK_Deinit(int err);
int TVSDK_Init(void);

HX_STATUS TVSDK_EventTask(struct event_st *event);


/**
 * @brief: Syncronize the SDK data with AZBox
 * @param: TVSDK_SYNC_ID_NONE, TVSDK_SYNC_ID_CHANNEL, TVSDK_SYNC_ID_EPG,TVSDK_SYNC_ID_RESERVED
 * @code
 * @endcode
 * @return 
 	HX_OK;
	HX_ERROR;
**/
#define TVSDK_SYNC_ID_NONE 0
#define TVSDK_SYNC_ID_CHANNEL 1
#define TVSDK_SYNC_ID_EPG 2
#define TVSDK_SYNC_ID_RESERVED 3
HX_STATUS TVSDK_Sync(int sync_id);

/**
 * @brief: Get the system time of AZBox
 * @param: void
 * @code
 * @endcode
 * @return 
	time_t : UTC
**/
time_t TVSDK_GetGMTOffset(void);

/*
param : 1 enum system_language
		2 language 
*/

/**
 * @brief: Get the language infomation which was set at AZBox
 * @param:
 	1 enum system_language(AUDIO_LANGUAGE, SUB_AUDIO_LANGUAGE, SUBTITLE_LANGUAGE)
	2 HX_UINT8 *language : language info
 * @code
 * @endcode
 * @return 
 	HX_OK, HX_ERROR
**/

enum system_language {
	AUDIO_LANGUAGE = 0,
	SUB_AUDIO_LANGUAGE,
	SUBTITLE_LANGUAGE,
};

HX_STATUS TVSDK_GetSystemLanguage(int language_type, HX_UINT8 *language);

/**
 * @brief: Get the stTVSDKChannelKey information which is needed at struct eit_info_st
 * @param:
 	struct eit_info_st *eit_info
 * @code
 * @endcode
 * @return 
 	stTVSDKChannelKey
**/
stTVSDKChannelKey TVSDK_MakeKeyByEPG(struct eit_info_st *eit_info);
/**
 * @brief: Get the stTVSDKChannelKey information which is needed at struct channel_st
 * @param:
 	struct channel_st *ch
 * @code
 * @endcode
 * @return 
 	stTVSDKChannelKey
**/

stTVSDKChannelKey TVSDK_MakeKeyByChannel(struct channel_st *ch);

/**
 * @brief: Get the detail EPG information from AZBox
 * @param
 	1. stTVSDKChannelKey : An information to identify a channel
	2. unsigned short event_id : An information to identify an event
 * @code
 * @endcode
 * @return 
 	struct eit_info_st : An EIT information which was getted
**/
struct eit_info_st TVSDK_GetDetailEPG(stTVSDKChannelKey *ChKey, unsigned short event_id);

/**
 * @brief: Get the EPG info from AZBox (The time information from start_time to duration)
 * @param
 	1. stTVSDKChannelKey : An information to identify a channel
	2. time_t start_time
	3. time_t duration  
	4. struct eit_info_st *epg_list : EIT lists which were getted  
 * @code
 * @endcode
 * @return 
 	count : The number of EIT information which were getted
**/

HX_UINT16 TVSDK_Geteit_info(stTVSDKChannelKey *ChKey, time_t start_time,
		time_t duration,struct eit_info_st *epg_list);

/**
 * @brief: Add EIT to AZBox (note: There is a limitation of size to add EIT at once,
 * so the return value is notifying the number of added EIT)
 * @param
 	1. struct eit_info_st: Pointers to be added at *eit_info
	2. HX_INT count : The total number of EIT to be added
 * @code
 * @endcode
 * @return 
 	count : The number of eit which was added
**/
HX_INT TVSDK_AddEPGInfo(struct eit_info_st *eit_info, HX_INT count);

/**
 * @brief: Initiate the reservation list
 * @param
 * @code
 * @endcode
 * @return 
 	HX_OK
 	HX_ERROR
**/
HX_STATUS TVSDK_InitReservedList(void);

/**
 * @brief: Read from the reservation list
 * @param
 * @code
 * @endcode
 * @return 
 	HX_OK
 	HX_ERROR
**/
HX_STATUS TVSDK_LoadReservedList(const char *fname);

/**
 * @brief: Save the reservation list as file
 * @param
 * @code
 * @endcode
 * @return 
 	HX_OK
 	HX_ERROR
**/
HX_STATUS TVSDK_SaveReservedList(const char *fname); 

/**
 * @brief: Add to the reservation list
 * @param
	struct reserved_info_st *info : An reservation information to be added
 * @code
 * @endcode
 * @return 
 	HX_OK
 	HX_ERROR
**/

HX_STATUS TVSDK_AddReservedInfo(struct reserved_info_st *info); 

/**
 * @brief: Delete from the reservation list
 * @param
	struct reserved_info_st *info : An reservation information to be deleted
 * @code
 * @endcode
 * @return 
 	HX_OK
 	HX_ERROR
**/

HX_STATUS TVSDK_DelReservedInfo(struct reserved_info_st *info);

/**
 * @brief: Get the whole reservation list
 * @param
 * @code
 * @endcode
 * @return 
 	struct reserved_list_st* : The pointer of the reservation lists data block
**/

struct reserved_list_st* TVSDK_GetReservedList(void); 


/**
 * @brief: A function to call a callback function when the Pid Filter was used
 * @param
 * @code
 * @endcode
 * @return 
**/

HX_STATUS TVSDK_SDCTRLTask(void);

/**
 * @brief: Get the tuner information to be used at the current time
 * @param
 * @code
 * @endcode
 * @return 
 	struct tuner_list_st * : The sturcture which has the number of tuners and what tuner is being used
**/
struct tuner_list_st * TVSDK_GetTunerList(void); 

/**
 * @brief: Try to lock
 * @param
 	1. HX_INT tuner_id : Tuner id(0,1) to be used
 	2. HX_UINT8 net_index : 
 	3. HX_UINT32 freq :
	4. HX_UINT8 polar : 
 * @code
 * @endcode
 * @return 
 	-1 : ERROR
 	0 : SUCCESS
**/
HX_INT TVSDK_LockTuner(HX_INT tuner_id, HX_UINT8 net_index, HX_UINT32 freq, HX_UINT8 polar);

/**
 * @brief: Check the locking status of the tuner which was indicated by tuner_id
 * @param
 	1. HX_INT tuner_id : Tuner id(0,1) to be used
 * @code
 * @endcode
 * @return 
 	-1 : ERROR
 	0 : FAIL
 	1 : SUCCESS
**/
HX_INT TVSDK_LockStatusTuner(HX_INT tuner_id);




/**
 * @brief: Start the pid filter task
 * @param
	1. HX_UINT16 pid : PID to be filtered
	2. HX_UINT8 *table_id_list : Table list to be filtered
	3. HX_INT32 table_list_num : The number of table to be filtered
	4. HX_UINT32 timeout : timeout (It is not stopped automatically, the checking routine is needed to stop)
	5 .HX_UINT16 table_id_ext :
	6. HX_INT32 filter_type : SECTION_PSI
	8. filterCallback callback : Register a callback function to get the stream which was filtered
 * @code
 * @endcode
 * @return 
 	filter index : It is used when the filter is closed.
**/

HX_INT32 TVSDK_PidFilterStart(HX_UINT16 pid,HX_UINT8 *table_id_list, 
		HX_INT32 table_list_num, HX_UINT32 timeout, HX_UINT16 table_id_ext, 
		HX_INT32 filter_type, filterCallback callback);

/**
 * @brief: Stop the pid filter
 * @param
	1. HX_INT32 filter_index : The filter index which is the return value of TVSDK_PidFilterStart
 * @code
 * @endcode
 * @return 
**/
HX_STATUS TVSDK_PidFilterStop(HX_INT32 filter_index);

/**
 * @brief: Get the filtering information
 * @param
	 HX_INT8 dtv : 0
	 HX_UINT16 pid : filtering pid
	 HX_UINT8 table_id : filtering table_id 
	 HX_UINT16 index : filter index
 * @code
 * @endcode
 * @return 
	stSectionMap * : A structure which has the filtering information
**/
stSectionMap * TVSDK_SectionMapFind(HX_INT8 dtv,HX_UINT16 pid, HX_UINT8 table_id);
stSectionMap * TVSDK_SectionMapFindByIndex(HX_INT8 dtv, HX_UINT16 index, HX_UINT8 table_id);
stSectionMap * TVSDK_SectionMapFindByPid(HX_INT8 dtv, HX_UINT16 pid);
/**
 * @brief 
 * @param
 * @code
 * @endcode
 * @return 
**/

void TVSDK_SectionMapFlush(stSectionMap *sec_map);



/**
 * @brief: Get the name of a tag from iso_639_tag
 * @param
	HX_INT8 *letter : 
	HX_INT32 from_tag : enum iso_639_tag 
	int to_tag : enum iso_639_tag 
 * @code
 * @endcode
 * @return 
	HX_INT8 *letter : letter 
**/

enum iso_639_tag {
	ISO_639_2B,
	ISO_639_2T,
	ISO_639_1,
	ENGLISH_FULL,
	FRENCH_FULL,
	CHARACTER_CODE,
};
HX_INT8 *TVSDK_GetLetter(HX_INT8 *letter, HX_INT32 from_tag, int to_tag);

/**
 * @brief: Initiate the EIT memory to be used
 * @param
 * @code
 * @endcode
 * @return 
	HX_INT32 memory_size : Memory size which was allocated (byte)
**/
HX_INT32 TVSDK_InitEITMemory(void); 

/**
 * @brief: Get the information of the EIT memory
 * @param
	struct memory_status_st *mem : A pointer which is to get the memory information
 * @code
 * @endcode
 * @return 
 	HX_OK
 	HX_ERROR
**/
HX_STATUS TVSDK_GetEITMemoryStatus(struct memory_status_st *mem);

/**
 * @brief: Setup the EIT memory to use at the SDK
 * @param
 	1. HX_INT32 mem_size : byte unit, The maximum size is 20MByte
	2. HX_INT mem_id : It must be 1
 * @code
 * @endcode
 * @return 
	HX_INT32 mem_size : 설정된 메모리
**/

HX_INT32 TVSDK_SetUserEITMemory(HX_INT32 mem_size/*byte*/, HX_INT mem_id /* 1 : fixed */);

/**
 * @brief: 
 * @param
	char *sned_buf :
	unsigned short send_size :
	char *received_buf :
 * @code
 * @endcode
 * @return 
 	received_size
**/

short TVSDK_SCMSG(char *sned_buf, unsigned short send_size, char *received_buf);

HX_STATUS TVSDK_GoToChannelDown(void);
HX_STATUS TVSDK_GoToChannelUp(void);
HX_STATUS TVSDK_GoToChannel(short major_chnum, short minor_chnum);

#endif
