MessageHandler.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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_QueueOffLineStartTransactionMessage,
  347. GetConfiguration_LocalAuthListEnabled,
  348. GetConfiguration_LocalAuthListMaxLength,
  349. GetConfiguration_SendLocalListMaxLength,
  350. GetConfiguration_ReserveConnectorZeroSupported,
  351. GetConfiguration_ChargeProfileMaxStackLevel,
  352. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  353. GetConfiguration_ChargingScheduleMaxPeriods,
  354. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  355. GetConfiguration_MaxChargingProfilesInstalled,
  356. };
  357. enum FIRMWARE_NOTIFICATION_STATUS
  358. {
  359. FIRMWARE_STATUS_DOWNLOADED = 0,
  360. FIRMWARE_STATUS_DOWNLOAD_FAILED = 1,
  361. FIRMWARE_STATUS_DOWNLOADING = 2,
  362. FIRMWARE_STATUS_IDLE = 3,
  363. FIRMWARE_STATUS_INSTALLATION_FAILED =4,
  364. FIRMWARE_STATUS_INSTALLING = 5,
  365. FIRMWARE_STATUS_INSTALLED = 6
  366. };
  367. enum DIAGNOSTIC_NOTIFICATION_STATUS
  368. {
  369. DIAGNOSTIC_STATUS_IDLE = 0,
  370. DIAGNOSTIC_STATUS_UPLOADED = 1,
  371. DIAGNOSTIC_STATUS_UPLOAD_FAIL = 2,
  372. DIAGNOSTIC_STATUS_UPLOADING =3
  373. };
  374. struct StructPeriod
  375. {
  376. int StartPeriod;
  377. float Limit;//0.1;
  378. int NumberPhases;
  379. };
  380. struct StructProfile
  381. {
  382. int Duration;
  383. int TotalPeriod;
  384. struct StructPeriod Period[10];
  385. };
  386. //===============================================
  387. // Common routine
  388. //===============================================
  389. int initialConfigurationTable(void);
  390. void StoreConfigurationTable(void);
  391. void GetStartTransactionIdTag(int gun_index);
  392. //==========================================
  393. // send request routine
  394. //==========================================
  395. int sendAuthorizeRequest(int gun_index);
  396. int sendBootNotificationRequest(void);
  397. int sendDataTransferRequest(int gun_index);
  398. int sendFirmwareVersionByDataTransfer(void);
  399. int sendDiagnosticsStatusNotificationRequest(char *status);
  400. int sendFirmwareStatusNotificationRequest(char *status);
  401. int sendHeartbeatRequest(int gun_index);
  402. int sendStartTransactionRequest(int gun_index);
  403. int sendStatusNotificationRequest(int gun_index);
  404. int sendStopTransactionRequest(int gun_index);
  405. int sendMeterValuesRequest(int gun_index, ReadingContext dataType);
  406. //==========================================
  407. // send confirm routine
  408. //==========================================
  409. int sendCancelReservationConfirmation(char *uuid,char *payload);
  410. int sendChangeAvailabilityConfirmation(char *uuid,char *payload);
  411. int sendChangeConfigurationConfirmation(char *uuid,char *payload);
  412. int sendClearCacheConfirmation(char *uuid,char *payload);
  413. int sendClearChargingProfileConfirmation(char *uuid,char *payload);
  414. int sendDataTransferConfirmation(char *uuid,char *payload);
  415. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod);
  416. int sendGetConfigurationConfirmation(char *uuid);
  417. int sendGetDiagnosticsConfirmation(char *uuid,char *payload);
  418. int sendGetLocalListVersionConfirmation(char *uuid,char *payload);
  419. int sendRemoteStartConfirmation(char *uuid,char *payload);
  420. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload);
  421. int sendReserveNowTransactionConfirmation(char *uuid,char *payload);
  422. int sendResetConfirmation(char *uuid,char *payload);
  423. int sendSendLocalListConfirmation(char *uuid,char *payload);
  424. int sendSetChargingProfileConfirmation(char *uuid,char *payload);
  425. int sendTriggerMessageConfirmation(char *uuid,char *payload);
  426. int sendUnlockConnectorConfirmation(char *uuid,char *payload);
  427. int sendUpdateFirmwareConfirmation(char *uuid);
  428. //==========================================
  429. // send CallError routine
  430. //==========================================
  431. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription);
  432. //==========================================
  433. // Handle server request routine Start
  434. //==========================================
  435. int handleCancelReservationRequest(char *uuid, char *payload);
  436. int handleChangeAvailabilityRequest(char *uuid, char *payload);
  437. int handleChangeConfigurationRequest(char *uuid, char *payload);
  438. int handleClearCacheRequest(char *uuid, char *payload);
  439. int handleClearChargingProfileRequest(char *uuid, char *payload);
  440. int handleDataTransferRequest(char *uuid, char *payload);
  441. int handleGetCompositeScheduleRequest(char *uuid, char *payload);
  442. int handleGetConfigurationRequest(char *uuid, char *payload);
  443. int handleGetDiagnosticsRequest(char *uuid, char *payload);
  444. int handleGetLocalListVersionRequest(char *uuid, char *payload);
  445. int handleRemoteStartRequest(char *uuid, char *payload);
  446. int handleRemoteStopTransactionRequest(char *uuid, char *payload);
  447. int handleReserveNowTransactionRequest(char *uuid, char *payload);
  448. int handleResetRequest(char *uuid, char *payload);
  449. int handleSendLocalListRequest(char *uuid, char *payload);
  450. int handleSetChargingProfileRequest(char *uuid, char *payload);
  451. int handleTriggerMessageRequest(char *uuid, char *payload);
  452. int handleUnlockConnectorRequest(char *uuid, char *payload);
  453. int handleUpdateFirmwareRequest(char *uuid, char *payload);
  454. void handleAuthorizeResponse(char *payload, int gun_index);
  455. void handleBootNotificationResponse(char *payload, int gun_index);
  456. void handleDataTransferResponse(char *payload, int gun_index);
  457. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index);
  458. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index);
  459. void handleHeartbeatResponse(char *payload, int gun_index);
  460. void handleMeterValuesResponse(char *payload, int gun_index);
  461. void handleStartTransactionResponse(char *payload, int gun_index);
  462. void handleStatusNotificationResponse(char *payload, int gun_index);
  463. void handleStopTransactionnResponse(char *payload, int gun_index);
  464. //==========================================
  465. // Handle Error routine
  466. //==========================================
  467. void handleError(char *id, char *errorCode, char *errorDescription,char *payload);
  468. //===============================================
  469. // Common routine
  470. //===============================================
  471. void getKeyValue(char *keyReq);
  472. int setKeyValue(char *key, char *value);
  473. int updateSetting(char *key, char *value);
  474. int httpDownLoadFile(char *location, char *path, char *filename,char *url);
  475. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url);
  476. void *UpdateFirmwareProcess(void* data);
  477. void* GetDiagnosticsProcess(void* data);
  478. int httpUploadFile(char *location, char *path, char *filename,char *url);
  479. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
  480. int get_file_contents(const char* filename, char** outbuffer);
  481. void LWS_Send(char * str);
  482. extern int queue_operation(int type, char *frontUUID, char *frontData);
  483. int GetOcppServerURL();
  484. int GetOcppPath();
  485. int GetOcppPort();
  486. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction);
  487. void SetTransactionIdZero(int transactionId);
  488. void GetChargingProfileRequest(int gunindex);
  489. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[]);
  490. void splitstring(char *src,const char *separator,char **dest,int *num);
  491. int GetWebSocketPingInterval(void);
  492. int GetInternetConn(void);
  493. int GetServerSign(void);
  494. void SetServerSign(int value);
  495. int GetBootNotificationInterval(void);
  496. void InitialSystemValue(void);
  497. void checkTempStopTransaction(int gun_index);
  498. void storeTempStopTransaction(int gun_index);
  499. //===============================================
  500. // sqlite related routine
  501. //===============================================
  502. int SettingChargingRecord(int target, int transactionId);
  503. int addBuff(int gun_idx, int user_id, int cmd_sn);
  504. void OCPP_getListVerion();
  505. int OCPP_cleanLocalList();
  506. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
  507. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
  508. void OCPP_getIdTag(char idTag[]);
  509. void OCPP_deleteIdTag(char idTag[]);
  510. #endif