static void runChprintfTest() { static MemoryStream ts; static char testBuffer[200]; msObjectInit(&ts, (uint8_t *) testBuffer, sizeof(testBuffer), 0); // it's a very, very long and mostly forgotten story how this became our %.2f precision format ts.eos = 0; // reset chprintf((BaseSequentialStream*)&ts, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234); ts.buffer[ts.eos] = 0; assertString(testBuffer, "0.23/239.9320/0.1234"); { LoggingWithStorage testLogging("test"); appendFloat(&testLogging, 1.23, 5); appendFloat(&testLogging, 1.234, 2); assertString(testLogging.buffer, "1.230001.23"); } { LoggingWithStorage testLogging("test"); appendFloat(&testLogging, -1.23, 5); assertString(testLogging.buffer, "-1.23000"); } { LoggingWithStorage testLogging("test"); appendPrintf(&testLogging, "a%.2fb%fc", -1.2, -3.4); assertString(testLogging.buffer, "a-1.20b-3.400000095c"); } }
void SVGPathStringBuilder::emitSegment(const PathSegmentData& segment) { ASSERT(segment.command > PathSegUnknown && segment.command <= PathSegCurveToQuadraticSmoothRel); m_stringBuilder.append(pathSegmentCharacter[segment.command]); switch (segment.command) { case PathSegMoveToRel: case PathSegMoveToAbs: case PathSegLineToRel: case PathSegLineToAbs: case PathSegCurveToQuadraticSmoothRel: case PathSegCurveToQuadraticSmoothAbs: appendPoint(m_stringBuilder, segment.targetPoint); break; case PathSegLineToHorizontalRel: case PathSegLineToHorizontalAbs: appendFloat(m_stringBuilder, segment.targetPoint.x()); break; case PathSegLineToVerticalRel: case PathSegLineToVerticalAbs: appendFloat(m_stringBuilder, segment.targetPoint.y()); break; case PathSegClosePath: break; case PathSegCurveToCubicRel: case PathSegCurveToCubicAbs: appendPoint(m_stringBuilder, segment.point1); appendPoint(m_stringBuilder, segment.point2); appendPoint(m_stringBuilder, segment.targetPoint); break; case PathSegCurveToCubicSmoothRel: case PathSegCurveToCubicSmoothAbs: appendPoint(m_stringBuilder, segment.point2); appendPoint(m_stringBuilder, segment.targetPoint); break; case PathSegCurveToQuadraticRel: case PathSegCurveToQuadraticAbs: appendPoint(m_stringBuilder, segment.point1); appendPoint(m_stringBuilder, segment.targetPoint); break; case PathSegArcRel: case PathSegArcAbs: appendPoint(m_stringBuilder, segment.point1); appendFloat(m_stringBuilder, segment.point2.x()); appendBool(m_stringBuilder, segment.arcLarge); appendBool(m_stringBuilder, segment.arcSweep); appendPoint(m_stringBuilder, segment.targetPoint); break; default: ASSERT_NOT_REACHED(); } m_stringBuilder.append(' '); }
void debugFloat(Logging *logging, const char *caption, float value, int precision) { append(logging, caption); append(logging, DELIMETER); appendFloat(logging, value, precision); append(logging, DELIMETER); }
static void reportWave(Logging *logging, int index) { if (readers[index].hw == NULL) { return; } if (readers[index].hw->started) { // int counter = getEventCounter(index); // debugInt2(logging, "ev", index, counter); float dwellMs = getSignalOnTime(index); float periodMs = getSignalPeriodMs(index); appendPrintf(logging, "duty%d%s", index, DELIMETER); appendFloat(logging, 100.0f * dwellMs / periodMs, 2); appendPrintf(logging, "%s", DELIMETER); /** * that's the ON time of the LAST signal */ appendPrintf(logging, "dwell%d%s", index, DELIMETER); appendFloat(logging, dwellMs, 2); appendPrintf(logging, "%s", DELIMETER); /** * that's the total ON time during the previous engine cycle */ appendPrintf(logging, "total_dwell%d%s", index, DELIMETER); appendFloat(logging, readers[index].prevTotalOnTimeUs / 1000.0f, 2); appendPrintf(logging, "%s", DELIMETER); appendPrintf(logging, "period%d%s", index, DELIMETER); appendFloat(logging, periodMs, 2); appendPrintf(logging, "%s", DELIMETER); uint32_t offsetUs = getWaveOffset(index); int rpm = GET_RPM(); if (rpm != 0) { float oneDegreeUs = getOneDegreeTimeUs(rpm); appendPrintf(logging, "advance%d%s", index, DELIMETER); float angle = (offsetUs / oneDegreeUs) - tdcPosition(); fixAngle(angle, "waveAn", CUSTOM_ERR_6564); appendFloat(logging, angle, 3); appendPrintf(logging, "%s", DELIMETER); } } }
static void reportWave(Logging *logging, int index) { if (readers[index].hw.started) { // int counter = getEventCounter(index); // debugInt2(logging, "ev", index, counter); float dwellMs = getSignalOnTime(index); float periodMs = getSignalPeriodMs(index); appendPrintf(logging, "duty%d%s", index, DELIMETER); appendFloat(logging, 100.0f * dwellMs / periodMs, 2); appendPrintf(logging, "%s", DELIMETER); /** * that's the ON time of the LAST signal */ appendPrintf(logging, "dwell%d%s", index, DELIMETER); appendFloat(logging, dwellMs, 2); appendPrintf(logging, "%s", DELIMETER); /** * that's the total ON time during the previous engine cycle */ appendPrintf(logging, "total_dwell%d%s", index, DELIMETER); appendFloat(logging, readers[index].prevTotalOnTimeUs / 1000.0f, 2); appendPrintf(logging, "%s", DELIMETER); appendPrintf(logging, "period%d%s", index, DELIMETER); appendFloat(logging, periodMs, 2); appendPrintf(logging, "%s", DELIMETER); uint32_t offsetUs = getWaveOffset(index); float oneDegreeUs = getOneDegreeTimeUs(getRpm()); appendPrintf(logging, "advance%d%s", index, DELIMETER); appendFloat(logging, fixAngle((offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset), 3); appendPrintf(logging, "%s", DELIMETER); } }
static int write_samples_header(const LoggerMessage *msg) { int i; ChannelSample *sample = msg->channelSamples; size_t channelCount = msg->sampleCount; for (i = 0; 0 < channelCount; channelCount--, sample++, i++) { appendFileBuffer(0 == i ? "" : ","); uint8_t precision = sample->cfg->precision; appendQuotedString(sample->cfg->label); appendFileBuffer("|"); appendQuotedString(sample->cfg->units); appendFileBuffer("|"); appendFloat(decodeSampleRate(sample->cfg->min), precision); appendFileBuffer("|"); appendFloat(decodeSampleRate(sample->cfg->max), precision); appendFileBuffer("|"); appendInt(decodeSampleRate(sample->cfg->sampleRate)); } appendFileBuffer("\n"); return writeFileBuffer(); }
static int write_samples_data(const LoggerMessage *msg) { ChannelSample *sample = msg->channelSamples; size_t channelCount = msg->sampleCount; if (NULL == sample) { pr_warning("Logger: null sample record\r\n"); return WRITE_FAIL; } int i; for (i = 0; 0 < channelCount; channelCount--, sample++, i++) { appendFileBuffer(0 == i ? "" : ","); if (!sample->populated) continue; const int precision = sample->cfg->precision; switch(sample->sampleData) { case SampleData_Float: case SampleData_Float_Noarg: appendFloat(sample->valueFloat, precision); break; case SampleData_Int: case SampleData_Int_Noarg: appendInt(sample->valueInt); break; case SampleData_LongLong: case SampleData_LongLong_Noarg: appendLongLong(sample->valueLongLong); break; case SampleData_Double: case SampleData_Double_Noarg: appendDouble(sample->valueDouble, precision); break; default: pr_warning("file: Unknown channel sample type\n"); } } appendFileBuffer("\n"); return writeFileBuffer(); }
inline void GTMTrackLayer::WriteTrackpoint( double lat, double lon, float altitude, bool start ) { void* pBuffer = CPLMalloc(25); void* pBufferAux = pBuffer; //latitude appendDouble(pBufferAux, lat); pBufferAux = (char*)pBufferAux + 8; //longitude appendDouble(pBufferAux, lon); pBufferAux = (char*)pBufferAux + 8; //date appendInt(pBufferAux, 0); pBufferAux = (char*)pBufferAux + 4; //start appendUChar(pBufferAux, start); pBufferAux = (char*)pBufferAux + 1; //altitude appendFloat(pBufferAux, altitude); VSIFWriteL(pBuffer, 25, 1, poDS->getTmpTrackpointsFP()); poDS->incNumTrackpoints(); CPLFree(pBuffer); }
static void reportSensorF(Logging *log, bool fileFormat, const char *caption, const char *units, float value, int precision) { if (!fileFormat) { #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) debugFloat(log, caption, value, precision); #endif /* EFI_PROD_CODE || EFI_SIMULATOR */ } else { #if EFI_FILE_LOGGING || defined(__DOXYGEN__) if (logFileLineIndex == 0) { append(log, caption); append(log, TAB); } else if (logFileLineIndex == 1) { append(log, units); append(log, TAB); } else { appendFloat(log, value, precision); append(log, TAB); } #endif /* EFI_FILE_LOGGING */ } }
void GTMTrackLayer::WriteFeatureAttributes( OGRFeature *poFeature ) { char* psztrackname = nullptr; int type = 1; unsigned int color = 0; for (int i = 0; i < poFeatureDefn->GetFieldCount(); ++i) { OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( i ); if( poFeature->IsFieldSetAndNotNull( i ) ) { const char* l_pszName = poFieldDefn->GetNameRef(); /* track name */ if (STARTS_WITH(l_pszName, "name")) { CPLFree(psztrackname); psztrackname = CPLStrdup( poFeature->GetFieldAsString( i ) ); } /* track type */ else if (STARTS_WITH(l_pszName, "type")) { type = poFeature->GetFieldAsInteger( i ); // Check if it is a valid type if (type < 1 || type > 30) type = 1; } /* track color */ else if (STARTS_WITH(l_pszName, "color")) { color = (unsigned int) poFeature->GetFieldAsInteger( i ); if (color > 0xFFFFFF) color = 0xFFFFFFF; } } } if (psztrackname == nullptr) psztrackname = CPLStrdup( "" ); const size_t trackNameLength = strlen(psztrackname); const size_t bufferSize = 14 + trackNameLength; void* pBuffer = CPLMalloc(bufferSize); void* pBufferAux = pBuffer; /* Write track string name size to buffer */ appendUShort(pBufferAux, (unsigned short) trackNameLength); pBufferAux = (char*)pBufferAux + 2; /* Write track name */ memcpy((char*)pBufferAux, psztrackname, trackNameLength); pBufferAux = (char*)pBufferAux + trackNameLength; /* Write track type */ appendUChar(pBufferAux, (unsigned char) type); pBufferAux = (char*)pBufferAux + 1; /* Write track color */ appendInt(pBufferAux, color); pBufferAux = (char*)pBufferAux + 4; /* Write track scale */ appendFloat(pBufferAux, 0); pBufferAux = (char*)pBufferAux + 4; /* Write track label */ appendUChar(pBufferAux, 0); pBufferAux = (char*)pBufferAux + 1; /* Write track layer */ appendUShort(pBufferAux, 0); VSIFWriteL(pBuffer, bufferSize, 1, poDS->getTmpTracksFP()); poDS->incNumTracks(); CPLFree(psztrackname); CPLFree(pBuffer); }
void GTMWaypointLayer::WriteFeatureAttributes( OGRFeature *poFeature, float altitude ) { char psNameField[] = " "; // 10 spaces char* pszcomment = nullptr; int icon = 48; int date = 0; for (int i = 0; i < poFeatureDefn->GetFieldCount(); ++i) { OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( i ); if( poFeature->IsFieldSetAndNotNull( i ) ) { const char* l_pszName = poFieldDefn->GetNameRef(); /* Waypoint name */ if (STARTS_WITH(l_pszName, "name")) { strncpy (psNameField, poFeature->GetFieldAsString( i ), 10); CPLStrlcat (psNameField, " ", sizeof(psNameField)); } /* Waypoint comment */ else if (STARTS_WITH(l_pszName, "comment")) { CPLFree(pszcomment); pszcomment = CPLStrdup( poFeature->GetFieldAsString( i ) ); } /* Waypoint icon */ else if (STARTS_WITH(l_pszName, "icon")) { icon = poFeature->GetFieldAsInteger( i ); // Check if it is a valid icon if (icon < 1 || icon > 220) icon = 48; } /* Waypoint date */ else if (EQUAL(l_pszName, "time")) { struct tm brokendowndate; int year, month, day, hour, min, sec, TZFlag; if (poFeature->GetFieldAsDateTime( i, &year, &month, &day, &hour, &min, &sec, &TZFlag)) { brokendowndate.tm_year = year - 1900; brokendowndate.tm_mon = month - 1; brokendowndate.tm_mday = day; brokendowndate.tm_hour = hour; brokendowndate.tm_min = min; brokendowndate.tm_sec = sec; GIntBig unixTime = CPLYMDHMSToUnixTime(&brokendowndate); if (TZFlag != 0) unixTime -= (TZFlag - 100) * 15; if (unixTime <= GTM_EPOCH || (unixTime - GTM_EPOCH) != (int)(unixTime - GTM_EPOCH)) { CPLError(CE_Warning, CPLE_AppDefined, "%04d/%02d/%02d %02d:%02d:%02d is not a valid datetime for GTM", year, month, day, hour, min, sec); } else { date = (int)(unixTime - GTM_EPOCH); } } } } } if (pszcomment == nullptr) pszcomment = CPLStrdup( "" ); const size_t commentLength = strlen(pszcomment); const size_t bufferSize = 27 + commentLength; void* pBuffer = CPLMalloc(bufferSize); void* pBufferAux = pBuffer; /* Write waypoint name to buffer */ memcpy((char*)pBufferAux, psNameField, 10); /* Write waypoint string comment size to buffer */ pBufferAux = (char*)pBuffer+10; appendUShort(pBufferAux, (unsigned short) commentLength); /* Write waypoint string comment to buffer */ memcpy((char*)pBuffer+12, pszcomment, commentLength); /* Write icon to buffer */ pBufferAux = (char*)pBuffer+12+commentLength; appendUShort(pBufferAux, (unsigned short) icon); /* Write dslp to buffer */ pBufferAux = (char*)pBufferAux + 2; appendUChar(pBufferAux, 3); /* Date */ pBufferAux = (char*)pBufferAux + 1; appendInt(pBufferAux, date); /* wrot */ pBufferAux = (char*)pBufferAux + 4; appendUShort(pBufferAux, 0); /* walt */ pBufferAux = (char*)pBufferAux + 2; appendFloat(pBufferAux, altitude); /* wlayer */ pBufferAux = (char*)pBufferAux + 4; appendUShort(pBufferAux, 0); VSIFWriteL(pBuffer, bufferSize, 1, poDS->getOutputFP()); poDS->incNumWaypoints(); CPLFree(pszcomment); CPLFree(pBuffer); }
void sdOSCMessage::appendFloats(float *floats, int number){ for (int i = 0; i < number; i++){ appendFloat(floats[i]); } }
static void appendPoint(StringBuilder& stringBuilder, const FloatPoint& point) { appendFloat(stringBuilder, point.x()); appendFloat(stringBuilder, point.y()); }