ProtocolPack.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /********************************************************************************
  2. * File Name: ProtocolPack.h
  3. * Function Describe: Header file for ProtocolPack.c
  4. * Explain:
  5. * Writer: ShiLiangWen
  6. * Date: 2019-2-9
  7. *******************************************************************************/
  8. #ifndef __PROTOCOL_PACK_H
  9. #define __PROTOCOL_PACK_H
  10. //-------------------------------------------------------------------------------
  11. //#include "MyUHFReader.h"
  12. #define PROPACKET_BUF_LEN 1200
  13. #define MSGID_UPGRADE 0xA902
  14. #define MSGID_IOT 0xA901//0xC900
  15. #define MSGID_LOGIN 0xA903//0x0929
  16. #define MSGID_POSITION 0xA904//0x0200
  17. #define MSGID_DOWNCMD 0xA905
  18. #define MSGID_ARRANGE 0xA906
  19. #define MSGID_VOICE_EVENT 0xA907
  20. #define MSGID_VOICE_INFO 0xA908
  21. #define MSGID_VOICE_DATA 0xA909
  22. #define MSGID_VOICE_AUTH 0xA910
  23. #define MSGID_VOICE_LOAD_INFO 0xB908
  24. #define MSGID_VOICE_LOAD_DATA 0xB909
  25. #define MSGID_VOICE_LOAD_AUTH 0xB910
  26. #define MSGID_VOICE_LOAD_TTS 0xB911
  27. #define MSGID_M_POSITION 0x0704
  28. #define MSGID_TICK 0x0002
  29. #define MSGID_LOGINACK 0x8929
  30. #define MSGID_COMACK 0x8001
  31. #define EXTRA_MSG_ID 0x3E
  32. #define EPC_NUM_MAX 25 //1°üÊý¾ÝÔÊÐí´øµÄEPC ¸öÊý
  33. #define EPC_LEN_MAX (7+2) //EPC±àÂ볤¶È
  34. #define PACKET_CONVERT_LEN_OVER -55
  35. #define PROTO_FLAG 0x5e
  36. //½á¹¹ÌåSUTDL ÓÃÓÚ½â¾öÍøÂç´«Êäunsigned longÀàÐÍʱ£¬ÒòMCUϵͳºÍPCϵͳ´æ´¢²îÒì¶ø×öµÄµ÷Õû
  37. typedef struct SUTDL
  38. {
  39. union {
  40. struct { unsigned char b1,b2,b3,b4; }ucData;
  41. unsigned long ulData;
  42. }Data;
  43. }SUTDL;
  44. //½á¹¹ÌåSUTDL ÓÃÓÚ½â¾öÍøÂç´«Êäunsigned shortÀàÐÍʱ£¬ÒòMCUϵͳºÍPCϵͳ´æ´¢²îÒì¶ø×öµÄµ÷Õû
  45. typedef struct SUTDS
  46. {
  47. union {
  48. struct { unsigned char b1,b2; }ucData;
  49. unsigned short usData;
  50. }Data;
  51. }SUTDS;
  52. typedef struct SUT_PROPACKET
  53. {
  54. unsigned char *pSendBuf;
  55. unsigned char *pRecvBuf;
  56. unsigned short SendBufLen;
  57. unsigned short RecvBufLen;
  58. unsigned char DeviceID[6];
  59. }SUT_PROPACKET;
  60. extern SUT_PROPACKET sutPropacket;
  61. typedef struct SUT_POS_ALARM{
  62. unsigned int NU1:4;//δÓÃ
  63. unsigned int GNSS:1;//bit 4 ¶¨Î»Ä£¿é
  64. unsigned int NU2:10;//δÓÃ
  65. unsigned int Meter:1;//bit 15 Ë®±í
  66. unsigned int NU3:16;//δÓÃ
  67. }__attribute__((packed)) SUT_POS_ALARM;
  68. typedef struct SUT_POS_STATUS{
  69. unsigned int ACC:1;//0 0£ºACC ¹Ø£»1£º ACC ¿ª
  70. unsigned int GNSS:1;//1 0£ºÎ´¶¨Î»£»1£º¶¨Î»
  71. unsigned int South:1;//2 0£º±±Î³£»1£ºÄÏγ
  72. unsigned int West:1;//3 0£º¶«¾­£»1£ºÎ÷¾­
  73. unsigned int NU1:14;//4~17 δÓÃ
  74. unsigned int GPS:1;//18 0£ºÎ´Ê¹Óà GPS ÎÀÐǽøÐж¨Î»£»1£ºÊ¹Óà GPS ÎÀÐǽøÐж¨Î»
  75. unsigned int BD:1;//19 0£ºÎ´Ê¹Óñ±¶·ÎÀÐǽøÐж¨Î»£»1£ºÊ¹Óñ±¶·ÎÀÐǽøÐж¨Î»
  76. unsigned int GLONASS:1;//20 0£ºÎ´Ê¹Óà GLONASS ÎÀÐǽøÐж¨Î»£»1£ºÊ¹Óà GLONASS ÎÀÐǽøÐж¨Î»
  77. unsigned int Galileo:1;//21 0£ºÎ´Ê¹Óà Galileo ÎÀÐǽøÐж¨Î»£»1£ºÊ¹Óà Galileo ÎÀÐǽøÐж¨Î»
  78. unsigned int NU2:10;//22-31 ±£Áô
  79. }__attribute__((packed)) SUT_POS_STATUS;
  80. typedef struct SUT_POSITION
  81. {
  82. unsigned char flag;//´æ´¢±êÖ¾£¬Óд洢Ϊ0£¬Î޴洢ΪFF
  83. SUT_POS_ALARM Alarm;//0 ±¨¾¯±êÖ¾ DWORD ±¨¾¯±ê־붨Òå¼û ±í 24
  84. SUT_POS_STATUS Status;//4 ״̬ DWORD ״̬붨Òå¼û ±í 25
  85. unsigned int Latitude;//8 γ¶È DWORD ÒÔ¶ÈΪµ¥Î»µÄγ¶ÈÖµ³ËÒÔ10µÄ6´Î·½£¬ ¾«È·µ½°ÙÍò·ÖÖ®Ò»¶È
  86. unsigned int Longitude;//12 ¾­¶È DWORD ÒÔ¶ÈΪµ¥Î»µÄ¾­¶ÈÖµ³ËÒÔ10µÄ6´Î·½£¬ ¾«È·µ½°ÙÍò·ÖÖ®Ò»¶È
  87. unsigned short Altitude; //16 ¸ß³Ì WORD º£°Î¸ß¶È£¬µ¥Î»ÎªÃ×£¨m£©
  88. unsigned short Speed;//18 ËÙ¶È WORD 1/10km/h
  89. unsigned short Aspect;//20 ·½Ïò WORD 0-359£¬Õý±±Îª 0£¬Ë³Ê±Õë
  90. unsigned char Time[6];//21 ʱ¼ä BCD[6] YY-MM-DD-hh-mm-ss£¨GMT+8 ʱ¼°µÄʱ¼ä¾ù²ÉÓôËʱÇø£©
  91. //ÉÏÃæÒÑÕ¼29bytes
  92. //¸½¼ÓÐÅÏ¢
  93. unsigned char ExtraMsgId;//¸½¼ÓÐÅÏ¢ID
  94. unsigned char ExtraMsgLen;//¸½¼ÓÐÅÏ¢³¤¶È --³¤¶È¹Ì¶¨Îª´ÓÏÂÒ»Ïʼµ½½á¹¹Ìå×îºóµÄ³¤¶È
  95. unsigned char GpsNum;
  96. unsigned char BDNum;
  97. unsigned char PDOP;
  98. unsigned short Ax;
  99. unsigned short Ay;
  100. unsigned short Az;
  101. unsigned short Mx;
  102. unsigned short My;
  103. unsigned short Mz;
  104. //ÉÏÃæÒÑÕ¼29+17=46bytes
  105. unsigned char EPCNum;//EPCÁбíÖÐÓÐЧµÄEPC¸öÊý
  106. //sutEPCInfoSaving EpcList[EPC_NUM_MAX];//EPCÁбí ×î¶àEPC_LIST_MAX×é ÿ¸öEPCInfo³¤¶ÈΪ8bytes
  107. unsigned char Res[5];//±£Áô£¬Ê¹Õ¼ÓÃ256 bytes
  108. unsigned long Mark;//´æ´¢±êÖ¾ 0x12345678
  109. }__attribute__((packed)) SUT_POSITION;
  110. void ProtocolPackInit(unsigned long DeviceId,unsigned char *pSendBuf,unsigned short SendBufLen,unsigned char *pRecvBuf,unsigned short RecvBufLen);
  111. int PacketIOT(unsigned short MsgNum);
  112. int PacketTick(unsigned short MsgNum);
  113. int PacketLogin(unsigned short MsgNum);
  114. int PacketPosition(unsigned short MsgNum,int max_size);
  115. int PacketMorePosition(unsigned short MsgNum);
  116. int PackeUpgradeAck(unsigned short MsgNum,unsigned short ackliushui,unsigned char result);
  117. void PacketConvertTest(void);
  118. void PacketDeConvertTest(void);
  119. int CheckPacket(unsigned char *pData,unsigned short DataLen,unsigned short *);
  120. unsigned short crc16Check(unsigned short initValue,unsigned char *pBuf,int i);
  121. //-------------------------------------------------------------------------------
  122. #include "plyRec.h"
  123. #define MAX_SUB_PACKET_NUM MAX_FRAMS_PCM_DATA/(MAX_USER_DATA_SIZE/2) //上传下载最大分包数,48K总数量最大量,我们按每包最大的MAX_USER_DATA_SIZE算,直接除去2,预算最大,实际没这么大
  124. typedef struct{
  125. unsigned char packetindex;
  126. unsigned short packetlen;
  127. unsigned char *packetdata;
  128. }PACKET_DEF;
  129. typedef struct{
  130. unsigned char packetnum;
  131. PACKET_DEF pInfo[MAX_SUB_PACKET_NUM];
  132. }PACKETLIST_DEF;
  133. typedef struct{
  134. unsigned char packetindex;
  135. unsigned short packetlen;
  136. }PACKET2_DEF;
  137. unsigned int getOverBytes(void);
  138. #endif