rllib  1
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
rlDataAcquisitionProvider Class Reference

#include <rldataacquisitionprovider.h>

Collaboration diagram for rlDataAcquisitionProvider:
Collaboration graph
[legend]

Classes

struct  SHM_HEADER
 

Public Types

enum  DAQ_PROVIDER_ENUM { DAQ_PROVIDER_ERROR = 256*256*128 }
 

Public Member Functions

 rlDataAcquisitionProvider (int maxNameLength=31, const char *shared_memory="c:\utomation\hm\ataacquisition.shm", long shared_memory_size=65536)
 
virtual ~rlDataAcquisitionProvider ()
 
int readItemList (const char *filename)
 
const char * firstItem ()
 
const char * nextItem ()
 
const char * stringValue (const char *variable)
 
int intValue (const char *variable)
 
float floatValue (const char *variable)
 
int setStringValue (const char *variable, const char *value)
 
int setIntValue (const char *variable, int value)
 
int setFloatValue (const char *variable, float value)
 
int readErrorCount ()
 
int writeErrorCount ()
 
int lifeCounter ()
 
int setReadErrorCount (int count)
 
int setWriteErrorCount (int count)
 
int setLifeCounter (int count)
 
int shmStatus ()
 
int setAllowAddValues (int allow, int maxItemNameLength)
 

Private Attributes

SHM_HEADERshmheader
 
char * shmvalues
 
int current_item
 
int allow_add_values
 
rlSharedMemoryshm
 
long sharedMemorySize
 

Detailed Description

This class is usefull to implement your own data acquisition according to the pvbrowser principle.
It is used within pvb/template/dataacquisition/client/data_acquisition_provider_template.cpp
Starting from there you can implement your data acquisition.

Definition at line 27 of file rldataacquisitionprovider.h.

Member Enumeration Documentation

◆ DAQ_PROVIDER_ENUM

Enumerator
DAQ_PROVIDER_ERROR 

Definition at line 44 of file rldataacquisitionprovider.h.

Constructor & Destructor Documentation

◆ rlDataAcquisitionProvider()

rlDataAcquisitionProvider::rlDataAcquisitionProvider ( int  maxNameLength = 31,
const char *  shared_memory = "c:\\automation\\shm\\dataacquisition.shm",
long  shared_memory_size = 65536 
)

Definition at line 21 of file rldataacquisitionprovider.cpp.

22 {
23  shm = new rlSharedMemory(shared_memory,shared_memory_size);
24  shmheader = (SHM_HEADER *) shm->getUserAdr();
25  shmvalues = ((char *)shmheader) + sizeof(SHM_HEADER);
26  memset(shmheader,0,shared_memory_size);
28  shmheader->maxNameLength = maxNameLength;
29  shmheader->numItems = 0;
32  sharedMemorySize = shared_memory_size;
33  strcpy(shmheader->ident, "daq");
34  allow_add_values = 0;
35 }

◆ ~rlDataAcquisitionProvider()

rlDataAcquisitionProvider::~rlDataAcquisitionProvider ( )
virtual

Definition at line 37 of file rldataacquisitionprovider.cpp.

38 {
39  delete shm;
40 }

Member Function Documentation

◆ firstItem()

const char * rlDataAcquisitionProvider::firstItem ( )

Definition at line 112 of file rldataacquisitionprovider.cpp.

113 {
114  int value_offset, delta_index;
115  const char *cptr;
116 
117  current_item = 0;
118  if(shmheader == NULL) return NULL;
119  if(shmheader->numItems <= 0) return NULL;
120  if(strcmp(shmheader->ident,"daq") != 0) return NULL;
121 
122  value_offset = shmheader->maxItemNameLength + 1;
123  delta_index = value_offset + shmheader->maxNameLength + 1;
124 
125  cptr = shmvalues;
126  return cptr + (current_item * delta_index);
127 }

◆ floatValue()

float rlDataAcquisitionProvider::floatValue ( const char *  variable)

Definition at line 186 of file rldataacquisitionprovider.cpp.

187 {
188  const char *cptr;
189  float ret;
190 
191  cptr = stringValue(variable);
192  if(isdigit(*cptr) || *cptr == '-')
193  {
194  ret = DAQ_PROVIDER_ERROR;
195  sscanf(cptr,"%f",&ret);
196  return ret;
197  }
198  return DAQ_PROVIDER_ERROR;
199 }
const char * stringValue(const char *variable)

◆ intValue()

int rlDataAcquisitionProvider::intValue ( const char *  variable)

Definition at line 171 of file rldataacquisitionprovider.cpp.

172 {
173  const char *cptr;
174  int ret;
175 
176  cptr = stringValue(variable);
177  if(isdigit(*cptr))
178  {
179  ret = DAQ_PROVIDER_ERROR;
180  sscanf(cptr,"%d",&ret);
181  return ret;
182  }
183  return DAQ_PROVIDER_ERROR;
184 }
const char * stringValue(const char *variable)

◆ lifeCounter()

int rlDataAcquisitionProvider::lifeCounter ( )

◆ nextItem()

const char * rlDataAcquisitionProvider::nextItem ( )

Definition at line 129 of file rldataacquisitionprovider.cpp.

130 {
131  int value_offset, delta_index;
132  const char *cptr;
133 
134  current_item++;
135  if(shmheader == NULL) return NULL;
136  if(shmheader->numItems <= 0) return NULL;
137  if(strcmp(shmheader->ident,"daq") != 0) return NULL;
138  if(shmheader->numItems <= current_item) return NULL;
139 
140  value_offset = shmheader->maxItemNameLength + 1;
141  delta_index = value_offset + shmheader->maxNameLength + 1;
142 
143  cptr = shmvalues;
144  return cptr + (current_item * delta_index);
145 }

◆ readErrorCount()

int rlDataAcquisitionProvider::readErrorCount ( )

◆ readItemList()

int rlDataAcquisitionProvider::readItemList ( const char *  filename)

Definition at line 42 of file rldataacquisitionprovider.cpp.

43 {
44  if(filename == NULL) return DAQ_PROVIDER_ERROR;
45 
46  FILE *fin;
47  char line[1024], *cptr, *cptr2;
48  int maxItemNameLength,numItems,len,i;
49  int value_offset, delta_index;
50  int ilong;
51 
52  // get maxItemNameLength and numItems
53  fin = fopen(filename,"r");
54  if(fin == NULL)
55  {
56  printf("could not open itemlist %s\n",filename);
57  return DAQ_PROVIDER_ERROR;
58  }
59  maxItemNameLength = numItems = 0;
60  while(fgets(line,sizeof(line)-1,fin) != NULL)
61  {
62  if(line[0] > ' ' && line[0] != '#')
63  {
64  len = strlen(line);
65  if(len > maxItemNameLength) maxItemNameLength = len;
66  numItems++;
67  }
68  }
69  fclose(fin);
70  shmheader->maxItemNameLength = maxItemNameLength;
71  shmheader->numItems = numItems;
72 
73  // read items
74  fin = fopen(filename,"r");
75  if(fin == NULL)
76  {
77  printf("could not open itemlist %s\n",filename);
78  return DAQ_PROVIDER_ERROR;
79  }
80  cptr = shmvalues;
81  value_offset = shmheader->maxItemNameLength + 1;
82  delta_index = value_offset + shmheader->maxNameLength + 1;
83  ilong = sharedMemorySize - sizeof(SHM_HEADER);
84  if(ilong < numItems*delta_index)
85  {
86  printf("rlDataAcquisitionProvider::shared memmory is too small sharedMemorySize=%ld sizeNeeded=%d\n", sharedMemorySize, (int) (numItems*delta_index + sizeof(SHM_HEADER)));
87  return DAQ_PROVIDER_ERROR;
88  }
89  i = 0;
90  while(fgets(line,sizeof(line)-1,fin) != NULL)
91  {
92  if(line[0] > ' ' && line[0] != '#')
93  {
94  len = strlen(line);
95  if(len > shmheader->maxNameLength) line[shmheader->maxNameLength] = '\0';
96  cptr2 = strchr(line,'\n');
97  if(cptr2 != NULL) *cptr2 = '\0';
98  cptr2 = strchr(line,' ');
99  if(cptr2 != NULL) *cptr2 = '\0';
100  cptr2 = strchr(line,'\t');
101  if(cptr2 != NULL) *cptr2 = '\0';
102  strcpy(cptr + (i*delta_index), line);
103  i++;
104  }
105  }
106  fclose(fin);
107  strcpy(shmheader->ident, "daq");
108 
109  return 0;
110 }

◆ setAllowAddValues()

int rlDataAcquisitionProvider::setAllowAddValues ( int  allow,
int  maxItemNameLength 
)

Definition at line 314 of file rldataacquisitionprovider.cpp.

315 {
316  if(allow == 0) allow_add_values = 0;
317  else allow_add_values = 1;
318  if(maxItemNameLength > 0) shmheader->maxItemNameLength = maxItemNameLength;
319  return 0;
320 }

◆ setFloatValue()

int rlDataAcquisitionProvider::setFloatValue ( const char *  variable,
float  value 
)

Definition at line 260 of file rldataacquisitionprovider.cpp.

261 {
262  char cval[128];
263 
264  sprintf(cval,"%f",value);
265  return setStringValue(variable,cval);
266 }
int setStringValue(const char *variable, const char *value)

◆ setIntValue()

int rlDataAcquisitionProvider::setIntValue ( const char *  variable,
int  value 
)

Definition at line 252 of file rldataacquisitionprovider.cpp.

253 {
254  char cval[128];
255 
256  sprintf(cval,"%d",value);
257  return setStringValue(variable,cval);
258 }
int setStringValue(const char *variable, const char *value)

◆ setLifeCounter()

int rlDataAcquisitionProvider::setLifeCounter ( int  count)

◆ setReadErrorCount()

int rlDataAcquisitionProvider::setReadErrorCount ( int  count)

◆ setStringValue()

int rlDataAcquisitionProvider::setStringValue ( const char *  variable,
const char *  value 
)

Definition at line 201 of file rldataacquisitionprovider.cpp.

202 {
203  if(variable == NULL || value == NULL || shmheader == NULL) return DAQ_PROVIDER_ERROR;
204  if(strcmp(shmheader->ident,"daq") != 0) return DAQ_PROVIDER_ERROR;
205 
206  int value_offset, delta_index, nmax, i;
207  char *cptr;
208 
209  if((int) strlen(variable) > shmheader->maxItemNameLength) return DAQ_PROVIDER_ERROR;
210 
211  int len = strlen(value);
212  char *val = new char[len+1];
213  strcpy(val,value);
214  if(len > shmheader->maxNameLength) val[shmheader->maxNameLength] = '\0';
215 
216  value_offset = shmheader->maxItemNameLength + 1;
217  delta_index = value_offset + shmheader->maxNameLength + 1;
218  nmax = shmheader->numItems;
219 
220  cptr = shmvalues;
221  for(i=0; i<nmax; i++)
222  {
223  if(strcmp(cptr,variable) == 0)
224  {
225  strcpy(cptr + value_offset, val); // update existing value
226  delete [] val;
227  return 0;
228  }
229  cptr += delta_index;
230  }
231 
232  if(allow_add_values == 1) // insert a new value
233  {
234  if(sharedMemorySize > ( (long) sizeof(SHM_HEADER) + (i*delta_index) + delta_index ) )
235  {
236  strcpy(cptr, variable); // insert the value
237  strcpy(cptr + value_offset, val); // insert the value
238  delete [] val;
239  shmheader->numItems += 1;
240  return 0;
241  }
242  else
243  {
244  ::printf("rlDataAcquisitionProvider: ERROR shared memory too small to add variable=%s val=%s please increase shared memory size", variable, val);
245  }
246  }
247 
248  delete [] val;
249  return DAQ_PROVIDER_ERROR;
250 }

◆ setWriteErrorCount()

int rlDataAcquisitionProvider::setWriteErrorCount ( int  count)

◆ shmStatus()

int rlDataAcquisitionProvider::shmStatus ( )

◆ stringValue()

const char * rlDataAcquisitionProvider::stringValue ( const char *  variable)

Definition at line 147 of file rldataacquisitionprovider.cpp.

148 {
149  int value_offset, delta_index, nmax, i;
150  const char *cptr;
151 
152  if(shmheader == NULL) return "DAQ_ERROR";
153  if(strcmp(shmheader->ident,"daq") != 0) return "DAQ_ERROR";
154  value_offset = shmheader->maxItemNameLength + 1;
155  delta_index = value_offset + shmheader->maxNameLength + 1;
156  nmax = shmheader->numItems;
157 
158  cptr = shmvalues;
159  for(i=0; i<nmax; i++)
160  {
161  if(strcmp(cptr,variable) == 0)
162  {
163  return cptr + value_offset;
164  }
165  cptr += delta_index;
166  }
167 
168  return "DAQ_ERROR";
169 }

◆ writeErrorCount()

int rlDataAcquisitionProvider::writeErrorCount ( )

Member Data Documentation

◆ allow_add_values

int rlDataAcquisitionProvider::allow_add_values
private

Definition at line 76 of file rldataacquisitionprovider.h.

◆ current_item

int rlDataAcquisitionProvider::current_item
private

Definition at line 76 of file rldataacquisitionprovider.h.

◆ sharedMemorySize

long rlDataAcquisitionProvider::sharedMemorySize
private

Definition at line 78 of file rldataacquisitionprovider.h.

◆ shm

rlSharedMemory* rlDataAcquisitionProvider::shm
private

Definition at line 77 of file rldataacquisitionprovider.h.

◆ shmheader

SHM_HEADER* rlDataAcquisitionProvider::shmheader
private

Definition at line 74 of file rldataacquisitionprovider.h.

◆ shmvalues

char* rlDataAcquisitionProvider::shmvalues
private

Definition at line 75 of file rldataacquisitionprovider.h.


The documentation for this class was generated from the following files: