UniSet 2.44.3
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// -------------------------------------------------------------------------
30namespace 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 {
84 cal.minRaw = cal.maxRaw = cal.minCal = cal.maxCal = cal.precision = 0;
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 );
95
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 );
101
103 UniversalIO::IOType stype;
106
107 long breaklim;
108 long value;
109 long craw;
110 long cprev;
111 long safeval;
112 long defval;
113 bool safevalDefined = { false };
114
116 bool nofilter;
117 bool f_median;
118 bool f_ls;
120
121 bool ignore;
122 bool invert;
123 bool noprecision;
124 bool calcrop;
125
129
130 Trigger trOnDelay;
131 Trigger trOffDelay;
132 Trigger trdebounce;
133
134 bool debounce_pause;
138
139 // Зависимость (d - depend)
141 IOController::IOStateList::iterator d_it;
142 long d_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;
173
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// -----------------------------------------------------------------------------
Определения Calibration.h:80
Определения DigitalFilter.h:31
Пассивный таймер
Определения PassiveTimer.h:94
Определения Trigger.h:31
Определения Mutex.h:32
@ NormalThreshold
Определения IOController_i.idl:211
Определения Calibration.h:27
const ObjectId DefaultObjectId
Определения UniSetTypes.h:71
long ObjectId
Определения UniSetTypes_i.idl:30
Определения IOController_i.idl:89
Определения IOController_i.idl:64
Определения IOController_i.idl:216
long value
Определения IOBase.h:108
bool f_ls
Определения IOBase.h:118
bool calcrop
Определения IOBase.h:124
bool nofilter
Определения IOBase.h:116
long craw
Определения IOBase.h:109
long breaklim
Определения IOBase.h:107
bool ondelay_state
Определения IOBase.h:136
long defval
Определения IOBase.h:112
bool debounce_state
Определения IOBase.h:135
PassiveTimer ptOffDelay
Определения IOBase.h:128
bool f_filter_iir
Определения IOBase.h:119
bool safevalDefined
Определения IOBase.h:113
uniset::ObjectId d_id
Определения IOBase.h:140
long d_off_value
Определения IOBase.h:143
Calibration * cdiagram
Определения IOBase.h:105
bool offdelay_state
Определения IOBase.h:137
bool check_on_delay(bool val)
Определения IOBase.cc:134
bool check_debounce(bool val)
Определения IOBase.cc:103
IOController_i::CalibrateInfo cal
Определения IOBase.h:104
bool check_off_delay(bool val)
Определения IOBase.cc:155
bool check_depend(const std::shared_ptr< SMInterface > &shm)
Определения IOBase.cc:79
PassiveTimer ptOnDelay
Определения IOBase.h:127
bool invert
Определения IOBase.h:122
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)
Определения IOBase.cc:687
UniversalIO::IOType stype
Определения IOBase.h:103
long safeval
Определения IOBase.h:111
long cprev
Определения IOBase.h:110
PassiveTimer ptDebounce
Определения IOBase.h:126
bool check_channel_break(long val)
Определения IOBase.cc:70
bool f_median
Определения IOBase.h:117
uniset::ObjectId t_ai
Определения IOBase.h:147
DigitalFilter df
Определения IOBase.h:115
bool ignore
Определения IOBase.h:121
bool check_front(bool val)
Определения IOBase.cc:175
uniset::uniset_rwmutex val_lock
Определения IOBase.h:172
long d_value
Определения IOBase.h:142