#include <rldataacquisitionprovider.h>

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="/srv/automation/shm/dataacquisition.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 | setReadErrorCount (int count) |
| int | setWriteErrorCount (int count) |
| int | shmStatus () |
| int | setAllowAddValues (int allow, int maxItemNameLength) |
Private Attributes | |
| SHM_HEADER * | shmheader |
| char * | shmvalues |
| int | current_item |
| int | allow_add_values |
| rlSharedMemory * | shm |
| long | sharedMemorySize |
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.
Definition at line 43 of file rldataacquisitionprovider.h.
00044 { 00045 DAQ_PROVIDER_ERROR = 256*256*128 00046 };
| rlDataAcquisitionProvider::rlDataAcquisitionProvider | ( | int | maxNameLength = 31, |
|
| const char * | shared_memory = "/srv/automation/shm/dataacquisition.shm", |
|||
| long | shared_memory_size = 65536 | |||
| ) |
Definition at line 21 of file rldataacquisitionprovider.cpp.
00022 { 00023 shm = new rlSharedMemory(shared_memory,shared_memory_size); 00024 shmheader = (SHM_HEADER *) shm->getUserAdr(); 00025 shmvalues = ((char *)shmheader) + sizeof(SHM_HEADER); 00026 memset(shmheader,0,shared_memory_size); 00027 shmheader->maxItemNameLength = 0; 00028 shmheader->maxNameLength = maxNameLength; 00029 shmheader->numItems = 0; 00030 shmheader->readErrorCount = 0; 00031 shmheader->writeErrorCount = 0; 00032 sharedMemorySize = shared_memory_size; 00033 strcpy(shmheader->ident, "daq"); 00034 allow_add_values = 0; 00035 }
| rlDataAcquisitionProvider::~rlDataAcquisitionProvider | ( | ) | [virtual] |
Definition at line 37 of file rldataacquisitionprovider.cpp.
00038 { 00039 delete shm; 00040 }
| const char * rlDataAcquisitionProvider::firstItem | ( | ) |
Definition at line 112 of file rldataacquisitionprovider.cpp.
00113 { 00114 int value_offset, delta_index; 00115 const char *cptr; 00116 00117 current_item = 0; 00118 if(shmheader == NULL) return NULL; 00119 if(shmheader->numItems <= 0) return NULL; 00120 if(strcmp(shmheader->ident,"daq") != 0) return NULL; 00121 00122 value_offset = shmheader->maxItemNameLength + 1; 00123 delta_index = value_offset + shmheader->maxNameLength + 1; 00124 00125 cptr = shmvalues; 00126 return cptr + (current_item * delta_index); 00127 }
| float rlDataAcquisitionProvider::floatValue | ( | const char * | variable | ) |
Definition at line 186 of file rldataacquisitionprovider.cpp.
00187 { 00188 const char *cptr; 00189 float ret; 00190 00191 cptr = stringValue(variable); 00192 if(isdigit(*cptr) || *cptr == '-') 00193 { 00194 ret = DAQ_PROVIDER_ERROR; 00195 sscanf(cptr,"%f",&ret); 00196 return ret; 00197 } 00198 return DAQ_PROVIDER_ERROR; 00199 }
| int rlDataAcquisitionProvider::intValue | ( | const char * | variable | ) |
Definition at line 171 of file rldataacquisitionprovider.cpp.
00172 { 00173 const char *cptr; 00174 int ret; 00175 00176 cptr = stringValue(variable); 00177 if(isdigit(*cptr)) 00178 { 00179 ret = DAQ_PROVIDER_ERROR; 00180 sscanf(cptr,"%d",&ret); 00181 return ret; 00182 } 00183 return DAQ_PROVIDER_ERROR; 00184 }
| const char * rlDataAcquisitionProvider::nextItem | ( | ) |
Definition at line 129 of file rldataacquisitionprovider.cpp.
00130 { 00131 int value_offset, delta_index; 00132 const char *cptr; 00133 00134 current_item++; 00135 if(shmheader == NULL) return NULL; 00136 if(shmheader->numItems <= 0) return NULL; 00137 if(strcmp(shmheader->ident,"daq") != 0) return NULL; 00138 if(shmheader->numItems <= current_item) return NULL; 00139 00140 value_offset = shmheader->maxItemNameLength + 1; 00141 delta_index = value_offset + shmheader->maxNameLength + 1; 00142 00143 cptr = shmvalues; 00144 return cptr + (current_item * delta_index); 00145 }
| int rlDataAcquisitionProvider::readErrorCount | ( | ) |
Definition at line 268 of file rldataacquisitionprovider.cpp.
00269 { 00270 if(shmheader == NULL) return DAQ_PROVIDER_ERROR; 00271 return shmheader->readErrorCount; 00272 }
| int rlDataAcquisitionProvider::readItemList | ( | const char * | filename | ) |
Definition at line 42 of file rldataacquisitionprovider.cpp.
00043 { 00044 if(filename == NULL) return DAQ_PROVIDER_ERROR; 00045 00046 FILE *fin; 00047 char line[1024], *cptr, *cptr2; 00048 int maxItemNameLength,numItems,len,i; 00049 int value_offset, delta_index; 00050 int ilong; 00051 00052 // get maxItemNameLength and numItems 00053 fin = fopen(filename,"r"); 00054 if(fin == NULL) 00055 { 00056 printf("could not open itemlist %s\n",filename); 00057 return DAQ_PROVIDER_ERROR; 00058 } 00059 maxItemNameLength = numItems = 0; 00060 while(fgets(line,sizeof(line)-1,fin) != NULL) 00061 { 00062 if(line[0] > ' ' && line[0] != '#') 00063 { 00064 len = strlen(line); 00065 if(len > maxItemNameLength) maxItemNameLength = len; 00066 numItems++; 00067 } 00068 } 00069 fclose(fin); 00070 shmheader->maxItemNameLength = maxItemNameLength; 00071 shmheader->numItems = numItems; 00072 00073 // read items 00074 fin = fopen(filename,"r"); 00075 if(fin == NULL) 00076 { 00077 printf("could not open itemlist %s\n",filename); 00078 return DAQ_PROVIDER_ERROR; 00079 } 00080 cptr = shmvalues; 00081 value_offset = shmheader->maxItemNameLength + 1; 00082 delta_index = value_offset + shmheader->maxNameLength + 1; 00083 ilong = sharedMemorySize - sizeof(SHM_HEADER); 00084 if(ilong < numItems*delta_index) 00085 { 00086 printf("rlDataAcquisitionProvider::shared memmory is too small sharedMemorySize=%ld sizeNeeded=%ld\n", sharedMemorySize, numItems*delta_index + sizeof(SHM_HEADER)); 00087 return DAQ_PROVIDER_ERROR; 00088 } 00089 i = 0; 00090 while(fgets(line,sizeof(line)-1,fin) != NULL) 00091 { 00092 if(line[0] > ' ' && line[0] != '#') 00093 { 00094 len = strlen(line); 00095 if(len > shmheader->maxNameLength) line[shmheader->maxNameLength] = '\0'; 00096 cptr2 = strchr(line,'\n'); 00097 if(cptr2 != NULL) *cptr2 = '\0'; 00098 cptr2 = strchr(line,' '); 00099 if(cptr2 != NULL) *cptr2 = '\0'; 00100 cptr2 = strchr(line,'\t'); 00101 if(cptr2 != NULL) *cptr2 = '\0'; 00102 strcpy(cptr + (i*delta_index), line); 00103 i++; 00104 } 00105 } 00106 fclose(fin); 00107 strcpy(shmheader->ident, "daq"); 00108 00109 return 0; 00110 }
| int rlDataAcquisitionProvider::setAllowAddValues | ( | int | allow, | |
| int | maxItemNameLength | |||
| ) |
Definition at line 301 of file rldataacquisitionprovider.cpp.
00302 { 00303 if(allow == 0) allow_add_values = 0; 00304 else allow_add_values = 1; 00305 if(maxItemNameLength > 0) shmheader->maxItemNameLength = maxItemNameLength; 00306 return 0; 00307 }
| int rlDataAcquisitionProvider::setFloatValue | ( | const char * | variable, | |
| float | value | |||
| ) |
Definition at line 260 of file rldataacquisitionprovider.cpp.
00261 { 00262 char cval[128]; 00263 00264 sprintf(cval,"%f",value); 00265 return setStringValue(variable,cval); 00266 }
| int rlDataAcquisitionProvider::setIntValue | ( | const char * | variable, | |
| int | value | |||
| ) |
Definition at line 252 of file rldataacquisitionprovider.cpp.
00253 { 00254 char cval[128]; 00255 00256 sprintf(cval,"%d",value); 00257 return setStringValue(variable,cval); 00258 }
| int rlDataAcquisitionProvider::setReadErrorCount | ( | int | count | ) |
Definition at line 280 of file rldataacquisitionprovider.cpp.
00281 { 00282 if(shmheader == NULL) return DAQ_PROVIDER_ERROR; 00283 shmheader->readErrorCount = count; 00284 return 0; 00285 }
| int rlDataAcquisitionProvider::setStringValue | ( | const char * | variable, | |
| const char * | value | |||
| ) |
Definition at line 201 of file rldataacquisitionprovider.cpp.
00202 { 00203 if(variable == NULL || value == NULL || shmheader == NULL) return DAQ_PROVIDER_ERROR; 00204 if(strcmp(shmheader->ident,"daq") != 0) return DAQ_PROVIDER_ERROR; 00205 00206 int value_offset, delta_index, nmax, i; 00207 char *cptr; 00208 00209 if((int) strlen(variable) > shmheader->maxItemNameLength) return DAQ_PROVIDER_ERROR; 00210 00211 int len = strlen(value); 00212 char *val = new char[len+1]; 00213 strcpy(val,value); 00214 if(len > shmheader->maxNameLength) val[shmheader->maxNameLength] = '\0'; 00215 00216 value_offset = shmheader->maxItemNameLength + 1; 00217 delta_index = value_offset + shmheader->maxNameLength + 1; 00218 nmax = shmheader->numItems; 00219 00220 cptr = shmvalues; 00221 for(i=0; i<nmax; i++) 00222 { 00223 if(strcmp(cptr,variable) == 0) 00224 { 00225 strcpy(cptr + value_offset, val); // update existing value 00226 delete [] val; 00227 return 0; 00228 } 00229 cptr += delta_index; 00230 } 00231 00232 if(allow_add_values == 1) // insert a new value 00233 { 00234 if(sharedMemorySize > ( (long) sizeof(SHM_HEADER) + (i*delta_index) + delta_index ) ) 00235 { 00236 strcpy(cptr, variable); // insert the value 00237 strcpy(cptr + value_offset, val); // insert the value 00238 delete [] val; 00239 shmheader->numItems += 1; 00240 return 0; 00241 } 00242 else 00243 { 00244 ::printf("rlDataAcquisitionProvider: ERROR shared memory too small to add variable=%s val=%s please increase shared memory size", variable, val); 00245 } 00246 } 00247 00248 delete [] val; 00249 return DAQ_PROVIDER_ERROR; 00250 }
| int rlDataAcquisitionProvider::setWriteErrorCount | ( | int | count | ) |
Definition at line 287 of file rldataacquisitionprovider.cpp.
00288 { 00289 if(shmheader == NULL) return DAQ_PROVIDER_ERROR; 00290 shmheader->writeErrorCount = count; 00291 return 0; 00292 }
| int rlDataAcquisitionProvider::shmStatus | ( | ) |
Definition at line 294 of file rldataacquisitionprovider.cpp.
00295 { 00296 if(shmheader == NULL) return DAQ_PROVIDER_ERROR; 00297 if(shm->status == rlSharedMemory::OK) return 0; 00298 return DAQ_PROVIDER_ERROR; 00299 }
| const char * rlDataAcquisitionProvider::stringValue | ( | const char * | variable | ) |
Definition at line 147 of file rldataacquisitionprovider.cpp.
00148 { 00149 int value_offset, delta_index, nmax, i; 00150 const char *cptr; 00151 00152 if(shmheader == NULL) return "DAQ_ERROR"; 00153 if(strcmp(shmheader->ident,"daq") != 0) return "DAQ_ERROR"; 00154 value_offset = shmheader->maxItemNameLength + 1; 00155 delta_index = value_offset + shmheader->maxNameLength + 1; 00156 nmax = shmheader->numItems; 00157 00158 cptr = shmvalues; 00159 for(i=0; i<nmax; i++) 00160 { 00161 if(strcmp(cptr,variable) == 0) 00162 { 00163 return cptr + value_offset; 00164 } 00165 cptr += delta_index; 00166 } 00167 00168 return "DAQ_ERROR"; 00169 }
| int rlDataAcquisitionProvider::writeErrorCount | ( | ) |
Definition at line 274 of file rldataacquisitionprovider.cpp.
00275 { 00276 if(shmheader == NULL) return DAQ_PROVIDER_ERROR; 00277 return shmheader->writeErrorCount; 00278 }
int rlDataAcquisitionProvider::allow_add_values [private] |
Definition at line 73 of file rldataacquisitionprovider.h.
int rlDataAcquisitionProvider::current_item [private] |
Definition at line 73 of file rldataacquisitionprovider.h.
long rlDataAcquisitionProvider::sharedMemorySize [private] |
Definition at line 75 of file rldataacquisitionprovider.h.
rlSharedMemory* rlDataAcquisitionProvider::shm [private] |
Definition at line 74 of file rldataacquisitionprovider.h.
SHM_HEADER* rlDataAcquisitionProvider::shmheader [private] |
Definition at line 71 of file rldataacquisitionprovider.h.
char* rlDataAcquisitionProvider::shmvalues [private] |
Definition at line 72 of file rldataacquisitionprovider.h.
1.6.3