22 #include "MPTypes.hpp" 24 #include <ml/MACollectedData.hpp> 25 #include <network/MAStreamPacketCoder.hpp> 26 #include <types/MAHead.hpp> 27 #include <types/MARobotState.hpp> 28 #include <types/MATorso.hpp> 30 #include <MCBinaryData.hpp> 32 #include <MCZipper.hpp> 34 #include <MEImage.hpp> 36 #include <qjsonobject.h> 37 #include <qstringlist.h> 38 #include <qtextstream.h> 41 #include <boost/scoped_ptr.hpp> 46 bool BackwardCompatibility =
false;
62 QJsonObject* Object =
new QJsonObject;
63 MC::BinaryDataSPtr BinaryData(collected_data.
Encode());
65 Object->insert(
"objectType", QString(
"objects.")+QString::fromStdString(collected_data.
GetName()));
66 Object->insert(
"sessionId", collected_data.
GetSessionID());
68 Object->insert(
"data", QString::fromStdString(BinaryData->ToBase64()));
75 QJsonObject* QueryObject =
new QJsonObject;
77 MC::BinaryDataSPtr BinaryData(collected_data.
Encode());
81 QueryObject->insert(
"objectType", QString(
"objects.")+QString::fromStdString(collected_data.
GetName()));
82 QueryObject->insert(
"query", Object);
91 BinaryData->FromBase64(json_object.value(
"data").toString().toStdString());
153 boost::scoped_ptr<MAStreamPacketCoder> Coder(MAStreamPacketCoder::Decode(packet));
154 MA::IntIntSortedMap RecordIDsTimestamps;
156 if (Coder.get() ==
nullptr)
158 MC_WARNING(
"Cannot decode packet into robot state record (packet size: %d)", packet.
GetSize());
159 return RecordIDsTimestamps;
164 Packet->
Clone(packet);
165 Packets.push_back(MP::PacketPtr(Packet));
167 MA::BinaryDataSPtrList RobotStates = Coder->GetRobotStates();
168 MA::BinaryDataSPtrList Images = Coder->GetImages();
169 MA::BinaryDataSPtrList LogMessages = Coder->GetLogMessages();
170 MA::BinaryDataSPtrList Sounds = Coder->GetSounds();
172 for (
int i = 0; i < Coder->GetPacketCapacity(); ++i)
181 ImageData->
Clone(*Images[i]);
182 Record->
Image = MP::ImagePtr(ImageData);
187 if (BackwardCompatibility)
192 *RobotStates[i] = FinalPacket;
206 *RobotStates[i] = FinalPacket;
210 BackwardCompatibility =
true;
218 int Milliseconds = Record->
RobotState->Torso->Timestamp.ToMilliseconds();
221 RecordIDsTimestamps.insert(std::pair<int, int>(Record->
ID, Milliseconds));
224 RobotStateData->
Clone(*RobotStates[i]);
230 QStringList* Messages =
new QStringList;
233 QByteArray LogMessageData((
const char*)LogMessages[i]->GetData(), LogMessages[i]->GetSize());
234 QTextStream Stream(&LogMessageData);
239 Line = Stream.readLine();
244 }
while (!Line.isNull());
245 Record->
LogMessages = MP::LogMessagesPtr(Messages);
251 SoundData->
Clone(*Sounds[i]);
252 Record->
SoundData = MC::BinaryDataSPtr(SoundData);
254 Records.push_back(MP::RecordPtr(Record));
256 return RecordIDsTimestamps;
const MP::PacketPtrList & GetPackets() const
Get the packets.
Collected data with portable storage functions.
MA::IntIntSortedMap AddDataFromPacket(MCBinaryData &packet)
Turn a packet content into robot state records.
std::string GetName() const
Get name.
const MP::RecordPtrList & GetRecords() const
Get the records.
MPRecord()
Struct constructor.
MP::RobotStatePtr RobotState
Stored robot state.
MP::ImagePtr Image
Stored image.
bool IsEmpty() const
Whenever the container is empty.
MC::BinaryDataSPtr RobotStateBinaryData
Stored robot state binary data.
MCBinaryData * MPDecodeImage(const MCBinaryData &binary_data)
Decode a jpeg image from AIBO.
MP::PacketPtrList Packets
Packet list.
#define MC_WARNING(...)
Warning macro.
int GetCollectionID()
Get collection ID.
MPTimestampList()
Struct constructor.
MP::RecordPtrList Records
Record list.
MC::BinaryDataSPtr SoundData
Stored sound data.
MCBinaryData * ExportRawImageData() const
Export the raw image data.
MPStreamMarkers()
Struct constructor.
void Clone(const MCBinaryData &other)
Clone an other binary data instance.
static void DecompressQuickLz(const MCBinaryData &input_buffer, MCBinaryData &output_buffer, bool without_header=false)
Decompress data with QuickLZ algorithm.
void Clear()
Clear the container.
QJsonObject * MPConvertCollectedDataToJsonQuery(MACollectedData &collected_data)
Convert the collected data in JSON object for query.
static MACollectedData * Decode(const MCBinaryData &data)
Decode from binary data.
MCBinaryData * Encode() const
Encode into binary data.
QJsonObject * MPConvertCollectedDataToJson(MACollectedData &collected_data)
Convert the collected data in JSON object.
MPMissingPackets()
Struct constructor.
static std::string RobotStateVariableMap
Cached variable map for robot state decoding.
Base class for the data exchange of the elements.
MPRecoveredPackets()
Struct constructor.
MPCursorPosition()
Struct constructor.
int GetSessionID()
Get session ID.
MPRecordsContainer()
Struct constructor.
MP::LogMessagesPtr LogMessages
Stored log messages.
static MARobotState * Decode(const MCBinaryData &data, const std::string &variable_map="")
Decode from binary data form.
bool Decompress(const MCBinaryData &data)
Decompress image data.
Robot state record struct.
MPLogEntryMap()
Struct constructor.
MACollectedData * MPConvertJsonToCollectedData(QJsonObject &json_object)
Convert a JSON object back to collected data.
int GetSize() const
Get binary data size.