main.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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 LED_RELAY_ON 14
  121. #define LED_RELAY_OFF 15
  122. #define LED_ACTION_HANDSHAKE_FAIL 16
  123. #define START_METHOD_MANUAL 0
  124. #define START_METHOD_RFID 1
  125. #define START_METHOD_BACKEND 2
  126. #define START_METHOD_BLE 3
  127. #define AUTH_MODE_PH_RFID 0
  128. #define AUTH_MODE_OCPP 1
  129. #define AUTH_MODE_PH_BACKEND 2
  130. #define AUTH_MODE_FREEMODE 3
  131. #define OFF_POLICY_LOCALLIST 0
  132. #define OFF_POLICY_PH_RFID 1
  133. #define OFF_POLICY_FREEMODE 2
  134. #define OFF_POLICY_NOCHARGE 3
  135. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  136. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  137. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  138. extern int StoreLogMsg(const char *fmt, ...);
  139. //============================================================
  140. // Private shared memory key define
  141. //============================================================
  142. #define ShmChargerKey 2001
  143. typedef struct Verion
  144. {
  145. char Version_FW[32];
  146. char Version_HW[32];
  147. }Ver;
  148. typedef struct PRESENTINPUTVOLTAGE
  149. {
  150. unsigned char inputType; // 0x00: Line to Line 0x01: Line to Neutral
  151. double L1N_L12;
  152. double L2N_L23;
  153. double L3N_L31;
  154. }PresentInputVoltage;
  155. typedef struct PRESENTOUTPUTVOLTAGE
  156. {
  157. double behindFuse_Voltage_C1;
  158. double behindRelay_Voltage_C1;
  159. double behindFuse_Voltage_C2;
  160. double behindRelay_Voltage_C2;
  161. }PresentOutputVoltage;
  162. typedef struct FANSPEED
  163. {
  164. unsigned short int speed[4];
  165. }FanSpeed;
  166. typedef struct TEMPERATURE
  167. {
  168. unsigned char point[8];
  169. }Temperature;
  170. typedef struct AUXPOWER
  171. {
  172. unsigned char voltage[8];
  173. }AuxPower;
  174. typedef struct RELAY
  175. {
  176. unsigned char relay_status[2][8];
  177. }Relay;
  178. typedef struct GFD
  179. {
  180. unsigned short int adc_value_positive[2];
  181. unsigned short int adc_value_negative[2];
  182. }Gfd;
  183. typedef struct GPIO_IN
  184. {
  185. unsigned char AC_Connector;
  186. unsigned char AC_MainBreaker;
  187. unsigned char SPD;
  188. unsigned char Door_Open;
  189. unsigned char GFD[2];
  190. unsigned char Button[2];
  191. unsigned char Button_Emergency;
  192. }Gpio_in;
  193. typedef struct GPIO_OUT
  194. {
  195. unsigned char AC_Connector;
  196. unsigned char Button_LED[2];
  197. unsigned char System_LED[4];
  198. }Gpio_out;
  199. typedef struct ALARM_LOG
  200. {
  201. unsigned char logArea;
  202. unsigned int alarmIndex;
  203. unsigned char log[8];
  204. }Alarm_Log;
  205. typedef struct BLE_CONFIG_DATA
  206. {
  207. unsigned char isLogin:1;
  208. unsigned char isRequestStart:1;
  209. unsigned char isRequestStop:1;
  210. }Ble_Config_Data;
  211. typedef struct BLE_LONGIN_CENTRAL_ID
  212. {
  213. unsigned char id[32];
  214. }Ble_Login_Central_Id;
  215. typedef struct RTC
  216. {
  217. unsigned short int year;
  218. unsigned char month;
  219. unsigned char day;
  220. unsigned char hour;
  221. unsigned char min;
  222. unsigned char sec;
  223. }Rtc;
  224. typedef struct PRESENTOUTPUTCURRENT
  225. {
  226. double L1N_L12[2];
  227. double L2N_L23[2];
  228. double L3N_L31[2];
  229. }Presentoutputcurrent;
  230. typedef struct AC_PRIMARY_MCU
  231. {
  232. unsigned char cp_state;
  233. unsigned int current_limit;
  234. float cp_voltage_positive;
  235. float cp_voltage_negtive;
  236. unsigned char locker_state;
  237. unsigned char relay_state;
  238. unsigned char shutter_state;
  239. unsigned char meter_state;
  240. unsigned char pp_state;
  241. unsigned char rating_current;
  242. unsigned char rotatory_switch;
  243. }Ac_Primary_Mcu;
  244. typedef struct AC_PRIMARY_MCU_ALARM
  245. {
  246. union
  247. {
  248. unsigned long InputAlarmCode;
  249. struct
  250. {
  251. unsigned long OVP:1;
  252. unsigned long UVP:1;
  253. unsigned long OCP:1;
  254. unsigned long OTP:1;
  255. unsigned long gmi_fault:1;
  256. unsigned long cp_fault:1;
  257. unsigned long ac_leak:1;
  258. unsigned long dc_leak:1;
  259. unsigned long mcu_selftest_fail:1;
  260. unsigned long handshaking_timeout:1;
  261. unsigned long emergency_stop:1;
  262. unsigned long relay_welding:1;
  263. unsigned long leak_module_fail:1;
  264. unsigned long shutter_fault:1;
  265. unsigned long locker_fault:1;
  266. unsigned long power_drop:1;
  267. unsigned long circuit_short:1;
  268. unsigned long set_circuit:1;
  269. unsigned long relay_drive_fault:1;
  270. unsigned long comm_timeout:1;
  271. }bits;
  272. };
  273. }Ac_Primary_Mcu_Alarm;
  274. typedef struct AC_PRIMARY_MCU_LED
  275. {
  276. unsigned char mode;
  277. unsigned long alarm_code;
  278. }Ac_Primary_Mcu_Led;
  279. typedef struct EVSE_ID
  280. {
  281. unsigned char model_name[14];
  282. unsigned char serial_number[12];
  283. }Evse_Id;
  284. typedef struct AC_PRIMARY_MCU_CP_PWM_DUTY
  285. {
  286. unsigned int max_current;
  287. }Ac_Primary_Mcu_Cp_Pwm_Duty;
  288. typedef struct LEGACY_REQUEST
  289. {
  290. unsigned char isLegacyRequest:1;
  291. }Legacy_Request;
  292. typedef struct POWER_CONSUMPTION
  293. {
  294. uint32_t power_consumption;
  295. }Power_Consumption;
  296. typedef struct MCU_OP_FLAG
  297. {
  298. unsigned char isSetModePass:1;
  299. unsigned char isSetSerialNumberPass:1;
  300. unsigned char isSetModelNamePass:1;
  301. unsigned char isReadFwVerPass:1;
  302. unsigned char isMcuUpgradeReq:1;
  303. }Mcu_Op_Flag;
  304. typedef struct SYSTEM_ALARM_CODE
  305. {
  306. unsigned long SystemAlarmCode;
  307. }System_Alarm_Code;
  308. typedef struct OTHER_ALARM_CODE
  309. {
  310. unsigned char isMcuSelfTest:1;
  311. unsigned char isCurrentShort:1;
  312. unsigned char isLeakageModule:1;
  313. unsigned char isShutter:1;
  314. unsigned char isLocker:1;
  315. unsigned char isRotatorySwitchr:1;
  316. unsigned char isPowerDrop:1;
  317. unsigned char isOverCurrent:1;
  318. unsigned char isHandshakingTimeOut:1;
  319. unsigned char HandShakingAlarmRequest:1;
  320. }Other_Alarm_Code;
  321. typedef struct PILOT_VOLTAGE
  322. {
  323. float PilotVoltagePositive;
  324. float PilotVoltageNegative;
  325. }Pilot_Voltage;
  326. typedef struct FW_UPGRADE_INFO
  327. {
  328. int fwType;
  329. char modelName[17];
  330. char location[384];
  331. }Fw_Upgrade_Info;
  332. typedef struct GUN_PLUGIN_TIMES
  333. {
  334. uint32_t GunPluginTimes;
  335. }Gun_Plugin_Times;
  336. typedef struct INTERNAL_SYSTEM_STATUS
  337. {
  338. unsigned char SystemStatus;
  339. unsigned char PreviousSystemStatus;
  340. }Internal_Sysyem_status;
  341. typedef struct GUN_INFO
  342. {
  343. Ver ver;
  344. PresentInputVoltage inputVoltage;
  345. Presentoutputcurrent outputCurrent;
  346. Temperature temperature;
  347. Ble_Config_Data bleConfigData;
  348. Ble_Login_Central_Id bleLoginCentralId;
  349. Rtc rtc;
  350. Ac_Primary_Mcu primaryMcuState;
  351. Ac_Primary_Mcu_Alarm primaryMcuAlarm;
  352. Ac_Primary_Mcu_Led primaryMcuLed;
  353. Mcu_Op_Flag mcuFlag;
  354. Power_Consumption powerConsumption;
  355. Legacy_Request legacyRequest;
  356. System_Alarm_Code systemAlarmCode;
  357. Ac_Primary_Mcu_Cp_Pwm_Duty primaryMcuCp_Pwn_Duty;
  358. Other_Alarm_Code otherAlarmCode;
  359. Pilot_Voltage PilotVoltage;
  360. Gun_Plugin_Times gunPluginTimes;
  361. Internal_Sysyem_status internalSystemStatus;
  362. }Gun_Info;
  363. struct Charger
  364. {
  365. Ver ver;
  366. Evse_Id evseId;
  367. Gun_Info gun_info[2];
  368. Fw_Upgrade_Info fwUpgradeInfo;
  369. unsigned char rfidReq:1;
  370. unsigned char speaker_type;
  371. unsigned char isSpeakerOn:1;
  372. };
  373. #endif /* CONFIG_MAIN_H_ */