1 #include "otsdaq-core/FECore/FESlowControlsChannel.h"
2 #include "otsdaq-core/Macros/CoutMacros.h"
26 FESlowControlsChannel::FESlowControlsChannel(
const std::string& interfaceUID,
27 const std::string& channelName,
28 const std::string& dataType,
29 unsigned int universalDataSize,
30 unsigned int universalAddressSize,
31 const std::string& universalAddress,
32 unsigned int universalDataBitOffset,
36 bool monitoringEnabled,
37 bool recordChangesOnly,
38 time_t delayBetweenSamples,
40 const std::string& savePath,
41 const std::string& saveFileRadix,
42 bool saveBinaryFormat,
45 const std::string& lolo,
46 const std::string& lo,
47 const std::string& hi,
48 const std::string& hihi)
49 : interfaceUID_(interfaceUID)
50 , channelName_(channelName)
51 , fullChannelName_(interfaceUID_ +
"/" + channelName_)
53 , universalDataBitOffset_(universalDataBitOffset)
54 , txPacketSequenceNumber_(0)
57 readAccess_(readAccess)
58 , writeAccess_(writeAccess)
59 , monitoringEnabled_(monitoringEnabled)
60 , recordChangesOnly_(recordChangesOnly)
61 , delayBetweenSamples_(delayBetweenSamples)
62 , saveEnabled_(saveEnabled)
64 , saveFileRadix_(saveFileRadix)
65 , saveBinaryFormat_(saveBinaryFormat)
66 , alarmsEnabled_(alarmsEnabled)
67 , latchAlarms_(latchAlarms)
75 , saveFullFileName_(savePath_ +
"/" + saveFileRadix_ +
"-" +
76 underscoreString(fullChannelName_) +
"-" +
77 std::to_string(time(0)) + (saveBinaryFormat_ ?
".dat" :
".txt"))
79 __COUT__ <<
"dataType_ = " << dataType_ << std::endl;
80 __COUT__ <<
"universalAddressSize = " << universalAddressSize << std::endl;
81 __COUT__ <<
"universalAddress = " << universalAddress << std::endl;
93 if(dataType_[dataType_.size() - 1] ==
'b')
94 sscanf(&dataType_[0],
"%u", &sizeOfDataTypeBits_);
95 else if(dataType_ ==
"char" || dataType_ ==
"unsigned char")
96 sizeOfDataTypeBits_ =
sizeof(char) * 8;
97 else if(dataType_ ==
"short" || dataType_ ==
"unsigned short")
98 sizeOfDataTypeBits_ =
sizeof(short) * 8;
99 else if(dataType_ ==
"int" || dataType_ ==
"unsigned int")
100 sizeOfDataTypeBits_ =
sizeof(int) * 8;
101 else if(dataType_ ==
"long long" || dataType_ ==
"unsigned long long")
102 sizeOfDataTypeBits_ =
sizeof(
long long) * 8;
103 else if(dataType_ ==
"float")
104 sizeOfDataTypeBits_ =
sizeof(float) * 8;
105 else if(dataType_ ==
"double")
106 sizeOfDataTypeBits_ =
sizeof(double) * 8;
109 __SS__ <<
"Data type '" << dataType_ <<
"' is invalid. "
110 <<
"Valid data types (w/size in bytes) are as follows: "
112 <<
", char (" <<
sizeof(char) <<
"B), unsigned char ("
113 <<
sizeof(
unsigned char) <<
"B), short (" <<
sizeof(short)
114 <<
"B), unsigned short (" <<
sizeof(
unsigned short) <<
"B), int ("
115 <<
sizeof(int) <<
"B), unsigned int (" <<
sizeof(
unsigned int)
116 <<
"B), long long (" <<
sizeof(
long long) <<
"B), unsigned long long ("
117 <<
sizeof(
unsigned long long) <<
"B), float (" <<
sizeof(float)
118 <<
"B), double (" <<
sizeof(
double) <<
"B)." << std::endl;
119 __COUT_ERR__ <<
"\n" << ss.str();
123 if(sizeOfDataTypeBits_ > 64)
125 __SS__ <<
"Invalid Data Type '" << dataType_ <<
"' (" << sizeOfDataTypeBits_
127 ". Size in bits must be less than or equal to 64-bits."
129 __COUT_ERR__ <<
"\n" << ss.str();
133 if(universalDataSize * 8 < sizeOfDataTypeBits_)
136 <<
"Invalid Data Type '" << dataType_ <<
"' (" << sizeOfDataTypeBits_
137 <<
"-bits) or Universal Data Size of " << universalDataSize * 8
138 <<
"-bits. Data Type size must be less than or equal to Universal Data Size."
140 __COUT_ERR__ <<
"\n" << ss.str();
144 universalAddress_.resize(universalAddressSize);
145 convertStringToBuffer(universalAddress, universalAddress_);
147 sizeOfDataTypeBytes_ =
148 (sizeOfDataTypeBits_ / 8 + ((universalDataBitOffset_ % 8) ? 1 : 0));
150 lolo_.resize(sizeOfDataTypeBytes_);
151 convertStringToBuffer(lolo, lolo_,
true);
152 lo_.resize(sizeOfDataTypeBytes_);
153 convertStringToBuffer(lo, lo_,
true);
154 hi_.resize(sizeOfDataTypeBytes_);
155 convertStringToBuffer(hi, hi_,
true);
156 hihi_.resize(sizeOfDataTypeBytes_);
157 convertStringToBuffer(hihi, hihi_,
true);
160 sample_.resize(sizeOfDataTypeBytes_);
161 lastSample_.resize(sizeOfDataTypeBytes_);
165 FESlowControlsChannel::~FESlowControlsChannel(
void) {}
170 std::string FESlowControlsChannel::underscoreString(
const std::string& str)
173 retStr.reserve(str.size());
174 for(
unsigned int i = 0; i < str.size(); ++i)
175 if((str[i] >=
'a' && str[i] <=
'z') || (str[i] >=
'A' && str[i] <=
'Z') ||
176 (str[i] >=
'0' && str[i] <=
'9'))
177 retStr.push_back(str[i]);
179 retStr.push_back(
'_');
189 void FESlowControlsChannel::convertStringToBuffer(
const std::string& inString,
193 __COUT__ <<
"Input Str Sz= \t" << inString.size() << std::endl;
194 __COUT__ <<
"Input Str Val= \t'" << inString <<
"'" << std::endl;
195 __COUT__ <<
"Output buffer Sz= \t" << buffer.size() << std::endl;
197 if(useDataType && (dataType_ ==
"float" || dataType_ ==
"double"))
199 __COUT__ <<
"Floating point spec'd" << std::endl;
200 if(dataType_ ==
"float" && buffer.size() ==
sizeof(float))
202 sscanf(&inString[0],
"%f", (
float*)&buffer[0]);
203 __COUT__ <<
"float: " << *((
float*)&buffer[0]) << std::endl;
205 else if(dataType_ ==
"double" && buffer.size() ==
sizeof(double))
207 sscanf(&inString[0],
"%lf", (
double*)&buffer[0]);
208 __COUT__ <<
"double: " << *((
double*)&buffer[0]) << std::endl;
212 __SS__ <<
"Invalid floating point spec! "
213 <<
"dataType_=" << dataType_ <<
" buffer.size()=" << buffer.size()
215 __COUT_ERR__ <<
"\n" << ss.str();
221 for(
int i = (
int)buffer.size() - 1; i >= 0; --i)
222 ss << std::hex << (
int)((buffer[i] >> 4) & 0xF)
223 << (int)((buffer[i]) & 0xF) <<
" " << std::dec;
225 __COUT__ <<
"\n" << ss.str();
231 for(
unsigned int i = 0; i < buffer.size(); ++i)
245 if(inString.size() > 2 && inString[0] ==
'0' && inString[1] ==
'x')
249 __COUT__ <<
"Hex." << std::endl;
253 for(
unsigned int i = 0; i < inString.size(); ++i)
255 j = (inString.size() - 1 - i);
256 if(inString[i] >=
'0' && inString[i] <=
'9')
257 val = inString[i] - 48;
258 else if(inString[i] >=
'A' && inString[i] <=
'F')
259 val = inString[i] - 55;
260 else if(inString[i] >=
'a' && inString[i] <=
'f')
261 val = inString[i] - 87;
265 buffer[j / 2] |= val << ((j % 2) * 4);
272 __COUT__ <<
"Decimal." << std::endl;
273 unsigned long long val;
275 if(!useDataType || dataType_[0] ==
'u')
277 sscanf(&inString[0],
"%llu", &val);
281 sscanf(&inString[0],
"%lld", (
long long*)&val);
284 for(
unsigned int i = 0; i <
sizeof(
long long) && i < buffer.size(); ++i)
285 buffer[i] = ((
char*)&val)[i];
292 for(
int i = (
int)buffer.size() - 1; i >= 0; --i)
293 ss << std::hex << (
int)((buffer[i] >> 4) & 0xF) << (int)((buffer[i]) & 0xF)
296 __COUT__ <<
"\n" << ss.str();
303 void FESlowControlsChannel::handleSample(
const std::string& universalReadValue,
304 std::string& txBuffer,
306 bool aggregateIsBinaryFormat)
308 __COUT__ <<
"txBuffer size=" << txBuffer.size() << std::endl;
312 extractSample(universalReadValue);
329 if(recordChangesOnly_)
331 if(lastSampleTime_ && lastSample_ == sample_)
333 __COUT__ <<
"no change." << std::endl;
338 __COUT__ <<
"new value!" << std::endl;
341 lastSampleTime_ = time(0);
342 lastSample_ = sample_;
349 if(monitoringEnabled_)
361 __COUT__ <<
"before txBuffer sz=" << txBuffer.size() << std::endl;
362 txBuffer.push_back(0);
363 txBuffer.push_back(txPacketSequenceNumber_++);
365 txBuffer.resize(txBuffer.size() +
sizeof(lastSampleTime_));
366 memcpy(&txBuffer[txBuffer.size() -
sizeof(lastSampleTime_)],
368 sizeof(lastSampleTime_));
370 unsigned int tmpSz = fullChannelName_.size();
372 txBuffer.resize(txBuffer.size() +
sizeof(tmpSz));
373 memcpy(&txBuffer[txBuffer.size() -
sizeof(tmpSz)], &tmpSz,
sizeof(tmpSz));
375 txBuffer += fullChannelName_;
377 txBuffer.push_back((
unsigned char)sample_.size());
378 txBuffer.push_back((
unsigned char)sizeOfDataTypeBits_);
381 __COUT__ <<
"after txBuffer sz=" << txBuffer.size() << std::endl;
384 __SS__ <<
"txBuffer: \n";
385 for(
unsigned int i = 0; i < txBuffer.size(); ++i)
387 ss << std::hex << (int)((txBuffer[i] >> 4) & 0xF)
388 << (int)((txBuffer[i]) & 0xF) <<
" " << std::dec;
393 __COUT__ <<
"\n" << ss.str();
399 alarmMask = checkAlarms(txBuffer);
402 std::string* alarmValueArray[] = {&lolo_, &lo_, &hi_, &hihi_};
410 if(aggregateIsBinaryFormat)
420 __COUT__ <<
"Aggregate Binary File Format: " <<
sizeof(lastSampleTime_) <<
" "
421 << sample_.size() << std::endl;
424 fwrite(&lastSampleTime_,
425 sizeof(lastSampleTime_),
429 unsigned int tmpSz = fullChannelName_.size();
430 fwrite(&tmpSz,
sizeof(tmpSz), 1, fpAggregate);
431 fwrite(&fullChannelName_[0],
432 fullChannelName_.size(),
436 unsigned char tmpChar = (
unsigned char)sample_.size();
437 fwrite(&tmpChar, 1, 1, fpAggregate);
439 tmpChar = (
unsigned char)sizeOfDataTypeBits_;
440 fwrite(&tmpChar, 1, 1, fpAggregate);
441 fwrite(&sample_[0], sample_.size(), 1, fpAggregate);
446 for(time_t i = 1; i < 5; ++i, alarmMask >>= 1)
451 sizeof(lastSampleTime_),
456 unsigned int tmpSz = fullChannelName_.size();
458 &tmpSz,
sizeof(tmpSz), 1, fpAggregate);
459 fwrite(&fullChannelName_[0],
460 fullChannelName_.size(),
464 unsigned char tmpChar = (
unsigned char)sample_.size();
465 fwrite(&tmpChar, 1, 1, fpAggregate);
467 tmpChar = (
unsigned char)sizeOfDataTypeBits_;
468 fwrite(&tmpChar, 1, 1, fpAggregate);
469 fwrite(&(*alarmValueArray[i - 1])[0],
470 (*alarmValueArray[i - 1]).size(),
483 __COUT__ <<
"Aggregate Text File Format: " << dataType_ << std::endl;
485 fprintf(fpAggregate,
"%lu\n", lastSampleTime_);
486 fprintf(fpAggregate,
"%s\n", fullChannelName_.c_str());
488 if(dataType_[dataType_.size() - 1] ==
491 std::stringstream ss;
493 for(
unsigned int i = 0; i < sample_.size(); ++i)
494 ss << std::hex << (
int)((sample_[i] >> 4) & 0xF)
495 << (int)((sample_[i]) & 0xF) << std::dec;
496 fprintf(fpAggregate,
"%s\n", ss.str().c_str());
498 else if(dataType_ ==
"char")
499 fprintf(fpAggregate,
"%d\n", *((
char*)(&sample_[0])));
500 else if(dataType_ ==
"unsigned char")
501 fprintf(fpAggregate,
"%u\n", *((
unsigned char*)(&sample_[0])));
502 else if(dataType_ ==
"short")
503 fprintf(fpAggregate,
"%d\n", *((
short*)(&sample_[0])));
504 else if(dataType_ ==
"unsigned short")
505 fprintf(fpAggregate,
"%u\n", *((
unsigned short*)(&sample_[0])));
506 else if(dataType_ ==
"int")
507 fprintf(fpAggregate,
"%d\n", *((
int*)(&sample_[0])));
508 else if(dataType_ ==
"unsigned int")
509 fprintf(fpAggregate,
"%u\n", *((
unsigned int*)(&sample_[0])));
510 else if(dataType_ ==
"long long")
511 fprintf(fpAggregate,
"%lld\n", *((
long long*)(&sample_[0])));
512 else if(dataType_ ==
"unsigned long long")
513 fprintf(fpAggregate,
"%llu\n", *((
unsigned long long*)(&sample_[0])));
514 else if(dataType_ ==
"float")
515 fprintf(fpAggregate,
"%f\n", *((
float*)(&sample_[0])));
516 else if(dataType_ ==
"double")
517 fprintf(fpAggregate,
"%f\n", *((
double*)(&sample_[0])));
523 for(time_t i = 1; i < 5; ++i, checkMask <<= 1)
524 if(alarmMask & checkMask)
526 fprintf(fpAggregate,
"%lu\n", i);
527 fprintf(fpAggregate,
"%s\n", fullChannelName_.c_str());
529 if(dataType_[dataType_.size() - 1] ==
532 std::stringstream ss;
534 for(
unsigned int j = 0; j < (*alarmValueArray[i - 1]).size();
537 << (
int)(((*alarmValueArray[i - 1])[j] >> 4) & 0xF)
538 << (
int)(((*alarmValueArray[i - 1])[j]) & 0xF)
540 fprintf(fpAggregate,
"%s\n", ss.str().c_str());
542 else if(dataType_ ==
"char")
545 *((
char*)(&(*alarmValueArray[i - 1])[0])));
546 else if(dataType_ ==
"unsigned char")
549 *((
unsigned char*)(&(*alarmValueArray[i - 1])[0])));
550 else if(dataType_ ==
"short")
553 *((
short*)(&(*alarmValueArray[i - 1])[0])));
554 else if(dataType_ ==
"unsigned short")
557 *((
unsigned short*)(&(*alarmValueArray[i - 1])[0])));
558 else if(dataType_ ==
"int")
561 *((
int*)(&(*alarmValueArray[i - 1])[0])));
562 else if(dataType_ ==
"unsigned int")
565 *((
unsigned int*)(&(*alarmValueArray[i - 1])[0])));
566 else if(dataType_ ==
"long long")
569 *((
long long*)(&(*alarmValueArray[i - 1])[0])));
570 else if(dataType_ ==
"unsigned long long")
574 *((
unsigned long long*)(&(*alarmValueArray[i - 1])[0])));
575 else if(dataType_ ==
"float")
578 *((
float*)(&(*alarmValueArray[i - 1])[0])));
579 else if(dataType_ ==
"double")
582 *((
double*)(&(*alarmValueArray[i - 1])[0])));
593 FILE* fp = fopen(saveFullFileName_.c_str(), saveBinaryFormat_ ?
"ab" :
"a");
596 __COUT_ERR__ <<
"Failed to open slow controls channel file: "
597 << saveFullFileName_ << std::endl;
602 if(saveBinaryFormat_)
604 __COUT__ <<
"Binary File Format: " <<
sizeof(lastSampleTime_) <<
" "
605 << sample_.size() << std::endl;
606 fwrite(&lastSampleTime_,
sizeof(lastSampleTime_), 1, fp);
607 fwrite(&sample_[0], sample_.size(), 1, fp);
611 for(time_t i = 1; i < 5; ++i, alarmMask >>= 1)
614 fwrite(&i,
sizeof(lastSampleTime_), 1, fp);
615 fwrite(&(*alarmValueArray[i - 1])[0],
616 (*alarmValueArray[i - 1]).size(),
623 __COUT__ <<
"Text File Format: " << dataType_ << std::endl;
625 fprintf(fp,
"%lu\n", lastSampleTime_);
627 if(dataType_[dataType_.size() - 1] ==
630 std::stringstream ss;
632 for(
unsigned int i = 0; i < sample_.size(); ++i)
633 ss << std::hex << (
int)((sample_[i] >> 4) & 0xF)
634 << (int)((sample_[i]) & 0xF) << std::dec;
635 fprintf(fp,
"%s\n", ss.str().c_str());
637 else if(dataType_ ==
"char")
638 fprintf(fp,
"%d\n", *((
char*)(&sample_[0])));
639 else if(dataType_ ==
"unsigned char")
640 fprintf(fp,
"%u\n", *((
unsigned char*)(&sample_[0])));
641 else if(dataType_ ==
"short")
642 fprintf(fp,
"%d\n", *((
short*)(&sample_[0])));
643 else if(dataType_ ==
"unsigned short")
644 fprintf(fp,
"%u\n", *((
unsigned short*)(&sample_[0])));
645 else if(dataType_ ==
"int")
646 fprintf(fp,
"%d\n", *((
int*)(&sample_[0])));
647 else if(dataType_ ==
"unsigned int")
648 fprintf(fp,
"%u\n", *((
unsigned int*)(&sample_[0])));
649 else if(dataType_ ==
"long long")
650 fprintf(fp,
"%lld\n", *((
long long*)(&sample_[0])));
651 else if(dataType_ ==
"unsigned long long")
652 fprintf(fp,
"%llu\n", *((
unsigned long long*)(&sample_[0])));
653 else if(dataType_ ==
"float")
654 fprintf(fp,
"%f\n", *((
float*)(&sample_[0])));
655 else if(dataType_ ==
"double")
656 fprintf(fp,
"%f\n", *((
double*)(&sample_[0])));
662 for(time_t i = 1; i < 5; ++i, checkMask <<= 1)
663 if(alarmMask & checkMask)
665 fprintf(fp,
"%lu\n", i);
667 if(dataType_[dataType_.size() - 1] ==
670 std::stringstream ss;
672 for(
unsigned int j = 0; j < (*alarmValueArray[i - 1]).size();
675 << (
int)(((*alarmValueArray[i - 1])[j] >> 4) & 0xF)
676 << (
int)(((*alarmValueArray[i - 1])[j]) & 0xF)
678 fprintf(fp,
"%s\n", ss.str().c_str());
680 else if(dataType_ ==
"char")
682 fp,
"%d\n", *((
char*)(&(*alarmValueArray[i - 1])[0])));
683 else if(dataType_ ==
"unsigned char")
686 *((
unsigned char*)(&(*alarmValueArray[i - 1])[0])));
687 else if(dataType_ ==
"short")
689 fp,
"%d\n", *((
short*)(&(*alarmValueArray[i - 1])[0])));
690 else if(dataType_ ==
"unsigned short")
693 *((
unsigned short*)(&(*alarmValueArray[i - 1])[0])));
694 else if(dataType_ ==
"int")
695 fprintf(fp,
"%d\n", *((
int*)(&(*alarmValueArray[i - 1])[0])));
696 else if(dataType_ ==
"unsigned int")
699 *((
unsigned int*)(&(*alarmValueArray[i - 1])[0])));
700 else if(dataType_ ==
"long long")
703 *((
long long*)(&(*alarmValueArray[i - 1])[0])));
704 else if(dataType_ ==
"unsigned long long")
708 *((
unsigned long long*)(&(*alarmValueArray[i - 1])[0])));
709 else if(dataType_ ==
"float")
711 fp,
"%f\n", *((
float*)(&(*alarmValueArray[i - 1])[0])));
712 else if(dataType_ ==
"double")
714 fp,
"%f\n", *((
double*)(&(*alarmValueArray[i - 1])[0])));
727 void FESlowControlsChannel::extractSample(
const std::string& universalReadValue)
732 __SS__ <<
"Univ Read: ";
733 for(
unsigned int i = 0; i < universalReadValue.size(); ++i)
734 ss << std::hex << (
int)((universalReadValue[i] >> 4) & 0xF)
735 << (int)((universalReadValue[i]) & 0xF) <<
" " << std::dec;
737 __COUT__ <<
"\n" << ss.str();
740 unsigned int byteOffset = universalDataBitOffset_ / 8;
741 unsigned int bitOffset = universalDataBitOffset_ % 8;
742 unsigned int bitsLeft = sizeOfDataTypeBits_;
745 unsigned long long tmp = 0;
754 tmp = ((
unsigned long long)(universalReadValue[byteOffset++])) >> bitOffset;
755 bitsLeft = 8 - bitOffset;
774 tmp |= ((
unsigned long long)(universalReadValue[byteOffset++]))
775 << (sizeOfDataTypeBits_ - bitsLeft);
795 tmp |= (((
unsigned long long)(universalReadValue[byteOffset])) &
796 (0xFF >> (8 - bitsLeft)))
797 << (sizeOfDataTypeBits_ - bitsLeft);
809 __COUT__ <<
"Temp Long Long Sample: " << tmp << std::endl;
812 for(
unsigned int i = 0;
813 i < (sizeOfDataTypeBits_ / 8 + ((universalDataBitOffset_ % 8) ? 1 : 0));
815 sample_.push_back(((
char*)&tmp)[i]);
817 __COUT__ <<
"sample_.size()= " << sample_.size() << std::endl;
820 __SS__ <<
"Sample: ";
821 for(
unsigned int i = 0; i < sample_.size(); ++i)
822 ss << std::hex << (
int)((sample_[i] >> 4) & 0xF) << (int)((sample_[i]) & 0xF)
825 __COUT__ <<
"\n" << ss.str();
833 void FESlowControlsChannel::clearAlarms(
int targetAlarm)
835 if(targetAlarm == -1 || targetAlarm == 0)
836 loloAlarmed_ =
false;
837 if(targetAlarm == -1 || targetAlarm == 1)
839 if(targetAlarm == -1 || targetAlarm == 2)
841 if(targetAlarm == -1 || targetAlarm == 3)
842 hihiAlarmed_ =
false;
850 char FESlowControlsChannel::checkAlarms(std::string& txBuffer)
864 char createPacketMask = 0;
866 if(dataType_[dataType_.size() - 1] ==
'b')
868 else if(dataType_ ==
"char")
870 else if(dataType_ ==
"unsigned char")
872 else if(dataType_ ==
"short")
874 else if(dataType_ ==
"unsigned short")
876 else if(dataType_ ==
"int")
878 else if(dataType_ ==
"unsigned int")
880 else if(dataType_ ==
"long long")
882 else if(dataType_ ==
"unsigned long long")
884 else if(dataType_ ==
"float")
886 else if(dataType_ ==
"double")
891 __COUT__ <<
"Using unsigned long long for alarms." << std::endl;
893 if((!loloAlarmed_ || !latchAlarms_) &&
894 *((
unsigned long long*)&sample_[0]) <= *((
unsigned long long*)&lolo_[0]))
897 createPacketMask |= 1 << 0;
900 if((!loAlarmed_ || !latchAlarms_) &&
901 *((
unsigned long long*)&sample_[0]) <= *((
unsigned long long*)&lo_[0]))
904 createPacketMask |= 1 << 1;
907 if((!hiAlarmed_ || !latchAlarms_) &&
908 *((
unsigned long long*)&sample_[0]) >= *((
unsigned long long*)&hi_[0]))
911 createPacketMask |= 1 << 2;
914 if((!hihiAlarmed_ || !latchAlarms_) &&
915 *((
unsigned long long*)&sample_[0]) >= *((
unsigned long long*)&hihi_[0]))
918 createPacketMask |= 1 << 3;
921 else if(useType == 1)
923 __COUT__ <<
"Using long long for alarms." << std::endl;
925 if((!loloAlarmed_ || !latchAlarms_) &&
926 *((
long long*)&sample_[0]) <= *((
long long*)&lolo_[0]))
929 createPacketMask |= 1 << 0;
932 if((!loAlarmed_ || !latchAlarms_) &&
933 *((
long long*)&sample_[0]) <= *((
long long*)&lo_[0]))
936 createPacketMask |= 1 << 1;
939 if((!hiAlarmed_ || !latchAlarms_) &&
940 *((
long long*)&sample_[0]) >= *((
long long*)&hi_[0]))
943 createPacketMask |= 1 << 2;
946 if((!hihiAlarmed_ || !latchAlarms_) &&
947 *((
long long*)&sample_[0]) >= *((
long long*)&hihi_[0]))
950 createPacketMask |= 1 << 3;
953 else if(useType == 2)
955 __COUT__ <<
"Using float for alarms." << std::endl;
957 if((!loloAlarmed_ || !latchAlarms_) &&
958 *((
float*)&sample_[0]) <= *((
float*)&lolo_[0]))
961 createPacketMask |= 1 << 0;
964 if((!loAlarmed_ || !latchAlarms_) && *((
float*)&sample_[0]) <= *((
float*)&lo_[0]))
967 createPacketMask |= 1 << 1;
970 if((!hiAlarmed_ || !latchAlarms_) && *((
float*)&sample_[0]) >= *((
float*)&hi_[0]))
973 createPacketMask |= 1 << 2;
976 if((!hihiAlarmed_ || !latchAlarms_) &&
977 *((
float*)&sample_[0]) >= *((
float*)&hihi_[0]))
980 createPacketMask |= 1 << 3;
983 else if(useType == 3)
985 __COUT__ <<
"Using double for alarms." << std::endl;
987 if((!loloAlarmed_ || !latchAlarms_) &&
988 *((
double*)&sample_[0]) <= *((
double*)&lolo_[0]))
991 createPacketMask |= 1 << 0;
994 if((!loAlarmed_ || !latchAlarms_) &&
995 *((
double*)&sample_[0]) <= *((
double*)&lo_[0]))
998 createPacketMask |= 1 << 1;
1001 if((!hiAlarmed_ || !latchAlarms_) &&
1002 *((
double*)&sample_[0]) >= *((
double*)&hi_[0]))
1005 createPacketMask |= 1 << 2;
1008 if((!hihiAlarmed_ || !latchAlarms_) &&
1009 *((
double*)&sample_[0]) >= *((
double*)&hihi_[0]))
1011 hihiAlarmed_ =
true;
1012 createPacketMask |= 1 << 3;
1017 std::string* alarmValueArray[] = {&lolo_, &lo_, &hi_, &hihi_};
1019 if(monitoringEnabled_)
1023 for(
int i = 0; i < 4; ++i, checkMask <<= 1)
1024 if(createPacketMask & checkMask)
1037 __COUT__ <<
"Create packet type " << i + 1
1038 <<
" alarm value = " << *alarmValueArray[i] << std::endl;
1040 __COUT__ <<
"before txBuffer sz=" << txBuffer.size() << std::endl;
1041 txBuffer.push_back(i + 1);
1043 txPacketSequenceNumber_++);
1045 txBuffer.resize(txBuffer.size() +
sizeof(lastSampleTime_));
1046 memcpy(&txBuffer[txBuffer.size() -
sizeof(lastSampleTime_)],
1048 sizeof(lastSampleTime_));
1050 unsigned int tmpSz = fullChannelName_.size();
1052 txBuffer.resize(txBuffer.size() +
sizeof(tmpSz));
1053 memcpy(&txBuffer[txBuffer.size() -
sizeof(tmpSz)], &tmpSz,
sizeof(tmpSz));
1055 txBuffer += fullChannelName_;
1058 (
unsigned char)(*alarmValueArray[i]).size());
1059 txBuffer.push_back((
unsigned char)sizeOfDataTypeBits_);
1061 txBuffer += (*alarmValueArray[i]);
1062 __COUT__ <<
"after txBuffer sz=" << txBuffer.size() << std::endl;
1065 __SS__ <<
"txBuffer: \n";
1066 for(
unsigned int i = 0; i < txBuffer.size(); ++i)
1068 ss << std::hex << (int)((txBuffer[i] >> 4) & 0xF)
1069 << (int)((txBuffer[i]) & 0xF) <<
" " << std::dec;
1074 __COUT__ <<
"\n" << ss.str();
1079 return createPacketMask;