📄 message.h
字号:
#ifndef MESSAGE_H
#define MESSAGE_H
#include "Define.h"
enum MOBILE_PC_MESSAGE_TYPE
{
MPMT_UNDEFINE = 0x00,
MPMT_ID_LIST_REQUEST = 0x01,
MPMT_ID_LIST_RESPONSE = 0x02,
MPMT_EQUIPMENT_STATUS_REQUEST = 0x03,
MPMT_EQUIPMENT_STATUS_RESPONSE = 0x04,
MPMT_EQUIPMENT_SET_REQUEST = 0x05,
MPMT_EQUIPMENT_SET_RESPONSE = 0x06,
MPMT_ACCESS_CONTROL_REQUEST = 0x07,
MPMT_EQUIPMENT_SET = 0x08,
MPMT_ALL_LIGHT_ON_REQUEST = 0x09,
MPMT_ALL_LIGHT_OFF_REQUEST = 0x0a,
MPMT_INITIAL_REQUEST = 0x0b,
MPMT_INITIAL_RESPONSE = 0x0c,
MPMT_ERROR_RESPONSE = 0x0d
};
struct MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_PC_MESSAGE_TYPE message_type;
unsigned int message_length;
MOBILE_PC_GENERIC_MESSAGE()
: message_type(MPMT_UNDEFINE)
, message_length(0)
{
}
virtual bool wrap(unsigned char *&, int &) = 0;
virtual bool parse(unsigned char *, int) = 0;
};
struct MOBILE_PC_ID_List_Request : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_PC_ID_List_Request()
{
message_type = MPMT_ID_LIST_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
message_length += 1;
memcpy(buf+1, &message_length, 4);
ptr += 5;
nLen = ptr - buf;
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_ID_List_Response : public MOBILE_PC_GENERIC_MESSAGE
{
EquipmentList m_eqlist;
bool SetEquipmentList(const EquipmentList eqlist)
{
if (eqlist.empty())
{
return false;
}
m_eqlist.assign(eqlist.begin(), eqlist.end());
return true;
}
MOBILE_PC_ID_List_Response()
{
message_type = MPMT_ID_LIST_RESPONSE;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
EquipmentList::iterator it;
for (it = m_eqlist.begin(); it != m_eqlist.end(); it++)
{
memcpy(ptr, &(*it).m_ID, 2);
ptr += 2;
}
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
m_eqlist.clear();
int tempLen = message_length;
while (tempLen>0)
{
EquipmentNode tempnode;
memcpy(&(tempnode.m_ID), ptr, 2);
ptr += 2;
m_eqlist.push_back(tempnode);
tempLen -= 2;
}
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Equipment_Status_Request : public MOBILE_PC_GENERIC_MESSAGE
{
WORD m_nEqID;
MOBILE_PC_Equipment_Status_Request()
: m_nEqID(0)
{
message_type = MPMT_EQUIPMENT_STATUS_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
memcpy(ptr, &m_nEqID, 2);
ptr += 2;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
memcpy(&m_nEqID, ptr, 2);
ptr += 2;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Equipment_Status_Response : public MOBILE_PC_GENERIC_MESSAGE
{
EquipmentState m_nState;
MOBILE_PC_Equipment_Status_Response()
: m_nState(EQUIPMENT_UNKNOWN)
{
message_type = MPMT_EQUIPMENT_STATUS_RESPONSE;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
memcpy(ptr, &m_nState, 1);
ptr += 1;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
memcpy(&m_nState, ptr, 1);
ptr += 1;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Equipment_Set_Request : public MOBILE_PC_GENERIC_MESSAGE
{
WORD m_nEqID;
EquipmentState m_nState;
MOBILE_PC_Equipment_Set_Request()
: m_nEqID(0)
, m_nState(EQUIPMENT_UNKNOWN)
{
message_type = MPMT_EQUIPMENT_SET_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
memcpy(ptr, &m_nEqID, 2);
ptr += 2;
memcpy(ptr, &m_nState, 1);
ptr += 1;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
memcpy(&m_nEqID, ptr, 2);
ptr += 2;
memcpy(&m_nState, ptr, 1);
ptr += 1;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Equipment_Set_Response : public MOBILE_PC_GENERIC_MESSAGE
{
bool m_bFlag;
MOBILE_PC_Equipment_Set_Response()
: m_bFlag(false)
{
message_type = MPMT_EQUIPMENT_SET_RESPONSE;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
memcpy(ptr, &m_bFlag, 1);
ptr += 1;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
memcpy(&m_bFlag, ptr, 1);
ptr += 1;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Error_Response : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_PC_Error_Response()
{
message_type = MPMT_ERROR_RESPONSE;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Access_Control_Request : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_PC_Access_Control_Request()
{
message_type = MPMT_ACCESS_CONTROL_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Equipment_Set : public MOBILE_PC_GENERIC_MESSAGE
{
WORD m_nEqID;
MOBILE_PC_Equipment_Set()
: m_nEqID(0)
{
message_type = MPMT_EQUIPMENT_SET;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
memcpy(ptr, &m_nEqID, 2);
ptr += 2;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
memcpy(&m_nEqID, ptr, 2);
ptr += 2;
return (ptr - buf == nLen);
}
};
struct MOBILE_All_Light_On_Request : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_All_Light_On_Request()
{
message_type = MPMT_ALL_LIGHT_ON_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
struct MOBILE_All_Light_Off_Request : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_All_Light_Off_Request()
{
message_type = MPMT_ALL_LIGHT_OFF_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Initial_Request : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_PC_Initial_Request()
{
message_type = MPMT_INITIAL_REQUEST;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
struct MOBILE_PC_Initial_Response : public MOBILE_PC_GENERIC_MESSAGE
{
MOBILE_PC_Initial_Response()
{
message_type = MPMT_INITIAL_RESPONSE;
}
bool wrap(unsigned char *& buf, int & nLen)
{
unsigned char * ptr = buf;
ptr[0] = (unsigned char)message_type;
ptr += 5;
nLen = ptr - buf;
message_length = nLen - 5;
memcpy(buf+1, &message_length, 4);
return true;
}
bool parse(unsigned char *buf, int nLen)
{
unsigned char * ptr = buf;
memcpy(&message_length, buf+1, 4);
ptr += 5;
return (ptr - buf == nLen);
}
};
#endif //MESSAGE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -