|
| 1 | +/* |
| 2 | +Copyright (c) 2020 Cedric Jimenez |
| 3 | +This file is part of OpenOCPP. |
| 4 | +
|
| 5 | +OpenOCPP is free software: you can redistribute it and/or modify |
| 6 | +it under the terms of the GNU Lesser General Public License as published by |
| 7 | +the Free Software Foundation, either version 2.1 of the License, or |
| 8 | +(at your option) any later version. |
| 9 | +
|
| 10 | +OpenOCPP is distributed in the hope that it will be useful, |
| 11 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +GNU Lesser General Public License for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU Lesser General Public License |
| 16 | +along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +*/ |
| 18 | + |
| 19 | +#include "DefaultBasicChargePointEventsHandler.h" |
| 20 | +#include "ChargePointDemoConfig.h" |
| 21 | + |
| 22 | +#include <iostream> |
| 23 | + |
| 24 | +using namespace std; |
| 25 | +using namespace ocpp::types; |
| 26 | +using namespace ocpp::types::ocpp20; |
| 27 | + |
| 28 | +/** @brief Constructor */ |
| 29 | +DefaultBasicChargePointEventsHandler::DefaultBasicChargePointEventsHandler(ChargePointDemoConfig& config, |
| 30 | + const std::filesystem::path& working_dir) |
| 31 | + : m_config(config), m_working_dir(working_dir), m_is_connected(false) |
| 32 | +{ |
| 33 | +} |
| 34 | + |
| 35 | +/** @brief Destructor */ |
| 36 | +DefaultBasicChargePointEventsHandler::~DefaultBasicChargePointEventsHandler() { } |
| 37 | + |
| 38 | +/** @copydoc void IChargePointEventsHandler20::connectionFailed(ocpp::types::ocpp20::RegistrationStatusEnumType) */ |
| 39 | +void DefaultBasicChargePointEventsHandler::connectionFailed(ocpp::types::ocpp20::RegistrationStatusEnumType status) |
| 40 | +{ |
| 41 | + cout << "Connection failed, previous registration status : " << RegistrationStatusEnumTypeHelper.toString(status) << endl; |
| 42 | +} |
| 43 | + |
| 44 | +/** @copydoc void IChargePointEventsHandler20::connectionStateChanged(bool) */ |
| 45 | +void DefaultBasicChargePointEventsHandler::connectionStateChanged(bool isConnected) |
| 46 | +{ |
| 47 | + cout << "Connection state changed : " << isConnected << endl; |
| 48 | + m_is_connected = isConnected; |
| 49 | +} |
| 50 | + |
| 51 | +/** @copydoc void IChargePointEventsHandler20::bootNotification(ocpp::types::ocpp20::RegistrationStatusEnumType, const ocpp::types::DateTime&) */ |
| 52 | +void DefaultBasicChargePointEventsHandler::bootNotification(ocpp::types::ocpp20::RegistrationStatusEnumType status, |
| 53 | + const ocpp::types::DateTime& datetime) |
| 54 | +{ |
| 55 | + cout << "Bootnotification : " << RegistrationStatusEnumTypeHelper.toString(status) << " - " << datetime.str() << endl; |
| 56 | +} |
| 57 | + |
| 58 | +/** @copydoc void IChargePointEventsHandler20::datetimeReceived(ocpp::types::DateTime) */ |
| 59 | +void DefaultBasicChargePointEventsHandler::datetimeReceived(const ocpp::types::DateTime& datetime) |
| 60 | +{ |
| 61 | + cout << "Date time received : " << datetime.str() << endl; |
| 62 | +} |
| 63 | + |
| 64 | +// IDeviceModel20 interface |
| 65 | + |
| 66 | +/** @brief Called to retrieve the value of a variable */ |
| 67 | +void DefaultBasicChargePointEventsHandler::getVariable(ocpp::types::ocpp20::GetVariableResultType& var) |
| 68 | +{ |
| 69 | + std::string value; |
| 70 | + m_config.getDeviceModelValue(var.component, var.variable, value); |
| 71 | + var.attributeValue.value().assign(std::move(value)); |
| 72 | + var.attributeStatus = GetVariableStatusEnumType::Accepted; |
| 73 | +} |
| 74 | + |
| 75 | +/** @brief Called to set the value of a variable */ |
| 76 | +ocpp::types::ocpp20::SetVariableStatusEnumType DefaultBasicChargePointEventsHandler::setVariable( |
| 77 | + const ocpp::types::ocpp20::SetVariableDataType& var) |
| 78 | +{ |
| 79 | + m_config.setDeviceModelValue(var.component, var.variable, var.attributeValue.str()); |
| 80 | + return SetVariableStatusEnumType::Accepted; |
| 81 | +} |
0 commit comments