123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "string.h"
- #include "stdlib.h"
- #include "math.h"
- #include "PowerDecoder.h"
- #include "RecordOutput.h"
- static double dRecordInterval;
- void ResamplerOutput_Init(BPSAMPLER *pstDecoder_, unsigned short usRecordInterval_, double dRecordInterval_, unsigned short usTimeBase_)
- {
- pstDecoder_->ucCadence = 0;
- pstDecoder_->dTotalEnergy = 0;
- pstDecoder_->fAccumEnergy = 0;
- pstDecoder_->fPendingEnergy = 0;
- pstDecoder_->fGapEnergy = 0;
- pstDecoder_->dTotalRotation = 0;
- pstDecoder_->fAccumRotation = 0;
- pstDecoder_->fPendingRotation = 0;
- pstDecoder_->fGapRotation = 0;
- pstDecoder_->ulEventTime = 0;
- pstDecoder_->ucRecordGapCount = 0;
- pstDecoder_->dLastRecordTime = 0;
- pstDecoder_->dLastMessageTime = 0;
- pstDecoder_->usRecordInterval = usRecordInterval_;
- pstDecoder_->usTimeBase = usTimeBase_;
- dRecordInterval = dRecordInterval_;
- }
- void RecordOutput(PowerRecordReceiver powerRecordReceiverPtr_, BPSAMPLER *pstDecoder_)
- {
-
- float fAveragePower = (float)(pstDecoder_->fPendingEnergy / dRecordInterval);
- float fAverageCadence = (float)(pstDecoder_->fPendingRotation * 60.0 / dRecordInterval);
- pstDecoder_->dTotalEnergy += pstDecoder_->fPendingEnergy;
- pstDecoder_->dTotalRotation += pstDecoder_->fPendingRotation;
- pstDecoder_->dLastRecordTime += dRecordInterval;
- pstDecoder_->ulLastRecordTime = (pstDecoder_->ulEventTime / pstDecoder_->usRecordInterval)*pstDecoder_->usRecordInterval;
- (*powerRecordReceiverPtr_)(pstDecoder_->dLastRecordTime, pstDecoder_->dTotalRotation, pstDecoder_->dTotalEnergy, fAverageCadence, fAveragePower);
-
- RecordOutput_FillGap(powerRecordReceiverPtr_, pstDecoder_);
- }
- void RecordOutput_FillGap(PowerRecordReceiver powerRecordReceiverPtr_, BPSAMPLER *pstDecoder_)
- {
- int i;
- float fIncEnergy;
- float fIncRotation;
- float fAveragePower;
- float fAverageCadence;
- if (pstDecoder_->ucRecordGapCount > 0)
- {
- fIncEnergy = (float)(pstDecoder_->fGapEnergy / pstDecoder_->ucRecordGapCount);
- fIncRotation = (float)(pstDecoder_->fGapRotation / pstDecoder_->ucRecordGapCount);
-
-
- fAveragePower = fIncEnergy / dRecordInterval;
- fAverageCadence = fIncRotation * 60.0f / dRecordInterval;
- for (i = 0; i < pstDecoder_->ucRecordGapCount; i++)
- {
- pstDecoder_->dTotalEnergy += fIncEnergy;
- pstDecoder_->dTotalRotation += fIncRotation;
- pstDecoder_->dLastRecordTime += dRecordInterval;
- (*powerRecordReceiverPtr_)(pstDecoder_->dLastRecordTime, pstDecoder_->dTotalRotation, pstDecoder_->dTotalEnergy, fAverageCadence, fAveragePower);
- }
- pstDecoder_->ucRecordGapCount = 0;
- }
- }
|