void UI::cmdRun(string & inputline) { // clear cmdVector each time when user input this->cmdVector.clear(); //std::cout << "inputline: " << inputline << inputline.size() << std::endl; // split input string for (auto it = inputline.begin(); it < inputline.end(); ++it) { string param; for(; it < inputline.end(); ++it) { if ((*it) == ' ' || (*it) == '\t') { break; } else if ((*it) == '\\' && (it + 1) != inputline.end() && *(it + 1) == ' ') { param += ' '; ++it; } else { param += *it; } } if (!param.empty()) { this->cmdVector.push_back(param); } } // for (auto it = cmdVector.cbegin(); it != cmdVector.cend(); ++it) // std::cout << it->size() << "cmdVector: " << *it << std::endl; // std::istringstream is(inputline); // while(is >> word) // this->cmdVector.push_back(word); if (!cmdCheck()) { return; } else { // remove command word, others are params cmdVector.erase(cmdVector.begin()); cliPI.run(this->cmdid, this->cmdVector); } // for (auto it = cmdVector.cbegin(); it != cmdVector.cend(); ++it) // std::cout << "cmdVector" << *it << std::endl; // for (std::vector<string>::size_type i = 0; i < cmdVector.size(); i++) // std::cout << cmdVecto }
//************************************************************************************** //*** //*** //*** //************************************************************************************** void main() { uchar cmd; schar j; uchar fname[14]; unsigned i; long swtrig = 0; picInit(); memInit(); serSendString("\r\nxPIClog\r\n"); serSendString("=======\r\n"); serUsage(); serSendString("\r\n\r\nCOLD START\r\n"); serSendString("CHECK TIME AND DATE!\r\n\r\n"); SDPOW(1); // SD card power on pinInitSD(); // other SD card pins filReadConfig("poweron"); pinExitSD(); // prepare card shutdown SDPOW(0); // SD card power on // a little ugly... for(;;) { // MENU LOOP for(;;) { // check serial commands cmd = cmdCheck(EXEC); // check pushbutton if( !SWITCH ) { LED(1); if( swtrig++ > 120000 ) cmd = CMD_OFF; } else { LED(1); // new v0.8a -> dim LED light during menu operation if( ( swtrig < 120000)&&(swtrig > 1000) ) cmd = CMD_START; swtrig = 0; LED(0); } if( cmd == CMD_START ) break; // power off? if( cmd == CMD_OFF ) { serSendString("\r\n\r\nGOING TO SLEEP\r\n\r\n"); LED(0); swtrig = 0; for(i=0;i<2000;i++) LED(1); LED(0); POWOUT(0); pinExitSD(); // prepare card shutdown SDPOW(0); // SD card power off BANDGAP(0); // voltage reference off sleep(); nop(); nop(); while( !SWITCH ) LED(1); LED(0); serSendString("\r\n\r\nWOKE UP\r\n\r\n"); cmd = CMD_LOAD; // ;-) } // read config file? if( cmd == CMD_LOAD ) { SDPOW(1); // SD card power on pinInitSD(); // other SD card pins filReadConfig((uchar *)&sCfg.crdFName); pinExitSD(); // prepare card shutdown SDPOW(0); // SD card power on }// END CMD load // read config file? if( cmd == CMD_SAVE ) { SDPOW(1); // SD card power on pinInitSD(); // other SD card pins filSaveConfig((uchar *)&sCfg.crdFName); pinExitSD(); // prepare card shutdown SDPOW(0); // SD card power on }// END CMD load }// END for menu loop // PREPARE ACQUISITION for(j=0;j<10;j++) { for(i=0;i<20000;i++) LED(1); for(i=0;i<20000;i++) LED(0); } serSendString("\r\nSTART\r\n"); measStorInit(); // new v0.8a; might be advantageous to clear the buffer first... rtcSetAlarm(sCfg.rtcSUnit,sCfg.rtcSRate); rtcEnableAlarm(); // ACQUISITION LOOP for(;;) { if( sCfg.rtcActive == NO ) break; if( sCfg.rtcSleep ) { sleep(); nop(); nop(); } } rtcDisableAlarm(); SDPOW(1); // SD card power on pinInitSD(); // other SD card pins LED(1); // just in case we left because of a serial transmission... serRXBufFlushIn(); serRXBufInit(); serSendString("\r\nWRITE PENDING DATA: "); strcpy((uchar *)&fname,(uchar*)&sCfg.crdFName); strcat((uchar *)&fname,".log"); // TODO if( (j=filOpenAppendClose((uchar *)&fname)) < 0) { // flush buffer while( measStorReadVMeas() > 0 ) {;} serSendString("ERROR\r\n"); } else { sCfg.crdSamplesWritten+=(uchar)j; serSendString("OK\r\n"); } pinExitSD(); // prepare card shutdown SDPOW(0); // SD card power off serSendString("\r\nSTOP\r\n"); // long->ulong might overflow (in years ;-) serSendStringDebug("SAMPLES WRITTEN: ",(long)sCfg.crdSamplesWritten,"\r\n"); while( !SWITCH ) {;} LED(0); }// END main for loop }
void userCmdLoop() { TSSAnalyzer analyzer; analyzer.Init(); bool fAutoMode = true, lastAutoMode = false; const size_t USERCMD_MAX = 128; char cmd[USERCMD_MAX + 1] = { 0 }; char lastCmd[USERCMD_MAX + 1] = { 0 }; do { if (lastAutoMode != fAutoMode) { myPrintf(fAutoMode ? "Auto mode ON\n" : "Auto mode OFF\n"); lastAutoMode = fAutoMode; } myPrintf(">"); memset(cmd, 0, sizeof(cmd)); fgets(cmd, USERCMD_MAX, stdin); char *newline = strchr(cmd, '\n'); if (newline) *newline = 0; myPrintfToLog("%s\n", cmd); if (cmd[0] == 0) memcpy(cmd, lastCmd, USERCMD_MAX); wchar_t wcmd[USERCMD_MAX + 1] = {0}; mbstowcs(wcmd, cmd, USERCMD_MAX); int argc = 0; wchar_t **argv = NULL; argv = CommandLineToArgvW(wcmd, &argc); if (argv == NULL) { continue; } if (_wcsicmp(argv[0], L"exit") == 0) { break; } else if (_wcsicmp(argv[0], L"clear") == 0 || _wcsicmp(argv[0], L"cls") == 0) { system("cls"); } else if (_wcsicmp(argv[0], L"logfile") == 0) { cmdLogFile(argc - 1, argv + 1); } else if (_wcsicmp(argv[0], L"status") == 0) { cmdStatus(); } else if (_wcsicmp(argv[0], L"auto") == 0) { if (argc > 1 && _wcsicmp(argv[1], L"off") == 0) fAutoMode = false; else fAutoMode = true; } else if (_wcsicmp(argv[0], L"snapshot") == 0 || _wcsicmp(argv[0], L"ss") == 0) { cmdSnapshot(analyzer); fAutoMode = false; } else if (_wcsicmp(argv[0], L"check") == 0) { cmdCheck(argc - 1, argv + 1); } else if (_wcsicmp(argv[0], L"use") == 0) { cmdUse(analyzer, argc, argv); } else { if (fAutoMode) analyzer.UpdateSnapshot(); bool fKnown = analyzer.Command(argc, argv); if (!fKnown) myPrintf("Unknown command\n"); } myPrintf("\n"); LocalFree(argv); memcpy(lastCmd, cmd, USERCMD_MAX); } while (true); analyzer.Term(); }