|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // ----------------------------------------------------------------------------- 00017 #ifndef IOBase_H_ 00018 #define IOBase_H_ 00019 // ----------------------------------------------------------------------------- 00020 #include <string> 00021 #include <memory> 00022 #include "PassiveTimer.h" 00023 #include "Trigger.h" 00024 #include "Mutex.h" 00025 #include "DigitalFilter.h" 00026 #include "Calibration.h" 00027 #include "IOController.h" 00028 #include "SMInterface.h" 00029 // ------------------------------------------------------------------------- 00030 namespace uniset 00031 { 00032 // ----------------------------------------------------------------------------- 00033 static const int DefaultSubdev = -1; 00034 static const int DefaultChannel = -1; 00035 static const int NoSafety = -1; 00036 // ----------------------------------------------------------------------------- 00038 struct IOBase 00039 { 00040 // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования 00041 // приходится здесь тоже объявлять разрешенными только операции "перемещения" 00042 IOBase( const IOBase& r ) = delete; 00043 IOBase& operator=(const IOBase& r) = delete; 00044 00045 IOBase( IOBase&& r ) = default; 00046 IOBase& operator=(IOBase&& r) = default; 00047 00048 ~IOBase(); 00049 IOBase(): 00050 stype(UniversalIO::UnknownIOType), 00051 cdiagram(nullptr), 00052 breaklim(0), 00053 value(0), 00054 craw(0), 00055 cprev(0), 00056 safety(0), 00057 defval(0), 00058 df(1), 00059 nofilter(false), 00060 f_median(false), 00061 f_ls(false), 00062 f_filter_iir(false), 00063 ignore(false), 00064 invert(false), 00065 noprecision(false), 00066 calcrop(true), 00067 debounce_pause(false), 00068 debounce_state(false), 00069 ondelay_state(false), 00070 offdelay_state(false), 00071 d_id(uniset::DefaultObjectId), 00072 d_value(1), 00073 d_off_value(0), 00074 d_iotype(UniversalIO::UnknownIOType), 00075 t_ai(uniset::DefaultObjectId), 00076 front(false), 00077 front_type(ftUnknown), 00078 front_prev_state(false), 00079 front_state(false), 00080 rawdata(false) 00081 { 00082 si.id = uniset::DefaultObjectId; 00083 si.node = uniset::DefaultObjectId; 00084 cal.minRaw = cal.maxRaw = cal.minCal = cal.maxCal = cal.precision = 0; 00085 ti.invert = false; 00086 ti.hilimit = 0; 00087 ti.lowlimit = 0; 00088 ti.id = uniset::DefaultObjectId; 00089 ti.state = IONotifyController_i::NormalThreshold; 00090 ti.tv_sec = 0; 00091 ti.tv_nsec = 0; 00092 } 00093 00094 bool check_channel_break( long val ); 00096 bool check_debounce( bool val ); 00097 bool check_on_delay( bool val ); 00098 bool check_off_delay( bool val ); 00099 bool check_front( bool val ); 00100 bool check_depend( const std::shared_ptr<SMInterface>& shm ); 00102 IOController_i::SensorInfo si; 00103 UniversalIO::IOType stype; 00104 IOController_i::CalibrateInfo cal; 00105 Calibration* cdiagram; 00107 long breaklim; 00108 long value; 00109 long craw; 00110 long cprev; 00111 long safety; 00112 long defval; 00114 DigitalFilter df; 00115 bool nofilter; 00116 bool f_median; 00117 bool f_ls; 00118 bool f_filter_iir; 00120 bool ignore; 00121 bool invert; 00122 bool noprecision; 00123 bool calcrop; 00125 PassiveTimer ptDebounce; 00126 PassiveTimer ptOnDelay; 00127 PassiveTimer ptOffDelay; 00129 Trigger trOnDelay; 00130 Trigger trOffDelay; 00131 Trigger trdebounce; 00132 00133 bool debounce_pause; 00134 bool debounce_state; 00135 bool ondelay_state; 00136 bool offdelay_state; 00138 // Зависимость (d - depend) 00139 uniset::ObjectId d_id; 00140 IOController::IOStateList::iterator d_it; 00141 long d_value; 00142 long d_off_value; 00143 UniversalIO::IOType d_iotype; 00144 00145 // Порог 00146 uniset::ObjectId t_ai; 00150 IONotifyController_i::ThresholdInfo ti; 00151 IOController::IOStateList::iterator t_ait; // итератор для аналогового датчика 00152 00153 // Работа по фронтам сигнала 00154 enum FrontType 00155 { 00156 ftUnknown, 00157 ft01, // срабатывание на переход "0-->1" 00158 ft10 // срабатывание на переход "1-->0" 00159 }; 00160 00161 friend std::ostream& operator<<( std::ostream& os, const FrontType& f ); 00162 00163 bool front; // флаг работы по фронту 00164 FrontType front_type; 00165 bool front_prev_state; 00166 bool front_state; 00167 00168 bool rawdata; // флаг для сохранения данный в таком виде в каком они пришли (4байта просто копируются в long). Актуально для Vtypes::F4. 00169 00170 IOController::IOStateList::iterator ioit; 00171 uniset::uniset_rwmutex val_lock; 00173 IOBase make_iobase_copy(); 00174 void create_from_iobase( const IOBase& b ); 00175 00176 friend std::ostream& operator<<(std::ostream& os, const IOBase& inf ); 00177 00178 static void processingFasAI( IOBase* it, float new_val, const std::shared_ptr<SMInterface>& shm, bool force ); 00179 static void processingAsAI( IOBase* it, long new_val, const std::shared_ptr<SMInterface>& shm, bool force ); 00180 static void processingAsDI( IOBase* it, bool new_set, const std::shared_ptr<SMInterface>& shm, bool force ); 00181 static long processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00182 static float processingFasAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00183 static bool processingAsDO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00184 static void processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00185 00189 static bool initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm, 00190 const std::string& prefix, bool init_prefix_only, 00191 std::shared_ptr<DebugStream> dlog = nullptr, std::string myname = "", 00192 int def_filtersize = 0, float def_filterT = 0.0, 00193 float def_lsparam = 0.2, float def_iir_coeff_prev = 0.5, 00194 float def_iir_coeff_new = 0.5 ); 00195 00196 00197 // helpes 00198 static std::string initProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const std::string& defval = "" ); 00199 static int initIntProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const int defval = 0 ); 00200 static timeout_t initTimeoutProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const timeout_t defval); 00201 }; 00202 // -------------------------------------------------------------------------- 00203 } // end of namespace uniset 00204 // ----------------------------------------------------------------------------- 00205 #endif // IOBase_H_ 00206 // -----------------------------------------------------------------------------
1.7.6.1