UniSet  2.8.0
IOBase.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 IOBase_H_
18 #define IOBase_H_
19 // -----------------------------------------------------------------------------
20 #include <string>
21 #include <memory>
22 #include "PassiveTimer.h"
23 #include "Trigger.h"
24 #include "Mutex.h"
25 #include "DigitalFilter.h"
26 #include "Calibration.h"
27 #include "IOController.h"
28 #include "SMInterface.h"
29 // -------------------------------------------------------------------------
30 namespace uniset
31 {
32  // -----------------------------------------------------------------------------
34  struct IOBase
35  {
36  static const int DefaultSubdev = -1;
37  static const int DefaultChannel = -1;
38  static const int DefaultCard = -1;
39 
40  // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования
41  // приходится здесь тоже объявлять разрешенными только операции "перемещения"
42  IOBase( const IOBase& r ) = delete;
43  IOBase& operator=(const IOBase& r) = delete;
44 
45  IOBase( IOBase&& r ) = default;
46  IOBase& operator=(IOBase&& r) = default;
47 
48  ~IOBase();
49  IOBase():
50  stype(UniversalIO::UnknownIOType),
51  cdiagram(nullptr),
52  breaklim(0),
53  value(0),
54  craw(0),
55  cprev(0),
56  safeval(0),
57  defval(0),
58  df(1),
59  nofilter(false),
60  f_median(false),
61  f_ls(false),
62  f_filter_iir(false),
63  ignore(false),
64  invert(false),
65  noprecision(false),
66  calcrop(true),
67  debounce_pause(false),
68  debounce_state(false),
69  ondelay_state(false),
70  offdelay_state(false),
72  d_value(1),
73  d_off_value(0),
74  d_iotype(UniversalIO::UnknownIOType),
76  front(false),
77  front_type(ftUnknown),
78  front_prev_state(false),
79  front_state(false),
80  rawdata(false)
81  {
85  ti.invert = false;
86  ti.hilimit = 0;
87  ti.lowlimit = 0;
90  ti.tv_sec = 0;
91  ti.tv_nsec = 0;
92  }
93 
94  bool check_channel_break( long val );
96  bool check_debounce( bool val );
97  bool check_on_delay( bool val );
98  bool check_off_delay( bool val );
99  bool check_front( bool val );
100  bool check_depend( const std::shared_ptr<SMInterface>& shm );
103  UniversalIO::IOType stype;
107  long breaklim;
108  long value;
109  long craw;
110  long cprev;
111  long safeval;
112  long defval;
113  bool safevalDefined = { false };
116  bool nofilter;
117  bool f_median;
118  bool f_ls;
121  bool ignore;
122  bool invert;
123  bool noprecision;
124  bool calcrop;
130  Trigger trOnDelay;
131  Trigger trOffDelay;
132  Trigger trdebounce;
133 
134  bool debounce_pause;
139  // Зависимость (d - depend)
141  IOController::IOStateList::iterator d_it;
142  long d_value;
143  long d_off_value;
144  UniversalIO::IOType d_iotype;
145 
146  // Порог
152  IOController::IOStateList::iterator t_ait; // итератор для аналогового датчика
153 
154  // Работа по фронтам сигнала
155  enum FrontType
156  {
157  ftUnknown,
158  ft01, // срабатывание на переход "0-->1"
159  ft10 // срабатывание на переход "1-->0"
160  };
161 
162  friend std::ostream& operator<<( std::ostream& os, const FrontType& f );
163 
164  bool front; // флаг работы по фронту
165  FrontType front_type;
166  bool front_prev_state;
167  bool front_state;
168 
169  bool rawdata; // флаг для сохранения данный в таком виде в каком они пришли (4байта просто копируются в long). Актуально для Vtypes::F4.
170 
171  IOController::IOStateList::iterator ioit;
174  IOBase make_iobase_copy();
175  void create_from_iobase( const IOBase& b );
176 
177  friend std::ostream& operator<<(std::ostream& os, const IOBase& inf );
178 
179  static void processingF64asAI( IOBase* it, double new_val, const std::shared_ptr<SMInterface>& shm, bool force );
180  static void processingFasAI( IOBase* it, float new_val, const std::shared_ptr<SMInterface>& shm, bool force );
181  static void processingAsAI( IOBase* it, long new_val, const std::shared_ptr<SMInterface>& shm, bool force );
182  static void processingAsDI( IOBase* it, bool new_set, const std::shared_ptr<SMInterface>& shm, bool force );
183  static long processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
184  static float processingFasAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
185  static double processingF64asAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
186  static bool processingAsDO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
187  static void processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
188 
192  static bool initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm,
193  const std::string& prefix, bool init_prefix_only,
194  std::shared_ptr<DebugStream> dlog = nullptr, std::string myname = "",
195  int def_filtersize = 0, float def_filterT = 0.0,
196  float def_lsparam = 0.2, float def_iir_coeff_prev = 0.5,
197  float def_iir_coeff_new = 0.5 );
198 
199 
200  // helpes
201  static std::string initProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const std::string& defval = "" );
202  static int initIntProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const int defval = 0 );
203  static timeout_t initTimeoutProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const timeout_t defval);
204  };
205  // --------------------------------------------------------------------------
206 } // end of namespace uniset
207 // -----------------------------------------------------------------------------
208 #endif // IOBase_H_
209 // -----------------------------------------------------------------------------
Пассивный таймер
Definition: PassiveTimer.h:92
long craw
Definition: IOBase.h:109
unsigned long tv_nsec
Definition: IOController_i.idl:211
long cprev
Definition: IOBase.h:110
bool calcrop
Definition: IOBase.h:124
Definition: CommonEventLoop.h:14
Definition: UniXML.h:43
long d_off_value
Definition: IOBase.h:143
short precision
Definition: IOController_i.idl:85
PassiveTimer ptOffDelay
Definition: IOBase.h:128
bool check_debounce(bool val)
Definition: IOBase.cc:103
long minCal
Definition: IOController_i.idl:83
unsigned long tv_sec
Definition: IOController_i.idl:210
Definition: IOController_i.idl:204
bool check_front(bool val)
Definition: IOBase.cc:175
long safeval
Definition: IOBase.h:111
bool check_on_delay(bool val)
Definition: IOBase.cc:134
long value
Definition: IOBase.h:108
long maxRaw
Definition: IOController_i.idl:82
uniset::ObjectId d_id
Definition: IOBase.h:140
bool check_off_delay(bool val)
Definition: IOBase.cc:155
bool offdelay_state
Definition: IOBase.h:137
bool f_filter_iir
Definition: IOBase.h:119
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
bool debounce_state
Definition: IOBase.h:135
uniset::uniset_rwmutex val_lock
Definition: IOBase.h:172
Calibration * cdiagram
Definition: IOBase.h:105
bool f_ls
Definition: IOBase.h:118
long breaklim
Definition: IOBase.h:107
PassiveTimer ptDebounce
Definition: IOBase.h:126
Definition: Trigger.h:29
PassiveTimer ptOnDelay
Definition: IOBase.h:127
Definition: Calibration.h:79
uniset::ObjectId node
Definition: IOController_i.idl:60
DigitalFilter df
Definition: IOBase.h:115
UniversalIO::IOType stype
Definition: IOBase.h:103
long minRaw
Definition: IOController_i.idl:81
long lowlimit
Definition: IOController_i.idl:208
long d_value
Definition: IOBase.h:142
uniset::ObjectId t_ai
Definition: IOBase.h:147
Definition: DigitalFilter.h:30
Definition: Mutex.h:31
long maxCal
Definition: IOController_i.idl:84
bool nofilter
Definition: IOBase.h:116
Definition: IOController_i.idl:79
bool safevalDefined
Definition: IOBase.h:113
long hilimit
Definition: IOController_i.idl:207
bool f_median
Definition: IOBase.h:117
Definition: IOBase.h:34
bool invert
Definition: IOBase.h:122
Definition: IOController_i.idl:57
long defval
Definition: IOBase.h:112
IOController_i::CalibrateInfo cal
Definition: IOBase.h:104
Definition: IOController_i.idl:200
boolean invert
Definition: IOController_i.idl:212
bool check_depend(const std::shared_ptr< SMInterface > &shm)
Definition: IOBase.cc:79
bool ondelay_state
Definition: IOBase.h:136
static bool initItem(IOBase *b, UniXML::iterator &it, const std::shared_ptr< SMInterface > &shm, const std::string &prefix, bool init_prefix_only, std::shared_ptr< DebugStream > dlog=nullptr, std::string myname="", int def_filtersize=0, float def_filterT=0.0, float def_lsparam=0.2, float def_iir_coeff_prev=0.5, float def_iir_coeff_new=0.5)
Definition: IOBase.cc:657
long ObjectId
Definition: UniSetTypes_i.idl:30
bool check_channel_break(long val)
Definition: IOBase.cc:70
uniset::ObjectId id
Definition: IOController_i.idl:59
bool ignore
Definition: IOBase.h:121