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