void EventRecorder::processMillis(uint32 &millis) { uint32 d; if (_recordMode == kPassthrough) { return; } g_system->lockMutex(_timeMutex); if (_recordMode == kRecorderRecord) { d = millis - _lastMillis; writeTime(_recordTimeFile, d); _recordTimeCount++; } if (_recordMode == kRecorderPlayback) { if (_recordTimeCount > _playbackTimeCount) { d = readTime(_playbackTimeFile); while ((_lastMillis + d > millis) && (_lastMillis + d - millis > 50)) { _recordMode = kPassthrough; g_system->delayMillis(50); millis = g_system->getMillis(); _recordMode = kRecorderPlayback; } millis = _lastMillis + d; _playbackTimeCount++; } } _lastMillis = millis; g_system->unlockMutex(_timeMutex); }
void readRecord(SeekableReadStream *inFile, uint32 &diff, Event &event, uint32 &millis) { millis = readTime(inFile); diff = inFile->readUint32LE(); event.type = (EventType)inFile->readUint32LE(); switch (event.type) { case EVENT_KEYDOWN: case EVENT_KEYUP: event.kbd.keycode = (KeyCode)inFile->readSint32LE(); event.kbd.ascii = inFile->readUint16LE(); event.kbd.flags = inFile->readByte(); break; case EVENT_MOUSEMOVE: case EVENT_LBUTTONDOWN: case EVENT_LBUTTONUP: case EVENT_RBUTTONDOWN: case EVENT_RBUTTONUP: case EVENT_WHEELUP: case EVENT_WHEELDOWN: case EVENT_MBUTTONDOWN: case EVENT_MBUTTONUP: event.mouse.x = inFile->readSint16LE(); event.mouse.y = inFile->readSint16LE(); break; default: break; } }
// Aquire data from buffer and convert to time_t // Returns true if successful bool DS1374RTC::readTime(time_t &t) { // TODO get rid of the unnecessary time conversions here tmElements_t tm; if (readTime(tm) == false) return false; t = makeTime(tm); return true; }
void hokuyo::Laser::readData(hokuyo::LaserScan& scan, bool has_intensity, int timeout) { scan.ranges.clear(); scan.intensities.clear(); int data_size = 3; if (has_intensity) data_size = 6; char buf[100]; int ind = 0; scan.self_time_stamp = readTime(timeout); int bytes; float range; float intensity; for (;;) { bytes = laserReadline(&buf[ind], 100 - ind, timeout); if (bytes == 1) // This is \n\n so we should be done return; if (!checkSum(&buf[ind], bytes)) HOKUYO_EXCEPT(hokuyo::CorruptedDataException, "Checksum failed on data read."); bytes += ind - 2; // Read as many ranges as we can get for (int j = 0; j < bytes - (bytes % data_size); j+=data_size) { if (scan.ranges.size() < MAX_READINGS) { range = (((buf[j]-0x30) << 12) | ((buf[j+1]-0x30) << 6) | (buf[j+2]-0x30)) / 1000.0; scan.ranges.push_back(range); if (has_intensity) { intensity = (((buf[j+3]-0x30) << 12) | ((buf[j+4]-0x30) << 6) | (buf[j+5]-0x30)); scan.intensities.push_back(intensity); } } else { HOKUYO_EXCEPT(hokuyo::CorruptedDataException, "Got more readings than expected"); } } // Shuffle remaining bytes to front of buffer to get them on the next loop ind = 0; for (int j = bytes - (bytes % data_size); j < bytes ; j++) buf[ind++] = buf[j]; } }
bool IniConfig::readSidplay2 (ini_fd_t ini) { bool ret = true; int time, version = sidplay2_s.version; (void) ini_locateHeading (ini, "SIDPlay2"); ret &= readInt (ini, "Version", version); if (version > 0) sidplay2_s.version = version; ret &= readString (ini, "Songlength Database", sidplay2_s.database); if (readTime (ini, "Default Play Length", time)) sidplay2_s.playLength = (uint_least32_t) time; if (readTime (ini, "Default Record Length", time)) sidplay2_s.recordLength = (uint_least32_t) time; return ret; }
int readGroup(Tgroup *group) { int array_size; printf("\n\nHow many runners do you have? "); scanf("%d", &array_size); if (array_size > 10 || array_size < 0) { printf("Wrong size!\n"); exit(0); } for (int i = 0; i < array_size; i++, printf("%d: ", i - 1), readName(&group->runners[i - 1], "Give the name for the runnner? ")); for (int i = 0; i < array_size; i++, printf("%d: ", i), readTime(&group->runners[i - 1], "Give the time for the runner: ")); return array_size; }
void HomeScreen::displayDateTime() { #if DBG Serial.print("HomeScreen::displayDateTime: "); Serial.println(tNow); #endif int hours=0, minutes=0, seconds=0; readTime(hours, minutes, seconds); displayTime(hours, minutes, seconds); }
TimeClient::TimeClient(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("多线程时间服务客户端")); serverNameLabel =new QLabel(tr("服务器名:")); serverNameLineEdit = new QLineEdit("Localhost"); portLabel =new QLabel(tr("端口:")); portLineEdit = new QLineEdit; QGridLayout *layout = new QGridLayout; layout->addWidget(serverNameLabel,0,0); layout->addWidget(serverNameLineEdit,0,1); layout->addWidget(portLabel,1,0); layout->addWidget(portLineEdit,1,1); dateTimeEdit = new QDateTimeEdit(this); QHBoxLayout *layout1 = new QHBoxLayout; layout1->addWidget(dateTimeEdit); stateLabel =new QLabel(tr("请首先运行时间服务器!")); QHBoxLayout *layout2 = new QHBoxLayout; layout2->addWidget(stateLabel); getBtn = new QPushButton(tr("获取时间")); getBtn->setDefault(true); getBtn->setEnabled(false); quitBtn = new QPushButton(tr("退出")); QHBoxLayout *layout3 = new QHBoxLayout; layout3->addStretch(); layout3->addWidget(getBtn); layout3->addWidget(quitBtn); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addLayout(layout); mainLayout->addLayout(layout1); mainLayout->addLayout(layout2); mainLayout->addLayout(layout3); connect(serverNameLineEdit,SIGNAL(textChanged(QString)),this,SLOT(enableGetBtn())); connect(portLineEdit,SIGNAL(textChanged(QString)),this,SLOT(enableGetBtn())); connect(getBtn,SIGNAL(clicked()),this,SLOT(getTime())); connect(quitBtn,SIGNAL(clicked()),this,SLOT(close())); tcpSocket = new QTcpSocket(this); connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(readTime())); connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(showError(QAbstractSocket::SocketError))); portLineEdit->setFocus(); }
void stretchFromTo(FILE* pfin, FILE* pfout, double interval, char sep ){ struct tm target, current; int sep_cnt, line_itr; char line[STR_SIZE]; cnt=0; //Catch useless first lines for (line_itr=2; line_itr; line_itr--) { fgets(line,STR_SIZE,pfin); fprintf(pfout,"%s",line); } //set first values sep_cnt=limiter_cnt(line,sep); printf("Number of limiters: %d\n", sep_cnt); readTime(&target,line); target.tm_sec+=interval; while(fgets(line,STR_SIZE,pfin)) { for (readTime(¤t,line);difftime(mktime(¤t),mktime(&target))>0; target.tm_sec+=interval) enterTime(&target,pfout,sep,sep_cnt); current.tm_sec+=interval; target=current; fprintf(pfout,"%s",line); } printf("Added %d paddings.\ndone\n", cnt); }
void TestCaseSandboxResultDecoderImpl:: handleEndCase() { if( endReceived || !startReceived || crashInformed) { throw Error(TESTNGPP_INTERNAL_ERROR(1005)); } endTime = readTime(); endReceived = true; }
void ODMatrix::readO(LineReader& lr, double scale, std::string vehType, bool matrixHasVehType) { PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR"); // parse first defs std::string line; if (matrixHasVehType) { line = getNextNonCommentLine(lr); int type = TplConvert::_2int(StringUtils::prune(line).c_str()); if (vehType == "") { vehType = toString(type); } } // parse time std::pair<SUMOTime, SUMOTime> times = readTime(lr); SUMOTime begin = times.first; SUMOTime end = times.second; // factor double factor = readFactor(lr, scale); // parse the cells while (lr.hasMore()) { line = getNextNonCommentLine(lr); if (line.length() == 0) { continue; } StringTokenizer st2(line, StringTokenizer::WHITECHARS); if (st2.size() == 0) { continue; } try { std::string sourceD = st2.next(); std::string destD = st2.next(); double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor; if (vehNumber != 0) { add(vehNumber, begin, end, sourceD, destD, vehType); } } catch (OutOfBoundsException&) { throw ProcessError("Missing at least one information in line '" + line + "'."); } catch (NumberFormatException&) { throw ProcessError("Not numeric vehicle number in line '" + line + "'."); } } PROGRESS_DONE_MESSAGE(); }
long long int hokuyo::Laser::getHokuyoClockOffset(int reps, int timeout) { std::vector<long long int> offset(reps); sendCmd("TM0",timeout); for (int i = 0; i < reps; i++) { long long int prestamp = timeHelper(); sendCmd("TM1",timeout); long long int hokuyostamp = readTime(); long long int poststamp = timeHelper(); offset[i] = hokuyostamp - (prestamp + poststamp) / 2; //printf("%lli %lli %lli", hokuyostamp, prestamp, poststamp); } sendCmd("TM2",timeout); long long out = median(offset); return out; }
void SuperTimeTick::run() { readTime(); while(!isFinal()) { zThread::sleep(1); currentTime.now(); Zebra::qwGameTime = qwStartGameTime + startTime.elapse(currentTime) / 1000; if (0 != Zebra::qwGameTime && 0 == Zebra::qwGameTime % 600) { saveTime(); } Cmd::Super::t_GameTime tCmd; tCmd.qwGameTime = Zebra::qwGameTime; ServerManager::getInstance().broadcast(&tCmd,sizeof(tCmd)); } saveTime(); }
int main(void) { int i; char buff1[3]; char buff2[3]; initDisplay(); initSomGenerator(); initTimer0(); initRC5(); resetTimer0(); initRTC(); initRIT(); setPriorities(); int lastAlarmToggle = 0; char alarmBit; ////////////////////////////////// char* test = generateSom(); char som[10]; strcpy(som, test); free(test); ////////////////////////////////// // char arr[3]; // readRAM(arr, 0x08); // delay(500); // alarmBit = arr[2]; // clear(); int arr2[3]; //int arr[3] = {0x00, 0x24, 0x12}; //setTime(arr); readTime(arr2, 0x00); if(arr2[2] < 10){ sprintf(buff1, "0%d", arr2[2]); } else { sprintf(buff1, "%d", arr2[2]); } if(arr2[1] < 10){ sprintf(buff2, "0%d", arr2[1]); } else { sprintf(buff2, "%d", arr2[1]); } //Set the last known values in RIT.c lastValues[0] = arr2[0]; lastValues[1] = arr2[1]; lastValues[2] = arr2[2]; sprintf(output, "%s:%s", buff1, buff2); // printf("%d\n", arr2[0]); // printf("%d\n", arr2[1]); // printf("%d\n", arr2[2]); //Main loop while (1) { while (!isTimeForAlarm(alarmBit) && (getCommand(commandCount - 1) != 15 && getCommand(commandCount - 1) != 11)) { //This is the main loop, all we do here is print the current time to the display since the current time is updated through the RIT and the EINT takes care of the remote control //Prints the current time printToDisplay(output); } if (getCommand(commandCount - 1) == 15) { //Goes into the set alarm state addAlarmState(); } if (getCommand(commandCount - 1) == 11 && commandCount != lastAlarmToggle) { // '11' needs to be replaced with an other number, because it's an temporary button //Toggle alar state alarmBit = !alarmBit; toggleAlarmState(alarmBit); lastAlarmToggle = commandCount; //Give the user some feedback(Tell them wether they set or unset the alarm) for(i=0; i<200; i++){ asm("nop"); if(alarmBit == 1){ printToDisplay(" + "); } else { printToDisplay(" - "); } } } if (isTimeForAlarm(alarmBit)) { //Goes into the alarm state alarmState(); resetAlarmTime(); } printToDisplay(output); } return 0; }
void RIT_IRQHandler(){ char tmp[5]; char buff1[3]; char buff2[3]; char lvbuff1[3]; char lvbuff2[3]; delay(20); readTime(array); // delay(20); //Make the values from the array into 0 formatted strings buff2[0] = (array[2] / 10) + '0'; buff2[1] = (array[2] % 10) + '0'; buff2[2] = '\0'; buff1[0] = (array[1] / 10) + '0'; buff1[1] = (array[1] % 10) + '0'; buff1[2] = '\0'; lvbuff2[0] = (lastValues[2] / 10) + '0'; lvbuff2[1] = (lastValues[2] % 10) + '0'; lvbuff2[2] = '\0'; lvbuff1[0] = (lastValues[1] / 10) + '0'; lvbuff1[1] = (lastValues[1] % 10) + '0'; lvbuff1[2] = '\0'; //Pretty much validates what was read from the RTC to be reasonable values if((array[2] == lastValues[2] + 1 ) || array[2] == 0){ if((array[1] == lastValues[1] + 1) || array[1] == 0){ strcpy(tmp, buff2); strcat(tmp, ":"); strcat(tmp, buff1); lastValues[1] = array[1]; lastValues[2] = array[2]; } else { //Was 1, 1 (Wrong?) strcpy(tmp, buff2); strcat(tmp, ":"); strcat(tmp, lvbuff1); lastValues[2] = array[2]; } } else { if((array[1] == lastValues[1] + 1) || array[1] == 0){ strcpy(tmp, lvbuff2); strcat(tmp, ":"); strcat(tmp, buff1); lastValues[1] = array[1]; } else { strcpy(tmp, lvbuff2); strcat(tmp, ":"); strcat(tmp, lvbuff1); } } lastValues[0] = array[0]; setOutput(tmp); RICONTROL |= 0x1; }
long long hokuyo::Laser::calcLatency(bool intensity, double min_ang, double max_ang, int clustering, int skip, int num, int timeout) { ROS_DEBUG("Entering calcLatency."); if (!portOpen()) HOKUYO_EXCEPT(hokuyo::Exception, "Port not open."); static const std::string buggy_version = "1.16.02(19/Jan./2010)"; if (firmware_version_ == buggy_version) { ROS_INFO("Hokuyo firmware version %s detected. Using hard-coded time offset of -23 ms.", buggy_version.c_str()); offset_ = -23000000; } else { offset_ = 0; uint64_t comp_time = 0; uint64_t laser_time = 0; long long diff_time = 0; long long drift_time = 0; long long tmp_offset1 = 0; long long tmp_offset2 = 0; int count = 0; sendCmd("TM0",timeout); count = 100; for (int i = 0; i < count;i++) { usleep(1000); sendCmd("TM1",timeout); comp_time = timeHelper(); try { laser_time = readTime(); diff_time = comp_time - laser_time; tmp_offset1 += diff_time / count; } catch (hokuyo::RepeatedTimeException &e) { // We expect to get Repeated Time's when hammering on the time server continue; } } uint64_t start_time = timeHelper(); usleep(5000000); sendCmd("TM1;a",timeout); sendCmd("TM1;b",timeout); comp_time = timeHelper(); drift_time = comp_time - start_time; laser_time = readTime() + tmp_offset1; diff_time = comp_time - laser_time; double drift_rate = double(diff_time) / double(drift_time); sendCmd("TM2",timeout); if (requestScans(intensity, min_ang, max_ang, clustering, skip, num, timeout) != 0) HOKUYO_EXCEPT(hokuyo::Exception, "Error requesting scans during latency calculation"); hokuyo::LaserScan scan; count = 200; for (int i = 0; i < count;i++) { try { serviceScan(scan, 1000); } catch (hokuyo::CorruptedDataException &e) { continue; } comp_time = scan.system_time_stamp; drift_time = comp_time - start_time; laser_time = scan.self_time_stamp + tmp_offset1 + (long long)(drift_time*drift_rate); diff_time = laser_time - comp_time; tmp_offset2 += diff_time / count; } offset_ = tmp_offset2; stopScanning(); } ROS_DEBUG("Leaving calcLatency."); return offset_; }
void hokuyo::Laser::readData(hokuyo::LaserScan& scan, bool has_intensity, int timeout) { scan.ranges.clear(); scan.intensities.clear(); int data_size = 3; if (has_intensity) data_size = 6; char buf[100]; int ind = 0; scan.self_time_stamp = readTime(timeout); //printf("readData 1\n"); int bytes; int range; float intensity; for (;;) { bytes = laserReadline(&buf[ind], 100 - ind, timeout); if (bytes == 1) // This is \n\n so we should be done return; //printf("readData: %s", buf+ind); if (!checkSum(&buf[ind], bytes)) { //printf("Checksum error!\n"); HOKUYO_EXCEPT(hokuyo::CorruptedDataException, "Checksum failed on data read."); } bytes += ind - 2; // Read as many ranges as we can get if(dmax_ > 20){ // Check error codes for the UTM 30LX (it is the only one with the long max range and has different error codes) for (int j = 0; j < bytes - (bytes % data_size); j+=data_size) { if (scan.ranges.size() < MAX_READINGS) { range = (((buf[j]-0x30) << 12) | ((buf[j+1]-0x30) << 6) | (buf[j+2]-0x30)); switch (range) // See the SCIP2.0 reference on page 12, Table 4 { case 1: // No Object in Range scan.ranges.push_back(std::numeric_limits<float>::infinity()); break; case 2: // Object is too near (Internal Error) scan.ranges.push_back(-std::numeric_limits<float>::infinity()); break; case 3: // Measurement Error (May be due to interference) scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 4: // Object out of range (at the near end) ///< @todo, Should this be an Infinity Instead? scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 5: // Other errors scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; default: scan.ranges.push_back(((float)range)/1000.0); } if (has_intensity) { intensity = (((buf[j+3]-0x30) << 12) | ((buf[j+4]-0x30) << 6) | (buf[j+5]-0x30)); scan.intensities.push_back(intensity); } } else { HOKUYO_EXCEPT(hokuyo::CorruptedDataException, "Got more readings than expected"); } } } else { // Check error codes for all other lasers (URG-04LX UBG-04LX-F01 UHG-08LX) for (int j = 0; j < bytes - (bytes % data_size); j+=data_size) { if (scan.ranges.size() < MAX_READINGS) { range = (((buf[j]-0x30) << 12) | ((buf[j+1]-0x30) << 6) | (buf[j+2]-0x30)); switch (range) // See the SCIP2.0 reference on page 12, Table 3 { case 0: // Detected object is possibly at 22m scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 1: // Reflected light has low intensity scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 2: // Reflected light has low intensity scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 6: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 7: // Distance data on the preceding and succeeding steps have errors scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 8: // Intensity difference of two waves scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 9: // The same step had error in the last two scan scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 10: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 11: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 12: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 13: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 14: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 15: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 16: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 17: // Others scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 18: // Error reading due to strong reflective object scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; case 19: // Non-Measurable step scan.ranges.push_back(std::numeric_limits<float>::quiet_NaN()); break; default: scan.ranges.push_back(((float)range)/1000.0); } if (has_intensity) { intensity = (((buf[j+3]-0x30) << 12) | ((buf[j+4]-0x30) << 6) | (buf[j+5]-0x30)); scan.intensities.push_back(intensity); } } else { HOKUYO_EXCEPT(hokuyo::CorruptedDataException, "Got more readings than expected"); } } } // Shuffle remaining bytes to front of buffer to get them on the next loop ind = 0; for (int j = bytes - (bytes % data_size); j < bytes ; j++) buf[ind++] = buf[j]; } }
QTime KLocale::readTime(const QString &intstr, KLocale::ReadTimeFlags flags, bool *ok) const { return d->readTime(intstr, flags, ok); }
QTime KLocale::readTime(const QString &intstr, bool *ok) const { return d->readTime(intstr, ok); }
string psoCat::odbcFieldToStr( uint32_t length ) { psoFieldDefinition * fieldODBC; int numFields, i; string outStr; fieldODBC = (psoFieldDefinition *) fieldDef; numFields = fieldDefLength / sizeof(psoFieldDefinition); psoaGetFieldOffsets( fieldODBC, numFields, fieldOffsets ); for ( i = 0; i < numFields; ++i ) { string s; switch( fieldODBC[i].type ) { case PSO_TINYINT: s = readInt8( &buffer[fieldOffsets[i]] ); break; case PSO_SMALLINT: s = readInt16( &buffer[fieldOffsets[i]] ); break; case PSO_INTEGER: s = readInt32( &buffer[fieldOffsets[i]] ); break; case PSO_BIGINT: s = readInt64( &buffer[fieldOffsets[i]] ); break; case PSO_BINARY: readBinary( s, fieldODBC[i].vals.length, &buffer[fieldOffsets[i]] ); break; case PSO_CHAR: readString( s, fieldODBC[i].vals.length, &buffer[fieldOffsets[i]] ); break; case PSO_NUMERIC: s = readDecimal( fieldODBC[i].vals.decimal.precision, fieldODBC[i].vals.decimal.scale, &buffer[fieldOffsets[i]] ); break; case PSO_VARCHAR: case PSO_LONGVARCHAR: readString( s, length - fieldOffsets[i], &buffer[fieldOffsets[i]] ); break; case PSO_VARBINARY: case PSO_LONGVARBINARY: readBinary( s, length - fieldOffsets[i], &buffer[fieldOffsets[i]] ); break; case PSO_REAL: s = readFloat32( &buffer[fieldOffsets[i]] ); break; case PSO_DOUBLE: s = readFloat64( &buffer[fieldOffsets[i]] ); break; case PSO_DATE: s = readDate( &buffer[fieldOffsets[i]] ); break; case PSO_TIME: s = readTime( &buffer[fieldOffsets[i]] ); break; case PSO_TIMESTAMP: s = readTimeStamp( &buffer[fieldOffsets[i]] ); break; } outStr += s; if ( i < numFields-1) outStr += ", "; } return outStr; }
string psoCat::odbcKeyToStr( uint32_t length ) { psoKeyFieldDefinition * keyODBC; int numKeys, i; string outStr; keyODBC = (psoKeyFieldDefinition *) keyDef; numKeys = keyDefLength / sizeof(psoKeyFieldDefinition); psoaGetKeyOffsets( keyODBC, numKeys, keyOffsets ); for ( i = 0; i < numKeys; ++i ) { string s; switch( keyODBC[i].type ) { case PSO_KEY_INTEGER: s = readInt32( &key[keyOffsets[i]] ); break; case PSO_KEY_BIGINT: s = readInt64( &key[keyOffsets[i]] ); break; case PSO_KEY_BINARY: readBinary( s, keyODBC[i].length, &key[keyOffsets[i]] ); break; case PSO_KEY_CHAR: readString( s, keyODBC[i].length, &key[keyOffsets[i]] ); break; case PSO_KEY_VARCHAR: case PSO_KEY_LONGVARCHAR: readString( s, length - keyOffsets[i], &key[keyOffsets[i]] ); break; case PSO_KEY_VARBINARY: case PSO_KEY_LONGVARBINARY: readBinary( s, length - keyOffsets[i], &key[keyOffsets[i]] ); break; case PSO_KEY_DATE: s = readDate( &key[keyOffsets[i]] ); break; case PSO_KEY_TIME: s = readTime( &key[keyOffsets[i]] ); break; case PSO_KEY_TIMESTAMP: s = readTimeStamp( &key[keyOffsets[i]] ); break; } outStr += s; if ( i < numKeys-1) outStr += ", "; } return outStr; }
void bi::InputNetCDFBuffer::map() { int ncDim, ncVar; Var* var; std::string name; VarType type; int i, k, id; /* ns dimension */ nsDim = nc_inq_dimid(ncid, "ns"); if (nsDim >= 0) { BI_ERROR_MSG(ns < (int )nc_inq_dimlen(ncid, nsDim), "Given index " << ns << " outside range of ns dimension"); } /* np dimension */ npDim = nc_inq_dimid(ncid, "np"); if (npDim >= 0) { BI_ERROR_MSG(np < 0 || np < (int )nc_inq_dimlen(ncid, npDim), "Given index " << np << " outside range of np dimension"); } /* record dimensions, time and coordinate variables */ int nvars = nc_inq_nvars(ncid); for (i = 0; i < nvars; ++i) { ncVar = i; name = nc_inq_varname(ncid, i); if (name.find("time") == 0) { /* is a time variable */ ncDim = mapTimeDim(ncVar); if (ncDim >= 0) { BOOST_AUTO(iter, std::find(recDims.begin(), recDims.end(), ncDim)); if (iter == recDims.end()) { /* newly encountered record dimension */ recDims.push_back(ncDim); timeVars.push_back(ncVar); coordVars.push_back(-1); } else { /* record dimension encountered before */ k = std::distance(recDims.begin(), iter); BI_ASSERT_MSG(timeVars[k] < 0, "Time variables " << nc_inq_varname(ncid, timeVars[k]) << " and " << name << " cannot share the same record dimension " << nc_inq_dimname(ncid, *iter)); timeVars[k] = ncVar; } } } else if (name.find("coord") == 0) { /* is a coordinate variable */ ncDim = mapCoordDim(ncVar); if (ncDim >= 0) { BOOST_AUTO(iter, std::find(recDims.begin(), recDims.end(), ncDim)); if (iter == recDims.end()) { /* newly encountered record dimension */ recDims.push_back(ncDim); timeVars.push_back(-1); coordVars.push_back(ncVar); } else { /* record dimension encountered before */ k = std::distance(recDims.begin(), iter); BI_ASSERT_MSG(coordVars[k] < 0, "Coordinate variables " << nc_inq_varname(ncid, coordVars[k]) << " and " << name << " cannot share the same record dimension " << nc_inq_dimname(ncid, *iter)); coordVars[k] = ncVar; } } } } /* model variables */ for (i = 0; i < NUM_VAR_TYPES; ++i) { type = static_cast<VarType>(i); /* initialise NetCDF variables for this type */ vars[type].resize(m.getNumVars(type), -1); /* map model variables */ for (id = 0; id < m.getNumVars(type); ++id) { var = m.getVar(type, id); if (var->hasInput()) { BOOST_AUTO(pair, mapVarDim(var)); k = pair.first; ncVar = pair.second; if (ncVar >= 0) { vars[type][id] = ncVar; } modelVars.insert(std::make_pair(k, var)); } } } /* preload random access tables */ std::multimap<real,int> seq; std::vector<size_t> starts(recDims.size(), 0), lens(recDims.size(), 0); real tnxt; for (k = 0; k < int(recDims.size()); ++k) { if (timeVars[k] >= 0 && modelVars.count(k) > 0) { /* ^ ignores record dimensions with no associated time or model * variables */ readTime(timeVars[k], starts[k], &lens[k], &tnxt); seq.insert(std::make_pair(tnxt, k)); } } while (!seq.empty()) { /* next in time */ tnxt = seq.begin()->first; k = seq.begin()->second; seq.erase(seq.begin()); ncDim = recDims[k]; ncVar = timeVars[k]; if (times.empty() || times.back() != tnxt) { times.push_back(tnxt); recStarts.push_back(std::vector < size_t > (recDims.size(), 0)); recLens.push_back(std::vector < size_t > (recDims.size(), 0)); } recStarts.back()[k] = starts[k]; recLens.back()[k] = lens[k]; /* read next time and range for this time variable */ starts[k] += lens[k]; if (starts[k] < nc_inq_dimlen(ncid, ncDim)) { /* more to come on this record dimension */ readTime(ncVar, starts[k], &lens[k], &tnxt); seq.insert(std::make_pair(tnxt, k)); } } }
void PluginDatabase::loadPersistentMetadataCache() { if (!isPersistentMetadataCacheEnabled() || persistentMetadataCachePath().isEmpty()) return; PlatformFileHandle file; String absoluteCachePath = pathByAppendingComponent(persistentMetadataCachePath(), persistentPluginMetadataCacheFilename); file = openFile(absoluteCachePath, OpenForRead); if (!isHandleValid(file)) return; // Mark cache as loaded regardless of success or failure. If // there's error in the cache, we won't try to load it anymore. m_persistentMetadataCacheIsLoaded = true; Vector<char> fileContents; fillBufferWithContentsOfFile(file, fileContents); closeFile(file); if (fileContents.size() < 2 || fileContents.first() != schemaVersion || fileContents.last() != '\0') { LOG_ERROR("Unable to read plugin metadata cache: corrupt schema"); deleteFile(absoluteCachePath); return; } char* bufferPos = fileContents.data() + 1; char* end = fileContents.data() + fileContents.size(); PluginSet cachedPlugins; HashMap<String, time_t> cachedPluginPathsWithTimes; HashMap<String, RefPtr<PluginPackage> > cachedPluginsByPath; while (bufferPos < end) { String path; time_t lastModified; String name; String desc; String mimeDesc; if (!(readUTF8String(path, bufferPos, end) && readTime(lastModified, bufferPos, end) && readUTF8String(name, bufferPos, end) && readUTF8String(desc, bufferPos, end) && readUTF8String(mimeDesc, bufferPos, end))) { LOG_ERROR("Unable to read plugin metadata cache: corrupt data"); deleteFile(absoluteCachePath); return; } // Skip metadata that points to plugins from directories that // are not part of plugin directory list anymore. String pluginDirectoryName = directoryName(path); if (m_pluginDirectories.find(pluginDirectoryName) == WTF::notFound) continue; RefPtr<PluginPackage> package = PluginPackage::createPackageFromCache(path, lastModified, name, desc, mimeDesc); if (package && cachedPlugins.add(package).isNewEntry) { cachedPluginPathsWithTimes.add(package->path(), package->lastModified()); cachedPluginsByPath.add(package->path(), package); } } m_plugins.swap(cachedPlugins); m_pluginsByPath.swap(cachedPluginsByPath); m_pluginPathsWithTimes.swap(cachedPluginPathsWithTimes); }
bool TARIFF_HELPER::SetTariffInfo(const xmlrpc_c::value & info) { std::map<std::string, xmlrpc_c::value> structVal( static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info)) ); std::map<std::string, xmlrpc_c::value>::iterator it; if ((it = structVal.find("fee")) != structVal.end()) { data.tariffConf.fee = xmlrpc_c::value_double(it->second); } if ((it = structVal.find("freemb")) != structVal.end()) { data.tariffConf.free = xmlrpc_c::value_double(it->second); } if ((it = structVal.find("passivecost")) != structVal.end()) { data.tariffConf.passiveCost = xmlrpc_c::value_double(it->second); } if ((it = structVal.find("traffType")) != structVal.end()) { data.tariffConf.traffType = static_cast<TARIFF::TRAFF_TYPE>(xmlrpc_c::value_int(it->second).cvalue()); } if ((it = structVal.find("period")) != structVal.end()) { data.tariffConf.period = TARIFF::StringToPeriod(xmlrpc_c::value_string(it->second)); } if ((it = structVal.find("changePolicy")) != structVal.end()) { data.tariffConf.changePolicy = TARIFF::StringToChangePolicy(xmlrpc_c::value_string(it->second)); } if ((it = structVal.find("changePolicyTimeout")) != structVal.end()) { data.tariffConf.changePolicyTimeout = readTime(xmlrpc_c::value_string(it->second)); } if ((it = structVal.find("dirprices")) != structVal.end()) { std::vector<xmlrpc_c::value> prices( xmlrpc_c::value_array(it->second).vectorValueValue() ); for (unsigned i = 0; i < DIR_NUM; ++i) { std::map<std::string, xmlrpc_c::value> dirPrice( static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(prices[i])) ); data.dirPrice[i].mDay = xmlrpc_c::value_int(dirPrice["mday"]); data.dirPrice[i].hDay = xmlrpc_c::value_int(dirPrice["hday"]); data.dirPrice[i].mNight = xmlrpc_c::value_int(dirPrice["mnight"]); data.dirPrice[i].hNight = xmlrpc_c::value_int(dirPrice["hnight"]); data.dirPrice[i].priceDayA = xmlrpc_c::value_double(dirPrice["pricedaya"]) / 1024 / 1024; data.dirPrice[i].priceDayB = xmlrpc_c::value_double(dirPrice["pricedayb"]) / 1024 / 1024; data.dirPrice[i].priceNightA = xmlrpc_c::value_double(dirPrice["pricenighta"]) / 1024 / 1024; data.dirPrice[i].priceNightB = xmlrpc_c::value_double(dirPrice["pricenightb"]) / 1024 / 1024; data.dirPrice[i].threshold = xmlrpc_c::value_int(dirPrice["threshold"]); data.dirPrice[i].singlePrice = xmlrpc_c::value_boolean(dirPrice["singleprice"]); data.dirPrice[i].noDiscount = xmlrpc_c::value_boolean(dirPrice["nodiscount"]); } } return false; }
void ODMatrix::readV(LineReader& lr, double scale, std::string vehType, bool matrixHasVehType) { PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR"); // parse first defs std::string line; if (matrixHasVehType) { line = getNextNonCommentLine(lr); if (vehType == "") { vehType = StringUtils::prune(line); } } // parse time std::pair<SUMOTime, SUMOTime> times = readTime(lr); SUMOTime begin = times.first; SUMOTime end = times.second; // factor double factor = readFactor(lr, scale); // districts line = getNextNonCommentLine(lr); const int numDistricts = TplConvert::_2int(StringUtils::prune(line).c_str()); // parse district names (normally ints) std::vector<std::string> names; while ((int)names.size() != numDistricts) { line = getNextNonCommentLine(lr); StringTokenizer st2(line, StringTokenizer::WHITECHARS); while (st2.hasNext()) { names.push_back(st2.next()); } } // parse the cells for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) { std::vector<std::string>::iterator di = names.begin(); // do { line = getNextNonCommentLine(lr); if (line.length() == 0) { continue; } try { StringTokenizer st2(line, StringTokenizer::WHITECHARS); while (st2.hasNext()) { assert(di != names.end()); double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor; if (vehNumber != 0) { add(vehNumber, begin, end, *si, *di, vehType); } if (di == names.end()) { throw ProcessError("More entries than districts found."); } ++di; } } catch (NumberFormatException&) { throw ProcessError("Not numeric vehicle number in line '" + line + "'."); } if (!lr.hasMore()) { break; } } while (di != names.end()); } PROGRESS_DONE_MESSAGE(); }