INOS
cinosprocessimage.h
Go to the documentation of this file.
1 //******************************************************************************
27 //******************************************************************************
28 
29 #ifndef INC_CINOSPROCESSIMAGE_H
30 #define INC_CINOSPROCESSIMAGE_H
31 
32 //------------------------------------------------------------------------------
33 // defines
34 //------------------------------------------------------------------------------
35 //
36 #define DF_PROCESS_IMAGE_NUMBER 8 // number supported of process images
37 //
38 // --- process image numbers ---------------------------------------------------
39 //
40 #define DF_PROCESS_IMAGE_DIGITAL_INPUTS 0 // nr proc image 'digital input'
41 #define DF_PROCESS_IMAGE_DIGITAL_OUTPUTS 1 // nr proc image 'digital output'
42 #define DF_PROCESS_IMAGE_ANALOG_INPUTS 2 // nr proc image 'analog input'
43 #define DF_PROCESS_IMAGE_ANALOG_OUTPUTS 3 // nr proc image 'analog output'
44 #define DF_PROCESS_IMAGE_DIGITAL_FLAGS 4 // nr proc image 'digital flags'
45 #define DF_PROCESS_IMAGE_POSITIONS 5 // nr proc image 'position'
46 #define DF_PROCESS_IMAGE_AXES 6 // nr proc image 'axes'
47 #define DF_PROCESS_IMAGE_SIO_CHANNELS 7 // nr proc image 'sio channels'
48 //
49 #define DF_INOS_IMAGE_CHN_SIM_NO 0 // simulate channel -> no
50 #define DF_INOS_IMAGE_CHN_SIM_YES 1 // simulate channel -> yes
51 #define DF_INOS_IMAGE_CHN_SIM_DEF 2 // simulate channel -> default
52 //
53 //------------------------------------------------------------------------------
54 // includes
55 //------------------------------------------------------------------------------
56 //
57 // system
58 #include <cinosbus.h>
59 
60 // C++
61 //
62 // project
63 //
64 //------------------------------------------------------------------------------
65 // class definition
66 //------------------------------------------------------------------------------
67 //
69 class CINOSBusJob;
71 {
72  //--- user interface ---------------------------------------------------
73 
74  // public member functions
75  public :
76  char* GetName();
77  //; return name of process image
78  uint32 GetNumber();
79  //; return number of process image channels
80 
81  virtual void Set(uint16 auNumber, real64 arValue)
82  { };
83  //; set channel 'auNumber' to arValue
84  virtual real64 Get(uint16 auNumber)
85  { return REAL64(0.0);};
86  //; get value of channel 'auNumber'
87 
88  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
89  virtual void SetOverwrite(bool abValue)=0;
90  //; change the whole process image from real to overwrite mode if
91  //; abValue = true or vice versa
92  virtual bool GetOverwrite()=0;
93  //; get actual overwrite mode of the whole process image
94  virtual void SetOverwrite(uint16 auNumber, bool abValue)=0;
95  //; change the channel 'auNumber' from real to overwrite mode if
96  //; abValue = true or vice versa
97  virtual bool GetOverwrite(uint16 auNumber)=0;
98  //; get actual overwrite mode of channel 'auNumber'
99  #endif
100 
101  virtual void SetEnabled(bool abValue);
102  //; enable whole process image if abValue = true or vice versa
103  virtual bool GetEnabled();
104  //; return true if the whole process image is enabled
105  virtual void SetEnabled(uint16 auNumber, bool abValue);
106  //; enable the channel 'auNumber' if abValue = true or vice versa
107  virtual bool GetEnabled(uint16 auNumber);
108  //; return true if channel 'auNumber' is enabled
109 
110  virtual void SetSimulated(uint16 auNumber, bool abValue)=0;
111  //; set simulated state of channel auNumber
112  virtual bool GetSimulated(uint16 auNumber)=0;
113  //; get simulated state of channel auNumber
114 
115  virtual void SetConfig(uint16 auNumber, uint32 auConfig, uint32 auMask,
116  uint32 auOffset=0);
117  //; set config of channel 'auNumber' to auConfig (only bits set in
118  //; auMask are affected)
119  virtual uint32 GetConfig(uint16 auNumber, uint32 auOffset=0);
120  //; get config of channel 'auNumber'
121  virtual void* GetConfigAdr(uint16 auNumber, uint32 auOffset=0);
122  //; get config address of channel 'auNumber'
123 
124  virtual void* GetBaseAddress();
125  //; get base address of process image (ATTENTION : only need this
126  //; address for READING purposes, NEVER write direct to the process
127  //; image)
128  virtual void* GetConfigBaseAddress();
129  //; get base address of process image config
130  INOS_INLINE void* GetAddress(uint16 auNumber)
131  {
132  // array based ?
133  if (m_pDesc[auNumber]<=1){
134  // no
135  return &m_pImage[auNumber];
136  } // end if
137  else {
138  #if defined(INOS_64)
139  return (void*) ((uint64(m_pUpper[auNumber])<<32) + m_pImage[auNumber]);
140  #else
141  // yes
142  return (void*)m_pImage[auNumber];
143  #endif
144  } // end else
145  }
146  //; get address of channel auNumber
147  virtual uint16 GetArrayLength(uint16 auNumber);
148  //; get array length of channel auNumber
149 
150  virtual void Add(CINOSProcessImageChannel* apChannel);
151  //; add process image channel to the image
152  virtual void Remove(CINOSProcessImageChannel* apChannel);
153  //; remove process image channel from image
154  virtual void Remove(uint32 auChannel);
155  //; remove process image channel from image
156  CINOSProcessImageChannel* Find(const char* apName);
157  //; return pointer to channel with apName or NULL if not found
158  CINOSProcessImageChannel* FindExact(const char* apName);
159  //; return pointer to channel with exact apName or NULL if not found
160  CINOSProcessImageChannel* Find(uint16 auNumber);
161  //; return pointer to channel with auNumber or NULL if not found
162  static CINOSProcessImageChannel* FindInp(const char* apName);
163  //; return pointer to input channel (bit,adc,pos) with apName or NULL
164  //; if not found
165  static CINOSProcessImageChannel* FindInp(uint16 auNumber);
166  //; return pointer to input channel (bit,adc,pos) with auNumber or NULL
167  //; if not found
168  static CINOSProcessImageChannel* FindOut(const char* apName);
169  //; return pointer to output channel (bit,dac) with apName or NULL
170  //; if not found
171  static CINOSProcessImageChannel* FindOut(uint16 auNumber);
172  //; return pointer to output channel (bit,dac) with auNumber or NULL
173  //; if not found
174 
175  virtual uint16 GetCycleNumber(uint16 auNumber)
176  { return 0;};
177  //; return bus subcycle number the channel is updated (needed to be
178  //; able to register bus hook in the correct subcycle)
179  virtual void SetCycleNumber(uint16 auNumber, uint16 auCycleNumber,
180  uint8 auBusId = CINOSBus::GetFirstBus()->GetId(), CINOSBusJob* apBusJob = 0){};
181  //; set bus id and subcycle number the channel is updated (the field bus
182  //; driver has to set this number to inform all others who are
183  //; interested in)
184  virtual uint16 GetCycleId(uint16 auNumber)
185  { return 0;};
186  //; return bus cycle id the channel is updated (needed to be
187  //; able to register bus hook in the correct cycle/core)
188  virtual void SetCycleId(uint16 auNumber, uint16 auCycleId, uint8 auBusId,
189  class CINOSBusPortHandler* apBusPortHandler){};
190  //; set bus id and cycle id the channel is updated (the field bus
191  //; driver has to set this number to inform all others who are
192  //; interested in)
193  virtual void UpdateCycleId(uint16 auNumber, uint16 auCycleId){};
194  //; update cycle id the channel is updated (this method is usually called
195  //; from axis controllers to inform about downsampled controlling and possible
196  //; other cores)
197  virtual uint8 GetBusId(uint16 auNumber)
198  { return 0;};
199  //; return bus id the channel belongs to (needed to be
200  //; able to register bus hook)
201  virtual CINOSBusJob* GetBusJob(uint16 auNumber)
202  { return 0;};
203  //; return pointer to the according bus job (or 0 if not available)
204  virtual class CINOSBusPortHandler* GetBusPortHandler(uint16 auNumber)
205  { return 0;};
206  //; return pointer to the according bus port (or 0 if not available)
207  virtual CINCOObject* GetRegister()
208  { return m_pRegister;};
209 
210  //--- internals --------------------------------------------------------
211 
212  friend class CINOSProcessImageChannel;
213  friend class CINOSProcessImageValue;
214 
215  // constructor / destructor
216  public :
217  CINOSProcessImage (char* apName, uint32 auNumber, void* apImage=0);
218  //; object constructor
219  virtual ~CINOSProcessImage() {}
220 
221  // public member functions but just for internal use
222  public :
223  ICACHE virtual void Get(uint16 auChannel, void* apValue);
224  //; get actual channel value to apValue
225  ICACHE virtual void Get64(uint16 auChannel, void* apValue);
226  //; get actual channel value to apValue
227  #if defined(INOS_PROCESSIMAGE_OVERWRITE)
228  virtual void Set(uint16 auChannel, void* apValue,
229  bool abOverwrite = false)=0;
230  //; set channel to apValue
231  //; (abOverwrite=true -> value always set, abOverwrite=false -> value
232  //; set if channel is NOT in overwrite mode)
233  #else
234  virtual void Set(uint16 auChannel, void* apValue)=0;
235  //; set channel to apValue
236  #endif
237  virtual void Set(uint16 auChannel, void* apValue, uint32 auMask);
238  //; set real channel to apValue (only bits set in auMask are
239  //; affected)
240  static bool SimulationRequested(uint32 auSimulate = DF_INOS_IMAGE_CHN_SIM_DEF);
241  //; return true, if simulation of image requested
242  virtual uint32 FindFreeNumber(bool ab32BitBased = false, bool abFromEnd = false);
243  //; return first (or last, if abFromEnd is set) free process image channel number or 0xffffffff if
244  //; no free numbers
245  static char* CreateUniqueName(uint16 auNumber);
246  //; create unique channel name for channel auNumber and return pointer
247  //; to it
248  virtual void MoveChannel(uint16 auOldNumber, uint16 auNewNumber);
249  //; move channel auOldNumber to auNewNumber
250  virtual CINCOObject* GetChannelParent(CINOSProcessImageChannel* apChannel, bool abCreate);
251  //; returns the parent INCO object of the given channel, creating the objects
252  //; along the path if requested
253  virtual bool RenameInco(CINOSProcessImageChannel* apChannel, const char* apNewName);
254  //; renames the given channel in the INCO tree
255 
256  // public member functions (but just for internal use
257  public:
258  static CINCOObject* Register(char* apName, void* apAddress=0);
259  //; create registration for apName and return pointer to it
260 
266  static bool MatchName(const char* apName, const char* apPattern);
267 
268  // protected members
269  protected:
270  char* m_pName{};
271  //; name of process image
272  uint32 m_uNumber{};
273  //; number of channels
274  CINCOObject* m_pRegister{};
275  //; pointer to inco registration object
276  CINOSProcessImageChannel** m_pChannel{};
277  //; array of channel pointers
278  uint32* m_pImage{};
279  //; pointer to process image
280  uint32* m_pDesc{};
281  //; pointer to process image channel descriptors
282  #if defined(INOS_64)
283  uint32* m_pUpper{};
284  //; upper 32 bit of 64 bit address
285  #endif
286 
287  #if defined(INOS_PROCESSIMAGE_CHANNELNUMBER_FREE)
288 
296  uint32 RequestChn(const char* apName, uint16 auBase, uint8 auChannels, uint16& aoChannel);
297 
303  uint32 ReleaseChn(uint16 auChannel);
304 
305  friend class CINOSBusChannelHandler;
306 
308  CINOSMutex m_ChnMutex;
310  std::map<std::string, uint16> m_mChnMap;
312  uint32 m_uChannelsActive{};
314  uint32* m_pChannelsActive{};
315  #endif
316 };
317 
318 #if defined(INOS_PROCESSIMAGE_OVERWRITE)
319 //------------------------------------------------------------------------------
320 // class CINCOoverwriteImage
321 //------------------------------------------------------------------------------
322 
323 class CINCOoverwriteImage : public CINCObit
324 {
325  // constructor
326  public:
327  CINCOoverwriteImage(
328  CINOSProcessImage* apImage
329  );
330 
331  // public member functions
332  public:
333  // item address = (long) pData + aIndex*sizeof(item) + aOffset
334  virtual long Put(void* aSource, long aIndex=0, long aOffset=0) override;
335  // item address = (long) pData + aIndex*sizeof(item) + aOffset
336  virtual long Get(void* aSource, long& aMaxLength, long aIndex=0, long aOffset=0) override;
337 
338  // protected members
339  protected :
340  CINOSProcessImage* m_pImage;
341  //; pointer to according image
342 
343  // allow dynamic object handling (new/delete)
344  DECLARE_DYNAMIC(CINCOoverwriteImage);
345 };
346 #endif
347 
348 //------------------------------------------------------------------------------
349 
351 {
352  friend class CINOSBusPortHandlerTdc;
353 
354  public :
356  static bool IsValid(class CINOSAdcChannel* apChannel);
358  static bool IsValid(const char* apChannel);
359 
361  static uint32 Calibrate(class CINOSAdcChannel* apChannel);
363  static uint32 Calibrate(const char* apChannel);
364 
365  protected :
366  // protection mutex
367  static CINOSMutex m_Mutex;
368  static TSafeArray<class CINOSAdcChannel*> m_AdcChannel;
369  static TSafeArray<class CINOSBusPortHandlerTdc*> m_Lvdt;
372 
374  public:
376  static CINOSLVDT& Instance()
377  {
378  // return our singleton instance
379  return m_Instance;
380  }
381 };
382 
383 //------------------------------------------------------------------------------
384 // includes
385 //------------------------------------------------------------------------------
386 //
387 // --- process images channels -------------------------------------------------
388 //
390 #include <cinosbit.h>
391 #include <cinosprocessimagevalue.h>
392 #include <cinosadcchannel.h>
393 #include <cinosdacchannel.h>
394 #include <cinosposchannel.h>
395 //
396 // --- more process images -----------------------------------------------------
397 //
398 #include <cinosprocessimagevalues.h>
399 #include <cinosbits.h>
400 #include <cinosadcchannels.h>
401 #include <cinosdacchannels.h>
402 #include <cinosposchannels.h>
403 //
404 //------------------------------------------------------------------------------
405 // global variables
406 //------------------------------------------------------------------------------
407 //
408 extern CINOSProcessImage* g_pImage[DF_PROCESS_IMAGE_NUMBER];
409 
411 extern CINOSMutex g_ImageLock[DF_PROCESS_IMAGE_NUMBER];
412 //
413 //------------------------------------------------------------------------------
414 // end of file
415 //------------------------------------------------------------------------------
416 
417 #endif // INC_CINOSPROCESSIMAGE_H
CINOSMutex
Definition: cinosmutex.h:35
CINOSProcessImage
Definition: cinosprocessimage.h:70
CINOSProcessImage::MatchName
static bool MatchName(const char *apName, const char *apPattern)
Try to match end part of name.
CINOSLVDT
Definition: cinosprocessimage.h:350
cinosposchannels.h
Short comment.
CINOSLVDT::Instance
static CINOSLVDT & Instance()
public
Definition: cinosprocessimage.h:376
INOS_INLINE
#define INOS_INLINE
Definition: inosdefine.h:60
g_ImageLock
CINOSMutex g_ImageLock[8]
lock used to protect process image creation
CINOSAdcChannel
Definition: cinosadcchannel.h:52
cinosprocessimagevalues.h
Short comment.
CINOSProcessImageValue
Definition: cinosprocessimagevalue.h:51
cinosadcchannels.h
Short comment.
cinosadcchannel.h
Short comment.
cinosbus.h
Short comment.
CINOSLVDT::Calibrate
static uint32 Calibrate(class CINOSAdcChannel *apChannel)
calibrate given channel
CINOSLVDT::m_Instance
static CINOSLVDT m_Instance
the one and only instance
Definition: cinosprocessimage.h:371
cinosbits.h
Short comment.
CINOSProcessImageChannel
Definition: cinosprocessimagechannel.h:110
cinosdacchannels.h
Short comment.
cinosbit.h
Description of this class.
cinosdacchannel.h
Short comment.
cinosprocessimagevalue.h
Short comment.
CINOSBus::GetFirstBus
static CINOSBus * GetFirstBus()
Return first valid bus (aka "g_pBus[0]").
Definition: cinosbus.h:606
CINOSLVDT::IsValid
static bool IsValid(class CINOSAdcChannel *apChannel)
return true if given channel is a valid LVDT channel
DECLARE_DYNAMIC
#define DECLARE_DYNAMIC(aClass)
Definition: cinospartitionmemory.h:328
cinosprocessimagechannel.h
Short comment.
cinosposchannel.h
Short comment.