-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀️ Merge branch 'yann/feature/ble/display-image' into develop
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Leka - LekaOS | ||
// Copyright 2024 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <span> | ||
|
||
#include "Utils.h" | ||
#include "interface/Command.h" | ||
#include "interface/libs/VideoKit.h" | ||
|
||
namespace leka { | ||
|
||
struct VideoCommand : interface::Command { | ||
explicit VideoCommand(interface::VideoKit &kit) : _videokit(kit) {} | ||
|
||
auto id() -> uint8_t override { return cmd::id; } | ||
|
||
auto data() -> uint8_t * override | ||
{ | ||
args = {}; | ||
return args.data(); | ||
} | ||
|
||
[[nodiscard]] auto size() const -> std::size_t override { return std::size(args); } | ||
|
||
auto execute() -> bool override | ||
{ | ||
auto [id_high, id_low, chcksm] = std::tuple_cat(args); | ||
|
||
auto expected = [&] { return utils::math::checksum8(std::span {args.data(), args.size() - 1}); }; | ||
|
||
if (chcksm != expected()) { | ||
return false; | ||
} | ||
|
||
auto id = (id_high << 8) | id_low; | ||
std::array<char, 32> image_path = {}; | ||
snprintf(image_path.data(), image_path.size(), "/fs/home/img/id/%.4X.jpg", id); | ||
|
||
_videokit.fillWhiteBackgroundAndDisplayImage(std::filesystem::path {image_path.data()}); | ||
|
||
return true; | ||
} | ||
|
||
private: | ||
struct cmd { | ||
static constexpr auto id = uint8_t {0x80}; | ||
static constexpr auto size = uint8_t {2 + 1}; // image_id + Checksum | ||
}; | ||
|
||
std::array<uint8_t, cmd::size> args {}; | ||
interface::VideoKit &_videokit; | ||
}; | ||
|
||
} // namespace leka |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Leka - LekaOS | ||
// Copyright 2024 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CommandKit.h" | ||
#include "commands/VideoCommand.h" | ||
#include "gtest/gtest.h" | ||
#include "mocks/leka/VideoKit.h" | ||
|
||
using namespace leka; | ||
|
||
class VideoCommandTest : public testing::Test | ||
{ | ||
protected: | ||
// void SetUp() override {} | ||
// void TearDown() override {} | ||
|
||
mock::VideoKit mock_videokit {}; | ||
|
||
VideoCommand video_command {mock_videokit}; | ||
}; | ||
|
||
TEST_F(VideoCommandTest, initialization) | ||
{ | ||
EXPECT_NE(&video_command, nullptr); | ||
} | ||
|
||
TEST_F(VideoCommandTest, commandID) | ||
{ | ||
auto expected_cmd_id = 0x80; | ||
auto actual_cmd_id = video_command.id(); | ||
|
||
EXPECT_EQ(actual_cmd_id, expected_cmd_id); | ||
} | ||
|
||
TEST_F(VideoCommandTest, commandSize) | ||
{ | ||
auto expected_cmd_size = uint8_t {2 + 1}; // image_id + Checksum | ||
auto actual_cmd_size = video_command.size(); | ||
|
||
EXPECT_EQ(actual_cmd_size, expected_cmd_size); | ||
} | ||
|
||
TEST_F(VideoCommandTest, execute) | ||
{ | ||
auto command = std::to_array({0x00, 0x7C, 0x7C}); | ||
auto expected_path = std::filesystem::path("/fs/home/img/id/007C.jpg"); | ||
|
||
auto *command_data = video_command.data(); | ||
std::copy(command.begin(), command.end(), command_data); | ||
|
||
EXPECT_CALL(mock_videokit, fillWhiteBackgroundAndDisplayImage(expected_path)); | ||
video_command.execute(); | ||
} | ||
|
||
TEST_F(VideoCommandTest, executeIncorrectChecksum) | ||
{ | ||
auto command = std::to_array({0x00, 0x7C, 0x22}); | ||
|
||
auto *command_data = video_command.data(); | ||
std::copy(command.begin(), command.end(), command_data); | ||
|
||
EXPECT_CALL(mock_videokit, fillWhiteBackgroundAndDisplayImage).Times(0); | ||
video_command.execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters