blob: b8daf7790a0c31edce4f9e81278660b76e7fa609 [file] [log] [blame]
zongqiang.zhang0c6a0882019-08-07 14:48:21 +08001#ifndef _SP_COMMUNICATE_H_
2#define _SP_COMMUNICATE_H_
3
4#include "sp_config.h"
5
6#define PROTOCOL_COMMAND_V2 0x80
7#define PROTOCOL_WITH_MAC(x) ((x) | 0x80)
8#define PROTOCOL_WITHOUT_MAC(x) ((x) & 0x7F)
9#define PROTOCOL_FLAG_PACK(x) ((x) | 0x01)
10#define PROTOCOL_FLAG_DES_PACK(x) ((x) & 0xFE)
11
12#define PK_BIN_DEVPHYID "a"
13#define PK_INT_CARDNO "b"
14#define PK_BIN_CARDVERNO "c"
15#define PK_INT_DEVSEQNO "d"
16#define PK_STR_VERSION "e"
17#define PK_INT_BLKINDEX "f"
18#define PK_BIN_TRANSDATE "g"
19#define PK_BIN_TRANSTIME "h"
20#define PK_INT_PAYAMT "i"
21#define PK_INT_AMOUNT "j"
22#define PK_INT_FLAG "k"
23#define PK_STR_AVAIABLE "l"
24#define PK_BIN_SYSTIME "m"
25#define PK_STR_UPGRADE "n"
26#define PK_BIN_BLKBITMAP "o"
27#define PK_BIN_FILECRC "p"
28#define PK_INT_FILESIZE "q"
29#define PK_INT_SEQNO "r"
30#define PK_BIN_FILEDATA "s"
31#define PK_INT_MAXSEQNO "t"
32#define PK_INT_SECONDS "u"
33#define PK_INT_CREDIT_TOTAL "v"
34#define PK_INT_CREDIT_PAYCNT "w"
35#define PK_INT_CREDIT_AVAILABAL "x"
36#define PK_INT_CREDIT_NO "y"
37#define PK_BIN_EXPIRE "z"
38#define PK_INT_FEETYPE "A"
39#define PK_BIN_CARDPHYID "B"
40#define PK_STR_STATUS "C"
41#define PK_INT_BALANCE "D"
42#define PK_INT_OFFLINE_FORBID_FLAG "E"
43#define PK_INT_CREDIT_PAYCNT_LACK "F"
44#define PK_INT_ONCETIME_LIMIT "G"
45#define PK_INT_DAYTOTAL_LIMIT "H"
46#define PK_INT_COUNT "J"
47#define PK_BIN_BLKLIST "K"
48#define PK_INT_CREDIT_NEXT_NO "L"
49#define PK_BIN_RANDOM "M"
50#define PK_INT_DEVICENO "N"
51#define PK_BIN_DEVTIME "O"
52#define PK_STR_DEVTYPE "P"
53#define PK_BIN_SAMNO "Q"
54#define PK_INT_PARAVERNO "R"
55#define PK_INT_PARA_GROUPID "S"
56#define PK_INT_FEEVERNO "T"
57#define PK_INT_FEE_CFGID "U"
58#define PK_BIN_WSCLIENT_ID "V"
59#define PK_INT_WSCLIENT_STATUS "W"
60#define PK_INT_FLOWSENSORS "X"
61#define PK_BIN_SOFT_MD5 "Y"
62#define PK_INT_CUSTID "Z"
63#define PK_STR_SHORT_URL "0"
64#define PK_INT_WATERSTATUS "1"
65#define PK_INT_WATERMUCH "2"
66
67#define PK_BIN_BILLNO "3"
68#define PK_INT_TRANSWAY "4"
69#define PK_INT_UNTRANSCONST "5"
70#define PK_BIN_DEVICEKEY "6"
71#define PK_INT_WORKMODE "7"
72#define PK_INT_OFFLINEMAXHOUR "8"
73#define PK_INT_PULSEINHML "9"
74#define PK_BIN_CITIZEN_CARDNO "10"
75#define PK_INT_WATERLIMIT "11"
76#define PK_INT_FEEAMOUNT "12"
77#define PK_INT_FEEUNIT "13"
78#define PK_INT_VAILDTIME "14"
79#define PK_INT_AUTHSTATUS "15"
80#define PK_INT_PAYSTATUS "16"
81#define PK_INT_FEESTART "17"
82
83#define SP_CMD_UPGRADE 0x20 //ÔÚÏßÉý¼¶
84#define SP_CMD_TRANSDTL_ACCOUNT 0x22 //¼ÇÕËÁ÷Ë®
85#define SP_CMD_HEARTBEAT 0x24 //ÐÄÌø
86#define SP_CMD_CARD_AUTHENTICATION 0x26 //¿¨ÔÚÏßÈÏÖ¤
87#define SP_CMD_LOGIN 0x2C //怬
88#define SP_CMD_FACTORY_LINK_TEST 0x2E //¹¤³§Á´Â·²âÊÔ
89#define SP_CMD_SHORTURL 0x28 //»ñÈ¡¶þάÂë¶ÌµØÖ·
90#define SP_CMD_QRCODE_PAY_QUERY 0x2A //¶þάÂëÏû·ÑÈ·ÈÏ
91
92#define IS_PUSH_FLOW(cmd) (0x1&(cmd))
93
94#pragma pack(push)
95#pragma pack(1)
96
97typedef struct
98{
99 uint16 datalen;
100 uint8 command;
101 uint8 excmd; // ÇëÇóÃüÁîÒªÇóżÊý
102 uint8 flag;
103 uint8 data[256];
104} sp_protocol_request_t;
105
106typedef struct
107{
108 uint16 datalen;
109 uint8 command;
110 uint8 excmd; // ÇëÇóÃüÁîÒªÇóżÊý
111 uint8 flag;
112 uint8 retcode;
113 uint8 data[256];
114} sp_protocol_response_t;
115
116#pragma pack(pop)
117
118typedef uint8(* protocol_cmd_func_t)(sp_protocol_response_t* resp, sp_pos_t* pos);
119
120typedef struct
121{
122 uint8 cmd;
123 protocol_cmd_func_t func;
124} protocol_cmd_t;
125
126void sp_communicate(sp_pos_t* pos);
127uint16 sp_card_authentication(sp_pos_t* pos, sp_card_t* card);
128uint16 sp_async_equipment_login(sp_pos_t* pos);
129uint16 sp_async_heartbeat(sp_pos_t* pos);
130uint16 sp_async_upload_transdtl(sp_pos_t* pos, sp_transdtl_t* dtl);
131uint16 sp_qrcode_init(sp_pos_t* pos, sp_card_t* card);
132uint16 sp_qrcode_query(sp_pos_t* pos, sp_card_t* card);
133
134//ͨѶ
135uint8 sp_comm_call(sp_pos_t* pos, sp_protocol_request_t* req,
136 sp_protocol_response_t* resp, int32 timeout_ms);
137void sp_protocol_req_init(sp_protocol_request_t* req, uint8 command);
138#endif
139