This commit is contained in:
maliakal_d 2020-06-23 13:56:45 +02:00
parent 4cbe354396
commit 692ade6c17
3 changed files with 24 additions and 29 deletions

View File

@ -2894,9 +2894,9 @@ int set_pattern_word(int file_des) {
#else #else
int addr = (int)args[0]; int addr = (int)args[0];
uint64_t word = args[1]; 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, 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) { if (Server_VerifyLock() == OK) {
// valid address // valid address
@ -7340,7 +7340,7 @@ int set_veto(int file_des) {
int set_pattern(int file_des) { int set_pattern(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); 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); memset(patwords, 0, sizeof(uint64_t) * MAX_PATTERN_LENGTH);
uint64_t patioctrl = 0; uint64_t patioctrl = 0;
int patlimits[2] = {0, 0}; int patlimits[2] = {0, 0};
@ -7348,7 +7348,8 @@ int set_pattern(int file_des) {
int patnloop[3] = {0, 0, 0}; int patnloop[3] = {0, 0, 0};
int patwait[3] = {0, 0, 0}; int patwait[3] = {0, 0, 0};
uint64_t patwaittime[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(); return printSocketReadError();
if (receiveData(file_des, &patioctrl, sizeof(patioctrl), INT64) < 0) if (receiveData(file_des, &patioctrl, sizeof(patioctrl), INT64) < 0)
return printSocketReadError(); return printSocketReadError();
@ -7368,12 +7369,12 @@ int set_pattern(int file_des) {
#else #else
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
LOG(logINFO, ("Setting Pattern from file\n")); 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) { for (int i = 0; i < MAX_PATTERN_LENGTH; ++i) {
if ((i%10 == 0) && patwords[i] != 0) { if ((i % 10 == 0) && patwords[i] != 0) {
LOG(logINFO, LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n",
("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", i, i, (long long int)patwords[i]));
(long long int)patwords[i]));
} }
writePatternWord(i, patwords[i]); writePatternWord(i, patwords[i]);
} }

View File

@ -1748,25 +1748,20 @@ void Module::setLEDEnable(bool enable) {
void Module::setPattern(const std::string &fname) { void Module::setPattern(const std::string &fname) {
patternParameters pat; patternParameters pat;
memset(&pat, 0, sizeof(pat)); std::ifstream input_file(fname);
std::ifstream input_file;
input_file.open(fname.c_str(), std::ios_base::in);
if (!input_file.is_open()) { if (!input_file.is_open()) {
throw RuntimeError("Could not open pattern file " + fname + throw RuntimeError("Could not open pattern file " + fname +
" for reading"); " for reading");
} }
std::string current_line; for (std::string line; std::getline(input_file, line);) {
while (input_file.good()) { if (line.find('#') != std::string::npos) {
getline(input_file, current_line); line.erase(line.find('#'));
if (current_line.find('#') != std::string::npos) {
current_line.erase(current_line.find('#'));
} }
LOG(logDEBUG1) << "current_line after removing comments:\n\t" LOG(logDEBUG1) << "line after removing comments:\n\t" << line;
<< current_line; if (line.length() > 1) {
if (current_line.length() > 1) {
// convert command and string to a vector // convert command and string to a vector
std::istringstream iss(current_line); std::istringstream iss(line);
auto it = std::istream_iterator<std::string>(iss); auto it = std::istream_iterator<std::string>(iss);
std::vector<std::string> args = std::vector<std::string>( std::vector<std::string> args = std::vector<std::string>(
it, std::istream_iterator<std::string>()); it, std::istream_iterator<std::string>());
@ -1848,7 +1843,6 @@ void Module::setPattern(const std::string &fname) {
} }
} }
} }
input_file.close();
sendToDetector(F_SET_PATTERN, pat, nullptr); sendToDetector(F_SET_PATTERN, pat, nullptr);
} }

View File

@ -442,13 +442,13 @@ typedef struct {
/** pattern structure */ /** pattern structure */
struct patternParameters { struct patternParameters {
uint64_t word[MAX_PATTERN_LENGTH]; uint64_t word[MAX_PATTERN_LENGTH] = {};
uint64_t patioctrl; uint64_t patioctrl{0};
uint32_t patlimits[2]; uint32_t patlimits[2] = {};
uint32_t patloop[6]; uint32_t patloop[6] = {};
uint32_t patnloop[3]; uint32_t patnloop[3] = {};
uint32_t patwait[3]; uint32_t patwait[3] = {};
uint64_t patwaittime[3]; uint64_t patwaittime[3] = {};
} __attribute__((packed)); } __attribute__((packed));
#endif #endif