Skip to content

Commit

Permalink
🚸 (rc): Set MagicCard via BLE
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Jan 30, 2023
1 parent 6b76777 commit de65ae2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
14 changes: 10 additions & 4 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "BLEServiceCommands.h"
#include "BLEServiceDeviceInformation.h"
#include "BLEServiceFileExchange.h"
#include "BLEServiceMagicCard.h"
#include "BLEServiceMonitoring.h"
#include "BLEServiceUpdate.h"

Expand Down Expand Up @@ -423,7 +424,10 @@ class RobotController : public interface::RobotController

// Setup callbacks for monitoring

_rfidkit.onTagActivated([this](const MagicCard &card) { onMagicCardAvailable(card); });
_rfidkit.onTagActivated([this](const MagicCard &card) {
onMagicCardAvailable(card);
_service_magic_card.setMagicCard(card);
});

_battery_kit.onDataUpdated([this](uint8_t level) {
auto is_charging = _battery.isCharging();
Expand Down Expand Up @@ -555,12 +559,14 @@ class RobotController : public interface::RobotController
BLEServiceCommands _service_commands {};
BLEServiceDeviceInformation _service_device_information {};
BLEServiceMonitoring _service_monitoring {};
BLEServiceMagicCard _service_magic_card {};
BLEServiceFileExchange _service_file_exchange {};
BLEServiceUpdate _service_update {};

std::array<interface::BLEService *, 6> services = {
&_service_battery, &_service_commands, &_service_device_information,
&_service_monitoring, &_service_file_exchange, &_service_update,
std::array<interface::BLEService *, 7> services = {
&_service_battery, &_service_commands, &_service_device_information,
&_service_monitoring, &_service_magic_card, &_service_file_exchange,
&_service_update,
};

uint8_t _emergency_stop_counter {0};
Expand Down
2 changes: 1 addition & 1 deletion libs/RobotKit/tests/RobotController_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class RobotControllerTest : public testing::Test
{
InSequence seq;

EXPECT_CALL(mbed_mock_gatt, addService).Times(6);
EXPECT_CALL(mbed_mock_gatt, addService).Times(7);
EXPECT_CALL(mbed_mock_gap, setEventHandler).Times(1);
EXPECT_CALL(mbed_mock_gatt, setEventHandler).Times(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_F(RobotControllerTest, initializeComponents)
{
InSequence seq;

EXPECT_CALL(mbed_mock_gatt, addService).Times(6);
EXPECT_CALL(mbed_mock_gatt, addService).Times(7);
EXPECT_CALL(mbed_mock_gap, setEventHandler).Times(1);
EXPECT_CALL(mbed_mock_gatt, setEventHandler).Times(1);

Expand Down
10 changes: 10 additions & 0 deletions libs/RobotKit/tests/RobotController_test_registerEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,13 @@ TEST_F(RobotControllerTest, onChargingBehaviorLevelAbove90)

rc.onChargingBehavior(battery_level);
}

TEST_F(RobotControllerTest, onTagActivated)
{
auto onTagActivated = rfidkit.getCallback();

// TODO: Specify which BLE service and what is expected if necessary
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).Times(2);

onTagActivated(MagicCard::none);
}

0 comments on commit de65ae2

Please sign in to comment.