@@ -458,7 +458,7 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const
458458
459459 // Dont log duplicate values if configured so
460460 if (this ->config == caPutJsonLogOnChange && !burst) {
461- if (this ->compareValues (pLogData))
461+ if (this ->valuesAreEqual (pLogData))
462462 return caPutJsonLogSuccess;
463463 }
464464
@@ -794,46 +794,22 @@ void CaPutJsonLogTask::calculateMax(VALUE *pres, const VALUE *pa, const VALUE *p
794794 }
795795}
796796
797- #define SINGLE_TYPE_COMPARE (_t, _s ) \
798- if (pLogData->is_array) \
799- return memcmp(pa->a_##_t, pb->a_##_t, size * _s) == 0 ; \
800- return pa->v_##_t == pb->v_##_t;
801-
802- bool CaPutJsonLogTask::compareValues (const LOGDATA *pLogData) {
797+ bool CaPutJsonLogTask::valuesAreEqual (const LOGDATA *pLogData) {
803798 const VALUE *pa = &pLogData->old_value ;
804799 const VALUE *pb = &pLogData->new_value .value ;
805- const int size = pLogData->old_log_size ;
800+ size_t size = pLogData->is_array ? pLogData-> old_log_size : 1 ;
806801
807- if (pLogData->is_array && pLogData-> old_log_size != pLogData->new_log_size )
802+ if (pLogData->old_log_size != pLogData->new_log_size )
808803 return false ;
809804
810- switch (pLogData->type )
811- {
812- case DBR_CHAR:
813- SINGLE_TYPE_COMPARE (int8, sizeof (epicsInt8));
814- case DBR_UCHAR:
815- SINGLE_TYPE_COMPARE (uint8, sizeof (epicsUInt8));
816- case DBR_SHORT:
817- SINGLE_TYPE_COMPARE (int16, sizeof (epicsInt16));
818- case DBR_USHORT:
819- case DBR_ENUM:
820- SINGLE_TYPE_COMPARE (uint16, sizeof (epicsUInt16));
821- case DBR_LONG:
822- SINGLE_TYPE_COMPARE (int32, sizeof (epicsInt32));
823- case DBR_ULONG:
824- SINGLE_TYPE_COMPARE (uint32, sizeof (epicsUInt32));
825- case DBR_INT64:
826- SINGLE_TYPE_COMPARE (int64, sizeof (epicsInt64));
827- case DBR_UINT64:
828- SINGLE_TYPE_COMPARE (uint64, sizeof (epicsUInt64));
829- case DBR_FLOAT:
830- SINGLE_TYPE_COMPARE (float , sizeof (epicsFloat32));
831- case DBR_DOUBLE:
832- SINGLE_TYPE_COMPARE (double , sizeof (epicsFloat64));
833- case DBR_STRING:
834- SINGLE_TYPE_COMPARE (string, MAX_STRING_SIZE);
835- default :
836- return 0 ;
805+ if (pLogData->type == DBR_STRING) {
806+ for (size_t i = 0 ; i < size; i++) {
807+ if (strncmp (pa->a_string [i], pb->a_string [i], MAX_STRING_SIZE) != 0 )
808+ return false ;
809+ }
810+ return true ;
811+ } else {
812+ return memcmp (pa, pb, size*dbValueSize (pLogData->type )) == 0 ;
837813 }
838814}
839815
0 commit comments