Skip to content

Commit b9985a7

Browse files
Conversion to fsm version 2 (#58)
* Conversion to fsm version 2: No linking with libfsm is required here, only the fsm.hpp must be included. The new fsm version makes it much easier to write state machines and suitable tests. The first D20 states have been adapted and a first SupportedAppProtocol state test has been added. A bug was found right here. Signed-off-by: Sebastian Lukas <sebastian.lukas@pionix.de> * Moved lib header to it's own folder * Bugfix for d20 SupportedAppProtocol transition * Added extra test for state request handle * Added template checks for state and result compliance to FSM * Updated for new FSM usage * Updated for comments/bugs Signed-off-by: AssemblyJohn <ioan.bogdann@gmail.com> --------- Signed-off-by: Sebastian Lukas <sebastian.lukas@pionix.de> Signed-off-by: AssemblyJohn <ioan.bogdann@gmail.com> Co-authored-by: Sebastian Lukas <sebastian.lukas@pionix.de>
1 parent 9b77420 commit b9985a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+741
-463
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ if (NOT DISABLE_EDM)
3737
# In EDM mode, we can't install exports (because the dependencies usually do not install their exports)
3838
set(ISO15118_INSTALL OFF)
3939
else()
40-
find_package(fsm REQUIRED)
4140
find_package(cbv2g REQUIRED)
4241
endif()
4342

dependencies.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
---
2-
libfsm:
3-
git: https://github.com/EVerest/libfsm.git
4-
git_tag: v0.2.0
5-
options: ["BUILD_EXAMPLES OFF"]
62
catch2:
73
git: https://github.com/catchorg/Catch2.git
84
git_tag: v3.7.1

include/iso15118/d20/context.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ class MessageExchange {
5252

5353
std::unique_ptr<MessageExchange> create_message_exchange(uint8_t* buf, const size_t len);
5454

55+
class StateBase;
56+
using BasePointerType = std::unique_ptr<StateBase>;
57+
5558
class Context {
5659
public:
5760
// FIXME (aw): bundle arguments
5861
Context(session::feedback::Callbacks, session::SessionLogger&, d20::SessionConfig,
5962
const std::optional<ControlEvent>&, MessageExchange&);
6063

64+
template <typename StateType, typename... Args> BasePointerType create_state(Args&&... args) {
65+
return std::make_unique<StateType>(*this, std::forward<Args>(args)...);
66+
}
67+
6168
std::unique_ptr<message_20::Variant> pull_request();
6269
message_20::Type peek_request_type() const;
6370

include/iso15118/d20/fsm.hpp

-31
This file was deleted.

include/iso15118/d20/state/authorization.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66
#include <iso15118/message/authorization.hpp>
77

88
namespace iso15118::d20::state {
9-
10-
struct Authorization : public FsmSimpleState {
11-
using FsmSimpleState::FsmSimpleState;
9+
struct Authorization : public StateBase {
10+
public:
11+
Authorization(Context& ctx) : StateBase(ctx, StateID::Authorization){};
1212

1313
void enter() final;
1414

15-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1616

1717
private:
1818
message_20::datatypes::AuthStatus authorization_status{message_20::datatypes::AuthStatus::Pending};

include/iso15118/d20/state/authorization_setup.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct AuthorizationSetup : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct AuthorizationSetup : public StateBase {
10+
AuthorizationSetup(Context& ctx) : StateBase(ctx, StateID::AuthorizationSetup) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516
};
1617

1718
} // namespace iso15118::d20::state

include/iso15118/d20/state/dc_cable_check.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct DC_CableCheck : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct DC_CableCheck : public StateBase {
10+
DC_CableCheck(Context& ctx) : StateBase(ctx, StateID::DC_CableCheck) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516

1617
private:
1718
bool cable_check_initiated{false};

include/iso15118/d20/state/dc_charge_loop.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
#include <cstdint>
88
#include <optional>
@@ -11,12 +11,13 @@
1111

1212
namespace iso15118::d20::state {
1313

14-
struct DC_ChargeLoop : public FsmSimpleState {
15-
using FsmSimpleState::FsmSimpleState;
14+
struct DC_ChargeLoop : public StateBase {
15+
DC_ChargeLoop(Context& ctx) : StateBase(ctx, StateID::DC_ChargeLoop) {
16+
}
1617

1718
void enter() final;
1819

19-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
20+
Result feed(Event) final;
2021

2122
private:
2223
float present_voltage{0};

include/iso15118/d20/state/dc_charge_parameter_discovery.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct DC_ChargeParameterDiscovery : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct DC_ChargeParameterDiscovery : public StateBase {
10+
DC_ChargeParameterDiscovery(Context& ctx) : StateBase(ctx, StateID::DC_ChargeParameterDiscovery) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516
};
1617

1718
} // namespace iso15118::d20::state

include/iso15118/d20/state/dc_pre_charge.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct DC_PreCharge : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct DC_PreCharge : public StateBase {
10+
DC_PreCharge(Context& ctx) : StateBase(ctx, StateID::DC_PreCharge) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516

1617
private:
1718
float present_voltage{0};

include/iso15118/d20/state/dc_welding_detection.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct DC_WeldingDetection : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct DC_WeldingDetection : public StateBase {
10+
DC_WeldingDetection(Context& ctx) : StateBase(ctx, StateID::DC_WeldingDetection) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516

1617
private:
1718
float present_voltage{0};

include/iso15118/d20/state/power_delivery.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
8-
9-
struct PowerDelivery : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
8+
struct PowerDelivery : public StateBase {
9+
PowerDelivery(Context& ctx) : StateBase(ctx, StateID::PowerDelivery) {
10+
}
1111

1212
void enter() final;
1313

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
14+
Result feed(Event) final;
1515

1616
private:
1717
float present_voltage{0};

include/iso15118/d20/state/schedule_exchange.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
#include <cstdint>
88
#include <optional>
99

1010
#include <iso15118/d20/dynamic_mode_parameters.hpp>
1111

1212
namespace iso15118::d20::state {
13-
14-
struct ScheduleExchange : public FsmSimpleState {
15-
using FsmSimpleState::FsmSimpleState;
13+
struct ScheduleExchange : public StateBase {
14+
ScheduleExchange(Context& ctx) : StateBase(ctx, StateID::ScheduleExchange) {
15+
}
1616

1717
void enter() final;
1818

19-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
19+
Result feed(Event) final;
2020

2121
private:
2222
UpdateDynamicModeParameters dynamic_parameters;

include/iso15118/d20/state/service_detail.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct ServiceDetail : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct ServiceDetail : public StateBase {
10+
public:
11+
ServiceDetail(Context& ctx) : StateBase(ctx, StateID::ServiceDetail) {
12+
}
1113

1214
void enter() final;
1315

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
16+
Result feed(Event) final;
1517
};
1618

1719
} // namespace iso15118::d20::state

include/iso15118/d20/state/service_discovery.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct ServiceDiscovery : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct ServiceDiscovery : public StateBase {
10+
public:
11+
ServiceDiscovery(Context& ctx) : StateBase(ctx, StateID::ServiceDiscovery) {
12+
}
1113

1214
void enter() final;
1315

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
16+
Result feed(Event) final;
1517
};
1618

1719
} // namespace iso15118::d20::state

include/iso15118/d20/state/service_selection.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct ServiceSelection : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct ServiceSelection : public StateBase {
10+
ServiceSelection(Context& ctx) : StateBase(ctx, StateID::ServiceSelection) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516
};
1617

1718
} // namespace iso15118::d20::state

include/iso15118/d20/state/session_setup.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
#pragma once
44
#include <string>
55

6-
#include "../fsm.hpp"
6+
#include "../states.hpp"
77

88
namespace iso15118::d20::state {
99

10-
struct SessionSetup : public FsmSimpleState {
11-
using FsmSimpleState::FsmSimpleState;
10+
struct SessionSetup : public StateBase {
11+
SessionSetup(Context& ctx) : StateBase(ctx, StateID::SessionSetup) {
12+
}
1213

1314
void enter() final;
1415

15-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
16+
Result feed(Event) final;
1617

1718
private:
1819
std::string evse_id;

include/iso15118/d20/state/session_stop.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// Copyright 2023 Pionix GmbH and Contributors to EVerest
33
#pragma once
44

5-
#include "../fsm.hpp"
5+
#include "../states.hpp"
66

77
namespace iso15118::d20::state {
88

9-
struct SessionStop : public FsmSimpleState {
10-
using FsmSimpleState::FsmSimpleState;
9+
struct SessionStop : public StateBase {
10+
SessionStop(Context& ctx) : StateBase(ctx, StateID::SessionStop) {
11+
}
1112

1213
void enter() final;
1314

14-
HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;
15+
Result feed(Event) final;
1516
};
1617

1718
} // namespace iso15118::d20::state

0 commit comments

Comments
 (0)