adds a simple rate calculation
This commit is contained in:
@@ -359,7 +359,13 @@ void asynStreamGeneratorDriver::receiveUDP() {
|
||||
// These messages don't have any obious start or end to synchronise
|
||||
// against...
|
||||
const std::size_t bufferSize = 1500;
|
||||
char buffer[bufferSize + 1]; // so that \0 can fit
|
||||
char buffer[bufferSize];
|
||||
|
||||
// We have 10 mcpdids
|
||||
uint64_t lastBufferNumber* = new uint64_t[10];
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
lastBufferNumber[i] = 0;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -454,6 +460,12 @@ void asynStreamGeneratorDriver::processEvents() {
|
||||
// uint32. It does support int64 though.. so we start with that
|
||||
epicsInt32 *counts = new epicsInt32[this->num_channels];
|
||||
|
||||
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 * 10];
|
||||
epicsTimeStamp lastRateUpdate = epicsTime::getCurrent();
|
||||
|
||||
asynStatus status = asynSuccess;
|
||||
NormalisedEvent *ne;
|
||||
uint64_t newestTimestamp = 0;
|
||||
@@ -473,6 +485,9 @@ void asynStreamGeneratorDriver::processEvents() {
|
||||
// resolution with a uint64_t we will have an overflow after around
|
||||
// 4 years
|
||||
newestTimestamp = std::max(newestTimestamp, ne->timestamp);
|
||||
|
||||
++countDiff[ne->source == 0 ? ne->pixelId + 1 : 0];
|
||||
|
||||
timeQueue.push(ne);
|
||||
}
|
||||
|
||||
@@ -580,6 +595,34 @@ void asynStreamGeneratorDriver::processEvents() {
|
||||
delete ne;
|
||||
}
|
||||
}
|
||||
|
||||
// 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(¤tTime, &lastRateUpdate) > 100'000'000ll) {
|
||||
lastRateUpdate = currentTime;
|
||||
|
||||
for (size_t i = 0; i <= this->num_channels; ++i) {
|
||||
countDiffs[i * 10 + countDiffsPtr] = countDiff[i];
|
||||
|
||||
uint64_t cnt = 0;
|
||||
for (size_t j = 0; j <= 10; ++j) {
|
||||
cnt += countDiffs[i * 10 + j];
|
||||
}
|
||||
rates[i] = cnt / 10.;
|
||||
|
||||
countDiff[i] = 0;
|
||||
}
|
||||
|
||||
countDiffsPtr = (countDiffsPtr + 1) % 10;
|
||||
|
||||
lock();
|
||||
for (size_t i = 0; i < num_channels; ++i) {
|
||||
setIntegerParam(P_Rates[i], rates[i]);
|
||||
}
|
||||
callParamCallbacks();
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user