std::string settingToString(Setting& setting, uint32_t maxElements) { Setting::Type t = setting.getType(); switch (t) { case Setting::Type::TypeInt: { return stringFormat("%i", (int)setting); } case Setting::Type::TypeInt64: { return stringFormat("%ll", (long long)setting); } case Setting::Type::TypeString: { return stringFormat("\"%s\"", (const char*)setting); } case Setting::Type::TypeBoolean: { return stringFormat("%i", (bool)setting); } case Setting::Type::TypeArray: case Setting::Type::TypeList: { std::ostringstream value; value << ((t == Setting::Type::TypeArray) ? "[" : "("); if (setting.getLength() > 0) { int i = 0; while (true) { value << settingToString(setting[i++]); if (i == setting.getLength()) { break; } if (i == maxElements) { value << ",..."; break; } else { value << ","; } } } else { value << "empty"; } value << ((t == Setting::Type::TypeArray) ? "]" : ")"); return value.str(); } default: { return std::string("<unknown-type>"); } } }
std::string beautyMem(T memSize) { if (memSize > 1024 * 1024 * 1024) { memSize /= 1024 * 1024 * 1024; return stringFormat("%d GB", memSize); } else if (memSize > 1024 * 1024) { memSize /= 1024 * 1024; return stringFormat("%d MB", memSize); } else if (memSize > 1024) { memSize /= 1024; return stringFormat("%d KB", memSize); } else { return stringFormat("%d B", memSize); } }
Stream* ClientStore::_replicateStream(StreamId stream) { assert(stream < _dynamicStreamIdBoundary); Message response = {0}; ClientPort& port = _getPort(); port.call(&response, RpcApi::CCV_StreamQuery, stream); ThrowOn((response.payloadType != MessagePayloadType::MptData) || (response.data.payloadLength != sizeof(StreamQueryInformation)), RpcMessageMalformedException); assert(response.data.payload != nullptr); StreamBuffer* buffer = _getStreamBuffer(response.parameter0); ThrowOnNull(buffer, NotFoundException, stringFormat("stream buffer with id %d", response.parameter0)); StreamQueryInformation* desc = reinterpret_cast<StreamQueryInformation*>(response.data.payload); std::unique_ptr<Stream> str(new StaticStream(stream, desc->descriptor, *buffer, getSession())); Stream* pstr = str.get(); // Make a shortcut for the return value _addStream(str); return pstr; }
//Measures shooter speed, calculates power, and updates LCD void calculateShooter() { wait1Msec(50); lastEncA = currentDistA; //Get the prevoius speed of the shooter currentDistA = SensorValue[encShooterRight2]; //Get the current speed of the shooter SensorValue[encShooterRight2] int currSysTime; //Calculate the motor speed based on the system timer and the motor distance. Average the results, weighing //heavily on the previous value to smooth out fluctuations float speed = ((currentDistA - lastEncA) * 50.0 / ((currSysTime = nSysTime) - lastSysTime+1)); speedAverages = speedAverages*0.9+ speed*0.1; //Save the previous states for next iteration lastSpeedA = speed; lastSysTime = currSysTime; if (speed > 80) { speed = 80; } //Clamp the aspeed to make sure it doesn't go over 80/s else if (speed < -80) { speed = -80; } // (prevents it from generating erronously high values) //Calculate error and add in a reversal gain if we are approaching the speed //(prevents overshooting due to the flywheel behavior of the shooter wheels) float error = targetSpeed - speedAverages; if (abs(error) < 0.25) {error = 0;} else if (abs(error) < 0.5) {error = error*-0.35;} //Make sure the motors will spin down on their own and not generate a negative power if (targetSpeed == 0) {error=0;} //Calculate power based on the error. Clamp the motor output to 127 shooterMotorRaw = manualSetSpeed+ error*(2.9*6.0); if (shooterMotorRaw <= 0) { shooterMotorRaw = 0; } //Update the LCD clearLCDLine(1); ready = (speedAverages > optimalSpeed - 1 && speedAverages < optimalSpeed + 1); bLCDBacklight = ready; string str; stringFormat(str, "M %-2i/%-3i",manualSetSpeed,shooterMotorRaw); displayLCDCenteredString(1, str); clearLCDLine(0); string str2; stringFormat(str2, "%2.2f/%2.2f",speedAverages,targetSpeed); displayLCDCenteredString(0, str2); }
void IBClient::commissionReport( const CommissionReport& commissionReport) { auto dict = createDictionary(std::map<std::string, K> { { "commission", kf(commissionReport.commission) }, { "currency", ks((S)commissionReport.currency.c_str()) }, { "execId", ks((S)commissionReport.execId.c_str()) }, { "realizedPNL", kf(commissionReport.realizedPNL) }, { "yield", kf(commissionReport.yield) }, { "yieldRedemptionDate", kp((S)stringFormat("%i", commissionReport.yieldRedemptionDate).c_str()) } }); receiveData("commissionReport", dict); }
std::string filenameWithFormat(std::string format, ...) { char *buffer; va_list args; va_start(args, format); vasprintf(&buffer,format.c_str(), args); va_end(args); char *name = getenv("EXECUTABLE_NAME"); // this is a bad way to do this, it's OSX specific atm std::string path = stringFormat("%s.app/Contents/Resources/%s",name,buffer); return path; }
std::unique_ptr<Stream> ClientStore::_createStream(StreamId id, StreamDescriptor& desc, BufferId buffer) { assert(id == INVALID_STREAM_ID); Message response = {0}; ClientPort& port = _getPort(); StreamBuffer* buf = _getStreamBuffer(buffer); ThrowOnNull(buf, NotFoundException, stringFormat("stream buffer with id %d", buffer)); if (IsSet(desc.flags, SfDynamic)) { const DynamicStreamDescriptor& dyndesc = reinterpret_cast<DynamicStreamDescriptor&>(desc); // For regular streams the server generates a valid id. For // dynamic streams we have to do this on our own, as dynamic // streams are local to the client. The ids must not collide! // The server generates ids for regular streams in the lower // positive integer range. We therefore generate the ids for // dynamic streams in the high positive integer range. The // limit for the number of streams (see Version.h) prevents a // collision. StreamId sid = --_dynamicStreamIdBoundary; #ifdef _DEBUG std::vector<StreamId> ids; _enumerateStreams(ids, StreamEnumFilter::SefRegular); StreamId max = *std::max_element(ids.cbegin(), ids.cend()); assert(max < sid); #endif return std::unique_ptr<Stream>( new DynamicStream(sid, dyndesc, *buf, getSession())); } else { port.call(&response, RpcApi::CCV_StreamRegister, &desc, sizeof(StreamDescriptor), buffer); StreamId rid = static_cast<StreamId>(response.parameter0); return std::unique_ptr<Stream>( new StaticStream(rid, desc, *buf, getSession())); } }
WinMenu::WinMenu(Rect rect,Player *player) : Menu(rect) { borderStyle = Border_Double; getCentreLabel()->setString("Victory"); getCentreLabel()->setColour(Colour::red()); Label *exitLabel = new Label("Exit"); exitLabel->setFrame(Rect(16,18+36,100,40)); add(exitLabel); Label *optionsLabel = new Label("You have won! Thanks for playing."); optionsLabel->setFrame(Rect(16,18+12,100,40)); add(optionsLabel); // LabelValue<bool,Object> *devLabel = new LabelValue<bool,Object>(std::string("Debug"),&(DEV)); // devLabel->setFrame(Rect(16,18+24,100,40)); // devLabel->setString("Debug"); // add(devLabel); Label *spiceLabel = new Label(stringFormat("You collected %d spice!",player->spiceCount())); spiceLabel->setFrame(Rect(16,18+24,100,40)); add(spiceLabel); }
FirstADTNPlusFwk::FirstADTNPlusFwk() : m_voidWorker(m_header + stringFormat(m_bigSignature, "bool", "bool"), stringFormat(m_footer, "true"), "f", m_commandLine, "./"), m_boolWorker(m_header + stringFormat(m_bigSignature, "bool", "bool"), stringFormat(m_footer, "true"), "f", m_commandLine, "./"), m_vectorWorker( m_header + stringFormat(m_bigSignature, "std::vector<std::string>", "std::vector<std::string>"), stringFormat(m_footer, "std::vector<std::string>()"), "f", m_commandLine, "./"), m_ext1DefaultWorker(m_header + stringFormat(m_littleSignature, "bool"), stringFormat(m_footer, "true"), "f", m_commandLine, "./"), m_ext2DefaultWorker(m_header + stringFormat(m_littleSignature, "bool"), stringFormat(m_footer, "true"), "f", m_commandLine, "./"), m_ext3DefaultWorker( m_header + stringFormat(m_littleSignature, "std::vector<std::string>"), stringFormat(m_footer, "std::vector<std::string>()"), "f", m_commandLine, "./"), m_ext4DefaultWorker(m_header + stringFormat(m_littleSignature, "bool"), stringFormat(m_footer, "false"), "f", m_commandLine, "./"), m_ext5DefaultWorker( m_header + stringFormat(m_littleSignature, "std::vector<std::string>"), stringFormat(m_footer, "std::vector<std::string>()"), "f", m_commandLine, "./") { }
std::string Tokenizer::generateErrorMessage(std::string message) { setLineCol(); return stringFormat("[Error] " + message + " at line %d col %d", line, col); }
void genResponse(short cid) { short power = motor[motorA]; float temp = 0.0; string tmpString; short index = 0; ubyte linebuff[20]; stringFromChars(tmpString, &RS485rxbuffer[0]); index = stringFind(tmpString, "/"); stringDelete(tmpString, 0, index); index = stringFind(tmpString, "HTTP"); stringDelete(tmpString, index, strlen(tmpString)); writeDebugStreamLine("Request:%s", tmpString); displayTextLine(2, "Request: "); displayTextLine(3, tmpString); if (stringFind(tmpString, "MOTA") > 0) { stringDelete(tmpString, 0, 6); index = stringFind(tmpString, " "); if (index > -1) stringDelete(tmpString, index, strlen(tmpString)); //power = RC_atoix(tmpString); power = clip(atoi(tmpString), -100, 100); writeDebugStreamLine("Power:%d", power); } else { writeDebugStreamLine("NO POWER: %s", tmpString); } sendHeader(cid); while(nxtHS_Status == HS_SENDING) sleep(5); sleep(100); index = 0; linebuff[0] = 27; // escape; linebuff[1] = 'S'; // the CID; linebuff[2] = (ubyte)cid + 48; // the CID; index = RS485appendToBuff(RS485txbuffer, index, linebuff, 3); stringFormat(tmpString, "MotorA=%d\n", power); memcpy(linebuff, tmpString, strlen(tmpString)); index = RS485appendToBuff(RS485txbuffer, index, linebuff, strlen(tmpString)); DTMPreadTemp(DTMP, temp); stringFormat(tmpString, "Temp: %2.2f C", temp); memcpy(linebuff, tmpString, strlen(tmpString)); index = RS485appendToBuff(RS485txbuffer, index, linebuff, strlen(tmpString)); linebuff[0] = 27; // escape; linebuff[1] = 'E'; // the CID; index = RS485appendToBuff(RS485txbuffer, index, endmarker, 2); RS485write(RS485txbuffer, index); if (power != 0) nMotorEncoderTarget[motorA] = 2000; motor[motorA] = power; if (power > 0) SensorType[COLOUR] = sensorColorNxtGREEN; else if (power < 0) SensorType[COLOUR] = sensorColorNxtBLUE; else if (nMotorRunState[motorA] == runStateIdle) SensorType[COLOUR] = sensorColorNxtRED; else SensorType[COLOUR] = sensorColorNxtRED; sleep(300); RS485clearRead(); DWIFIClose(1); memset(RS485rxbuffer, 0, sizeof(RS485rxbuffer)); //sleep(100); //RS485read(RS485rxbuffer, sizeof(RS485rxbuffer)); //clear_read_buffer(); RS485clearRead(); }