|
| 1 | +#include "ClassFlowControll.h" |
| 2 | + |
| 3 | +#include "ClassLogFile.h" |
| 4 | +#include "time_sntp.h" |
| 5 | +#include "Helper.h" |
| 6 | +#include "server_ota.h" |
| 7 | + |
| 8 | +std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){ |
| 9 | + bool found = false; |
| 10 | + std::string _classname = ""; |
| 11 | + std::string result = ""; |
| 12 | + if (_stepname.compare("[MakeImage]") == 0){ |
| 13 | + _classname = "ClassFlowMakeImage"; |
| 14 | + } |
| 15 | + if (_stepname.compare("[Alignment]") == 0){ |
| 16 | + _classname = "ClassFlowAlignment"; |
| 17 | + } |
| 18 | + if (_stepname.compare("[Digits]") == 0){ |
| 19 | + _classname = "ClassFlowDigit"; |
| 20 | + } |
| 21 | + if (_stepname.compare("[Analog]") == 0){ |
| 22 | + _classname = "ClassFlowAnalog"; |
| 23 | + } |
| 24 | +// std::string zw = "Classname: " + _classname + "\n"; |
| 25 | +// printf(zw.c_str()); |
| 26 | + |
| 27 | + for (int i = 0; i < FlowControll.size(); ++i) |
| 28 | + if (FlowControll[i]->name().compare(_classname) == 0){ |
| 29 | + // printf(FlowControll[i]->name().c_str()); printf("\n"); |
| 30 | + FlowControll[i]->doFlow(""); |
| 31 | + result = FlowControll[i]->getHTMLSingleStep(_host); |
| 32 | + found = true; |
| 33 | + } |
| 34 | + |
| 35 | + return result; |
| 36 | +} |
| 37 | + |
| 38 | +std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital() |
| 39 | +{ |
| 40 | + for (int i = 0; i < FlowControll.size(); ++i) |
| 41 | + if (FlowControll[i]->name().compare("ClassFlowDigit") == 0) |
| 42 | + return ((ClassFlowDigit*) (FlowControll[i]))->GetHTMLInfo(); |
| 43 | + |
| 44 | + std::vector<HTMLInfo*> empty; |
| 45 | + return empty; |
| 46 | +} |
| 47 | + |
| 48 | +std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog() |
| 49 | +{ |
| 50 | + for (int i = 0; i < FlowControll.size(); ++i) |
| 51 | + if (FlowControll[i]->name().compare("ClassFlowAnalog") == 0) |
| 52 | + return ((ClassFlowAnalog*) (FlowControll[i]))->GetHTMLInfo(); |
| 53 | + |
| 54 | + std::vector<HTMLInfo*> empty; |
| 55 | + return empty; |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +void ClassFlowControll::SetInitialParameter(void) |
| 60 | +{ |
| 61 | + AutoStart = false; |
| 62 | + AutoIntervall = 10; |
| 63 | +} |
| 64 | + |
| 65 | +bool ClassFlowControll::isAutoStart(long &_intervall) |
| 66 | +{ |
| 67 | + _intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms |
| 68 | + return AutoStart; |
| 69 | +} |
| 70 | + |
| 71 | +ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type) |
| 72 | +{ |
| 73 | + ClassFlow* cfc = NULL; |
| 74 | + |
| 75 | + _type = trim(_type); |
| 76 | + |
| 77 | + if (_type.compare("[MakeImage]") == 0) |
| 78 | + cfc = new ClassFlowMakeImage(&FlowControll); |
| 79 | + if (_type.compare("[Alignment]") == 0) |
| 80 | + cfc = new ClassFlowAlignment(&FlowControll); |
| 81 | + if (_type.compare("[Analog]") == 0) |
| 82 | + cfc = new ClassFlowAnalog(&FlowControll); |
| 83 | + if (_type.compare("[Digits]") == 0) |
| 84 | + cfc = new ClassFlowDigit(&FlowControll); |
| 85 | + if (_type.compare("[PostProcessing]") == 0) |
| 86 | + { |
| 87 | + cfc = new ClassFlowPostProcessing(&FlowControll); |
| 88 | + flowpostprocessing = (ClassFlowPostProcessing*) cfc; |
| 89 | + } |
| 90 | + |
| 91 | + if (cfc) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll |
| 92 | + FlowControll.push_back(cfc); |
| 93 | + |
| 94 | + if (_type.compare("[AutoTimer]") == 0) |
| 95 | + cfc = this; |
| 96 | + |
| 97 | + if (_type.compare("[Debug]") == 0) |
| 98 | + cfc = this; |
| 99 | + |
| 100 | + return cfc; |
| 101 | +} |
| 102 | + |
| 103 | +void ClassFlowControll::InitFlow(std::string config) |
| 104 | +{ |
| 105 | + string line; |
| 106 | + |
| 107 | + flowpostprocessing = NULL; |
| 108 | + |
| 109 | + ClassFlow* cfc; |
| 110 | + FILE* pFile; |
| 111 | + config = FormatFileName(config); |
| 112 | + pFile = fopen(config.c_str(), "r"); |
| 113 | + |
| 114 | + line = ""; |
| 115 | + |
| 116 | + char zw[1024]; |
| 117 | + if (pFile != NULL) |
| 118 | + { |
| 119 | + fgets(zw, 1024, pFile); |
| 120 | + printf("%s", zw); |
| 121 | + line = std::string(zw); |
| 122 | + } |
| 123 | + |
| 124 | + while ((line.size() > 0) && !(feof(pFile))) |
| 125 | + { |
| 126 | + cfc = CreateClassFlow(line); |
| 127 | + if (cfc) |
| 128 | + { |
| 129 | + cfc->ReadParameter(pFile, line); |
| 130 | + } |
| 131 | + else |
| 132 | + { |
| 133 | + fgets(zw, 1024, pFile); |
| 134 | + printf("%s", zw); |
| 135 | + line = std::string(zw); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + fclose(pFile); |
| 140 | + |
| 141 | +} |
| 142 | + |
| 143 | +std::string ClassFlowControll::getActStatus(){ |
| 144 | + return aktstatus; |
| 145 | +} |
| 146 | + |
| 147 | +bool ClassFlowControll::doFlow(string time) |
| 148 | +{ |
| 149 | + bool result = true; |
| 150 | + std::string zw_time; |
| 151 | + int repeat = 0; |
| 152 | + |
| 153 | + for (int i = 0; i < FlowControll.size(); ++i) |
| 154 | + { |
| 155 | + zw_time = gettimestring("%Y%m%d-%H%M%S"); |
| 156 | + aktstatus = zw_time + ": " + FlowControll[i]->name(); |
| 157 | + string zw = "FlowControll.doFlow - " + FlowControll[i]->name(); |
| 158 | + LogFile.WriteToFile(zw); |
| 159 | + if (!FlowControll[i]->doFlow(time)){ |
| 160 | + repeat++; |
| 161 | + LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt"); |
| 162 | + i = -1; // Soll wieder bei i = 0 anfangen ==> komplett von vorne !!! |
| 163 | + result = false; |
| 164 | + if (repeat > 5) { |
| 165 | + LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot"); |
| 166 | + doReboot(); |
| 167 | + // Schritt wurde 5x wiederholt --> reboot |
| 168 | + } |
| 169 | + } |
| 170 | + else |
| 171 | + { |
| 172 | + result = true; |
| 173 | + } |
| 174 | + } |
| 175 | + zw_time = gettimestring("%Y%m%d-%H%M%S"); |
| 176 | + aktstatus = zw_time + ": Flow is done"; |
| 177 | + return result; |
| 178 | +} |
| 179 | + |
| 180 | +string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false) |
| 181 | +{ |
| 182 | + if (flowpostprocessing) |
| 183 | + return flowpostprocessing->getReadoutParam(_rawvalue, _noerror); |
| 184 | + |
| 185 | + string zw = ""; |
| 186 | + string result = ""; |
| 187 | + |
| 188 | + for (int i = 0; i < FlowControll.size(); ++i) |
| 189 | + { |
| 190 | + zw = FlowControll[i]->getReadout(); |
| 191 | + if (zw.length() > 0) |
| 192 | + { |
| 193 | + if (result.length() == 0) |
| 194 | + result = zw; |
| 195 | + else |
| 196 | + result = result + "\t" + zw; |
| 197 | + } |
| 198 | + } |
| 199 | + |
| 200 | + return result; |
| 201 | +} |
| 202 | + |
| 203 | +string ClassFlowControll::GetPrevalue() |
| 204 | +{ |
| 205 | + if (flowpostprocessing) |
| 206 | + { |
| 207 | + return flowpostprocessing->GetPreValue(); |
| 208 | + } |
| 209 | + |
| 210 | + return std::string(); |
| 211 | +} |
| 212 | + |
| 213 | +std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue) |
| 214 | +{ |
| 215 | + float zw; |
| 216 | + char* p; |
| 217 | + |
| 218 | + _newvalue = trim(_newvalue); |
| 219 | +// printf("Input UpdatePreValue: %s\n", _newvalue.c_str()); |
| 220 | + |
| 221 | + if (_newvalue.compare("0.0") == 0) |
| 222 | + { |
| 223 | + zw = 0; |
| 224 | + } |
| 225 | + else |
| 226 | + { |
| 227 | + zw = strtof(_newvalue.c_str(), &p); |
| 228 | + if (zw == 0) |
| 229 | + return "- Error in String to Value Conversion!!! Must be of format value=123.456"; |
| 230 | + } |
| 231 | + |
| 232 | + |
| 233 | + if (flowpostprocessing) |
| 234 | + { |
| 235 | + flowpostprocessing->SavePreValue(zw); |
| 236 | + return to_string(zw); |
| 237 | + } |
| 238 | + |
| 239 | + return std::string(); |
| 240 | +} |
| 241 | + |
| 242 | +bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) |
| 243 | +{ |
| 244 | + std::vector<string> zerlegt; |
| 245 | + |
| 246 | + aktparamgraph = trim(aktparamgraph); |
| 247 | + |
| 248 | + if (aktparamgraph.size() == 0) |
| 249 | + if (!this->GetNextParagraph(pfile, aktparamgraph)){ |
| 250 | + return false; |
| 251 | + } |
| 252 | + |
| 253 | +// if ((aktparamgraph.compare("[Autotimer]") != 0) && (aktparamgraph.compare("[Debug]") != 0)) // Paragraph passt nich zu MakeImage |
| 254 | + if (aktparamgraph.compare("[Autotimer]") != 0) // Paragraph passt nich zu MakeImage |
| 255 | + return false; |
| 256 | + |
| 257 | +// if ((toUpper(aktparamgraph) != "[AUTOTIMER]") && (toUpper(aktparamgraph) != ("[DEBUG]"))) // Paragraph passt nich zu MakeImage |
| 258 | +// return false; |
| 259 | + |
| 260 | + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) |
| 261 | + { |
| 262 | + zerlegt = this->ZerlegeZeile(aktparamgraph); |
| 263 | + if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1)) |
| 264 | + { |
| 265 | + if (toUpper(zerlegt[1]) == "TRUE") |
| 266 | + { |
| 267 | + AutoStart = true; |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1)) |
| 272 | + { |
| 273 | + AutoIntervall = std::stof(zerlegt[1]); |
| 274 | + } |
| 275 | + |
| 276 | +/* |
| 277 | + if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1)) |
| 278 | + { |
| 279 | + if (toUpper(zerlegt[1]) == "TRUE") |
| 280 | + { |
| 281 | + LogFile.SwitchOnOff(true); |
| 282 | + printf("TurnLogFile On\n"); |
| 283 | + } |
| 284 | + if (toUpper(zerlegt[1]) == "FALSE") |
| 285 | + { |
| 286 | + LogFile.SwitchOnOff(false); |
| 287 | + printf("TurnLogFile Off\n"); |
| 288 | + } |
| 289 | + } |
| 290 | +*/ |
| 291 | + } |
| 292 | + return true; |
| 293 | +} |
| 294 | + |
0 commit comments