MessageHandler.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #ifndef MessageHandler_H
  2. #define MessageHandler_H
  3. //===================================
  4. // Define CP State constant
  5. //===================================
  6. #define CP_STATE_UNKNOWN 0
  7. #define CP_STATE_A 1
  8. #define CP_STATE_B 2
  9. #define CP_STATE_C 3
  10. #define CP_STATE_D 4
  11. #define CP_STATE_E 5
  12. #define CP_STATE_F 6
  13. //==========================================
  14. // Init all Enumeration & Mapping String
  15. //==========================================
  16. #define MACROSTR(k) #k
  17. /*ChargePointErrorCode*/
  18. typedef enum {
  19. ConnectorLockFailure,
  20. EVCommunicationError,
  21. GroundFailure,
  22. HighTemperature,
  23. InternalError,
  24. LocalListConflict,
  25. NoError,
  26. OtherError,
  27. OverCurrentFailure,
  28. OverVoltage,
  29. PowerMeterFailure,
  30. PowerSwitchFailure,
  31. ReaderFailure,
  32. ResetFailure,
  33. UnderVoltage,
  34. WeakSignal
  35. } ChargePointErrorCode;
  36. /*ChargePointStatus*/
  37. typedef enum {
  38. Available =0,
  39. Preparing,
  40. Charging,
  41. SuspendedEVSE,
  42. SuspendedEV,
  43. Finishing,
  44. Reserved,
  45. Unavailable,
  46. Faulted
  47. } ChargePointStatus;
  48. /*AvailabilityType*/
  49. typedef enum {
  50. RegistrationStatus_Accepted,
  51. RegistrationStatus_Pending,
  52. RegistrationStatus_Rejected
  53. } RegistrationStatus;
  54. /*AvailabilityType*/
  55. typedef enum {
  56. Inoperative,
  57. Operative
  58. } AvailabilityType;
  59. /*AvailabilityStatus*/
  60. typedef enum {
  61. Accepted,
  62. Rejected,
  63. Scheduled
  64. } AvailabilityStatus;
  65. /*ConfigurationStatus*/
  66. typedef enum {
  67. ConfigurationStatus_Accepted,
  68. ConfigurationStatus_Rejected,
  69. RebootRequired,
  70. NotSupported
  71. } ConfigurationStatus;
  72. /*ClearCacheStatus*/
  73. typedef enum {
  74. ClearCacheStatus_Accepted,
  75. ClearCacheStatus_Rejected
  76. } ClearCacheStatus;
  77. /*ChargingProfilePurposeType*/
  78. typedef enum {
  79. ChargePointMaxProfile,
  80. TxDefaultProfile,
  81. TxProfile
  82. } ChargingProfilePurposeType;
  83. /*ChargingProfileStatus*/
  84. typedef enum {
  85. ChargingProfileStatus_Accepted,
  86. ChargingProfileStatus_Rejected,
  87. ChargingProfileStatus_NotSupported
  88. } ChargingProfileStatus;
  89. /*ClearChargingProfileStatus*/
  90. typedef enum {
  91. ClearChargingProfileStatus_Accepted,
  92. ClearChargingProfileStatus_Unknown
  93. } ClearChargingProfileStatus;
  94. /*GetCompositeScheduleStatus*/
  95. typedef enum {
  96. GetCompositeScheduleStatus_Accepted,
  97. GetCompositeScheduleStatus_Rejected
  98. } GetCompositeScheduleStatus;
  99. /*ChargingRateUnitType*/
  100. typedef enum {
  101. ChargingRateUnitType_W,
  102. ChargingRateUnitType_A
  103. } ChargingRateUnitType;
  104. /*AuthorizationStatus*/
  105. typedef enum {
  106. AuthorizationStatus_Accepted ,
  107. AuthorizationStatus_Blocked ,
  108. AuthorizationStatus_Expired ,
  109. AuthorizationStatus_Invalid ,
  110. AuthorizationStatus_ConcurrentTx
  111. } AuthorizationStatus;
  112. /*UpdateType*/
  113. typedef enum {
  114. Differential ,
  115. Full
  116. } UpdateType;
  117. /*UpdateStatus*/
  118. typedef enum {
  119. UpdateStatus_Accepted ,
  120. UpdateStatus_Failed ,
  121. UpdateStatus_NotSupported ,
  122. UpdateStatus_VersionMismatch
  123. } UpdateStatus;
  124. /*RemoteStartStopStatus*/
  125. typedef enum {
  126. RemoteStartStopStatus_Accepted,
  127. RemoteStartStopStatus_Rejected
  128. } RemoteStartStopStatus;
  129. /*ReservationStatus*/
  130. typedef enum {
  131. ReservationStatus_Accepted,
  132. ReservationStatus_Faulted,
  133. ReservationStatus_Occupied,
  134. ReservationStatus_Rejected,
  135. ReservationStatus_Unavailable
  136. } ReservationStatus;
  137. /*ResetType*/
  138. typedef enum {
  139. Hard,
  140. Soft
  141. } ResetType;
  142. /*ResetStatus*/
  143. typedef enum {
  144. ResetStatus_Accepted,
  145. ResetStatus_Rejected
  146. } ResetStatus;
  147. /*DiagnosticsStatus*/
  148. typedef enum {
  149. DiagnosticsStatus_Idle,
  150. DiagnosticsStatus_Uploaded,
  151. DiagnosticsStatus_UploadFailed,
  152. DiagnosticsStatus_Uploading
  153. } DiagnosticsStatus;
  154. /*FirmwareStatus*/
  155. typedef enum {
  156. FirmwareStatus_Downloaded,
  157. FirmwareStatus_DownloadFailed,
  158. FirmwareStatus_Downloading,
  159. FirmwareStatus_Idle,
  160. FirmwareStatus_InstallationFailed,
  161. FirmwareStatus_Installing,
  162. FirmwareStatus_Installed
  163. } FirmwareStatus;
  164. /*MessageTrigger*/
  165. typedef enum {
  166. BootNotification,
  167. DiagnosticsStatusNotification,
  168. FirmwareStatusNotification,
  169. Heartbeat,
  170. MeterValues,
  171. StatusNotification
  172. } MessageTrigger;
  173. /*TriggerMessageStatus*/
  174. typedef enum {
  175. TriggerMessageStatus_Accepted ,
  176. TriggerMessageStatus_Rejected ,
  177. TriggerMessageStatus_NotImplemented
  178. } TriggerMessageStatus;
  179. /*UnlockStatus*/
  180. typedef enum {
  181. Unlocked,
  182. UnlockFailed,
  183. UnlockStatus_NotSupported
  184. } UnlockStatus;
  185. /*StopTransactionReason*/
  186. typedef enum {
  187. EmergencyStop,
  188. EVDisconnected,
  189. HardReset,
  190. Local,
  191. Other,
  192. PowerLoss,
  193. Reboot,
  194. Remote,
  195. SoftReset,
  196. UnlockCommand,
  197. DeAuthorized
  198. } StopTransactionReason;
  199. /*CancelReservationStatus*/
  200. typedef enum {
  201. CancelReservationStatus_Accepted,
  202. CancelReservationStatus_Rejected
  203. } CancelReservationStatus;
  204. /*ReadingContext*/
  205. typedef enum {
  206. ReadingContext_Interruption_Begin,
  207. ReadingContext_Interruption_End,
  208. ReadingContext_Other,
  209. ReadingContext_Sample_Clock,
  210. ReadingContext_Sample_Periodic ,
  211. ReadingContext_Transaction_Begin ,
  212. ReadingContext_Transaction_End,
  213. ReadingContext_Trigger
  214. } ReadingContext;
  215. /*ValueFormat*/
  216. typedef enum {
  217. Raw,
  218. SignedData
  219. } ValueFormat;
  220. /*Measurand*/
  221. typedef enum {
  222. Current_Export ,
  223. Current_Import,
  224. Current_Offered,
  225. Energy_Active_Export_Register,
  226. Energy_Active_Import_Register,
  227. Energy_Reactive_Export_Register,
  228. Energy_Reactive_Import_Register,
  229. Energy_Active_Export_Interval,
  230. Energy_Active_Import_Interval,
  231. Energy_Reactive_Export_Interval,
  232. Energy_Reactive_Import_Interval,
  233. Frequency,
  234. Power_Active_Export ,
  235. Power_Active_Import,
  236. Power_Factor,
  237. Power_Offered,
  238. Power_Reactive_Export,
  239. Power_Reactive_Import,
  240. RPM,
  241. SoC,
  242. Temperature ,
  243. Voltage
  244. } Measurand;
  245. /*Location*/
  246. typedef enum {
  247. Location_Body,
  248. Location_Cable,
  249. Location_EV,
  250. Location_Inlet ,
  251. Location_Outlet
  252. } Location;
  253. /*Phase*/
  254. typedef enum {
  255. L1,
  256. L2,
  257. L3,
  258. N,
  259. L1_N,
  260. L2_N,
  261. L3_N,
  262. L1_L2,
  263. L2_L3,
  264. L3_L1
  265. } Phase;
  266. /*UnitOfMeasure*/
  267. typedef enum {
  268. UnitOfMeasure_Wh,
  269. UnitOfMeasure_kWh ,
  270. UnitOfMeasure_varh ,
  271. UnitOfMeasure_kvarh ,
  272. UnitOfMeasure_W ,
  273. UnitOfMeasure_kW ,
  274. UnitOfMeasure_VA ,
  275. UnitOfMeasure_kVA ,
  276. UnitOfMeasure_var ,
  277. UnitOfMeasure_kvar ,
  278. UnitOfMeasure_A ,
  279. UnitOfMeasure_V ,
  280. UnitOfMeasure_Celsius ,
  281. UnitOfMeasure_Fahrenheit ,
  282. UnitOfMeasure_K ,
  283. UnitOfMeasure_Percent
  284. } UnitOfMeasure;
  285. enum LocalAuthListManagementProfile{
  286. LocalAuthListEnabled=0,
  287. LocalAuthListMaxLength,
  288. SendLocalListMaxLength,
  289. _LocalAuthListManagementProfile_CNT
  290. };
  291. enum ReservationProfile{
  292. ReserveConnectorZeroSupported
  293. };
  294. enum SmartChargingProfile{
  295. ChargeProfileMaxStackLevel,
  296. ChargingScheduleAllowedChargingRateUnit,
  297. ChargingScheduleMaxPeriods,
  298. ConnectorSwitch3to1PhaseSupported,
  299. MaxChargingProfilesInstalled
  300. };
  301. enum ChargerSystemStatus{
  302. ChargerSystemStatus_Booting,
  303. ChargerSystemStatus_Idle,
  304. ChargerSystemStatus_Authorizing,
  305. ChargerSystemStatus_Preparing,
  306. ChargerSystemStatus_Charging,
  307. ChargerSystemStatus_Terminating,
  308. ChargerSystemStatus_Alarm,
  309. ChargerSystemStatus_Fault
  310. };
  311. enum GetConfigurationKey {
  312. GetConfiguration_AllowOfflineTxForUnknownId=0,
  313. GetConfiguration_AuthorizationCacheEnabled,
  314. GetConfiguration_AuthorizeRemoteTxRequests,
  315. GetConfiguration_BlinkRepeat,
  316. GetConfiguration_ClockAlignedDataInterval,
  317. GetConfiguration_ConnectionTimeOut,
  318. GetConfiguration_GetConfigurationMaxKeys,
  319. GetConfiguration_HeartbeatInterval,
  320. GetConfiguration_LightIntensity,
  321. GetConfiguration_LocalAuthorizeOffline,
  322. GetConfiguration_LocalPreAuthorize,
  323. GetConfiguration_MaxEnergyOnInvalidId,
  324. GetConfiguration_MeterValuesAlignedData,
  325. GetConfiguration_MeterValuesAlignedDataMaxLength,
  326. GetConfiguration_MeterValuesSampledData,
  327. GetConfiguration_MeterValuesSampledDataMaxLength,
  328. GetConfiguration_MeterValueSampleInterval,
  329. GetConfiguration_MinimumStatusDuration,
  330. GetConfiguration_NumberOfConnectors,
  331. GetConfiguration_ResetRetries,
  332. GetConfiguration_ConnectorPhaseRotation,
  333. GetConfiguration_ConnectorPhaseRotationMaxLength,
  334. GetConfiguration_StopTransactionOnEVSideDisconnect,
  335. GetConfiguration_StopTransactionOnInvalidId,
  336. GetConfiguration_StopTxnAlignedData,
  337. GetConfiguration_StopTxnAlignedDataMaxLength,
  338. GetConfiguration_StopTxnSampledData,
  339. GetConfiguration_StopTxnSampledDataMaxLength,
  340. GetConfiguration_SupportedFeatureProfiles,
  341. GetConfiguration_SupportedFeatureProfilesMaxLength,
  342. GetConfiguration_TransactionMessageAttempts,
  343. GetConfiguration_TransactionMessageRetryInterval,
  344. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  345. GetConfiguration_WebSocketPingInterval,
  346. GetConfiguration_LocalAuthListEnabled,
  347. GetConfiguration_LocalAuthListMaxLength,
  348. GetConfiguration_SendLocalListMaxLength,
  349. GetConfiguration_ReserveConnectorZeroSupported,
  350. GetConfiguration_ChargeProfileMaxStackLevel,
  351. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  352. GetConfiguration_ChargingScheduleMaxPeriods,
  353. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  354. GetConfiguration_MaxChargingProfilesInstalled,
  355. };
  356. enum FIRMWARE_NOTIFICATION_STATUS
  357. {
  358. FIRMWARE_STATUS_DOWNLOADED = 0,
  359. FIRMWARE_STATUS_DOWNLOAD_DAILED = 1,
  360. FIRMWARE_STATUS_DOWNLOADING = 2,
  361. FIRMWARE_STATUS_IDLE = 3,
  362. FIRMWARE_STATUS_INSTALLATION_FAILED =4,
  363. FIRMWARE_STATUS_INSTALLING = 5,
  364. FIRMWARE_STATUS_INSTALLED = 6
  365. };
  366. enum DIAGNOSTIC_NOTIFICATION_STATUS
  367. {
  368. DIAGNOSTIC_STATUS_IDLE = 0,
  369. DIAGNOSTIC_STATUS_UPLOADED = 1,
  370. DIAGNOSTIC_STATUS_UPLOAD_FAIL = 2,
  371. DIAGNOSTIC_STATUS_UPLOADING =3
  372. };
  373. struct StructPeriod
  374. {
  375. int StartPeriod;
  376. float Limit;//0.1;
  377. int NumberPhases;
  378. };
  379. struct StructProfile
  380. {
  381. int Duration;
  382. int TotalPeriod;
  383. struct StructPeriod Period[10];
  384. };
  385. //===============================================
  386. // Common routine
  387. //===============================================
  388. int initialConfigurationTable(void);
  389. void StoreConfigurationTable(void);
  390. void GetStartTransactionIdTag(int gun_index);
  391. //==========================================
  392. // send request routine
  393. //==========================================
  394. int sendAuthorizeRequest(int gun_index);
  395. int sendBootNotificationRequest(void);
  396. int sendDataTransferRequest(int gun_index);
  397. int sendFirmwareVersionByDataTransfer(void);
  398. int sendDiagnosticsStatusNotificationRequest(char *status);
  399. int sendFirmwareStatusNotificationRequest(char *status);
  400. int sendHeartbeatRequest(int gun_index);
  401. int sendStartTransactionRequest(int gun_index);
  402. int sendStatusNotificationRequest(int gun_index);
  403. int sendStopTransactionRequest(int gun_index);
  404. int sendMeterValuesRequest(int gun_index, ReadingContext dataType);
  405. //==========================================
  406. // send confirm routine
  407. //==========================================
  408. int sendCancelReservationConfirmation(char *uuid,char *payload);
  409. int sendChangeAvailabilityConfirmation(char *uuid,char *payload);
  410. int sendChangeConfigurationConfirmation(char *uuid,char *payload);
  411. int sendClearCacheConfirmation(char *uuid,char *payload);
  412. int sendClearChargingProfileConfirmation(char *uuid,char *payload);
  413. int sendDataTransferConfirmation(char *uuid,char *payload);
  414. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod);
  415. int sendGetConfigurationConfirmation(char *uuid);
  416. int sendGetDiagnosticsConfirmation(char *uuid,char *payload);
  417. int sendGetLocalListVersionConfirmation(char *uuid,char *payload);
  418. int sendRemoteStartConfirmation(char *uuid,char *payload);
  419. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload);
  420. int sendReserveNowTransactionConfirmation(char *uuid,char *payload);
  421. int sendResetConfirmation(char *uuid,char *payload);
  422. int sendSendLocalListConfirmation(char *uuid,char *payload);
  423. int sendSetChargingProfileConfirmation(char *uuid,char *payload);
  424. int sendTriggerMessageConfirmation(char *uuid,char *payload);
  425. int sendUnlockConnectorConfirmation(char *uuid,char *payload);
  426. int sendUpdateFirmwareConfirmation(char *uuid);
  427. //==========================================
  428. // send CallError routine
  429. //==========================================
  430. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription);
  431. //==========================================
  432. // Handle server request routine Start
  433. //==========================================
  434. int handleCancelReservationRequest(char *uuid, char *payload);
  435. int handleChangeAvailabilityRequest(char *uuid, char *payload);
  436. int handleChangeConfigurationRequest(char *uuid, char *payload);
  437. int handleClearCacheRequest(char *uuid, char *payload);
  438. int handleClearChargingProfileRequest(char *uuid, char *payload);
  439. int handleDataTransferRequest(char *uuid, char *payload);
  440. int handleGetCompositeScheduleRequest(char *uuid, char *payload);
  441. int handleGetConfigurationRequest(char *uuid, char *payload);
  442. int handleGetDiagnosticsRequest(char *uuid, char *payload);
  443. int handleGetLocalListVersionRequest(char *uuid, char *payload);
  444. int handleRemoteStartRequest(char *uuid, char *payload);
  445. int handleRemoteStopTransactionRequest(char *uuid, char *payload);
  446. int handleReserveNowTransactionRequest(char *uuid, char *payload);
  447. int handleResetRequest(char *uuid, char *payload);
  448. int handleSendLocalListRequest(char *uuid, char *payload);
  449. int handleSetChargingProfileRequest(char *uuid, char *payload);
  450. int handleTriggerMessageRequest(char *uuid, char *payload);
  451. int handleUnlockConnectorRequest(char *uuid, char *payload);
  452. int handleUpdateFirmwareRequest(char *uuid, char *payload);
  453. void handleAuthorizeResponse(char *payload, int gun_index);
  454. void handleBootNotificationResponse(char *payload, int gun_index);
  455. void handleDataTransferResponse(char *payload, int gun_index);
  456. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index);
  457. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index);
  458. void handleHeartbeatResponse(char *payload, int gun_index);
  459. void handleMeterValuesResponse(char *payload, int gun_index);
  460. void handleStartTransactionResponse(char *payload, int gun_index);
  461. void handleStatusNotificationResponse(char *payload, int gun_index);
  462. void handleStopTransactionnResponse(char *payload, int gun_index);
  463. //==========================================
  464. // Handle Error routine
  465. //==========================================
  466. void handleError(char *id, char *errorCode, char *errorDescription,char *payload);
  467. //===============================================
  468. // Common routine
  469. //===============================================
  470. void getKeyValue(char *keyReq);
  471. int setKeyValue(char *key, char *value);
  472. int updateSetting(char *key, char *value);
  473. int httpDownLoadFile(char *location, char *path, char *filename,char *url);
  474. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url);
  475. void *UpdateFirmwareProcess(void* data);
  476. void* GetDiagnosticsProcess(void* data);
  477. int httpUploadFile(char *location, char *path, char *filename,char *url);
  478. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
  479. int get_file_contents(const char* filename, char** outbuffer);
  480. void LWS_Send(char * str);
  481. extern int queue_operation(int type, char *frontUUID, char *frontData);
  482. int GetOcppServerURL();
  483. int GetOcppPath();
  484. int GetOcppPort();
  485. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction);
  486. void SetTransactionIdZero(int transactionId);
  487. void GetChargingProfileRequest(int gunindex);
  488. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[]);
  489. void splitstring(char *src,const char *separator,char **dest,int *num);
  490. int GetWebSocketPingInterval(void);
  491. int GetInternetConn(void);
  492. int GetServerSign(void);
  493. void SetServerSign(int value);
  494. int GetBootNotificationInterval(void);
  495. void InitialSystemValue(void);
  496. void checkTempStopTransaction(int gun_index);
  497. void storeTempStopTransaction(int gun_index);
  498. //===============================================
  499. // sqlite related routine
  500. //===============================================
  501. int SettingChargingRecord(int target, int transactionId);
  502. int addBuff(int gun_idx, int user_id, int cmd_sn);
  503. void OCPP_getListVerion();
  504. int OCPP_cleanLocalList();
  505. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
  506. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
  507. void OCPP_getIdTag(char idTag[]);
  508. void OCPP_deleteIdTag(char idTag[]);
  509. #endif