rllib  1
rlopcxmlda.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rlopcxmlda.cpp - description
3  -------------------
4  begin : Mon Aug 27 2007
5  copyright : (C) 20071 by pvbrowser
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #include "rlopcxmlda.h"
17 #include <stdio.h>
18 #include <string.h>
19 #include <ctype.h>
20 
21 rlOpcXmlDa::rlOpcXmlDa(const char *mailbox, const char *shared_memory, long shared_memory_size)
22 {
23  mbx = new rlMailbox(mailbox);
24  shm = new rlSharedMemory(shared_memory,shared_memory_size);
26  shmvalues = ((const char *)shmheader) + sizeof(SHM_HEADER);
27 }
28 
30 {
31  delete mbx;
32  delete shm;
33 }
34 
35 const char *rlOpcXmlDa::stringValue(const char *variable)
36 {
37  int value_offset, delta_index, nmax, i;
38  const char *cptr;
39 
40  if(shmheader == NULL) return "OPCXMLDA_ERROR";
41  if(strcmp(shmheader->ident,"opc") != 0) return "OPCXMLDA_ERROR";
42  value_offset = shmheader->maxItemNameLength + 1;
43  delta_index = value_offset + shmheader->maxNameLength + 1;
44  nmax = shmheader->numItems;
45 
46  cptr = shmvalues;
47  for(i=0; i<nmax; i++)
48  {
49  if(strcmp(cptr,variable) == 0)
50  {
51  return cptr + value_offset;
52  }
53  cptr += delta_index;
54  }
55 
56  return "OPCXMLDA_ERROR";
57 }
58 
59 int rlOpcXmlDa::intValue(const char *variable)
60 {
61  const char *cptr;
62  int ret;
63 
64  cptr = stringValue(variable);
65  if(isdigit(*cptr))
66  {
67  ret = OPCXMLDA_ERROR;
68  sscanf(cptr,"%d",&ret);
69  return ret;
70  }
71  return OPCXMLDA_ERROR;
72 }
73 
74 float rlOpcXmlDa::floatValue(const char *variable)
75 {
76  const char *cptr;
77  float ret;
78 
79  cptr = stringValue(variable);
80  if(isdigit(*cptr) || *cptr == '-')
81  {
82  ret = OPCXMLDA_ERROR;
83  sscanf(cptr,"%f",&ret);
84  return ret;
85  }
86  return OPCXMLDA_ERROR;
87 }
88 
89 int rlOpcXmlDa::writeStringValue(const char *variable, const char *value)
90 {
91  mbx->printf("%s,%s\n",variable,value);
92  return 0;
93 }
94 
95 int rlOpcXmlDa::writeIntValue(const char *variable, int value)
96 {
97  mbx->printf("%s,%d\n",variable,value);
98  return 0;
99 }
100 
101 int rlOpcXmlDa::writeFloatValue(const char *variable, float value)
102 {
103  mbx->printf("%s,%f\n",variable,value);
104  return 0;
105 }
106 
108 {
109  if(shmheader == NULL) return OPCXMLDA_ERROR;
110  return shmheader->readErrorCount;
111 }
112 
114 {
115  if(shmheader == NULL) return OPCXMLDA_ERROR;
116  return shmheader->writeErrorCount;
117 }
118 
120 {
121  if(shmheader == NULL) return OPCXMLDA_ERROR;
122  if(shm->status == rlSharedMemory::OK) return 0;
123  return OPCXMLDA_ERROR;
124 }
125 
virtual ~rlOpcXmlDa()
Definition: rlopcxmlda.cpp:29
int writeFloatValue(const char *variable, float value)
Definition: rlopcxmlda.cpp:101
rlOpcXmlDa(const char *mailbox="c:\utomation\bx\pcxmlda.mbx", const char *shared_memory="c:\utomation\hm\pcxmlda.shm", long shared_memory_size=65536)
Definition: rlopcxmlda.cpp:21
const char * stringValue(const char *variable)
Definition: rlopcxmlda.cpp:35
float floatValue(const char *variable)
Definition: rlopcxmlda.cpp:74
rlSharedMemory * shm
Definition: rlopcxmlda.h:74
int writeIntValue(const char *variable, int value)
Definition: rlopcxmlda.cpp:95
int printf(const char *format,...)
Definition: rlmailbox.cpp:344
int writeErrorCount()
Definition: rlopcxmlda.cpp:113
int readErrorCount()
Definition: rlopcxmlda.cpp:107
SHM_HEADER * shmheader
Definition: rlopcxmlda.h:71
int writeStringValue(const char *variable, const char *value)
Definition: rlopcxmlda.cpp:89
int shmStatus()
Definition: rlopcxmlda.cpp:119
int intValue(const char *variable)
Definition: rlopcxmlda.cpp:59
rlMailbox * mbx
Definition: rlopcxmlda.h:73
const char * shmvalues
Definition: rlopcxmlda.h:72