|
UniSet
2.2.1
|
00001 // ----------------------------------------------------------------------------- 00002 #ifndef IOControl_H_ 00003 #define IOControl_H_ 00004 // ----------------------------------------------------------------------------- 00005 #include <vector> 00006 #include <memory> 00007 #include <deque> 00008 #include <string> 00009 #include "UniXML.h" 00010 #include "PassiveTimer.h" 00011 #include "Trigger.h" 00012 #include "IONotifyController.h" 00013 #include "UniSetObject.h" 00014 #include "Mutex.h" 00015 #include "MessageType.h" 00016 #include "ComediInterface.h" 00017 #include "DigitalFilter.h" 00018 #include "Calibration.h" 00019 #include "SMInterface.h" 00020 #include "SingleProcess.h" 00021 #include "IOController.h" 00022 #include "IOBase.h" 00023 #include "SharedMemory.h" 00024 #include "LogServer.h" 00025 #include "DebugStream.h" 00026 #include "LogAgregator.h" 00027 // ----------------------------------------------------------------------------- 00166 // ----------------------------------------------------------------------------- 00169 class CardList: 00170 public std::vector<ComediInterface*> 00171 { 00172 public: 00173 00174 explicit CardList( int size ) : std::vector<ComediInterface * >(size) { } 00175 00176 ~CardList() 00177 { 00178 for( unsigned int i = 0; i < size(); i++ ) 00179 delete (*this)[i]; 00180 } 00181 00182 inline ComediInterface* getCard(int ncard) 00183 { 00184 if( ncard >= 0 && ncard < (int)size() ) 00185 return (*this)[ncard]; 00186 00187 return NULL; 00188 } 00189 00190 }; 00191 00207 class IOControl: 00208 public UniSetObject 00209 { 00210 public: 00211 IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, const std::shared_ptr<SharedMemory>& shm = nullptr, int numcards = 2, const std::string& prefix = "io" ); 00212 virtual ~IOControl(); 00213 00215 static std::shared_ptr<IOControl> init_iocontrol( int argc, const char* const* argv, 00216 UniSetTypes::ObjectId icID, const std::shared_ptr<SharedMemory>& ic = nullptr, 00217 const std::string& prefix = "io" ); 00219 static void help_print( int argc, const char* const* argv ); 00220 00222 struct IOInfo: 00223 public IOBase 00224 { 00225 // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования 00226 // приходится здесь тоже объявлять разрешенными только операции "перемещения" 00227 IOInfo( const IOInfo& r ) = delete; 00228 IOInfo& operator=(const IOInfo& r) = delete; 00229 IOInfo( IOInfo&& r ) = default; 00230 IOInfo& operator=(IOInfo&& r) = default; 00231 00232 IOInfo(): 00233 subdev(DefaultSubdev), channel(DefaultChannel), 00234 ncard(-1), 00235 aref(0), 00236 range(0), 00237 lamp(false), 00238 no_testlamp(false), 00239 enable_testmode(false), 00240 disable_testmode(false) 00241 {} 00242 00243 00244 int subdev; 00245 int channel; 00246 int ncard; 00254 int aref; 00255 00262 int range; 00263 00264 bool lamp; 00265 bool no_testlamp; 00266 bool enable_testmode; 00267 bool disable_testmode; 00269 friend std::ostream& operator<<(std::ostream& os, IOInfo& inf ); 00270 }; 00271 00272 struct IOPriority 00273 { 00274 IOPriority(int p, int i): 00275 priority(p), index(i) {} 00276 00277 int priority; 00278 int index; 00279 }; 00280 00281 enum TestModeID 00282 { 00283 tmNone = 0, 00284 tmOffPoll = 1, 00285 tmConfigEnable = 2, 00286 tmConfigDisable = 3, 00287 tmOnlyInputs = 4, 00288 tmOnlyOutputs = 5 00289 }; 00290 00291 void execute(); 00292 00293 protected: 00294 00295 void iopoll(); 00296 void ioread( IOInfo* it ); 00297 void check_testlamp(); 00298 void check_testmode(); 00299 void blink(); 00300 00301 // действия при завершении работы 00302 virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) override; 00303 virtual void askSensors( UniversalIO::UIOCommand cmd ); 00304 virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override; 00305 virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override; 00306 virtual void sigterm( int signo ) override; 00307 virtual bool activateObject() override; 00308 00309 // начальная инициализация выходов 00310 void initOutputs(); 00311 00312 // инициализация карты (каналов в/в) 00313 void initIOCard(); 00314 00315 // чтение файла конфигурации 00316 void readConfiguration(); 00317 bool initIOItem( UniXML::iterator& it ); 00318 bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec ); 00319 void buildCardsList(); 00320 00321 void waitSM(); 00322 00323 bool checkCards( const std::string& func = "" ); 00324 00325 xmlNode* cnode = { 0 }; 00327 int polltime = { 150 }; 00328 CardList cards; 00329 bool noCards = { false }; 00330 00331 typedef std::vector<IOInfo> IOMap; 00332 IOMap iomap; 00334 typedef std::deque<IOPriority> PIOMap; 00335 PIOMap pmap; 00337 unsigned int maxItem = { 0 }; 00338 unsigned int maxHalf = { 0 }; 00339 int filtersize = { 0 }; 00340 float filterT = { 0.0 }; 00341 00342 std::string s_field; 00343 std::string s_fvalue; 00344 00345 std::shared_ptr<SMInterface> shm; 00346 UniSetTypes::ObjectId myid = { UniSetTypes::DefaultObjectId }; 00347 std::string prefix; 00348 00349 typedef std::list<IOInfo*> BlinkList; 00350 00351 void addBlink( IOInfo* it, BlinkList& lst ); 00352 void delBlink( IOInfo* it, BlinkList& lst ); 00353 void blink( BlinkList& lst, bool& bstate ); 00354 00355 // обычное мигание 00356 BlinkList lstBlink; 00357 PassiveTimer ptBlink; 00358 bool blink_state = { false }; 00359 00360 // мигание с двойной частотой 00361 BlinkList lstBlink2; 00362 PassiveTimer ptBlink2; 00363 bool blink2_state = { false }; 00364 00365 // мигание с тройной частотой 00366 BlinkList lstBlink3; 00367 PassiveTimer ptBlink3; 00368 bool blink3_state = { false }; 00369 00370 UniSetTypes::ObjectId testLamp_s = { UniSetTypes::DefaultObjectId }; 00371 Trigger trTestLamp; 00372 bool isTestLamp = { false }; 00373 IOController::IOStateList::iterator itTestLamp; 00374 00375 PassiveTimer ptHeartBeat; 00376 UniSetTypes::ObjectId sidHeartBeat; 00377 int maxHeartBeat = { 10 }; 00378 IOController::IOStateList::iterator itHeartBeat; 00379 00380 bool force = { false }; 00381 bool force_out = { false }; 00382 timeout_t smReadyTimeout = { 15000 }; 00383 int defCardNum = { -1 }; 00384 int maxCardNum = { 10 }; 00386 UniSetTypes::uniset_mutex iopollMutex; 00387 std::atomic_bool activated = { false }; 00388 bool readconf_ok = { false }; 00389 int activateTimeout; 00390 UniSetTypes::ObjectId sidTestSMReady = { UniSetTypes::DefaultObjectId }; 00391 bool term = { false }; 00392 00393 00394 UniSetTypes::ObjectId testMode_as = { UniSetTypes::DefaultObjectId }; 00395 IOController::IOStateList::iterator itTestMode; 00396 long testmode = { false }; 00397 long prev_testmode = { false }; 00398 00399 std::shared_ptr<LogAgregator> loga; 00400 std::shared_ptr<DebugStream> iolog; 00401 std::shared_ptr<LogServer> logserv; 00402 std::string logserv_host = {""}; 00403 int logserv_port = {0}; 00404 00405 private: 00406 }; 00407 // ----------------------------------------------------------------------------- 00408 #endif // IOControl_H_ 00409 // -----------------------------------------------------------------------------
1.7.6.1