-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session cost add message #1007
base: main
Are you sure you want to change the base?
Session cost add message #1007
Changes from 3 commits
305c444
49f3df9
07368e3
8f2382d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,11 +11,11 @@ | |||||
|
||||||
### User-specific price / SetUserPrice | ||||||
|
||||||
The User-specific price is used for display purposes only and can be sent as soon as the user identifies itself with an | ||||||
The User-specific price is used for display purposes only and can be sent as soon as the user identifies itself with an | ||||||
id token. It should not be used to calculate prices. | ||||||
Internally, the messages in the DataTransfer json (for 1.6) is converted to a `DisplayMessage`, defined in | ||||||
`common/types.hpp`. In case of multi language messages, they are all added to the DisplayMessage vector. | ||||||
If the message is sent when a transaction has already started, the session id will be included in the display message and the `IdentifierType` will be set to `SessionId`. If it has not started yet, the id token is sent with | ||||||
Internally, the messages in the DataTransfer json (for 1.6) is converted to a `SessionCostMessage`, defined in | ||||||
`common/types.hpp`. In case of multi language messages, they are all added to the SessionCostMessage vector. | ||||||
If the message is sent when a transaction has already started, the session id will be included in the session cost message and the `IdentifierType` will be set to `SessionId`. If it has not started yet, the id token is sent with | ||||||
`IdentifierType` set to `IdToken`. | ||||||
|
||||||
### Running cost and Final / total cost | ||||||
|
@@ -53,11 +53,11 @@ | |||||
For California Pricing to work, the following callbacks must be enabled: | ||||||
|
||||||
- `session_cost_callback`, used for running cost and final cost | ||||||
- `set_display_message_callback`, used to show a user specific price | ||||||
- `session_cost_message_callback`, used to show a user specific price | ||||||
|
||||||
## OCPP 2.0.1 | ||||||
|
||||||
OCPP 2.0.1 uses different mechanisms to send pricing information. The messages are converted to internally used structs as descripbed above. For California Pricing Requirements to work, DisplayMessage and TariffAndCost must be implemented as well. | ||||||
OCPP 2.0.1 uses different mechanisms to send pricing information. The messages are converted to internally used structs as descripbed above. For California Pricing Requirements to work, TariffAndCost must be implemented as well. | ||||||
|
||||||
### Device Model Variables | ||||||
|
||||||
|
@@ -82,22 +82,22 @@ | |||||
|
||||||
> **_NOTE:_** Tariff and cost can be enabled separately. To be able to use all functionality, it is recommended to | ||||||
enable both. If cost is enabled and tariff is not enabled, the total cost message will not contain the personal message (`set_running_cost_callback`). | ||||||
If tariff is enabled and cost is not enabled, the total cost message will only be a DisplayMessage | ||||||
(`set_display_message_callback`) containing the personal message(s). | ||||||
If tariff is enabled and cost is not enabled, the total cost message will only be a SessionCostMessage | ||||||
(`session_cost_message_callback`) containing the personal message(s). | ||||||
|
||||||
### Callbacks | ||||||
|
||||||
For California Pricing to work, the following callbacks must be enabled: | ||||||
|
||||||
- `set_running_cost_callback` | ||||||
- `set_display_message_callback` | ||||||
- `session_cost_message_callback` | ||||||
|
||||||
For the tariff information (the personal messages), the `set_display_message_callback` is used. The same callback is also used for the SetDisplayMessageRequest in OCPP. The latter does require an id, the former will not have an id. So when `GetDisplayMessageRequest` is called from the CSMS, the Tariff display messages (that do not have an id) should not be returned. They should also be removed as soon as the transaction has ended. | ||||||
For the tariff information (the personal messages), the `session_cost_message_callback` is used. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Driver specific tariffs / pricing information can be returned by the CSMS in the `AuthorizeResponse` message. In | ||||||
libocpp, the whole message is just forwared (pricing information is not extracted from it), because the pricing | ||||||
information is coupled to the authorize response. So when Tariff and Cost are enabled, the `idTokenInfo` field must be read for pricing information. | ||||||
|
||||||
Cost information is also sent by the CSMS in the TransactionEventResponse. In that case, the pricing / cost information | ||||||
is extracted from the message and a RunningCost message is sent containing the current cost and extra messages | ||||||
(optional). If only Tariff is enabled and there is a personal message in the TransationEventResponse, a DisplayMessage is sent. | ||||||
(optional). If only Tariff is enabled and there is a personal message in the TransationEventResponse, a SessionCostMessage is sent. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,6 +573,12 @@ class ChargePoint { | |
const std::function<DataTransferResponse(const RunningCost& session_cost, const uint32_t number_of_decimals)>& | ||
session_cost_callback); | ||
|
||
/// \brief Registers a callback function for the session cost text message (California Pricing Requirements). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would help to give a little bit more context here and to describe whats expected from the callback. |
||
/// \param session_cost_message_callback The callback | ||
/// \ingroup ocpp16_callbacks | ||
void register_session_cost_message_callback( | ||
const std::function<DataTransferResponse(const SessionCostMessage& message)>& session_cost_message_callback); | ||
|
||
/// \brief Register a callback function for display messages (used in California Pricing Requirements) | ||
/// \param set_display_message_callback The callback. | ||
/// \ingroup ocpp16_callbacks | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -161,6 +161,9 @@ struct Callbacks { | |||||
std::optional<std::string> currency_code)>> | ||||||
set_running_cost_callback; | ||||||
|
||||||
/// \brief Callback function is called when tariff message is set. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would help to give a little bit more context here and to describe whats expected from the callback. |
||||||
std::optional<std::function<void(const SessionCostMessage& message)>> session_cost_message_callback; | ||||||
|
||||||
/// \brief Callback function is called when a reservation request is received from the CSMS | ||||||
std::optional<std::function<ReserveNowStatusEnum(const ReserveNowRequest& request)>> reserve_now_callback; | ||||||
/// \brief Callback function is called when a cancel reservation request is received from the CSMS | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should now be able to drop
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not build in that case: it is missing |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3101,7 +3101,7 @@ DataTransferResponse ChargePointImpl::handle_set_user_price(const std::optional< | |||||||
return response; | ||||||||
} | ||||||||
|
||||||||
if (set_display_message_callback == nullptr) { | ||||||||
if (session_cost_message_callback == nullptr) { | ||||||||
EVLOG_error << "Received data transfer for set user price, but no callback is registered."; | ||||||||
return response; | ||||||||
} | ||||||||
|
@@ -3124,9 +3124,8 @@ DataTransferResponse ChargePointImpl::handle_set_user_price(const std::optional< | |||||||
return response; | ||||||||
} | ||||||||
|
||||||||
// Find transaction with given id tag | ||||||||
std::vector<DisplayMessage> messages; | ||||||||
DisplayMessage message; | ||||||||
SessionCostMessage session_cost_message; | ||||||||
std::vector<DisplayMessageContent> messages; | ||||||||
const auto t = this->transaction_handler->get_transaction_from_id_tag(id_token.value()); | ||||||||
std::string identifier_id; | ||||||||
IdentifierType identifier_type; | ||||||||
|
@@ -3137,33 +3136,38 @@ DataTransferResponse ChargePointImpl::handle_set_user_price(const std::optional< | |||||||
} else { | ||||||||
identifier_id = t->get_session_id(); | ||||||||
identifier_type = IdentifierType::SessionId; | ||||||||
const std::optional<int32_t> transaction_id = t->get_transaction_id(); | ||||||||
if (transaction_id != std::nullopt) { | ||||||||
session_cost_message.ocpp_transaction_id = std::to_string(transaction_id.value()); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
message.identifier_id = identifier_id; | ||||||||
message.identifier_type = identifier_type; | ||||||||
session_cost_message.identifier_id = identifier_id; | ||||||||
session_cost_message.identifier_type = identifier_type; | ||||||||
|
||||||||
if (data.contains("priceText")) { | ||||||||
message.message.message = data.at("priceText"); | ||||||||
DisplayMessageContent m; | ||||||||
m.message = data.at("priceText"); | ||||||||
if (this->configuration->getLanguage().has_value()) { | ||||||||
message.message.language = this->configuration->getLanguage().value(); | ||||||||
m.language = this->configuration->getLanguage().value(); | ||||||||
} | ||||||||
messages.push_back(m); | ||||||||
} | ||||||||
|
||||||||
messages.push_back(message); | ||||||||
|
||||||||
if (this->configuration->getCustomMultiLanguageMessagesEnabled() && data.contains("priceTextExtra") && | ||||||||
data.at("priceTextExtra").is_array()) { | ||||||||
for (const json& j : data.at("priceTextExtra")) { | ||||||||
DisplayMessage display_message; | ||||||||
display_message.identifier_id = identifier_id; | ||||||||
display_message.identifier_type = identifier_type; | ||||||||
display_message.message = j; | ||||||||
DisplayMessageContent message; | ||||||||
message = j; | ||||||||
|
||||||||
messages.push_back(display_message); | ||||||||
messages.push_back(message); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
response = this->set_display_message_callback(messages); | ||||||||
if (!messages.empty()) { | ||||||||
session_cost_message.message = messages; | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And you can drop this
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? |
||||||||
|
||||||||
response = this->session_cost_message_callback(session_cost_message); | ||||||||
return response; | ||||||||
} | ||||||||
|
||||||||
|
@@ -4597,6 +4601,11 @@ void ChargePointImpl::register_session_cost_callback( | |||||||
this->session_cost_callback = session_cost_callback; | ||||||||
} | ||||||||
|
||||||||
void ChargePointImpl::register_session_cost_message_callback( | ||||||||
const std::function<DataTransferResponse(const SessionCostMessage& message)>& session_cost_message_callback) { | ||||||||
this->session_cost_message_callback = session_cost_message_callback; | ||||||||
} | ||||||||
|
||||||||
void ChargePointImpl::register_set_display_message_callback( | ||||||||
const std::function<DataTransferResponse(const std::vector<DisplayMessage>& display_message)> | ||||||||
set_display_message_callback) { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.