main.h 11 KB

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