bool svrIncreaseTicks(int sig) { if (SIGALRM == sig) { nTimer_ticks ++; if (IsTimerRunning(static_chp.m_nCommBusy)) static_chp.m_nCommBusy --; if (IsTimerRunning(timer_noise_floor)) timer_noise_floor --; if (IsTimerRunning(timer_radio_query)) timer_radio_query --; if (IsTimerRunning(timer_chan_switch)) timer_chan_switch --; if (IsTimerRunning(timer_wifi_update)) timer_wifi_update --; return true; } else return false; }
/*------------------------------------------- "Cancel" button ---------------------------------------------*/ void OnCancel(HWND hDlg) { if(!IsTimerRunning()) PostMessage(g_hwndTimer, WM_CLOSE, 0, 0); DestroyWindow(hDlg); }
void svrTimer(int sig) { if (0 == pthread_mutex_trylock(&mutex_lock_timer)) { SerialCom* comm = static_chp.m_comm; int nQid = static_chp.m_nQid; bool dbg = static_debug_gws; if (!svrIncreaseTicks(sig)) { pthread_mutex_unlock(&mutex_lock_timer); return; } if (CheckPeriod(nTimer_ticks,2 * SECOND_TICKS)) { svrIamAlive(-1); } const int nNoiseScanPeriod = PERIOD_TOTAL * MSEC_TICKS; switch (svrIsScanning()) { case SCANNING_FIXED_INIT: //fixed channel scanning... svrQueryNoise(NULL,static_chp.m_pKpi,static_chp.m_nIdentifier); //reset noise floor PRE_SCAN_COMMAND(comm,"setrxatten 0 0"); PRE_SCAN_COMMAND(comm,"setrxatten 1 36"); EnableTimer(timer_chan_switch,2000 * MSEC_TICKS); //500 ms to ensure the pll done static_chp.m_uChanScan = SCANNING_FIXED_READ; break; case SCANNING_FIXED_READ: //channel scanning... if (IsTimerTimeout(timer_chan_switch)) svrNoiseFloorRead(dbg,static_chp.m_ifName, static_chp.m_pKpi, static_chp.m_nIdentifier); break; case SCANNING_FIXED_DONE: do { //channel scan done int region = 0; int ch = -1; RW_KPI_VAR(static_chp.m_nIdentifier,region,static_chp.m_pKpi->m_radio.m_nRegion); ch = static_chp.m_nCurrentChannel - MIN_CHANNEL(region); RW_KPI_VAR(static_chp.m_nIdentifier,static_chp.m_pKpi->m_noise_floor[ch].m_noise_cur, static_chp.m_pKpi->m_noise_floor[ch].m_noise_avg); CHANNEL_SCAN_ON_OFF(static_chp.m_uChanScan,SCANNING_DONE); APP_SCAN_COMMAND(comm,static_chp.m_nOriginChannel); } while (0); break; case SCANNING_ALL_INIT: //channel scanning... if (TimeDiff(nTimer_ticks, &nRecentChanSW, nNoiseScanPeriod)) { //handler for noise scan svrNoiseFloorSwitchChan(dbg,comm,&timer_chan_switch); } else if (IsTimerTimeout(timer_chan_switch)) { //switch done, notify that noise available svrNoiseFloorSetAvailable(dbg,&timer_chan_switch,&timer_noise_floor); static_chp.m_uChanScan = SCANNING_ALL_READ; } break; case SCANNING_ALL_READ: //channel scanning... if (IsTimerDisabled(timer_chan_switch) && IsTimerRunning(timer_noise_floor)) { svrNoiseFloorRead(dbg,static_chp.m_ifName, static_chp.m_pKpi, static_chp.m_nIdentifier); } else if (IsTimerTimeout(timer_noise_floor)) { svrNoiseFloorDone(dbg,comm,&timer_noise_floor,&static_chp.m_uChanScan); } break; default: //routine... if (CheckPeriod(nTimer_ticks,3 * SECOND_TICKS)) { //radio polling..... svrGwsRequest(dbg,comm,&timer_radio_query); } else if (IsTimerRunning(timer_radio_query)) { //within radio query timeout svrGwsPolling(dbg,comm,&timer_radio_query); } else if (IsTimerTimeout(timer_radio_query)) { //radio query done or timeout svrGwsParse(dbg,&timer_radio_query); } if (IsTimerDisabled(timer_noise_floor)) { // ensure noise is not reading currently svrQueryWifi(dbg,static_chp.m_ifName, static_chp.m_pKpi, static_chp.m_nIdentifier,nTimer_ticks); } } if (TASK_COMMAND == latest_msg.m_nType) { if (0 == svrCmdHandler(comm,&latest_msg,&static_chp)) { SVR_DEBUG(dbg,VT100_RESET VT100_STYLE_HOT "\nDone : idel = %d\n",nSvrTimerBusy); pthread_mutex_unlock(&mutex_lock_timer); svrExitCommandHandler(); return; } } if (COM_TEST) { //latest message has already done if (msgrcv(nQid, &latest_msg, MSG_SZ, latest_msg.m_nType, IPC_NOWAIT) > 0) { //no task currently, try to detect new task } else { //no new message, we can handle the channel scan things } } //else, consider there is still a task not handled yet pthread_mutex_unlock(&mutex_lock_timer); } return; }