void FORTE_BL_IX::executeEvent(int pa_nEIID){ switch(pa_nEIID){ case scm_nEventINITID: delete m_poGPIO; m_poGPIO = NULL; if(QI() == true){ char * pacBuffer = new char[PARAMS().length() + 3]; PARAMS().toString(pacBuffer, sizeof(char)*(PARAMS().length() + 3)); if (verifyInput(pacBuffer, PARAMS().length() + 2)){ STATUS() = "OK"; QO() = true; }else{ STATUS() = "Input PARAM error"; QO() = false; } delete[] pacBuffer; }else{ STATUS() = "INIT- OK"; QO() = false; } sendOutputEvent(scm_nEventINITOID); break; case scm_nEventREQID: if(m_poGPIO != NULL){ IN() = m_poGPIO->isHigh(); STATUS() = "OK"; }else{ IN() = false; STATUS() = "Not initialized"; } sendOutputEvent(scm_nEventCNFID); break; } }
int main(int argc, char **argv) { char * operation; char * output; int * resultBinary; char * finaloutput; ArbitraryInt *firstNum; ArbitraryInt *secondNum; if (argc < 5) { fprintf(stderr, "ERROR: Too Few Arguments.\n"); return 1; } operation = argv[1]; if (operation[0] != '+' && operation [0] != '-') { fprintf(stderr, "ERROR: Unrecognized Arithmetic Operation. Please use only '+' or '-'.\n"); return 1; } firstNum = CreateInt(argv[2]); secondNum = CreateInt(argv[3]); if(firstNum->type == Invalid) { fprintf(stderr, "ERROR: Unrecognized format type for First Number. Please use 'b' for Binary, 'd' for Decimal, 'x' for Hexadecimal, or 'o' for Octal.\n"); return 1; } if(secondNum->type == Invalid) { fprintf(stderr, "ERROR: Unrecognized format type for Second Number. Please use 'b' for Binary, 'd' for Decimal, 'x' for Hexadecimal, or 'o' for Octal.\n"); return 1; } if(verifyInput(firstNum) == 1) { fprintf(stderr, "ERROR: Invalid Numerical String in First Number. Please enter a valid number for that format type.\n"); return 1; } if(verifyInput(secondNum) == 1) { fprintf(stderr, "ERROR: Invalid Numerical String in Second Number. Please enter a valid number for that format type.\n"); return 1; } output = argv[4]; if (output[0] != 'd' && output[0] != 'x' && output[0] != 'b' && output[0] != 'o') { fprintf(stderr, "ERROR: Invalid Output type. Please use 'b' for Binary, 'd' for Decimal, 'x' for Hexadecimal, or 'o' for Octal.\n"); return 1; } formatNum(firstNum); formatNum(secondNum); evenBinary(firstNum, secondNum); resultBinary = (int*) malloc((sizeof(int) * firstNum->size)); if(operation[0] == '+') add(firstNum, secondNum, resultBinary); else subtract(firstNum, secondNum, resultBinary); if (resultBinary[0] == 1) printf("%c", '-'); if(output[0] == 'o') { finaloutput = IntToOctASCII(resultBinary, firstNum->size); } else if(output[0] == 'b') { finaloutput = IntToBinASCII(resultBinary, firstNum->size); } else if(output[0] == 'x') { finaloutput = IntToHexASCII(resultBinary, firstNum->size); } else if(output[0] == 'd') { finaloutput = IntToDecASCII(resultBinary, firstNum->size); } printf(output); printf("%s\n", finaloutput); return 0; }
/*! This is the main routine for parsing input on the clientSocket. There should be one command for each line of input. This reads one line, and looks at the first word (up to the first space character) to determine the command. Then if there are body or robot indices to read, it calls a support routine to read those and return a vector of bodies or robots. These are then passed to the appropriate routine to carry out the action and write out any necessary results. */ void ClientSocket::readClient() { int i,numData,numBodies,numRobots; double time; std::vector<Body *> bodyVec; std::vector<Robot *> robVec; bool ok; while ( canReadLine() ) { line = readLine(); line.truncate(line.length()-1); //strip newline character lineStrList = QStringList::split(' ',line); strPtr = lineStrList.begin(); #ifdef GRASPITDBG std::cout <<"Command parser line: "<<line << std::endl; #endif if (*strPtr == "getContacts") { strPtr++; if (strPtr == lineStrList.end()) continue; numData = (*strPtr).toInt(&ok); strPtr++; if (!ok) continue; #ifdef GRASPITDBG std::cout << "Num data: "<<numData<<std::endl; #endif if (readBodyIndList(bodyVec)) continue; numBodies = bodyVec.size(); for (i=0;i<numBodies;i++) sendContacts(bodyVec[i],numData); } else if (*strPtr == "getAverageContacts") { strPtr++; if (readBodyIndList(bodyVec)) continue; numBodies = bodyVec.size(); for (i=0;i<numBodies;i++) sendAverageContacts(bodyVec[i]); } else if (*strPtr == "getBodyName") { strPtr++; if (readBodyIndList(bodyVec)) continue; numBodies = bodyVec.size(); for (i=0;i<numBodies;i++) sendBodyName(bodyVec[i]); } else if(*strPtr == "setBodyName") { strPtr++; int body_index; if(strPtr != lineStrList.end()){ body_index = strPtr->toInt(&ok); strPtr++; if(strPtr == lineStrList.end()) return; if (body_index == -1 || body_index >= graspItGUI->getIVmgr()->getWorld()->getNumBodies()) { body_index = graspItGUI->getIVmgr()->getWorld()->getNumBodies() - 1; } graspItGUI->getIVmgr()->getWorld()->getBody(body_index)->setName(*strPtr); } } else if (*strPtr == "getRobotName") { strPtr++; if (readRobotIndList(robVec)) continue; numRobots = robVec.size(); for (i=0;i<numRobots;i++) sendRobotName(robVec[i]); } else if (*strPtr == "getDOFVals") { strPtr++; if (readRobotIndList(robVec)) continue; numRobots = robVec.size(); for (i=0;i<numRobots;i++) sendDOFVals(robVec[i]); } else if (*strPtr == "moveDOFs") { strPtr++; readDOFVals(); } else if (*strPtr == "render") graspItGUI->getIVmgr()->getViewer()->render(); else if (*strPtr == "setDOFForces") { strPtr++; if (readRobotIndList(robVec)) continue; numRobots = robVec.size(); for (i=0;i<numRobots;i++) if (readDOFForces(robVec[i])==FAILURE) continue; } else if ((*strPtr) == "moveDynamicBodies") { strPtr++; if (strPtr == lineStrList.end()) ok = FALSE; else { time = (*strPtr).toDouble(&ok); strPtr++; } if (!ok) moveDynamicBodies(-1); else moveDynamicBodies(time); } else if (*strPtr == "computeNewVelocities") { #ifdef GRASPITDBG std::cout << "cnv" << std::endl; #endif strPtr++; if (strPtr == lineStrList.end()) continue; time = (*strPtr).toDouble(&ok); strPtr++; if (!ok) continue; #ifdef GRASPITDBG std::cout << time <<std::endl; #endif computeNewVelocities(time); } else if ((*strPtr) == "outputPlannerResults"){ strPtr++; outputPlannerResults(0); } else if ((*strPtr) == "outputCurrentGrasp"){ strPtr++; outputCurrentGrasp(); } else if ((*strPtr) == "sendBodyTransf"){ strPtr++; verifyInput(1); sendBodyTransf(); } else if ((*strPtr) == "setBodyTransf"){ strPtr++; verifyInput(7); setBodyTransf(); } else if ((*strPtr) == "addObstacle"){ strPtr++; verifyInput(1); addObstacle(*(strPtr+1)); strPtr+=2; } else if ((*strPtr) == "addObject"){ verifyInput(2); addGraspableBody(*(strPtr+1), *(strPtr+2)); strPtr+=3; verifyInput(7); transf object_pose; readTransf(&object_pose); World * w = graspItGUI->getIVmgr()->getWorld(); w->getGB(w->getNumGB() - 1)->setTran(object_pose); } else if ((*strPtr) == "getCurrentHandTran"){ strPtr++; getCurrentHandTran(); } else if ((*strPtr) == "signalGraspUnreachable"){ strPtr+=4; std::cout << line.toStdString() << std::endl; graspItGUI->getIVmgr()->blinkBackground(); } else if ((*strPtr) == "getPlannerTarget"){ strPtr+=1; QTextStream os (this) ; os << graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp()->getObject()->getName() << "\n"; } else if ((*strPtr) == "setPlannerTarget"){ QTextStream os(this); os << setPlannerTarget(*(strPtr+1)) << "\n"; strPtr+=2; } else if ((*strPtr) == "rotateHandLat"){ strPtr+=1; rotateHandLat(); } else if ((*strPtr) == "rotateHandLong"){ strPtr+=1; rotateHandLong(); } else if ((*strPtr) == "exec"){ strPtr+=1; exec(); } else if ((*strPtr) == "next"){ strPtr+=1; next(); } else if ((*strPtr) == "addPointCloud") { strPtr += 1; addPointCloud(); //QTextStream os(this); //os << addPointCloud() <<" \n"; } else if ((*strPtr) == "setCameraOrigin") { strPtr += 1; setCameraOrigin(); } else if ((*strPtr) == "removeBodies"){ strPtr += 1; removeBodies(); } else if ((*strPtr) == "clearGraspableBodies"){ strPtr += 1; removeBodies(true); } } }