int main () { /* Try to open Raw Data file at place defined by 'FILE_NAME' */ if ( NULL == (fp = fopen (FILE_NAME, "r") ) ) { printf("[%s] %s: can't open file <%s> \n", __FILE__, __func__ , FILE_NAME); return P_ERROR; } printf("[%s] %s: loading USB-curve-data via NFS from file <%s>\n", __FILE__, __func__, FILE_NAME); /* For each string of Raw Data file */ while ( ! (feof (fp) ) ) { /* Try to scan a whole string into temp. buffer */ if (0 > fscanf (fp, "%s", cBuf ) ) { // eof reached } else { /* Aux. buffer to keep results of parsing */ char * cpTmp = cBuf; #if DEBUG_DATA printf("[%s] %s: scanned: < %s >\n", __FILE__, __func__, cBuf); #endif /* (DEBUG_DATA) */ #if !defined(QUASIFLOAT) /* Set default values. MISRA RULE #TODO */ fltTM = fltDIn = fltDOut = 0.0f; #else /* Set default values. MISRA RULE #TODO */ memset (&qfltTM, 0, sizeof (QuasiFloatType) ) ; memset (&qfltDIn, 0, sizeof (QuasiFloatType) ) ; memset (&qfltDOut, 0, sizeof (QuasiFloatType) ) ; #endif /* !defined(QUASIFLOAT) */ /* For each character in aux. buffer */ while (*cpTmp) /* replace all commas with spaces, to let the <scanf()> parse it */ { if (',' == *cpTmp) *cpTmp = ' '; cpTmp++; } #if !defined(QUASIFLOAT) /* Find 3 floats separated by spaces in aux. buffer */ sscanf(cBuf, "%f %f %f,", &fltTM, &fltDIn, &fltDOut ); #else /* Find 3 floats separated by spaces in aux. buffer. Each float represented as <INT>.<INT>e<SIGN>0<INT> */ sscanf(cBuf, "%d.%de%c0%d %d.%de%c0%d %d.%de%c0%d,", &(qfltTM.integer),&(qfltTM.fraction),&(qfltTM.sgn),&(qfltTM.power), &(qfltDIn.integer),&(qfltDIn.fraction),&(qfltDIn.sgn),&(qfltDIn.power), &(qfltDOut.integer),&(qfltDOut.fraction),&(qfltDOut.sgn),&(qfltDOut.power) ); /* For each 'second' value do output. Only once. */ /* TODO: remove? */ if (0 == qfltTM.power) if (iOldSec!= qfltTM.integer){iOldSec=qfltTM.integer; printf("sec: %d; ", iOldSec); fflush(stdout); } #endif /* !defined(QUASIFLOAT) */ #if DEBUG_DATA #if !defined(QUASIFLOAT) printf("[%s] %s: parsed : <%f> <%f> <%f>\n", __FILE__, __func__, fltTM, fltDIn, fltDOut ); #else printf("[%s] %s: parsed : <%d.%de%c0%d> <%d.%de%c0%d> <%d.%de%c0%d> \n", __FILE__, __func__, qfltTM.integer,qfltTM.fraction,qfltTM.sgn,qfltTM.power, qfltDIn.integer,qfltDIn.fraction,qfltDIn.sgn,qfltDIn.power, qfltDOut.integer,qfltDOut.fraction,qfltDOut.sgn,qfltDOut.power ); #endif /* !defined(QUASIFLOAT) */ #endif /* (DEBUG_DATA) */ #if !defined(QUASIFLOAT) /* Attach just scanned data (three floats) to tail of dynamic structure */ EnrollPoint(&pTimeChain, &fltTM, &fltDIn, &fltDOut, "N/A"); #else /* Attach just scanned data (three floats represented as <INT>.<INT>e<SIGN>0<INT>) to tail of dynamic structure */ EnrollPoint(&pTimeChain, &qfltTM, &qfltDIn, &qfltDOut, "N/A"); #endif /* !defined(QUASIFLOAT) */ } } /* Dispose pointer to Raw Data file */ fclose(fp); printf("\n[%s] %s: issuing USB-curve-data on Pin #0 Port 'D'\n", __FILE__, __func__); /* Set pins of Port D as inputs/outputs, sets rest platform registers */ PortD_Prepare( ); /* Process data stored in dynamic structure pointed by 'pTimeChain' */ ProcessPoints(pTimeChain); printf("\n[%s] %s: disposing memory allocations\n", __FILE__, __func__); /* Free memory occupied by dynamically stored raw data */ DeletePoints(&pTimeChain); printf("[%s] %s: done (success) \n", __FILE__, __func__); fflush(stdout); return P_SUCCESS; }
bool MPointCreator::CreateResult(const std::vector<MHTRouteCandidate*>& rvecRouteCandidates) { if (!Init()) return false; const size_t nCandidates = rvecRouteCandidates.size(); for (size_t i = 0; i < nCandidates; ++i) { MHTRouteCandidate* pCandidate = rvecRouteCandidates[i]; if (pCandidate == NULL) continue; std::vector<const SimpleLine*> vecCurvesBetweenPoints; MHTRouteCandidate::RouteSegmentIterator it = pCandidate->RouteSegmentBegin(); MHTRouteCandidate::RouteSegmentIterator itEnd = pCandidate->RouteSegmentEnd(); MHTRouteCandidate::PointDataPtr pData1 = MHTRouteCandidate::PointDataPtr(); MHTRouteCandidate::RouteSegmentPtr pSegment1 = MHTRouteCandidate::RouteSegmentPtr(); while (it != itEnd) { const MHTRouteCandidate::RouteSegmentPtr& pSegment = *it; ++it; if (pSegment == NULL) continue; const std::vector<MHTRouteCandidate::PointDataPtr>& vecPoints = pSegment->GetPoints(); if (vecPoints.size() == 0) { const shared_ptr<IMMNetworkSection>& pSection = pSegment->GetSection(); if (pSection != NULL && pSection->IsDefined()) vecCurvesBetweenPoints.push_back(pSection->GetCurve()); } else { std::vector<MHTRouteCandidate::PointDataPtr>::const_iterator itPts = vecPoints.begin(); std::vector<MHTRouteCandidate::PointDataPtr>::const_iterator itPtsEnd = vecPoints.end(); while (itPts != itPtsEnd && pData1 == NULL) { pData1 = *itPts; pSegment1 = pSegment; ++itPts; } while (itPts != itPtsEnd && pData1 != NULL) { MHTRouteCandidate::PointDataPtr pData2 = MHTRouteCandidate::PointDataPtr(); MHTRouteCandidate::RouteSegmentPtr pSegment2 = MHTRouteCandidate::RouteSegmentPtr(); while (itPts != itPtsEnd && pData2 == NULL) { pData2 = *itPts; pSegment2 = pSegment; ++itPts; } if (pData2 == NULL) continue; ProcessPoints(*pData1, *pSegment1, *pData2, vecCurvesBetweenPoints); vecCurvesBetweenPoints.clear(); pData1 = pData2; pSegment1 = pSegment2; } } } } Finalize(); return true; }