|
UniSet
2.6.0
|
00001 00002 // -------------------------------------------------------------------------- 00003 /* 00004 DO NOT EDIT THIS FILE. IT IS AUTOGENERATED FILE. 00005 ALL YOUR CHANGES WILL BE LOST. 00006 00007 НЕ РЕДАКТИРУЙТЕ ЭТОТ ФАЙЛ. ЭТОТ ФАЙЛ СОЗДАН АВТОМАТИЧЕСКИ. 00008 ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ. 00009 */ 00010 // -------------------------------------------------------------------------- 00011 // generate timestamp: 2016-12-09 00012 // ----------------------------------------------------------------------------- 00013 #ifndef TestProc_SK_H_ 00014 #define TestProc_SK_H_ 00015 // ----------------------------------------------------------------------------- 00016 #include <memory> 00017 #include <string> 00018 #include <unordered_map> 00019 #include <sstream> 00020 #include "UniSetObject.h" 00021 #include "UniXML.h" 00022 #include "Trigger.h" 00023 #include "DebugStream.h" 00024 #include "LogServer.h" 00025 #include "LogAgregator.h" 00026 #include "VMonitor.h" 00027 // ----------------------------------------------------------------------------- 00028 class TestProc_SK: 00029 public uniset::UniSetObject 00030 { 00031 public: 00032 TestProc_SK( uniset::ObjectId id, xmlNode* node=uniset::uniset_conf()->getNode("TestProc"), const std::string& argprefix="" ); 00033 TestProc_SK(); 00034 virtual ~TestProc_SK(); 00035 00036 00037 long getValue( uniset::ObjectId sid ); 00038 void setValue( uniset::ObjectId sid, long value ); 00039 void askSensor( uniset::ObjectId sid, UniversalIO::UIOCommand, uniset::ObjectId node = uniset::uniset_conf()->getLocalNode() ); 00040 void updateValues(); 00041 00042 virtual uniset::SimpleInfo* getInfo( const char* userparam ) override; 00043 00044 virtual bool setMsg( uniset::ObjectId code, bool state = true ) noexcept; 00045 00046 inline std::shared_ptr<DebugStream> log() noexcept { return mylog; } 00047 inline std::shared_ptr<uniset::LogAgregator> logAgregator() noexcept { return loga; } 00048 00049 void init_dlog( std::shared_ptr<DebugStream> d ) noexcept; 00050 00051 // "синтаксический сахар"..для логов 00052 #ifndef myinfo 00053 #define myinfo if( log()->debugging(Debug::INFO) ) log()->info() 00054 #endif 00055 #ifndef mywarn 00056 #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn() 00057 #endif 00058 #ifndef mycrit 00059 #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit() 00060 #endif 00061 #ifndef mylog1 00062 #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1() 00063 #endif 00064 #ifndef mylog2 00065 #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2() 00066 #endif 00067 #ifndef mylog3 00068 #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3() 00069 #endif 00070 #ifndef mylog4 00071 #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4() 00072 #endif 00073 #ifndef mylog5 00074 #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5() 00075 #endif 00076 #ifndef mylog6 00077 #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6() 00078 #endif 00079 #ifndef mylog7 00080 #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7() 00081 #endif 00082 #ifndef mylog8 00083 #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8() 00084 #endif 00085 #ifndef mylog9 00086 #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9() 00087 #endif 00088 #ifndef mylogany 00089 #define mylogany log()->any() 00090 #endif 00091 #ifndef vmonit 00092 #define vmonit( var ) vmon.add( #var, var ) 00093 #endif 00094 00095 // Вспомогательные функции для удобства логирования 00096 // ------------------------------------------------------------ 00104 std::string dumpIO(); 00105 00110 std::string str( uniset::ObjectId id, bool showLinkName=true ) const; 00111 00116 std::string strval( uniset::ObjectId id, bool showLinkName=true ) const; 00117 00119 inline std::string dumpVars(){ return std::move(vmon.pretty_str()); } 00120 // ------------------------------------------------------------ 00121 std::string help() noexcept; 00122 00123 00124 #ifndef DISABLE_REST_API 00125 // HTTP API 00126 virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) override; 00127 virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override; 00128 virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override; 00129 #endif 00130 00131 00132 // Используемые идентификаторы 00133 00134 const uniset::ObjectId on_s; 00135 const uniset::ObjectId node_on_s; 00136 00137 const uniset::ObjectId lamp_c; 00138 const uniset::ObjectId node_lamp_c; 00139 00140 const uniset::ObjectId depend_c; 00141 const uniset::ObjectId node_depend_c; 00142 00143 const uniset::ObjectId d1_check_s; 00144 const uniset::ObjectId node_d1_check_s; 00145 00146 const uniset::ObjectId d2_check_s; 00147 const uniset::ObjectId node_d2_check_s; 00148 00149 const uniset::ObjectId set_d1_check_s; 00150 const uniset::ObjectId node_set_d1_check_s; 00151 00152 const uniset::ObjectId set_d2_check_s; 00153 const uniset::ObjectId node_set_d2_check_s; 00154 00155 const uniset::ObjectId undef_c; 00156 const uniset::ObjectId node_undef_c; 00157 00158 const uniset::ObjectId check_undef_s; 00159 const uniset::ObjectId node_check_undef_s; 00160 00161 const uniset::ObjectId t_set_c; 00162 const uniset::ObjectId node_t_set_c; 00163 00164 const uniset::ObjectId t_check_s; 00165 const uniset::ObjectId node_t_check_s; 00166 00167 const uniset::ObjectId log_c; 00168 const uniset::ObjectId node_log_c; 00169 00170 const uniset::ObjectId log_s; 00171 const uniset::ObjectId node_log_s; 00172 00173 00174 // Используемые идентификаторы сообщений 00175 00176 00177 // Текущее значение 00178 const long& in_on_s; 00179 long out_lamp_c; 00180 long out_depend_c; 00181 const long& in_d1_check_s; 00182 const long& in_d2_check_s; 00183 long out_set_d1_check_s; 00184 long out_set_d2_check_s; 00185 long out_undef_c; 00186 const long& in_check_undef_s; 00187 long out_t_set_c; 00188 const long& in_t_check_s; 00189 long out_log_c; 00190 const long& in_log_s; 00191 00192 00193 // --- public variables --- 00194 00195 const int changeTime; 00196 const int checkWorkingTime; 00197 const int checkTime; 00198 const int checkLogTime; 00199 const std::string mbIP; 00200 const int mbADDR; 00201 int mbPort; 00203 // --- end of public variables --- 00204 00205 protected: 00206 // --- protected variables --- 00207 00208 00209 // ---- end of protected variables ---- 00210 00211 00212 virtual void callback() noexcept override; 00213 virtual void processingMessage( const uniset::VoidMessage* msg ) override; 00214 virtual void sysCommand( const uniset::SystemMessage* sm ){}; 00215 virtual void askSensors( UniversalIO::UIOCommand cmd ){} 00216 virtual void sensorInfo( const uniset::SensorMessage* sm ) override{} 00217 virtual void timerInfo( const uniset::TimerMessage* tm ) override{} 00218 virtual void sigterm( int signo ) override; 00219 virtual bool activateObject() override; 00220 virtual std::string getMonitInfo(){ return ""; } 00222 #ifndef DISABLE_REST_API 00223 virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ){} 00224 virtual Poco::JSON::Object::Ptr httpDumpIO(); 00225 virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p ); 00226 #endif 00227 00228 // Выполнение очередного шага программы 00229 virtual void step(){} 00230 00231 void preAskSensors( UniversalIO::UIOCommand cmd ); 00232 void preSysCommand( const uniset::SystemMessage* sm ); 00233 00234 virtual void testMode( bool state ); 00235 void updateOutputs( bool force ); 00236 00237 void waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId ); 00238 uniset::ObjectId getSMTestID(); 00239 00240 void resetMsg(); 00241 uniset::Trigger trResetMsg; 00242 uniset::PassiveTimer ptResetMsg; 00243 int resetMsgTime; 00244 00245 int sleep_msec; 00246 bool active; 00247 00248 const std::string argprefix; 00249 uniset::ObjectId smTestID; 00251 // управление датчиком "сердцебиения" 00252 uniset::PassiveTimer ptHeartBeat; 00253 uniset::ObjectId idHeartBeat; 00254 long maxHeartBeat; 00256 xmlNode* confnode; 00258 int getIntProp(const std::string& name) { return uniset::uniset_conf()->getIntProp(confnode, name); } 00260 inline const std::string getProp(const std::string& name) { return uniset::uniset_conf()->getProp(confnode, name); } 00261 00262 uniset::timeout_t smReadyTimeout; 00263 std::atomic_bool activated; 00264 uniset::timeout_t activateTimeout; 00265 uniset::PassiveTimer ptStartUpTimeout; 00266 int askPause; 00268 IOController_i::SensorInfo si; 00269 bool forceOut; 00271 std::shared_ptr<uniset::LogAgregator> loga; 00272 std::shared_ptr<DebugStream> mylog; 00273 std::shared_ptr<uniset::LogServer> logserv; 00274 std::string logserv_host = {""}; 00275 int logserv_port = {0}; 00276 00277 uniset::VMonitor vmon; 00278 00279 00280 00281 private: 00282 00283 // --- private variables --- 00284 // --- end of private variables --- 00285 00286 // предыдущее значение (для работы UpdateValue()) 00287 long prev_in_on_s; 00288 long prev_out_lamp_c; 00289 long prev_out_depend_c; 00290 long prev_in_d1_check_s; 00291 long prev_in_d2_check_s; 00292 long prev_out_set_d1_check_s; 00293 long prev_out_set_d2_check_s; 00294 long prev_out_undef_c; 00295 long prev_in_check_undef_s; 00296 long prev_out_t_set_c; 00297 long prev_in_t_check_s; 00298 long prev_out_log_c; 00299 long prev_in_log_s; 00300 00301 00302 // Текущее значение (rw-переменные) 00303 long priv_in_on_s; 00304 long priv_in_d1_check_s; 00305 long priv_in_d2_check_s; 00306 long priv_in_check_undef_s; 00307 long priv_in_t_check_s; 00308 long priv_in_log_s; 00309 00310 00311 // Используемые идентификаторы сообщений 00312 00313 // ------------ private функции --------------- 00314 void updatePreviousValues() noexcept; 00315 void preSensorInfo( const uniset::SensorMessage* sm ); 00316 void preTimerInfo( const uniset::TimerMessage* tm ); 00317 void initFromSM(); 00318 void checkSensors(); 00319 // -------------------------------------------- 00320 00321 class StatHashFn 00322 { 00323 public: 00324 size_t operator() (const uniset::ObjectId& key) const 00325 { 00326 return std::hash<long>()(key); 00327 } 00328 }; 00329 00330 std::unordered_map<const uniset::ObjectId,size_t, StatHashFn> smStat; 00331 size_t processingMessageCatchCount = { 0 }; 00334 bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода) 00335 }; 00336 00337 // ----------------------------------------------------------------------------- 00338 #endif // TestProc_SK_H_
1.7.6.1