emqx_ocpp.hrl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %% %% http://www.apache.org/licenses/LICENSE-2.0
  8. %%
  9. %% Unless required by applicable law or agreed to in writing, software
  10. %% distributed under the License is distributed on an "AS IS" BASIS,
  11. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. %% See the License for the specific language governing permissions and
  13. %% limitations under the License.
  14. %%--------------------------------------------------------------------
  15. -define(APP, emqx_ocpp).
  16. %% types for ocppj-1.6
  17. -define(OCPP_MSG_TYPE_ID_CALL, 2).
  18. -define(OCPP_MSG_TYPE_ID_CALLRESULT, 3).
  19. -define(OCPP_MSG_TYPE_ID_CALLERROR, 4).
  20. %% actions for ocppj-1.6
  21. -define(OCPP_ACT_Authorize, <<"Authorize">>).
  22. -define(OCPP_ACT_BootNotification, <<"BootNotification">>).
  23. -define(OCPP_ACT_CancelReservation, <<"CancelReservation">>).
  24. -define(OCPP_ACT_ChangeAvailability, <<"ChangeAvailability">>).
  25. -define(OCPP_ACT_ChangeConfiguration, <<"ChangeConfiguration">>).
  26. -define(OCPP_ACT_ClearCache, <<"ClearCache">>).
  27. -define(OCPP_ACT_ClearChargingProfile, <<"ClearChargingProfile">>).
  28. -define(OCPP_ACT_DataTransfer, <<"DataTransfer">>).
  29. -define(OCPP_ACT_DiagnosticsStatusNotification, <<"DiagnosticsStatusNotification">>).
  30. -define(OCPP_ACT_FirmwareStatusNotification, <<"FirmwareStatusNotification">>).
  31. -define(OCPP_ACT_GetCompositeSchedule, <<"GetCompositeSchedule">>).
  32. -define(OCPP_ACT_GetConfiguration, <<"GetConfiguration">>).
  33. -define(OCPP_ACT_GetDiagnostics, <<"GetDiagnostics">>).
  34. -define(OCPP_ACT_GetLocalListVersion, <<"GetLocalListVersion">>).
  35. -define(OCPP_ACT_Heartbeat, <<"Heartbeat">>).
  36. -define(OCPP_ACT_MeterValues, <<"MeterValues">>).
  37. -define(OCPP_ACT_RemoteStartTransaction, <<"RemoteStartTransaction">>).
  38. -define(OCPP_ACT_RemoteStopTransaction, <<"RemoteStopTransaction">>).
  39. -define(OCPP_ACT_ReserveNow, <<"ReserveNow">>).
  40. -define(OCPP_ACT_Reset, <<"Reset">>).
  41. -define(OCPP_ACT_SendLocalList, <<"SendLocalList">>).
  42. -define(OCPP_ACT_SetChargingProfile, <<"SetChargingProfile">>).
  43. -define(OCPP_ACT_StartTransaction, <<"StartTransaction">>).
  44. -define(OCPP_ACT_StatusNotification, <<"StatusNotification">>).
  45. -define(OCPP_ACT_StopTransaction, <<"StopTransaction">>).
  46. -define(OCPP_ACT_TriggerMessage, <<"TriggerMessage">>).
  47. -define(OCPP_ACT_UnlockConnector, <<"UnlockConnector">>).
  48. -define(OCPP_ACT_UpdateFirmware, <<"UpdateFirmware">>).
  49. %% error codes for ocppj-1.6
  50. -define(OCPP_ERR_NotSupported, <<"NotSupported">>).
  51. -define(OCPP_ERR_InternalError, <<"InternalError">>).
  52. -define(OCPP_ERR_ProtocolError, <<"ProtocolError">>).
  53. -define(OCPP_ERR_SecurityError, <<"SecurityError">>).
  54. -define(OCPP_ERR_FormationViolation, <<"FormationViolation">>).
  55. -define(OCPP_ERR_PropertyConstraintViolation, <<"PropertyConstraintViolation">>).
  56. -define(OCPP_ERR_OccurenceConstraintViolation, <<"OccurenceConstraintViolation">>).
  57. -define(OCPP_ERR_TypeConstraintViolation, <<"TypeConstraintViolation">>).
  58. -define(OCPP_ERR_GenericError, <<"GenericError">>).
  59. -type utf8_string() :: unicode:unicode_binary().
  60. -type message_type() :: ?OCPP_MSG_TYPE_ID_CALL..?OCPP_MSG_TYPE_ID_CALLERROR.
  61. %% OCPP_ACT_Authorize..OCPP_ACT_UpdateFirmware
  62. -type action() :: utf8_string().
  63. -type frame() :: #{
  64. type := message_type(),
  65. %% The message ID serves to identify a request.
  66. %% Maximum of 36 characters, to allow for GUIDs
  67. id := utf8_string(),
  68. %% the name of the remote procedure or action.
  69. %% This will be a case-sensitive string.
  70. %% Only presented in ?OCPP_MSG_TYPE_ID_CALL
  71. action => action(),
  72. %% json map decoded by jsx and validated by json schema
  73. payload := null | map()
  74. }.
  75. -define(IS_REQ(F), F = #{type := ?OCPP_MSG_TYPE_ID_CALL}).
  76. -define(IS_REQ(F, Id), F = #{type := ?OCPP_MSG_TYPE_ID_CALL, id := Id}).
  77. -define(IS_RESP(F), F = #{type := ?OCPP_MSG_TYPE_ID_CALLRESULT}).
  78. -define(IS_RESP(F, Id), F = #{type := ?OCPP_MSG_TYPE_ID_CALLRESULT, id := Id}).
  79. -define(IS_ERROR(F), F = #{type := ?OCPP_MSG_TYPE_ID_CALLERROR}).
  80. -define(IS_ERROR(F, Id), F = #{type := ?OCPP_MSG_TYPE_ID_CALLERROR, id := Id}).
  81. -define(IS_BootNotification_RESP(Status, Interval), #{
  82. type := ?OCPP_MSG_TYPE_ID_CALLRESULT,
  83. payload := #{<<"status">> := Status, <<"interval">> := Interval}
  84. }).
  85. -define(ERR_FRAME(Id, Code, Desc), #{
  86. id => Id,
  87. type => ?OCPP_MSG_TYPE_ID_CALLERROR,
  88. error_code => Code,
  89. error_desc => Desc,
  90. error_details => null
  91. }).