From 692ade6c172839aaead498ab544aa636b66e908a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 23 Jun 2020 13:56:45 +0200 Subject: [PATCH] fix --- .../src/slsDetectorServer_funcs.c | 19 +++++++++--------- slsDetectorSoftware/src/Module.cpp | 20 +++++++------------ slsSupportLib/include/sls_detector_defs.h | 14 ++++++------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index b336cedc6..d2a993028 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -2894,9 +2894,9 @@ int set_pattern_word(int file_des) { #else int addr = (int)args[0]; uint64_t word = args[1]; - if (word != (int64_t)-1) { + if (word != (uint64_t)-1) { LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx\n", addr, - (long long int)word)); + (long long int)word)); } if (Server_VerifyLock() == OK) { // valid address @@ -7340,7 +7340,7 @@ int set_veto(int file_des) { int set_pattern(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - uint64_t* patwords = malloc(sizeof(uint64_t) * MAX_PATTERN_LENGTH); + uint64_t *patwords = malloc(sizeof(uint64_t) * MAX_PATTERN_LENGTH); memset(patwords, 0, sizeof(uint64_t) * MAX_PATTERN_LENGTH); uint64_t patioctrl = 0; int patlimits[2] = {0, 0}; @@ -7348,7 +7348,8 @@ int set_pattern(int file_des) { int patnloop[3] = {0, 0, 0}; int patwait[3] = {0, 0, 0}; uint64_t patwaittime[3] = {0, 0, 0}; - if (receiveData(file_des, patwords, sizeof(uint64_t) * MAX_PATTERN_LENGTH, INT64) < 0) + if (receiveData(file_des, patwords, sizeof(uint64_t) * MAX_PATTERN_LENGTH, + INT64) < 0) return printSocketReadError(); if (receiveData(file_des, &patioctrl, sizeof(patioctrl), INT64) < 0) return printSocketReadError(); @@ -7368,12 +7369,12 @@ int set_pattern(int file_des) { #else if (Server_VerifyLock() == OK) { LOG(logINFO, ("Setting Pattern from file\n")); - LOG(logINFO, ("Setting Pattern Word (printing every 10 words that are not 0\n")); + LOG(logINFO, + ("Setting Pattern Word (printing every 10 words that are not 0\n")); for (int i = 0; i < MAX_PATTERN_LENGTH; ++i) { - if ((i%10 == 0) && patwords[i] != 0) { - LOG(logINFO, - ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", i, - (long long int)patwords[i])); + if ((i % 10 == 0) && patwords[i] != 0) { + LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", + i, (long long int)patwords[i])); } writePatternWord(i, patwords[i]); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 0299e04f6..57c53a688 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1748,25 +1748,20 @@ void Module::setLEDEnable(bool enable) { void Module::setPattern(const std::string &fname) { patternParameters pat; - memset(&pat, 0, sizeof(pat)); - std::ifstream input_file; - input_file.open(fname.c_str(), std::ios_base::in); + std::ifstream input_file(fname); if (!input_file.is_open()) { throw RuntimeError("Could not open pattern file " + fname + " for reading"); } - std::string current_line; - while (input_file.good()) { - getline(input_file, current_line); - if (current_line.find('#') != std::string::npos) { - current_line.erase(current_line.find('#')); + for (std::string line; std::getline(input_file, line);) { + if (line.find('#') != std::string::npos) { + line.erase(line.find('#')); } - LOG(logDEBUG1) << "current_line after removing comments:\n\t" - << current_line; - if (current_line.length() > 1) { + LOG(logDEBUG1) << "line after removing comments:\n\t" << line; + if (line.length() > 1) { // convert command and string to a vector - std::istringstream iss(current_line); + std::istringstream iss(line); auto it = std::istream_iterator(iss); std::vector args = std::vector( it, std::istream_iterator()); @@ -1848,7 +1843,6 @@ void Module::setPattern(const std::string &fname) { } } } - input_file.close(); sendToDetector(F_SET_PATTERN, pat, nullptr); } diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index a673906f5..651e23da6 100644 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -442,13 +442,13 @@ typedef struct { /** pattern structure */ struct patternParameters { - uint64_t word[MAX_PATTERN_LENGTH]; - uint64_t patioctrl; - uint32_t patlimits[2]; - uint32_t patloop[6]; - uint32_t patnloop[3]; - uint32_t patwait[3]; - uint64_t patwaittime[3]; + uint64_t word[MAX_PATTERN_LENGTH] = {}; + uint64_t patioctrl{0}; + uint32_t patlimits[2] = {}; + uint32_t patloop[6] = {}; + uint32_t patnloop[3] = {}; + uint32_t patwait[3] = {}; + uint64_t patwaittime[3] = {}; } __attribute__((packed)); #endif