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
|
// These messages don't have any obious start or end to synchronise
|
||||||
// against...
|
// against...
|
||||||
const std::size_t bufferSize = 1500;
|
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) {
|
while (true) {
|
||||||
|
|
||||||
@@ -454,6 +460,12 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
// uint32. It does support int64 though.. so we start with that
|
// uint32. It does support int64 though.. so we start with that
|
||||||
epicsInt32 *counts = new epicsInt32[this->num_channels];
|
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;
|
asynStatus status = asynSuccess;
|
||||||
NormalisedEvent *ne;
|
NormalisedEvent *ne;
|
||||||
uint64_t newestTimestamp = 0;
|
uint64_t newestTimestamp = 0;
|
||||||
@@ -473,6 +485,9 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
// resolution with a uint64_t we will have an overflow after around
|
// resolution with a uint64_t we will have an overflow after around
|
||||||
// 4 years
|
// 4 years
|
||||||
newestTimestamp = std::max(newestTimestamp, ne->timestamp);
|
newestTimestamp = std::max(newestTimestamp, ne->timestamp);
|
||||||
|
|
||||||
|
++countDiff[ne->source == 0 ? ne->pixelId + 1 : 0];
|
||||||
|
|
||||||
timeQueue.push(ne);
|
timeQueue.push(ne);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,6 +595,34 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
delete ne;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,15 +56,6 @@ struct __attribute__((__packed__)) MonitorEvent {
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Simplified Event Struct Definition
|
* Simplified Event Struct Definition
|
||||||
*/
|
*/
|
||||||
struct __attribute__((__packed__)) NormalisedMonitorEvent {
|
|
||||||
uint64_t TimeStamp;
|
|
||||||
uint8_t DataID : 4;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct __attribute__((__packed__)) NormalisedDetectorEvent {
|
|
||||||
uint64_t TimeStamp;
|
|
||||||
uint32_t PixID;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct __attribute__((__packed__)) NormalisedEvent {
|
struct __attribute__((__packed__)) NormalisedEvent {
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
|
|||||||
Reference in New Issue
Block a user