UniSet  2.6.0
TestProc_SK.h
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; 
00200         // --- end of public variables ---
00201 
00202     protected:
00203         // --- protected variables ---
00204         
00205         
00206         // ---- end of protected variables ----
00207 
00208         
00209         virtual void callback() noexcept override;
00210         virtual void processingMessage( const uniset::VoidMessage* msg ) override;
00211         virtual void sysCommand( const uniset::SystemMessage* sm ){};
00212         virtual void askSensors( UniversalIO::UIOCommand cmd ){}
00213         virtual void sensorInfo( const uniset::SensorMessage* sm ) override{}
00214         virtual void timerInfo( const uniset::TimerMessage* tm ) override{}
00215         virtual void sigterm( int signo ) override;
00216         virtual bool activateObject() override;
00217         virtual std::string getMonitInfo(){ return ""; } 
00219 #ifndef DISABLE_REST_API
00220         virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ){} 
00221         virtual Poco::JSON::Object::Ptr httpDumpIO();
00222         virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p );
00223 #endif
00224 
00225         // Выполнение очередного шага программы
00226         virtual void step(){}
00227 
00228         void preAskSensors( UniversalIO::UIOCommand cmd );
00229         void preSysCommand( const uniset::SystemMessage* sm );
00230         
00231         virtual void testMode( bool state );
00232         void updateOutputs( bool force );
00233 
00234         void waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
00235         uniset::ObjectId getSMTestID();
00236 
00237         void resetMsg();
00238         uniset::Trigger trResetMsg;
00239         uniset::PassiveTimer ptResetMsg;
00240         int resetMsgTime;
00241 
00242         int sleep_msec; 
00243         bool active;
00244 
00245         const std::string argprefix;
00246         uniset::ObjectId smTestID; 
00248         // управление датчиком "сердцебиения"
00249         uniset::PassiveTimer ptHeartBeat;               
00250         uniset::ObjectId idHeartBeat;       
00251         long maxHeartBeat;                      
00253         xmlNode* confnode;
00255         int getIntProp(const std::string& name) { return uniset::uniset_conf()->getIntProp(confnode, name); }
00257         inline const std::string getProp(const std::string& name) { return uniset::uniset_conf()->getProp(confnode, name); }
00258 
00259         uniset::timeout_t smReadyTimeout;   
00260         std::atomic_bool activated;
00261         uniset::timeout_t activateTimeout;  
00262         uniset::PassiveTimer ptStartUpTimeout;  
00263         int askPause; 
00265         IOController_i::SensorInfo si;
00266         bool forceOut; 
00268         std::shared_ptr<uniset::LogAgregator> loga;
00269         std::shared_ptr<DebugStream> mylog;
00270         std::shared_ptr<uniset::LogServer> logserv;
00271         std::string logserv_host = {""};
00272         int logserv_port = {0};
00273 
00274         uniset::VMonitor vmon;
00275 
00276         
00277 
00278     private:
00279         
00280         // --- private variables ---
00281         // --- end of private variables ---
00282 
00283         // предыдущее значение (для работы UpdateValue())
00284         long prev_in_on_s;
00285         long prev_out_lamp_c;
00286         long prev_out_depend_c;
00287         long prev_in_d1_check_s;
00288         long prev_in_d2_check_s;
00289         long prev_out_set_d1_check_s;
00290         long prev_out_set_d2_check_s;
00291         long prev_out_undef_c;
00292         long prev_in_check_undef_s;
00293         long prev_out_t_set_c;
00294         long prev_in_t_check_s;
00295         long prev_out_log_c;
00296         long prev_in_log_s;
00297         
00298         
00299         // Текущее значение (rw-переменные)
00300         long priv_in_on_s;
00301         long priv_in_d1_check_s;
00302         long priv_in_d2_check_s;
00303         long priv_in_check_undef_s;
00304         long priv_in_t_check_s;
00305         long priv_in_log_s;
00306         
00307 
00308         // Используемые идентификаторы сообщений
00309         
00310         // ------------ private функции ---------------
00311         void updatePreviousValues() noexcept;
00312         void preSensorInfo( const uniset::SensorMessage* sm );
00313         void preTimerInfo( const uniset::TimerMessage* tm );
00314         void initFromSM();
00315         void checkSensors();
00316         // --------------------------------------------
00317         
00318         class StatHashFn
00319         {
00320             public:
00321             size_t operator() (const uniset::ObjectId& key) const
00322             {
00323                 return std::hash<long>()(key);
00324             }
00325         };
00326         
00327         std::unordered_map<const uniset::ObjectId,size_t, StatHashFn> smStat; 
00328         size_t processingMessageCatchCount = { 0 }; 
00331         bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
00332 };
00333 
00334 // -----------------------------------------------------------------------------
00335 #endif // TestProc_SK_H_