DoComm.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #ifndef _DO_COMM_H_
  2. #define _DO_COMM_H_
  3. //------------------------------------------------------------------------------
  4. #include <stdint.h>
  5. //------------------------------------------------------------------------------
  6. //--- common define ---
  7. //------------------------------------------------------------------------------
  8. #define CMP_ETH_IP_HEAD "192.168.100"
  9. #define DoIPAddress "192.168.100.1"
  10. #define DoTcpPort 36000
  11. #define IMAGE_FILE_PATH "../mnt"
  12. #define TFTP_PULL_CMD "tftp"
  13. #define SIGTERM_MSG "SegmentFault.~~~~\n"
  14. #define MAX_REGISTER_NUM 45
  15. #define CHECK_NETWORK_FAIL_COUNT 10//10
  16. #define CONNECT_SERVER_FAIL_COUNT 3//5
  17. #define WARNING_CODE_SIZE 6
  18. #define MAX_VOLTAGE 10000
  19. #define MAX_CURRENCY 5000
  20. #define MAX_POWER 3600
  21. #define DISPENSER_INIT_SUCC 0x01
  22. #define DISPENER_INIT_FAIL 0x02
  23. #define DISPENSER_SOCKET_RECONN 0x03
  24. #define VERSION_BUF_SIZE 32
  25. #define PRICES_UNIT 0.01
  26. #define LOOP_RETRY_TIME 1000 //1 second
  27. //------------------------------------------------------------------------------
  28. //--- dispenser ID ---
  29. //------------------------------------------------------------------------------
  30. #define ID_RESERVER 0x00
  31. #define ID_OF_DISPENSER 0x01
  32. #define ID_REGISTER 0xFF
  33. //------------------------------------------------------------------------------
  34. //--- dispenser operation ---
  35. //------------------------------------------------------------------------------
  36. #define OP_READ_DATA 0x01
  37. #define OP_WRITE_DATA 0x02
  38. #define OP_WAIT_RESPONSE 0x03
  39. //------------------------------------------------------------------------------
  40. //--- connector status ---
  41. //------------------------------------------------------------------------------
  42. #define CONN_ST_IDLE 0x00
  43. #define CONN_ST_PREPARING 0x01
  44. #define CONN_ST_CHARGING 0x02
  45. #define CONN_ST_TERMINATING 0x03
  46. #define CONN_ST_ALARM 0x04
  47. //------------------------------------------------------------------------------
  48. //--- dispenser register ---
  49. //------------------------------------------------------------------------------
  50. #define REG_MODEL_NAME 0x01
  51. #define REG_CONNECTOR_ID 0x02
  52. #define REG_POWER_CABINET_STATUS 0x03
  53. #define REG_DISPENSER_STATUS 0x04
  54. #define REG_CHARGING_CAP 0x05
  55. #define REG_CHARGING_TARGET 0x06
  56. #define REG_SOFTWARE_UPDATE 0x07
  57. #define REG_PLUG_IN_STATE 0x08
  58. #define REG_CONNECTOR_STATE 0x09
  59. #define REG_USER_ID 0x0A
  60. #define REG_CHARGING_PERMISSION 0x0B
  61. #define REG_MISC_CONTROL 0X0C
  62. #define REG_REPORT_CSU_VERSION 0X0D
  63. #define REG_REPORT_OTHER_VERSION 0X0E
  64. #define REG_PRESENT_CHARGING_INFO 0X0F
  65. #define REG_QRCODE_URL_INFO 0X10
  66. #define REG_WAIT_PLUG_IT_STATE 0x11
  67. #define REG_Ground_Fault_Detection 0x12
  68. #define REG_CABINET_DCM_VERSION 0x13
  69. #define REG_CABINET_OTHER_VERSION 0x14
  70. #define REG_TOTAL_PSU_QUANTITY 0x15
  71. #define REG_PSU_VERSION 0x16
  72. #define REG_RESERVATION_IDTAG 0x17
  73. #define REG_DISPENSER_REQUEST 0x18
  74. #define REG_REMOTE_START_NO_ID 0x19
  75. #define REG_REFUND_AMOUNT 0x1A
  76. #define REG_PREPAYMENT_INFO 0x1B
  77. #define REG_PAYMENT_FAIL_REASON 0x1C
  78. #define REG_CONNECTOR_QR_CODE 0x1D
  79. #define REG_STATION_INFO 0x1E
  80. #define REG_DEDUCT_INFO 0x1F
  81. #define REG_READ_CABINET_SYSTEMID 0x20
  82. #define REG_READ_DEFAULT_PRICE 0x21
  83. #define REG_READ_USER_PRICE 0x22
  84. #define REG_RECEIPT_INFO 0x23
  85. #define REG_POWER_CONSUMPTION_INFO 0x24
  86. #define REG_READ_CHARGING_TIMESTAMP 0x25
  87. #define REG_CHARGING_BILL 0x26
  88. #define REG_PARKING_STATUS 0x27
  89. #define REG_PARKING_BILL 0x28
  90. //------------------------------------------------------------------------------
  91. //--- dispenser result ---
  92. //------------------------------------------------------------------------------
  93. #define COMMAND_RESULT_OK 0x01
  94. #define COMMAND_RESULT_NG 0x02 //wait state
  95. //------------------------------------------------------------------------------
  96. //--- power cabinet misc status code ---
  97. //------------------------------------------------------------------------------
  98. #define MISC_ST_MISC_CMD "B40001"
  99. #define MISC_ST_VERSION "B40999"
  100. //------------------------------------------------------------------------------
  101. //--- power cabinet misc command ---
  102. //------------------------------------------------------------------------------
  103. #define MISC_CMD_CONNECOTOR_TIMEOUT (0X0001)
  104. #define MISC_CMD_OPERATIVE_STATE (0X0002)
  105. #define MISC_CMD_DEFAULT_PRICES (0x0003)
  106. #define MISC_CMD_DEFAULT_CURRENCY (0x0004)
  107. #define MISC_CMD_ACCOUNT_BALANCE (0x0005)
  108. #define MISC_CMD_BACKEND_STATUS (0x0006)
  109. #define MISC_CMD_ETHERNET_STATUS (0x0007)
  110. #define MISC_CMD_WIFI_STATUS (0x0008)
  111. #define MISC_CMD_4G_STATUS (0x0009)
  112. #define MISC_CMD_BILLING_INFO (0x000A)
  113. #define MISC_CMD_WEB_STOP_CHARGING (0x000B)
  114. #define MISC_CMD_AUTH_DISABLE (0x000C)
  115. #define MISC_CMD_EVCCID_ENABLE (0x000D)
  116. #define MISC_CMD_LED_INTENSITY (0x000E)
  117. #define MISC_CMD_AC_CONTACTOR (0x000F)
  118. #define MISC_CMD_TIME_OFFSET (0x0010)
  119. #define MISC_CMD_PAKING_PRICES (0x0011)
  120. #define MISC_CMD_RFID_ENDIAN (0x0012)
  121. #define MISC_CMD_HARDWARE_REBOOT (0x0101)
  122. #define MISC_CMD_SOFTWARE_RESTART (0x0102)
  123. #define MISC_CMD_REMOTE_START_CHARGING (0x0103)
  124. #define MISC_CMD_REMOTE_STOP_CHARGING (0x0104)
  125. #define MISC_CMD_REMOTE_UNLOCK (0x0105)
  126. #define MISC_CMD_RESERVATION (0x0106)
  127. #define MISC_CMD_CHANGE_LCM_PAGE (0x0107)
  128. #define MISC_CMD_QR_CODE_REQ (0x0108)
  129. #define MISC_CMD_STATION_INFO_REQ (0x0109)
  130. #define MISC_CMD_FINAL_COST_REQ (0x010A)
  131. #define MISC_CMD_LINE_STATUS_REQ (0x010B)
  132. #define MISC_CMD_DEFAULT_PRICE_REQ (0x010C)
  133. #define MISC_CMD_USER_PRICE_REQ (0x010D)
  134. #define MISC_CMD_RECEIPT_REQ (0x010E)
  135. #define MISC_CMD_CHARGING_BILL (0x010F)
  136. #define MISC_CMD_PARKING_STATUS (0x0110)
  137. #define ST_UPDATE_FIRMWARE (0x01)
  138. #define ST_NO_UPDATE_FIRMWARE (0x02)
  139. #define LCM_PAGE_REMOTE_START_NO_ID (0x0001)
  140. #define DISPENSER_REQ_CHARGING_CANCEL (0x0001)
  141. #define DISPENSER_REQ_PARKING_BILL (0x0002)
  142. #define UPLOAD_DEDUCT_DB (0x5656)
  143. //------------------------------------------------------------------------------
  144. #pragma pack(push)
  145. #pragma pack(1)
  146. typedef union
  147. {
  148. unsigned int Value;
  149. struct
  150. {
  151. unsigned int ChargingCancel : 1; // 0: no effect, 1: charging cancel request
  152. unsigned int ParkingBillReq : 1; // 0: no effect, 1: Parking Bill Request
  153. unsigned int res : 30;
  154. }bits;
  155. } ConnectorActReqVar;
  156. typedef struct StDeductInfoVar {
  157. unsigned char DeductResult; // 0: Fail, 1: Pass
  158. unsigned char IsDonateInvoice; // 0: Do not donate, 1: Donate
  159. int TransactionId; // transaction id
  160. int Amount; // unit = 0.01 dollar
  161. char ApprovalNumber[12]; // approval number
  162. } DeductInfoVar;
  163. /*
  164. typedef union
  165. {
  166. unsigned int Value;
  167. struct
  168. {
  169. unsigned int JoinLine:1; // 0: no effect, 1: JoinLine page is trigger
  170. unsigned int PaymentSwitch:1; // 0: no effect, 1: PaymentSwitch page is trigger
  171. unsigned int res:30;
  172. }bits;
  173. } ChangePageReq;
  174. */
  175. typedef union
  176. {
  177. unsigned int Value;
  178. struct
  179. {
  180. unsigned int ReservationReq:1; // 0: no effect, 1: need to request Reservation
  181. unsigned int RemoteStartNoID:1; // 0: no effect, 1: need to request RemoteStartNoID
  182. unsigned int StationInfoReq:1; // 0: no effect, 1: need to request StationInfo
  183. unsigned int FinalCostReq:1; // 0: no effect, 1: need to request FinalCost
  184. unsigned int ChargingBill:1; // 0: no effect, 1: need to request ChargineBill
  185. unsigned int ParkingReq : 1; // 0: no effect, 1: need to request Parking
  186. unsigned int res:26;
  187. } bits;
  188. } MoreInfoReq;
  189. typedef struct StStationVar {
  190. int StationID;
  191. char StationName[64];
  192. int WeatherID;
  193. float Temperature;
  194. } StationVar;
  195. typedef struct StConnectorState {
  196. uint8_t State;
  197. uint8_t WarningCode[6];
  198. uint8_t ConnectorTemp;
  199. uint8_t ChillerTemp;
  200. uint8_t PlugIn;
  201. uint32_t consumption;
  202. uint8_t ConnectMode;
  203. } ConnectorState;
  204. typedef struct StConnectorIDTable {
  205. uint8_t DcConnID1;
  206. uint8_t DcConnID2;
  207. uint8_t AcConnID;
  208. uint8_t Reserved;
  209. } ConnectorIDTable;
  210. typedef struct StDoCommGlobalVar {
  211. uint8_t SeqNum;
  212. uint8_t DisConnCount;
  213. uint8_t ConnectorID[3]; //keep from power cabinet
  214. uint8_t MiscCmd;
  215. uint8_t Reserved[2];
  216. } DoCommGblData;
  217. typedef struct StCommnadHead {
  218. uint8_t SeqNum; //sequence number 0 ~ 255
  219. uint8_t ID; //0: Reserved, 0x01 ~ 0xFE: connector ID, 0xFF: exists in register 1 and register 2
  220. uint8_t OP; //0x01: read, 0x02: write, 0x03: response from power cabinet
  221. uint8_t DataLen; //raw data Length
  222. } CmdHead;
  223. typedef struct StCommandData {
  224. uint8_t Register; /* 0x01: dispenser model name (maximum 32 bytes) and the value of dispenser switch
  225. 0x02: The ID to connector equipped at dispenser
  226. 0x03: Power cabinet status
  227. 0x04: Dispenser status
  228. 0x05: The charging capacity of each connector
  229. 0x06: The required voltage and current during charging
  230. 0x07: The indicator of software update to dispenser
  231. 0x08: Indicate whether the connector is plug-in or not
  232. 0x09: Indicate the connector state
  233. 0x0A: The user ID can be RFID card number, EVCCID, etc.
  234. 0x0B: Charging permission from power cabinet to dispenser
  235. */
  236. uint8_t Data[250];
  237. } CmdData;
  238. typedef struct StResultData {
  239. uint8_t Register; /* 0x01: dispenser model name (maximum 32 bytes) and the value of dispenser switch
  240. 0x02: The ID to connector equipped at dispenser
  241. 0x03: Power cabinet status
  242. 0x04: Dispenser status
  243. 0x05: The charging capacity of each connector
  244. 0x06: The required voltage and current during charging
  245. 0x07: The indicator of software update to dispenser
  246. 0x08: Indicate whether the connector is plug-in or not
  247. 0x09: Indicate the connector state
  248. 0x0A: The user ID can be RFID card number, EVCCID, etc.
  249. 0x0B: Charging permission from power cabinet to dispenser
  250. */
  251. uint8_t Result;
  252. uint8_t Data[249];
  253. } ResultData;
  254. typedef struct StCsuCmdPkt {
  255. CmdHead Head;
  256. CmdData Data;
  257. } CsuCmdPkt;
  258. typedef struct StCsuResultPkt {
  259. CmdHead Head;
  260. ResultData Data;
  261. } CsuResultPkt;
  262. typedef struct StMiscCommand {
  263. uint16_t CMD;
  264. uint8_t Value[4];
  265. } MiscCommand;
  266. typedef struct StPresentChargingInfo {
  267. uint16_t PresentChargingVoltage; //0~6553.5 volt
  268. uint16_t PresentChargingCurrent; //0~6553.5 amp
  269. int RemainChargingDuration; // second
  270. uint8_t EvBatterySoc; // 0~100%
  271. } PreChargingInfo;
  272. typedef struct StGroundFaultDetection { //Ground Fault Detection
  273. uint8_t Status;
  274. } GroundFaultDetection;
  275. typedef struct StSoftwareUpdInfo {
  276. uint8_t UpdateState; //1:update , 2: not update
  277. uint8_t ImgName[248];
  278. } SoftwareUpdInfo;
  279. typedef struct StCapabilityInfo {
  280. uint16_t OutputVoltage;
  281. uint16_t OutputCurrent;
  282. uint16_t OutputPower;
  283. uint8_t Reserved[2];
  284. } CapabilityInfo;
  285. typedef struct StAccountInfo {
  286. uint8_t Currency;
  287. int UserPrices;
  288. int TotalCost;
  289. int Balance;
  290. int Discount;
  291. int Transaction;
  292. int EnergyCost;
  293. int ParkingFee;
  294. uint32_t RemainAmount;
  295. uint8_t Reserved[1];
  296. } AccountInfo;
  297. typedef struct StChargingBillInfo {
  298. int TotalCost;
  299. int Balance;
  300. int Discount;
  301. int Transaction;
  302. int EnergyCost;
  303. int ParkingFee;
  304. uint32_t RemainAmount;
  305. } ChargingBillInfo;
  306. typedef struct StParkingBillInfo {
  307. int ParkingFee;
  308. int Duration;
  309. } ParkingBillInfo;
  310. #pragma pack(pop)
  311. #endif /* _DO_COMM_H_ */