FIAP (IEEE1888) library
Dependents: Fetch_IEEE1888_Storage IEEE1888_MULTI_SENSOR_GW
Fork of FiapV2 by
Diff: fiap.cpp
- Revision:
- 6:52e95ea60ec1
- Parent:
- 5:f0b636449aa3
- Child:
- 7:cc924e783dff
diff -r f0b636449aa3 -r 52e95ea60ec1 fiap.cpp --- a/fiap.cpp Wed Aug 22 00:04:32 2012 +0000 +++ b/fiap.cpp Wed Aug 22 02:20:31 2012 +0000 @@ -60,7 +60,7 @@ int FIAP::fetch_last_data(struct fiap_element* v,unsigned int esize) { HTTPClient http; - int i,ii,ll; + int i,ii,ll,k1,k2; fetch_xml_initialize(); strcpy( _soap_text, _soap_header); sprintf(uuid,"%04x%04x-%04x-%04x-%04x-%04x%04x%04x",rand()%0x10000,rand()%0x10000,rand()%0x10000,rand()%1000|0x4000,rand()%0x1000|0x8000,rand()%0x10000,rand()%10000,(rand()+1)%0x10000); @@ -86,14 +86,14 @@ char rstr[800]; HTTPText stream(rstr,800); //stream.readNext((byte*)outBuffer,1500); - if (debug_mode)printf("post.start \n\r"); + if (debug_mode)printf("post.start \n\r"); HTTPResult r = http.postXML(_fiap_storage,"http://soap.fiap.org/query",InData,&stream); if (debug_mode) printf("post.end \n\r"); - if (debug_mode){ - printf("****\n\r"); - printf(rstr); - printf("\n\r****\n\r"); - } + if (debug_mode) { + printf("****\n\r"); + printf(rstr); + printf("\n\r****\n\r"); + } if(!r) { if (debug_mode)printf("Success \n"); } else { @@ -134,8 +134,15 @@ if (debug_mode)printf("Connection error\n"); return -1; } + if (r==HTTP_CLOSED) { + if (debug_mode)printf("Connection error\n"); + return -1; + } + if (debug_mode)printf("Unknown Network Error\n"); + return -1; } SP_XmlNodeList * points; + SP_XmlNodeList * trans_point; if (strlen(rstr)>0) { if (debug_mode)printf("\n\r data Get Ok\n\r"); SP_XmlDomParser parser; @@ -148,35 +155,53 @@ char str[50]; if (debug_mode) printf ("%s \n",transport.toElement()->getName()); if (fiapError==NULL) { - SP_XmlElementNode * values =transport.getChild("body").toElement(); - points=(SP_XmlNodeList *)values->getChildren() ; - int j=points->getLength(); - if (debug_mode) printf("GetValues of No %d \n\r",j); - SP_XmlElementNode *data_point_node,*data_value_node; - SP_XmlCDataNode *data_value_cnode; - for (i=0; i<j; i++) { - SP_XmlHandle data_handle(points->get(i));//Point - data_point_node=data_handle.toElement(); - data_value_node=data_handle.getChild("value").toElement(); - data_value_cnode=data_handle.getChild("value").getChild(0).toCData(); - if (debug_mode) printf("PointID=%s \r\n",data_point_node->getAttrValue("id")); - if (debug_mode) printf("date=%s \r\n",data_value_node->getAttrValue("time")); - if (debug_mode) printf("data=%s \r\n",data_value_cnode->getText()); - for (ii=0; ii<esize; ii++) { - if (strcmp(v[ii].cid,data_point_node->getAttrValue("id"))==0) { - sprintf(str,"%s",data_value_node->getAttrValue("time")); - ll=sscanf(str,"%d-%d-%dT%d:%d:%d.",&yy,&mo,&dd,&hh,&mm,&ss); - if (debug_mode)printf("date convert no %d (%d/%d/%d %d:%d:%d) \r\n",ll,yy,mo,dd,hh,mm,ss); - v[ii].year=yy; - v[ii].month=mo; - v[ii].day=dd; - v[ii].hour=hh; - v[ii].minute=mm; - v[ii].second=ss; - sprintf(v[ii].value,"%s",data_value_cnode->getText()); + SP_XmlElementNode * trans_element = transport.toElement(); + trans_point=(SP_XmlNodeList *)trans_element->getChildren() ; + k1=trans_point->getLength(); + if(debug_mode)printf("Trans Child has Element of No %d \n\r",k1); + SP_XmlElementNode * values; + for(k2=0; k2<k1; k2++) { + values =transport.getChild(k2).toElement(); + if(debug_mode)printf(values->getName()); + if(debug_mode)printf("\n\r"); + if(strstr((values->getName()),"body") !=NULL) { + if(debug_mode)printf("find body \n\r"); + points=(SP_XmlNodeList *)values->getChildren() ; + int j=points->getLength(); + if (debug_mode) printf("GetValues of No %d \n\r",j); + SP_XmlElementNode *data_point_node,*data_value_node; + SP_XmlCDataNode *data_value_cnode; + for (i=0; i<j; i++) { + SP_XmlHandle data_handle(points->get(i));//Point + data_point_node=data_handle.toElement(); + //data_value_node=data_handle.getChild("value").toElement(); + //data_value_cnode=data_handle.getChild("value").getChild(0).toCData(); + data_value_node=data_handle.getChild(0).toElement(); + data_value_cnode=data_handle.getChild(0).getChild(0).toCData(); + if (debug_mode) printf("PointID=%s \r\n",data_point_node->getAttrValue("id")); + if (debug_mode) printf("date=%s \r\n",data_value_node->getAttrValue("time")); + if (debug_mode) printf("data=%s \r\n",data_value_cnode->getText()); + for (ii=0; ii<esize; ii++) { + if (strcmp(v[ii].cid,data_point_node->getAttrValue("id"))==0) { + sprintf(str,"%s",data_value_node->getAttrValue("time")); + ll=sscanf(str,"%d-%d-%dT%d:%d:%d.",&yy,&mo,&dd,&hh,&mm,&ss); + if (debug_mode)printf("date convert no %d (%d/%d/%d %d:%d:%d) \r\n",ll,yy,mo,dd,hh,mm,ss); + v[ii].year=yy; + v[ii].month=mo; + v[ii].day=dd; + v[ii].hour=hh; + v[ii].minute=mm; + v[ii].second=ss; + sprintf(v[ii].value,"%s",data_value_cnode->getText()); + } + } } + } + + } + } else { printf("ERROR\n\r"); } @@ -214,9 +239,9 @@ HTTPText InData(_soap_text); HTTPText stream(rstr,800); // stream.readNext((byte*)outBuffer,strlen(outBuffer)); - if (debug_mode)printf("post.start \n\r"); + if (debug_mode)printf("post.start \n\r"); HTTPResult r = http.postXML(_fiap_storage,"http://soap.fiap.org/query",InData,&stream); - if (debug_mode)printf("post.end \n\r"); + if (debug_mode)printf("post.end \n\r"); if(!r) { if (debug_mode)printf("Success \n"); } else { @@ -256,24 +281,30 @@ if (debug_mode)printf("Connection error\n"); return -1; } + if (r==HTTP_CLOSED) { + if (debug_mode)printf("Connection error\n"); + return -1; + } + if (debug_mode)printf("Unknown Network Error\n"); + return -1; } SP_XmlNodeList * points; if (strlen(rstr)>0) { if (debug_mode)printf("\n\r data Get Ok\n\r"); - + SP_XmlDomParser parser; - + // if (debug_mode)printf("stream readlen = %d \n\r",stream.readLen()); // outBuffer[stream.readLen()]=0; - if (debug_mode)printf("check0\n\r"); + if (debug_mode)printf("check0\n\r"); parser.append(rstr,strlen(rstr)); - if (debug_mode)printf("check1\n\r"); + if (debug_mode)printf("check1\n\r"); SP_XmlHandle rootHandle(parser.getDocument()->getRootElement()); SP_XmlHandle transport = rootHandle.getChild(0).getChild(0).getChild(0); SP_XmlElementNode * fiapError = transport.getChild("header").getChild("error").toElement(); int yy,mo,dd,hh,mm,ss; char str[50]; - if (debug_mode)printf ("%s \n\r",transport.toElement()->getName()); + if (debug_mode)printf ("%s \n\r",transport.toElement()->getName()); if (fiapError==NULL) { SP_XmlElementNode * values =transport.getChild("body").toElement(); points=(SP_XmlNodeList *)values->getChildren() ; @@ -345,11 +376,11 @@ HTTPResult r = http.postXML(_fiap_storage,"http://soap.fiap.org/data",InData,&OutData); if(!r) { if (debug_mode)printf("Success \n"); - if (debug_mode){ - printf("****\n\r"); - printf(rstr); - printf("\n\r****\n\r"); - } + if (debug_mode) { + printf("****\n\r"); + printf(rstr); + printf("\n\r****\n\r"); + } } else { if (r==HTTP_PROCESSING) { if (debug_mode)printf("Processing \n"); @@ -387,6 +418,12 @@ if (debug_mode)printf("Connection error\n"); return -1; } + if (r==HTTP_CLOSED) { + if (debug_mode)printf("Connection error\n"); + return -1; + } + if (debug_mode)printf("Unknown Network Error\n"); + return -1; } return 0; } \ No newline at end of file