Skip to content

Commit 8b45fac

Browse files
committed
Process incoming reports by upcating status of all EVSE
This may be a waste of effort since not every report will change the EVSE status, but I want to make sure we capture any changes so for now it is worth the extra overhead.
1 parent 332b77f commit 8b45fac

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/ocpp_device_model.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
-feature(maybe_expr, enable).
88

9-
-export([new/0, add_variable/5, add_attribute/8, get_value/5, update_attribute/6]).
9+
-export([new/0, add_variable/5, add_attribute/8, get_value/5, update_attribute/6, get_evse_availability/1]).
1010

1111
-export_type([device_model/0, attribute/0, charactersitics/0,
1212
variable_identifiers/0, attribute_type/0]).
@@ -246,6 +246,13 @@ get_value(#device_model{attributes = Attributes},
246246
_ -> error(ambiguous)
247247
end.
248248

249+
-spec get_evse_availability(DeviceModel :: device_model()) -> [{pos_integer(), string()}].
250+
get_evse_availability(#device_model{attributes = Attributes}) ->
251+
Component = make_component_identifier(<<"EVSE">>, [{evse, '$1'}]),
252+
Variable = make_variable_identifier(<<"AvailabilityState">>, []),
253+
[{EVSE, Availability}
254+
|| [EVSE, Availability] <- ets:match(Attributes, {{Component, Variable, 'Actual'}, '$2', '_', '_'})].
255+
249256
parse_value(_, undefined) ->
250257
undefined;
251258
parse_value(_, <<"">>) ->

src/ocpp_station.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,23 @@ process_report(ReportMsg, Data) ->
645645
if ToBeContinued ->
646646
Data;
647647
not ToBeContinued ->
648+
NewData = update_evse_status(Data),
648649
ocpp_handler:report_received(Data#data.stationid, RequestId),
649-
Data#data{expecting_report = lists:delete(RequestId, Data#data.expecting_report)}
650+
NewData#data{expecting_report = lists:delete(RequestId, Data#data.expecting_report)}
650651
end.
651652

653+
update_evse_status(Data) ->
654+
NewEVSE = lists:foldl(
655+
fun({EVSEId, Status}, Acc) ->
656+
maps:update_with(
657+
EVSEId,
658+
fun(EVSE) -> ocpp_evse:set_evse_status(EVSE, Status) end,
659+
Acc)
660+
end,
661+
Data#data.evse,
662+
ocpp_device_model:get_evse_availability(Data#data.device_model)),
663+
Data#data{evse = NewEVSE}.
664+
652665
process_report_data(ReportData, DeviceModel) ->
653666
ComponentName = ocpp_message:get(<<"component/name">>, ReportData),
654667
VariableName = ocpp_message:get(<<"variable/name">>, ReportData),

0 commit comments

Comments
 (0)