void onCommandSetPoint() { if (isChannelCorrect(gParameters[0])) { int channel = convertToInt(gParameters[0]); double setPoint = atof(gParameters[1]); if (isReadCommand(gParameters[1])) { sendDouble(setPoints[channel]); sendAck(); } else if (isDoubleWithinRange(setPoint, minSetPoint[channel], maxSetPoint[channel])) { setPoints[channel] = setPoint; sendAck(); } else { sendDoubleRangeError(minSetPoint[channel], maxSetPoint[channel], DEGREES_UNIT); } } else { sendChannelError(); } }
int StringCalculator::calculateExpression(char string[]) { StackInterface* stackObject = new PointerStack(); makePolish(string, stackObject); //printf("%s\n", string); int i = 0; int length = strlen(string) + 1; int argument1 = 1; int argument2 = 1; int tmpResult = 0; for (i = 0; i < length; i++) { if (isNumber(string[i])) stackObject->push(convertToInt(string[i])); if (isSign(string[i])) { argument2 = stackObject->pop(); argument1 = stackObject->pop(); tmpResult = makeOperation(string[i], argument1, argument2); stackObject->push(tmpResult); } } int result = stackObject->pop(); delete stackObject; return result; }
int main(int argc, char *argv[]) { char *instruction = *(argv + 2); char *input = *(argv + 1); switch(*instruction) { case '1': convertToInt(input); break; case '2': convertToFloat(input); break; case '3': convertToUpperCase(input); break; case '4': revString(input); break; case '5': palindrome(input); break; default: printf("Error: \"%s\" was an invalid input.\n", argv[2]); } return 0; }
void onCommandLoopInterval() { int loopInterval = convertToInt(gParameters[0]); if (isReadCommand(gParameters[0])) { sendInt(pidLoopInterval); sendAck(); } else if (isIntWithinRange(loopInterval, PID_INTERVAL_MS_MIN, PID_INTERVAL_MS_MAX)) { if (!isPidEnabled) { pidLoopInterval = loopInterval; sendAck(); } else { Serial.println(F("Cannot change loop interval while PID control is on.")); sendNack(); } } else { sendIntRangeError(PID_INTERVAL_MS_MIN, PID_INTERVAL_MS_MAX, MILLISECONDS_UNIT); } }
void CNodesManager::addNode( CNodeMedium * _medium ) { boost::lock_guard<boost::mutex> lock( m_nodesLock ); // create and run ping action m_ptrToNodes.insert( std::make_pair( convertToInt( _medium->getNode() ), _medium ) ); }
void onCommandIntegralWindup() { if (isChannelCorrect(gParameters[0])) { int channel = convertToInt(gParameters[0]); double windup = atof(gParameters[1]); if (isReadCommand(gParameters[1])) { sendDouble(iWindupThresholds[channel]); sendAck(); } else if (isDoubleWithinRange(windup, I_WINDUP_THRESH_MIN, I_WINDUP_THRESH_MAX)) { iWindupThresholds[channel] = windup; sendAck(); } else { sendDoubleRangeError(I_WINDUP_THRESH_MIN, I_WINDUP_THRESH_MAX, DEGREES_UNIT); } } else { sendChannelError(); } }
void egEncrypt(egpbk_t k, egdm_t m, egem_t *c) { // Useful for random generation if (!seed_initialized) rnInit(); // Temporary variables mpz_t tmp; mpz_init(tmp); mpz_urandomb(tmp, seed, EG_KEY_SIZE); // Counters and size of encrypted message int i = 0, l = 0; // Memory initialization mpz_init(c->y1); c->y2 = convertToInt(m.m, m.size, k.k, &l); c->size = l; mpz_powm(c->y1, k.alpha, tmp, k.p); mpz_powm(tmp, k.beta, tmp, k.p); while(i < c->size) { // Encryption mpz_mul(c->y2[i], c->y2[i], tmp); mpz_mod(c->y2[i], c->y2[i], k.p); i++; } mpz_clear(tmp); }
// 投影mesh模型的坐标到屏幕上 void ScanLineZBufferCore::ProjectModelToScene() { int height = m_viewport[3]; int width = m_viewport[4]; for (auto vertex_it = pMesh->vertices_begin(); vertex_it != pMesh->vertices_end(); ++vertex_it) { int idx = vertex_it.handle().idx(); auto point = pMesh->point(vertex_it.handle()); auto x = point.data()[0], y = point.data()[1], z = point.data()[2]; //std::cout << "几何点坐标: " << x << " " << y << " " << z << std::endl; gluProject(x, y, z, m_modelview, m_projection, m_viewport, &m_projectionVertex[idx].x, &m_projectionVertex[idx].y, &m_projectionVertex[idx].z); m_projectionVertex[idx].x = convertToInt(m_projectionVertex[idx].x); m_projectionVertex[idx].y = convertToInt(m_projectionVertex[idx].y); m_projectionVertex[idx].z = m_projectionVertex[idx].z * 1000; //std::cout << "投影坐标: " << m_projectionVertex[idx].x << " " << m_projectionVertex[idx].y << " " << m_projectionVertex[idx].z << std::endl; } //std::cout << pMesh->n_vertices() << std::endl; }
void medDoubleParameter::updateInternWigets() { if(d->spinBox) d->spinBox->setValue(m_value); if(d->slider) d->slider->setValue(convertToInt(m_value)); if(d->valueLabel) d->valueLabel->setText(QString::number(m_value, 'f', 2)); }
IMS_Data::ListSysInfo_ptr SysInfoServer::getSysInfo() { string req = "SELECT diskspace, machineid, memory from machine WHERE vishnu_vishnuid='"+convertToString(mvishnuId)+"'"; vector<string> results = vector<string>(); vector<string>::iterator iter; if(mop.getMachineId().compare("")) { string reqnmid = "SELECT nummachineid from machine where machineid ='"+mop.getMachineId()+"'"; boost::scoped_ptr<DatabaseResult> result(mdatabase->getResult(reqnmid.c_str())); if(result->getNbTuples() == 0) { throw IMSVishnuException(ERRCODE_INVPROCESS, "Unknown machine id"); } req += " AND machineid ='"+mop.getMachineId()+"'"; } IMS_Data::IMS_DataFactory_ptr ecoreFactory = IMS_Data::IMS_DataFactory::_instance(); IMS_Data::ListSysInfo_ptr mlistObject = ecoreFactory->createListSysInfo(); try { boost::scoped_ptr<DatabaseResult> result(mdatabase->getResult(req.c_str())); for (size_t i = 0; i < result->getNbTuples(); i++){ results.clear(); results = result->get(i); iter = results.begin(); IMS_Data::SystemInfo_ptr sys = ecoreFactory->createSystemInfo(); if ((*(iter)).empty()) { sys->setDiskSpace(-1); } else { sys->setDiskSpace(convertToInt(*(iter))); } if ((*(iter+2)).empty()) { sys->setMemory(-1); } else { sys->setMemory(convertToInt(*(iter+2))); } sys->setMachineId(*(iter+1)); mlistObject->getSysInfo().push_back(sys); } } catch (SystemException& e) { throw (e); } return mlistObject; }
// Allows the reading or changing of direction for specified motor, but only allows change in // direction if the change results in a percentage change of less than the outputRateLimit void onCommandDirection() { if (isChannelCorrect(gParameters[0])) { uint8_t channel = convertToInt(gParameters[0]); if (isReadCommand(gParameters[1])) { sendDirectionStatus(directions[channel]); sendAck(); } else if (!isPidEnabled) { int output = currentOutputs[channel]; int outputRateLimit = outputRateLimits[channel]; Direction direction; if (isClockwiseCommandArg(gParameters[1])) { direction = Direction::Clockwise; } else if (isCounterClockwiseCommandArg(gParameters[1])) { direction = Direction::CounterClockwise; } else { sendDirectionError(); return; } if (direction != directions[channel] && output > outputRateLimit / 2) { Serial << F("Cannot make a change to output by more than ") << outputRateLimit << F("%") << NEWLINE; sendNack(); } else { applyMotorOutputs(channel, direction, output); sendAck(); } } else { Serial.println(F("Cannot change direction while PID control is on.")); sendNack(); } } else { sendChannelError(); } }
/** * \brief Function to parse the string representing the version * \param version the string representing the version * \return The version object */ UMS_Data::Version_ptr vishnu::parseVersion(const std::string& version) { UMS_Data::Version_ptr vers = NULL; std::string major; std::string minor; std::string patch; size_t found = version.find_first_of("."); if (found != std::string::npos) { major = version.substr(0, found) ; std::string rest = version.substr(found+1, version.size()) ; found = rest.find_first_of("."); if (found != std::string::npos) { minor = rest.substr(0, found); patch = rest.substr(found+1, rest.size()); } //if the string major, minor, patch are not empty if ((major.size() != 0) && (minor.size() != 0) && (patch.size() != 0)) { //if the values major, minor, patch are positives and major value higher than zero if ((convertToInt(major) > 0) && (convertToInt(minor) >= 0) && (convertToInt(patch) >= 0)) { UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance(); vers = ecoreFactory->createVersion(); vers->setMajor(convertToInt(major)); vers->setMinor(convertToInt(minor)); vers->setPatch(convertToInt(patch)); vers->setStringformat(version); } } } return vers; }
void medDoubleParameter::setRange(double min, double max) { d->min = min; d->max = max; if(min == max) return; if(d->spinBox) d->spinBox->setRange(min, max); if(d->slider) d->slider->setRange(0,convertToInt(max)); }
int convertToIntTest() { START_TEST_CASE; char *input; uint32_t output = 0; int error = 1; input = calloc(100, sizeof(char)); strcpy(input, "5"); if (convertToInt(input, &output) == 0) { fprintf(stderr, "%s\n", "Error nonnumeric input"); } SHOULD_BE(output == 5); strcpy(input, "abc"); if (convertToInt(input, &output) == 0) { error = 0; } SHOULD_BE(error == 0); error = 1; strcpy(input, "abc123"); if (convertToInt(input, &output) == 0) { error = 0; } SHOULD_BE(error == 0); error = 1; strcpy(input, "123abc"); if (convertToInt(input, &output) == 0) { error = 0; } SHOULD_BE(error == 0); error = 1; free(input); END_TEST_CASE; }
void onCommandMotorDriver() { if (isChannelCorrect(gParameters[0])) { uint8_t channel = convertToInt(gParameters[0]); if (isReadCommand(gParameters[1])) { sendMotorDriverStatus(motorDriverTypes[channel]); sendAck(); } else { if (!isPidEnabled) { if (isAnalogVoltageCommandArg(gParameters[1])) { motorDriverTypes[channel] = AnalogVoltage; sendAck(); } else if (isFrequencyCommandArg(gParameters[1])) { if (channel == TILT_CHANNEL) { motorDriverTypes[channel] = Frequency; sendAck(); } else { Serial.println(F("Yaw (Channel 1) can only be set to Analog Voltage")); sendNack(); } } else { sendMotorDriverError(); } } else { Serial.println(F("Cannot change driver type while PID control is on.")); sendNack(); } } } else { sendChannelError(); } }
void rsaEncrypt(rsapbk_t k, rsadm_t m, rsaem_t *c) { // Counters and size of encrypted message int i = 0, tmp; // Memory initialization c->mess = convertToInt(m.mess, m.size, k.k, &tmp); c->size = tmp; while(i < c->size) { // Encryption mpz_powm(c->mess[i], c->mess[i], k.pbk, k.n); i++; } }
//This function takes in the input binary string and extracts values and sets the global variables. void Scheduler::Tokenize(String binaryInput) { String tokens[4]; // Tokenize the input binary input tokens[0]= binaryInput.substring(0, 1); // 1 bit tokens[1]= binaryInput.substring(1, 3); // 2 bits tokens[2]= binaryInput.substring(3, 6); // 3 bits tokens[3]= binaryInput.substring(6, 11); // 5 bits /* // Setting up appropriate variables based on the input if(convertToInt(tokens[0]) == 0) userType = "Passenger"; else userType = "Operator"; */ elevatorID = convertToInt(tokens[1]); opCode = convertToInt(tokens[2]); floor = convertToInt(tokens[3]); if(elevatorID == 3) { if(userType == "Passenger") { userType = "Operator"; Serial.println("---- Operator Mode ----"); } else { userType = "Passenger"; Serial.println("---- Passenger Mode ----"); } } }
void onCommandOutput() { if (isChannelCorrect(gParameters[0])) { int channel = convertToInt(gParameters[0]); int output = convertToInt(gParameters[1]); if (isReadCommand(gParameters[1])) { sendInt(currentOutputs[channel]); sendAck(); } else if (!isPidEnabled) { if (isIntWithinRange(output, PID_OUTPUT_MIN, PID_OUTPUT_MAX)) { const Direction direction = directions[channel]; applyMotorOutputs(channel, direction, output); sendAck(); } else { sendIntRangeError(PID_OUTPUT_MIN, PID_OUTPUT_MAX, PERCENTAGE_UNIT); } } else { Serial.println(F("Cannot change percentage output while PID control is on.")); sendNack(); } } else { sendChannelError(); } }
// 对活化多边形表排序的比较函数, bool cmp(const ActiveEdgeTableElem &lhs, const ActiveEdgeTableElem &rhs) { if (convertToInt(lhs.xl) < convertToInt(rhs.xl)) return true; else if (convertToInt(lhs.xl) == convertToInt(rhs.xl)) { if (convertToInt(lhs.dxl) < convertToInt(rhs.dxl)) return true; } return false; }
void onCommandDerivativeGain() { if (isChannelCorrect(gParameters[0])) { int channel = convertToInt(gParameters[0]); if (isProfileCorrect(gParameters[1])) { int profile = convertToInt(gParameters[1]); double dGain = atof(gParameters[2]); if (isReadCommand(gParameters[2])) { sendDouble(dGains[channel][profile]); sendAck(); } else if (isDoubleWithinRange(dGain, D_GAIN_MIN, D_GAIN_MAX)) { dGains[channel][profile] = dGain; sendAck(); } else { sendDoubleRangeError(D_GAIN_MIN, D_GAIN_MAX, NO_UNIT); } } else { sendProfileError(); } } else { sendChannelError(); } }
int main(int, char**) { std::cout << "Hello world folly" << std::endl; convertToInt("77"); convertToInt("77 "); convertToInt(" 77 "); convertToInt("77 a"); convertToInt("77 x"); convertToInt("77"); convertToInt("abc"); convertToInt(""); convertToInt("0x0"); convertToInt("0.000000"); folly::dynamic result = folly::dynamic::object("rows", {{"123456"}, {"67589"}}); for (auto& row : result["rows"]) { auto s = folly::to<std::string>(row[0].asString()); std::cout << s << std::endl; } return 0; }
void medDoubleParameter::setSingleStep(double step) { if(step <= 0) { qWarning() << "Attempt to set a step <= 0 to medDoubleParameter"; return; } d->step = step; if(d->spinBox) d->spinBox->setSingleStep(step); if(d->slider) d->slider->setSingleStep(convertToInt(step)); }
void onCommandAdc() { int adcChannel = convertToInt(gParameters[0]); if (isIntWithinRange(adcChannel, ADC_CHANNEL_MIN, ADC_CHANNEL_MAX)) { double voltage = getSampledAdcVoltage(adcChannel); sendDouble(voltage); sendAck(); } else { sendIntRangeError(ADC_CHANNEL_MIN, ADC_CHANNEL_MAX, NO_UNIT); } }
// This command is complex because it only allows setting of frequency for channel 1 // This is because only the tilt motor can be controlled by frequency void onCommandFrequencyOutput() { if (isChannelCorrect(gParameters[0])) { uint8_t channel = convertToInt(gParameters[0]); uint16_t frequency = convertToUint(gParameters[1]); if (channel == TILT_CHANNEL) { if (isReadCommand(gParameters[1])) { sendInt(currentFrequency); sendAck(); } else { if (!isSafetyOn) { if (isIntWithinRange(frequency, MOTOR_MIN_FREQUENCY, MOTOR_MAX_FREQUENCY)) { setFrequency(frequency); sendAck(); } else { sendIntRangeError(MOTOR_MIN_FREQUENCY, MOTOR_MAX_FREQUENCY, HERTZ_UNIT); } } else { Serial.println(F("Cannot change frequency output while safety is on.")); sendNack(); } } } else { Serial.println(F("Changing or reading of frequency only applies to channel 1")); sendNack(); } } else { sendChannelError(); } }
/** * \brief Function to check a userId * \fn bool existuserId(std::string userId) * \param userId The userId to check * \return true if the userId exists */ bool UserServer::existuserId(std::string userId) { //If the userID exists on the database if (getAttribut("where userid='"+userId+"'").size() != 0) { //If the user is not locked if ( convertToInt(getAttribut("where userid='"+userId+"'", "status")) == 1) { return true; } //END if the user is not locked else { UMSVishnuException e (ERRCODE_USER_LOCKED); throw e; } }//END If the userID exists on the database else { return false; } }
int ShellExporter::exporte(string oldSession, string &content){ vector<string>::iterator iter; vector<string> line; // Init the script content = "#!/bin/sh"; content += " \n"; // Check the user is alloed to export if (!muser.isAdmin() && !isAllowed(oldSession, muser)){ throw IMSVishnuException(ERRCODE_INVEXPORT, "The user is not allowed to export this session"); } // Check the session is closed if (!isClosed(oldSession)) { throw IMSVishnuException(ERRCODE_INVEXPORT, "The session id is invalid"); } // The request, ordered by starttime (=submission) string req = "SELECT command.ctype, command.description, command.starttime from " " command, vsession where vsession.numsessionid=command.vsession_numsessionid and " " vsession.vsessionid='"+oldSession+"' order by starttime asc"; boost::scoped_ptr<DatabaseResult> result (mdatabase->getResult(req.c_str())); // Adding all the results to the content for (size_t i = 0 ; i<result->getNbTuples(); i++) { line.clear(); line = result->get(i); iter = line.begin(); //MAPPER CREATION try { CmdType type = static_cast<CmdType>(convertToInt(*iter)); Mapper* mapper = MapperRegistry::getInstance()->getMapper(getMapperName(type)); content += mapper->decode(*(++iter)); } catch (SystemException &e) { throw (e); } content += " \n"; } return 0; }
/** * \brief Function to list machines information * \fn UMS_Data::ListMachines* list() * \return The pointer to the UMS_Data::ListMachines containing machines information * \return raises an exception on error */ UMS_Data::ListMachines* list() { std::string sqlListofMachines = "SELECT machineid, name, site, status, lang, description from machine, description " "where machine.nummachineid = description.machine_nummachineid"; std::vector<std::string>::iterator ii; std::vector<std::string> results; UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance(); mlistObject = ecoreFactory->createListMachines(); //Creation of the object user UserServer userServer = UserServer(msessionServer); userServer.init(); //if the user exists if (userServer.exist()) { //To process options processOptions(userServer, mparameters, sqlListofMachines); boost::scoped_ptr<DatabaseResult> ListofMachines (mdatabaseVishnu->getResult(sqlListofMachines.c_str())); if (ListofMachines->getNbTuples() != 0){ for (size_t i = 0; i < ListofMachines->getNbTuples(); ++i) { results.clear(); results = ListofMachines->get(i); ii = results.begin(); UMS_Data::Machine_ptr machine = ecoreFactory->createMachine(); machine->setMachineId(*ii); machine->setName(*(++ii)); machine->setSite(*(++ii)); machine->setStatus(convertToInt(*(++ii))); machine->setLanguage(*(++ii)); machine->setMachineDescription(*(++ii)); mlistObject->getMachines().push_back(machine); } } } else { UMSVishnuException e (ERRCODE_UNKNOWN_USER); throw e; } return mlistObject; }
/* creates token number struct which holds information * about the one of numbers that the user inputted will return NULL * if number is greater than 32 bits. Holds negative indicator, base 10 * equivalent, type of input and the number string itself*/ number* numCreate (char* str) { number *ptr = (number*) malloc (sizeof(number)); ptr -> equiv = 0; if (str[0] == '-') { ptr -> negative = 1; ptr -> type = str[1]; ptr -> numString = strdup(&str[2]); } else { ptr -> negative = 0; ptr -> type = str[0]; ptr -> numString = strdup(&str[1]); } if (convertToInt(ptr) == 1) return NULL; return ptr; }
void onCommandAngle() { if (isChannelCorrect(gParameters[0])) { int channel = convertToInt(gParameters[0]); if (isReadCommand(gParameters[1])) { sendDouble(currentAngles[channel]); sendAck(); } else { sendReadOnlyError(); } } else { sendChannelError(); } }
/** * @brief OptionDefinition::convertValue * @param stringValue * @return */ QVariant OptionDefinition::convertValue(const QString &stringValue) const { QVariant value(QVariant::Invalid); switch (d->m_dataType) { case QVariant::Bool: value.setValue(convertToBool(stringValue)); break; case QVariant::Date: value.setValue(convertToDate(stringValue)); break; case QVariant::DateTime: value.setValue(convertToDateTime(stringValue)); break; case QVariant::Double: value.setValue(convertToDouble(stringValue)); break; case QVariant::Int: value.setValue(convertToInt(stringValue)); break; case QVariant::LongLong: value.setValue(convertToLongLong(stringValue)); break; case QVariant::String: value.setValue(stringValue); break; case QVariant::Time: value.setValue(convertToTime(stringValue)); break; case QVariant::UInt: value.setValue(convertToUInt(stringValue)); break; case QVariant::ULongLong: value.setValue(convertToULongLong(stringValue)); break; default: break; } return value; }