|
@@ -0,0 +1,57 @@
|
|
|
+#include "ar548pac.h"
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+#define POS_ServiceID 0
|
|
|
+#define POS_MethodID 2
|
|
|
+#define POS_Length 4
|
|
|
+#define POS_ClientID 8
|
|
|
+#define POS_SessionID 10
|
|
|
+#define POS_ProtocolVersion 12
|
|
|
+#define POS_InterfaceVersion 13
|
|
|
+#define POS_MessageType 14
|
|
|
+#define POS_ReturnCode 15
|
|
|
+
|
|
|
+ars548pac::ars548pac(const char * pdata,int ndatalen)
|
|
|
+{
|
|
|
+ if(ndatalen<16)
|
|
|
+ {
|
|
|
+ std::cout<<" ARS548 Packet Len < 16, ndatalen:"<<ndatalen<<std::endl;
|
|
|
+ mbPacValid = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ memcpy(&mheader.ServiceID,pdata+POS_ServiceID,2);
|
|
|
+ memcpy(&mheader.MethodID,pdata+POS_MethodID,2);
|
|
|
+ memcpy(&mheader.Length,pdata+POS_Length,4);
|
|
|
+ memcpy(&mheader.ClientID,pdata+POS_ClientID,2);
|
|
|
+ memcpy(&mheader.SessionID,pdata+POS_SessionID,2);
|
|
|
+ memcpy(&mheader.ProtocolVersion,pdata+POS_ProtocolVersion,1);
|
|
|
+ memcpy(&mheader.InterfaceVersion,pdata+POS_InterfaceVersion,1);
|
|
|
+ memcpy(&mheader.MessageType,pdata+POS_MessageType,1);
|
|
|
+ memcpy(&mheader.ReturnCode,pdata+POS_ReturnCode,1);
|
|
|
+
|
|
|
+ if(mheader.Length != (unsigned short)(ndatalen-8))
|
|
|
+ {
|
|
|
+ std::cout<<" Packet Length Error. "<<"Length Told in header, "<<mheader.Length<<" ndatalen:"<<ndatalen<<std::endl;
|
|
|
+ mbPacValid = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+iv::ars548pac_header ars548pac::GetHeader()
|
|
|
+{
|
|
|
+ return mheader;
|
|
|
+}
|
|
|
+
|
|
|
+iv::ars548pac_Payload ars548pac::GetPayload()
|
|
|
+{
|
|
|
+ return mPayload;
|
|
|
+}
|
|
|
+
|
|
|
+bool ars548pac::IsValidPac()
|
|
|
+{
|
|
|
+ return mbPacValid;
|
|
|
+}
|