123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include "ticket.h"
- static T_UINT32 ticket;
- //清空投票
- void ticketReset(void){
- int i;
- ticket=0;
- //for(i=0;i<TICKET_PT_MAX;i++) ticketDeVote(i);
- ticketDeVote(TICKET_PT_DOMAIN);
- ticketDeVote(TICKET_PT_NETWORK);
- ticketDeVote(TICKET_PT_QUECOM);
- ticketDeVote(TICKET_PT_HOOK);
- ticketDeVote(TICKET_PT_TUP);
- }
- //投票
- void ticketVote(TICKET_ENUM vote){
- #if defined ENABLE_TICKET
- ticket &= ~(1<<vote);
- #endif
- }
- //撤票
- void ticketDeVote(TICKET_ENUM vote){
- #if defined ENABLE_TICKET
- ticket |= 1<<vote;
- #endif
- }
- //投票结果
- static T_BOOL isTicketReady(void){
- if(0==ticket) return TRUE;
- else return FALSE;
- }
- LSAPI_OSI_Thread_t *timeThread=NULL;
- LSAPI_OSI_Timer_t *ptimer_t = NULL;
- static T_BOOL timerSleepStatus=FALSE;
- void Timeroutcallback(void *param){
- wlog_info("Timeroutcallback enter");
- LSAPI_OSI_TimerStop(ptimer_t);
- threadPostEvent(timeThread,USER_EVENT_TIMEOUT);
- }
- /*
- 串口、网络等唤醒深度睡眠接口
- */
- void WakeupNow(char *name){
- #if defined ENABLE_TICKET
- if(ptimer_t==NULL || timeThread==NULL || timerSleepStatus==FALSE) return;
- wlog_info("WakeupNow by %s",name);
- LSAPI_OSI_TimerStop(ptimer_t);
- threadPostEvent(timeThread,USER_EVENT_TIMEOUT);
- #endif
- }
- static T_INT32 getMintWaitCnt(void);
- static void addWaitCnt(T_INT32 value);
- PT_THREAD (ptTicketTask(pt_timer_t *ptPool, struct pt *pt)){
- static pt_timer_t ptTimer;
- static T_UINT8 sleepDlyTime;
- T_INT32 value;
- T_UINT32 sleeptime;
- static int64_t lastSleepTime;
- char info[30];
- PT_BEGIN(pt);
- while(1){
- if(FALSE==isTicketReady()) sleepDlyTime=0;
- else{
- if(++sleepDlyTime>=3){//延时3秒
- sleepDlyTime=0;
- //开启下次唤醒的定时器,也就是发心跳的时刻即可
- value=getMintWaitCnt();
- if(value>0){
- sleeptime=value*1000;
- snprintf(info, sizeof(info),"Waitevent:%d\r\n",value);
- outterInfo(info,strlen(info));
- timeThread=LSAPI_OSI_ThreadCurrent();
- if(NULL == ptimer_t) ptimer_t = LSAPI_OSI_TimerCreate(timeThread, Timeroutcallback, NULL);
- if(NULL != ptimer_t){
- if(FALSE==LSAPI_OSI_TimerStart(ptimer_t, sleeptime)){
- wlog_warn("sleep timer start failed");
- goto TICKET_END;
- }
- }else{
- wlog_warn("sleep timer create failed");
- goto TICKET_END;
- }
- lastSleepTime=LSAPI_OSI_UpTime();
- LSAPI_OSI_Event_t event = {};
- timerSleepStatus=TRUE;
- while(1){
- LSAPI_OSI_EventWait(timeThread, &event);
- if(event.id==USER_EVENT_TIMEOUT) break;
- }
- value=(LSAPI_OSI_UpTime()-lastSleepTime)/1000;
- ticketReset();
- timerSleepStatus=FALSE;
- addWaitCnt(value);
- }else wlog_warn("value %d, no sleep",value);
- }
- }
- TICKET_END:
- PTTimerStart(ptPool, &ptTimer,100);//need set to 1 seconds
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
- static T_INT32 getMintWaitCnt(void){
- //获取所有计数器,并得出最小值
- #define VALUE_SIZE 3
- T_INT32 value[VALUE_SIZE],temp,i;
-
- temp=0xfffffff;
- for(i=0;i<VALUE_SIZE;i++) value[i]=0xfffffff;
- i=0;
- value[i++]=getPocMinCnt();
- #if defined ENABLE_BUBIAO_GPS
- value[i++]=getBubiaoMinCnt();
- value[i++]=getGpsMinCnt();
- #endif
- for(i=0;i<VALUE_SIZE;i++){
- temp=(value[i]>temp)?temp:value[i];
- }
- return temp;
- }
- static void addWaitCnt(T_INT32 value){
- //更新所有计数器值
- pocCntUpdate(value);
- #if defined ENABLE_BUBIAO_GPS
- bubiaoCntUpdate(value);
- gpsCntUpdate(value);
- #endif
- }
- /*定时显示一下票箱状态*/
- void ticketStatusShow(void){
- static unsigned char cnt=0;
- char info[100]="TICKET:";
- char tbuf[10];
- unsigned char i;
- if(cnt==0){
- if(ticket==0) wlog_info("TICKET:Idle");
- else{
- for(i=TICKET_PT_DOMAIN;i<TICKET_PT_MAX;i++){
- if(ticket & (1<<i)){
- snprintf(tbuf, sizeof(tbuf), "%d ",i);
- strcat(info, tbuf);
- }
- }
- wlog_info(info);
- }
- }
- if(++cnt>=10) cnt=0;//10秒打印一次
- }
|