Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 12 additions & 36 deletions caPutLogApp/caPutJsonLogTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const

// Dont log duplicate values if configured so
if (this->config == caPutJsonLogOnChange && !burst) {
if (this->compareValues(pLogData))
if (this->valuesAreEqual(pLogData))
return caPutJsonLogSuccess;
}

Expand Down Expand Up @@ -794,46 +794,22 @@ void CaPutJsonLogTask::calculateMax(VALUE *pres, const VALUE *pa, const VALUE *p
}
}

#define SINGLE_TYPE_COMPARE(_t, _s) \
if (pLogData->is_array) \
return memcmp(pa->a_##_t, pb->a_##_t, size * _s) == 0; \
return pa->v_##_t == pb->v_##_t;

bool CaPutJsonLogTask::compareValues(const LOGDATA *pLogData) {
bool CaPutJsonLogTask::valuesAreEqual(const LOGDATA *pLogData) {
const VALUE *pa = &pLogData->old_value;
const VALUE *pb = &pLogData->new_value.value;
const int size = pLogData->old_log_size;
size_t size = pLogData->is_array ? pLogData->old_log_size : 1;

if (pLogData->is_array && pLogData->old_log_size != pLogData->new_log_size)
if (pLogData->old_log_size != pLogData->new_log_size)
return false;

switch (pLogData->type)
{
case DBR_CHAR:
SINGLE_TYPE_COMPARE(int8, sizeof(epicsInt8));
case DBR_UCHAR:
SINGLE_TYPE_COMPARE(uint8, sizeof(epicsUInt8));
case DBR_SHORT:
SINGLE_TYPE_COMPARE(int16, sizeof(epicsInt16));
case DBR_USHORT:
case DBR_ENUM:
SINGLE_TYPE_COMPARE(uint16, sizeof(epicsUInt16));
case DBR_LONG:
SINGLE_TYPE_COMPARE(int32, sizeof(epicsInt32));
case DBR_ULONG:
SINGLE_TYPE_COMPARE(uint32, sizeof(epicsUInt32));
case DBR_INT64:
SINGLE_TYPE_COMPARE(int64, sizeof(epicsInt64));
case DBR_UINT64:
SINGLE_TYPE_COMPARE(uint64, sizeof(epicsUInt64));
case DBR_FLOAT:
SINGLE_TYPE_COMPARE(float, sizeof(epicsFloat32));
case DBR_DOUBLE:
SINGLE_TYPE_COMPARE(double, sizeof(epicsFloat64));
case DBR_STRING:
SINGLE_TYPE_COMPARE(string, MAX_STRING_SIZE);
default:
return 0;
if (pLogData->type == DBR_STRING) {
for (size_t i = 0; i < size; i++) {
if (strncmp(pa->a_string[i], pb->a_string[i], MAX_STRING_SIZE) != 0)
return false;
}
return true;
} else {
return memcmp(pa, pb, size*dbValueSize(pLogData->type)) == 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion caPutLogApp/caPutJsonLogTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class epicsShareClass CaPutJsonLogTask {
* @return true If values are the same.
* @return false If values are not the same.
*/
bool compareValues(const LOGDATA *pLogData);
bool valuesAreEqual(const LOGDATA *pLogData);

/**
* @brief Get a string representation of the value stored in the ::VALUE.
Expand Down