TSGpsProcess.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #ifndef TSGPS_PROCESS_H
  2. #define TSGPS_PROCESS_H
  3. /******************************************************************************/
  4. #define TSGPS_PACK_HEAD 0x7e
  5. #define TSGPS_PACK_END 0x7e
  6. /***终端通用应答***/
  7. #define TS_TERMINAL_UNIVERSAL_ANSWER 0x0001
  8. //平台通用应答
  9. #define TS_PLATFORM_UNIVERSAL_ANSWER 0x8001
  10. //终端心跳
  11. #define TS_TERMINAL_HEARTBEAT 0x0002
  12. //分包
  13. #define TS_SUBCONTRACTPACKET 0x8003
  14. //终端注册
  15. #define TS_TERMINAL_REGISTRATION 0X0100
  16. //终端注册应答
  17. #define TS_TERMINAL_REGISTRATION_REPLY 0X8100
  18. //终端注销
  19. #define TS_TERMINAL_CANCELLATION 0x0003
  20. //终端鉴权
  21. #define TS_TERMINAL_AUTHENTICATION 0x0102
  22. //设置终端参数
  23. #define TS_SETTING_TERMINAL_PARAMETERS 0x8103
  24. //查询终端参数
  25. #define TS_QUERY_TERMINAL_PARAMETERS 0x8104
  26. //查询终端参数应答
  27. #define TS_QUERY_PARAMETER_RESPONSE_TERMINAL 0x0104
  28. //终端控制
  29. #define TS_TERMINAL_CONTROL 0x8105
  30. //位置信息汇报
  31. #define TS_LOCATION_INFORMATION_REPORTING 0x0200
  32. //位置信息查询
  33. #define TS_LOCATION_INFORMATION_INQUIRY 0x8201
  34. //位置信息查询应答
  35. #define TS_LOCATION_INFORMATION_INQUIRY_RESPONSE 0x0201
  36. //临时位置跟踪控制
  37. #define TS_PROVISIONAL_INFORMATION_TRACKING_CONTROL 0x8202
  38. //文本信息下发
  39. #define TS_TEXT_INFORMATION_ISSUED 0x8300
  40. //事件设置
  41. #define TS_EVENT_SETTINGS 0x8301
  42. //事件报告
  43. #define TS_EVENT_REPORT 0x0301
  44. //提问下发
  45. #define TS_QUESTION_ISSUED 0x8302
  46. //提问应答
  47. #define TS_QUESTION_ANSWER 0x0302
  48. //信息点播菜单设置
  49. #define TS_INFORMATION_ON_DEMAND_MENU_SETTINGS 0x8303
  50. //信息点播/取消
  51. #define TS_INFORMATION_ON_DEMAND_CANCELLATIONS 0x0303
  52. //信息服务
  53. #define TS_INFORMATION_SERVICES 0x8304
  54. //电话回拨
  55. #define TS_CALL_BACK 0x8400
  56. //设置电话本
  57. #define TS_SET_THE_PHONE_BOOK 0x8401
  58. //车辆控制
  59. #define TS_THE_VEHICLE_CONTROL 0x8500
  60. //车辆控制应答
  61. #define TS_VEHICLE_CONTROL_RESPONSES 0x0500
  62. //设置圆形区域
  63. #define TS_SET_CIRCULAR_AREA 0x8600
  64. //删除圆形区域
  65. #define TS_REMOVE_CIRCULAR_AREA 0x8601
  66. //设置矩形区域
  67. #define TS_SETTING_RECTANGULAR_AREA 0x8602
  68. //删除矩形区域
  69. #define TS_DELETE_RECTANGULAR_AREA 0x8603
  70. //设置多边形区域
  71. #define TS_SET_POLYGON_AREA 0x8604
  72. //删除多边形区域
  73. #define TS_DELETE_POLYGON_AREA 0x8605
  74. //设置线路
  75. #define TS_SET_LINE 0x8606
  76. //删除线路
  77. #define TS_DELETE_SET_LINE 0x8607
  78. //行驶记录数据采集命令
  79. #define TS_WITH_RECORD_DATA_COLLECTION 0x8700
  80. //行驶记录数据上传
  81. #define TS_WITH_RECORDING_DATA_UPLOAD 0x0700
  82. //行驶记录参数下传
  83. #define TS_WITH_RECORDING_DATA_DOWNLINK 0x8101
  84. //电子运单上报
  85. #define TS_ELECTRONIC_WAYBILL_REPORTED 0x0701
  86. //驾驶员身份信息采集上报
  87. #define TS_DRIVER_IDENTITY_DATA_COLLECTION 0x0702
  88. //多媒体事件信息上传
  89. #define TS_MULTIMEDIA_EVENT_UPLOAD 0x0800
  90. //多媒体数据上传
  91. #define TS_MULTIMEDIA_DATA_UPLOAD 0x0801
  92. //多媒体数据上传应答
  93. #define TS_MULTIMEDIA_DATA_UPLOAD_REPLY 0x8800
  94. //摄像头立即拍摄命令
  95. #define TS_CAMERA_IMMEDIATELY_SHOOTING_COMMAND 0x8801
  96. //存储多媒体数据检索
  97. #define TS_STORING_MULTIMEDIA_DATA_RETRIEVAL 0x8802
  98. //存储多媒体数据检索应答
  99. #define TS_STORING_MULTIMEDIA_DATA_RETRIEVAL_RESPONSE 0x0802
  100. //存储多媒体数据上传命令
  101. #define TS_STORING_MULTIMEDIA_DATA_UPLOAD_COMMAND 0x8803
  102. //录音开始命令
  103. #define TS_RECORDING_START_COMMAND 0x8804
  104. //数据下行透传
  105. #define TS_DOWNLINK_DATA_PASSTHROUGH 0x8900
  106. //数据上行透传
  107. #define TS_UPLINK_DATA_PASSTHROUGH 0x0900
  108. //数据压缩上报
  109. #define TS_DATA_COMPRESSION_REPORTING 0x0901
  110. //平台RSA公钥
  111. #define TS_PLATFORM_RSA_PUBLIC_KEY 0x8A00
  112. //终端RSA公钥
  113. #define TS_TERMINAL_RSA_PUBLIC_KEY 0x0A00
  114. // 终端属性上报
  115. #define TS_TERMINAL_ATTRIBUTEINFO_ANSWER 0x0107
  116. // 平台主动查询终端属性
  117. #define TS_PLATFORM_ATTRIBUTEINFO_ANSWER 0x8107
  118. //保留自定义
  119. //终端上传SOS消息
  120. #define TS_SEND_SOS_SMS 0x0F01
  121. #define TS_TERMINAL_REQTIME 0x0F02
  122. #define TS_PROID 0x44//省ID取前两位 440000
  123. #define TS_CITYID 0x0300//市ID取后四位440300
  124. #define PLATE 0x0100000000000000
  125. #define MANUFACTURERS 3431303030
  126. /***********************************
  127. *typedef unsigned int (*Xingan_process_packet)(unsigned char *p_buf,unsigned short size);
  128. typedef struct XinganCmd_struct
  129. {
  130. unsigned int cmd;
  131. Xingan_process_packet process_packet;
  132. }XinganCmd_struct;
  133. ************************************/
  134. typedef unsigned int (*TSGPS_process_packet)(unsigned char *p_buf,unsigned short size);
  135. typedef struct TSCmd_struct
  136. {
  137. unsigned int cmd;
  138. TSGPS_process_packet process_packet;
  139. }TSCmd_struct;
  140. /***************************************************************
  141. 7E 标示位
  142. 0100 消息id
  143. 002D 消息属性
  144. 015512341234 手机号
  145. 0001 002C 01303431303030323031 3430 3400 0000000000 0000000000000000 30303030313131
  146. 01 车牌颜色
  147. GBK 采用双子节
  148. D4C1423738583134 车牌号
  149. 3A 校验码
  150. 7E 标示位
  151. ****************************************************************/
  152. typedef unsigned char BYTE;
  153. typedef unsigned short WORD;
  154. typedef unsigned long DWORD;
  155. typedef unsigned int BOOL;
  156. //对应string类型
  157. typedef struct STRING{
  158. BYTE number[64];
  159. short size;
  160. }STRING;
  161. //数据包封装项
  162. typedef struct msgPacket{
  163. WORD msgTotalCount;//总数 16byte
  164. WORD msgPacketID; //包序号16byte
  165. }MSG_PACKET;
  166. typedef enum ENCRYPTYPE1{NO_ENCRYP=0,RSA=1}ENCRYPTYPE;
  167. typedef struct msgBodyAttrib{
  168. BOOL bSepartePack;//是否分包
  169. ENCRYPTYPE EncrypType; //加密
  170. int msgBodyLength; //消息长度
  171. }AVL_MSG_BODY_ATTRIB;
  172. typedef struct msgHead{
  173. WORD msgID;//ID 16byte
  174. WORD msgBodyAttrib; //消息体属性16byte
  175. WORD msgSimCard[6]; //电话号码
  176. WORD msgNum; //消息流水号
  177. WORD msgPacket; //封包项 包封装
  178. }MSG_HEAD;
  179. /******************************
  180. *3431303030制作商ID
  181. 3230313430340000000000000000000000000000终端型号
  182. 30303030313131 终端ID
  183. 颜色:
  184. 1 蓝
  185. 4 白
  186. 2 黄
  187. 9 其他
  188. 3 黑
  189. *********************************/
  190. typedef struct registration{
  191. WORD proID;//省域ID 16byte
  192. WORD CityID; //市域ID16byte
  193. BYTE Manufacturers[5]; //制造商
  194. BYTE TerMod[20]; //终端型号 不足补0x00
  195. BYTE TerID[7]; //终端ID 不足补0x00 本来7个字节 为了跟星安一致 取4个字节
  196. BYTE PlateColor; //车牌颜色 未上牌取值为0
  197. // STRING Plate; //车牌
  198. BYTE Plate[8];//WORD 8
  199. }REGISTRATION;
  200. //鉴权
  201. //有个问题 如果收到数据里面有7E或者7D数据会相应边长但是幸运的是鉴权都是日期时间
  202. typedef struct Auth{
  203. BYTE auth[7];
  204. }AUTH;
  205. //SIM卡号
  206. typedef struct Sim{
  207. BYTE SIM[6];
  208. }SIM;
  209. //定位消息ID是0x0200
  210. //起始字节 字段 数据格式 描述
  211. //0 报警标志 DWORD
  212. //1 状态 DWORD
  213. //8 纬度 DWORD 以度为单位的纬度乘以10的6次方 精确到百万分之一抖�
  214. //12 经度 DWORD 同纬度
  215. //16 高程 WORD 海拔高度,单位(m)
  216. //18 速度 WORD 1/10km/h
  217. //20 方向 WORD 0-359, 0,
  218. //21 时间 BCD[6] YY-MM-DD-hh-mm-ss(GMT+8 时间 )
  219. //详细参考文档22页
  220. typedef struct SUT_GPS_SEND_DATA{
  221. // unsigned int St;//报警 int
  222. // unsigned int status; //状态 int
  223. // unsigned int WWWW;//4
  224. // unsigned int JJJJ;//经纬度4
  225. // unsigned short Mileag;//高度 里程 2
  226. // unsigned char SSFF;//速度 方位角 2 做在一起
  227. // unsigned char Acpect;//速度 方位角 1 做在一起
  228. // unsigned char Time[6];// 时间
  229. unsigned int St;
  230. unsigned int status;
  231. unsigned char WWWW[4];
  232. unsigned char JJJJ[4];
  233. unsigned short Mileag;
  234. unsigned short SSFF;
  235. unsigned short Acpect;
  236. unsigned char Time[6];
  237. }__attribute__((packed)) SUT_GPS_SEND_DATA;//__attribute__((packed))
  238. typedef struct SUT_LCDGPS_SEND_DATA
  239. {
  240. unsigned char WWWW[4];
  241. unsigned char JJJJ[4];
  242. unsigned int W;
  243. unsigned int j;
  244. }SUT_LCDGPS_SEND_DATA;
  245. extern MSG_PACKET msgPacket;
  246. extern AVL_MSG_BODY_ATTRIB msgBodyAttrib;
  247. extern MSG_HEAD msghead;
  248. extern REGISTRATION Regist;
  249. extern SUT_GPS_SEND_DATA sutGpsSendData;
  250. extern SUT_LCDGPS_SEND_DATA sutLcdGpsSendData;
  251. void TSGpsDataInit(void);
  252. void TSGPS_GPRMC_Alysis(char *RMC_Data);
  253. void TSMakeGpsSendData(void);
  254. void TSGpsServerConect(void);
  255. void TSGpsSendData(void);
  256. int TSGpsPacket(unsigned char *Buffer,unsigned long PSN,unsigned short ID,unsigned char *pData,int DataLen);
  257. unsigned char TSGpsServerCheckPack(unsigned char *data,unsigned short DataLen);
  258. void TSGpsTimingSendPos(void);
  259. unsigned char TSGpsServerProcess(unsigned char *data, unsigned short DataLen);
  260. int reduce(unsigned char *pData,int DataLen);
  261. int escapse(unsigned char *pData,int DataLen);
  262. void Registration(void);
  263. void RegistrationLogout(void);
  264. void Authentication(void);
  265. int DectoBCD(int Dec, unsigned char *Bcd, int length);
  266. void getData(void);
  267. void TSRegData(void);
  268. void SIMReg(void);
  269. void TS_SendHeartTick(void);
  270. void TS_SendSOSMessage(void);
  271. void TS_ReqRealTime(void);
  272. void buBiaoICCID(unsigned char socketID);
  273. /********************************************************************************/
  274. #endif // GPS_STRUCT_H