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:
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @file BroadcastLabel.hpp
|
||||
* @brief Validated on-air label text (RDS PS/RT, DAB 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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief BroadcastLabel — trimmed UTF-8 label from chip byte buffers.
|
||||
*
|
||||
* @dname BroadcastLabel
|
||||
* @return n/a (type)
|
||||
* @pubstate Owns label_ (immutable after construction).
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
class BroadcastLabel {
|
||||
public:
|
||||
/** Maximum DAB DLS length supported in status JSON. */
|
||||
static constexpr std::size_t kMaxLength = 128;
|
||||
|
||||
/**
|
||||
* @brief tryFromChipBytes — parse a NUL- or space-padded chip buffer.
|
||||
*
|
||||
* @dname tryFromChipBytes
|
||||
* @param raw Raw bytes from RDS or DAB data service (may contain NUL).
|
||||
* @return BroadcastLabel when non-empty after trim, otherwise nullopt.
|
||||
* @pubstate none
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
[[nodiscard]] static std::optional<BroadcastLabel>
|
||||
tryFromChipBytes(std::string_view raw);
|
||||
|
||||
/**
|
||||
* @brief value — read the validated label text.
|
||||
*
|
||||
* @dname value
|
||||
* @return Trimmed label string.
|
||||
* @pubstate reads label_.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
[[nodiscard]] std::string_view value() const noexcept;
|
||||
|
||||
private:
|
||||
explicit BroadcastLabel(std::string label);
|
||||
|
||||
std::string label_;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file DabDynamicLabelAccumulator.hpp
|
||||
* @brief Reassemble DAB DLS payloads into one dynamic label string.
|
||||
*
|
||||
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||
*
|
||||
* Copyright 2026 Michele Bigi
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/BroadcastLabel.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief DabDynamicLabelAccumulator — segmented DAB DLS label buffer.
|
||||
*
|
||||
* @dname DabDynamicLabelAccumulator
|
||||
* @return n/a (type)
|
||||
* @pubstate Holds partial DLS segments until the label can be read out.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
class DabDynamicLabelAccumulator {
|
||||
public:
|
||||
/**
|
||||
* @brief reset — discard accumulated DLS segments.
|
||||
*
|
||||
* @dname reset
|
||||
* @return n/a
|
||||
* @pubstate clears buffer and segment flags.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
void reset() noexcept;
|
||||
|
||||
/**
|
||||
* @brief applySegment — ingest one DLS payload block from the driver.
|
||||
*
|
||||
* @dname applySegment
|
||||
* @param segmentIndex Zero-based segment index from the chip.
|
||||
* @param segmentCount Total segments advertised for this label.
|
||||
* @param payload Raw UTF-8 bytes for this segment.
|
||||
* @return n/a
|
||||
* @pubstate copies payload into buffer_ at the computed offset.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
void applySegment(std::uint16_t segmentIndex,
|
||||
std::uint16_t segmentCount,
|
||||
std::span<const std::uint8_t> payload) noexcept;
|
||||
|
||||
/**
|
||||
* @brief label — read the assembled dynamic label when complete.
|
||||
*
|
||||
* @dname label
|
||||
* @return Trimmed DLS text when all segments were received.
|
||||
* @pubstate reads buffer_ and segmentValid_.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
[[nodiscard]] std::optional<BroadcastLabel> label() const;
|
||||
|
||||
private:
|
||||
static constexpr std::size_t kMaxSegments = 32U;
|
||||
|
||||
std::array<char, BroadcastLabel::kMaxLength> buffer_{};
|
||||
std::array<bool, kMaxSegments> segmentValid_{};
|
||||
std::uint16_t expectedSegments_{0U};
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @file RdsMetadataAccumulator.hpp
|
||||
* @brief Accumulate FM RDS program name and radiotext from raw groups.
|
||||
*
|
||||
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||
*
|
||||
* Copyright 2026 Michele Bigi
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/BroadcastLabel.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief RdsMetadataAccumulator — stateful RDS PS/RT decoder (IEC 62106).
|
||||
*
|
||||
* @dname RdsMetadataAccumulator
|
||||
* @return n/a (type)
|
||||
* @pubstate Holds partial PS and RT buffers until complete groups arrive.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
class RdsMetadataAccumulator {
|
||||
public:
|
||||
/**
|
||||
* @brief reset — clear accumulated PS and radiotext.
|
||||
*
|
||||
* @dname reset
|
||||
* @return n/a
|
||||
* @pubstate clears internal buffers.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
void reset() noexcept;
|
||||
|
||||
/**
|
||||
* @brief applyGroup — ingest one RDS group (blocks A–D).
|
||||
*
|
||||
* @dname applyGroup
|
||||
* @param blockA RDS block A (PI code).
|
||||
* @param blockB RDS block B (group type and address).
|
||||
* @param blockC RDS block C (text payload).
|
||||
* @param blockD RDS block D (text payload for RT).
|
||||
* @return n/a
|
||||
* @pubstate updates PS/RT buffers for group types 0A and 2A.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
void applyGroup(std::uint16_t blockA,
|
||||
std::uint16_t blockB,
|
||||
std::uint16_t blockC,
|
||||
std::uint16_t blockD) noexcept;
|
||||
|
||||
/**
|
||||
* @brief programName — read the accumulated 8-character PS name.
|
||||
*
|
||||
* @dname programName
|
||||
* @return Trimmed PS label when all four segments were received.
|
||||
* @pubstate reads psBuffer_.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
[[nodiscard]] std::optional<BroadcastLabel> programName() const;
|
||||
|
||||
/**
|
||||
* @brief radiotext — read the accumulated 64-character RT string.
|
||||
*
|
||||
* @dname radiotext
|
||||
* @return Trimmed radiotext when at least one RT segment was received.
|
||||
* @pubstate reads rtBuffer_.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
[[nodiscard]] std::optional<BroadcastLabel> radiotext() const;
|
||||
|
||||
private:
|
||||
static constexpr std::size_t kPsSegments = 4U;
|
||||
static constexpr std::size_t kRtSegments = 16U;
|
||||
|
||||
std::array<char, 8> psBuffer_{};
|
||||
std::array<bool, kPsSegments> psSegmentValid_{};
|
||||
std::array<char, 64> rtBuffer_{};
|
||||
std::array<bool, kRtSegments> rtSegmentValid_{};
|
||||
bool rtAbFlag_{false};
|
||||
bool rtAbInitialized_{false};
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
@@ -29,6 +29,7 @@ enum class StationListError {
|
||||
Full,
|
||||
NotFound,
|
||||
SlotInUse,
|
||||
PersistFailed,
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
|
||||
@@ -38,6 +38,21 @@ struct StationRemoveRequest {
|
||||
std::size_t index; ///< Zero-based list index to delete.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief StationReorderRequest — parsed POST /api/stations/reorder body.
|
||||
*
|
||||
* @dname StationReorderRequest
|
||||
* @return n/a (type)
|
||||
* @pubstate Plain DTO filled by parseStationReorderJson.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
struct StationReorderRequest {
|
||||
std::size_t fromIndex; ///< Current list position.
|
||||
std::size_t toIndex; ///< Target list position.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief serializeStationListJson — serialise all presets for GET /api/stations.
|
||||
*
|
||||
@@ -93,6 +108,20 @@ parseStationListJson(std::string_view json);
|
||||
[[nodiscard]] std::expected<StationRemoveRequest, ParseError>
|
||||
parseStationRemoveJson(std::string_view json);
|
||||
|
||||
/**
|
||||
* @brief parseStationReorderJson — validate POST /api/stations/reorder body.
|
||||
*
|
||||
* @dname parseStationReorderJson
|
||||
* @param json Untrusted request body with from/to index fields.
|
||||
* @return StationReorderRequest on success, or ParseError.
|
||||
* @pubstate none
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-06
|
||||
*/
|
||||
[[nodiscard]] std::expected<StationReorderRequest, ParseError>
|
||||
parseStationReorderJson(std::string_view json);
|
||||
|
||||
/**
|
||||
* @brief serializeStationListErrorJson — serialise a station API error.
|
||||
*
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/BroadcastLabel.hpp"
|
||||
#include "core/FrequencyKHz.hpp"
|
||||
#include "core/TunerBand.hpp"
|
||||
|
||||
@@ -56,10 +57,15 @@ struct TunerStatus {
|
||||
std::optional<std::uint8_t> dabFreqIndex; ///< Current Band III ensemble index.
|
||||
std::optional<std::uint8_t> dabFicQuality; ///< FIC quality 0–100 when DAB.
|
||||
std::optional<std::int8_t> dabCnrDb; ///< CNR in dB when DAB.
|
||||
std::optional<std::uint32_t> dabPlayingServiceId; ///< Last played DAB service.
|
||||
std::optional<std::uint32_t> dabPlayingComponentId; ///< Last played DAB component.
|
||||
std::optional<FrequencyKHz> fmFrequency; ///< Tuned FM centre frequency.
|
||||
std::optional<std::int8_t> fmRssiDbuV; ///< FM RSSI in dBµV.
|
||||
std::optional<std::int8_t> fmSnrDb; ///< FM SNR in dB.
|
||||
std::optional<bool> fmStereo; ///< FM stereo pilot detected.
|
||||
std::optional<BroadcastLabel> fmStationName; ///< FM RDS program service name.
|
||||
std::optional<BroadcastLabel> fmRadiotext; ///< FM RDS radiotext (RT).
|
||||
std::optional<BroadcastLabel> dabDynamicLabel; ///< DAB DLS now-playing label.
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
|
||||
Reference in New Issue
Block a user