Skip to content

Commit

Permalink
* changed from get_connector_effective_status to individual_connector…
Browse files Browse the repository at this point in the history
…_status in send_status_notification_single_connector_internal

* applied same change in initialize_reported_state_cache
* removed unused function connector_status_to_operational_status
* fixed CMakeLists.txt in test dir
* removed obsolete test cases

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Jan 18, 2024
1 parent 34c8cbb commit 468bedb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 98 deletions.
Binary file not shown.
19 changes: 7 additions & 12 deletions lib/ocpp/v201/component_state_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@

namespace ocpp::v201 {

static OperationalStatusEnum connector_status_to_operational_status(ConnectorStatusEnum connector_status) {
if (connector_status == ConnectorStatusEnum::Unavailable || connector_status == ConnectorStatusEnum::Faulted) {
return OperationalStatusEnum::Inoperative;
} else {
return OperationalStatusEnum::Operative;
}
}

void ComponentStateManager::read_all_states_from_database_or_set_defaults(
const std::map<int32_t, int32_t>& evse_connector_structure) {

Expand Down Expand Up @@ -54,9 +46,10 @@ void ComponentStateManager::initialize_reported_state_cache() {

OperationalStatusEnum evse_effective = this->get_evse_effective_operational_status(evse_id);
for (int connector_id = 1; connector_id <= num_connectors; connector_id++) {
ConnectorStatusEnum connector_effective = this->get_connector_effective_status(evse_id, connector_id);
connector_statuses.push_back(connector_effective);
connector_op_statuses.push_back(connector_status_to_operational_status(connector_effective));
ConnectorStatusEnum connector_status =
this->individual_connector_status(evse_id, connector_id).to_connector_status();
connector_statuses.push_back(connector_status);
connector_op_statuses.push_back(this->get_connector_effective_operational_status(evse_id, connector_id));
}

this->last_evse_and_connector_effective_operational_statuses.push_back(
Expand Down Expand Up @@ -294,9 +287,11 @@ void ComponentStateManager::trigger_all_effective_availability_changed_callbacks
this->trigger_callbacks_cs(false);
}

// TODO(Piet): Move to connector file
void ComponentStateManager::send_status_notification_single_connector_internal(int32_t evse_id, int32_t connector_id,
bool only_if_changed) {
ConnectorStatusEnum connector_status = this->get_connector_effective_status(evse_id, connector_id);
ConnectorStatusEnum connector_status =
this->individual_connector_status(evse_id, connector_id).to_connector_status();
ConnectorStatusEnum& last_reported_status = this->last_connector_reported_status(evse_id, connector_id);
if (!only_if_changed || last_reported_status != connector_status) {
if (this->send_connector_status_notification_callback(evse_id, connector_id, connector_status)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ add_subdirectory(lib/ocpp/common)

add_executable(utils_tests utils_tests.cpp)

target_include_directories(utils_tests PUBLIC${GTEST_INCLUDE_DIRS})
target_include_directories(utils_tests PUBLIC ${GTEST_INCLUDE_DIRS})

target_link_libraries(utils_tests PRIVATE
ocpp
Expand Down
85 changes: 0 additions & 85 deletions tests/lib/ocpp/v201/test_component_state_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,64 +361,6 @@ TEST_F(ComponentStateManagerTest, test_effective_state_changed_callbacks) {
state_mgr.set_cs_individual_operational_status(OperationalStatusEnum::Operative, false);
}

/// \brief Test the ComponentStateManager calls "status notification" callbacks correctly at run-time
TEST_F(ComponentStateManagerTest, test_status_notification_callbacks) {
// Prepare
std::shared_ptr<DatabaseHandler> mock_database = std::make_shared<DatabaseHandlerMock>();
auto state_mgr = this->component_state_manager(mock_database, {1, 2});

// Set up mock expectations
testing::Sequence seq;
// EVSE 1 connector 1 set to Occupied
EXPECT_CALL(this->callbacks, connector_status_update(1, 1, "Occupied"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
// EVSE 2 disabled
EXPECT_CALL(this->callbacks, connector_status_update(2, 1, "Unavailable"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
EXPECT_CALL(this->callbacks, connector_status_update(2, 2, "Unavailable"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
// CS disabled
EXPECT_CALL(this->callbacks, connector_status_update(1, 1, "Unavailable"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
// EVSE 2 re-enabled
// EVSE 2 connector 1 faulted
// CS re-enabled
EXPECT_CALL(this->callbacks, connector_status_update(1, 1, "Occupied"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
EXPECT_CALL(this->callbacks, connector_status_update(2, 1, "Faulted"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
EXPECT_CALL(this->callbacks, connector_status_update(2, 2, "Available"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));

// Act & Verify
state_mgr.set_connector_occupied(1, 1, true);
state_mgr.set_evse_individual_operational_status(2, OperationalStatusEnum::Inoperative, false);
state_mgr.set_connector_unavailable(2, 1, true);
state_mgr.set_connector_unavailable(2, 2, true);
state_mgr.set_cs_individual_operational_status(OperationalStatusEnum::Inoperative, false);
state_mgr.set_connector_unavailable(1, 1, true);
state_mgr.set_evse_individual_operational_status(2, OperationalStatusEnum::Operative, false);
state_mgr.set_connector_faulted(2, 1, true);
state_mgr.set_cs_individual_operational_status(OperationalStatusEnum::Operative, false);
state_mgr.set_connector_unavailable(1, 1, false);
state_mgr.set_connector_unavailable(2, 1, false);
state_mgr.set_connector_unavailable(2, 2, false);
}

/// \brief Test the ComponentStateManager::trigger_all_effective_availability_changed_callbacks()
TEST_F(ComponentStateManagerTest, test_trigger_boot_callbacks) {
// Prepare
Expand Down Expand Up @@ -455,33 +397,6 @@ TEST_F(ComponentStateManagerTest, test_trigger_boot_callbacks) {
state_mgr.trigger_all_effective_availability_changed_callbacks();
}

/// \brief Test the ComponentStateManager::send_status_notification_all_connectors()
TEST_F(ComponentStateManagerTest, test_send_status_notification_all_connectors) {
// Prepare
std::shared_ptr<DatabaseHandler> mock_database = std::make_shared<DatabaseHandlerMock>();
// EVSE 1 disabled on boot
mock_database->insert_evse_availability(1, OperationalStatusEnum::Inoperative, true);
auto state_mgr = this->component_state_manager(mock_database, {1, 2});

// Set up mock expectations
testing::Sequence seq;
EXPECT_CALL(this->callbacks, connector_status_update(1, 1, "Unavailable"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
EXPECT_CALL(this->callbacks, connector_status_update(2, 1, "Available"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));
EXPECT_CALL(this->callbacks, connector_status_update(2, 2, "Available"))
.Times(1)
.InSequence(seq)
.WillOnce(testing::Return(true));

// Act & Verify
state_mgr.send_status_notification_all_connectors();
}

/// \brief Test the ComponentStateManager::send_status_notification_changed_connectors()
TEST_F(ComponentStateManagerTest, test_send_status_notification_changed_connectors) {
// Prepare
Expand Down

0 comments on commit 468bedb

Please sign in to comment.