Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
gdatalogger.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GDATALOGGERVARIABLE
 
struct  GDATALOGGER
 
struct  GDATALOGGERIPC_SHM
 

Macros

#define GDATALOGGER_MAXVARIABLES   150
 
#define QUEUE_MAXDESTINATIONS   4
 
#define QUEUE_DESTINATION_FILE   QUEUE_READ_GATE_0
 
#define QUEUE_DESTINATION_IPC   QUEUE_READ_GATE_1
 
#define QUEUE_DESTINATION_USER1   QUEUE_READ_GATE_2
 
#define QUEUE_DESTINATION_USER2   QUEUE_READ_GATE_3
 
#define GDATALOGGER_IPC_MAXQUEUESIZE   1000
 
#define GDATALOGGER_IPC_FLAGIDDLE   0
 
#define GDATALOGGER_IPC_FLAGREQUESTDATA   1
 
#define GDATALOGGER_IPC_FLAGDATAAVAILABLE   2
 
#define GDATALOGGER_IPC_FLAGNOTEXIST   3
 
#define GDATALOGGER_IPC_FLAGTIMEOUT   4
 
#define GDATALOGGER_IPC_STATEFILE   "/gdatalogger.shm"
 

Typedefs

typedef struct
GDATALOGGERVARIABLE
PGDATALOGGERVARIABLE
 
typedef struct GDATALOGGERPGDATALOGGER
 

Functions

int gDataLogger_Init (PGDATALOGGER pgDataLogger, char *filename, char *dirname)
 
int gDataLogger_DeclareVariable (PGDATALOGGER pgDataLogger, char *varname, char *varunit, int nrows, int ncols, int queuesize)
 
int gDataLogger_InsertVariable (PGDATALOGGER pgDataLogger, char *varname, double *varvalue)
 
int gDataLogger_IPC_RetrieveVariable (char *varname, char *varunit, double *pbuffer, int *bufferlen)
 
int gDataLogger_MatfileUpdate (PGDATALOGGER pgDataLogger)
 
int gDataLogger_IPCUpdate (PGDATALOGGER pgDataLogger)
 
int gDataLogger_Close (PGDATALOGGER pgDataLogger)
 

Macro Definition Documentation

#define GDATALOGGER_IPC_FLAGDATAAVAILABLE   2

Definition at line 41 of file gdatalogger.h.

Referenced by gDataLogger_IPC_RetrieveVariable(), and gDataLogger_IPCUpdate().

#define GDATALOGGER_IPC_FLAGIDDLE   0

Definition at line 39 of file gdatalogger.h.

Referenced by gDataLogger_Init(), and gDataLogger_IPC_RetrieveVariable().

#define GDATALOGGER_IPC_FLAGNOTEXIST   3

Definition at line 42 of file gdatalogger.h.

Referenced by gDataLogger_IPC_RetrieveVariable(), and gDataLogger_IPCUpdate().

#define GDATALOGGER_IPC_FLAGREQUESTDATA   1

Definition at line 40 of file gdatalogger.h.

Referenced by gDataLogger_IPC_RetrieveVariable(), and gDataLogger_IPCUpdate().

#define GDATALOGGER_IPC_FLAGTIMEOUT   4

Definition at line 43 of file gdatalogger.h.

Referenced by gDataLogger_IPC_RetrieveVariable().

#define GDATALOGGER_IPC_MAXQUEUESIZE   1000

Definition at line 38 of file gdatalogger.h.

#define GDATALOGGER_IPC_STATEFILE   "/gdatalogger.shm"

Definition at line 56 of file gdatalogger.h.

Referenced by gDataLogger_Close(), and gDataLogger_Init().

#define GDATALOGGER_MAXVARIABLES   150

Definition at line 13 of file gdatalogger.h.

Referenced by gDataLogger_DeclareVariable(), and gDataLogger_Init().

#define QUEUE_DESTINATION_FILE   QUEUE_READ_GATE_0

Definition at line 33 of file gdatalogger.h.

Referenced by gDataLogger_InsertVariable(), and gDataLogger_MatfileUpdate().

#define QUEUE_DESTINATION_IPC   QUEUE_READ_GATE_1

Definition at line 34 of file gdatalogger.h.

Referenced by gDataLogger_IPCUpdate().

#define QUEUE_DESTINATION_USER1   QUEUE_READ_GATE_2

Definition at line 35 of file gdatalogger.h.

#define QUEUE_DESTINATION_USER2   QUEUE_READ_GATE_3

Definition at line 36 of file gdatalogger.h.

#define QUEUE_MAXDESTINATIONS   4

Definition at line 32 of file gdatalogger.h.

Referenced by gDataLogger_DeclareVariable().

Typedef Documentation

typedef struct GDATALOGGER* PGDATALOGGER

Function Documentation

int gDataLogger_Close ( PGDATALOGGER  pgDataLogger)

Definition at line 362 of file gdatalogger.c.

References GDATALOGGERVARIABLE::CircularQueue, GDATALOGGER_IPC_STATEFILE, gDataLogger_MatfileUpdate(), gDataLoggerIPC_SHM_fd, gDataLoggerIPC_SHM_flagmodeserver, gMATLABDataFile_Close(), gMATLABDataFile_SaveVector(), GDATALOGGER::GMatlabDataFileConfig, GDATALOGGERVARIABLE::GMatlabDataFileIndex, GDATALOGGERVARIABLE::HasBeenWritten, GDATALOGGER::m_NumberOfVariables, GDATALOGGERVARIABLE::Nc, GDATALOGGERVARIABLE::Nr, TRUE, GDATALOGGERVARIABLE::VariableName, GDATALOGGER::Variables, and GDATALOGGERVARIABLE::VariableUnit.

Referenced by datalogger_close().

363 {
364  int nvar,datasize;
365  double v;
366  double *value;
367  char matvarname[70];
368 
369  /* Garante salvar ultimos dados inseridos: */
370  if(pgDataLogger!=NULL){
371  gDataLogger_MatfileUpdate(pgDataLogger);
372 
373  /* Se for um unico escalar, trata de forma especial: */
374  for(nvar=0;nvar<pgDataLogger->m_NumberOfVariables;++nvar){
375  if((pgDataLogger->Variables[nvar].Nc == 1)&&(pgDataLogger->Variables[nvar].Nr == 1)){
376  if(pgDataLogger->Variables[nvar].HasBeenWritten == 1){
377  value = (double *) malloc(sizeof(double));
378  value[0] = pgDataLogger->Variables[nvar].CircularQueue[0];
379  sprintf(matvarname,"%s_%li_%li",pgDataLogger->Variables[nvar].VariableName, (long int)0, (long int)0);
380  gMATLABDataFile_SaveVector(&pgDataLogger->GMatlabDataFileConfig, matvarname, value, 1);
381  free(value);
382  pgDataLogger->Variables[nvar].GMatlabDataFileIndex = 1;
383  }
384  }
385  }
386 
387  /* Cria variaveis que indicam o numero de cada variavel salva: */
388  for(nvar=0;nvar<pgDataLogger->m_NumberOfVariables;++nvar){
389  v = (double)(pgDataLogger->Variables[nvar].GMatlabDataFileIndex);
390  datasize = 1;
391  sprintf(matvarname,"%s_size",pgDataLogger->Variables[nvar].VariableName);
392  gMATLABDataFile_SaveVector(&pgDataLogger->GMatlabDataFileConfig, matvarname, &v, datasize);
393  }
394 
395  /* Salva o numero de linhas: */
396  for(nvar=0;nvar<pgDataLogger->m_NumberOfVariables;++nvar){
397  v = (double)(pgDataLogger->Variables[nvar].Nr);
398  datasize = 1;
399  sprintf(matvarname,"%s_nr",pgDataLogger->Variables[nvar].VariableName);
400  gMATLABDataFile_SaveVector(&pgDataLogger->GMatlabDataFileConfig, matvarname, &v, datasize);
401  }
402 
403  /* Salva o numero de colunas: */
404  for(nvar=0;nvar<pgDataLogger->m_NumberOfVariables;++nvar){
405  v = (double)(pgDataLogger->Variables[nvar].Nc);
406  datasize = 1;
407  sprintf(matvarname,"%s_nc",pgDataLogger->Variables[nvar].VariableName);
408  gMATLABDataFile_SaveVector(&pgDataLogger->GMatlabDataFileConfig, matvarname, &v, datasize);
409  }
410 
411  /* Fecha o arquivo. */
413 
414  /* Deletar as filas: */
415  for(nvar=0;nvar<pgDataLogger->m_NumberOfVariables;++nvar){
416  sprintf(pgDataLogger->Variables[nvar].VariableName," ");
417  sprintf(pgDataLogger->Variables[nvar].VariableUnit," ");
418  free(pgDataLogger->Variables[nvar].CircularQueue);
419  pgDataLogger->Variables[nvar].CircularQueue = NULL;
420  pgDataLogger->Variables[nvar].GMatlabDataFileIndex = 0;
421  }
422  pgDataLogger->m_NumberOfVariables = 0;
423  }
424 
425  /* IPC: */
426 #if DATALOGGER_COMPILE_FOR_XENOMAI
428  rt_heap_free(&gDataLoggerIPC_SHM_hd,pgDataLoggerIPC_SHM);
429  rt_heap_delete(&gDataLoggerIPC_SHM_hd);
430  } else{
431  rt_heap_unbind(&gDataLoggerIPC_SHM_hd);
432  }
433 #else
434  munmap(pgDataLoggerIPC_SHM, sizeof(GDATALOGGERIPC_SHM));
435  close(gDataLoggerIPC_SHM_fd);
436  shm_unlink(GDATALOGGER_IPC_STATEFILE);
437 #endif
438 
439  return(TRUE);
440 }
int gMATLABDataFile_SaveVector(PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, const char *varname, double *v, long nlin)
GDATALOGGERVARIABLE Variables[GDATALOGGER_MAXVARIABLES]
Definition: gdatalogger.h:27
char VariableName[100]
Definition: gdatalogger.h:16
void gMATLABDataFile_Close(PGMATLABDATAFILECONFIG pGMatlabDataFileConfig)
double * CircularQueue
Definition: gdatalogger.h:21
GMATLABDATAFILECONFIG GMatlabDataFileConfig
Definition: gdatalogger.h:29
char VariableUnit[50]
Definition: gdatalogger.h:17
long int GMatlabDataFileIndex
Definition: gdatalogger.h:18
static int gDataLoggerIPC_SHM_flagmodeserver
Definition: gdatalogger.c:31
#define TRUE
int gDataLogger_MatfileUpdate(PGDATALOGGER pgDataLogger)
Definition: gdatalogger.c:245
int m_NumberOfVariables
Definition: gdatalogger.h:28
static int gDataLoggerIPC_SHM_fd
Definition: gdatalogger.c:36
#define GDATALOGGER_IPC_STATEFILE
Definition: gdatalogger.h:56
static GDATALOGGERIPC_SHM * pgDataLoggerIPC_SHM
Definition: gdatalogger.c:30

Here is the call graph for this function:

Here is the caller graph for this function:

int gDataLogger_DeclareVariable ( PGDATALOGGER  pgDataLogger,
char *  varname,
char *  varunit,
int  nrows,
int  ncols,
int  queuesize 
)

Definition at line 173 of file gdatalogger.c.

References GDATALOGGERVARIABLE::CircularQueue, GDATALOGGERVARIABLE::CircularQueueControl, FALSE, GDATALOGGER_MAXVARIABLES, GDATALOGGERVARIABLE::GMatlabDataFileIndex, gQUEUE_Init(), GDATALOGGER::m_NumberOfVariables, GDATALOGGERVARIABLE::Nc, GDATALOGGERVARIABLE::Nr, QUEUE_MAXDESTINATIONS, TRUE, GDATALOGGERVARIABLE::VariableName, GDATALOGGER::Variables, and GDATALOGGERVARIABLE::VariableUnit.

Referenced by datalogger_init().

174 {
175  if(pgDataLogger->m_NumberOfVariables>=GDATALOGGER_MAXVARIABLES-1){
176  return(FALSE);
177  }
178  queuesize = queuesize * nrows * ncols; /* no caso, o tamanho da fila eh calculado em numero de elementos double. */
179  sprintf(pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].VariableName,"%s",varname);
180  sprintf(pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].VariableUnit,"%s",varunit);
181  pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].CircularQueue = (double *) malloc(queuesize * nrows * ncols * sizeof(double));
182  if(pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].CircularQueue==NULL){
183  return(FALSE);
184  }
185  pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].Nr = nrows;
186  pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].Nc = ncols;
187  gQUEUE_Init(&pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].CircularQueueControl, queuesize, QUEUE_MAXDESTINATIONS);
188  pgDataLogger->Variables[pgDataLogger->m_NumberOfVariables].GMatlabDataFileIndex = 0;
189 
190  ++pgDataLogger->m_NumberOfVariables;
191 
192  return(TRUE);
193 }
GDATALOGGERVARIABLE Variables[GDATALOGGER_MAXVARIABLES]
Definition: gdatalogger.h:27
char VariableName[100]
Definition: gdatalogger.h:16
GQUEUECONTROL CircularQueueControl
Definition: gdatalogger.h:22
#define FALSE
double * CircularQueue
Definition: gdatalogger.h:21
char VariableUnit[50]
Definition: gdatalogger.h:17
long int GMatlabDataFileIndex
Definition: gdatalogger.h:18
#define TRUE
int m_NumberOfVariables
Definition: gdatalogger.h:28
#define GDATALOGGER_MAXVARIABLES
Definition: gdatalogger.h:13
#define QUEUE_MAXDESTINATIONS
Definition: gdatalogger.h:32
int gQUEUE_Init(PGQUEUECONTROL pQueueControl, int Size, int NReaders)
Definition: gqueue.c:31

Here is the call graph for this function:

Here is the caller graph for this function:

int gDataLogger_Init ( PGDATALOGGER  pgDataLogger,
char *  filename,
char *  dirname 
)

Definition at line 42 of file gdatalogger.c.

References GDATALOGGERVARIABLE::CircularQueue, FALSE, GDATALOGGERIPC_SHM::Flag, GDATALOGGER_IPC_FLAGIDDLE, GDATALOGGER_IPC_STATEFILE, GDATALOGGER_MAXVARIABLES, gDataLoggerIPC_SHM_fd, gDataLoggerIPC_SHM_flagmodeserver, gMATLABDataFile_OpenWrite(), GDATALOGGER::GMatlabDataFileConfig, GDATALOGGERVARIABLE::GMatlabDataFileIndex, GDATALOGGERVARIABLE::HasBeenWritten, GDATALOGGER::m_NumberOfVariables, GDATALOGGERVARIABLE::Nc, GDATALOGGERVARIABLE::Nr, status, TRUE, GDATALOGGERVARIABLE::VariableName, GDATALOGGER::Variables, and GDATALOGGERVARIABLE::VariableUnit.

Referenced by datalogger_init().

43 {
44  int i;
45  int first = 0;
46 #if DATALOGGER_COMPILE_FOR_XENOMAI
47  int err;
48 #else
49  int status = 0;
50 #endif
51 
52  /* GQueue */
53  if(pgDataLogger!=NULL){
54  for (i=0;i<GDATALOGGER_MAXVARIABLES;++i){
55  sprintf(pgDataLogger->Variables[i].VariableName," ");
56  sprintf(pgDataLogger->Variables[i].VariableUnit," ");
57  pgDataLogger->Variables[i].CircularQueue = NULL;
58  pgDataLogger->Variables[i].GMatlabDataFileIndex = 0;
59  pgDataLogger->Variables[i].Nc = 1;
60  pgDataLogger->Variables[i].Nr = 1;
61  pgDataLogger->Variables[i].HasBeenWritten = 0;
62  }
63  pgDataLogger->m_NumberOfVariables = 0;
64  }
65 
66  /* IPC */
67 #if DATALOGGER_COMPILE_FOR_XENOMAI
68  if(pgDataLogger!=NULL){
69  /* cria memoria compartilhada */
70  int heapsize;
71  if(sizeof(GDATALOGGERIPC_SHM) > ((256*1024))){
72  heapsize = sizeof(GDATALOGGERIPC_SHM);
73  }
74  else{
75  heapsize = ((256*1024));
76  }
77 
78  if((err=rt_heap_create(&gDataLoggerIPC_SHM_hd,GDATALOGGER_IPC_STATEFILE,sizeof(GDATALOGGERIPC_SHM),H_SHARED))!=0){
79  printf("gDataLogger_Init: Could not create xenomai heap object (return %i)\n", err);
80  printf("\n EEXIST = %i",EEXIST);
81  printf("\n EINVAL = %i",EINVAL);
82  printf("\n ENOMEM = %i",ENOMEM);
83  printf("\n EPERM = %i",EPERM);
84  printf("\n EIDRM = %i",EIDRM);
85  printf("\n ENOSYS = %i",ENOSYS);
86  if(err==-EEXIST){
87  err=rt_heap_delete(&gDataLoggerIPC_SHM_hd);
88  printf("gDataLogger_Init: Deleting xenomai heap object (return %i)\n", err);
89  }
90  return FALSE;
91  }
92 
93  if(rt_heap_alloc(&gDataLoggerIPC_SHM_hd,sizeof(GDATALOGGERIPC_SHM),TM_NONBLOCK,(void**)&pgDataLoggerIPC_SHM)!=0){
94  printf("gDataLogger_Init: Could not allocated xenomai heap object. (return %i)\n", err);
95  return FALSE;
96  }
97 
98  first = 1; /* We are the first instance */
100  }
101  else{
102  /* abre memoria compartilhada */
103  if((err=rt_heap_bind(&gDataLoggerIPC_SHM_hd,GDATALOGGER_IPC_STATEFILE,TM_NONBLOCK))!=0){
104  /* printf("gDataLogger_Init: Could not create xenomai heap object (return %i)\n", err); */
105 /* printf("\n EEXIST = %i",EEXIST);
106  printf("\n EINVAL = %i",EINVAL);
107  printf("\n ENOMEM = %i",ENOMEM);
108  printf("\n EPERM = %i",EPERM);
109  printf("\n EIDRM = %i",EIDRM);
110  printf("\n ENOSYS = %i",ENOSYS);*/
111  return FALSE;
112  }
113 
114  if(rt_heap_alloc(&gDataLoggerIPC_SHM_hd,0,TM_NONBLOCK,(void**)&pgDataLoggerIPC_SHM)!=0){
115  printf("gDataLogger_Init: Could not allocated xenomai heap object. (return %i)\n", err);
116  return FALSE;
117  }
118 
120  }
121 
122 #else
123  /* Try to open the shm instance with O_EXCL, this tests if the shm is already opened by someone else */
124  if((gDataLoggerIPC_SHM_fd = shm_open(GDATALOGGER_IPC_STATEFILE, (O_CREAT | O_RDWR),(S_IREAD | S_IWRITE))) < 0) {
125  /* Try to open the shm instance normally and share it with existing clients */
126  printf("gDataLogger_Init: Could not create shm object. %s\n", strerror(errno));
127  return FALSE;
128  }
129  if(pgDataLogger!=NULL){
131  first = 1;
132  } else{
134  first = 0;
135  }
136 /* if((gDataLoggerIPC_SHM_fd = shm_open(GDATALOGGER_IPC_STATEFILE, (O_CREAT | O_EXCL | O_RDWR),(S_IREAD | S_IWRITE))) > 0 ) {
137 */ first = 1; /* We are the first instance */
138 /* gDataLoggerIPC_SHM_flagmodeserver = 1;
139  }
140  else if((gDataLoggerIPC_SHM_fd = shm_open(GDATALOGGER_IPC_STATEFILE, (O_CREAT | O_RDWR),(S_IREAD | S_IWRITE))) < 0) {
141 */ /* Try to open the shm instance normally and share it with existing clients */
142 /* printf("gDataLogger_Init: Could not create shm object. %s\n", strerror(errno));
143  return FALSE;
144  }
145 */ /* Set the size of the SHM to be the size of the struct. */
146  status = ftruncate(gDataLoggerIPC_SHM_fd, sizeof(GDATALOGGERIPC_SHM));
147 
148  /* Connect the conf pointer to set to the shared memory area, with desired permissions */
149  if((pgDataLoggerIPC_SHM = mmap(0, sizeof(GDATALOGGERIPC_SHM), (PROT_READ | PROT_WRITE), MAP_SHARED, gDataLoggerIPC_SHM_fd, 0)) == MAP_FAILED) {
150  return FALSE;
151  }
152 
153  /* Set permission so all can read/write to shared memory */
154  status = fchmod(gDataLoggerIPC_SHM_fd, (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH));
155 
156 #endif
157 
158  if(first){
160  }
161 
162  /* GMatlabDataFile */
163  if((pgDataLogger!=NULL)&&(filename!=NULL)){
164  return(gMATLABDataFile_OpenWrite(&pgDataLogger->GMatlabDataFileConfig, filename, dirname));
165  }
166 
167  return TRUE;
168 }
GDATALOGGERVARIABLE Variables[GDATALOGGER_MAXVARIABLES]
Definition: gdatalogger.h:27
char VariableName[100]
Definition: gdatalogger.h:16
int gMATLABDataFile_OpenWrite(PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, char *filename, char *dirname)
#define FALSE
double * CircularQueue
Definition: gdatalogger.h:21
GMATLABDATAFILECONFIG GMatlabDataFileConfig
Definition: gdatalogger.h:29
char VariableUnit[50]
Definition: gdatalogger.h:17
long int GMatlabDataFileIndex
Definition: gdatalogger.h:18
static int gDataLoggerIPC_SHM_flagmodeserver
Definition: gdatalogger.c:31
int status
Definition: communication.c:10
#define TRUE
#define GDATALOGGER_IPC_FLAGIDDLE
Definition: gdatalogger.h:39
int m_NumberOfVariables
Definition: gdatalogger.h:28
#define GDATALOGGER_MAXVARIABLES
Definition: gdatalogger.h:13
static int gDataLoggerIPC_SHM_fd
Definition: gdatalogger.c:36
#define GDATALOGGER_IPC_STATEFILE
Definition: gdatalogger.h:56
static GDATALOGGERIPC_SHM * pgDataLoggerIPC_SHM
Definition: gdatalogger.c:30

Here is the call graph for this function:

Here is the caller graph for this function:

int gDataLogger_InsertVariable ( PGDATALOGGER  pgDataLogger,
char *  varname,
double *  varvalue 
)

Definition at line 199 of file gdatalogger.c.

References GDATALOGGERVARIABLE::CircularQueue, GDATALOGGERVARIABLE::CircularQueueControl, FALSE, GQUEUECONTROL::FlagFull, gDataLogger_MatfileUpdate(), gQUEUE_RequestWriteIndex(), GDATALOGGERVARIABLE::HasBeenWritten, GDATALOGGER::m_NumberOfVariables, GDATALOGGERVARIABLE::Nc, GDATALOGGERVARIABLE::Nr, QUEUE_DESTINATION_FILE, TRUE, GDATALOGGERVARIABLE::VariableName, and GDATALOGGER::Variables.

Referenced by datalogger_init(), datalogger_set_Ts(), and datalogger_update().

200 {
201  int queueindex,varindex,n;
202  long int nr,nc;
203  int FlagQueueFull;
204 
205  /* Procura pela variavel */
206  varindex = -1;
207  for(n=0;n<pgDataLogger->m_NumberOfVariables;++n){
208  if(strcmp(varname,pgDataLogger->Variables[n].VariableName)==0){
209  varindex = n;
210  break;
211  }
212  }
213  if(varindex<0){
214  return(FALSE);
215  }
216 
217  if(pgDataLogger->Variables[varindex].HasBeenWritten == 1) pgDataLogger->Variables[varindex].HasBeenWritten = 2; // Second write
218  if(pgDataLogger->Variables[varindex].HasBeenWritten == 0) pgDataLogger->Variables[varindex].HasBeenWritten = 1; // First write (1 data point)
219 
220  /* Insere o conteudo */
221  for(nr=0;nr<pgDataLogger->Variables[varindex].Nr;++nr){
222  for(nc=0;nc<pgDataLogger->Variables[varindex].Nc;++nc){
223  FlagQueueFull = gQUEUE_RequestWriteIndex(&pgDataLogger->Variables[varindex].CircularQueueControl, &queueindex);
224 
225  pgDataLogger->Variables[varindex].CircularQueue[queueindex] = varvalue[nr+(nc)*pgDataLogger->Variables[varindex].Nr];
226 
227  if(!FlagQueueFull){
228  /* The queue is full. Test if it is the reading head associated to matlab data files. */
229  if(pgDataLogger->Variables[varindex].CircularQueueControl.FlagFull[QUEUE_DESTINATION_FILE]==TRUE){
230  /* Empty in matlab data file. */
231  gDataLogger_MatfileUpdate(pgDataLogger);
232  /* Clear flag: */
234  }
235  }
236  }
237  }
238 
239  return(TRUE);
240 }
GDATALOGGERVARIABLE Variables[GDATALOGGER_MAXVARIABLES]
Definition: gdatalogger.h:27
char VariableName[100]
Definition: gdatalogger.h:16
#define QUEUE_DESTINATION_FILE
Definition: gdatalogger.h:33
GQUEUECONTROL CircularQueueControl
Definition: gdatalogger.h:22
int FlagFull[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:45
#define FALSE
double * CircularQueue
Definition: gdatalogger.h:21
#define TRUE
int gDataLogger_MatfileUpdate(PGDATALOGGER pgDataLogger)
Definition: gdatalogger.c:245
int m_NumberOfVariables
Definition: gdatalogger.h:28
int gQUEUE_RequestWriteIndex(PGQUEUECONTROL pQueueControl, int *Index)
Definition: gqueue.c:233

Here is the call graph for this function:

Here is the caller graph for this function:

int gDataLogger_IPC_RetrieveVariable ( char *  varname,
char *  varunit,
double *  pbuffer,
int *  bufferlen 
)

Definition at line 319 of file gdatalogger.c.

References GDATALOGGERIPC_SHM::Flag, GDATALOGGER_IPC_FLAGDATAAVAILABLE, GDATALOGGER_IPC_FLAGIDDLE, GDATALOGGER_IPC_FLAGNOTEXIST, GDATALOGGER_IPC_FLAGREQUESTDATA, GDATALOGGER_IPC_FLAGTIMEOUT, GDATALOGGERIPC_SHM::QueueData, GDATALOGGERIPC_SHM::QueueSize, GDATALOGGERIPC_SHM::VariableName, and GDATALOGGERIPC_SHM::VariableUnit.

320 {
321  int counter;
322 
323  sprintf(pgDataLoggerIPC_SHM->VariableName, "%s", varname);
325 
326 /* printf("\ngDataLogger_IPC_RetrieveVariable: solicitação feita pela variavel %s",varname); */
327 
328  counter = 0;
330  usleep(10000);
331  if(++counter > 100){
332  *bufferlen = 0;
334  /* printf("\ngDataLogger_IPC_RetrieveVariable: solicitação não atendida"); */
336  }
337  }
338 
340  memcpy(pbuffer,pgDataLoggerIPC_SHM->QueueData, pgDataLoggerIPC_SHM->QueueSize * sizeof(double));
341  sprintf(varunit, "%s", pgDataLoggerIPC_SHM->VariableUnit);
342  *bufferlen = pgDataLoggerIPC_SHM->QueueSize;
345  }
346 
348  *bufferlen = 0;
351  }
352 
353  *bufferlen = 0;
356 }
#define GDATALOGGER_IPC_FLAGDATAAVAILABLE
Definition: gdatalogger.h:41
#define GDATALOGGER_IPC_FLAGNOTEXIST
Definition: gdatalogger.h:42
#define GDATALOGGER_IPC_FLAGTIMEOUT
Definition: gdatalogger.h:43
char VariableUnit[50]
Definition: gdatalogger.h:47
#define GDATALOGGER_IPC_FLAGIDDLE
Definition: gdatalogger.h:39
double QueueData[GDATALOGGER_IPC_MAXQUEUESIZE]
Definition: gdatalogger.h:48
#define GDATALOGGER_IPC_FLAGREQUESTDATA
Definition: gdatalogger.h:40
char VariableName[100]
Definition: gdatalogger.h:46
static GDATALOGGERIPC_SHM * pgDataLoggerIPC_SHM
Definition: gdatalogger.c:30
int gDataLogger_IPCUpdate ( PGDATALOGGER  pgDataLogger)

Definition at line 274 of file gdatalogger.c.

References GDATALOGGERVARIABLE::CircularQueue, GDATALOGGERVARIABLE::CircularQueueControl, FALSE, GDATALOGGERIPC_SHM::Flag, GDATALOGGER_IPC_FLAGDATAAVAILABLE, GDATALOGGER_IPC_FLAGNOTEXIST, GDATALOGGER_IPC_FLAGREQUESTDATA, gDataLoggerIPC_SHM_flagmodeserver, gQUEUE_GetNumberOfUnreadData(), gQUEUE_RequestReadIndex(), GDATALOGGER::m_NumberOfVariables, QUEUE_DESTINATION_IPC, GDATALOGGERIPC_SHM::QueueData, GDATALOGGERIPC_SHM::QueueSize, TRUE, GDATALOGGERVARIABLE::VariableName, GDATALOGGERIPC_SHM::VariableName, GDATALOGGER::Variables, GDATALOGGERVARIABLE::VariableUnit, and GDATALOGGERIPC_SHM::VariableUnit.

Referenced by datalogger_update_IPC().

275 {
276  int QueueIndex,nvar,n,i;
277 
278  /********** IPC **********/
280  return FALSE;
281  }
282 
284 
285  /* Procura pela variavel */
286  nvar = -1;
287  for(n=0;n<pgDataLogger->m_NumberOfVariables;++n){
288  if(strcmp(pgDataLoggerIPC_SHM->VariableName,pgDataLogger->Variables[n].VariableName)==0){
289  nvar = n;
290  break;
291  }
292  }
293  if(nvar<0){
295  return FALSE;
296  }
297 
298  /* Metodo otimizado, que salva em uma variavel MATLAB todas as ultimas leituras. */
301  }
302  if(pgDataLoggerIPC_SHM->QueueSize>0){ /* Existem dados a serem salvos. */
303  for(i=0;i<pgDataLoggerIPC_SHM->QueueSize;++i){
305  pgDataLoggerIPC_SHM->QueueData[i] = pgDataLogger->Variables[nvar].CircularQueue[QueueIndex];
306  }
307  }
308 
309  sprintf(pgDataLoggerIPC_SHM->VariableUnit, "%s", pgDataLogger->Variables[nvar].VariableUnit);
311  }
312 
313  return(TRUE);
314 }
#define GDATALOGGER_IPC_FLAGDATAAVAILABLE
Definition: gdatalogger.h:41
GDATALOGGERVARIABLE Variables[GDATALOGGER_MAXVARIABLES]
Definition: gdatalogger.h:27
char VariableName[100]
Definition: gdatalogger.h:16
#define GDATALOGGER_IPC_FLAGNOTEXIST
Definition: gdatalogger.h:42
char VariableUnit[50]
Definition: gdatalogger.h:47
GQUEUECONTROL CircularQueueControl
Definition: gdatalogger.h:22
#define FALSE
double * CircularQueue
Definition: gdatalogger.h:21
char VariableUnit[50]
Definition: gdatalogger.h:17
static int gDataLoggerIPC_SHM_flagmodeserver
Definition: gdatalogger.c:31
#define TRUE
int m_NumberOfVariables
Definition: gdatalogger.h:28
double QueueData[GDATALOGGER_IPC_MAXQUEUESIZE]
Definition: gdatalogger.h:48
#define GDATALOGGER_IPC_FLAGREQUESTDATA
Definition: gdatalogger.h:40
char VariableName[100]
Definition: gdatalogger.h:46
int gQUEUE_GetNumberOfUnreadData(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:314
#define QUEUE_DESTINATION_IPC
Definition: gdatalogger.h:34
int gQUEUE_RequestReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:117
static GDATALOGGERIPC_SHM * pgDataLoggerIPC_SHM
Definition: gdatalogger.c:30

Here is the call graph for this function:

Here is the caller graph for this function:

int gDataLogger_MatfileUpdate ( PGDATALOGGER  pgDataLogger)

Definition at line 245 of file gdatalogger.c.

References GDATALOGGERVARIABLE::CircularQueue, GDATALOGGERVARIABLE::CircularQueueControl, FALSE, gMATLABDataFile_SaveVector(), GDATALOGGER::GMatlabDataFileConfig, GDATALOGGERVARIABLE::GMatlabDataFileIndex, gQUEUE_GetNumberOfUnreadData(), gQUEUE_RequestReadIndex(), GDATALOGGER::m_NumberOfVariables, QUEUE_DESTINATION_FILE, TRUE, GDATALOGGERVARIABLE::VariableName, and GDATALOGGER::Variables.

Referenced by datalogger_close(), datalogger_write_file(), gDataLogger_Close(), and gDataLogger_InsertVariable().

246 {
247  int QueueIndex,nvar,datasize,i;
248  double *v;
249  char matvarname[70];
250 
251  /********** MATFILE **********/
252  /* Esvaziar queues de todas as variaveis que vao para o arquivo: */
253  for(nvar=0;nvar<pgDataLogger->m_NumberOfVariables;++nvar){
254  /* Metodo otimizado, que salva em uma variavel MATLAB todas as ultimas leituras. */
256  return(FALSE);
257  }
258  if(datasize>0){ /* Existem dados a serem salvos. */
259  v = (double *) malloc(datasize * sizeof(double));
260  for(i=0;i<datasize;++i){
262  v[i] = pgDataLogger->Variables[nvar].CircularQueue[QueueIndex];
263  }
264  sprintf(matvarname,"%s_%li_%li",pgDataLogger->Variables[nvar].VariableName,pgDataLogger->Variables[nvar].GMatlabDataFileIndex,pgDataLogger->Variables[nvar].GMatlabDataFileIndex+datasize-1);
265  gMATLABDataFile_SaveVector(&pgDataLogger->GMatlabDataFileConfig, matvarname, v, datasize);
266  free(v);
267  pgDataLogger->Variables[nvar].GMatlabDataFileIndex += datasize;
268  }
269  }
270 
271  return(TRUE);
272 }
int gMATLABDataFile_SaveVector(PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, const char *varname, double *v, long nlin)
GDATALOGGERVARIABLE Variables[GDATALOGGER_MAXVARIABLES]
Definition: gdatalogger.h:27
char VariableName[100]
Definition: gdatalogger.h:16
#define QUEUE_DESTINATION_FILE
Definition: gdatalogger.h:33
GQUEUECONTROL CircularQueueControl
Definition: gdatalogger.h:22
#define FALSE
double * CircularQueue
Definition: gdatalogger.h:21
GMATLABDATAFILECONFIG GMatlabDataFileConfig
Definition: gdatalogger.h:29
long int GMatlabDataFileIndex
Definition: gdatalogger.h:18
#define TRUE
int m_NumberOfVariables
Definition: gdatalogger.h:28
int gQUEUE_GetNumberOfUnreadData(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:314
int gQUEUE_RequestReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:117

Here is the call graph for this function:

Here is the caller graph for this function: