comments on time overflow
This commit is contained in:
@@ -350,6 +350,13 @@ asynStatus asynStreamGeneratorDriver::writeInt32(asynUser *pasynUser,
|
|||||||
void asynStreamGeneratorDriver::receiveUDP() {
|
void asynStreamGeneratorDriver::receiveUDP() {
|
||||||
|
|
||||||
// TODO fix time overflows
|
// TODO fix time overflows
|
||||||
|
// Regarding time overflow.
|
||||||
|
// * the header time stamp is 3 words, i.e. 48 bits.
|
||||||
|
// * it has a resolution of 100ns
|
||||||
|
// * so we can cover a maximum of (2^(3*16) - 1) * 1e-7 = 28147497 seconds
|
||||||
|
// * or about 325 days
|
||||||
|
// * so maybe this isn't necessary to solve, as long as we restart the
|
||||||
|
// electronics at least once a year...
|
||||||
|
|
||||||
const char *functionName = "receiveUDP";
|
const char *functionName = "receiveUDP";
|
||||||
asynStatus status = asynSuccess;
|
asynStatus status = asynSuccess;
|
||||||
@@ -482,7 +489,8 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
size_t countDiffsPtr = 0;
|
size_t countDiffsPtr = 0;
|
||||||
epicsInt32 *rates = new epicsInt32[this->num_channels];
|
epicsInt32 *rates = new epicsInt32[this->num_channels];
|
||||||
epicsInt32 *countDiff = new epicsInt32[this->num_channels];
|
epicsInt32 *countDiff = new epicsInt32[this->num_channels];
|
||||||
epicsInt32 *countDiffs = new epicsInt32[this->num_channels * rateAverageWindow];
|
epicsInt32 *countDiffs =
|
||||||
|
new epicsInt32[this->num_channels * rateAverageWindow];
|
||||||
uint64_t *timeSpans = new uint64_t[this->num_channels];
|
uint64_t *timeSpans = new uint64_t[this->num_channels];
|
||||||
epicsTimeStamp lastRateUpdate = epicsTime::getCurrent();
|
epicsTimeStamp lastRateUpdate = epicsTime::getCurrent();
|
||||||
|
|
||||||
@@ -616,25 +624,27 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
// Careful changing any of these magic numbers until I clean this up
|
// Careful changing any of these magic numbers until I clean this up
|
||||||
// as you might end up calculating the wrong rate
|
// as you might end up calculating the wrong rate
|
||||||
epicsTimeStamp currentTime = epicsTime::getCurrent();
|
epicsTimeStamp currentTime = epicsTime::getCurrent();
|
||||||
if (epicsTimeDiffInNS(¤tTime, &lastRateUpdate) > minRateSamplePeriod) {
|
if (epicsTimeDiffInNS(¤tTime, &lastRateUpdate) >
|
||||||
timeSpans[countDiffsPtr] = epicsTimeDiffInNS(¤tTime, &lastRateUpdate);
|
minRateSamplePeriod) {
|
||||||
|
timeSpans[countDiffsPtr] =
|
||||||
|
epicsTimeDiffInNS(¤tTime, &lastRateUpdate);
|
||||||
|
|
||||||
uint64_t totalTime = 0;
|
uint64_t totalTime = 0;
|
||||||
for (size_t i = 0; i <= rateAverageWindow; ++i) {
|
for (size_t i = 0; i <= rateAverageWindow; ++i) {
|
||||||
totalTime += timeSpans[i];
|
totalTime += timeSpans[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
lastRateUpdate = currentTime;
|
lastRateUpdate = currentTime;
|
||||||
|
|
||||||
for (size_t i = 0; i <= this->num_channels; ++i) {
|
for (size_t i = 0; i <= this->num_channels; ++i) {
|
||||||
countDiffs[i * rateAverageWindow + countDiffsPtr] = countDiff[i];
|
countDiffs[i * rateAverageWindow + countDiffsPtr] =
|
||||||
|
countDiff[i];
|
||||||
|
|
||||||
uint64_t cnt = 0;
|
uint64_t cnt = 0;
|
||||||
for (size_t j = 0; j <= rateAverageWindow; ++j) {
|
for (size_t j = 0; j <= rateAverageWindow; ++j) {
|
||||||
cnt += countDiffs[i * rateAverageWindow + j];
|
cnt += countDiffs[i * rateAverageWindow + j];
|
||||||
}
|
}
|
||||||
rates[i] =
|
rates[i] = cnt / (totalTime * 1e-9);
|
||||||
cnt / (totalTime * 1e-9);
|
|
||||||
|
|
||||||
countDiff[i] = 0;
|
countDiff[i] = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user