ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdcsRTD.hpp
Go to the documentation of this file.
1
7#ifndef ngcdcsRTD_H
8#define ngcdcsRTD_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
15#include <ngc/core/ngcbSHM.hpp>
16
20#define ngcdcsRTD_MAX_ACQ 24
21
27 char host[64];
28
31
33 int nx;
34
36 int ny;
37
40 memset(host, 0, sizeof(host));
41 dataPort = 0; nx = 0; ny = 0;
42 }
43};
44
52
56class ngcdcsRTD: public ngcbSHMDB
57{
58public:
60 explicit ngcdcsRTD(const char *s, ngcdcs_rtdshm_t *initVal = NULL)
61 : ngcbSHMDB("ngcdcsrtd", s, initVal, sizeof(ngcdcs_rtdshm_t)) {
62 shm_ = static_cast<ngcdcs_rtdshm_t *>(shmBuf);
63 server_ = (initVal != NULL);
64 }
65
67 virtual ~ngcdcsRTD() {
68 shm_ = NULL;
69 }
70
72 void Cfg(int idx, const ngcdcs_rtdacq_t &acq) {
73 if (server_ && (CheckIdx_(idx) == 0))
74 {
75 if (Lock() != -1)
76 {
77 memcpy(&shm_->acq[idx], &acq, sizeof(ngcdcs_rtdacq_t));
78 Unlock();
79 }
80 }
81 }
82
84 int GetCfg(int idx, ngcdcs_rtdacq_t *acq) {
85 if (CheckIdx_(idx) != 0) return (-1);
86 else if (Lock() != 0) return (-1);
87 else
88 {
89 memcpy(acq, &shm_->acq[idx], sizeof(ngcdcs_rtdacq_t));
90 Unlock();
91 }
92 return (0);
93 }
94
95protected:
96
97private:
99 ngcdcs_rtdshm_t *shm_;
100
102 int server_;
103
105 int CheckIdx_(int idx) {
106 if ((idx < 0) || (idx >= ngcdcsRTD_MAX_ACQ))
107 {
108 strcpy(ErrMsg(), "invalid acquisition module index");
109 return (-1);
110 }
111 else
112 {
113 return (0);
114 }
115 }
116};
117
118#endif
void * shmBuf
Shared memory buffer.
Definition ngcbSHMDB.hpp:57
ngcbSHMDB(const char *app, const char *s, void *initBuffer=NULL, size_t size=0)
Constructor.
Definition ngcbSHMDB.hpp:60
int Lock()
Lock shared memory.
Definition ngcbSHMDB.hpp:278
void Unlock()
Unlock shared memory.
Definition ngcbSHMDB.hpp:319
char * ErrMsg()
Error message.
Definition ngcbSHMDB.hpp:275
ngcdcsRTD(const char *s, ngcdcs_rtdshm_t *initVal=NULL)
Constructor.
Definition ngcdcsRTD.hpp:60
int GetCfg(int idx, ngcdcs_rtdacq_t *acq)
Get connection configuration.
Definition ngcdcsRTD.hpp:84
void Cfg(int idx, const ngcdcs_rtdacq_t &acq)
Configure.
Definition ngcdcsRTD.hpp:72
virtual ~ngcdcsRTD()
Destructor.
Definition ngcdcsRTD.hpp:67
#define ngcdcsRTD_MAX_ACQ
Definition ngcdcsRTD.hpp:20
Definition ngcdcsRTD.hpp:25
int ny
Maximum Y-dimension.
Definition ngcdcsRTD.hpp:36
char host[64]
Host name.
Definition ngcdcsRTD.hpp:27
int dataPort
Data port number.
Definition ngcdcsRTD.hpp:30
int nx
Maximum X-dimension.
Definition ngcdcsRTD.hpp:33
ngcdcs_rtdacq_t()
Constructor.
Definition ngcdcsRTD.hpp:39
Definition ngcdcsRTD.hpp:48
ngcdcs_rtdacq_t acq[ngcdcsRTD_MAX_ACQ]
Acquisition process configuration structures.
Definition ngcdcsRTD.hpp:50