main.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * Config.h
  3. *
  4. * Created on: 2020年01月15日
  5. * Author: Eason Yang
  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. #include <sqlite3.h>
  40. //===================================
  41. // Define CP State constant
  42. //===================================
  43. #define CP_STATE_UNKNOWN 0
  44. #define CP_STATE_A 1
  45. #define CP_STATE_B 2
  46. #define CP_STATE_C 3
  47. #define CP_STATE_D 4
  48. #define CP_STATE_E 5
  49. #define CP_STATE_F 6
  50. //===================================
  51. // Define start mode constant
  52. //===================================
  53. #define START_METHOD_FREE 0
  54. #define START_METHOD_RFID 1
  55. #define START_METHOD_BACKEND 2
  56. #define START_METHOD_BLE 3
  57. //===================================
  58. // Define Speaker type constant
  59. //===================================
  60. #define SPEAKER_STOP 0
  61. #define SPEAKER_ALWAYS_ON 1
  62. #define SPEAKER_SHORT 2
  63. #define SPEAKER_LONG 3
  64. #define SPEAKER_INTERVAL_SHORT 4
  65. #define SPEAKER_INTERVAL_LONG 5
  66. #define SPEAKER_INTERVAL_3COUNT 6
  67. //===================================
  68. // Define Alarm code constant
  69. //===================================
  70. #define ALARM_OVER_VOLTAGE 0x000001
  71. #define ALARM_UNDER_VOLTAGE 0x000002
  72. #define ALARM_OVER_CURRENT 0x000004
  73. #define ALARM_OVER_TEMPERATURE 0x000008
  74. #define ALARM_GROUND_FAIL 0x000010
  75. #define ALARM_CP_ERROR 0x000020
  76. #define ALARM_CURRENT_LEAK_AC 0x000040
  77. #define ALARM_CURRENT_LEAK_DC 0x000080
  78. #define ALARM_MCU_TESTFAIL 0x000100
  79. #define ALARM_HANDSHAKE_TIMEOUT 0x000200
  80. #define ALARM_EMERGENCY_STOP 0x000400
  81. #define ALARM_RELAY_WELDING 0x000800
  82. #define ALARM_LEAK_MODULE_FAIL 0x001000
  83. #define ALARM_SHUTTER_FAULT 0x002000
  84. #define ALARM_LOCKER_FAULT 0x004000
  85. #define ALARM_POWER_DROP 0x008000
  86. #define ALARM_CURRENT_SHORT 0x010000
  87. #define ALARM_ROTATORY_SWITCH_FAULT 0x020000
  88. #define ALARM_RELAY_DRIVE_FAULT 0x040000
  89. //===================================
  90. // Define Led constant
  91. //===================================
  92. #define LED_ACTION_INIT 0
  93. #define LED_ACTION_IDLE 1
  94. #define LED_ACTION_AUTHED 2
  95. #define LED_ACTION_CONNECTED 3
  96. #define LED_ACTION_CHARGING 4
  97. #define LED_ACTION_STOP 5
  98. #define LED_ACTION_ALARM 6
  99. #define LED_ACTION_MAINTAIN 7
  100. #define LED_ACTION_RFID_PASS 8
  101. #define LED_ACTION_RFID_FAIL 9
  102. #define LED_ACTION_BLE_CONNECT 10
  103. #define LED_ACTION_BLE_DISABLE 11
  104. #define LED_ACTION_DEBUG 12
  105. #define LED_ACTION_ALL_OFF 13
  106. #define LED_RELAY_ON 14
  107. #define LED_RELAY_OFF 15
  108. #define LED_ACTION_HANDSHAKE_FAIL 16
  109. #define LED_ACTION_INTERNET_DISCONNECT 17
  110. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  111. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  112. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  113. extern int StoreLogMsg(const char *fmt, ...);
  114. //============================================================
  115. // Private shared memory key define
  116. //============================================================
  117. #define ShmChargerKey 2001
  118. typedef struct Verion
  119. {
  120. char Version_FW[32];
  121. char Version_HW[32];
  122. }Ver;
  123. typedef struct PRESENTINPUTVOLTAGE
  124. {
  125. unsigned char inputType; // 0x00: Line to Line 0x01: Line to Neutral
  126. double L1N_L12;
  127. double L2N_L23;
  128. double L3N_L31;
  129. }PresentInputVoltage;
  130. typedef struct PRESENTOUTPUTVOLTAGE
  131. {
  132. double behindFuse_Voltage_C1;
  133. double behindRelay_Voltage_C1;
  134. double behindFuse_Voltage_C2;
  135. double behindRelay_Voltage_C2;
  136. }PresentOutputVoltage;
  137. typedef struct FANSPEED
  138. {
  139. unsigned short int speed[4];
  140. }FanSpeed;
  141. typedef struct TEMPERATURE
  142. {
  143. unsigned char point[8];
  144. }Temperature;
  145. typedef struct AUXPOWER
  146. {
  147. unsigned char voltage[8];
  148. }AuxPower;
  149. typedef struct RELAY
  150. {
  151. unsigned char relay_status[2][8];
  152. }Relay;
  153. typedef struct GFD
  154. {
  155. unsigned short int adc_value_positive[2];
  156. unsigned short int adc_value_negative[2];
  157. }Gfd;
  158. typedef struct GPIO_IN
  159. {
  160. unsigned char AC_Connector;
  161. unsigned char AC_MainBreaker;
  162. unsigned char SPD;
  163. unsigned char Door_Open;
  164. unsigned char GFD[2];
  165. unsigned char Button[2];
  166. unsigned char Button_Emergency;
  167. }Gpio_in;
  168. typedef struct GPIO_OUT
  169. {
  170. unsigned char AC_Connector;
  171. unsigned char Button_LED[2];
  172. unsigned char System_LED[4];
  173. }Gpio_out;
  174. typedef struct ALARM_LOG
  175. {
  176. unsigned char logArea;
  177. unsigned int alarmIndex;
  178. unsigned char log[8];
  179. }Alarm_Log;
  180. typedef struct BLE_CONFIG_DATA
  181. {
  182. unsigned char isLogin:1;
  183. unsigned char isRequestStart:1;
  184. unsigned char isRequestStop:1;
  185. }Ble_Config_Data;
  186. typedef struct BLE_LONGIN_CENTRAL_ID
  187. {
  188. unsigned char id[32];
  189. }Ble_Login_Central_Id;
  190. typedef struct RTC
  191. {
  192. unsigned short int year;
  193. unsigned char month;
  194. unsigned char day;
  195. unsigned char hour;
  196. unsigned char min;
  197. unsigned char sec;
  198. }Rtc;
  199. typedef struct PRESENTOUTPUTCURRENT
  200. {
  201. double L1N_L12[2];
  202. double L2N_L23[2];
  203. double L3N_L31[2];
  204. }Presentoutputcurrent;
  205. typedef struct AC_PRIMARY_MCU
  206. {
  207. unsigned char cp_state;
  208. unsigned int current_limit;
  209. float cp_voltage_positive;
  210. float cp_voltage_negtive;
  211. unsigned char locker_state;
  212. unsigned char relay_state;
  213. unsigned char shutter_state;
  214. unsigned char meter_state;
  215. unsigned char pp_state;
  216. unsigned char rating_current;
  217. unsigned char rotatory_switch;
  218. }Ac_Primary_Mcu;
  219. typedef struct AC_PRIMARY_MCU_ALARM
  220. {
  221. union
  222. {
  223. unsigned long InputAlarmCode;
  224. struct
  225. {
  226. unsigned long OVP:1;
  227. unsigned long UVP:1;
  228. unsigned long OCP:1;
  229. unsigned long OTP:1;
  230. unsigned long gmi_fault:1;
  231. unsigned long cp_fault:1;
  232. unsigned long ac_leak:1;
  233. unsigned long dc_leak:1;
  234. unsigned long mcu_selftest_fail:1;
  235. unsigned long handshaking_timeout:1;
  236. unsigned long emergency_stop:1;
  237. unsigned long relay_welding:1;
  238. unsigned long leak_module_fail:1;
  239. unsigned long shutter_fault:1;
  240. unsigned long locker_fault:1;
  241. unsigned long power_drop:1;
  242. unsigned long circuit_short:1;
  243. unsigned long set_circuit:1;
  244. unsigned long relay_drive_fault:1;
  245. unsigned long comm_timeout:1;
  246. }bits;
  247. };
  248. }Ac_Primary_Mcu_Alarm;
  249. typedef struct AC_PRIMARY_MCU_LED
  250. {
  251. unsigned char mode;
  252. unsigned long alarm_code;
  253. }Ac_Primary_Mcu_Led;
  254. typedef struct EVSE_ID
  255. {
  256. unsigned char model_name[14];
  257. unsigned char serial_number[12];
  258. }Evse_Id;
  259. typedef struct AC_PRIMARY_MCU_CP_PWM_DUTY
  260. {
  261. unsigned int max_current;
  262. }Ac_Primary_Mcu_Cp_Pwm_Duty;
  263. typedef struct LEGACY_REQUEST
  264. {
  265. unsigned char isLegacyRequest:1;
  266. }Legacy_Request;
  267. typedef struct POWER_CONSUMPTION
  268. {
  269. uint32_t power_consumption;
  270. uint32_t power_consumption_at_start;
  271. }Power_Consumption;
  272. typedef struct MCU_OP_FLAG
  273. {
  274. unsigned char isSetModePass:1;
  275. unsigned char isSetSerialNumberPass:1;
  276. unsigned char isSetModelNamePass:1;
  277. unsigned char isReadFwVerPass:1;
  278. unsigned char isMcuUpgradeReq:1;
  279. unsigned char isSetCpPwmDuty:1;
  280. }Mcu_Op_Flag;
  281. typedef struct SYSTEM_ALARM_CODE
  282. {
  283. unsigned long SystemAlarmCode;
  284. }System_Alarm_Code;
  285. typedef struct OTHER_ALARM_CODE
  286. {
  287. unsigned long isHandshakingTimeOut:1;
  288. unsigned long isDcLeakage:1;
  289. unsigned long isACLeakage:1;
  290. }Other_Alarm_Code;
  291. typedef struct PILOT_VOLTAGE
  292. {
  293. float PilotVoltagePositive;
  294. float PilotVoltageNegative;
  295. }Pilot_Voltage;
  296. typedef struct FW_UPGRADE_INFO
  297. {
  298. int fwType;
  299. char modelName[17];
  300. char location[384];
  301. }Fw_Upgrade_Info;
  302. typedef struct GUN_PLUGIN_TIMES
  303. {
  304. uint32_t GunPluginTimes;
  305. }Gun_Plugin_Times;
  306. typedef struct MCU_RESET_REQUEST
  307. {
  308. unsigned char isMcuResetRequest:1;
  309. }Mcu_Reset_Request;
  310. typedef struct TIMEOUT_SPEC
  311. {
  312. int Setting_Timeout_Spec;
  313. int Present_Timeout_Spec;
  314. }Timeout_Spec;
  315. typedef struct SET_BREATHE_LED_TIMING
  316. {
  317. uint16_t set_Led_Action_Connected_Fade_In;
  318. uint16_t set_Led_Action_Connected_Fade_Out;
  319. uint16_t set_Led_Action_Authed_Fade_In;
  320. uint16_t set_Led_Action_Authed_Fade_Out;
  321. uint16_t Set_Led_Action_Chaging_Fade_In;
  322. uint16_t set_Led_Action_Chaging_Fade_Out;
  323. }Set_Breathe_Led_Timing;
  324. typedef struct SET_LED_BRIGHTNESS
  325. {
  326. uint8_t sector_1; // 0~1 AM and 1~2 AM
  327. uint8_t sector_2; // 2~3 AM and 3~4 AM
  328. uint8_t sector_3; // 4~5 AM and 5~6 AM
  329. uint8_t sector_4; // 6~7 AM and 7~8 AM
  330. uint8_t sector_5; // 8~9 AM and 9~10 AM
  331. uint8_t sector_6; // 10~11 AM and 11~12 AM
  332. uint8_t sector_7; // 12~13 PM and 13~14 PM
  333. uint8_t sector_8; // 14~15 PM and 15~16 PM
  334. uint8_t sector_9; // 16~17 PM and 17~18 PM
  335. uint8_t sector_10; // 18~19 PM and 19~20 PM
  336. uint8_t sector_11; // 20~21 PM and 21~22 PM
  337. uint8_t sector_12; // 22~23 PM and 23~24 PM
  338. }Set_Led_Brightness;
  339. typedef struct GUN_INFO
  340. {
  341. Ver ver;
  342. PresentInputVoltage inputVoltage;
  343. Presentoutputcurrent outputCurrent;
  344. Temperature temperature;
  345. Ble_Config_Data bleConfigData;
  346. Ble_Login_Central_Id bleLoginCentralId;
  347. Rtc rtc;
  348. Ac_Primary_Mcu primaryMcuState;
  349. Ac_Primary_Mcu_Alarm primaryMcuAlarm;
  350. Ac_Primary_Mcu_Led primaryMcuLed;
  351. Mcu_Op_Flag mcuFlag;
  352. Power_Consumption powerConsumption;
  353. Legacy_Request legacyRequest;
  354. System_Alarm_Code systemAlarmCode;
  355. Ac_Primary_Mcu_Cp_Pwm_Duty primaryMcuCp_Pwn_Duty;
  356. Other_Alarm_Code otherAlarmCode;
  357. Pilot_Voltage PilotVoltage;
  358. Gun_Plugin_Times gunPluginTimes;
  359. Mcu_Reset_Request mcuResetRequest;
  360. Set_Breathe_Led_Timing setBreatheLedTiming;
  361. Set_Led_Brightness setLedBrightness;
  362. uint16_t targetCurrent;
  363. uint16_t isAuthPassEnd:1;
  364. uint16_t rfidReq:1;
  365. uint16_t isGunPlugged:1;
  366. uint16_t isInitialPass:1;
  367. uint16_t isSetBreatheLedTiming:1;
  368. uint16_t isSetLedBrightness:1;
  369. uint16_t isUnlockerConnetor:1;
  370. uint16_t isOperactive:1;
  371. uint16_t isGunPlug:1;
  372. uint16_t isHandshakeTimeOn:1;
  373. }Gun_Info;
  374. struct Charger
  375. {
  376. Ver ver;
  377. Evse_Id evseId;
  378. Gun_Info gun_info[2];
  379. Fw_Upgrade_Info fwUpgradeInfo;
  380. Timeout_Spec timeoutSpec;
  381. uint8_t gun_selectd;
  382. uint8_t speaker_type;
  383. uint8_t isSpeakerOn:1;
  384. uint8_t isUpdateSuccess:1;
  385. };
  386. #endif /* CONFIG_MAIN_H_ */