Skip to content

Commit

Permalink
- Added Evse and Connector classes
Browse files Browse the repository at this point in the history
- moved ChargePointConnectionState back to 1.6
- improved ws connection and bootnotification handling
- implemented functional block Provisioning profile as draft (B01 - B08)
- renamed common ChargePoint to ChargingStationBase
- renamed ChargePointConfiguration to DeviceModelManager
- added method documentation
- implemented draft for state machine within connector class instead of using libfsm

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Feb 23, 2023
1 parent 767494f commit 58d7340
Show file tree
Hide file tree
Showing 24 changed files with 1,108 additions and 279 deletions.
19 changes: 19 additions & 0 deletions config/v201/component_schemas/InternalCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@
],
"default": "31536000",
"type": "integer"
},
"NumberOfConnectors": {
"characteristics": {
"minLimit": 1,
"maxLimit": 128,
"supportsMonitoring": true,
"dataType": "integer"
},
"attributes": [
{
"type": "Actual",
"mutability": "ReadOnly"
}
],
"minimum": 1,
"maximum": 128,
"default": "1",
"type": "integer"
}
},
"required": [
Expand All @@ -291,6 +309,7 @@
"ChargePointModel",
"ChargePointVendor",
"FirmwareVersion",
"NumberOfConnectors",
"SupportedCiphers12",
"SupportedCiphers13",
"WebsocketReconnectInterval"
Expand Down
4 changes: 4 additions & 0 deletions config/v201/component_schemas/SecurityCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
},
"SecurityProfile": {
"characteristics": {
"minLimit": 1,
"maxLimit": 3,
"supportsMonitoring": true,
"dataType": "integer"
},
Expand All @@ -128,6 +130,8 @@
}
],
"description": "The security profile used by the Charging Station.",
"minimum": 1,
"maximum": 3,
"type": "integer"
}
},
Expand Down
3 changes: 2 additions & 1 deletion config/v201/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"ChargePointModel": "Yeti",
"ChargePointVendor": "Pionix",
"FirmwareVersion": "0.4",
"NumberOfConnectors": 2,
"SupportedCiphers12": "ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES256,GCM-SHA384,AES128-GCM-SHA256,AES256-GCM-SHA384,TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256",
"SupportedCiphers13": "TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256",
"WebsocketReconnectInterval": 30
Expand Down Expand Up @@ -41,7 +42,7 @@
"TxUpdatedMeasurands": ""
},
"SecurityCtrlr": {
"SecurityProfile": 0,
"SecurityProfile": 1,
"OrganizationName": "Pionix",
"CertificateEntries": 100
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@

namespace ocpp {

/// \brief Common base class for OCPP1.6 and OCPP2.0.1 chargepoints
class ChargePoint {
/// \brief Common base class for OCPP1.6 and OCPP2.0.1 charging stations
class ChargingStationBase {

protected:
std::unique_ptr<Websocket> websocket;
std::shared_ptr<PkiHandler> pki_handler;
std::shared_ptr<MessageLogging> logging;
std::shared_ptr<DatabaseHandler> database_handler;

ChargePointConnectionState connection_state;

boost::shared_ptr<boost::asio::io_service::work> work;
boost::asio::io_service io_service;
std::thread io_service_thread;

public:
ChargePoint();
virtual ~ChargePoint(){};
ChargingStationBase();
virtual ~ChargingStationBase(){};
};

} // namespace ocpp
Expand Down
2 changes: 1 addition & 1 deletion include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ template <typename M> class MessageQueue {
/// \brief Handles a message timeout or a CALLERROR. \p enhanced_message_opt is set only in case of CALLERROR
void handle_timeout_or_callerror(const boost::optional<EnhancedMessage<M>>& enhanced_message_opt) {
std::lock_guard<std::mutex> lk(this->message_mutex);
EVLOG_warning << "Message timeout for: " << this->in_flight->messageType << " (" << this->in_flight->uniqueId()
EVLOG_warning << "Message timeout or CALLERROR for: " << this->in_flight->messageType << " (" << this->in_flight->uniqueId()
<< ")";
if (this->isTransactionMessage(this->in_flight)) {
if (this->in_flight->message_attempts < this->transaction_message_attempts) {
Expand Down
22 changes: 0 additions & 22 deletions include/ocpp/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,28 +254,6 @@ void from_json(const json& j, CallError& c);
/// \returns an output stream with the CallError written to
std::ostream& operator<<(std::ostream& os, const CallError& c);

/// \brief Contains the different connection states of the charge point
enum ChargePointConnectionState {
Disconnected,
Connected,
Booted,
Pending,
Rejected,
};
namespace conversions {
/// \brief Converts the given ChargePointConnectionState \p e to std::string
/// \returns a string representation of the ChargePointConnectionState
std::string charge_point_connection_state_to_string(ChargePointConnectionState e);

/// \brief Converts the given std::string \p s to ChargePointConnectionState
/// \returns a ChargePointConnectionState from a string representation
ChargePointConnectionState string_to_charge_point_connection_state(const std::string& s);
} // namespace conversions

/// \brief Writes the string representation of the given \p charge_point_connection_state
/// to the given output stream \p os \returns an output stream with the ChargePointConnectionState written to
std::ostream& operator<<(std::ostream& os, const ChargePointConnectionState& charge_point_connection_state);

/// \brief Contains the different connection states of the charge point
enum SessionStartedReason {
EVConnected,
Expand Down
5 changes: 3 additions & 2 deletions include/ocpp/v16/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <everest/timer.hpp>

#include <ocpp/common/charge_point.hpp>
#include <ocpp/common/charging_station_base.hpp>
#include <ocpp/common/database_handler.hpp>
#include <ocpp/common/message_queue.hpp>
#include <ocpp/common/schemas.hpp>
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace ocpp {
namespace v16 {

/// \brief Contains a ChargePoint implementation compatible with OCPP-J 1.6
class ChargePoint : ocpp::ChargePoint {
class ChargePoint : ocpp::ChargingStationBase {
private:
std::unique_ptr<MessageQueue<v16::MessageType>> message_queue;
std::map<int32_t, std::shared_ptr<Connector>> connectors;
Expand All @@ -82,6 +82,7 @@ class ChargePoint : ocpp::ChargePoint {
std::set<MessageType> allowed_message_types;
std::mutex allowed_message_types_mutex;
RegistrationStatus registration_status;
ChargePointConnectionState connection_state;
std::unique_ptr<ChargePointStates> status;
std::shared_ptr<ChargePointConfiguration> configuration;
std::shared_ptr<ocpp::DatabaseHandler> database_handler;
Expand Down
22 changes: 22 additions & 0 deletions include/ocpp/v16/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ SupportedFeatureProfiles string_to_supported_feature_profiles(const std::string&
/// \returns an output stream with the SupportedFeatureProfiles written to
std::ostream& operator<<(std::ostream& os, const SupportedFeatureProfiles& supported_feature_profiles);

/// \brief Contains the different connection states of the charge point
enum ChargePointConnectionState {
Disconnected,
Connected,
Booted,
Pending,
Rejected,
};
namespace conversions {
/// \brief Converts the given ChargePointConnectionState \p e to std::string
/// \returns a string representation of the ChargePointConnectionState
std::string charge_point_connection_state_to_string(ChargePointConnectionState e);

/// \brief Converts the given std::string \p s to ChargePointConnectionState
/// \returns a ChargePointConnectionState from a string representation
ChargePointConnectionState string_to_charge_point_connection_state(const std::string& s);
} // namespace conversions

/// \brief Writes the string representation of the given \p charge_point_connection_state
/// to the given output stream \p os \returns an output stream with the ChargePointConnectionState written to
std::ostream& operator<<(std::ostream& os, const ChargePointConnectionState& charge_point_connection_state);

/// \brief Combines a Measurand with an optional Phase
struct MeasurandWithPhase {
Measurand measurand; ///< A OCPP Measurand
Expand Down
62 changes: 53 additions & 9 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@

#include <future>

#include <ocpp/common/charge_point.hpp>
#include <ocpp/common/charging_station_base.hpp>

#include <ocpp/v201/charge_point_configuration.hpp>
#include <ocpp/v201/device_model_management.hpp>
#include <ocpp/v201/enums.hpp>
#include <ocpp/v201/evse.hpp>
#include <ocpp/v201/ocpp_types.hpp>
#include <ocpp/v201/types.hpp>

#include <ocpp/v201/messages/BootNotification.hpp>
#include <ocpp/v201/messages/GetBaseReport.hpp>
#include <ocpp/v201/messages/GetReport.hpp>
#include <ocpp/v201/messages/GetVariables.hpp>
#include <ocpp/v201/messages/Heartbeat.hpp>
#include <ocpp/v201/messages/NotifyReport.hpp>
#include <ocpp/v201/messages/SetVariables.hpp>
#include <ocpp/v201/messages/StatusNotification.hpp>
#include <ocpp/v201/messages/TriggerMessage.hpp>

namespace ocpp {
namespace v201 {

/// \brief Class implements OCPP2.0.1 charging point
class ChargePoint : ocpp::ChargePoint {
/// \brief Class implements OCPP2.0.1 Charging Station
class ChargePoint : ocpp::ChargingStationBase {

private:
std::unique_ptr<MessageQueue<v201::MessageType>> message_queue;
std::shared_ptr<ChargePointConfiguration> configuration;
std::shared_ptr<DeviceModelManager> device_model_manager;

std::map<int32_t, std::unique_ptr<Evse>> evses;

// timers
Everest::SteadyTimer heartbeat_timer;
Everest::SteadyTimer boot_notification_timer;

// states
RegistrationStatusEnum registration_status;
WebsocketConnectionStatusEnum websocket_connection_status;

// general message handling
template <class T> bool send(Call<T> call);
Expand All @@ -31,24 +49,50 @@ class ChargePoint : ocpp::ChargePoint {

void init_websocket();

void handle_message(const json& json_message, MessageType message_type);
void handle_message(const json& json_message, const MessageType& message_type);
void message_callback(const std::string& message);

// message requests

// Provisioning
void boot_notification_req();
void boot_notification_req(const BootReasonEnum& reason);
void notify_report_req(const int request_id, const int seq_no, const std::vector<ReportData>& report_data);

// Availability
void status_notification_req(const int32_t evse_id, const int32_t connector_id, const ConnectorStatusEnum status);
void heartbeat_req();

// message response handlers
// message handlers

// Provisioning
void handle_boot_notification_response(CallResult<BootNotificationResponse> call_result);
void handle_set_variables_req(Call<SetVariablesRequest> call);
void handle_get_variables_req(Call<GetVariablesRequest> call);
void handle_get_base_report_req(Call<GetBaseReportRequest> call);
void handle_get_report_req(Call<GetReportRequest> call);

public:
/// \brief Construct a new ChargePoint object
/// \param config OCPP json config
/// \param ocpp_main_path Path where utility files for OCPP are read and written to
/// \param message_log_path Path to where logfiles are written to
ChargePoint(const json& config, const std::string& ocpp_main_path, const std::string& message_log_path);

/// \brief Starts the ChargePoint, initializes and connects to the Websocket endpoint
bool start();
void start();

/// \brief Stops the ChargePoint. Disconnects the websocket connection and stops MessageQueue and all timers
void stop();

/// \brief Event handler that should be called when a session has started
/// \param evse_id
/// \param connector_id
void on_session_started(const int32_t evse_id, const int32_t connector_id);

/// \brief Event handler that should be called when a session has finished
/// \param evse_id
/// \param connector_id
void on_session_finished(const int32_t evse_id, const int32_t connector_id);
};

} // namespace v201
Expand Down
56 changes: 56 additions & 0 deletions include/ocpp/v201/connector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest

#include <functional>
#include <mutex>

#include <ocpp/v201/enums.hpp>

namespace ocpp {
namespace v201 {

/// \brief Enum for ConnectorEvents
enum class ConnectorEvent {
PlugIn,
PlugOut,
Reserve,
Error,
Unavailable,
ReservationFinished,
PlugInAndTokenValid,
ErrorCleared,
ErrorCleardOnOccupied,
ErrorCleardOnReserved,
UnavailableToAvailable,
UnavailableToOccupied,
UnavailableToReserved,
UnavailableFaulted
};

/// \brief Represents a Connector, thus electrical outlet on a Charging Station. Single physical Connector.
class Connector {
private:
int32_t connector_id;
ConnectorStatusEnum state;
std::mutex state_mutex;

std::function<void(const ConnectorStatusEnum& status)> status_notification_callback;

public:
/// \brief Construct a new Connector object
/// \param connector_id id of the connector
/// \param status_notification_callback callback executed when the state of the connector changes
Connector(const int32_t connector_id,
const std::function<void(const ConnectorStatusEnum& status)>& status_notification_callback);

/// \brief Get the state object
/// \return ConnectorStatusEnum
ConnectorStatusEnum get_state();

/// \brief Submits the given \p event to the state machine controller
/// \param event
void submit_event(ConnectorEvent event);
};

} // namespace v201
} // namespace ocpp
Loading

0 comments on commit 58d7340

Please sign in to comment.