void GdbTermEngine::setupEngine() { QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); showMessage(_("TRYING TO START ADAPTER")); // Currently, adapters are not re-used // // We leave the console open, so recycle it now. // m_stubProc.blockSignals(true); // m_stubProc.stop(); // m_stubProc.blockSignals(false); if (!prepareCommand()) return; m_stubProc.setWorkingDirectory(runParameters().workingDirectory); // Set environment + dumper preload. m_stubProc.setEnvironment(runParameters().stubEnvironment); connect(&m_stubProc, &ConsoleProcess::processError, this, &GdbTermEngine::stubError); connect(&m_stubProc, &ConsoleProcess::processStarted, this, &GdbTermEngine::stubStarted); connect(&m_stubProc, &ConsoleProcess::stubStopped, this, &GdbTermEngine::stubExited); // FIXME: Starting the stub implies starting the inferior. This is // fairly unclean as far as the state machine and error reporting go. if (!m_stubProc.start(runParameters().executable, runParameters().processArgs)) { // Error message for user is delivered via a signal. handleAdapterStartFailed(QString()); return; } }
//命令处理,将命令与参数分开 void getComAndArgs(char*command,char ***pargs,short*pArgNum){ prepareCommand(command); int commandLen=strlen(command); int i=0; int j=0; int pos=0; //记录每次断点 int len=0; //命令或者参数长度 *pArgNum=0; for(i=0;i<commandLen;i++) if(command[i]==' ') len++; (*pargs)=(char**)malloc(sizeof(char*)*(len+2)); for(i=0;i<=commandLen;i++){ if(command[i]==' '||command[i]=='\0'){ ((*pargs)[*pArgNum])=malloc(i-pos+1); j=0; while(pos<i){ ((*pargs)[*pArgNum][j++])=command[pos++]; } ((*pargs)[*pArgNum][j])='\0'; pos++; (*pArgNum)++; } } ((*pargs)[len+1])=NULL; *pArgNum=len+2; }
void GetSecretCommand::send(ProtocolManager *to) { prepareCommand(0x00); sendCommand(to, true); user = to->user; }
void LocalPlainGdbAdapter::startAdapter() { QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); showMessage(_("TRYING TO START ADAPTER")); if (!prepareCommand()) return; QStringList gdbArgs; if (!m_outputCollector.listen()) { m_engine->handleAdapterStartFailed(tr("Cannot set up communication with child process: %1") .arg(m_outputCollector.errorString()), QString()); return; } gdbArgs.append(_("--tty=") + m_outputCollector.serverName()); if (!startParameters().workingDirectory.isEmpty()) m_gdbProc.setWorkingDirectory(startParameters().workingDirectory); if (startParameters().environment.size()) m_gdbProc.setEnvironment(startParameters().environment.toStringList()); if (!m_engine->startGdb(gdbArgs)) { m_outputCollector.shutdown(); return; } checkForReleaseBuild(); m_engine->handleAdapterStarted(); }
void GetSecretCommand::send(ProtocolSocket *to) { prepareCommand(Protocol::commandState(0)); sendCommand(to); user = to->user; }
void Speech::speak(QString command, bool stdIn, const QString &text, const QString &language, int encoding, QTextCodec *codec) { if (text.length() > 0) { // 1. prepare the text: // 1.a) encode the text QTextStream ts(&encText, QIODevice::WriteOnly); if (encoding == Local) ts.setCodec(QTextCodec::codecForLocale()); else if (encoding == Latin1) ts.setCodec("ISO-8859-1"); else if (encoding == Unicode) ts.setCodec("UTF-16"); else ts.setCodec(codec); ts << text; ts.flush(); // 1.b) create a temporary file for the text tempFile.open(); QTextStream fs(&tempFile); if (encoding == Local) fs.setCodec(QTextCodec::codecForLocale()); else if (encoding == Latin1) fs.setCodec("ISO-8859-1"); else if (encoding == Unicode) fs.setCodec("UTF-16"); else fs.setCodec(codec); fs << text; fs << endl; QString filename = tempFile.fileName(); tempFile.flush(); // 2. prepare the command: command = prepareCommand(command, QLatin1String(encText), filename, language); // 3. create a new process process << command; connect(&process, SIGNAL(processExited(K3Process*)), this, SLOT(processExited(K3Process*))); connect(&process, SIGNAL(wroteStdin(K3Process*)), this, SLOT(wroteStdin(K3Process*))); connect(&process, SIGNAL(receivedStdout(K3Process*, char*, int)), this, SLOT(receivedStdout(K3Process*, char*, int))); connect(&process, SIGNAL(receivedStderr(K3Process*, char*, int)), this, SLOT(receivedStderr(K3Process*, char*, int))); // 4. start the process if (stdIn) { process.start(K3Process::NotifyOnExit, K3Process::All); if (encText.size() > 0) process.writeStdin(encText, encText.size()); else process.closeStdin(); } else process.start(K3Process::NotifyOnExit, K3Process::AllOutput); }
void Speech::speak(QString command, bool stdIn, const QString &text, const QString &language, int encoding, QTextCodec *codec) { if (text.length () > 0) { // 1. prepare the text: // 1.a) encode the text QTextStream ts (encText, IO_WriteOnly); if (encoding == Local) ts.setEncoding (QTextStream::Locale); else if (encoding == Latin1) ts.setEncoding (QTextStream::Latin1); else if (encoding == Unicode) ts.setEncoding (QTextStream::Unicode); else ts.setCodec (codec); ts << text; // 1.b) create a temporary file for the text tempFile.setAutoDelete(true); QTextStream* fs = tempFile.textStream(); if (encoding == Local) fs->setEncoding (QTextStream::Locale); else if (encoding == Latin1) fs->setEncoding (QTextStream::Latin1); else if (encoding == Unicode) fs->setEncoding (QTextStream::Unicode); else fs->setCodec (codec); *fs << text; *fs << endl; QString filename = tempFile.file()->name(); tempFile.close(); // 2. prepare the command: command = prepareCommand (command, encText, filename, language); // 3. create a new process process << command; connect(&process, SIGNAL(processExited(KProcess *)), this, SLOT(processExited(KProcess *))); connect(&process, SIGNAL(wroteStdin(KProcess *)), this, SLOT(wroteStdin(KProcess *))); connect(&process, SIGNAL(receivedStdout(KProcess *, char *, int)), this, SLOT(receivedStdout(KProcess *, char *, int))); connect(&process, SIGNAL(receivedStderr(KProcess *, char *, int)), this, SLOT(receivedStderr(KProcess *, char *, int))); // 4. start the process if (stdIn) { process.start(KProcess::NotifyOnExit, KProcess::All); if (encText.size() > 0) process.writeStdin(encText, encText.size()); else process.closeStdin(); } else process.start(KProcess::NotifyOnExit, KProcess::AllOutput); }
int myBoard_prepare( int board ) { MY_BOARD_HARDWARE *pBoardHard = myBoard_getHardwareBoard( board ); MY_BOARD_SOFTWARE *pBoardSoft = myBoard_getSoftwareBoard( board ); if (pBoardHard == NULL || pBoardSoft == NULL) return 1; if (getOptimalRangeNumber( board )) { return 1; } if (configBoard( board )) { return 1; } if (prepareCommand( board )) { return 1; } return 0; }
void GdbPlainEngine::setupEngine() { QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); showMessage(_("TRYING TO START ADAPTER")); if (!prepareCommand()) return; QStringList gdbArgs; if (!m_outputCollector.listen()) { handleAdapterStartFailed(tr("Cannot set up communication with child process: %1") .arg(m_outputCollector.errorString())); return; } gdbArgs.append(_("--tty=") + m_outputCollector.serverName()); if (!runParameters().inferior.workingDirectory.isEmpty()) m_gdbProc.setWorkingDirectory(runParameters().inferior.workingDirectory); startGdb(gdbArgs); }
/*---------------------------------------------------------------------- * THREADED CODE - READS TELEMETRY AND SENDS COMMANDS TO KEEP FORTIUS ALIVE *----------------------------------------------------------------------*/ void Fortius::run() { // newly read values - compared against cached values double newload, newgradient; bool isDeviceOpen = false; // Cached current values // when new values are received from the device // if they differ from current values we update // otherwise do nothing int curmode, curstatus; double curload, curgradient; double curPower; // current output power in Watts double curHeartRate; // current heartrate in BPM double curCadence; // current cadence in RPM double curSpeed; // current speef in KPH int curButtons; // Button status // we need to average out power for the last second // since we get updates every 16ms (60hz) int powerhist[16]; // last 60s values received int powertot=0; // running total int powerindex=0; // index into the powerhist array for (int i=0; i<16; i++) powerhist[i]=0; // initialise local cache & main vars pvars.lock(); this->deviceStatus = FT_RUNNING; curmode = this->mode; curload = this->load; curgradient = this->gradient; curPower = this->devicePower = 0; curHeartRate = this->deviceHeartRate = 0; curCadence = this->deviceCadence = 0; curSpeed = this->deviceSpeed = 0; curButtons = this->deviceButtons; curButtons = 0; this->deviceButtons = 0; pvars.unlock(); // open the device if (openPort()) { quit(2); return; // open failed! } else { isDeviceOpen = true; } // send first command prepareCommand(curmode, curmode == FT_ERGOMODE ? curload : curgradient); if (sendCommand(curmode) == -1) { // send failed - ouch! closePort(); // need to release that file handle!! quit(4); return; // couldn't write to the device } QTime timer; timer.start(); while(1) { if (isDeviceOpen == true) { if (readMessage() > 0) { msleep(60); //slow down - need to wait for previous interrupt to clear // before reading. Not sure why, but solves issues // when working on OSX, and possibly Windows //---------------------------------------------------------------- // UPDATE BASIC TELEMETRY (HR, CAD, SPD et al) // The data structure is very simple, no bit twiddling needed here //---------------------------------------------------------------- // buttons curButtons = buf[13]; // brake status status&0x04 == stopping wheel // status&0x01 == brake on // buf[42]; // cadence curCadence = buf[44]; // speed curSpeed = (double)(qFromLittleEndian<quint16>(&buf[32])) / 360.00f; // power int power = qFromLittleEndian<qint16>(&buf[38])/10; powertot += power; powertot -= powerhist[powerindex]; powerhist[powerindex] = power; curPower = powertot / 16; powerindex = (powerindex == 15) ? 0 : powerindex+1; // heartrate curHeartRate = buf[12]; } else { // no data available!? It should block in libusb.. but lets sleep anyway msleep (50); } } //---------------------------------------------------------------- // LISTEN TO GUI CONTROL COMMANDS //---------------------------------------------------------------- pvars.lock(); curstatus = this->deviceStatus; load = curload = newload = this->load; gradient = curgradient = newgradient = this->gradient; // whilst we are here lets update the values deviceButtons = curButtons; deviceSpeed = curSpeed; deviceCadence = curCadence; deviceHeartRate = curHeartRate; devicePower = curPower; pvars.unlock(); /* time to shut up shop */ if (!(curstatus&FT_RUNNING)) { // time to stop! closePort(); // need to release that file handle!! quit(0); return; } if ((curstatus&FT_PAUSED) && isDeviceOpen == true) { closePort(); isDeviceOpen = false; } else if (!(curstatus&FT_PAUSED) && (curstatus&FT_RUNNING) && isDeviceOpen == false) { if (openPort()) { quit(2); return; // open failed! } isDeviceOpen = true; timer.restart(); // reset smoothing. powertot = 0; powerindex = 0; for (int i=0; i<16; i++) powerhist[i]=0; // send first command to get fortius ready prepareCommand(curmode, curmode == FT_ERGOMODE ? curload : curgradient); if (sendCommand(curmode) == -1) { // send failed - ouch! closePort(); // need to release that file handle!! quit(4); return; // couldn't write to the device } } //---------------------------------------------------------------- // KEEP THE FORTIUS CONNECTION ALIVE //---------------------------------------------------------------- if (isDeviceOpen == true) { prepareCommand(curmode, curmode == FT_ERGOMODE ? curload : curgradient); if (sendCommand(curmode) == -1) { // send failed - ouch! closePort(); // need to release that file handle!! quit(4); return; // couldn't write to the device } } } }
rootpaerror_t executeOneCmpCommand(CMTHANDLE handle, CmpMessage* commandP, CmpMessage* responseP) { LOGD(">>executeOneCmpCommand"); if (unlikely( bad_write_ptr(handle,sizeof(CMTSTRUCT)))) { return ROOTPA_ERROR_INTERNAL; } if(unlikely (commandP->contentP==NULL || commandP->length< sizeof(cmpCommandId_t))) { return ROOTPA_ERROR_INTERNAL; } mcResult_t mcRet=MC_DRV_OK; cmpCommandId_t commandId=getCmpCommandId(commandP->contentP); handle->mappedSize=getTotalMappedBufferSize(commandP); if(0==handle->mappedSize) { LOGE("<<executeOneCmpCommand, command %d not supported", commandId); return ROOTPA_COMMAND_NOT_SUPPORTED; } rootpaerror_t ret=ROOTPA_OK; while(true) { handle->mappedP=malloc((size_t) handle->mappedSize); if(NULL==handle->mappedP) { ret=ROOTPA_ERROR_OUT_OF_MEMORY; break; } memset(handle->mappedP, 0,handle->mappedSize); mcRet=mcMap(&handle->session, handle->mappedP, handle->mappedSize, &handle->mapInfo); if(mcRet!=MC_DRV_OK) { LOGE("executeOneCmpCommand not able to map memory %d", mcRet); ret=ROOTPA_ERROR_MOBICORE_CONNECTION; commandP->hdr.intRet=mcRet; responseP->hdr.intRet=mcRet; break; } if((ret = prepareCommand(commandId, commandP, handle, responseP))!=ROOTPA_OK) { LOGE("prepareCommand failed %d", ret); break; } if (unlikely( !tltChannelTransmit(handle, NOTIFICATION_WAIT_TIMEOUT_MS))) { ret=ROOTPA_ERROR_MOBICORE_CONNECTION; commandP->hdr.intRet=handle->lasterror; responseP->hdr.intRet=handle->lasterror; break; } uint32_t neededBytes=getNeededBytesFromResponse(handle->wsmP); if(0==neededBytes) { break; } if(-1==neededBytes) { ret=ROOTPA_ERROR_MOBICORE_CONNECTION; break; } if(neededBytes <= handle->mappedSize) { LOGE("executeOneCmpCommand, there is something wrong. CMTL is requesting smaller buffer than we originally had. Command: %d, original %d requested %d", commandId, handle->mappedSize, neededBytes); ret=ROOTPA_ERROR_MOBICORE_CONNECTION; break; } // this is Info level LOGI on purpose LOGI("executeOneCmpCommand, updating RootPA recommended (%d bytes was not enough for %d response, allocating %d bytes and retrying)", handle->mappedSize, commandId, neededBytes); mcRet=mcUnmap(&handle->session, handle->mappedP, &handle->mapInfo); if(mcRet!=MC_DRV_OK) { LOGE("executeOneCmpCommand not able to free mapped memory %d", mcRet); ret=ROOTPA_ERROR_MOBICORE_CONNECTION; commandP->hdr.intRet=mcRet; responseP->hdr.intRet=mcRet; break; } free(handle->mappedP); memset(&handle->mapInfo, 0 , sizeof(handle->mapInfo)); handle->mappedSize=neededBytes; } if(ROOTPA_OK==ret) { ret=handleResponse(commandId, responseP, handle); } else { responseP->hdr.ret=ret; } LOGD("cleaning up mapped memory %ld",(long int) handle->mappedP); mcRet=mcUnmap(&handle->session, handle->mappedP, &handle->mapInfo); if(mcRet!=MC_DRV_OK) { LOGE("executeOneCmpCommand not able to free mapped memory %d", mcRet); ret=ROOTPA_ERROR_MOBICORE_CONNECTION; } LOGD("freeing mapped memory %ld", (long int) handle->mappedP); free(handle->mappedP); if(commandP->hdr.ret==ROOTPA_OK) commandP->hdr.ret=ret; if(responseP->hdr.ret==ROOTPA_OK) responseP->hdr.ret=ret; LOGD("<<executeOneCmpCommand %d %d",commandId, ret); return ret; }