// 注:仅支持单板模式 // 必须打开单板模式编译宏“SINGLE_BOARD_PLATFORM”才能编译通过!!! int main(int argc, char** argv) { HV_Trace(5, "Begin...\n"); HV_Trace(5, "%s %s\n", __TIME__, __DATE__); LinuxSystemInit(); CUserExitThread e; e.Start(NULL); // 使能看门狗。 // 注:使能之前必须喂狗,防止遇到“打开看门狗的同时发生喂狗超时而导致设备复位”这样的情况。 WdtHandshake(); CPLD_Write(CPLD_WTD_ENABLE, 1); WdtHandshake(); // 载入各模块参数 ModuleParams cModuleParams; if ( S_OK != LoadModuleParam(cModuleParams) ) { HV_Trace(5, "LoadModuleParam failed!\n"); HV_Exit(HEC_FAIL|HEC_RESET_DEV, "LoadModuleParam failed!"); } WdtHandshake(); // 判断是否恢复出厂设置 if (IsRecoverFactorySettings()) { RecoverFactorySettings(); HV_Exit(HEC_SUCC, "RecoverFactorySettings!"); } WdtHandshake(); // 初始化共享内存 if (S_OK != InitDspLinkMemBlocks(LPRAPP_SINGLE_BOARD_PLATFORM)) { HV_Trace(5, "Memory blocks initialize failed!\n"); HV_Exit(HEC_RESET_DEV|HEC_FAIL, "Memory blocks initialize failed!"); } WdtHandshake(); BOOL fIsIP1Correct = FALSE; // 判断是否测试相机口(生产测试时使用) if (!IsTestCamLanPort()) { // 正常工作,非测试,设置LAN1和LAN2口 // 确保LAN1和LAN2不在同一网段内,如果在同一网段内,LAN1将会被强行关闭 if (CheckIPAddr(cModuleParams.cTcpipCfgParam_1, cModuleParams.cTcpipCfgParam_2) == S_OK) { fIsIP1Correct = TRUE; SetTcpipAddr_1(&cModuleParams.cTcpipCfgParam_1); } // 设置设备IP SetTcpipAddr_2(&cModuleParams.cTcpipCfgParam_2); } else { // 进行测试相机口,只设置LAN1口为通信息端口 fIsIP1Correct = TRUE; SetTcpipAddr_1(&cModuleParams.cTcpipCfgParam_2); } if (S_OK == StartCamTransmit(0, "", cModuleParams.cTcpipCfgParam_1, cModuleParams.cTcpipCfgParam_2)) { HV_Trace(5, "StartCamTransmit...\n"); } WdtHandshake(); CSafeSaverDm6467Impl* pcSafeSaver = NULL; if (1 == cModuleParams.cResultSenderParam.fInitHdd) { SetAllLightOn(); g_cHddOpThread.SetHddOpType(HOT_FULL_INIT); g_cHddOpThread.Start(NULL); HV_Trace(5, "Hdd init...\n"); } if (cModuleParams.cResultSenderParam.fIsSafeSaver) { if (!cModuleParams.cResultSenderParam.fInitHdd) { SetAllLightOn(); g_cHddOpThread.SetHddOpType(HOT_INIT); g_cHddOpThread.Start(NULL); HV_Trace(5, "Hdd check...\n"); } WdtHandshake(); while (1 != g_nHddCheckStatus) { HV_Trace(5, "等待硬盘初始化完成...\n"); HV_Sleep(1000); WdtHandshake(); } pcSafeSaver = new CSafeSaverDm6467Impl(); SSafeSaveParam sParam; sParam.fCoverCtrl = true; sParam.fSaveRecord = true; pcSafeSaver->Init(&sParam); } SEND_RECORD_PARAM cParam; cParam.pcSafeSaver = pcSafeSaver; CCameraRecordLinkCtrl cCameraRecordLinkCtrl; cCameraRecordLinkCtrl.SetParam(&cParam); if ( S_OK != cCameraRecordLinkCtrl.Start(NULL) ) { HV_Trace(5, "CCameraRecordLinkCtrl Start failed!\n"); HV_Exit(HEC_FAIL, "CCameraRecordLinkCtrl Start failed!"); } WdtHandshake(); ICameraCmdProcess* pICameraCmdProcess = NULL; if ( S_OK != CCameraCmdProcess::CreateICameraCmdProcess(&pICameraCmdProcess) ) { HV_Trace(5, "CreateICameraCmdProcess failed!\n"); HV_Exit(HEC_FAIL, "CreateICameraCmdProcess failed!"); } CCameraCmdLinkCtrl cCameraCmdLinkCtrl(pICameraCmdProcess); if ( S_OK != cCameraCmdLinkCtrl.Start(NULL) ) { HV_Trace(5, "CCameraCmdLinkCtrl Start failed!\n"); HV_Exit(HEC_FAIL, "CCameraCmdLinkCtrl Start failed!"); } WdtHandshake(); CHvBoxHolder cHvBoxHolder; cHvBoxHolder.Init(&cModuleParams, pcSafeSaver); HV_Sleep(300); // 启动设备搜索响应线程 CIPSearchThread cDevSearch; if ( S_OK != cDevSearch.Create() ) { HV_Trace(5, "IP search thread create failed!\n"); HV_Exit(HEC_FAIL, "IP search thread create failed!"); } // 初始化HvTelnet服务 if ( -1 == TelnetInit() ) { HV_Trace(5, "TelnetInit is Failed!\n"); HV_Exit(HEC_FAIL, "TelnetInit is Failed!"); } WdtHandshake(); /* SetBuzzerOn(); HV_Sleep(200); SetBuzzerOff(); */ SetLan1LedOff(); SetLan2LedOff(); SetHddLedOff(); SetStatLedOff(); HV_Trace(5, "Running...\n"); // 定时对网关进行ARPPing CPingThread cPingThread; cPingThread.SetIPAddress(cModuleParams.cTcpipCfgParam_1.szIp, cModuleParams.cTcpipCfgParam_1.szNetmask, cModuleParams.cTcpipCfgParam_1.szGateway); cPingThread.Start(NULL); WdtHandshake(); DWORD32 dwIPTick = 0; DWORD32 dwBoxTick = 0; DWORD32 dwDotTick = 0; DWORD32 dwMemTick = GetSystemTick(); while (1) { if (!fIsIP1Correct && (GetSystemTick() - dwIPTick >= 5000)) { HV_Trace(5, "LAN1和LAN2的IP不能设置为同一网段,请更改!\n"); dwIPTick = GetSystemTick(); } HV_Sleep(500); if (GetSystemTick() - dwBoxTick >= 10000) { cHvBoxHolder.ShowStatus(); dwBoxTick = GetSystemTick(); } if (GetSystemTick() - dwMemTick >= 20000) { ShareMemPoolStatusShow(); dwMemTick = GetSystemTick(); } WdtHandshake(); WorkLedLight(); if (GetSystemTick() - dwDotTick >= 1000) { HV_Trace(5,"."); fflush(stdout); dwDotTick = GetSystemTick(); } } HV_Exit(HEC_FAIL, "MainExit"); }
// ************************************************************ // Main application entry point. // ************************************************************ int main(void) { static DWORD t = 0; static DWORD dwLastIP = 0; #if defined (EZ_CONFIG_STORE) static DWORD ButtonPushStart = 0; #endif UINT8 channelList[] = MY_DEFAULT_CHANNEL_LIST_PRESCAN; // WF_PRESCAN tWFScanResult bssDesc; #if 0 INT8 TxPower; // Needed to change MRF24WG transmit power. #endif // Initialize application specific hardware InitializeBoard(); // Initialize TCP/IP stack timer TickInit(); // Timer 3 interrupt for refreshing motor status inside here demo_TickInit(); #if defined(STACK_USE_MPFS2) // Initialize the MPFS File System // Generate a WifiGDemoMPFSImg.c file using the MPFS utility (refer to Convert WebPages to MPFS.bat) // that gets compiled into source code and programmed into the flash of the uP. MPFSInit(); #endif // Initialize Stack and application related NV variables into AppConfig. InitAppConfig(); // Initialize core stack layers (MAC, ARP, TCP, UDP) and // application modules (HTTP, SNMP, etc.) StackInit(); Exosite_Init("microchip","dv102412",IF_WIFI, 0); #if 0 // Below is used to change MRF24WG transmit power. // This has been verified to be functional (Jan 2013) if (AppConfig.networkType == WF_SOFT_AP) { WF_TxPowerGetMax(&TxPower); WF_TxPowerSetMax(TxPower); } #endif // Run Self Test if SW0 pressed on startup if(SW0_IO == 1) SelfTest(); #ifdef STACK_USE_TELNET_SERVER // Initialize Telnet and // Put Remote client in Remote Character Echo Mode TelnetInit(); putc(0xff, stdout); // IAC = Interpret as Command putc(0xfe, stdout); // Type of Operation = DONT putc(0x22, stdout); // Option = linemode putc(0xff, stdout); // IAC = Interpret as Command putc(0xfb, stdout); // Type of Operation = DO putc(0x01, stdout); // Option = echo #endif #if defined ( EZ_CONFIG_SCAN ) // Initialize WiFi Scan State Machine NV variables WFInitScan(); #endif // WF_PRESCAN: Pre-scan before starting up as SoftAP mode WF_CASetScanType(MY_DEFAULT_SCAN_TYPE); WF_CASetChannelList(channelList, sizeof(channelList)); if (WFStartScan() == WF_SUCCESS) { SCAN_SET_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; } // Needed to trigger g_scan_done WFRetrieveScanResult(0, &bssDesc); #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) // Initialize Zeroconf Link-Local state-machine, regardless of network type. ZeroconfLLInitialize(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) // Initialize DNS Host-Name from TCPIPConfig.h, regardless of network type. mDNSInitialize(MY_DEFAULT_HOST_NAME); mDNSServiceRegister( // (const char *) AppConfig.NetBIOSName, // base name of the service. Ensure uniformity with CheckHibernate(). (const char *) "DemoWebServer", // base name of the service. Ensure uniformity with CheckHibernate(). "_http._tcp.local", // type of the service 80, // TCP or UDP port, at which this service is available ((const BYTE *)"path=/index.htm"), // TXT info 1, // auto rename the service when if needed NULL, // no callback function NULL // no application context ); mDNSMulticastFilterRegister(); #endif #if defined(WF_CONSOLE) // Initialize the WiFi Console App WFConsoleInit(); #endif // Now that all items are initialized, begin the co-operative // multitasking loop. This infinite loop will continuously // execute all stack-related tasks, as well as your own // application's functions. Custom functions should be added // at the end of this loop. // Note that this is a "co-operative mult-tasking" mechanism // where every task performs its tasks (whether all in one shot // or part of it) and returns so that other tasks can do their // job. // If a task needs very long time to do its job, it must be broken // down into smaller pieces so that other tasks can have CPU time. #ifndef PERIOD #define PERIOD 3120 // set 3120 for get to timer interrupt every 20ms, 40MHz PBUS, div by 256 #endif OpenTimer3(T3_ON | T3_SOURCE_INT | T3_PS_1_256, PERIOD); while(1) { if (AppConfig.networkType == WF_SOFT_AP) { if (g_scan_done) { if (g_prescan_waiting) { SCANCXT.displayIdx = 0; while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) { WFDisplayScanMgr(); } #if defined(WF_CS_TRIS) WF_Connect(); #endif g_scan_done = 0; g_prescan_waiting = 0; } } } #if defined (EZ_CONFIG_STORE) // Hold SW0 for 4 seconds to reset to defaults. if (SW0_IO == 1u) { // Button is pressed button_state = 1; if (ButtonPushStart == 0) //Just pressed ButtonPushStart = TickGet(); else if(TickGet() - ButtonPushStart > 4*TICK_SECOND) RestoreWifiConfig(); } else { ButtonPushStart = 0; //Button release reset the clock } if (AppConfig.saveSecurityInfo) { // set true by WF_ProcessEvent after connecting to a new network // get the security info, and if required, push the PSK to EEPROM if ((AppConfig.SecurityMode == WF_SECURITY_WPA_WITH_PASS_PHRASE) || (AppConfig.SecurityMode == WF_SECURITY_WPA2_WITH_PASS_PHRASE) || (AppConfig.SecurityMode == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE)) { // only need to save when doing passphrase tWFCPElements profile; UINT8 connState; UINT8 connID; WF_CMGetConnectionState(&connState, &connID); WF_CPGetElements(connID, &profile); memcpy((char*)AppConfig.SecurityKey, (char*)profile.securityKey, 32); AppConfig.SecurityMode--; // the calc psk is exactly one below for each passphrase option AppConfig.SecurityKeyLength = 32; SaveAppConfig(&AppConfig); } AppConfig.saveSecurityInfo = FALSE; } #endif // EZ_CONFIG_STORE // Blink LED0 twice per sec when unconfigured, once per sec after config if((TickGet() - t >= TICK_SECOND/(4ul - (CFGCXT.isWifiDoneConfigure*3ul)))) { t = TickGet(); LED0_INV(); } // This task performs normal stack task including checking // for incoming packet, type of packet and calling // appropriate stack entity to process it. StackTask(); // This task invokes each of the core stack application tasks if (cloud_mode == 0) StackApplications(); // Enable WF_USE_POWER_SAVE_FUNCTIONS WiFiTask(); #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLProcess(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSProcess(); #endif Exosite_Demo(); // Process application specific tasks here. // Any custom modules or processing you need to do should // go here. #if defined(WF_CONSOLE) WFConsoleProcess(); WFConsoleProcessEpilogue(); #endif // If the local IP address has changed (ex: due to DHCP lease change) // write the new IP address to the LCD display, UART, and Announce // service if(dwLastIP != AppConfig.MyIPAddr.Val) { dwLastIP = AppConfig.MyIPAddr.Val; DisplayIPValue(AppConfig.MyIPAddr); #if defined(STACK_USE_ANNOUNCE) AnnounceIP(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSFillHostRecord(); #endif } } }