Skip to content

Commit ed3a647

Browse files
authored
Merge pull request #191 from c-jimenez/integ/dev_mahdidadashi65
Allow to send infos in status notifications messages even if their are no errors + fix decimal precision to 1 digit
2 parents 629a28b + 90409e6 commit ed3a647

File tree

8 files changed

+27
-13
lines changed

8 files changed

+27
-13
lines changed

examples/common/DefaultChargePointEventsHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ bool DefaultChargePointEventsHandler::remoteStartTransactionRequested(unsigned i
169169
bool ret = false;
170170
cout << "Remote start transaction : " << connector_id << " - " << id_tag << endl;
171171

172-
if(connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
172+
if (connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
173173
{
174-
ret=false;
174+
ret = false;
175175
}
176176
else
177177
{
178178
m_remote_start_pending[connector_id - 1u] = true;
179179
m_remote_start_id_tag[connector_id - 1u] = id_tag;
180-
ret=true;
180+
ret = true;
181181
}
182182
return ret;
183183
}

examples/common/config/OcppConfig.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ ocpp::types::ConfigurationStatus OcppConfig::setConfiguration(const std::string&
207207
}
208208
}
209209

210-
if (ret != ConfigurationStatus::Rejected)
211-
{
210+
if (ret != ConfigurationStatus::Rejected)
211+
{
212212
if ((it->second & PARAM_OCPP) != 0)
213213
{
214214
m_config.set(OCPP_PARAMS, key, value);
@@ -225,7 +225,7 @@ ocpp::types::ConfigurationStatus OcppConfig::setConfiguration(const std::string&
225225
{
226226
ret = ConfigurationStatus::Accepted;
227227
}
228-
}
228+
}
229229
}
230230
else
231231
{

src/chargepoint/smartcharging/ProfileDatabase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ std::string ProfileDatabase::serialize(const ocpp::types::ChargingProfile& profi
362362

363363
rapidjson::StringBuffer buffer;
364364
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
365+
writer.SetMaxDecimalPlaces(1); // OCPP decimals have 1 digit precision
365366
profile_json.Accept(writer);
366367
profile_str = buffer.GetString();
367368
return profile_str;

src/chargepoint/smartcharging/SmartChargingManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
303303
}
304304
else
305305
{
306-
ret = false;
306+
ret = false;
307307
error_message = "Recurring profiles must have a start schedule and a duration";
308308
}
309309
}

src/messages/IMessageConverter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ class IMessageConverter
9494
json.AddMember(rapidjson::StringRef(name), rapidjson::Value(value), *allocator);
9595
}
9696

97+
/**
98+
* @brief Helper function to fill a floating point value in a JSON object
99+
* @param json JSON object to fill
100+
* @param field Name of the field to fill
101+
* @param value Floating point value to fill
102+
*/
103+
void fill(rapidjson::Value& json, const char* name, const double value)
104+
{
105+
json.AddMember(rapidjson::StringRef(name), rapidjson::Value(value), *allocator);
106+
}
107+
97108
/**
98109
* @brief Helper function to fill a string value in a JSON object
99110
* @param json JSON object to fill

src/messages/StatusNotification.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ bool StatusNotificationReqConverter::fromJson(const rapidjson::Value& json,
7171
extract(json, "info", data.info);
7272
data.status = ChargePointStatusHelper.fromString(json["status"].GetString());
7373
ret = ret && extract(json, "timestamp", data.timestamp, error_message);
74-
extract(json, "info", data.vendorId);
75-
extract(json, "info", data.vendorErrorCode);
74+
extract(json, "vendorId", data.vendorId);
75+
extract(json, "vendorErrorCode", data.vendorErrorCode);
7676
if (!ret)
7777
{
7878
error_code = ocpp::rpc::IRpc::RPC_ERROR_TYPE_CONSTRAINT_VIOLATION;
@@ -87,12 +87,12 @@ bool StatusNotificationReqConverter::toJson(const StatusNotificationReq& data, r
8787
fill(json, "errorCode", ChargePointErrorCodeHelper.toString(data.errorCode));
8888
fill(json, "status", ChargePointStatusHelper.toString(data.status));
8989
fill(json, "timestamp", data.timestamp);
90-
if (data.errorCode != ChargePointErrorCode::NoError)
91-
{
90+
if (data.info.isSet())
9291
fill(json, "info", data.info);
92+
if (data.vendorId.isSet())
9393
fill(json, "vendorId", data.vendorId);
94+
if (data.vendorErrorCode.isSet())
9495
fill(json, "vendorErrorCode", data.vendorErrorCode);
95-
}
9696
return true;
9797
}
9898

src/rpc/RpcBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ bool RpcBase::call(const std::string& action,
7575
// Serialize message
7676
rapidjson::StringBuffer buffer;
7777
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
78+
writer.SetMaxDecimalPlaces(1); // OCPP decimals have 1 digit precision
7879
payload.Accept(writer);
7980

8081
std::stringstream serialized_message;
@@ -186,6 +187,7 @@ void RpcBase::processIncomingRequest(std::shared_ptr<RpcMessage>& rpc_message)
186187
// Serialize message
187188
rapidjson::StringBuffer buffer;
188189
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
190+
writer.SetMaxDecimalPlaces(1); // OCPP decimals have 1 digit precision
189191
response.Accept(writer);
190192

191193
std::stringstream serialized_message;

src/websockets/libwebsockets/LibWebsocketClientPool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void LibWebsocketClientPool::process()
144144

145145
// Dummy vhost to handle context related events
146146
struct lws_protocols protocols[] = {{"LibWebsocketClientPool", &LibWebsocketClientPool::eventCallback, 0, 0, 0, this, 0},
147-
LWS_PROTOCOL_LIST_TERM};
147+
LWS_PROTOCOL_LIST_TERM};
148148
struct lws_context_creation_info vhost_info;
149149
memset(&vhost_info, 0, sizeof(vhost_info));
150150
vhost_info.protocols = protocols;

0 commit comments

Comments
 (0)