UniSet 2.32.1
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// -------------------------------------------------------------------------
43#ifndef vmonit
44#define vmonit( var ) vmon.add( #var, var )
45#endif
46// -------------------------------------------------------------------------
47namespace uniset
48{
49 // ---------------------------------------------------------------------
188 // -----------------------------------------------------------------------------
191 class CardList:
192 public std::vector<ComediInterface*>
193 {
194 public:
195
196 explicit CardList( size_t size ) : std::vector<ComediInterface * >(size) { }
197
198 ~CardList()
199 {
200 for( size_t i = 0; i < size(); i++ )
201 delete (*this)[i];
202 }
203
204 inline ComediInterface* getCard( int ncard ) const
205 {
206 if( ncard > 0 && ncard < size() )
207 return (*this)[ncard];
208
209 return nullptr;
210 }
211
212 inline ComediInterface* getCard( size_t ncard ) const
213 {
214 if( ncard < size() )
215 return (*this)[ncard];
216
217 return nullptr;
218 }
219
220 };
221
238 public UniSetObject
239 {
240 public:
241 IOControl( uniset::ObjectId id, uniset::ObjectId icID, const std::shared_ptr<SharedMemory>& shm = nullptr, size_t numcards = 2, const std::string& prefix = "io" );
242 virtual ~IOControl();
243
245 static std::shared_ptr<IOControl> init_iocontrol( int argc, const char* const* argv,
246 uniset::ObjectId icID, const std::shared_ptr<SharedMemory>& ic = nullptr,
247 const std::string& prefix = "io" );
249 static void help_print( int argc, const char* const* argv );
250
251 virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
252
254 struct IOInfo:
255 public IOBase
256 {
257 // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования
258 // приходится здесь тоже объявлять разрешенными только операции "перемещения"
259 IOInfo( const IOInfo& r ) = delete;
260 IOInfo& operator=(const IOInfo& r) = delete;
261 IOInfo( IOInfo&& r ) = default;
262 IOInfo& operator=(IOInfo&& r) = default;
263
264 IOInfo() {}
265
266 int subdev = { DefaultSubdev };
267 int channel = { DefaultChannel };
268 int ncard = { DefaultCard };
276 int aref = { 0 };
277
278 int adelay = { 0 };
286 int range = { 0 };
287
288 bool lamp = { false };
289 bool no_testlamp = { false };
290 bool enable_testmode = { false };
291 bool disable_testmode = { false };
293 friend std::ostream& operator<<(std::ostream& os, const IOInfo& inf );
294 friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<IOInfo>& inf );
295 };
296
298 {
299 IOPriority(size_t p, size_t i):
300 priority(p), index(i) {}
301
302 size_t priority;
303 size_t index;
304 };
305
315
316 protected:
317
318 void iopoll();
319 void ioread( std::shared_ptr<IOInfo>& it );
320 void check_testlamp();
321 void check_testmode();
322 void blink();
323 void iothread();
324
325 // действия при завершении работы
326 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
327 virtual void askSensors( UniversalIO::UIOCommand cmd );
328 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
329 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
330 virtual bool activateObject() override;
331 virtual bool deactivateObject() override;
332
333 // начальная инициализация выходов
334 void initOutputs();
335
336 // инициализация карты (каналов в/в)
337 void initIOCard();
338
339 // чтение файла конфигурации
340 void readConfiguration();
341 bool initIOItem( UniXML::iterator& it );
342 bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
343 void buildCardsList();
344
345 bool waitSM();
346
347 xmlNode* confnode = { 0 };
349 int polltime = { 150 };
351 bool noCards = { false };
352
353 typedef std::vector< std::shared_ptr<IOInfo> > IOMap;
354 IOMap iomap;
356 typedef std::deque<IOPriority> PIOMap;
357 PIOMap pmap;
359 size_t maxItem = { 0 };
360 size_t maxHalf = { 0 };
361 int filtersize = { 0 };
362 float filterT = { 0.0 };
363
364 std::string s_field;
365 std::string s_fvalue;
366
367 std::shared_ptr<SMInterface> shm;
369 std::string prefix;
370
371 typedef std::list<std::shared_ptr<IOInfo>> BlinkList;
372
373 void addBlink( std::shared_ptr<IOInfo>& it, BlinkList& lst );
374 void delBlink( std::shared_ptr<IOInfo>& it, BlinkList& lst );
375 void blink( BlinkList& lst, bool& bstate );
376
377 // обычное мигание
378 BlinkList lstBlink;
379 PassiveTimer ptBlink;
380 bool blink_state = { false };
381
382 // мигание с двойной частотой
383 BlinkList lstBlink2;
384 PassiveTimer ptBlink2;
385 bool blink2_state = { false };
386
387 // мигание с тройной частотой
388 BlinkList lstBlink3;
389 PassiveTimer ptBlink3;
390 bool blink3_state = { false };
391
393 Trigger trTestLamp;
394 bool isTestLamp = { false };
395 IOController::IOStateList::iterator itTestLamp;
396
397 PassiveTimer ptHeartBeat;
398 uniset::ObjectId sidHeartBeat;
399 int maxHeartBeat = { 10 };
400 IOController::IOStateList::iterator itHeartBeat;
401
402 bool force = { false };
403 bool force_out = { false };
404 timeout_t smReadyTimeout = { 15000 };
405 ssize_t defCardNum = { -1 };
406 size_t maxCardNum = { 10 };
408 std::mutex iopollMutex;
409 std::atomic_bool activated = { false };
410 std::atomic_bool cancelled = { false };
411 bool readconf_ok = { false };
412 int activateTimeout;
413 uniset::ObjectId sidTestSMReady = { uniset::DefaultObjectId };
414
416 IOController::IOStateList::iterator itTestMode;
417 long testmode = { false };
418 long prev_testmode = { false };
419
420 std::shared_ptr<LogAgregator> loga;
421 std::shared_ptr<DebugStream> iolog;
422 std::shared_ptr<LogServer> logserv;
423 std::string logserv_host = {""};
424 int logserv_port = {0};
425
426 std::shared_ptr< ThreadCreator<IOControl> > ioThread;
427
428 VMonitor vmon;
429
430 private:
431 };
432 // --------------------------------------------------------------------------
433} // end of namespace uniset
434// -----------------------------------------------------------------------------
435#endif // IOControl_H_
436// -----------------------------------------------------------------------------
Definition IOControl.h:193
Definition ComediInterface.h:29
Definition IOControl.h:239
xmlNode * confnode
Definition IOControl.h:347
PIOMap pmap
Definition IOControl.h:357
void iopoll()
Definition IOControl/iocontrol.cc:492
CardList cards
Definition IOControl.h:350
TestModeID
Definition IOControl.h:307
@ tmConfigEnable
Definition IOControl.h:310
@ tmNone
Definition IOControl.h:308
@ tmOnlyInputs
Definition IOControl.h:312
@ tmConfigDisable
Definition IOControl.h:311
@ tmOnlyOutputs
Definition IOControl.h:313
@ tmOffPoll
Definition IOControl.h:309
ssize_t defCardNum
Definition IOControl.h:405
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:1222
IOMap iomap
Definition IOControl.h:354
static void help_print(int argc, const char *const *argv)
Definition IOControl/iocontrol.cc:1250
timeout_t smReadyTimeout
Definition IOControl.h:404
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации)
Definition IOControl/iocontrol.cc:903
int polltime
Definition IOControl.h:349
bool force_out
Definition IOControl.h:403
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition IOControl/iocontrol.cc:917
size_t maxItem
Definition IOControl.h:359
bool force
Definition IOControl.h:402
std::mutex iopollMutex
Definition IOControl.h:408
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition UniSetObject.h:80
Definition UniXML.h:44
Definition Calibration.h:27
const ObjectId DefaultObjectId
Definition UniSetTypes.h:71
long ObjectId
Definition UniSetTypes_i.idl:30
Definition IOBase.h:35
Definition IOControl.h:256
int range
Definition IOControl.h:286
bool disable_testmode
Definition IOControl.h:291
bool lamp
Definition IOControl.h:288
int aref
Definition IOControl.h:276
bool enable_testmode
Definition IOControl.h:290
bool no_testlamp
Definition IOControl.h:289
int ncard
Definition IOControl.h:268
int channel
Definition IOControl.h:267
int subdev
Definition IOControl.h:266
Definition IOControl.h:298
Definition UniSetTypes_i.idl:65