process.c
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:2k
- /*************************************************/
- #include "My_head.h"
- /*************************************************/
- static BYTE idata Cur_State=IDEL_STATUS;
- void SetCurState(BYTE stat) // (状态切换)
- {
- if(stat>=MY_MAX_STATUS)return;
- Cur_State = stat;
- }
- BYTE GetCurState(void)
- {
- return(Cur_State);
- }
- static QUEUE_MESSAGE idata queue_message;
- /*-----------------------------------------------------------*/
- void Message_Clear(void)
- {
- queue_message.head=queue_message.tail=0;
- }
- /*-----------------------------------------------------------*/
- /* */
- /*-----------------------------------------------------------*/
- bit PostMessage(BYTE Code, BYTE Dat)
- {
- BYTE head=queue_message.head;
- if(++head>=MESSAGE_SIZE)head = 0;
- if(head == queue_message.tail)return FALSE;
- queue_message.array[queue_message.head].Code = Code;
- queue_message.array[queue_message.head].Dat = Dat;
- queue_message.head = head;
- return TRUE;
- }
- /*-----------------------------------------------------------*/
- /* */
- /*-----------------------------------------------------------*/
- bit GetMessage(MESSAGE *Message)
- {
- if(queue_message.tail == queue_message.head)return FALSE;
- Message->Code = queue_message.array[queue_message.tail].Code;
- Message->Dat = queue_message.array[queue_message.tail].Dat;
- if(++queue_message.tail>=MESSAGE_SIZE)queue_message.tail= 0;
- return TRUE;
- }
- /*--------------------------------------------------------*/
- //#include "even_tab.c"
- extern BYTE code *code Status_Even_Tab[];
- extern BYTE (code *code EventFunc_Tab[])(BYTE);
- /*--------------------------------------------------------*/
- void Do_Process(MESSAGE Message)
- {
- BYTE (code *func)(BYTE);
- BYTE i,*Even_Tab = Status_Even_Tab[Cur_State];
- for(i=0;Even_Tab[i]<OTHER_UNKNOW_ENVENT;i+=2)
- if(Message.Code == Even_Tab[i])
- {
- i=Even_Tab[i+1];
- //if(i > sizeof(EventFunc_Tab)/sizeof(func))break;
- func = EventFunc_Tab[i];
- if(func)i=func(Message.Dat);
- //if(i)send_for_test(i);
- break; //must!!
- }
- }
- /*
- void Init_Message(void)
- {
- SetCurState(IDEL_STATUS);
- Message_Clear();
- }
- */