//**************************************************************************** // //! Task function implementing the gettime functionality using an NTP server //! //! \param none //! //! This function //! 1. Initializes the required peripherals //! 2. Initializes network driver and connects to the default AP //! 3. Creates a UDP socket, gets the NTP server IP address using DNS //! 4. Periodically gets the NTP time and displays the time //! //! \return Returns \b TASK_RET_IN_PROG. // //**************************************************************************** int GetNTPTimeTask(void *pvParameters) { SlSecParams_t SecurityParams; long lRetVal = -1; struct SlTimeval_t timeVal; static char cTaskOwnState = GET_TIME_TASK_STATE_INIT; static tGetTime sGetTime; long OptionLen; int SetCommitInt; unsigned char OptionVal; switch(cTaskOwnState) { case GET_TIME_TASK_STATE_INIT: // // Start networking service in default STA_MODE state // lRetVal = NetStartDefaultState(); if(lRetVal < 0) { return TASK_RET_DONE; } // // Set the status as stated // sDisplayInfo.ucNetStat = NET_STAT_STARTED; // // Set the time zone // sGetTime.ucGmtDiffHr = GMT_DIFF_TIME_HRS; sGetTime.ucGmtDiffMins = GMT_DIFF_TIME_MINS; // // Set conneting status // sDisplayInfo.ucNetStat = NET_STAT_CONN; // // Get the Version Info // NetFwInfoGet(&sDisplayInfo.sNwpVersion); // // Make the formated string for firmware version // sprintf(sDisplayInfo.ucNwpVersion, "%d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d", sDisplayInfo.sNwpVersion.NwpVersion[0], sDisplayInfo.sNwpVersion.NwpVersion[1], sDisplayInfo.sNwpVersion.NwpVersion[2], sDisplayInfo.sNwpVersion.NwpVersion[3], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[0], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[1], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[2], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[3], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[0], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[1], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[2], sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[3]); // // Set next task state // cTaskOwnState = GET_TIME_TASK_STATE_CONN; // // Signal display refresh // DisplayRefresh(); break; case GET_TIME_TASK_STATE_CONN: // // Initialize AP security params // SecurityParams.Key = (signed char *)SECURITY_KEY; SecurityParams.KeyLen = strlen(SECURITY_KEY); SecurityParams.Type = SECURITY_TYPE; // // Connect to Access Point // lRetVal = NetWlanConnect(SSID_NAME,&SecurityParams); // // Failed to connect to AP, kill the task // if(lRetVal != 0) { return TASK_RET_DONE; } // // Check if this image is booted in test mode // sl_extLib_OtaGet(pvOtaApp,EXTLIB_OTA_GET_OPT_IS_PENDING_COMMIT, &OptionLen,&OptionVal); if(OptionVal == true) { SetCommitInt = OTA_ACTION_IMAGE_COMMITED; sl_extLib_OtaSet(pvOtaApp, EXTLIB_OTA_SET_OPT_IMAGE_COMMIT, sizeof(int), (_u8 *)&SetCommitInt); // // Set status // g_ulSysState = SYS_STATE_TEST_REBOOT; DisplayRefresh(); // // Reboot the MCU // cTaskOwnState = GET_TIME_TASK_STATE_DONE; break; } // // Set the status // sDisplayInfo.ucNetStat = NET_STAT_CONNED; DisplayRefresh(); // // Signal the network start // TaskSyncObjSignal(&g_NetStatSyncObj); // // Set next task state // cTaskOwnState = GET_TIME_TASK_STATE_OPEN_SOCK; break; case GET_TIME_TASK_STATE_OPEN_SOCK: // // Create UDP socket // sGetTime.iSocket = sl_Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // // Failed to create a socket, kill the task // while(sGetTime.iSocket < 0) { return TASK_RET_DONE; } // // Set socket time option // timeVal.tv_sec = 20; timeVal.tv_usec = 0; sl_SetSockOpt(sGetTime.iSocket,SOL_SOCKET,SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal)); // // Initialize Server Index // sDisplayInfo.ucServerIndex = 0; DisplayRefresh(); // // Set next task state // cTaskOwnState = GET_TIME_TASK_STATE_GET_IP; break; case GET_TIME_TASK_STATE_GET_IP: // // Get the NTP server host IP address using the DNS lookup // lRetVal = NetGetHostIP((char*)g_acSNTPserver[sDisplayInfo.ucServerIndex], &sGetTime.ulNtpServerIP); sDisplayInfo.ulServerIP = sGetTime.ulNtpServerIP; DisplayRefresh(); // // Set the net task state based on return value // if(lRetVal >= 0) { // // Go to get time // cTaskOwnState = GET_TIME_TASK_STATE_GET_TIME; } else { // // Go back and try a new NTP server // cTaskOwnState = GET_TIME_TASK_STATE_SET_SERVER; } break; case GET_TIME_TASK_STATE_GET_TIME: // // Get the NTP time and display the time // lRetVal = GetSNTPTime(&sGetTime); DisplayRefresh(); // // On failure go back and try a new NTP server // if(lRetVal != 0) { // // Chech and wait if we are disconnected // while( !NetIsConnectedToAP() ) { } cTaskOwnState = GET_TIME_TASK_STATE_SET_SERVER; } // // End the task if Reboot was requested // if(g_ulSysState == SYS_STATE_REBOOT) { cTaskOwnState = GET_TIME_TASK_STATE_DONE; } // // Set some sleep // TaskSleep(5*1000); break; case GET_TIME_TASK_STATE_SET_SERVER: strcpy((char *)sDisplayInfo.ucUTCTime,"NTP Server Error. Retrying..."); sDisplayInfo.ucLocalTime[0]='-'; sDisplayInfo.ucLocalTime[1]='\0'; sDisplayInfo.ucServerIndex = ((sDisplayInfo.ucServerIndex + 1)%NOF_NTP_SERVER); cTaskOwnState = GET_TIME_TASK_STATE_GET_IP; DisplayRefresh(); break; default: // // Disconnect and stop networking service // NetStop(); sDisplayInfo.ucNetStat = NET_STAT_OFF; DisplayRefresh(); // // Reboot nonw // RebootMCU(); // // Return task done // return TASK_RET_DONE; } // // Return task in progress // return TASK_RET_IN_PROG; }
BOOL CPlayer::UnpreparePlayback(BOOL fEos, BOOL fError) { if (fEos) { if (m_pOutHdr) { OutputBuffer(m_pOutHdr, m_cbOutBuf - m_cbOutBufLeft); m_pOutHdr = NULL; m_cbOutBufLeft = 0; } while (!m_Output.IsFlushed()) { if (m_fPlay && GetStatus() == MAP_STATUS_PLAY) { m_Output.Pause(FALSE); m_fPlay = FALSE; } Sleep(1); if (m_fSeek) return FALSE; if (m_fStop) break; UpdatePeek(); } } m_Output.Close(); m_Echo.Close(); m_Reverb.Close(); m_BassBoost.Close(); m_3DChorus.Close(); m_Decoder.Destroy(); if (!m_Options.fAlwaysOpenDevice || fError) m_Output.CloseAll(); if (m_fOpen == OPEN_URL) { m_Receiver.Disconnect(); m_StreamingStatus = MAP_STREAMING_DISCONNECTED; } m_pOutHdr = NULL; m_cbOutBufLeft = 0; m_nSeek = 0; m_fPlay = FALSE; m_fStop = FALSE; m_fSeek = FALSE; switch (m_fOpen) { case OPEN_PLUGIN: PlugInStop(); break; case OPEN_MPG_FILE: MpgStop(); break; case OPEN_OV_FILE: OvStop(); break; case OPEN_WAV_FILE: WavStop(); break; case OPEN_URL: NetStop(); break; } PostMessage(m_hwndMessage, MAP_MSG_PEEK, 0, 0); UpdateStatus(MAP_STATUS_STOP, fError); return TRUE; }