main.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. * Config.h
  3. *
  4. * Created on: 2019年12月25日
  5. * Author: EasonYang
  6. */
  7. #ifndef CONFIG_MAIN_H_
  8. #define CONFIG_MAIN_H_
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/time.h>
  12. #include <sys/timeb.h>
  13. #include <sys/types.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/socket.h>
  16. #include <sys/ipc.h>
  17. #include <sys/shm.h>
  18. #include <sys/mman.h>
  19. #include <linux/wireless.h>
  20. #include <arpa/inet.h>
  21. #include <netinet/in.h>
  22. #include <dirent.h>
  23. #include <unistd.h>
  24. #include <stdarg.h>
  25. #include <stdio.h> /*標準輸入輸出定義*/
  26. #include <stdlib.h> /*標準函數庫定義*/
  27. #include <unistd.h> /*Unix 標準函數定義*/
  28. #include <fcntl.h> /*檔控制定義*/
  29. #include <termios.h> /*PPSIX 終端控制定義*/
  30. #include <errno.h> /*錯誤號定義*/
  31. #include <errno.h>
  32. #include <string.h>
  33. #include <time.h>
  34. #include <ctype.h>
  35. #include <ifaddrs.h>
  36. #include <stdbool.h>
  37. #include <stddef.h>
  38. #include <stdint.h>
  39. //==========================
  40. // Define system mode constant
  41. //==========================
  42. #define MODE_BOOTING 0
  43. #define MODE_IDLE 1
  44. #define MODE_AUTHORIZING 2
  45. #define MODE_PREPARING 3
  46. #define MODE_CHARGING 4
  47. #define MODE_TERMINATING 5
  48. #define MODE_ALARM 6
  49. #define MODE_FAULT 7
  50. #define MODE_RESERVATION 8
  51. #define MODE_BOOKING 9
  52. #define MODE_MAINTAIN 10
  53. #define MODE_DEBUG 11
  54. //===================================
  55. // Define CP State constant
  56. //===================================
  57. #define CP_STATE_UNKNOWN 0
  58. #define CP_STATE_A 1
  59. #define CP_STATE_B 2
  60. #define CP_STATE_C 3
  61. #define CP_STATE_D 4
  62. #define CP_STATE_E 5
  63. #define CP_STATE_F 6
  64. //===================================
  65. // Define start mode constant
  66. //===================================
  67. #define START_METHOD_MANUAL 0
  68. #define START_METHOD_RFID 1
  69. #define START_METHOD_BACKEND 2
  70. #define START_METHOD_BLE 3
  71. //===================================
  72. // Define Speaker type constant
  73. //===================================
  74. #define SPEAKER_STOP 0
  75. #define SPEAKER_ALWAYS_ON 1
  76. #define SPEAKER_SHORT 2
  77. #define SPEAKER_LONG 3
  78. #define SPEAKER_INTERVAL_SHORT 4
  79. #define SPEAKER_INTERVAL_LONG 5
  80. #define SPEAKER_INTERVAL_3COUNT 6
  81. //===================================
  82. // Define Alarm code constant
  83. //===================================
  84. #define ALARM_OVER_VOLTAGE 0x000001
  85. #define ALARM_UNDER_VOLTAGE 0x000002
  86. #define ALARM_OVER_CURRENT 0x000004
  87. #define ALARM_OVER_TEMPERATURE 0x000008
  88. #define ALARM_GROUND_FAIL 0x000010
  89. #define ALARM_CP_ERROR 0x000020
  90. #define ALARM_CURRENT_LEAK_AC 0x000040
  91. #define ALARM_CURRENT_LEAK_DC 0x000080
  92. #define ALARM_MCU_TESTFAIL 0x000100
  93. #define ALARM_HANDSHAKE_TIMEOUT 0x000200
  94. #define ALARM_EMERGENCY_STOP 0x000400
  95. #define ALARM_RELAY_STATUS 0x000800
  96. #define ALARM_LEAK_MODULE_FAIL 0x001000
  97. #define ALARM_SHUTTER_FAULT 0x002000
  98. #define ALARM_LOCKER_FAULT 0x004000
  99. #define ALARM_POWER_DROP 0x008000
  100. #define ALARM_CIRCUIT_SHORT 0x010000
  101. #define ALARM_ROTATORY_SWITCH_FAULT 0x020000
  102. #define ALARM_RELAY_DRIVE_FAULT 0x040000
  103. //===================================
  104. // Define Led constant
  105. //===================================
  106. #define LED_ACTION_INIT 0
  107. #define LED_ACTION_IDLE 1
  108. #define LED_ACTION_AUTHED 2
  109. #define LED_ACTION_CONNECTED 3
  110. #define LED_ACTION_CHARGING 4
  111. #define LED_ACTION_STOP 5
  112. #define LED_ACTION_ALARM 6
  113. #define LED_ACTION_MAINTAIN 7
  114. #define LED_ACTION_RFID_PASS 8
  115. #define LED_ACTION_RFID_FAIL 9
  116. #define LED_ACTION_BLE_CONNECT 10
  117. #define LED_ACTION_BLE_DISABLE 11
  118. #define LED_ACTION_DEBUG 12
  119. #define LED_ACTION_ALL_OFF 13
  120. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  121. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  122. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  123. extern int StoreLogMsg(const char *fmt, ...);
  124. //============================================================
  125. // Private shared memory key define
  126. //============================================================
  127. #define ShmChargerKey 2001
  128. typedef struct Verion
  129. {
  130. char Version_FW[32];
  131. char Version_HW[32];
  132. }Ver;
  133. typedef struct PRESENTINPUTVOLTAGE
  134. {
  135. unsigned char inputType; // 0x00: Line to Line 0x01: Line to Neutral
  136. double L1N_L12;
  137. double L2N_L23;
  138. double L3N_L31;
  139. }PresentInputVoltage;
  140. typedef struct PRESENTOUTPUTVOLTAGE
  141. {
  142. double behindFuse_Voltage_C1;
  143. double behindRelay_Voltage_C1;
  144. double behindFuse_Voltage_C2;
  145. double behindRelay_Voltage_C2;
  146. }PresentOutputVoltage;
  147. typedef struct FANSPEED
  148. {
  149. unsigned short int speed[4];
  150. }FanSpeed;
  151. typedef struct TEMPERATURE
  152. {
  153. unsigned char point[8];
  154. }Temperature;
  155. typedef struct AUXPOWER
  156. {
  157. unsigned char voltage[8];
  158. }AuxPower;
  159. typedef struct RELAY
  160. {
  161. unsigned char relay_status[2][8];
  162. }Relay;
  163. typedef struct GFD
  164. {
  165. unsigned short int adc_value_positive[2];
  166. unsigned short int adc_value_negative[2];
  167. }Gfd;
  168. typedef struct GPIO_IN
  169. {
  170. unsigned char AC_Connector;
  171. unsigned char AC_MainBreaker;
  172. unsigned char SPD;
  173. unsigned char Door_Open;
  174. unsigned char GFD[2];
  175. unsigned char Button[2];
  176. unsigned char Button_Emergency;
  177. }Gpio_in;
  178. typedef struct GPIO_OUT
  179. {
  180. unsigned char AC_Connector;
  181. unsigned char Button_LED[2];
  182. unsigned char System_LED[4];
  183. }Gpio_out;
  184. typedef struct ALARM_LOG
  185. {
  186. unsigned char logArea;
  187. unsigned int alarmIndex;
  188. unsigned char log[8];
  189. }Alarm_Log;
  190. typedef struct BLE_CONFIG_DATA
  191. {
  192. unsigned char isLogin:1;
  193. unsigned char isRequestStart:1;
  194. unsigned char isRequestStop:1;
  195. }Ble_Config_Data;
  196. typedef struct BLE_LONGIN_CENTRAL_ID
  197. {
  198. unsigned char id[32];
  199. }Ble_Login_Central_Id;
  200. typedef struct RTC
  201. {
  202. unsigned short int year;
  203. unsigned char month;
  204. unsigned char day;
  205. unsigned char hour;
  206. unsigned char min;
  207. unsigned char sec;
  208. }Rtc;
  209. typedef struct PRESENTOUTPUTCURRENT
  210. {
  211. double L1N_L12[2];
  212. double L2N_L23[2];
  213. double L3N_L31[2];
  214. }Presentoutputcurrent;
  215. typedef struct AC_PRIMARY_MCU
  216. {
  217. unsigned char cp_state;
  218. unsigned int current_limit;
  219. unsigned int cp_voltage_positive;
  220. unsigned int cp_voltage_negtive;
  221. unsigned char locker_state;
  222. unsigned char relay_state;
  223. unsigned char shutter_state;
  224. unsigned char meter_state;
  225. unsigned char pp_state;
  226. unsigned char rating_current;
  227. }Ac_Primary_Mcu;
  228. typedef struct AC_PRIMARY_MCU_ALARM
  229. {
  230. union
  231. {
  232. unsigned long InputAlarmCode;
  233. struct
  234. {
  235. unsigned long OVP:1;
  236. unsigned long UVP:1;
  237. unsigned long OCP:1;
  238. unsigned long OTP:1;
  239. unsigned long gmi_fault:1;
  240. unsigned long cp_fault:1;
  241. unsigned long ac_leak:1;
  242. unsigned long dc_leak:1;
  243. unsigned long mcu_selftest_fail:1;
  244. unsigned long handshaking_timeout:1;
  245. unsigned long emergency_stop:1;
  246. unsigned long relay_welding:1;
  247. unsigned long leak_module_fail:1;
  248. unsigned long shutter_fault:1;
  249. unsigned long locker_fault:1;
  250. unsigned long power_drop:1;
  251. unsigned long circuit_short:1;
  252. unsigned long set_circuit:1;
  253. unsigned long relay_drive_fault:1;
  254. unsigned long comm_timeout:1;
  255. }bits;
  256. };
  257. }Ac_Primary_Mcu_Alarm;
  258. typedef struct AC_PRIMARY_MCU_LED
  259. {
  260. unsigned char mode;
  261. unsigned long alarm_code;
  262. }Ac_Primary_Mcu_Led;
  263. typedef struct EVSE_ID
  264. {
  265. unsigned char model_name[14];
  266. unsigned char serial_number[12];
  267. }Evse_Id;
  268. typedef struct AC_PRIMARY_MCU_CP_PWM_DUTY
  269. {
  270. unsigned int max_current;
  271. }Ac_Primary_Mcu_Cp_Pwm_Duty;
  272. typedef struct LEGACY_REQUEST
  273. {
  274. unsigned char isLegacyRequest:1;
  275. }Legacy_Request;
  276. typedef struct POWER_CONSUMPTION
  277. {
  278. uint32_t power_consumption;
  279. }Power_Consumption;
  280. typedef struct MCU_OP_FLAG
  281. {
  282. unsigned char isSetModePass:1;
  283. unsigned char isSetSerialNumberPass:1;
  284. unsigned char isSetModelNamePass:1;
  285. unsigned char isReadFwVerPass:1;
  286. unsigned char isMcuUpgradeReq:1;
  287. }Mcu_Op_Flag;
  288. typedef struct SYSTEM_ALARM_CODE
  289. {
  290. unsigned long SystemAlarmCode;
  291. }System_Alarm_Code;
  292. typedef struct OTHER_ALARM_CODE
  293. {
  294. unsigned char isMcuSelfTest:1;
  295. unsigned char isCurrentShort:1;
  296. unsigned char isLeakageModule:1;
  297. unsigned char isShutter:1;
  298. unsigned char isLocker:1;
  299. unsigned char isRotatorySwitchr:1;
  300. unsigned char isPowerDrop:1;
  301. unsigned char isOverCurrent:1;
  302. unsigned char isHandshakingTimeOut:1;
  303. unsigned char HandShakingAlarmRequest:1;
  304. }Other_Alarm_Code;
  305. typedef struct PILOT_VOLTAGE
  306. {
  307. float PilotVoltagePositive;
  308. float PilotVoltageNegative;
  309. }Pilot_Voltage;
  310. typedef struct FW_UPGRADE_INFO
  311. {
  312. int fwType;
  313. char modelName[17];
  314. char location[384];
  315. }Fw_Upgrade_Info;
  316. typedef struct GUN_INFO
  317. {
  318. Ver ver;
  319. PresentInputVoltage inputVoltage;
  320. Presentoutputcurrent outputCurrent;
  321. Temperature temperature;
  322. Ble_Config_Data bleConfigData;
  323. Ble_Login_Central_Id bleLoginCentralId;
  324. Rtc rtc;
  325. Ac_Primary_Mcu primaryMcuState;
  326. Ac_Primary_Mcu_Alarm primaryMcuAlarm;
  327. Ac_Primary_Mcu_Led primaryMcuLed;
  328. Mcu_Op_Flag mcuFlag;
  329. Power_Consumption powerConsumption;
  330. Legacy_Request legacyRequest;
  331. System_Alarm_Code systemAlarmCode;
  332. Ac_Primary_Mcu_Cp_Pwm_Duty primaryMcuCp_Pwn_Duty;
  333. Other_Alarm_Code otherAlarmCode;
  334. Pilot_Voltage PilotVoltage;
  335. }Gun_Info;
  336. struct Charger
  337. {
  338. Ver ver;
  339. Evse_Id evseId;
  340. Gun_Info gun_info[2];
  341. Fw_Upgrade_Info fwUpgradeInfo;
  342. unsigned char rfidReq:1;
  343. unsigned char speaker_type;
  344. unsigned char isSpeakerOn:1;
  345. };
  346. #endif /* CONFIG_MAIN_H_ */