main.h 10.0 KB

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