ClassFlowControll.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #include "ClassFlowControll.h"
  2. #include "ClassLogFile.h"
  3. #include "time_sntp.h"
  4. #include "Helper.h"
  5. std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
  6. bool found = false;
  7. std::string _classname = "";
  8. std::string result = "";
  9. if (_stepname.compare("[MakeImage]") == 0){
  10. _classname = "ClassFlowMakeImage";
  11. }
  12. if (_stepname.compare("[Alignment]") == 0){
  13. _classname = "ClassFlowAlignment";
  14. }
  15. if (_stepname.compare("[Digits]") == 0){
  16. _classname = "ClassFlowDigit";
  17. }
  18. if (_stepname.compare("[Analog]") == 0){
  19. _classname = "ClassFlowAnalog";
  20. }
  21. // std::string zw = "Classname: " + _classname + "\n";
  22. // printf(zw.c_str());
  23. for (int i = 0; i < FlowControll.size(); ++i)
  24. if (FlowControll[i]->name().compare(_classname) == 0){
  25. // printf(FlowControll[i]->name().c_str()); printf("\n");
  26. FlowControll[i]->doFlow("");
  27. result = FlowControll[i]->getHTMLSingleStep(_host);
  28. found = true;
  29. }
  30. return result;
  31. }
  32. std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
  33. {
  34. for (int i = 0; i < FlowControll.size(); ++i)
  35. if (FlowControll[i]->name().compare("ClassFlowDigit") == 0)
  36. return ((ClassFlowDigit*) (FlowControll[i]))->GetHTMLInfo();
  37. std::vector<HTMLInfo*> empty;
  38. return empty;
  39. }
  40. std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog()
  41. {
  42. for (int i = 0; i < FlowControll.size(); ++i)
  43. if (FlowControll[i]->name().compare("ClassFlowAnalog") == 0)
  44. return ((ClassFlowAnalog*) (FlowControll[i]))->GetHTMLInfo();
  45. std::vector<HTMLInfo*> empty;
  46. return empty;
  47. }
  48. void ClassFlowControll::SetInitialParameter(void)
  49. {
  50. AutoStart = false;
  51. AutoIntervall = 10;
  52. }
  53. bool ClassFlowControll::isAutoStart(long &_intervall)
  54. {
  55. _intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms
  56. return AutoStart;
  57. }
  58. ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
  59. {
  60. ClassFlow* cfc = NULL;
  61. _type = trim(_type);
  62. if (_type.compare("[MakeImage]") == 0)
  63. cfc = new ClassFlowMakeImage(&FlowControll);
  64. if (_type.compare("[Alignment]") == 0)
  65. cfc = new ClassFlowAlignment(&FlowControll);
  66. if (_type.compare("[Analog]") == 0)
  67. cfc = new ClassFlowAnalog(&FlowControll);
  68. if (_type.compare("[Digits]") == 0)
  69. cfc = new ClassFlowDigit(&FlowControll);
  70. if (_type.compare("[PostProcessing]") == 0)
  71. {
  72. cfc = new ClassFlowPostProcessing(&FlowControll);
  73. flowpostprocessing = (ClassFlowPostProcessing*) cfc;
  74. }
  75. if (cfc) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
  76. FlowControll.push_back(cfc);
  77. if (_type.compare("[AutoTimer]") == 0)
  78. cfc = this;
  79. return cfc;
  80. }
  81. void ClassFlowControll::InitFlow(std::string config)
  82. {
  83. string line;
  84. flowpostprocessing = NULL;
  85. ClassFlow* cfc;
  86. FILE* pFile;
  87. config = FormatFileName(config);
  88. pFile = fopen(config.c_str(), "r");
  89. line = "";
  90. char zw[1024];
  91. if (pFile != NULL)
  92. {
  93. fgets(zw, 1024, pFile);
  94. printf("%s", zw);
  95. line = std::string(zw);
  96. }
  97. while ((line.size() > 0) && !(feof(pFile)))
  98. {
  99. cfc = CreateClassFlow(line);
  100. if (cfc)
  101. {
  102. cfc->ReadParameter(pFile, line);
  103. }
  104. else
  105. {
  106. fgets(zw, 1024, pFile);
  107. printf("%s", zw);
  108. line = std::string(zw);
  109. }
  110. }
  111. fclose(pFile);
  112. }
  113. std::string ClassFlowControll::getActStatus(){
  114. return aktstatus;
  115. }
  116. bool ClassFlowControll::doFlow(string time)
  117. {
  118. bool result = true;
  119. std::string zw_time;
  120. for (int i = 0; i < FlowControll.size(); ++i)
  121. {
  122. zw_time = gettimestring("%Y%m%d-%H%M%S");
  123. aktstatus = zw_time + ": " + FlowControll[i]->name();
  124. string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
  125. LogFile.WriteToFile(zw);
  126. result = result && FlowControll[i]->doFlow(time);
  127. }
  128. zw_time = gettimestring("%Y%m%d-%H%M%S");
  129. aktstatus = zw_time + ": Flow is done";
  130. return result;
  131. }
  132. string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
  133. {
  134. if (flowpostprocessing)
  135. return flowpostprocessing->getReadoutParam(_rawvalue, _noerror);
  136. string zw = "";
  137. string result = "";
  138. for (int i = 0; i < FlowControll.size(); ++i)
  139. {
  140. zw = FlowControll[i]->getReadout();
  141. if (zw.length() > 0)
  142. {
  143. if (result.length() == 0)
  144. result = zw;
  145. else
  146. result = result + "\t" + zw;
  147. }
  148. }
  149. return result;
  150. }
  151. string ClassFlowControll::GetPrevalue()
  152. {
  153. if (flowpostprocessing)
  154. {
  155. return flowpostprocessing->GetPreValue();
  156. }
  157. return std::string();
  158. }
  159. std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
  160. {
  161. float zw;
  162. char* p;
  163. _newvalue = trim(_newvalue);
  164. // printf("Input UpdatePreValue: %s\n", _newvalue.c_str());
  165. if (_newvalue.compare("0.0") == 0)
  166. {
  167. zw = 0;
  168. }
  169. else
  170. {
  171. zw = strtof(_newvalue.c_str(), &p);
  172. if (zw == 0)
  173. return "- Error in String to Value Conversion!!! Must be of format value=123.456";
  174. }
  175. if (flowpostprocessing)
  176. {
  177. flowpostprocessing->SavePreValue(zw);
  178. return _newvalue;
  179. }
  180. return std::string();
  181. }
  182. bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
  183. {
  184. std::vector<string> zerlegt;
  185. aktparamgraph = trim(aktparamgraph);
  186. if (aktparamgraph.size() == 0)
  187. if (!this->GetNextParagraph(pfile, aktparamgraph))
  188. return false;
  189. if (aktparamgraph.compare("[AutoTimer]") != 0) // Paragraph passt nich zu MakeImage
  190. return false;
  191. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  192. {
  193. zerlegt = this->ZerlegeZeile(aktparamgraph);
  194. if ((zerlegt[0] == "AutoStart") && (zerlegt.size() > 1))
  195. {
  196. if (toUpper(zerlegt[1]) == "TRUE")
  197. {
  198. AutoStart = true;
  199. }
  200. }
  201. if ((zerlegt[0] == "Intervall") && (zerlegt.size() > 1))
  202. {
  203. AutoIntervall = std::stof(zerlegt[1]);
  204. }
  205. }
  206. return true;
  207. }