Add preset polish and broadcast metadata (fw 0.8.0).
Ship station reorder, DAB playing ids in presets, RDS PS/RT and DAB DLS in tuner status, Si4684 data-service read, host tests, and UI now-playing lines. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -41,6 +41,9 @@ add_library(digiradio_core STATIC
|
||||
"${CORE_SRC_DIR}/StationList.cpp"
|
||||
"${CORE_SRC_DIR}/StationListJson.cpp"
|
||||
"${CORE_SRC_DIR}/BluetoothJson.cpp"
|
||||
"${CORE_SRC_DIR}/BroadcastLabel.cpp"
|
||||
"${CORE_SRC_DIR}/RdsMetadataAccumulator.cpp"
|
||||
"${CORE_SRC_DIR}/DabDynamicLabelAccumulator.cpp"
|
||||
)
|
||||
target_include_directories(digiradio_core PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
|
||||
@@ -78,6 +81,18 @@ add_executable(enhancements_design_test enhancements_design_test.cpp)
|
||||
target_link_libraries(enhancements_design_test PRIVATE digiradio_core)
|
||||
add_test(NAME enhancements_design_test COMMAND enhancements_design_test)
|
||||
|
||||
add_executable(station_service_test station_service_test.cpp)
|
||||
target_include_directories(station_service_test PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/station/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/tuner/include"
|
||||
)
|
||||
target_sources(station_service_test PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/station/src/StationService.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/tuner/src/TunerService.cpp"
|
||||
)
|
||||
target_link_libraries(station_service_test PRIVATE digiradio_core)
|
||||
add_test(NAME station_service_test COMMAND station_service_test)
|
||||
|
||||
add_executable(station_list_test station_list_test.cpp)
|
||||
target_link_libraries(station_list_test PRIVATE digiradio_core)
|
||||
add_test(NAME station_list_test COMMAND station_list_test)
|
||||
@@ -85,3 +100,7 @@ add_test(NAME station_list_test COMMAND station_list_test)
|
||||
add_executable(bt1035_at_test bt1035_at_test.cpp)
|
||||
target_link_libraries(bt1035_at_test PRIVATE digiradio_core)
|
||||
add_test(NAME bt1035_at_test COMMAND bt1035_at_test)
|
||||
|
||||
add_executable(broadcast_metadata_test broadcast_metadata_test.cpp)
|
||||
target_link_libraries(broadcast_metadata_test PRIVATE digiradio_core)
|
||||
add_test(NAME broadcast_metadata_test COMMAND broadcast_metadata_test)
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file broadcast_metadata_test.cpp
|
||||
* @brief Host tests for broadcast metadata parsing (RDS / DLS).
|
||||
*
|
||||
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||
*
|
||||
* Copyright 2026 Michele Bigi
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
|
||||
#include "core/BroadcastLabel.hpp"
|
||||
#include "core/DabDynamicLabelAccumulator.hpp"
|
||||
#include "core/RdsMetadataAccumulator.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] int runChipLabelTrimTest()
|
||||
{
|
||||
const auto label = core::BroadcastLabel::tryFromChipBytes(" RAI 1 \0\0");
|
||||
if (!label || label->value() != "RAI 1") {
|
||||
std::cerr << "chip label trim failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runRdsProgramNameTest()
|
||||
{
|
||||
core::RdsMetadataAccumulator acc;
|
||||
acc.applyGroup(0U, 0x0000U, 0x5445U, 0U);
|
||||
acc.applyGroup(0U, 0x0002U, 0x5354U, 0U);
|
||||
acc.applyGroup(0U, 0x0004U, 0x2020U, 0U);
|
||||
acc.applyGroup(0U, 0x0006U, 0x2020U, 0U);
|
||||
|
||||
const auto name = acc.programName();
|
||||
if (!name || name->value() != "TEST") {
|
||||
std::cerr << "RDS PS parse failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runRdsRadiotextTest()
|
||||
{
|
||||
core::RdsMetadataAccumulator acc;
|
||||
acc.applyGroup(0U, 0x2000U, 0x4E6FU, 0x7720U);
|
||||
|
||||
const auto text = acc.radiotext();
|
||||
if (!text || text->value() != "Now") {
|
||||
std::cerr << "RDS RT parse failed: "
|
||||
<< (text ? std::string(text->value()) : "nullopt") << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runDabDynamicLabelTest()
|
||||
{
|
||||
core::DabDynamicLabelAccumulator acc;
|
||||
const std::vector<std::uint8_t> payload = {'L', 'i', 'v', 'e', ' ', 'D', 'J'};
|
||||
acc.applySegment(0U, 1U, payload);
|
||||
|
||||
const auto label = acc.label();
|
||||
if (!label || label->value() != "Live DJ") {
|
||||
std::cerr << "DLS single-segment parse failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runDabDynamicLabelSegmentsTest()
|
||||
{
|
||||
core::DabDynamicLabelAccumulator acc;
|
||||
const std::vector<std::uint8_t> part1 = {'A', 'B', 'C'};
|
||||
const std::vector<std::uint8_t> part2 = {'D', 'E', 'F'};
|
||||
acc.applySegment(0U, 2U, part1);
|
||||
acc.applySegment(1U, 2U, part2);
|
||||
|
||||
const auto label = acc.label();
|
||||
if (!label || label->value() != "ABCDEF") {
|
||||
std::cerr << "DLS multi-segment parse failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
if (runChipLabelTrimTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runRdsProgramNameTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runRdsRadiotextTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runDabDynamicLabelTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runDabDynamicLabelSegmentsTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -81,6 +81,37 @@ namespace {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runParseStationReorderJsonTest()
|
||||
{
|
||||
const auto parsed =
|
||||
core::parseStationReorderJson(R"({"from":1,"to":0})");
|
||||
if (!parsed || parsed->fromIndex != 1U || parsed->toIndex != 0U) {
|
||||
std::cerr << "reorder parse failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runStationListReorderTest()
|
||||
{
|
||||
core::StationList list;
|
||||
if (auto a = list.add(makeFmStation("A", 88000U, 1U)); !a) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (auto b = list.add(makeFmStation("B", 90000U, 2U)); !b) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (auto moved = list.move(1U, 0U); !moved) {
|
||||
std::cerr << "move failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (list.stations()[0U].name().value() != "B") {
|
||||
std::cerr << "expected B first after reorder\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -94,5 +125,11 @@ int main()
|
||||
if (runParseStationJsonTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runParseStationReorderJsonTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runStationListReorderTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
* @file station_service_test.cpp
|
||||
* @brief Host tests for StationService with in-memory fake store.
|
||||
*
|
||||
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||
*
|
||||
* Copyright 2026 Michele Bigi
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
|
||||
#include "core/FrequencyKHz.hpp"
|
||||
#include "core/ISecureStore.hpp"
|
||||
#include "core/StationListJson.hpp"
|
||||
#include "core/StationName.hpp"
|
||||
#include "core/TunerBand.hpp"
|
||||
#include "station/StationService.hpp"
|
||||
#include "tuner/TunerService.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeTuner final : public core::ITuner {
|
||||
public:
|
||||
[[nodiscard]] std::expected<void, core::TunerError> boot(
|
||||
core::TunerBand) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<core::TunerBand, core::TunerError> currentBand()
|
||||
const override
|
||||
{
|
||||
return core::TunerBand::Dab;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<core::TunerStatus, core::TunerError> readStatus()
|
||||
override
|
||||
{
|
||||
core::TunerStatus status = {};
|
||||
status.booted = true;
|
||||
status.band = core::TunerBand::Dab;
|
||||
status.locked = true;
|
||||
status.volume = 40;
|
||||
status.dabFreqIndex = 12U;
|
||||
return status;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::TunerError> tuneDab(
|
||||
std::uint8_t) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::TunerError> tuneFm(
|
||||
core::FrequencyKHz) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<core::FrequencyKHz, core::TunerError> seekFm(
|
||||
core::SeekDirection) override
|
||||
{
|
||||
return std::unexpected(core::TunerError::WrongBand);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<std::vector<core::TunerServiceEntry>,
|
||||
core::TunerError>
|
||||
listDabServices() override
|
||||
{
|
||||
return std::vector<core::TunerServiceEntry>{};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::TunerError> playDabService(
|
||||
std::uint32_t, std::uint32_t) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::TunerError> setVolume(
|
||||
std::uint8_t) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
class FakeSecureStore final : public core::ISecureStore {
|
||||
public:
|
||||
[[nodiscard]] bool hasWifiCredentials() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::StoreError> saveWifiCredentials(
|
||||
const core::WifiCredentials&) override
|
||||
{
|
||||
return std::unexpected(core::StoreError::IoFailed);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<core::WifiCredentials, core::StoreError>
|
||||
loadWifiCredentials() const override
|
||||
{
|
||||
return std::unexpected(core::StoreError::NotFound);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::StoreError> clearWifiCredentials()
|
||||
override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] bool hasStationList() const override
|
||||
{
|
||||
return stationJson_.has_value();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::StoreError> saveStationListJson(
|
||||
std::string_view json) override
|
||||
{
|
||||
stationJson_ = std::string(json);
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<std::string, core::StoreError>
|
||||
loadStationListJson() const override
|
||||
{
|
||||
if (!stationJson_) {
|
||||
return std::unexpected(core::StoreError::NotFound);
|
||||
}
|
||||
return *stationJson_;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<void, core::StoreError> clearStationList()
|
||||
override
|
||||
{
|
||||
stationJson_.reset();
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<std::string> stationJson_;
|
||||
};
|
||||
|
||||
[[nodiscard]] core::Station makeFmStation(const char* name, std::uint32_t khz)
|
||||
{
|
||||
return core::Station(
|
||||
*core::StationName::tryFrom(name),
|
||||
core::TunerBand::Fm,
|
||||
0U,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
*core::FrequencyKHz::tryFromKhz(khz),
|
||||
std::nullopt);
|
||||
}
|
||||
|
||||
[[nodiscard]] int runPersistRoundTripTest()
|
||||
{
|
||||
FakeSecureStore store;
|
||||
FakeTuner tuner;
|
||||
tuner::TunerService tunerService(tuner);
|
||||
station::StationService service(store, tunerService);
|
||||
|
||||
if (auto added = service.add(makeFmStation("Jazz", 101500U)); !added) {
|
||||
std::cerr << "add failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
station::StationService reloaded(store, tunerService);
|
||||
if (auto loaded = reloaded.loadFromStore(); !loaded) {
|
||||
std::cerr << "load failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (reloaded.list().stations().size() != 1U) {
|
||||
std::cerr << "expected one preset after reload\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runReorderPersistTest()
|
||||
{
|
||||
FakeSecureStore store;
|
||||
FakeTuner tuner;
|
||||
tuner::TunerService tunerService(tuner);
|
||||
station::StationService service(store, tunerService);
|
||||
|
||||
if (auto a = service.add(makeFmStation("A", 88000U)); !a) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (auto b = service.add(makeFmStation("B", 90000U)); !b) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (auto moved = service.reorder(1U, 0U); !moved) {
|
||||
std::cerr << "reorder failed\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
station::StationService reloaded(store, tunerService);
|
||||
if (auto loaded = reloaded.loadFromStore(); !loaded) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (reloaded.list().stations()[0U].name().value() != "B") {
|
||||
std::cerr << "reorder not persisted\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
if (runPersistRoundTripTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runReorderPersistTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "core/TunerBand.hpp"
|
||||
#include "core/TunerJson.hpp"
|
||||
#include "core/TunerStatus.hpp"
|
||||
#include "core/BroadcastLabel.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
@@ -102,6 +103,26 @@ namespace {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runTunerStatusPlayingSerialiseTest()
|
||||
{
|
||||
core::TunerStatus status = {};
|
||||
status.booted = true;
|
||||
status.band = core::TunerBand::Dab;
|
||||
status.locked = true;
|
||||
status.volume = 40;
|
||||
status.dabFreqIndex = 12U;
|
||||
status.dabPlayingServiceId = 42U;
|
||||
status.dabPlayingComponentId = 7U;
|
||||
|
||||
const std::string json = core::serializeTunerStatusJson(status);
|
||||
if (json.find("\"playing_service_id\":42") == std::string::npos
|
||||
|| json.find("\"playing_component_id\":7") == std::string::npos) {
|
||||
std::cerr << "playing ids missing: " << json << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runTunerServicesSerialiseTest()
|
||||
{
|
||||
core::TunerServiceEntry entry = {};
|
||||
@@ -118,6 +139,36 @@ namespace {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runTunerStatusMetadataSerialiseTest()
|
||||
{
|
||||
core::TunerStatus status = {};
|
||||
status.booted = true;
|
||||
status.band = core::TunerBand::Fm;
|
||||
status.locked = true;
|
||||
status.volume = 40;
|
||||
status.fmFrequency = *core::FrequencyKHz::tryFromKhz(101500U);
|
||||
status.fmStationName = core::BroadcastLabel::tryFromChipBytes("RADIO 1");
|
||||
status.fmRadiotext = core::BroadcastLabel::tryFromChipBytes("Now playing");
|
||||
|
||||
const std::string json = core::serializeTunerStatusJson(status);
|
||||
if (json.find("\"station_name\":\"RADIO 1\"") == std::string::npos
|
||||
|| json.find("\"radiotext\":\"Now playing\"") == std::string::npos) {
|
||||
std::cerr << "FM metadata missing: " << json << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
status.band = core::TunerBand::Dab;
|
||||
status.dabFreqIndex = 5U;
|
||||
status.dabDynamicLabel =
|
||||
core::BroadcastLabel::tryFromChipBytes("Live show");
|
||||
const std::string dabJson = core::serializeTunerStatusJson(status);
|
||||
if (dabJson.find("\"dynamic_label\":\"Live show\"") == std::string::npos) {
|
||||
std::cerr << "DAB metadata missing: " << dabJson << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[[nodiscard]] int runTunerErrorSerialiseTest()
|
||||
{
|
||||
if (!expectEqual(core::serializeTunerErrorJson("not_booted"),
|
||||
@@ -146,6 +197,12 @@ int main()
|
||||
if (runTunerStatusSerialiseTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runTunerStatusPlayingSerialiseTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runTunerStatusMetadataSerialiseTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (runTunerServicesSerialiseTest() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user