UniSet  1.4.0
include/IOControl.h
00001 // -----------------------------------------------------------------------------
00002 #ifndef IOControl_H_
00003 #define IOControl_H_
00004 // -----------------------------------------------------------------------------
00005 #include <vector>
00006 #include <list>
00007 #include <string>
00008 #include "UniXML.h"
00009 #include "PassiveTimer.h"
00010 #include "Trigger.h"
00011 #include "IONotifyController.h"
00012 #include "UniSetObject_LT.h"
00013 #include "Mutex.h"
00014 #include "MessageType.h"
00015 #include "ComediInterface.h" 
00016 #include "DigitalFilter.h" 
00017 #include "Calibration.h" 
00018 #include "SMInterface.h" 
00019 #include "SingleProcess.h"
00020 #include "IOController.h" 
00021 #include "IOBase.h" 
00022 #include "SharedMemory.h" 
00023 // -----------------------------------------------------------------------------
00154 // -----------------------------------------------------------------------------
00157 class CardList:
00158     public std::vector<ComediInterface*>
00159 {
00160     public:
00161 
00162         CardList(int size) : std::vector<ComediInterface*>(size) { }
00163 
00164         ~CardList() {
00165             for( unsigned int i=0; i<size(); i++ )
00166                 delete (*this)[i];
00167         }
00168 
00169         inline ComediInterface* getCard(int ncard) {
00170             if( ncard >= 0 && ncard < (int)size() )
00171                 return (*this)[ncard];
00172             return NULL;
00173     }
00174 
00175 };
00176 
00192 class IOControl:
00193     public UniSetObject
00194 {
00195     public:
00196         IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, SharedMemory* ic=0, int numcards=2, const std::string prefix="io" );
00197         virtual ~IOControl();
00198 
00200         static IOControl* init_iocontrol( int argc, const char* const* argv,
00201                                             UniSetTypes::ObjectId icID, SharedMemory* ic=0,
00202                                             const std::string prefix="io" );
00204         static void help_print( int argc, const char* const* argv );
00205 
00206 //      inline std::string getName(){ return myname; }
00207 
00209         struct IOInfo:
00210             public IOBase
00211         {
00212             IOInfo():
00213                 subdev(DefaultSubdev),channel(DefaultChannel),
00214                 ncard(-1),
00215                 aref(0),
00216                 range(0),
00217                 lamp(false),
00218                 no_testlamp(false),
00219                 enable_testmode(false),
00220                 disable_testmode(false)
00221             {}
00222 
00223 
00224             int subdev;     
00225             int channel;    
00226             int ncard;      
00234             int aref;
00235 
00242             int range;
00243 
00244             bool lamp;      
00245             bool no_testlamp; 
00246             bool enable_testmode; 
00247             bool disable_testmode; 
00249             friend std::ostream& operator<<(std::ostream& os, IOInfo& inf );
00250         };
00251 
00252         struct IOPriority
00253         {
00254             IOPriority(int p, int i):
00255                 priority(p),index(i){}
00256                 
00257             int priority;
00258             int index;
00259         };
00260         
00261         enum TestModeID
00262         {
00263             tmNone      = 0,        
00264             tmOffPoll   = 1,        
00265             tmConfigEnable  = 2,    
00266             tmConfigDisable = 3,    
00267             tmOnlyInputs    = 4,    
00268             tmOnlyOutputs   = 5     
00269         };
00270 
00271         void execute();
00272 
00273     protected:
00274 
00275         void iopoll(); 
00276         void ioread( IOInfo* it );
00277         void check_testlamp();
00278         void check_testmode();
00279         void blink();
00280     
00281         // действия при завершении работы
00282         virtual void processingMessage( UniSetTypes::VoidMessage* msg );
00283         virtual void sysCommand( UniSetTypes::SystemMessage* sm );
00284         virtual void askSensors( UniversalIO::UIOCommand cmd );
00285         virtual void sensorInfo( UniSetTypes::SensorMessage* sm );
00286         virtual void timerInfo( UniSetTypes::TimerMessage* tm );
00287         virtual void sigterm( int signo );
00288         virtual bool activateObject();
00289         
00290         // начальная инициализация выходов
00291         void initOutputs();
00292 
00293         // инициализация карты (каналов в/в)
00294         void initIOCard();
00295 
00296         // чтение файла конфигурации
00297         void readConfiguration();
00298         bool initIOItem( UniXML_iterator& it );
00299         bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec );
00300         void buildCardsList();
00301 
00302         void waitSM();
00303 
00304         bool checkCards( const std::string func="" );
00305 
00306 //      std::string myname;
00307         xmlNode* cnode;         
00309         int polltime;           
00310         CardList cards;         
00311         bool noCards;
00312 
00313 
00314         typedef std::vector<IOInfo> IOMap;
00315         IOMap iomap;            
00317         typedef std::list<IOPriority> PIOMap;
00318         PIOMap pmap;    
00320         unsigned int maxItem;   
00321         unsigned int maxHalf;
00322         int filtersize;
00323         float filterT;
00324 
00325         std::string s_field;
00326         std::string s_fvalue;
00327 
00328         SMInterface* shm;         
00329         UniversalInterface ui;
00330         UniSetTypes::ObjectId myid;
00331         std::string prefix;
00332 
00333         typedef std::list<IOInfo*> BlinkList;
00334 
00335         void addBlink( IOInfo* it, BlinkList& lst );
00336         void delBlink( IOInfo* it, BlinkList& lst );
00337         void blink( BlinkList& lst, bool& bstate );
00338 
00339         // обычное мигание
00340         BlinkList lstBlink;
00341         PassiveTimer ptBlink;
00342         bool blink_state;
00343         
00344         // мигание с двойной частотой
00345         BlinkList lstBlink2;
00346         PassiveTimer ptBlink2;
00347         bool blink2_state;
00348 
00349         // мигание с тройной частотой
00350         BlinkList lstBlink3;
00351         PassiveTimer ptBlink3;
00352         bool blink3_state;
00353         
00354         UniSetTypes::ObjectId testLamp_S;
00355         Trigger trTestLamp;
00356         bool isTestLamp;
00357         IOController::DIOStateList::iterator ditTestLamp;
00358 
00359         PassiveTimer ptHeartBeat;
00360         UniSetTypes::ObjectId sidHeartBeat;
00361         int maxHeartBeat;
00362         IOController::AIOStateList::iterator aitHeartBeat;
00363 
00364         bool force;         
00365         bool force_out;     
00366         int smReadyTimeout;     
00367         int defCardNum;     
00368         int maxCardNum;     
00370         UniSetTypes::uniset_mutex iopollMutex;
00371         bool activated;
00372         bool readconf_ok;
00373         int activateTimeout;
00374         UniSetTypes::ObjectId sidTestSMReady;
00375         bool term;
00376 
00377 
00378         UniSetTypes::ObjectId testMode_as;
00379         IOController::AIOStateList::iterator aitTestMode;
00380         long testmode;
00381         long prev_testmode;
00382 
00383     private:
00384 };
00385 // -----------------------------------------------------------------------------
00386 #endif // IOControl_H_
00387 // -----------------------------------------------------------------------------