source: branches/testFACT++branch/dim/src/examples/pvss_dim_server.cxx@ 18342

Last change on this file since 18342 was 18058, checked in by tbretz, 10 years ago
Updated to v20r11
File size: 5.0 KB
Line 
1#include <dis.hxx>
2#include <iostream>
3#include <stdio.h>
4#include <time.h>
5using namespace std;
6
7typedef struct{
8 int bitset;
9 char boolval;
10 int intval;
11 float floatval;
12 char stringval[128];
13}COMPLEXDATA;
14
15typedef struct{
16 float farr[10];
17 int intval;
18 int iarr[3];
19 char str[20];
20 int intval1;
21}COMPLEXDATA1;
22
23class RecvCommand : public DimCommand
24{
25 int reset_flag;
26 void commandHandler()
27 {
28 cout << "Size: " << getSize() << endl;
29 cout << "Command " << getString() << " received" << endl;
30 reset_flag = 1;
31 }
32public :
33 RecvCommand(const char *name) : DimCommand(name,"C") {reset_flag = 0;};
34 int isReset() {return reset_flag;};
35 void clearReset() {reset_flag = 0;};
36};
37
38class RecvCommandComplex : public DimCommand
39{
40 void commandHandler()
41 {
42 COMPLEXDATA *complexData;
43
44 complexData = (COMPLEXDATA *)getData();
45 cout << "Command " << complexData->intval
46 << " received " << complexData->stringval << endl;
47 }
48public :
49 RecvCommandComplex(const char *name) : DimCommand(name,"I:1;C:1;I:1;F:1;C") {};
50};
51/*
52typedef struct{
53 char oper;
54 char data[128];
55}MEMCMND;
56
57typedef struct{
58 int code;
59 float data[128];
60}MEMDATA;
61
62DimService *TestMem[1010];
63MEMDATA TestMemData;
64
65class RecvCommandMem : public DimCommand
66{
67 int itsIndex;
68 void commandHandler()
69 {
70 MEMCMND *complexData;
71
72 complexData = (MEMCMND *)getData();
73 cout << "Command " << complexData->oper
74 << " received " << complexData->data[0] << endl;
75 TestMemData.code = 1;
76 TestMemData.data[0] = 123;
77 TestMemData.data[1] = 456;
78 TestMem[itsIndex]->updateService();
79 }
80public :
81 RecvCommandMem(char *name, int index) : DimCommand(name,"C:1;C"),itsIndex(index) {};
82};
83*/
84
85class RpcService : public DimRpc
86{
87 int val;
88
89 void rpcHandler()
90 {
91 val = getInt();
92 val++;
93cout << "Received " << val -1 << " Answering " << val << endl;
94 setData(val);
95 }
96public:
97 RpcService(const char *name): DimRpc(name,"I","I") {val = 0;};
98};
99
100int main()
101{
102 COMPLEXDATA complexData;
103 COMPLEXDATA1 cData;
104 float simpleData;
105
106 int index = 0;
107 complexData.bitset = 0x1;
108 complexData.boolval = 1;
109 complexData.intval = index;
110 complexData.floatval = (float)3.4;
111 strcpy(complexData.stringval,"IDLE");
112
113
114 cData.farr[0] = (float)1.2;
115 cData.farr[1] = (float)2.2;
116 cData.farr[2] = (float)3.2;
117 cData.farr[3] = 0;
118 cData.farr[4] = 0;
119 cData.farr[5] = 0;
120 cData.farr[6] = 0;
121 cData.farr[7] = 0;
122 cData.farr[8] = 0;
123 cData.farr[9] = 0;
124 cData.intval = 123;
125 cData.iarr[0] = 12;
126 cData.iarr[1] = 13;
127 cData.iarr[2] = 14;
128 cData.intval1 = 456;
129 strcpy(cData.str,"hello");
130
131 DimService cTestService("COMPLEX_SERVICE_TEST","F:10;I:1;I:3;C:20;I:1",
132 (void *)&cData, sizeof(cData));
133
134 DimService complexService("COMPLEX_SERVICE","I:1;C:1;I:1;F:1;C",
135 (void *)&complexData, sizeof(complexData));
136
137 simpleData = (float)1.23;
138
139 DimService simpleService("SIMPLE_SERVICE", simpleData);
140 simpleService.setQuality(1);
141
142 RecvCommand recvCommand("SIMPLE_COMMAND");
143 RecvCommandComplex recvCommandComplex("COMPLEX_COMMAND");
144/*
145 {
146 char tstr[128];
147 int i;
148 RecvCommandMem *rmem;
149// TestMem = new DimService("TEST_MEM", "I:1;F", (void *)&TestMemData, sizeof(TestMemData));
150// RecvCommandMem recvCommandMem("TEST_MEM_CMND");
151
152 for(i = 1; i <= 1000; i++)
153 {
154 sprintf(tstr,"TEST_MEM%04d",i);
155 TestMem[i] = new DimService(tstr, "I:1;F", (void *)&TestMemData, sizeof(TestMemData));
156 sprintf(tstr,"TEST_MEM_CMND%04d",i);
157 rmem = new RecvCommandMem(tstr, i);
158 }
159 }
160*/
161 RpcService rpc("RPC");
162
163 DimServer::start("PVSS_DIM_TEST");
164
165 while(1)
166 {
167 sleep(5);
168
169 if( recvCommand.isReset() )
170 {
171
172 index = 0;
173 complexData.bitset = 0x1;
174 complexData.boolval = 1;
175 complexData.intval = index;
176 complexData.floatval = (float)3.4;
177 strcpy(complexData.stringval,"IDLE");
178 simpleData = (float)1.23;
179 recvCommand.clearReset();
180 }
181 else
182 {
183 index++;
184 complexData.bitset <<= 1;
185 complexData.boolval = index;
186 complexData.intval = index;
187 complexData.floatval = index * (float)1.1;
188 sprintf(complexData.stringval,"State %d", index);
189 simpleData += (float)1.1;
190 }
191
192 complexService.updateService();
193
194// simpleService.setQuality(complexData.bitset);
195/*
196 {
197 int secs;
198 time_t tsecs;
199
200 tsecs = time((time_t)NULL);
201 secs = (int)tsecs;
202 secs -=60;
203 simpleService.setTimestamp(secs, 123);
204 simpleService.setQuality(index);
205 tsecs = (time_t)secs;
206 cout << "quality "<< index << " time "<< ctime(&tsecs) << endl;
207 }
208*/
209 simpleService.updateService();
210// simpleData += (float)1;
211// simpleService.updateService();
212// simpleData += (float)1;
213// simpleService.updateService();
214// simpleData += (float)1;
215// simpleService.updateService();
216// simpleData += (float)1;
217// simpleService.updateService();
218// simpleData += (float)1;
219// simpleService.updateService();
220// simpleData += (float)1;
221// simpleService.updateService();
222// simpleData += (float)1;
223// simpleService.updateService();
224// simpleData += (float)1;
225// simpleService.updateService();
226// simpleData += (float)1;
227// simpleService.updateService();
228
229 if((int)strlen(cData.str) < 16)
230 strcat(cData.str," abc");
231 cTestService.updateService();
232 }
233 return 0;
234}
Note: See TracBrowser for help on using the repository browser.