UniSet  2.24.2
SMemoryTest/TestProc_SK.h
1 
2 // --------------------------------------------------------------------------
3 /*
4  DO NOT EDIT THIS FILE. IT IS AUTOGENERATED FILE.
5  ALL YOUR CHANGES WILL BE LOST.
6 
7  НЕ РЕДАКТИРУЙТЕ ЭТОТ ФАЙЛ. ЭТОТ ФАЙЛ СОЗДАН АВТОМАТИЧЕСКИ.
8  ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
9 */
10 // --------------------------------------------------------------------------
11 // generate timestamp: 2022-11-04
12 // -----------------------------------------------------------------------------
13 #ifndef TestProc_SK_H_
14 #define TestProc_SK_H_
15 // -----------------------------------------------------------------------------
16 #include <memory>
17 #include <string>
18 #include <unordered_map>
19 #include <sstream>
20 #include "UniSetObject.h"
21 #include "UniXML.h"
22 #include "Trigger.h"
23 #include "DebugStream.h"
24 #include "LogServer.h"
25 #include "LogAgregator.h"
26 #include "VMonitor.h"
27 // -----------------------------------------------------------------------------
28 class TestProc_SK:
30 {
31  public:
32  TestProc_SK( uniset::ObjectId id, xmlNode* node=uniset::uniset_conf()->getNode("TestProc"), const std::string& argprefix="", xmlNode* globalConfNode=nullptr );
33  TestProc_SK();
34  virtual ~TestProc_SK();
35 
36 
37  long getValue( uniset::ObjectId sid );
38  void setValue( uniset::ObjectId sid, long value );
39  void askSensor( uniset::ObjectId sid, UniversalIO::UIOCommand, uniset::ObjectId node = uniset::uniset_conf()->getLocalNode() );
40  void updateValues();
41 
42  virtual uniset::SimpleInfo* getInfo( const char* userparam ) override;
43 
44  virtual bool setMsg( uniset::ObjectId code, bool state = true ) noexcept;
45 
46  inline std::shared_ptr<DebugStream> log() noexcept { return mylog; }
47  inline std::shared_ptr<uniset::LogAgregator> logAgregator() noexcept { return loga; }
48 
49  void init_dlog( std::shared_ptr<DebugStream> d ) noexcept;
50 
51  // "синтаксический сахар"..для логов
52  #ifndef myinfo
53  #define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
54  #endif
55  #ifndef mywarn
56  #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
57  #endif
58  #ifndef mycrit
59  #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
60  #endif
61  #ifndef mylog1
62  #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
63  #endif
64  #ifndef mylog2
65  #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
66  #endif
67  #ifndef mylog3
68  #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
69  #endif
70  #ifndef mylog4
71  #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
72  #endif
73  #ifndef mylog5
74  #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
75  #endif
76  #ifndef mylog6
77  #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
78  #endif
79  #ifndef mylog7
80  #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
81  #endif
82  #ifndef mylog8
83  #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
84  #endif
85  #ifndef mylog9
86  #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
87  #endif
88  #ifndef mylogany
89  #define mylogany log()->any()
90  #endif
91  #ifndef vmonit
92  #define vmonit( var ) vmon.add( #var, var )
93  #endif
94 
95  // Вспомогательные функции для удобства логирования
96  // ------------------------------------------------------------
104  std::string dumpIO();
105 
110  std::string str( uniset::ObjectId id, bool showLinkName=true ) const;
111 
116  std::string strval( uniset::ObjectId id, bool showLinkName=true ) const;
117 
122  std::string msgstr( uniset::ObjectId id, bool showLinkName=true ) const;
123 
124 
126  inline std::string dumpVars(){ return vmon.pretty_str(); }
127  // ------------------------------------------------------------
128  std::string help() const noexcept;
129 
130 
131 #ifndef DISABLE_REST_API
132  // HTTP API
133  virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) override;
134  virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override;
135  virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
136 #endif
137 
138 
139  // Используемые идентификаторы
140 
141  const uniset::ObjectId on_s;
142  const uniset::ObjectId node_on_s;
143 
144  const uniset::ObjectId lamp_c;
145  const uniset::ObjectId node_lamp_c;
146 
147  const uniset::ObjectId depend_c;
148  const uniset::ObjectId node_depend_c;
149 
151  const uniset::ObjectId node_d1_check_s;
152 
154  const uniset::ObjectId node_d2_check_s;
155 
157  const uniset::ObjectId node_set_d1_check_s;
158 
160  const uniset::ObjectId node_set_d2_check_s;
161 
162  const uniset::ObjectId undef_c;
163  const uniset::ObjectId node_undef_c;
164 
166  const uniset::ObjectId node_check_undef_s;
167 
168  const uniset::ObjectId t_set_c;
169  const uniset::ObjectId node_t_set_c;
170 
172  const uniset::ObjectId node_t_check_s;
173 
174  const uniset::ObjectId log_c;
175  const uniset::ObjectId node_log_c;
176 
177  const uniset::ObjectId log_s;
178  const uniset::ObjectId node_log_s;
179 
180 
181  // Используемые идентификаторы сообщений
182 
183 
184  // Текущее значение
185  const long& in_on_s;
186  long out_lamp_c;
187  long out_depend_c;
188  const long& in_d1_check_s;
189  const long& in_d2_check_s;
190  long out_set_d1_check_s;
191  long out_set_d2_check_s;
192  long out_undef_c;
193  const long& in_check_undef_s;
194  long out_t_set_c;
195  const long& in_t_check_s;
196  long out_log_c;
197  const long& in_log_s;
198 
199 
200  // --- public variables ---
201 
202  const int changeTime;
203  const int checkWorkingTime;
204  const int checkTime;
205  const int checkLogTime;
207  // --- end of public variables ---
208 
209  protected:
210  // --- protected variables ---
211 
212 
213  // ---- end of protected variables ----
214 
215 
216  virtual void callback() noexcept override;
217  virtual void processingMessage( const uniset::VoidMessage* msg ) override;
218  virtual void sysCommand( const uniset::SystemMessage* sm ) override {}
219  virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
220  virtual void sensorInfo( const uniset::SensorMessage* sm ) override {}
221  virtual void timerInfo( const uniset::TimerMessage* tm ) override {}
222  virtual bool activateObject() override;
223  virtual bool deactivateObject() override;
224  virtual std::string getMonitInfo() const { return ""; }
225  virtual std::string getTypeOfMessage( int t ) const { return uniset::strTypeOfMessage(t); }
227 #ifndef DISABLE_REST_API
228  virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ){}
229  virtual Poco::JSON::Object::Ptr httpDumpIO();
230  virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p );
231  virtual Poco::JSON::Object::Ptr request_params_set( const std::string& req, const Poco::URI::QueryParameters& p ) override;
232  virtual Poco::JSON::Object::Ptr request_params_get( const std::string& req, const Poco::URI::QueryParameters& p ) override;
233 #endif
234 
235  // Выполнение очередного шага программы
236  virtual void step(){}
237 
238  void preAskSensors( UniversalIO::UIOCommand cmd );
239  void preSysCommand( const uniset::SystemMessage* sm );
240 
241  virtual void testMode( bool state );
242  void updateOutputs( bool force );
243 
244  bool waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
245  uniset::ObjectId getSMTestID() const;
246 
247  void resetMsg();
248  uniset::Trigger trResetMsg;
249  uniset::PassiveTimer ptResetMsg;
250  int resetMsgTime;
251 
252  int sleep_msec;
253  bool active;
254 
255  const std::string argprefix;
258  // управление датчиком "сердцебиения"
259  uniset::PassiveTimer ptHeartBeat;
261  long maxHeartBeat;
263  xmlNode* confnode;
265  int getIntProp(const std::string& name) { return uniset::uniset_conf()->getIntProp(confnode, name); }
267  inline const std::string getProp(const std::string& name) { return uniset::uniset_conf()->getProp(confnode, name); }
268 
269  uniset::timeout_t smReadyTimeout;
270  std::atomic_bool activated = { false };
271  std::atomic_bool cancelled = { false };
272  uniset::timeout_t activateTimeout;
274  int askPause;
277  bool forceOut;
279  std::shared_ptr<uniset::LogAgregator> loga;
280  std::shared_ptr<DebugStream> mylog;
281  std::shared_ptr<uniset::LogServer> logserv;
282  std::string logserv_host = {""};
283  int logserv_port = {0};
284 
285  uniset::VMonitor vmon;
286 
287 
288 
289  private:
290 
291  // --- private variables ---
292  // --- end of private variables ---
293 
294  // предыдущее значение (для работы UpdateValue())
295  long prev_in_on_s;
296  long prev_out_lamp_c;
297  long prev_out_depend_c;
298  long prev_in_d1_check_s;
299  long prev_in_d2_check_s;
300  long prev_out_set_d1_check_s;
301  long prev_out_set_d2_check_s;
302  long prev_out_undef_c;
303  long prev_in_check_undef_s;
304  long prev_out_t_set_c;
305  long prev_in_t_check_s;
306  long prev_out_log_c;
307  long prev_in_log_s;
308 
309 
310  // Текущее значение (rw-переменные)
311  long priv_in_on_s;
312  long priv_in_d1_check_s;
313  long priv_in_d2_check_s;
314  long priv_in_check_undef_s;
315  long priv_in_t_check_s;
316  long priv_in_log_s;
317 
318 
319  // Используемые идентификаторы сообщений
320 
321  // ------------ private функции ---------------
322  void updatePreviousValues() noexcept;
323  void preSensorInfo( const uniset::SensorMessage* sm );
324  void preTimerInfo( const uniset::TimerMessage* tm );
325  void initFromSM();
326  void checkSensors();
327  // --------------------------------------------
328 
329  class StatHashFn
330  {
331  public:
332  size_t operator() (const uniset::ObjectId& key) const
333  {
334  return std::hash<long>()(key);
335  }
336  };
337 
338  std::unordered_map<const uniset::ObjectId,size_t, StatHashFn> smStat;
339  size_t processingMessageCatchCount = { 0 };
341  std::unordered_map<long,size_t> msgTypeStat;
343  std::string ostate = { "" };
346  bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
347 };
348 
349 // -----------------------------------------------------------------------------
350 #endif // TestProc_SK_H_
Definition: DebugStream.h:62
Definition: MBSlaveTest/TestProc_SK.h:30
std::string dumpIO()
long maxHeartBeat
Definition: MBSlaveTest/TestProc_SK.h:264
const uniset::ObjectId undef_c
Definition: MBSlaveTest/TestProc_SK.h:162
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации)
const int checkLogTime
Definition: MBSlaveTest/TestProc_SK.h:205
const uniset::ObjectId log_s
Definition: MBSlaveTest/TestProc_SK.h:177
uniset::PassiveTimer ptStartUpTimeout
Definition: MBSlaveTest/TestProc_SK.h:276
const uniset::ObjectId set_d1_check_s
Definition: MBSlaveTest/TestProc_SK.h:156
virtual void callback() noexcept override
virtual void processingMessage(const uniset::VoidMessage *msg) override
const uniset::ObjectId d1_check_s
Definition: MBSlaveTest/TestProc_SK.h:150
int sleep_msec
Definition: MBSlaveTest/TestProc_SK.h:255
virtual void httpGetUserData(Poco::JSON::Object::Ptr &jdata)
Definition: SMemoryTest/TestProc_SK.h:228
std::string msgstr(uniset::ObjectId id, bool showLinkName=true) const
uniset::timeout_t smReadyTimeout
Definition: MBSlaveTest/TestProc_SK.h:272
const uniset::ObjectId t_set_c
Definition: MBSlaveTest/TestProc_SK.h:168
const uniset::ObjectId log_c
Definition: MBSlaveTest/TestProc_SK.h:174
virtual std::string getTypeOfMessage(int t) const
Definition: SMemoryTest/TestProc_SK.h:225
int getIntProp(const std::string &name)
Definition: SMemoryTest/TestProc_SK.h:265
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
const int checkWorkingTime
Definition: MBSlaveTest/TestProc_SK.h:203
const uniset::ObjectId check_undef_s
Definition: MBSlaveTest/TestProc_SK.h:165
const uniset::ObjectId lamp_c
Definition: MBSlaveTest/TestProc_SK.h:144
std::string strval(uniset::ObjectId id, bool showLinkName=true) const
const uniset::ObjectId on_s
Definition: MBSlaveTest/TestProc_SK.h:141
const int checkTime
Definition: MBSlaveTest/TestProc_SK.h:204
const uniset::ObjectId depend_c
Definition: MBSlaveTest/TestProc_SK.h:147
uniset::timeout_t activateTimeout
Definition: MBSlaveTest/TestProc_SK.h:275
const uniset::ObjectId d2_check_s
Definition: MBSlaveTest/TestProc_SK.h:153
const std::string getProp(const std::string &name)
Definition: SMemoryTest/TestProc_SK.h:267
bool forceOut
Definition: MBSlaveTest/TestProc_SK.h:280
const int changeTime
Definition: MBSlaveTest/TestProc_SK.h:202
uniset::ObjectId idHeartBeat
Definition: MBSlaveTest/TestProc_SK.h:263
uniset::ObjectId smTestID
Definition: MBSlaveTest/TestProc_SK.h:259
const uniset::ObjectId t_check_s
Definition: MBSlaveTest/TestProc_SK.h:171
int askPause
Definition: MBSlaveTest/TestProc_SK.h:277
std::string str(uniset::ObjectId id, bool showLinkName=true) const
const uniset::ObjectId set_d2_check_s
Definition: MBSlaveTest/TestProc_SK.h:159
virtual std::string getMonitInfo() const
Definition: SMemoryTest/TestProc_SK.h:224
xmlNode * confnode
Definition: MBSlaveTest/TestProc_SK.h:266
std::string dumpVars()
Definition: SMemoryTest/TestProc_SK.h:126
Пассивный таймер
Definition: PassiveTimer.h:94
Definition: MessageType.h:127
Definition: MessageType.h:171
Definition: MessageType.h:214
Definition: Trigger.h:31
Definition: UniSetObject.h:80
Definition: VMonitor.h:117
std::string pretty_str(int namewidth=NameWidth, int colnum=ColCount) const
Definition: VMonitor.cc:186
Definition: CommonEventLoop.h:15
KeyType key(const uniset::ObjectId id, const uniset::ObjectId node)
Definition: UniSetTypes.cc:746
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:70
std::shared_ptr< Configuration > uniset_conf() noexcept
Definition: Configuration.cc:90
long ObjectId
Definition: UniSetTypes_i.idl:30
Definition: IOController_i.idl:58
Definition: UniSetTypes_i.idl:65