UniSet @VERSION@
IOControl.h
1/*
2 * Copyright (c) 2015 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// -----------------------------------------------------------------------------
17#ifndef IOControl_H_
18#define IOControl_H_
19// -----------------------------------------------------------------------------
20#include <vector>
21#include <memory>
22#include <deque>
23#include <string>
24#include "UniXML.h"
25#include "ThreadCreator.h"
26#include "PassiveTimer.h"
27#include "Trigger.h"
28#include "IONotifyController.h"
29#include "UniSetObject.h"
30#include "Mutex.h"
31#include "MessageType.h"
32#include "ComediInterface.h"
33#include "DigitalFilter.h"
34#include "Calibration.h"
35#include "SMInterface.h"
36#include "IOController.h"
37#include "IOBase.h"
38#include "SharedMemory.h"
39#include "LogServer.h"
40#include "DebugStream.h"
41#include "LogAgregator.h"
42#include "USingleProcess.h"
43// -------------------------------------------------------------------------
44#ifndef vmonit
45#define vmonit( var ) vmon.add( #var, var )
46#endif
47// -------------------------------------------------------------------------
48namespace uniset
49{
50 // ---------------------------------------------------------------------
189 // -----------------------------------------------------------------------------
192 class CardList:
193 public std::vector<ComediInterface*>
194 {
195 public:
196
197 explicit CardList( size_t size ) : std::vector<ComediInterface * >(size) { }
198
199 ~CardList()
200 {
201 for( size_t i = 0; i < size(); i++ )
202 delete (*this)[i];
203 }
204
205 inline ComediInterface* getCard( int ncard ) const
206 {
207 if( ncard > 0 && ncard < size() )
208 return (*this)[ncard];
209
210 return nullptr;
211 }
212
213 inline ComediInterface* getCard( size_t ncard ) const
214 {
215 if( ncard < size() )
216 return (*this)[ncard];
217
218 return nullptr;
219 }
220
221 };
222
239 private USingleProcess,
240 public UniSetObject
241 {
242 public:
243 IOControl( uniset::ObjectId id, xmlNode* cnode,
244 uniset::ObjectId icID, const std::shared_ptr<SharedMemory>& shm = nullptr, size_t numcards = 2, const std::string& prefix = "io" );
245 virtual ~IOControl();
246
248 static std::shared_ptr<IOControl> init_iocontrol( int argc, const char* const* argv,
249 uniset::ObjectId icID, const std::shared_ptr<SharedMemory>& ic = nullptr,
250 const std::string& prefix = "io" );
252 static void help_print( int argc, const char* const* argv );
253
254 virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
255
257 struct IOInfo:
258 public IOBase
259 {
260 // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования
261 // приходится здесь тоже объявлять разрешенными только операции "перемещения"
262 IOInfo( const IOInfo& r ) = delete;
263 IOInfo& operator=(const IOInfo& r) = delete;
264 IOInfo( IOInfo&& r ) = default;
265 IOInfo& operator=(IOInfo&& r) = default;
266
267 IOInfo() {}
268
269 int subdev = { DefaultSubdev };
270 int channel = { DefaultChannel };
271 int ncard = { DefaultCard };
279 int aref = { 0 };
280
281 int adelay = { 0 };
289 int range = { 0 };
290
291 bool lamp = { false };
292 bool no_testlamp = { false };
293 bool enable_testmode = { false };
294 bool disable_testmode = { false };
296 friend std::ostream& operator<<(std::ostream& os, const IOInfo& inf );
297 friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<IOInfo>& inf );
298 };
299
301 {
302 IOPriority(size_t p, size_t i):
303 priority(p), index(i) {}
304
305 size_t priority;
306 size_t index;
307 };
308
318
319 protected:
320
321 void iopoll();
322 void ioread( std::shared_ptr<IOInfo>& it );
323 void check_testlamp();
324 void check_testmode();
325 void blink();
326 void iothread();
327
328 // действия при завершении работы
329 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
330 virtual void askSensors( UniversalIO::UIOCommand cmd );
331 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
332 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
333 virtual bool activateObject() override;
334 virtual bool deactivateObject() override;
335
336 // начальная инициализация выходов
337 void initOutputs();
338
339 // инициализация карты (каналов в/в)
340 void initIOCard();
341
342 // чтение файла конфигурации
343 void readConfiguration();
344 bool initIOItem( UniXML::iterator& it );
345 bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
346 void buildCardsList();
347
348 bool waitSM();
349
350 xmlNode* confnode = { 0 };
352 int polltime = { 150 };
354 bool noCards = { false };
355
356 typedef std::vector< std::shared_ptr<IOInfo> > IOMap;
357 IOMap iomap;
359 typedef std::deque<IOPriority> PIOMap;
360 PIOMap pmap;
362 size_t maxItem = { 0 };
363 size_t maxHalf = { 0 };
364 int filtersize = { 0 };
365 float filterT = { 0.0 };
366
367 std::string s_field;
368 std::string s_fvalue;
369
370 std::shared_ptr<SMInterface> shm;
372 std::string prefix;
373
374 typedef std::list<std::shared_ptr<IOInfo>> BlinkList;
375
376 void addBlink( std::shared_ptr<IOInfo>& it, BlinkList& lst );
377 void delBlink( std::shared_ptr<IOInfo>& it, BlinkList& lst );
378 void blink( BlinkList& lst, bool& bstate );
379
380 // обычное мигание
381 BlinkList lstBlink;
382 PassiveTimer ptBlink;
383 bool blink_state = { false };
384
385 // мигание с двойной частотой
386 BlinkList lstBlink2;
387 PassiveTimer ptBlink2;
388 bool blink2_state = { false };
389
390 // мигание с тройной частотой
391 BlinkList lstBlink3;
392 PassiveTimer ptBlink3;
393 bool blink3_state = { false };
394
396 Trigger trTestLamp;
397 bool isTestLamp = { false };
398 IOController::IOStateList::iterator itTestLamp;
399
400 PassiveTimer ptHeartBeat;
401 uniset::ObjectId sidHeartBeat;
402 int maxHeartBeat = { 10 };
403 IOController::IOStateList::iterator itHeartBeat;
404
405 bool force = { false };
406 bool force_out = { false };
407 timeout_t smReadyTimeout = { 15000 };
408 ssize_t defCardNum = { -1 };
409 size_t maxCardNum = { 10 };
411 std::mutex iopollMutex;
412 std::atomic_bool activated = { false };
413 std::atomic_bool cancelled = { false };
414 bool readconf_ok = { false };
415 int activateTimeout;
416 uniset::ObjectId sidTestSMReady = { uniset::DefaultObjectId };
417
419 IOController::IOStateList::iterator itTestMode;
420 long testmode = { false };
421 long prev_testmode = { false };
422
423 std::shared_ptr<LogAgregator> loga;
424 std::shared_ptr<DebugStream> iolog;
425 std::shared_ptr<LogServer> logserv;
426 std::string logserv_host = {""};
427 int logserv_port = {0};
428
429 std::shared_ptr< ThreadCreator<IOControl> > ioThread;
430
431 VMonitor vmon;
432
433 private:
434 };
435 // --------------------------------------------------------------------------
436} // end of namespace uniset
437// -----------------------------------------------------------------------------
438#endif // IOControl_H_
439// -----------------------------------------------------------------------------
Definition IOControl.h:194
Definition ComediInterface.h:29
Definition IOControl.h:241
xmlNode * confnode
Definition IOControl.h:350
PIOMap pmap
Definition IOControl.h:360
void iopoll()
Definition IOControl/IOControl.cc:493
CardList cards
Definition IOControl.h:353
TestModeID
Definition IOControl.h:310
@ tmConfigEnable
Definition IOControl.h:313
@ tmNone
Definition IOControl.h:311
@ tmOnlyInputs
Definition IOControl.h:315
@ tmConfigDisable
Definition IOControl.h:314
@ tmOnlyOutputs
Definition IOControl.h:316
@ tmOffPoll
Definition IOControl.h:312
ssize_t defCardNum
Definition IOControl.h:408
static std::shared_ptr< IOControl > init_iocontrol(int argc, const char *const *argv, uniset::ObjectId icID, const std::shared_ptr< SharedMemory > &ic=nullptr, const std::string &prefix="io")
Definition IOControl/IOControl.cc:1227
IOMap iomap
Definition IOControl.h:357
static void help_print(int argc, const char *const *argv)
Definition IOControl/IOControl.cc:1263
timeout_t smReadyTimeout
Definition IOControl.h:407
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации)
Definition IOControl/IOControl.cc:908
int polltime
Definition IOControl.h:352
bool force_out
Definition IOControl.h:406
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition IOControl/IOControl.cc:922
size_t maxItem
Definition IOControl.h:362
bool force
Definition IOControl.h:405
std::mutex iopollMutex
Definition IOControl.h:411
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition USingleProcess.h:28
Definition UniSetObject.h:80
Definition UniXML.h:44
Definition AccessConfig.h:30
const ObjectId DefaultObjectId
Definition UniSetTypes.h:71
long ObjectId
Definition UniSetTypes_i.idl:30
Definition IOBase.h:35
Definition IOControl.h:259
int range
Definition IOControl.h:289
bool disable_testmode
Definition IOControl.h:294
bool lamp
Definition IOControl.h:291
int aref
Definition IOControl.h:279
bool enable_testmode
Definition IOControl.h:293
bool no_testlamp
Definition IOControl.h:292
int ncard
Definition IOControl.h:271
int channel
Definition IOControl.h:270
int subdev
Definition IOControl.h:269
Definition IOControl.h:301
Definition UniSetTypes_i.idl:65