comments on time overflow

This commit is contained in:
2025-11-05 10:13:08 +01:00
parent 617dd3153b
commit 2ccf37ce33

View File

@@ -350,6 +350,13 @@ asynStatus asynStreamGeneratorDriver::writeInt32(asynUser *pasynUser,
void asynStreamGeneratorDriver::receiveUDP() {
// 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";
asynStatus status = asynSuccess;
@@ -482,7 +489,8 @@ void asynStreamGeneratorDriver::processEvents() {
size_t countDiffsPtr = 0;
epicsInt32 *rates = 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];
epicsTimeStamp lastRateUpdate = epicsTime::getCurrent();
@@ -616,25 +624,27 @@ void asynStreamGeneratorDriver::processEvents() {
// Careful changing any of these magic numbers until I clean this up
// as you might end up calculating the wrong rate
epicsTimeStamp currentTime = epicsTime::getCurrent();
if (epicsTimeDiffInNS(&currentTime, &lastRateUpdate) > minRateSamplePeriod) {
timeSpans[countDiffsPtr] = epicsTimeDiffInNS(&currentTime, &lastRateUpdate);
if (epicsTimeDiffInNS(&currentTime, &lastRateUpdate) >
minRateSamplePeriod) {
timeSpans[countDiffsPtr] =
epicsTimeDiffInNS(&currentTime, &lastRateUpdate);
uint64_t totalTime = 0;
for (size_t i = 0; i <= rateAverageWindow; ++i) {
totalTime += timeSpans[i];
}
uint64_t totalTime = 0;
for (size_t i = 0; i <= rateAverageWindow; ++i) {
totalTime += timeSpans[i];
}
lastRateUpdate = currentTime;
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;
for (size_t j = 0; j <= rateAverageWindow; ++j) {
cnt += countDiffs[i * rateAverageWindow + j];
}
rates[i] =
cnt / (totalTime * 1e-9);
rates[i] = cnt / (totalTime * 1e-9);
countDiff[i] = 0;
}