main.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. Relay relayState;
  219. }Ac_Primary_Mcu;
  220. typedef struct AC_PRIMARY_MCU_ALARM
  221. {
  222. union
  223. {
  224. unsigned long InputAlarmCode;
  225. struct
  226. {
  227. unsigned long OVP:1;
  228. unsigned long UVP:1;
  229. unsigned long OCP:1;
  230. unsigned long OTP:1;
  231. unsigned long gmi_fault:1;
  232. unsigned long cp_fault:1;
  233. unsigned long ac_leak:1;
  234. unsigned long dc_leak:1;
  235. unsigned long mcu_selftest_fail:1;
  236. unsigned long handshaking_timeout:1;
  237. unsigned long emergency_stop:1;
  238. unsigned long relay_welding:1;
  239. unsigned long leak_module_fail:1;
  240. unsigned long shutter_fault:1;
  241. unsigned long locker_fault:1;
  242. unsigned long power_drop:1;
  243. unsigned long circuit_short:1;
  244. unsigned long set_circuit:1;
  245. unsigned long relay_drive_fault:1;
  246. unsigned long comm_timeout:1;
  247. }bits;
  248. };
  249. }Ac_Primary_Mcu_Alarm;
  250. typedef struct AC_PRIMARY_MCU_LED
  251. {
  252. unsigned char mode;
  253. unsigned long alarm_code;
  254. }Ac_Primary_Mcu_Led;
  255. typedef struct EVSE_ID
  256. {
  257. unsigned char model_name[14];
  258. unsigned char serial_number[12];
  259. }Evse_Id;
  260. typedef struct AC_PRIMARY_MCU_CP_PWM_DUTY
  261. {
  262. unsigned int max_current;
  263. }Ac_Primary_Mcu_Cp_Pwm_Duty;
  264. typedef struct LEGACY_REQUEST
  265. {
  266. unsigned char isLegacyRequest:1;
  267. uint8_t isRelayOn:1;
  268. }Legacy_Request;
  269. typedef struct POWER_CONSUMPTION
  270. {
  271. uint32_t power_consumption;
  272. uint32_t power_consumption_at_start;
  273. }Power_Consumption;
  274. typedef struct MCU_OP_FLAG
  275. {
  276. unsigned char isSetModePass:1;
  277. unsigned char isSetSerialNumberPass:1;
  278. unsigned char isSetModelNamePass:1;
  279. unsigned char isReadFwVerPass:1;
  280. unsigned char isMcuUpgradeReq:1;
  281. unsigned char isSetCpPwmDuty:1;
  282. }Mcu_Op_Flag;
  283. typedef struct SYSTEM_ALARM_CODE
  284. {
  285. unsigned long SystemAlarmCode;
  286. }System_Alarm_Code;
  287. typedef struct OTHER_ALARM_CODE
  288. {
  289. unsigned long isHandshakingTimeOut:1;
  290. unsigned long isDcLeakage:1;
  291. unsigned long isACLeakage:1;
  292. }Other_Alarm_Code;
  293. typedef struct PILOT_VOLTAGE
  294. {
  295. float PilotVoltagePositive;
  296. float PilotVoltageNegative;
  297. }Pilot_Voltage;
  298. typedef struct FW_UPGRADE_INFO
  299. {
  300. int fwType;
  301. char modelName[17];
  302. char location[384];
  303. }Fw_Upgrade_Info;
  304. typedef struct GUN_PLUGIN_TIMES
  305. {
  306. uint32_t GunPluginTimes;
  307. }Gun_Plugin_Times;
  308. typedef struct MCU_RESET_REQUEST
  309. {
  310. unsigned char isMcuResetRequest:1;
  311. }Mcu_Reset_Request;
  312. typedef struct TIMEOUT_SPEC
  313. {
  314. int Setting_Timeout_Spec;
  315. int Present_Timeout_Spec;
  316. }Timeout_Spec;
  317. typedef struct SET_BREATHE_LED_TIMING
  318. {
  319. uint16_t set_Led_Action_Connected_Fade_In;
  320. uint16_t set_Led_Action_Connected_Fade_Out;
  321. uint16_t set_Led_Action_Authed_Fade_In;
  322. uint16_t set_Led_Action_Authed_Fade_Out;
  323. uint16_t Set_Led_Action_Chaging_Fade_In;
  324. uint16_t set_Led_Action_Chaging_Fade_Out;
  325. }Set_Breathe_Led_Timing;
  326. typedef struct SET_LED_BRIGHTNESS
  327. {
  328. uint8_t sector_1; // 0~1 AM and 1~2 AM
  329. uint8_t sector_2; // 2~3 AM and 3~4 AM
  330. uint8_t sector_3; // 4~5 AM and 5~6 AM
  331. uint8_t sector_4; // 6~7 AM and 7~8 AM
  332. uint8_t sector_5; // 8~9 AM and 9~10 AM
  333. uint8_t sector_6; // 10~11 AM and 11~12 AM
  334. uint8_t sector_7; // 12~13 PM and 13~14 PM
  335. uint8_t sector_8; // 14~15 PM and 15~16 PM
  336. uint8_t sector_9; // 16~17 PM and 17~18 PM
  337. uint8_t sector_10; // 18~19 PM and 19~20 PM
  338. uint8_t sector_11; // 20~21 PM and 21~22 PM
  339. uint8_t sector_12; // 22~23 PM and 23~24 PM
  340. }Set_Led_Brightness;
  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. Mcu_Reset_Request mcuResetRequest;
  362. Set_Breathe_Led_Timing setBreatheLedTiming;
  363. Set_Led_Brightness setLedBrightness;
  364. uint8_t chargingMode;
  365. uint16_t targetCurrent;
  366. float tempCoefficient;
  367. uint16_t isAuthPassEnd:1;
  368. uint16_t rfidReq:1;
  369. uint16_t isGunPlugged:1;
  370. uint16_t isInitialPass:1;
  371. uint16_t isSetBreatheLedTiming:1;
  372. uint16_t isSetLedBrightness:1;
  373. uint16_t isUnlockerConnetor:1;
  374. uint16_t isOperactive:1;
  375. uint16_t isChargerStopByCondition:1;
  376. }Gun_Info;
  377. struct Charger
  378. {
  379. Ver ver;
  380. Evse_Id evseId;
  381. Gun_Info gun_info[2];
  382. Fw_Upgrade_Info fwUpgradeInfo;
  383. Timeout_Spec timeoutSpec;
  384. uint8_t gun_selectd;
  385. uint8_t speaker_type;
  386. uint8_t isSpeakerOn:1;
  387. uint8_t isUpdateSuccess:1;
  388. };
  389. #endif /* CONFIG_MAIN_H_ */