uniset-algorithms  0.2
Automat.h
00001 
00019 // подразделы сформируются автоматически из описаний сделанных в соответствующих h-файлах
00020 // ------------------------------------------------------------------------------------------
00021 #ifndef Automat_H_
00022 #define Automat_H_
00023 // ------------------------------------------------------------------------------------------
00024 #include <TriggerOutput.h>
00025 #include <TriggerOR.h>
00026 #include <ObjectsManager.h>
00027 #include <DebugStream.h>
00028 #include <SandClock.h>
00029 #include "AutomatMessages.h" 
00030 #include "Automat_SK.h"
00031 // ------------------------------------------------------------------------------------------
00032 class AutomatMode;
00033 class AutomatWaitingMode;
00034 
00036 class Automat:
00037     public Automat_SK
00038 {
00039     public:
00040         Automat( const std::string qname, ObjectsManager* master, xmlNode* node );
00041         ~Automat();
00042 
00043         virtual char* getName();
00044 
00045         void on();
00046         void off();
00047         void reset();
00048 
00049         void offOnlyMode();
00050         void onControl();
00051         void offControl();
00052 
00053         inline bool isProtection() { return protection; }
00054         bool getState();
00055         bool isOnMode();
00056         bool checkNAState( bool commit = true ); // проверка противоречивого состояния б/к
00057         
00058         bool getRealState();
00059         
00060         inline long getMode(){ return out_state_as; }
00061 
00062         // таймеры
00063         enum Timers
00064         {
00065             OnTimer,
00066             OffTimer,
00067             CheckState
00068         };
00069 
00070 
00071         ObjectsManager* master;
00072         TriggerOutput<Automat, UniSetTypes::ObjectId, bool>* out;
00073         TriggerOutput<Automat, Automat::Timers, int>* tm;
00074         TriggerOR<Automat,UniSetTypes::ObjectId>* protect; 
00077         TriggerOutput<Automat, UniSetTypes::ObjectId, bool>* msg;
00078 
00079         friend std::ostream& operator<<(std::ostream& os, Automat& am );
00080         friend std::ostream& operator<<(std::ostream& os, Automat* am );
00081 
00082         inline unsigned int getNumber(){ return num; }
00083 
00084         SandClock scUnknown; 
00086         static DebugStream dlog;
00087         static void init_dlog( DebugStream& dlog );
00088 
00089     protected:
00090         Automat();
00091 
00092         virtual void step();
00093         
00094         virtual void processingMessage( UniSetTypes::VoidMessage *msg );
00095 //      void askSensors( UniversalIO::UIOCommand cmd );
00096         void sysCommand( UniSetTypes::SystemMessage *sm );
00097         void sensorInfo( UniSetTypes::SensorMessage *sm );
00098         void timerInfo( UniSetTypes::TimerMessage *tm );
00099         void automatCommand( AutomatMessage* m );
00100 
00101         void changeMode( AutomatMode* m );
00102 
00103         void setProtection( bool st );
00104         void setOut(UniSetTypes::ObjectId sid, bool state);
00105         void setTimer(Automat::Timers tid, int val);
00106         virtual void sigterm( int signo );
00107 
00108     private:
00109 
00110     
00111         AutomatMode* mode;
00112         bool protection;
00113         unsigned int num;
00114         
00115         friend class AutomatMode;
00116         friend class AutomatWaitingMode;
00117         // Для переходных режимов
00118         
00119         int attemptCounter;                             // счётчик неудачных попыток перехода
00120         int attempt;                                    // попытка       
00121         AutomatMessage::Commands command;   // в какой режим перейти
00122         AutomatMessage::Commands prevCmd; // предидущая команда
00123         AutomatMode* backMode;                          // из какого ушли
00124 
00125 };
00126 // ------------------------------------------------------------------------------------------
00127 #endif // Automat_H_
00128 // ------------------------------------------------------------------------------------------