INOS
cinosprocessimagechannel.h
Go to the documentation of this file.
1 //******************************************************************************
27 //******************************************************************************
28 
29 #ifndef INC_CINOSPROCESSIMAGECHANNEL_H
30 #define INC_CINOSPROCESSIMAGECHANNEL_H
31 
32 //------------------------------------------------------------------------------
33 // defines
34 //------------------------------------------------------------------------------
35 //
36 #define DF_INOS_IMAGE_CHN_DEF_CHAR 0xffff // default characteristics
37 #define DF_INOS_IMAGE_CHN_DEF_REAL 1.2345 // default real32 number
38 #define DF_INOS_IMAGE_CHN_DEF_INT 123456789 // default int32 number
39 //
40 //------------------------------------------------------------------------------
41 // includes
42 //------------------------------------------------------------------------------
43 //
44 // system
45 #include <inos.h>
46 #include <cinosbus.h>
47 //
48 // C++
49 //
50 // project
51 //
52 //
53 //------------------------------------------------------------------------------
54 // forward declarations
55 //------------------------------------------------------------------------------
56 class CINOSProcessImage;
57 class CINOSBusPortHandler;
58 class CINOSBusJob;
59 //
60 //------------------------------------------------------------------------------
61 // type definition
62 //------------------------------------------------------------------------------
63 //
64 typedef float (*tpHook)(float, intid);
65 typedef void (*tpConversion)(char*, uint32, intid);
66 //
67 //------------------------------------------------------------------------------
68 // structure definition
69 //------------------------------------------------------------------------------
70 //
73  //; pointer to next hook in chain
74  tpHook m_pFunction;
75  //; pointer to hook function
76  tpHook m_pInvFunction;
77  //; pointer to inverse hook function (used to convert value when writing back)
78  tpConversion m_pConversion;
79  //; pointer to hook function
80  intid m_iId;
81  //; hook id
82  real32 m_rValue;
83  //; raw value (before hook)
84  char* m_pUnit;
85  //; unit of raw value (before hook)
86  real32 m_rLower;
87  //; lower limit of raw value (before hook)
88  real32 m_rUpper;
89  //; upper limit of raw value (before hook)
90  uint32 m_uCharacteristics;
91  //; characteristics of raw value (before hook)
92  enum {
93  eFlgUnit = 0x00000001,
94  eFlgMin = 0x00000002,
95  eFlgMax = 0x00000004,
96  eFlgChar = 0x00000008,
97  eFlgLast = 0x00000010, // last hook in chain
98  };
99  uint32 m_uFlags;
100  //; flags which properties are hook specific
101 
102  // allow dynamic object handling (new/delete)
103  DECLARE_DYNAMIC(SINOSProcessImageChannelHook);
104 };
105 
106 //------------------------------------------------------------------------------
107 // class definition
108 //------------------------------------------------------------------------------
109 //
111 {
112  //--- user interface ---------------------------------------------------
113 
114  // public member functions
115  public :
116  const char* GetName();
117  //; return name of channel
118  void Rename(const char* apName);
119  //; renames this channel and updates the INCO registration
120  uint16 GetNumber();
121  //; return number of channel
122  CINOSProcessImage* GetParent();
123  //; get pointer to according process image
124 
125  ICACHE virtual void Set(real64 arValue)
126  { };
127  ICACHE virtual void SetControl(real64 arValue)
128  { Set(arValue); };
129  //; set channel to arValue
130  ICACHE virtual real64 Get()
131  { return REAL64(0.0);};
132  //; get value of channel
133 
134  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
135  virtual void SetOverwrite(bool abValue);
136  //; change the channel from real to overwrite mode if abValue = true
137  //; or vice versa
138  virtual bool GetOverwrite();
139  //; get actual overwrite mode of channel
140  #endif
141 
142  virtual void SetEnabled(bool abValue);
143  //; enable channel if abValue = true or vice versa
144  virtual bool GetEnabled();
145  //; return true if channel is enabled
146 
147  virtual void SetSimulated(bool abValue);
148  //; set simulation state
149  virtual bool GetSimulated();
150  //; get simulation state
151 
152  virtual void SetConfig(uint32 auConfig, uint32 auMask, uint32 auOffset=0);
153  //; set config to auConfig (only bits set in auMask are affected)
154  virtual uint32 GetConfig(uint32 auOffset=0);
155  //; get config
156  virtual void* GetConfigAdr(uint32 auOffset=0);
157  //; get address of config
158 
160  uintid RegisterHook(tpHook apHook, intid aiId, char* apUnit=0,
161  uint32 auCharacteristics=DF_INOS_IMAGE_CHN_DEF_CHAR,
162  real32 arLower=real32(DF_INOS_IMAGE_CHN_DEF_REAL),
163  real32 arUpper=real32(DF_INOS_IMAGE_CHN_DEF_REAL),
164  tpHook apInvHook=NULL
165  );
168  uintid RegisterLastHook(tpHook apHook, intid aiId);
170  void UnRegisterHook(uintid auHookId);
173  return m_pFirstHook;
174  }
177 
181  bool IsHooked() {
182  return m_pFirstHook!=NULL;
183  }
184 
194  virtual void RegisterBusHook(uintid& auHookId, void* apHandler, void* apObject = 0,
195  int32 aiOrder = DF_INOS_BUS_HOOK_ORDER_DEFAULT);
197  virtual void UnRegisterBusHook(uintid auHookId);
198 
199  virtual uint32 GetCycleTimeNs();
200  //; return channel cycletime [ns]
201  virtual uint16 GetCycleNumber()
202  { return 0;};
203  //; return bus subcycle number the channel is updated (needed to be
204  //; able to register bus hook in the correct subcycle)
205  virtual void SetCycleNumber(uint16 auCycleNumber, uint8 auBusId = CINOSBus::GetFirstBus()->GetId(),
206  CINOSBusJob* apBusJob = 0){};
207  //; set bus id and subcycle number the channel is updated (the field bus
208  //; driver has to set this number to inform all others who are
209  //; interested in)
210  virtual uint16 GetCycleId() = 0;
211  //; return bus cycle id the channel is updated (needed to be
212  //; able to register bus hook in the correct cycle/core)
213  virtual void SetCycleId(uint16 auCycleId, uint8 auBusId, CINOSBusPortHandler* apBusPortHandler){};
214  //; set bus id and subcycle number the channel is updated (the field bus
215  //; driver has to set this number to inform all others who are
216  //; interested in)
217  virtual void UpdateCycleId(uint16 auCycleId);
218  //; update cycle id the channel is updated (this method is usually called
219  //; from axis controllers to inform about downsampled controlling and possible
220  //; other cores)
221  virtual uint8 GetBusId() = 0;
222  //; return bus id the channel belongs to (needed to be
223  //; able to register bus hook)
224  virtual CINOSBusJob* GetBusJob()
225  { return 0;};
226  //; return pointer to the according bus job (or 0 if not available)
227  virtual CINOSBusPortHandler* GetBusPortHandler();
228  //; return pointer to the according bus port (or 0 if not available)
229  virtual uint32 GetOversampling();
230  //; get channel oversampling (returns 0 if no oversampling)
231  virtual uint32 GetArrayLength();
232  //; get channel array length
233  virtual bool IsRaw32();
234  //; return true if value is a 'raw32' or 'raw32 inv ovr' value
235  virtual bool IsRaw();
236  //; return true if value is a 'raw' value
237 
238  #ifdef INOS_USE_CUSTOMER_IMAGE_DATA
239  void* GetCustomerSpecificData() const;
240  //; \return The pinter to the customer specific data (or NULL if
241  //; no such data are set).
242  void SetCustomerSpecificData(void* apData);
243  //; Sets apData to be the "customer specific data" of this
244  //; image channel. The function doesn't care about any
245  //; previously set customer specific data: The caller is 100%
246  //; responsible for freeing amy resource related to these data!
247  //; This class will never access the data in any way apart from
248  //; initialization to NULL during object contstruction!
249  #endif
250 
251  virtual void IwasMoved(uint32 auToNumber){};
252  //; called whenever a channel was moved to a new number
253  virtual void SetDescription(const char* apDescription);
254  //; set channel description
255 
256  //--- internals --------------------------------------------------------
257 
258  friend class CINOSProcessImage;
259  friend class CINOSAdcChannels;
260  friend class CINOSDacChannels;
261  friend class CINOSPosChannels;
262  friend class CINOSBusPortHandlerAdc;
263  friend class CINOSBusPortHandlerDac;
264 
265  // constructor / destructor
266  public:
271  CINOSProcessImageChannel (const char* apName, uint16 auNumber, uint8 auParent);
272  //; object constructor
273  virtual ~CINOSProcessImageChannel();
274 
275  // protected members
276  protected:
277  const char* m_pName;
278  //; channel name
279  const char* m_pIncoName;
280  //; channel name in inco tree (e.g. if m_pName = "Z.InitMot" then
281  //; m_pIncoName = "InitMot")
282  uint16 m_uNumber;
283  //; channel number
284  uint16 m_uParent;
285  //; index of parent process image
286  CINCOObject* m_pRegister;
287  //; inco registration of channel
288  SINOSProcessImageChannelHook* m_pFirstHook;
289  //; pointer to first hook in chain
290  #ifdef INOS_USE_CUSTOMER_IMAGE_DATA
291  //; from time to time, a customers may need to attach customer
292  //; specific data to a certain process channel (such as a Bit, DAC,
293  //; ADC, etc.). One possiblity to add such data is to subclass e.g.
294  //; CINOSBit, and add new dt2 tables in order to create the
295  //; subclasses instances. Another way is to use this member.
296  void* m_pCustomerSpecificData;
297  #endif
298 
299  // public member functions but just for internal use
300  public:
301  CINCOObject* GetRegister();
302  //; return pointer to inco registration of this channel
303 
304  // operators (needed to handle binary tree search)
305  public:
306  int operator < (const CINOSProcessImageChannel& aChannel) const
307  { return (strcmp(m_pName, aChannel.m_pName)<0);}
308  int operator == (const CINOSProcessImageChannel& aChannel) const
309  { return (strcmp(m_pName, aChannel.m_pName)==0);}
310  int operator < (const char* apName) const
311  { return (strcmp(m_pName, apName)<0);}
312  int operator == (const char* apName) const
313  { return (strcmp(m_pName, apName)==0);}
314 };
315 
316 //
317 //------------------------------------------------------------------------------
318 // global variables
319 //------------------------------------------------------------------------------
320 //
321 extern const char PROCESS_IMAGE_CHANNEL_DUMMY_NAME[];
322 //
323 //------------------------------------------------------------------------------
324 // end of file
325 //------------------------------------------------------------------------------
326 
327 #endif // INC_CINOSPROCESSIMAGECHANNEL_H
CINOSDacChannels
Definition: cinosdacchannels.h:76
CINOSProcessImage
Definition: cinosprocessimage.h:70
CINOSProcessImageChannel::GetFirstHookDescriptor
SINOSProcessImageChannelHook * GetFirstHookDescriptor()
Get first hook descriptor.
Definition: cinosprocessimagechannel.h:172
CINOSProcessImageChannel::UnRegisterBusHook
virtual void UnRegisterBusHook(uintid auHookId)
unregister a previously registered bus hook
DF_INOS_BUS_HOOK_ORDER_DEFAULT
#define DF_INOS_BUS_HOOK_ORDER_DEFAULT
bus hook order 'default'
Definition: cinosbus.h:137
CINOSProcessImageChannel::RegisterHook
uintid RegisterHook(tpHook apHook, intid aiId, char *apUnit=0, uint32 auCharacteristics=0xffff, real32 arLower=real32(1.2345), real32 arUpper=real32(1.2345), tpHook apInvHook=NULL)
register channel hook
CINOSPosChannels
Definition: cinosposchannels.h:81
CINOSAdcChannels
Definition: cinosadcchannels.h:77
CINOSProcessImageChannel::CINOSProcessImageChannel
CINOSProcessImageChannel(const char *apName, uint16 auNumber, uint8 auParent)
cinosbus.h
Short comment.
SINOSProcessImageChannelHook
Definition: cinosprocessimagechannel.h:71
CINOSProcessImageChannel::UnRegisterHook
void UnRegisterHook(uintid auHookId)
Unregister channel hook.
CINOSProcessImageChannel
Definition: cinosprocessimagechannel.h:110
CINOSProcessImageChannel::RegisterLastHook
uintid RegisterLastHook(tpHook apHook, intid aiId)
CINOSProcessImageChannel::GetLastHookDescriptor
SINOSProcessImageChannelHook * GetLastHookDescriptor()
Get last hook descriptor.
CINOSBus::GetFirstBus
static CINOSBus * GetFirstBus()
Return first valid bus (aka "g_pBus[0]").
Definition: cinosbus.h:604
CINOSProcessImageChannel::RegisterBusHook
virtual void RegisterBusHook(uintid &auHookId, void *apHandler, void *apObject=0, int32 aiOrder=DF_INOS_BUS_HOOK_ORDER_DEFAULT)
Register hook and return hook id. The registered function will be called in the context of the corres...
CINOSProcessImageChannel::IsHooked
bool IsHooked()
Check if this channel has a hook or not.
Definition: cinosprocessimagechannel.h:181