/***************************************************************************** * Function Name: main() ****************************************************************************** * Summary: * Central function which controls the application flow. * * Parameters: * None. * * Return: * None. * * Note: * *****************************************************************************/ int main() { // Init. InitializeSystem(); // Wait for BLE component to finish initialization. while (CyBle_GetState() == CYBLE_STATE_INITIALIZING) { CyBle_ProcessEvents(); } ////////////////////////////////////////////////////////////////////////// // Main Loop ////////////////////////////////////////////////////////////////////////// for(;;) { // Process all the events in the stack. CyBle_ProcessEvents(); #if LOWPOWERMODE_ENABLED // Put the BLESS in deepest sleep possible. CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); #endif ////////////////////////////////////////////////////////////////////// // Device connected ////////////////////////////////////////////////////////////////////// if (_BLE_deviceConnected) { // Update the CapSense CCCD. _BLE_UpdateCCCD(); // Update the Control values. _BLE_UpdateControl(); // If asked by client, send the status flags by notification or // indication. if (_BLE_sendStatus) _BLE_sendStatusFlags(); #if LOWPOWERMODE_ENABLED // Handle the Capsense low power mode. LowPowerMode_Capsense(); #endif // If asked by client, send the content of the vector containing // the CapSense data. if (_BLE_sendData) { SendData(); // Allow DeepSleep between connection intervals. LowPowerMode_System_DeepSleepAllowed = TRUE; } // If asked by client, acquire CapSense data and store it in // the vector. else if (_BLE_acquireData || TEST_USB) { AcquireData(); // Keep system in Active mode during scanning. LowPowerMode_System_DeepSleepAllowed = FALSE; } // If the 'acquireData' request is not present, but the vector // isn't empty, then no more data can be acquired. else if (!_BLE_acquireData && !vectorIsEmpty()) { ReadyToSendData(); // Allow DeepSleep between connection intervals. LowPowerMode_System_DeepSleepAllowed = TRUE; } // If the 'sendData' and 'acquireData' requests are not present, // but the vector is empty, then data has been all sent and // it's ready to acquire new data. else if (!_BLE_sendData && !_BLE_acquireData && vectorIsEmpty()) { ReadyToAcquireData(); // Allow DeepSleep between connection intervals. LowPowerMode_System_DeepSleepAllowed = TRUE; } } else // Allow DeepSleep between advertisement intervals. LowPowerMode_System_DeepSleepAllowed = TRUE; ////////////////////////////////////////////////////////////////////// // Advertisement ////////////////////////////////////////////////////////////////////// // Start advertisement if the flag is set in the BLE event handler. if (_BLE_restartAdvertisement) { // Reset the flag. _BLE_restartAdvertisement = FALSE; // Start advertisement. CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); } ////////////////////////////////////////////////////////////////////// // Reset ////////////////////////////////////////////////////////////////////// // If the client is disconnected, reset everything as the program // would be is first started. if (_BLE_resetNeeded) { // Reset the flag. _BLE_resetNeeded = FALSE; // Reset everything that needs to. ResetSystem(); } ////////////////////////////////////////////////////////////////////// // Low Power Mode (Sleep) ////////////////////////////////////////////////////////////////////// #if LOWPOWERMODE_ENABLED // Put the system in the deepest sleep possible. LowPowerMode_Sleep(); // Reset flag. LowPowerMode_System_DeepSleepAllowed = FALSE; #endif } }
void ParticleEditor::LoadEditor() { m_sphereSprite = m_provider->GetVideo()->CreateSprite(utf8::c(utf8::c(m_provider->GetFileIOHub()->GetProgramDirectory()).str() + "/" + BSPHERE_BMP).wc_str()); ResetSystem(); SetupMenu(); }
VOID Monitor( IN ULONG CallerSource, IN PFW_EXCEPTION_FRAME Frame ) /*++ Routine Description: This is the main dispatch routine to the various commands that can be typed at the monitor prompt. Arguments: For Alpha/Jensen: CallerSource 0 if exception (or bugcheck, on Alpha/Jensen) 3 if called from boot menu Frame the machine / exception state. Return Value: None. --*/ { CHAR Buffer[2][128]; ULONG ParityDiag[3]; PULONG ParDiag; ULONG BufferIndex; PCHAR Argv[10]; PCHAR Tmp; CHAR String[128]; BOOLEAN CommandValid; GETSTRING_ACTION Action; #ifdef ALPHA_FW_KDHOOKS // // If this is a breakpoint exception which is recognized, process it. // Otherwise, continue into the Monitor. // if ((Frame->ExceptionType == FW_EXC_BPT) && (FwKdProcessBreakpoint(Frame) == TRUE)) { // // This does not return. // FwRfe(Frame); } #endif FwPrint(MON_MONITOR_MSG); FwPrint(MON_PRESS_H_MSG); // // Initialize command line to null. // Argv[0] = (PCHAR)NULL; if (CallerSource !=3) { // // Display Cause of exception. // if ((Frame->ExceptionType >= FW_EXC_FIRST) && (Frame->ExceptionType <= FW_EXC_LAST) ) { FwPrint(ExceptionNameTable[(Frame->ExceptionType & 0xf)]);} else { FwPrint("** !! Unknown Exception"); } FwPrint(MON_EXCEPTION_MSG); FwPrint("PC = 0x%016Lx, VA = 0x%016Lx\r\n", Frame->ExceptionFaultingInstructionAddress, Frame->ExceptionVa); // // If an exception happened before the ARC console was opened, // a call to JzGetString will not work since JzGetString calls // ArcRead. So, close the console (nothing bad will happen if these // are not already opened) and reopen it. // FwClose(ARC_CONSOLE_INPUT); FwClose(ARC_CONSOLE_OUTPUT); #ifdef ALPHA_FW_KDHOOKS // // If we are built with the kernel debugger stubs, and have come // here because of an exception, we want to enter the debugger. // Frame->ExceptionType = FW_EXC_BPT; DbgBreakPoint(); #endif FwOpenConsole(); } // // Initialize Static variables. // DefaultAddress = KSEG0_BASE; DataSize = MON_QUAD; BufferIndex = 0; // // loop forever getting commands and dispatching them // while(TRUE) { // // print prompt // FwPrint(">"); // // read a command. // do { Action = JzGetString(Buffer[BufferIndex], 128, NULL, FwRow+1, FwColumn+1, FALSE); } while ((Action != GetStringSuccess) && (Action != GetStringEscape)); FwPrint(FW_CRLF_MSG); // // convert string to lower case. // for (Tmp=Buffer[BufferIndex];*Tmp;*Tmp++) { *Tmp=tolower(*Tmp); } // // if escape was pressed, simulate a quit command. // if (Action == GetStringEscape) { Argc = 1; Argv[0] = "q"; // // separate command line into tokens delimited by spaces // load up Argv with pointers to arguments and put count in Argc // } else if (*Buffer[BufferIndex] != '\0') { Tmp = Buffer[BufferIndex]; Argc = 0; // // Skip leading blanks // while ( *Tmp == ' ') { Tmp++; } while ( *Tmp ) { Argv[Argc++] = Tmp; while ( *Tmp ) { if (*Tmp == ' ') { *Tmp++ = '\0'; while ( *Tmp == ' ') { Tmp++; } break; } Tmp++; } } // // Increment index so that next command is read into the other // buffer. And we preserve the previous one. // BufferIndex = (BufferIndex+1) & 0x1; } else { // // repeat the last command already in Argv Argc // } // // if first argument is not null, then dispatch to routines. // if (Argv[0] != (PCHAR) NULL) { CurrentArg = 1; CurrentCommand = GetCommand(Argv[0]); switch(CurrentCommand) { case DumpByte: case DumpWord: case DumpLongword: case DumpQuad: DataSizeShift = (CurrentCommand - Dump -1); DataSize = 1 << DataSizeShift; DataSizeMask = DataSize-1; case Dump: CommandValid = DumpCommand(Argv,Frame); break; case EnterByte: case EnterWord: case EnterLongword: case EnterQuad: DataSizeShift = (CurrentCommand - Enter -1); DataSize = 1 << DataSizeShift; DataSizeMask = DataSize-1; case Enter: CommandValid = EnterCommand(Argv,Frame); break; case Help: case Help2: HelpCommand(); break; case DepositByte: case DepositWord: case DepositLongword: case DepositQuad: DataSizeShift = (CurrentCommand - Deposit -1); DataSize = 1 << DataSizeShift; DataSizeMask = DataSize-1; case Deposit: CommandValid = DepositCommand(Argv,Frame); break; case ExamineByte: case ExamineWord: case ExamineLongword: case ExamineQuad: DataSizeShift = (CurrentCommand - Examine -1); DataSize = 1 << DataSizeShift; DataSizeMask = DataSize-1; case Examine: CommandValid = ExamineCommand(Argv,Frame); break; case IOReadByte: case IOReadWord: case IOReadLongword: DataSizeShift = (CurrentCommand - IORead -1); DataSize = 1 << DataSizeShift; DataSizeMask = DataSize-1; case IORead: CommandValid = IOReadCommand(Argv, Frame); break; #if 0 case IOWriteByte: case IOWriteWord: case IOWriteLongword: DataSizeShift = (CurrentCommand - IOWrite -1); DataSize = 1 << DataSizeShift; DataSizeMask = DataSize-1; case IOWrite: CommandValid = IOWriteCommand(Argv, Frame); break; #endif case Register: case IntegerRegisterDump: case FloatingRegisterDump: CommandValid = RegisterCommand(Argv, Frame); break; case Zero: CommandValid = ZeroCommand(Argv,Frame); break; case Fill: CommandValid = FillCommand(Argv,Frame); break; #if 0 case AvailableDevices: CommandValid = FwDumpLookupTable(); break; #endif case Quit: if (CallerSource == 3) { return; } else { // // We came because of an exception. // The only way to exit is reseting the system. // FwPrint(MON_NO_RETURN_MSG); FwPrint(MON_RESET_MACHINE_MSG); do { Action = JzGetString(Buffer[BufferIndex], 128, NULL, FwRow+1, FwColumn+1, FALSE); } while ((Action != GetStringSuccess) && (Action != GetStringEscape)); FwPrint(FW_CRLF_MSG); Buffer[BufferIndex][0]=tolower(Buffer[BufferIndex][0]); if (strcmp(Buffer[BufferIndex],"y") == 0) { ResetSystem(); } break; } case invalidcommand: FwPrint(MON_UNRECOGNIZED_COMMAND_MSG); // // Clear the argument so that re-do last command // doesn't repeat the erroneous command. // CommandValid = FALSE; break; } if (!CommandValid) { Argv[0] = (PCHAR) NULL; } } } }
int cmdRestore(CLISESSION *pSession, int argc, char **argv, void *pHandler) { WORKSESSION *pWorker; char szCommand[128]; int pid, child, status; if (pSession->nType == CLITYPE_TELNET) { OUTTEXT(pSession, "Restore does not support telnet mode.\r\n"); return CLIERR_OK; } if (!Confirm(pSession, MSG_DEFAULT)) return CLIERR_OK; unlink(SAVE_FILENAME); pid = Spawn(child, 1, "/tmp"); if (pid > 0) { if (pSession->nType == CLITYPE_TELNET) { pWorker = (WORKSESSION *)pSession->pSession; dup2(pWorker->sSocket, STDIN_FILENO); dup2(pWorker->sSocket, STDOUT_FILENO); dup2(pWorker->sSocket, STDERR_FILENO); } execl("/usr/bin/rz", "rz", "-b", "-Z", "-y", NULL); exit(0); } while(waitpid(child, &status, WNOHANG) == 0) usleep(1000000); if (!IsExists(SAVE_FILENAME)) { printf("\r\n**** Configration file not found: %s ****\r\n", SAVE_FILENAME); return IF4ERR_INVALID_FILENAME; } usleep(1000000); printf("\r\n"); printf("Remove old configuration.\r\n"); VARAPI_EnableModify(FALSE); system("rm -rf /app/conf"); system("rm -rf /app/member"); system("rm -rf /app/data"); system("rm -rf /app/event"); system("rm -rf /app/log"); system("rm -f /app/sw/apn"); system("rm -f /app/sw/phonelist"); printf("Make new configuration.\r\n"); chdir("/app"); sprintf(szCommand, "tar zxvf %s > /tmp/result", SAVE_FILENAME); system(szCommand); system("/bin/chown -R root:root /app/conf"); system("/bin/chown -R root:root /app/sw"); system("/bin/chown -R root:root /app/data"); system("/bin/chown -R root:root /app/log"); unlink(SAVE_FILENAME); chdir("/app/sw"); printf("Sync ...\r\n"); system("sync"); usleep(1000000); system("sync"); usleep(1000000); system("sync"); printf("Reboot.\r\n"); ResetSystem(); return CLIERR_OK; }
void Metage::TaskMetage(void) { long l; IED_DATABASE::YP_DATA *Sample = &IedDb.Sample1[0]; MetagePtr = &Sample[m_cPos-1].UQuality.Q[metagType]; int MetageBit = MetagePtr==&Sample[m_cPos-1].UQuality.SQuality.lMPot?S_WEIGHT_POT: //置当前状态:正在称坩埚或称样 MetagePtr==&Sample[m_cPos-1].UQuality.SQuality.lM0?S_WEIGHT_SAMPLE: MetagePtr==&Sample[m_cPos-1].UQuality.SQuality.lM1?S_TEST_WATER: MetagePtr==&Sample[m_cPos-1].UQuality.SQuality.lMPotSample2?S_WEIGHT_COVER: MetagePtr==&Sample[m_cPos-1].UQuality.SQuality.lM2?S_TEST_VOL: MetagePtr==&Sample[m_cPos-1].UQuality.SQuality.lM3?S_TEST_ASH:S_TEST_ASH+1; gcKey=GetKey(); switch(*m_cSchedule) { case M_INIT: //初始化 ResetSystem(); m_cMDelay=0; m_cPos=1; *m_cSchedule=M_POS; break; case M_POS: //移动炉子到称样位 SuspendTask(TASK_MANUAL); //停止手动进位 if((m_cPos==IedDb.MtrState.CurSamplePos) && (0==IedDb.MtrState.bRun)&& (LowTempStove.m_StovePos==LowVertStoveBar::POS_TOP)&& ((IedDb.DownloadWorkParam.m_szSystemType==G5000)|| ((LeftHighTempStove.m_StovePos==LowVertStoveBar::POS_BOT)&& (RightHighTempStove.m_StovePos==LowVertStoveBar::POS_BOT))))//判位置 { //if(IedDb.Sample1[m_cPos-1].cSta>S_NULL) //有样 if(Sample[m_cPos-1].cSta&(1<<MetageBit)) { m_cMDelay = 0; m_cDelayCnt = 0; MTBalan.ZeroWeight(); //清0 *m_cSchedule=M_TARE; //TODO:清除目标位置重量数据 } else { //无样 *m_cSchedule=M_NEXTPOS; } } break; case M_TARE: l=MTBalan.GetBalanceAvr(); if((l>-BALANCE_ZERO && l<BALANCE_ZERO)||m_cDelayCnt>MAX_WEIGHTING_CNT) //除皮成功或者除皮次数超过规定次数 { LowTempStove.MoveStoveBar(LowVertStoveBar::POS_BOT); //移动炉子到称样位置 *m_cSchedule=M_METAGE; m_cDelayCnt = 0; m_cMDelay=0; } else if(m_cMDelay++>TARE_DELAY) //不稳定,再次清零 { BeepBalErr(); //除皮不稳定,提醒一次 MTBalan.ZeroWeight(); //清0 m_cMDelay=0; m_cDelayCnt ++; } break; case M_METAGE: //称量 if((LowTempStove.m_StovePos==LOW_POS_BOT)&& ((IedDb.DownloadWorkParam.m_szSystemType==G5000)|| ((LeftHighTempStove.m_StovePos==LowVertStoveBar::POS_BOT)&& (RightHighTempStove.m_StovePos==LowVertStoveBar::POS_BOT))))//判位置 { //称的不是样重,或者快速称样,或者确认,进入保存重量环节 if(((metagType==T_SAMPLE)&&(gcKey==KEY_ENT))||(T_QUICK==metagSpeed)||(metagType!=T_SAMPLE)) { *m_cSchedule=M_SAVE; if(KEY_ENT==gcKey) { m_cMDelay = M_DELAY; BeepOK(); } } m_cMDelay ++; //TODO:增加称样时到达重量范围内的提示音 } break; case M_SAVE: if(m_cMDelay++>M_DELAY) //延时M_DELAY后存数 { m_cMDelay=M_DELAY-2; m_cDelayCnt++; if((MTBalan.BalanceMaxErr(METAGE_MAXERR))||m_cDelayCnt>MAX_WEIGHTING_CNT) //增加称样超时 { *MetagePtr= MTBalan.GetBalanceAvr(); //存坩埚质量 if(m_cDelayCnt>MAX_WEIGHTING_CNT) { BeepBalErr(); //*MetagePtr= IedDb.buf.CurrWeight; //存坩埚不稳定质量 } LowTempStove.MoveStoveBar(LOW_POS_BOT); //移动炉子到放样位置 m_cDelayCnt = 0; setbit(Sample[m_cPos-1].cCSta,MetageBit); *m_cSchedule=M_NEXTPOS; } } break; case M_NEXTPOS: //转到下一个样位 if((LowTempStove.m_StovePos==LOW_POS_TOP)&& ((IedDb.DownloadWorkParam.m_szSystemType==G5000)|| ((LeftHighTempStove.m_StovePos==LowVertStoveBar::POS_BOT)&& (RightHighTempStove.m_StovePos==LowVertStoveBar::POS_BOT))))//判位置 { while(m_cPos<*MAX_SAMPLE) { //有坩埚,该位有上位机下载下来,只要有一个实验项目就会有 // 是否称量该重量,由是否做该实验决定 if(Sample[m_cPos].cSta&(1<<MetageBit)) { m_cPos++; m_cMDelay = 0; StepMotor[0].MoveStepMotor(m_cPos); //转到下个样位 *m_cSchedule=M_POS; return; } m_cPos++; } StepMotor[0].MoveStepMotor(1); //转到1st样位 *m_cSchedule=M_END; __NOP(); } break; case M_END: m_cPos=1; //完成,复位 SuspendTask(TASK_METAGE); //停止“称量”任务 ActiveTask(TASK_MANUAL,100L); //启动手动进位 beep.beep(2,1000L); //称量完毕,提示音 break; } }
void Test::TaskTestGB(void) { char i; long l; CFuzzy *pFuzzy = IedDb.fuzzy; //升温到105度 ; long *ADValue = IedDb.ADValue.ad ; SuspendTask(TASK_MANUAL); switch(IedDb.TestState) { case T_INIT: //初始化 SuspendTask(TASK_MANUAL); //停止手动进位 ResetSystem(); m_MDelay = 0; m_Pos = 1; m_TestTimer = -1; //增加条件判断,是否做该实验 switch(GetWillBeTestedType()) { case S_TEST_WATER: IedDb.TestState = T_WARM_WATER; break; case S_TEST_VOL: IedDb.TestState = T_WARM_HIGH1; break; case S_TEST_ASH: IedDb.TestState = T_WARM_HIGH2; break; default: IedDb.TestState = T_END; break; } break; case T_WARM_WATER: case T_TEST_WATER: case T_WEIGHT_WATER: case T_WATERCOOL: case T_WATER_END: TestWater(); break; case T_WARM_HIGH1: case T_TEST_VOL: case T_BURN_VOL: case T_WEIGHT_VOL: case T_VOL_END: TestVol(); break; case T_WARM_HIGH2: case T_TEST_ASH: case T_BURN_ASH: case T_WEIGHT_ASH: case T_ASH_END: TestAsh(); break; case T_END: __NOP(); break; default: ASSERT(false); break; } }