
#ifndef _POPUP_SCHEDULER_H_
#define _POPUP_SCHEDULER_H_
#include "Popup_List.h"
#include "IO_Manager.h"
#define   POPUP_DISP_TIME_NORMAL            10
#define   POPUP_DISP_TIME_MIN               4

/******************************************************************************
报警状态定义
******************************************************************************/
#define   POPUP_STATUS_OFF                  0x00
#define   POPUP_STATUS_NEW                  0x01
#define   POPUP_STATUS_FIRST                0x02
#define   POPUP_STATUS_LOOP                 0x03
#define   POPUP_STATUS_MASKED               0x04
#define   POPUP_STATUS_DELETE               0x05
#define   POPUP_STATUS_CLEAR                0x06

/******************************************************************************
查询模式定义
******************************************************************************/
#define   POPUP_POLLING_FORWARD             0x00
#define   POPUP_POLLING_REVERSE             0x01

/******************************************************************************
最大优先级数
******************************************************************************/
#if       (POPUP_PRIORITY_NUMBER_FATAL >= POPUP_PRIORITY_NUMBER_HINT)
#if     (POPUP_PRIORITY_NUMBER_FATAL >= POPUP_PRIORITY_NUMBER_WARNING)
#define   POPUP_PRIORITY_NUMBER_MAX     POPUP_PRIORITY_NUMBER_FATAL
#else
#define   POPUP_PRIORITY_NUMBER_MAX     POPUP_PRIORITY_NUMBER_WARNING
#endif
#else
#if     (POPUP_PRIORITY_NUMBER_HINT >= POPUP_PRIORITY_NUMBER_WARNING)
#define   POPUP_PRIORITY_NUMBER_MAX     POPUP_PRIORITY_NUMBER_HINT
#else
#define   POPUP_PRIORITY_NUMBER_MAX     POPUP_PRIORITY_NUMBER_WARNING
#endif
#endif

/******************************************************************************
链表名称
******************************************************************************/
#define   POPUP_LINK_LIST_NEW_FATAL         0
#define   POPUP_LINK_LIST_FATAL             1

#define   POPUP_LINK_LIST_NEW_HINT          2
#define   POPUP_LINK_LIST_HINT              3

#define   POPUP_LINK_LIST_NEW_WARNING       4
#define   POPUP_LINK_LIST_WARNING           5
#define   POPUP_LINK_LIST_MASKED_WARNING    6

#define   POPUP_LINK_LIST_NONE              255

/******************************************************************************
弹出信息状态结构
******************************************************************************/
typedef struct
{
  uint8_t   Status;     //弹出信息状态
  uint8_t   LinkList;   //弹出信息所在链表
  uint8_t   Prev;       //前一个被使能的报警
  uint8_t   Next;       //后一个被使能的报警
  uint8_t   SndReqCode; //声音请求码
} PopupStatusStruct;

/******************************************************************************
弹出信息优先级管理结构
******************************************************************************/
typedef struct
{
  uint8_t   First;      //当前优先级下的第一个弹出信息
  uint8_t   Last;       //当前优先级下的最后一个弹出信息
} PopupPrioCtrlStruct;

/******************************************************************************
弹出信息优先级管理结构
******************************************************************************/
typedef struct
{
  uint8_t               Cnt;
  uint8_t               Cur;
  uint8_t               PrioNum;
  PopupPrioCtrlStruct   Prio[POPUP_PRIORITY_NUMBER_MAX];
} PopupLinkListCtrlStruct;

/******************************************************************************
弹出信息调度结构
******************************************************************************/
typedef struct
{
  uint8_t   Timer;
  uint8_t   Current;
  uint8_t   Message;
  uint8_t   NewSnd;
  uint8_t   WarningExist;
  uint8_t   MaskReq;
  uint8_t   LastMasked;
  uint8_t   MaskedPolling;
} PopupSchedulingStruct;

/******************************************************************************
函数声明
******************************************************************************/
void Popup_Scheduler_Init(void);
void Popup_Scheduling_Service(void);        //100ms
void Popup_Request(uint8_t PopupID);
void Popup_Delete(uint8_t PopupID);
void Popup_Clear(uint8_t PopupID);
void Popup_Mask_Request(void);
void Popup_Hint_Mask_Request(uint8_t PopupID);
uint8_t Popup_Get_Status(uint8_t PopupID);
uint8_t Popup_Get_Current_Type(void);
uint8_t Popup_Get_Current_Message(void);
uint8_t Popup_Get_Current_Sound(void);
uint8_t Popup_Get_Current_Sound_Req_Code(void);
uint8_t Popup_Get_Warning_Status(void);
uint8_t Popup_Get_First_Masked_Warning(void);
uint8_t Popup_Get_Last_Masked_Warning(void);
uint8_t Popup_Get_Masked_Warning_Msg(void);
void Popup_Masked_Warning_Polling_Reset(uint8_t Mode);
void Popup_Masked_Warning_Polling(uint8_t Mode);
void Popup_Link_List_Init(uint8_t LinkListID, uint8_t PrioNum);
void Popup_Link_List_Insert(uint8_t LinkListID, uint8_t PopupID);
void Popup_Link_List_Remove(uint8_t PopupID);

#endif
