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

#include <rldataacquisition.h>

Collaboration diagram for rlDataAcquisition:
Collaboration graph
[legend]

Classes

struct  SHM_HEADER
 

Public Types

enum  DAQ_ENUM { DAQ_ERROR = 256*256*128 }
 

Public Member Functions

 rlDataAcquisition (const char *mailbox="c:\utomation\bx\ataacquisition.mbx", const char *shared_memory="c:\utomation\hm\ataacquisition.shm", long shared_memory_size=65536)
 
virtual ~rlDataAcquisition ()
 
const char * stringValue (const char *variable)
 
int intValue (const char *variable)
 
float floatValue (const char *variable)
 
int writeStringValue (const char *variable, const char *value)
 
int writeIntValue (const char *variable, int value)
 
int writeFloatValue (const char *variable, float value)
 
int readErrorCount ()
 
int writeErrorCount ()
 
int lifeCounter ()
 
const char * firstVariable ()
 
const char * nextVariable ()
 
int shmStatus ()
 
int shmKey ()
 
int shmId ()
 

Private Attributes

SHM_HEADERshmheader
 
const char * shmvalues
 
rlMailboxmbx
 
rlSharedMemoryshm
 
int iCurrent
 

Detailed Description

This class is for data acquisition within pvserver according to the pvbrowser principle.
It communicates by the means of a shared memory and a mailbox.
Use it together with rlDataAcquisitionProvider.

Definition at line 28 of file rldataacquisition.h.

Member Enumeration Documentation

◆ DAQ_ENUM

Enumerator
DAQ_ERROR 

Definition at line 45 of file rldataacquisition.h.

46  {
47  DAQ_ERROR = 256*256*128
48  };

Constructor & Destructor Documentation

◆ rlDataAcquisition()

rlDataAcquisition::rlDataAcquisition ( const char *  mailbox = "c:\\automation\\mbx\\dataacquisition.mbx",
const char *  shared_memory = "c:\\automation\\shm\\dataacquisition.shm",
long  shared_memory_size = 65536 
)

Definition at line 21 of file rldataacquisition.cpp.

22 {
23  mbx = new rlMailbox(mailbox);
24  shm = new rlSharedMemory(shared_memory,shared_memory_size);
25  shmheader = (SHM_HEADER *) shm->getUserAdr();
26  shmvalues = ((const char *)shmheader) + sizeof(SHM_HEADER);
27  iCurrent = -1;
28 }
SHM_HEADER * shmheader
const char * shmvalues
rlSharedMemory * shm

◆ ~rlDataAcquisition()

rlDataAcquisition::~rlDataAcquisition ( )
virtual

Definition at line 30 of file rldataacquisition.cpp.

31 {
32  delete mbx;
33  delete shm;
34 }
rlSharedMemory * shm

Member Function Documentation

◆ firstVariable()

const char * rlDataAcquisition::firstVariable ( )

Definition at line 126 of file rldataacquisition.cpp.

127 {
128  const char *cptr;
129 
130  if(shmheader == NULL) return "DAQ_ERROR";
131  if(strcmp(shmheader->ident,"daq") != 0) return "DAQ_ERROR";
132  cptr = shmvalues;
133  iCurrent = 1;
134  return cptr;
135 }
SHM_HEADER * shmheader
const char * shmvalues

◆ floatValue()

float rlDataAcquisition::floatValue ( const char *  variable)

Definition at line 75 of file rldataacquisition.cpp.

76 {
77  const char *cptr;
78  float ret;
79 
80  cptr = stringValue(variable);
81  if(isdigit(*cptr) || *cptr == '-')
82  {
83  ret = DAQ_ERROR;
84  sscanf(cptr,"%f",&ret);
85  return ret;
86  }
87  return DAQ_ERROR;
88 }
const char * stringValue(const char *variable)

◆ intValue()

int rlDataAcquisition::intValue ( const char *  variable)

Definition at line 60 of file rldataacquisition.cpp.

61 {
62  const char *cptr;
63  int ret;
64 
65  cptr = stringValue(variable);
66  if(isdigit(*cptr))
67  {
68  ret = DAQ_ERROR;
69  sscanf(cptr,"%d",&ret);
70  return ret;
71  }
72  return DAQ_ERROR;
73 }
const char * stringValue(const char *variable)

◆ lifeCounter()

int rlDataAcquisition::lifeCounter ( )

Incremented by the daemon in each cycle

Definition at line 120 of file rldataacquisition.cpp.

121 {
122  if(shmheader == NULL) return DAQ_ERROR;
123  return shmheader->lifeCounter;
124 }
SHM_HEADER * shmheader

◆ nextVariable()

const char * rlDataAcquisition::nextVariable ( )

Definition at line 137 of file rldataacquisition.cpp.

138 {
139  int value_offset, delta_index, nmax, i;
140  const char *cptr;
141 
142  if(iCurrent < 0) return NULL;
143  if(shmheader == NULL) return "DAQ_ERROR";
144  if(strcmp(shmheader->ident,"daq") != 0) return "DAQ_ERROR";
145  value_offset = shmheader->maxItemNameLength + 1;
146  delta_index = value_offset + shmheader->maxNameLength + 1;
147  nmax = shmheader->numItems;
148 
149  cptr = shmvalues;
150  for(i=0; i<nmax; i++)
151  {
152  if(i == iCurrent)
153  {
154  iCurrent++;
155  return cptr;
156  }
157  cptr += delta_index;
158  }
159 
160  iCurrent = -1;
161  return NULL;
162 }
SHM_HEADER * shmheader
const char * shmvalues

◆ readErrorCount()

int rlDataAcquisition::readErrorCount ( )

Incremented by the daemon on each read error

Definition at line 108 of file rldataacquisition.cpp.

◆ shmId()

int rlDataAcquisition::shmId ( )

Definition at line 177 of file rldataacquisition.cpp.

178 {
179  if(shm == NULL) return -1;
180  return shm->shmId();
181 }
rlSharedMemory * shm

◆ shmKey()

int rlDataAcquisition::shmKey ( )

Definition at line 171 of file rldataacquisition.cpp.

172 {
173  if(shm == NULL) return -1;
174  return shm->shmKey();
175 }
rlSharedMemory * shm

◆ shmStatus()

int rlDataAcquisition::shmStatus ( )

Definition at line 164 of file rldataacquisition.cpp.

165 {
166  if(shmheader == NULL) return DAQ_ERROR;
167  if(shm->status == rlSharedMemory::OK) return 0;
168  return DAQ_ERROR;
169 }
SHM_HEADER * shmheader
rlSharedMemory * shm

◆ stringValue()

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

Definition at line 36 of file rldataacquisition.cpp.

37 {
38  int value_offset, delta_index, nmax, i;
39  const char *cptr;
40 
41  if(shmheader == NULL) return "DAQ_ERROR: shmheader==NULL";
42  if(strcmp(shmheader->ident,"daq") != 0) return "DAQ_ERROR: shmheader->ident is false";
43  value_offset = shmheader->maxItemNameLength + 1;
44  delta_index = value_offset + shmheader->maxNameLength + 1;
45  nmax = shmheader->numItems;
46 
47  cptr = shmvalues;
48  for(i=0; i<nmax; i++)
49  {
50  if(strcmp(cptr,variable) == 0)
51  {
52  return cptr + value_offset;
53  }
54  cptr += delta_index;
55  }
56 
57  return "DAQ_ERROR: variable not found in shared memory";
58 }
SHM_HEADER * shmheader
const char * shmvalues

◆ writeErrorCount()

int rlDataAcquisition::writeErrorCount ( )

Incremented by the daemon on each write error

Definition at line 114 of file rldataacquisition.cpp.

◆ writeFloatValue()

int rlDataAcquisition::writeFloatValue ( const char *  variable,
float  value 
)

Definition at line 102 of file rldataacquisition.cpp.

103 {
104  mbx->printf("%s,%f\n",variable,value);
105  return 0;
106 }
int printf(const char *format,...)
Definition: rlmailbox.cpp:344

◆ writeIntValue()

int rlDataAcquisition::writeIntValue ( const char *  variable,
int  value 
)

Definition at line 96 of file rldataacquisition.cpp.

97 {
98  mbx->printf("%s,%d\n",variable,value);
99  return 0;
100 }
int printf(const char *format,...)
Definition: rlmailbox.cpp:344

◆ writeStringValue()

int rlDataAcquisition::writeStringValue ( const char *  variable,
const char *  value 
)

Definition at line 90 of file rldataacquisition.cpp.

91 {
92  mbx->printf("%s,%s\n",variable,value);
93  return 0;
94 }
int printf(const char *format,...)
Definition: rlmailbox.cpp:344

Member Data Documentation

◆ iCurrent

int rlDataAcquisition::iCurrent
private

Definition at line 79 of file rldataacquisition.h.

◆ mbx

rlMailbox* rlDataAcquisition::mbx
private

Definition at line 77 of file rldataacquisition.h.

◆ shm

rlSharedMemory* rlDataAcquisition::shm
private

Definition at line 78 of file rldataacquisition.h.

◆ shmheader

SHM_HEADER* rlDataAcquisition::shmheader
private

Definition at line 75 of file rldataacquisition.h.

◆ shmvalues

const char* rlDataAcquisition::shmvalues
private

Definition at line 76 of file rldataacquisition.h.


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