FEDRA emulsion software from the OPERA Collaboration
MessageReader Class Reference

#include <MessageReader.h>

Inheritance diagram for MessageReader:
Collaboration diagram for MessageReader:

Public Member Functions

std::string GetErrorStr (int err_)
 
bool GetJobFinished ()
 
std::string GetValueForKey (const char *key_)
 
std::string GetValueForKey (std::string &key_)
 
bool HasValueForKey (const char *key_)
 
bool Load (uint8 *buf_, uint32 size_)
 
 MessageReader ()
 
void Process ()
 
void ProcessErrorNode (TiXmlElement *err_)
 
void ProcessGMPNode (TiXmlElement *el_)
 
void ProcessGPPNode (TiXmlElement *el_)
 
void ProcessMarksNode (TiXmlElement *el_)
 
void ProcessSMPNode (TiXmlElement *el_)
 
void ProcessSPPNode (TiXmlElement *el_)
 
void ProcessStartNode (TiXmlElement *el_)
 
void ProcessStopNode (TiXmlElement *el_)
 

Private Attributes

std::map< std::string, std::string > m_keysMap
 
int m_messId
 
TiXmlElementm_messNode
 
bool m_stoped
 
TiXmlDocument m_xmlDoc
 
- Private Attributes inherited from PAVProtocol
uint32 m_headerSize
 

Additional Inherited Members

- Private Member Functions inherited from PAVProtocol
uint32 Crc32 (uint32 len_, const uint8 *buf_)
 
 PAVProtocol ()
 
virtual bool ReadMessage (uint8 *buf_, uint32 size_, std::vector< uint8 > &dstbuf_)
 
virtual bool ReadMessageRaw (uint8 *buf_, uint32 size_, std::vector< uint8 > &dstbuf_)
 
virtual bool WriteMessage (std::vector< uint8 > &buf_, const void *srcbuf_, uint32 srcsize_)
 
virtual bool WriteMessageRaw (std::vector< uint8 > &buf_, const void *srcbuf_, uint32 srcsize_)
 
virtual ~PAVProtocol ()
 

Constructor & Destructor Documentation

◆ MessageReader()

MessageReader::MessageReader ( )
inline
10 :m_stoped(false)
11 {};
bool m_stoped
Definition: MessageReader.h:44

Member Function Documentation

◆ GetErrorStr()

std::string MessageReader::GetErrorStr ( int  err_)
256 {
257 switch(err_){
258 case PAVPROT_OK:
259 return "Succsess";
260 case PAVPROT_ERROR:
261 return "Error";
262 case PAVPROT_BUSY:
263 return "Busy";
264 case PAVPROT_CANCELED:
265 return "Canceled";
266 case PAVPROT_FINISHED:
267 return "Finished";
268 case PAVPROT_SEQVIOLATION:
269 return "Message sequence violation";
270 case PAVPROT_XMLERROR:
271 return "XML Error";
272 case PAVPROT_MSGERROR:
273 return "Message error";
274 };
275 return "Unknown error";
276};

◆ GetJobFinished()

bool MessageReader::GetJobFinished ( )
inline
35{return m_stoped;};

◆ GetValueForKey() [1/2]

std::string MessageReader::GetValueForKey ( const char *  key_)
inline
38{return m_keysMap[key_];};
std::map< std::string, std::string > m_keysMap
Definition: MessageReader.h:46

◆ GetValueForKey() [2/2]

std::string MessageReader::GetValueForKey ( std::string &  key_)
inline
39{return m_keysMap[key_];};

◆ HasValueForKey()

bool MessageReader::HasValueForKey ( const char *  key_)
inline
37{return (m_keysMap.find(key_) != m_keysMap.end());};

◆ Load()

bool MessageReader::Load ( uint8 buf_,
uint32  size_ 
)
3 {
4 m_keysMap.clear();
5 std::vector<uint8> xmlstr;
7 m_messNode = 0;
8 bool res = ReadMessage(buf_, size_, xmlstr);
9 if(!res){
10 printf("Received message in incorrect format.\n");
11 return res;
12 };
13 if(xmlstr[xmlstr.size()-1] != 0){
14 xmlstr.resize(xmlstr.size()+1);
15 xmlstr[xmlstr.size()-1] = 0;
16 };
17
18 /*debug substitution*/
19 //const char * debugxml = "<PAVControl><Message id=\"0\"/><StopR/><SetModuleParamsR module=\"camera\"><Error code=\"1\">A</Error></SetModuleParamsR><GetModuleParamsR module=\"camera\"><Error code=\"2\"/><Clip val=\"false\"/><ClipSize val=\"0 0 1280 1024\"/><DCFFileName val=\"..\\mc1310_8channels.dcf\"/><Fps val=\"110\"/><FpsMax val=\"360\"/><FpsMin val=\"11\"/><ImageSpec val=\"None\"/></GetModuleParamsR><GetModuleParamsR module=\"stage\"><Error code=\"3\"/><AccCoef val=\"90000 90000 200\"/><CommandRate val=\"50\"/><Eps val=\"1.5 1.5 0.05\"/><MoveToTries val=\"5\"/><PU val=\"0.25 0.25 0.004\"/><QueryPosTries val=\"3\"/><VelCoef val=\"295.5 295.5 4.73\"/><VelMax val=\"37233 37233 40\"/><VelMin val=\"295.5 295.5 4.73\"/><Velocity val=\"23640 23640 14.190001\"/><ZeroTries val=\"5\"/></GetModuleParamsR><GetModuleParamsR module=\"proc\"><Error code=\"4\"/><CoordFile val=\"coord.txt\"/><CoordTemplate val=\"&lt;id&gt;: |&lt;rn&gt;| &lt;x:.3&gt; &lt;y:.3&gt;&lt;z:.3&gt;\"/><EventDirectory val=\"C:/Andrey/svn-cur/tmp/\"/><ImageQuality val=\"99\"/><ImageTemplate val=\"&lt;ox:03&gt;_&lt;oy:03&gt;\img&lt;oz:03&gt;.jpg\"/><MaxProcThreads val=\"1\"/></GetModuleParamsR><GetModuleParamsR module=\"guide\"><Error code=\"5\"/><PathsDir val=\"..\\..\\..\\bin\"/></GetModuleParamsR><SetPathParamsR lib=\"PAVPathLib-dbg.pth\" path=\"NS_SPIRAL1S\"><Error code=\"6\"/></SetPathParamsR><GetPathParamsR lib=\"PAVPathLib-dbg.pth\" path=\"NS_SPIRAL1S\"><Error code=\"0\">server sais hello</Error><count val=\"3 3 10\"/><delta val=\"100 100 1\"/><offset val=\"0.000000 0.000000 0.000000\"/><order val=\"ZXY\"/></GetPathParamsR><StartR error=\"4\"/></PAVControl>";
20 m_xmlDoc.Parse((char*)&xmlstr[0]);/*(debugxml);*/
21
22
23 if(m_xmlDoc.Error()){
24 printf("Message Parsing failed. Col %d, row %d, in:\n%s\n Description: %s\n",
26 return false;
27 };
29 if(!rootnode){
30 printf("Root node not found.\n");
31 return false;
32 };
33 if(rootnode->ValueStr() != PAVPROT_NODE_ROOT){
34 printf("Wrong root node, got \"%s\".\n", rootnode->ValueStr().c_str());
35 return false;
36 };
37 m_messNode = rootnode->FirstChildElement();
38 if(!m_messNode){
39 printf("Message node not found.\n");
40 return false;
41 };
42 m_messNode->ValueStr();
43 if(m_messNode->ValueStr() != PAVPROT_NODE_MESS){
44 printf("Wrong message node, got \"%s\".\n", m_messNode->ValueStr().c_str());
45 return false;
46 };
47
48 int errid;
49 if(m_messNode->QueryIntAttribute("error", &errid) == TIXML_SUCCESS){
50 printf("Server response of an error, code=%d (%s).\n", errid, GetErrorStr(errid).c_str());
51 const char *errstr = m_messNode->GetText();
52 if(errstr)
53 printf("\tStatus:\"%s\"\n", errstr);
54 }else{
55 const char *msg = m_messNode->GetText();
56 if(msg)
57 printf(">>Got message from server: \"%s\"\n", msg);
58 };
60 m_messId = -1;
61 //we are not taking server errors or id-absence as errors, and will try to process xml further
62 return res;
63};
TiXmlElement * m_messNode
Definition: MessageReader.h:43
int m_messId
Definition: MessageReader.h:45
std::string GetErrorStr(int err_)
Definition: MessageReader.cpp:256
TiXmlDocument m_xmlDoc
Definition: MessageReader.h:39
virtual bool ReadMessage(uint8 *buf_, uint32 size_, std::vector< uint8 > &dstbuf_)
Definition: PAVProtocol.cpp:75
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1463
int ErrorRow() const
Definition: tinyxml.h:1477
bool Error() const
Definition: tinyxml.h:1460
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxmlparser.cpp:704
int ErrorCol() const
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1478
Definition: tinyxml.h:941
int QueryIntAttribute(const char *name, int *_value) const
Definition: tinyxml.cpp:661
const char * GetText() const
Definition: tinyxml.cpp:900
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:452
void Clear()
Delete all the children of this node. Does not affect 'this'.
Definition: tinyxml.cpp:169
@ TIXML_SUCCESS
Definition: tinyxml.h:156

◆ Process()

void MessageReader::Process ( )
65 {
66 m_stoped = false;
67 if(m_messNode){
68 printf("\n_____________________________\n PAVICOM responce id=%d\n_____________________________\n", m_messId);
69 TiXmlElement *el;
70 std::string stopr = PAVPROT_NODE_STOP; stopr+="R";
71 std::string startr = PAVPROT_NODE_START; startr+="R";
72 std::string marksr = PAVPROT_NODE_MARKS; marksr+="R";
73 std::string smpr = PAVPROT_NODE_SMP; smpr+="R";
74 std::string gmpr = PAVPROT_NODE_GMP; gmpr+="R";
75 std::string sppr = PAVPROT_NODE_SPP; sppr+="R";
76 std::string gppr = PAVPROT_NODE_GPP; gppr+="R";
77 el = m_messNode;
78 while((el = el->NextSiblingElement())){
79 if(el->ValueStr() == stopr){
81 }else if(el->ValueStr() == startr){
83 }else if(el->ValueStr() == smpr){
85 }else if(el->ValueStr() == gmpr){
87 }else if(el->ValueStr() == sppr){
89 }else if(el->ValueStr() == gppr){
91 }else if(el->ValueStr() == marksr){
93 };
94 };
95 printf("_____________________________\n\n");
96 };
97};
void ProcessGPPNode(TiXmlElement *el_)
Definition: MessageReader.cpp:206
void ProcessMarksNode(TiXmlElement *el_)
Definition: MessageReader.cpp:128
void ProcessStartNode(TiXmlElement *el_)
Definition: MessageReader.cpp:110
void ProcessGMPNode(TiXmlElement *el_)
Definition: MessageReader.cpp:172
void ProcessSPPNode(TiXmlElement *el_)
Definition: MessageReader.cpp:158
void ProcessStopNode(TiXmlElement *el_)
Definition: MessageReader.cpp:99
void ProcessSMPNode(TiXmlElement *el_)
Definition: MessageReader.cpp:145
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cpp:482

◆ ProcessErrorNode()

void MessageReader::ProcessErrorNode ( TiXmlElement err_)
237 {
238 if(err_){
239 int errid;
240 if(err_->QueryIntAttribute("code", &errid) == TIXML_SUCCESS){
241 if(errid != PAVPROT_OK)
242 printf("failed. code=%d (%s).\n", errid, GetErrorStr(errid).c_str());
243 else
244 printf("succeeded.\n");
245 }else
246 printf("unknown state\n");
247 const char *errstr = err_->GetText();
248 if(errstr)
249 printf("\t>>Status:\"%s\"\n", errstr);
250 }else
251 printf("succeeded.\n");
252
253};

◆ ProcessGMPNode()

void MessageReader::ProcessGMPNode ( TiXmlElement el_)
172 {
173 const char * mod = el_->Attribute("module");
174 if(!mod){
175 std::string xmlstr;
176 xmlstr << *el_;
177 printf("GMP format error, got \"%s\"\n", xmlstr.c_str());
178 return;
179 };
180
181 printf("GMP for module \"%s\": ", mod);
182 TiXmlElement *err = el_->FirstChildElement("Error");
183 ProcessErrorNode(err);
184
185 TiXmlElement * param;
186 if(err)
187 param = err->NextSiblingElement();
188 else
189 param = el_->FirstChildElement();
190
191 std::string rootkey = PAVPROT_NODE_GMP;
192 rootkey += "R.";
193 rootkey += mod;
194 rootkey += ".";
195
196 while(param){
197 std::string key = rootkey;
198 key += param->Value();
199 m_keysMap[key] = param->Attribute("val");
200
201 printf("\t%s=%s\n", param->Value(), param->Attribute("val"));
202 param = param->NextSiblingElement();
203 };
204};
void ProcessErrorNode(TiXmlElement *err_)
Definition: MessageReader.cpp:237
const char * Attribute(const char *name) const
Definition: tinyxml.cpp:577
const char * Value() const
Definition: tinyxml.h:487

◆ ProcessGPPNode()

void MessageReader::ProcessGPPNode ( TiXmlElement el_)
206 {
207 const char * lib = el_->Attribute("lib");
208 const char * path = el_->Attribute("path");
209 if(!lib || !path){
210 std::string xmlstr;
211 xmlstr << *el_;
212 printf("GPP format error, got \"%s\"\n", xmlstr.c_str());
213 return;
214 };
215 printf("GPP for path \"%s@%s\": ", path, lib);
216 TiXmlElement *err = el_->FirstChildElement("Error");
217 ProcessErrorNode(err);
218
219 TiXmlElement * param;
220 if(err)
221 param = err->NextSiblingElement();
222 else
223 param = el_->FirstChildElement();
224
225 std::string rootkey = PAVPROT_NODE_GPP;
226 rootkey += "R.";
227
228 while(param){
229 std::string key = rootkey;
230 key += param->Value();
231 m_keysMap[key] = param->Attribute("val");
232 printf("\t%s=%s\n", param->Value(), param->Attribute("val"));
233 param = param->NextSiblingElement();
234 };
235};

◆ ProcessMarksNode()

void MessageReader::ProcessMarksNode ( TiXmlElement el_)
128 {
129 int errid=PAVPROT_OK;
130 std::string key = PAVPROT_NODE_MARKS;
131 key += "R";
132 if(el_->QueryIntAttribute("error", &errid) == TIXML_SUCCESS){
133 if(errid == PAVPROT_BUSY)
134 printf("MARKS response code=%d (%s).\n", errid, GetErrorStr(errid).c_str());
135 const char *errstr = el_->GetText();
136 if(errstr)
137 printf("\tStatus:\"%s\"\n", errstr);
138 }else
139 printf("MARKS succeded.\n");
140 char val[10];
141 sprintf(val, "%d", errid);
142 m_keysMap[key] = val;
143};

◆ ProcessSMPNode()

void MessageReader::ProcessSMPNode ( TiXmlElement el_)
145 {
146 const char * mod = el_->Attribute("module");
147 if(!mod){
148 std::string xmlstr;
149 xmlstr << *el_;
150 printf("SMP format error, got \"%s\"\n", xmlstr.c_str());
151 return;
152 };
153 printf("SMP for module \"%s\": ", mod);
154 TiXmlElement *err = el_->FirstChildElement("Error");
155 ProcessErrorNode(err);
156};

◆ ProcessSPPNode()

void MessageReader::ProcessSPPNode ( TiXmlElement el_)
158 {
159 const char * lib = el_->Attribute("lib");
160 const char * path = el_->Attribute("path");
161 if(!lib || !path){
162 std::string xmlstr;
163 xmlstr << *el_;
164 printf("SPP format error, got \"%s\"\n", xmlstr.c_str());
165 return;
166 };
167 printf("SPP for path \"%s@%s\": ", path, lib);
168 TiXmlElement *err = el_->FirstChildElement("Error");
169 ProcessErrorNode(err);
170};

◆ ProcessStartNode()

void MessageReader::ProcessStartNode ( TiXmlElement el_)
110 {
111 int errid=PAVPROT_OK;
112 std::string key = PAVPROT_NODE_START;
113 key += "R";
114 if(el_->QueryIntAttribute("error", &errid) == TIXML_SUCCESS){
115 if(errid == PAVPROT_CANCELED || errid == PAVPROT_FINISHED)
116 m_stoped = true;
117 printf("START response code=%d (%s).\n", errid, GetErrorStr(errid).c_str());
118 const char *errstr = el_->GetText();
119 if(errstr)
120 printf("\tStatus:\"%s\"\n", errstr);
121 }else
122 printf("START succeded.\n");
123 char val[10];
124 sprintf(val, "%d", errid);
125 m_keysMap[key] = val;
126};

◆ ProcessStopNode()

void MessageReader::ProcessStopNode ( TiXmlElement el_)
99 {
100 int errid;
101 if(el_->QueryIntAttribute("error", &errid) == TIXML_SUCCESS){
102 printf("STOP response code=%d (%s).\n", errid, GetErrorStr(errid).c_str());
103 const char *errstr = el_->GetText();
104 if(errstr)
105 printf("\tStatus:\"%s\"\n", errstr);
106 }else
107 printf("STOP succeded.\n");
108};

Member Data Documentation

◆ m_keysMap

std::map<std::string, std::string> MessageReader::m_keysMap
private

◆ m_messId

int MessageReader::m_messId
private

◆ m_messNode

TiXmlElement* MessageReader::m_messNode
private

◆ m_stoped

bool MessageReader::m_stoped
private

◆ m_xmlDoc

TiXmlDocument MessageReader::m_xmlDoc
private

The documentation for this class was generated from the following files: