void DomusEngineUSBDevice::addSyntetichData() { RequestedAttributes::Attribute &firstAttr = requestedAttributes.attributes[0]; NwkAddr nwkAddr = firstAttr.nwkAddrs; EndpointID endpoint = firstAttr.endpoint; ClusterID cluster = firstAttr.clusterID; std::vector<RequestedAttributes::Attribute> attributesToSend{getAttributeToSend(nwkAddr, endpoint, cluster)}; size_t size = calcTotalSize(attributesToSend) + sizeof(ReadAttributeResponseMessage); auto *data = new uint8_t[size]; ReadAttributeResponseMessage *message = reinterpret_cast<ReadAttributeResponseMessage *>(data); message->networkAddr = nwkAddr.getId(); message->endpoint = endpoint.getId(); message->clusterId = cluster.getId(); message->generticDataMsg = ATTRIBUTE_VALUES; message->numAttributes = attributesToSend.size(); message->panId = 0; message->type = 0; uint8_t *rawData = data + sizeof(ReadAttributeResponseMessage); BOOST_LOG_TRIVIAL(info) << "start attributes data: " << (void *) rawData; fillRawData(attributesToSend, rawData); usbResponseExecuters.execute(data, size); delete[]data; }
char* XMLStack::parseXMLStream(char *stream, XMLElement *parent) { if(!stream || !parent) return nullChar; NSString token; if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; if(!consumeWhiteSpaces(&stream)) return nullChar; if(*stream == '<' && (!consumeComment(&stream) && !consumeXMLHeader(&stream))) { stream++; if(!moveAndCheckProgress()) return nullChar; getIdentifier(&stream, token); parent->setName(token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; if(*stream == '>') { stream++; if(!moveAndCheckProgress()) return nullChar; } else { while((*stream != stx_getOsSeparator() && *(stream + 1) != '>') && (*stream != '>')) { XMLElement *newTag = new XMLElement(); getIdentifier(&stream, token); newTag->setName(token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; getStringValue(&stream, token); newTag->setValue(token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; parent->addChild(newTag); } if(*stream == stx_getOsSeparator() && *(stream + 1) == '>') { stream +=2; if(!moveAndCheckProgress(2)) return nullChar; return stream; } stream++; } if(parent->getName() != "RawData") { getStreamedValue(&stream, token); parent->setValue(token); } else { XMLElement *info = parent->getChildByName("length"); bool sucess = (!info) ? fillRawData(&stream, &parent->rawData) : fillRawData(&stream, &parent->rawData, info->getValuei()); if(!sucess) writeFatalLogInfo("\n<!>Failed to load raw data, check your XML file.\n"); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; } if(!consumeWhiteSpaces(&stream)) return nullChar; consumeComment(&stream); while(*stream == '<' && *(stream + 1) != stx_getOsSeparator()) { XMLElement *newTag = new XMLElement(); stream = parseXMLStream(stream, newTag); if(!stream || !consumeWhiteSpaces(&stream)) return nullChar; parent->addChild(newTag); } if(*stream == '<' && *(stream + 1)== stx_getOsSeparator()) { stream+=2; if(!moveAndCheckProgress(2)) return nullChar; getIdentifier(&stream, token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; } if(token != parent->getName() || *stream != '>') { /* //writeFatalLogInfoList LOG_PRINT("\n<!>Start tag <%s> & End Tag <%s> do not match,"\ "check your XML file.\n", parent->getName(), token); ??? */ return nullChar; } stream++; if(!consumeWhiteSpaces(&stream)) return nullChar; } return (state == XML_SUCCESS) ? stream : nullChar; }