rllib
1
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
lib
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);
25
shmheader
= (
SHM_HEADER
*)
shm
->
getUserAdr
();
26
shmvalues
= ((
const
char
*)
shmheader
) +
sizeof
(
SHM_HEADER
);
27
}
28
29
rlOpcXmlDa::~rlOpcXmlDa
()
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
107
int
rlOpcXmlDa::readErrorCount
()
108
{
109
if
(
shmheader
== NULL)
return
OPCXMLDA_ERROR
;
110
return
shmheader
->
readErrorCount
;
111
}
112
113
int
rlOpcXmlDa::writeErrorCount
()
114
{
115
if
(
shmheader
== NULL)
return
OPCXMLDA_ERROR
;
116
return
shmheader
->
writeErrorCount
;
117
}
118
119
int
rlOpcXmlDa::shmStatus
()
120
{
121
if
(
shmheader
== NULL)
return
OPCXMLDA_ERROR
;
122
if
(
shm
->
status
==
rlSharedMemory::OK
)
return
0;
123
return
OPCXMLDA_ERROR
;
124
}
125
Generated by
1.8.2