#include <QJsonParseError>
#include <QVariantMap>
#include <QJsonObject>
#include <QJsonArray>
#include <QApplication>
#include <iostream>
template <class T>
class Integer
{
public:
Integer( T data ) noexcept
: m_hData( uint32_t( data ) >> 16 )
, m_lData( data & 0xFFFF )
{
}
operator T() const noexcept
{
return static_cast<T>( m_hData << 16 | m_lData );
}
uint16_t getHData() const noexcept
{
return m_hData;
}
uint16_t getLData() const noexcept
{
return m_lData;
}
private:
uint16_t m_hData;
uint16_t m_lData;
};
typedef Integer<uint32_t> UInt32;
typedef Integer<int32_t> Int32;
typedef struct
{
uint16_t result;
uint16_t loginNodeId;
uint32_t x;
uint32_t y;
} LoginResponseInfo, * LoginResponseInfoPtr;
typedef struct
{
uint16_t comandId;
uint16_t taskState; //1 idle 2 busy
uint16_t startNodeId;
uint16_t targetNodeId;
uint16_t currentNodeId;
Int32 x = 0;
Int32 y = 0;
uint16_t isToLearn;
int16_t learnParam;
uint16_t angle;
uint16_t speed;
UInt32 mileage = 0;
uint16_t runLength;
uint16_t energy;
UInt32 exceptionA = 0;
UInt32 exceptionB = 0;
UInt32 exceptionC = 0;
uint16_t isLoad; // 1 有载 2 无载
UInt32 actionStatus = 0;
uint16_t isAuto;
uint16_t isPause; // 1暂停 2 正常
uint16_t remained[2];
} AgvStateInfo;
typedef struct
{
uint16_t comandId;
uint16_t taskState; //1 idle 2 busy
uint16_t startNodeId;
uint16_t targetNodeId;
uint16_t currentNodeId;
Int32 x;
Int32 y;
uint16_t isToLearn;
int16_t learnParam;
uint16_t angle;
uint16_t speed;
UInt32 mileage;
uint16_t runLength;
uint16_t energy;
UInt32 exceptionA;
UInt32 exceptionB;
UInt32 exceptionC;
uint16_t isLoad; // 1 有载 2 无载
UInt32 actionStatus;
uint16_t isAuto;
uint16_t isPause; // 1暂停 2 正常
uint16_t remained[2];
}* RecieveStateInfoPtr;
int main( int argc, char* argv[] )
{
QApplication a( argc, argv );
RecieveStateInfoPtr agv_state;
agv_state->comandId = 111;
agv_state->taskState = 1;
agv_state->startNodeId = 2100;
agv_state->targetNodeId = 2350;
agv_state->currentNodeId = 2166;
agv_state->x = 481;
agv_state->y = 1100;
agv_state->isToLearn = 0;
agv_state->learnParam = 0;
agv_state->angle = 2000;
agv_state->speed = 120;
agv_state->mileage = 100000;
agv_state->runLength = 3000;
agv_state->energy = 98;
agv_state->exceptionA = 111;
agv_state->exceptionB = 222;
agv_state->exceptionC = 333;
agv_state->isLoad = 1;
agv_state->actionStatus = 444;
agv_state->isAuto = 1;
agv_state->isPause = 0;
agv_state->remained[0] = 0;
agv_state->remained[1] = 0;
RecieveStateInfoPtr zx = agv_state;
quint16* content = new quint16[30]();
content = reinterpret_cast<quint16*>( agv_state );
for ( int i = 0; i < 30; i++ )
{
std::cout << i << ": " << content[i] << std::endl;
}
int tmp_speed = content[12];
int tmp_energy = content[16];
RecieveStateInfoPtr recieve_state = reinterpret_cast<RecieveStateInfoPtr>( content );
int x = recieve_state->x;
int y = recieve_state->y;
int energy = recieve_state->energy;
return a.exec();
}