//////////////////////////////////////////////////////////////////////////////////// /// /// \brief Tests large data set creation and merging. /// //////////////////////////////////////////////////////////////////////////////////// void TestLargeDataSets() { Packet payload; // Large data set payload. Header header; // Message header data. UShort messageCode = 50; // Random message type. Packet::List stream; // Multi-packet stream sequence. Header::List streamHeaders; // Mutli-packet stream sequence headers. unsigned int payloadSize = 60000; // Payload data size to create. header.mSourceID(50, 1, 1); header.mDestinationID(51, 1, 1); for(unsigned int i = 0; i < payloadSize/UINT_SIZE; i++) { payload.Write(i); } LargeDataSet::CreateLargeDataSet(header, messageCode, payload, stream, streamHeaders, NULL, 1437, 30); payload.Destroy(); messageCode = 0; header = Header(); LargeDataSet::MergeLargeDataSet(header, messageCode, payload, stream, NULL); unsigned int data; for(unsigned int i = 0; i < payloadSize/UINT_SIZE; i++) { payload.Read(data); if(data != i) { std::cout << "Large Data Sets Error: Data Does Not Match!\n"; return; } } std::random_shuffle(stream.begin(), stream.end()); LargeDataSet dataSet; for(unsigned int i = 0; i < (unsigned int)stream.size(); i++) { Header header; UShort messageCode; stream[i].SetReadPos(0); header.Read(stream[i]); stream[i].Read(messageCode); if(dataSet.AddPacket(header, messageCode, stream[i]) == false) { std::cout << "Large Data Sets Error: Could Not Collect Stream.\n"; } } // Now merge the data. LargeDataSet::MergeLargeDataSet(header, messageCode, payload, dataSet.mStream, NULL); for(unsigned int i = 0; i < payloadSize/UINT_SIZE; i++) { payload.Read(data); if(data != i) { std::cout << "Large Data Sets Error: Data Does Not Match!\n"; return; } } }
//////////////////////////////////////////////////////////////////////////////////// /// /// \brief Test method to verify ability to read/write message data from /// an example wireshark log provided for testing systems for the JAUS /// Interoperability Challenge hosted at several AUVSI competitions. /// //////////////////////////////////////////////////////////////////////////////////// void VerifyAgainstLog() { Packet::List packets; Packet::List::iterator packet; Component component; component.DiscoveryService()->SetSubsystemIdentification(Subsystem::OCU, "OCP"); component.AddService(new LocalPoseSensor()); component.AddService(new VelocityStateSensor()); component.AddService(new ListManager()); component.AddService(new TestLocalWaypointListDriver()); Packet::LoadWiresharkCapturePacketExport("logs/example-capture.txt", packets); Address cop(42, 1, 1); Address sim(6000, 1, 1); //Packet::LoadWiresharkCapturePacketExport("logs/example_capture-2.txt", packets); Message::List messages; Message::List::iterator message; // Delete UDP header data to get to just the JAUS message. for(packet = packets.begin(); packet != packets.end();) { // Delete UDP header data. packet->Delete(43); // Read message header data. Header jausHeader; if(jausHeader.Read(*packet)) { UShort messageCode = 0; packet->Read(messageCode, Header::PayloadOffset); Message* jausMessage = component.TransportService()->CreateMessage(messageCode); if(jausMessage) { packet->SetReadPos(0); if(jausMessage->Read(*packet)) { messages.push_back(jausMessage); if(jausMessage->GetMessageCode() == SET_ELEMENT) { Element::List::iterator m; SetElement* setElement = (SetElement *)jausMessage; for(m = setElement->GetElementList()->begin(); m != setElement->GetElementList()->end(); m++) { UShort code = 0; m->mPayload.SetReadPos(0); m->mPayload.Read(code); Message* element = component.TransportService()->CreateMessage(code); if(element) { element->CopyHeaderData(jausMessage); if(element->ReadMessageBody(m->mPayload)) { messages.push_back(element); } else { std::cout << "Failed to Read Message Data [" << std::hex << element->GetMessageCode() << "]:\n"; delete element; } } } } } else { std::cout << "Failed to Read Message Data [" << std::hex << jausMessage->GetMessageCode() << "]:\n"; } } else { std::cout << "Unknown Message Type [" << std::hex << messageCode << "]:\n"; } } else { std::cout << "Bad Header!\n"; } packet++; } component.Initialize(cop); message = messages.begin(); for(message = messages.begin(); message != messages.end(); message++) { //(*message)->Print(); if((*message)->GetSourceID() == cop) { (*message)->SetDestinationID(sim); component.Send((*message)); } CxUtils::SleepMs(1); delete (*message); } }