bolar_2 backup

This commit is contained in:
2026-11-27 16:38:11 +08:00
commit e96d6d19df
305 changed files with 43350 additions and 0 deletions

14
main/ports/alert_ringer.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include "core/playback_types.h"
namespace borla {
class IAlertRinger {
public:
virtual ~IAlertRinger() = default;
virtual void Start(AlertKind kind) = 0;
virtual void Stop() = 0;
};
} // namespace borla

View File

@@ -0,0 +1,16 @@
#pragma once
#include "core/app_event.h"
#include "core/runtime_state.h"
namespace borla {
class IApplicationObserver {
public:
virtual ~IApplicationObserver() = default;
virtual void OnApplicationEvent(
const AppEvent& event,
const RuntimeState& state) = 0;
};
} // namespace borla

69
main/ports/audio_engine.h Normal file
View File

@@ -0,0 +1,69 @@
#pragma once
#include "core/playback_types.h"
#include "core/runtime_state.h"
#include "ports/volume_status_provider.h"
#include <cstddef>
#include <cstdint>
namespace borla {
class IAudioEngine : public IVolumeStatusProvider {
public:
~IAudioEngine() override = default;
virtual bool Start() = 0;
virtual void Stop() = 0;
virtual void ApplyPolicy(AudioPolicy policy) = 0;
virtual void SetVolume(uint8_t volume_percent) = 0;
virtual void SetWakeWordEnabled(bool enabled) = 0;
virtual void SetBargeInEnabled(bool enabled) = 0;
virtual void SetPlaybackPaused(bool paused) = 0;
// Frees the WakeNet instance. Only for entering BLE provisioning, where the
// BT controller needs every spare byte and the wake word is unused; the
// device reboots out of provisioning anyway. Never call this on an ordinary
// policy change — reloading the model takes ~110 ms and stalls capture.
virtual void ReleaseWakeWord() = 0;
// Blocks until nothing owns the speaker, or the timeout elapses. Returns
// true when playback actually finished. Only for callers that are about to
// destroy the audio path — chiefly the provisioning reboot, which used to
// cut "配网成功啦" mid-sentence.
virtual bool WaitForPlaybackIdle(uint32_t timeout_ms) = 0;
// Emits the voice frontend counters (AEC reference misses in particular) to
// the log. Called by diagnostics; the counters are otherwise invisible.
virtual void LogAudioMetrics(const char* reason) = 0;
// Emits one aggregated line covering the capture DSP chain for the frames
// seen since the previous call: microphone/AEC/reference levels, echo
// return loss, AGC gain, NS state, VAD state, reference ring depth and the
// measured frame period. Returns false when nothing was captured, so the
// caller can stay quiet while the microphone is off. Must be called from a
// diagnostics task: the capture task cannot afford a console write.
virtual bool LogAudioFrameStats() = 0;
virtual void CancelPlayback(PlaybackSessionId session_id) = 0;
virtual void BeginRemotePlayback(
PlaybackSessionId session_id,
PlaybackPriority priority) = 0;
virtual void EndPlaybackInput(PlaybackSessionId session_id) = 0;
virtual bool SubmitOpusFrame(
PlaybackSessionId session_id,
const uint8_t* data,
size_t size) = 0;
virtual PlaybackSessionId PlayLocalPrompt(
LocalPrompt prompt,
PlaybackPriority priority,
int16_t selector = -1) = 0;
virtual PlaybackSessionId PlayLocalSequence(
const LocalPromptSequence& sequence,
PlaybackPriority priority) = 0;
// Plays a prompt WITHOUT publishing kLocalPromptStarted. Used for the
// wake acknowledgement, which must be audible while the device is already
// listening: routing it through the normal lifecycle would drive the
// conversation state to kSpeaking and close the uplink the child is about
// to talk into.
virtual PlaybackSessionId PlayDetachedPrompt(
LocalPrompt prompt,
PlaybackPriority priority) = 0;
};
} // namespace borla

View File

@@ -0,0 +1,13 @@
#pragma once
#include "sensor/sensor_types.h"
namespace borla {
class IBatteryStatusProvider {
public:
virtual ~IBatteryStatusProvider() = default;
virtual BatteryStatus GetBatteryStatus() const = 0;
};
} // namespace borla

View File

@@ -0,0 +1,50 @@
#pragma once
#include "connectivity/wifi_types.h"
#include <array>
#include <cstdint>
namespace borla {
enum class ConnectivityPhase : uint8_t {
kStopped,
kCredentialsMissing,
kStartingTransport,
kConnecting,
kWaitingRetry,
kOnline,
};
struct ConnectivityDiagnostics {
ConnectivityPhase phase = ConnectivityPhase::kStopped;
bool online = false;
int8_t rssi_dbm = -127;
uint8_t channel = 0;
uint16_t last_disconnect_reason = 0;
uint32_t retry_attempt_count = 0;
size_t active_credential_index = 0;
size_t credential_count = 0;
std::array<char, kWifiSsidCapacity> ssid{};
std::array<char, kWifiIpv4Capacity> ipv4{};
};
class IConnectivityManager {
public:
virtual ~IConnectivityManager() = default;
virtual void Start() = 0;
virtual void Stop() = 0;
virtual void SwitchNetwork() = 0;
// 2026-9-7 ckkj add: BLE 好友模式启动前静默挂起网络。BT 控制器需要
// ~65KB 内部 RAM,与已初始化的 WiFi 驱动无法共存(配网服务已验证),
// 挂起期间不发布断开事件,避免打断应用层状态机;结束后 ResumeAfterBle()
// 立即按正常流程重连。默认空实现供无此需求的实现者忽略。
virtual void SuspendForBle() {}
virtual void ResumeAfterBle() {}
////////
virtual bool IsOnline() const = 0;
virtual ConnectivityDiagnostics GetDiagnostics() const = 0;
};
} // namespace borla

View File

@@ -0,0 +1,39 @@
#pragma once
#include "core/runtime_state.h"
#include <cstdint>
namespace borla {
struct DeviceIdentity {
char board[24]{};
char mac[18]{};
char app_version[32]{};
char chip_model[24]{};
};
enum class SoftOffWakeReason : uint8_t {
kNone,
kButton,
kTimer,
kOther,
};
class IDevicePlatform {
public:
virtual ~IDevicePlatform() = default;
virtual bool Initialize() = 0;
virtual const DeviceIdentity& Identity() const = 0;
virtual void SetLed(LedPattern pattern) = 0;
virtual void ShowTemporaryLedAlert(uint32_t duration_ms) = 0;
virtual void ReportError(uint32_t error_id) = 0;
virtual void Reboot() = 0;
virtual void EnterSoftOff(uint64_t timer_wakeup_us) = 0;
virtual SoftOffWakeReason ConsumeSoftOffWakeReason() = 0;
//2026-8-26 ckkj add
virtual bool ReadWakeButton() = 0;
};
} // namespace borla

View File

@@ -0,0 +1,11 @@
#pragma once
namespace borla {
class IDeviceProfileSink {
public:
virtual ~IDeviceProfileSink() = default;
virtual void SetDeviceName(const char* device_name) = 0;
};
} // namespace borla

15
main/ports/effect_sink.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "core/app_effect.h"
#include "core/runtime_state.h"
namespace borla {
class IEffectSink {
public:
virtual ~IEffectSink() = default;
virtual void Handle(const AppEffect& effect,
const RuntimeState& resulting_state) = 0;
};
} // namespace borla

View File

@@ -0,0 +1,13 @@
#pragma once
#include "core/app_event.h"
namespace borla {
class IEventPublisher {
public:
virtual ~IEventPublisher() = default;
virtual bool Publish(const AppEvent& event) = 0;
};
} // namespace borla

View File

@@ -0,0 +1,12 @@
#pragma once
namespace borla {
class IFriendService {
public:
virtual ~IFriendService() = default;
virtual void Start() = 0;
virtual void Stop() = 0;
};
} // namespace borla

View File

@@ -0,0 +1,15 @@
#pragma once
#include "core/playback_types.h"
namespace borla {
class ILocalSequenceHandler {
public:
virtual ~ILocalSequenceHandler() = default;
virtual bool StartLocalSequence(
const LocalPromptSequence& sequence) = 0;
virtual void StopLocalSequence() = 0;
};
} // namespace borla

19
main/ports/memory_cache.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "memory/memory_types.h"
namespace borla {
class IMemoryCache {
public:
virtual ~IMemoryCache() = default;
virtual bool Load() = 0;
// Deliberately an out-parameter rather than a by-value return: a returned
// MemorySnapshot materialises a ~2 KB temporary in the caller's frame, and
// the only caller is the WebSocket/TLS task building ClientHello, whose
// stack cannot absorb that on top of the message buffer.
virtual void CopySnapshot(MemorySnapshot* output) const = 0;
virtual bool Update(const MemorySnapshot& snapshot) = 0;
};
} // namespace borla

13
main/ports/ota_service.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include <cstdint>
namespace borla {
class IOtaService {
public:
virtual ~IOtaService() = default;
virtual void StartUpgrade(uint32_t request_id) = 0;
};
} // namespace borla

View File

@@ -0,0 +1,11 @@
#pragma once
namespace borla {
class IPowerService {
public:
virtual ~IPowerService() = default;
virtual void EnterSoftOff() = 0;
};
} // namespace borla

View File

@@ -0,0 +1,12 @@
#pragma once
namespace borla {
class IProvisioningService {
public:
virtual ~IProvisioningService() = default;
virtual void Start() = 0;
virtual void Stop() = 0;
};
} // namespace borla

View File

@@ -0,0 +1,44 @@
#pragma once
#include "core/playback_types.h"
#include "core/runtime_state.h"
#include <cstdint>
namespace borla {
class IRealtimeProtocol {
public:
virtual ~IRealtimeProtocol() = default;
virtual void Open() = 0;
virtual void Close() = 0;
virtual void SendStartListening() = 0;
virtual void SendStopListening() = 0;
virtual void SendAbortSpeaking(
ConversationInterruptSource source) = 0;
virtual void SendGoodbye() = 0;
virtual void SendAcceptCall() = 0;
virtual void SendHangupCall() = 0;
virtual void SendButtonClick(uint8_t click_count) = 0;
virtual void SendLocalPlaybackState(
LocalPrompt prompt,
bool started) = 0;
virtual bool SendFriendAdd(
const char* local_mac,
const char* local_name,
const char* remote_mac,
const char* remote_name) = 0;
// Asks the server to speak an upgrade announcement. `optional` marks an
// advisory notice the user may decline; otherwise the device is about to
// start installing. Returns false when the channel is not open.
virtual bool SendOtaNotify(
const char* text,
bool optional) = 0;
// Publishes the remote-configured connection-error prompt. Used when
// playback of a server reply dies mid-sentence so the child hears that
// something broke instead of silence.
virtual void RequestConnectionErrorPrompt() = 0;
};
} // namespace borla

View File

@@ -0,0 +1,27 @@
#pragma once
#include "core/playback_types.h"
#include "core/remote_behavior.h"
namespace borla {
class IRemoteBehaviorConfig {
public:
virtual ~IRemoteBehaviorConfig() = default;
virtual ButtonAction ResolveButtonAction(
uint8_t click_count) const = 0;
virtual LocalPrompt ServerUnreachablePrompt() const = 0;
virtual LocalPrompt NoNetworkPrompt() const = 0;
virtual bool UpdateButtonActions(
ButtonAction triple_click,
ButtonAction quadruple_click) = 0;
virtual bool UpdateConnectionPrompts(
bool has_server_unreachable,
LocalPrompt server_unreachable,
bool has_no_network,
LocalPrompt no_network) = 0;
};
} // namespace borla

View File

@@ -0,0 +1,16 @@
#pragma once
#include <cstddef>
namespace borla {
class ISensorMessageSink {
public:
virtual ~ISensorMessageSink() = default;
// Sensor data is best effort. A false result means the connection is not
// ready or the bounded transport queue is full; callers must drop it.
virtual bool SendSensorMessage(const char* data, size_t size) = 0;
};
} // namespace borla

View File

@@ -0,0 +1,15 @@
#pragma once
#include <cstdint>
namespace borla {
// Narrow read-only view the protocol layer uses for the periodic status frame.
// Keeps RealtimeProtocol from depending on the whole audio engine.
class IVolumeStatusProvider {
public:
virtual ~IVolumeStatusProvider() = default;
virtual uint8_t OutputVolumePercent() const = 0;
};
} // namespace borla