|
UniSet
2.2.1
|
00001 // ----------------------------------------------------------------------------- 00002 #ifndef IOBase_H_ 00003 #define IOBase_H_ 00004 // ----------------------------------------------------------------------------- 00005 #include <string> 00006 #include <memory> 00007 #include "PassiveTimer.h" 00008 #include "Trigger.h" 00009 #include "Mutex.h" 00010 #include "DigitalFilter.h" 00011 #include "Calibration.h" 00012 #include "IOController.h" 00013 #include "SMInterface.h" 00014 // ----------------------------------------------------------------------------- 00015 static const int DefaultSubdev = -1; 00016 static const int DefaultChannel = -1; 00017 static const int NoSafety = -1; 00018 // ----------------------------------------------------------------------------- 00020 struct IOBase 00021 { 00022 // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования 00023 // приходится здесь тоже объявлять разрешенными только операции "перемещения" 00024 IOBase( const IOBase& r ) = delete; 00025 IOBase& operator=(const IOBase& r) = delete; 00026 00027 IOBase( IOBase&& r ) = default; 00028 IOBase& operator=(IOBase&& r) = default; 00029 00030 ~IOBase(); 00031 IOBase(): 00032 stype(UniversalIO::UnknownIOType), 00033 cdiagram(nullptr), 00034 breaklim(0), 00035 value(0), 00036 craw(0), 00037 cprev(0), 00038 safety(0), 00039 defval(0), 00040 df(1), 00041 nofilter(false), 00042 f_median(false), 00043 f_ls(false), 00044 f_filter_iir(false), 00045 ignore(false), 00046 invert(false), 00047 noprecision(false), 00048 calcrop(true), 00049 debounce_pause(false), 00050 debounce_state(false), 00051 ondelay_state(false), 00052 offdelay_state(false), 00053 d_id(UniSetTypes::DefaultObjectId), 00054 d_value(1), 00055 d_off_value(0), 00056 d_iotype(UniversalIO::UnknownIOType), 00057 t_ai(UniSetTypes::DefaultObjectId), 00058 front(false), 00059 front_type(ftUnknown), 00060 front_prev_state(false), 00061 front_state(false), 00062 rawdata(false) 00063 { 00064 si.id = UniSetTypes::DefaultObjectId; 00065 si.node = UniSetTypes::DefaultObjectId; 00066 cal.minRaw = cal.maxRaw = cal.minCal = cal.maxCal = cal.precision = 0; 00067 ti.invert = false; 00068 ti.hilimit = 0; 00069 ti.lowlimit = 0; 00070 ti.id = UniSetTypes::DefaultObjectId; 00071 ti.state = IONotifyController_i::NormalThreshold; 00072 ti.tv_sec = 0; 00073 ti.tv_usec = 0; 00074 } 00075 00076 bool check_channel_break( long val ); 00078 bool check_debounce( bool val ); 00079 bool check_on_delay( bool val ); 00080 bool check_off_delay( bool val ); 00081 bool check_front( bool val ); 00082 bool check_depend( const std::shared_ptr<SMInterface>& shm ); 00084 IOController_i::SensorInfo si; 00085 UniversalIO::IOType stype; 00086 IOController_i::CalibrateInfo cal; 00087 Calibration* cdiagram; 00089 long breaklim; 00090 long value; 00091 long craw; 00092 long cprev; 00093 long safety; 00094 long defval; 00096 DigitalFilter df; 00097 bool nofilter; 00098 bool f_median; 00099 bool f_ls; 00100 bool f_filter_iir; 00102 bool ignore; 00103 bool invert; 00104 bool noprecision; 00105 bool calcrop; 00107 PassiveTimer ptDebounce; 00108 PassiveTimer ptOnDelay; 00109 PassiveTimer ptOffDelay; 00111 Trigger trOnDelay; 00112 Trigger trOffDelay; 00113 Trigger trdebounce; 00114 00115 bool debounce_pause; 00116 bool debounce_state; 00117 bool ondelay_state; 00118 bool offdelay_state; 00120 // Зависимость (d - depend) 00121 UniSetTypes::ObjectId d_id; 00122 IOController::IOStateList::iterator d_it; 00123 long d_value; 00124 long d_off_value; 00125 UniversalIO::IOType d_iotype; 00126 00127 // Порог 00128 UniSetTypes::ObjectId t_ai; 00132 IONotifyController_i::ThresholdInfo ti; 00133 IOController::IOStateList::iterator t_ait; // итератор для аналогового датчика 00134 00135 // Работа по фронтам сигнала 00136 enum FrontType 00137 { 00138 ftUnknown, 00139 ft01, // срабатывание на переход "0-->1" 00140 ft10 // срабатывание на переход "1-->0" 00141 }; 00142 00143 friend std::ostream& operator<<( std::ostream& os, const FrontType& f ); 00144 00145 bool front; // флаг работы по фронту 00146 FrontType front_type; 00147 bool front_prev_state; 00148 bool front_state; 00149 00150 bool rawdata; // флаг для сохранения данный в таком виде в каком они пришли (4байта просто копируются в long). Актуально для Vtypes::F4. 00151 00152 IOController::IOStateList::iterator ioit; 00153 UniSetTypes::uniset_rwmutex val_lock; 00155 IOBase make_iobase_copy(); 00156 void create_from_iobase( const IOBase& b ); 00157 00158 friend std::ostream& operator<<(std::ostream& os, const IOBase& inf ); 00159 00160 static void processingFasAI( IOBase* it, float new_val, const std::shared_ptr<SMInterface>& shm, bool force ); 00161 static void processingAsAI( IOBase* it, long new_val, const std::shared_ptr<SMInterface>& shm, bool force ); 00162 static void processingAsDI( IOBase* it, bool new_set, const std::shared_ptr<SMInterface>& shm, bool force ); 00163 static long processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00164 static float processingFasAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00165 static bool processingAsDO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00166 static void processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); 00167 00171 static bool initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm, 00172 const std::string& prefix, bool init_prefix_only, 00173 std::shared_ptr<DebugStream> dlog = nullptr, std::string myname = "", 00174 int def_filtersize = 0, float def_filterT = 0.0, 00175 float def_lsparam = 0.2, float def_iir_coeff_prev = 0.5, 00176 float def_iir_coeff_new = 0.5 ); 00177 00178 00179 // helpes 00180 static std::string initProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const std::string& defval = "" ); 00181 static int initIntProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const int defval = 0 ); 00182 static timeout_t initTimeoutProp( UniXML::iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const timeout_t defval); 00183 }; 00184 00185 // ----------------------------------------------------------------------------- 00186 #endif // IOBase_H_ 00187 // -----------------------------------------------------------------------------
1.7.6.1