implements PR014 a PR016
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use prometeu_drivers::{AudioCommand, Channel, MAX_CHANNELS, OUTPUT_SAMPLE_RATE};
|
||||
use prometeu_hal::LoopMode;
|
||||
use ringbuf::traits::{Consumer, Producer, Split};
|
||||
use ringbuf::HeapRb;
|
||||
use ringbuf::traits::{Consumer, Producer, Split};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
@@ -93,6 +93,12 @@ pub struct HostAudio {
|
||||
_stream: Option<Box<dyn AudioStreamHandle>>,
|
||||
}
|
||||
|
||||
impl Default for HostAudio {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl HostAudio {
|
||||
pub fn new() -> Self {
|
||||
Self { producer: None, perf_consumer: None, _stream: None }
|
||||
@@ -150,7 +156,7 @@ impl HostAudio {
|
||||
pub fn send_commands(&mut self, commands: &mut Vec<AudioCommand>) {
|
||||
if let Some(producer) = &mut self.producer {
|
||||
for cmd in commands.drain(..) {
|
||||
if let Err(_) = producer.try_push(cmd) {
|
||||
if producer.try_push(cmd).is_err() {
|
||||
eprintln!("[HostAudio] Command ringbuffer full, dropping command.");
|
||||
}
|
||||
}
|
||||
@@ -301,6 +307,12 @@ pub struct AudioMixer {
|
||||
paused: bool,
|
||||
}
|
||||
|
||||
impl Default for AudioMixer {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioMixer {
|
||||
pub fn new() -> Self {
|
||||
Self { voices: Default::default(), last_processing_time: Duration::ZERO, paused: false }
|
||||
|
||||
@@ -27,6 +27,12 @@ pub struct HostDebugger {
|
||||
last_fault_summary: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for HostDebugger {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl HostDebugger {
|
||||
/// Creates a new debugger interface in an idle state.
|
||||
pub fn new() -> Self {
|
||||
@@ -70,21 +76,21 @@ impl HostDebugger {
|
||||
|
||||
/// Sends a structured response to the connected debugger client.
|
||||
fn send_response(&mut self, resp: DebugResponse) {
|
||||
if let Some(stream) = &mut self.stream {
|
||||
if let Ok(json) = serde_json::to_string(&resp) {
|
||||
let _ = stream.write_all(json.as_bytes());
|
||||
let _ = stream.write_all(b"\n");
|
||||
}
|
||||
if let Some(stream) = &mut self.stream
|
||||
&& let Ok(json) = serde_json::to_string(&resp)
|
||||
{
|
||||
let _ = stream.write_all(json.as_bytes());
|
||||
let _ = stream.write_all(b"\n");
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends an asynchronous event to the connected debugger client.
|
||||
fn send_event(&mut self, event: DebugEvent) {
|
||||
if let Some(stream) = &mut self.stream {
|
||||
if let Ok(json) = serde_json::to_string(&event) {
|
||||
let _ = stream.write_all(json.as_bytes());
|
||||
let _ = stream.write_all(b"\n");
|
||||
}
|
||||
if let Some(stream) = &mut self.stream
|
||||
&& let Ok(json) = serde_json::to_string(&event)
|
||||
{
|
||||
let _ = stream.write_all(json.as_bytes());
|
||||
let _ = stream.write_all(b"\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,31 +98,31 @@ impl HostDebugger {
|
||||
/// It handles new connections and processes incoming commands.
|
||||
pub fn check_commands(&mut self, firmware: &mut Firmware, hardware: &mut Hardware) {
|
||||
// 1. Accept new client connections.
|
||||
if let Some(listener) = &self.listener {
|
||||
if let Ok((stream, _addr)) = listener.accept() {
|
||||
// Currently, only one debugger client is supported at a time.
|
||||
if self.stream.is_none() {
|
||||
println!("[Debugger] Connection received!");
|
||||
stream.set_nonblocking(true).expect("Cannot set non-blocking on stream");
|
||||
if let Some(listener) = &self.listener
|
||||
&& let Ok((stream, _addr)) = listener.accept()
|
||||
{
|
||||
// Currently, only one debugger client is supported at a time.
|
||||
if self.stream.is_none() {
|
||||
println!("[Debugger] Connection received!");
|
||||
stream.set_nonblocking(true).expect("Cannot set non-blocking on stream");
|
||||
|
||||
self.stream = Some(stream);
|
||||
self.last_fault_summary = None;
|
||||
self.stream = Some(stream);
|
||||
self.last_fault_summary = None;
|
||||
|
||||
// Immediately send the Handshake message to identify the Runtime and App.
|
||||
let handshake = DebugResponse::Handshake {
|
||||
protocol_version: DEVTOOLS_PROTOCOL_VERSION,
|
||||
runtime_version: "0.1".to_string(),
|
||||
cartridge: HandshakeCartridge {
|
||||
app_id: firmware.os.current_app_id,
|
||||
title: firmware.os.current_cartridge_title.clone(),
|
||||
app_version: firmware.os.current_cartridge_app_version.clone(),
|
||||
app_mode: firmware.os.current_cartridge_app_mode,
|
||||
},
|
||||
};
|
||||
self.send_response(handshake);
|
||||
} else {
|
||||
println!("[Debugger] Connection refused: already connected.");
|
||||
}
|
||||
// Immediately send the Handshake message to identify the Runtime and App.
|
||||
let handshake = DebugResponse::Handshake {
|
||||
protocol_version: DEVTOOLS_PROTOCOL_VERSION,
|
||||
runtime_version: "0.1".to_string(),
|
||||
cartridge: HandshakeCartridge {
|
||||
app_id: firmware.os.current_app_id,
|
||||
title: firmware.os.current_cartridge_title.clone(),
|
||||
app_version: firmware.os.current_cartridge_app_version.clone(),
|
||||
app_mode: firmware.os.current_cartridge_app_mode,
|
||||
},
|
||||
};
|
||||
self.send_response(handshake);
|
||||
} else {
|
||||
println!("[Debugger] Connection refused: already connected.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@ pub struct HostInputHandler {
|
||||
pub signals: InputSignals,
|
||||
}
|
||||
|
||||
impl Default for HostInputHandler {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl HostInputHandler {
|
||||
pub fn new() -> Self {
|
||||
Self { signals: InputSignals::default() }
|
||||
|
||||
@@ -4,6 +4,12 @@ pub struct HostConsoleSink {
|
||||
last_seq: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for HostConsoleSink {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl HostConsoleSink {
|
||||
pub fn new() -> Self {
|
||||
Self { last_seq: None }
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::stats::HostStats;
|
||||
use crate::utilities::draw_rgb565_to_rgba8;
|
||||
use pixels::wgpu::PresentMode;
|
||||
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
|
||||
use prometeu_drivers::hardware::Hardware;
|
||||
use prometeu_drivers::AudioCommand;
|
||||
use prometeu_drivers::hardware::Hardware;
|
||||
use prometeu_firmware::{BootTarget, Firmware};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::telemetry::CertificationConfig;
|
||||
@@ -190,8 +190,8 @@ impl HostRunner {
|
||||
let cert_color = if tel.violations > 0 { color_warn } else { color_text };
|
||||
self.hardware.gfx.draw_text(10, 82, &format!("CERT LAST: {}", tel.violations), cert_color);
|
||||
|
||||
if tel.violations > 0 {
|
||||
if let Some(event) = self
|
||||
if tel.violations > 0
|
||||
&& let Some(event) = self
|
||||
.firmware
|
||||
.os
|
||||
.log_service
|
||||
@@ -199,13 +199,12 @@ impl HostRunner {
|
||||
.into_iter()
|
||||
.rev()
|
||||
.find(|e| e.tag >= 0xCA01 && e.tag <= 0xCA03)
|
||||
{
|
||||
let mut msg = event.msg.clone();
|
||||
if msg.len() > 30 {
|
||||
msg.truncate(30);
|
||||
}
|
||||
self.hardware.gfx.draw_text(10, 90, &msg, color_warn);
|
||||
{
|
||||
let mut msg = event.msg.clone();
|
||||
if msg.len() > 30 {
|
||||
msg.truncate(30);
|
||||
}
|
||||
self.hardware.gfx.draw_text(10, 90, &msg, color_warn);
|
||||
}
|
||||
|
||||
if let Some(report) = self.firmware.os.last_crash_report.as_ref() {
|
||||
@@ -315,11 +314,11 @@ impl ApplicationHandler for HostRunner {
|
||||
// 2. Maintain filesystem connection if it was lost (e.g., directory removed).
|
||||
if let Some(root) = &self.fs_root {
|
||||
use prometeu_system::fs::FsState;
|
||||
if matches!(self.firmware.os.fs_state, FsState::Unmounted | FsState::Error(_)) {
|
||||
if std::path::Path::new(root).exists() {
|
||||
let backend = HostDirBackend::new(root);
|
||||
self.firmware.os.mount_fs(Box::new(backend));
|
||||
}
|
||||
if matches!(self.firmware.os.fs_state, FsState::Unmounted | FsState::Error(_))
|
||||
&& std::path::Path::new(root).exists()
|
||||
{
|
||||
let backend = HostDirBackend::new(root);
|
||||
self.firmware.os.mount_fs(Box::new(backend));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,6 +400,7 @@ mod tests {
|
||||
use std::net::TcpStream;
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires localhost TCP bind/connect; run via `cargo test -p prometeu-host-desktop-winit --lib -- --ignored`"]
|
||||
fn test_debug_port_opens() {
|
||||
let mut runner = HostRunner::new(None, None);
|
||||
let port = 9999;
|
||||
@@ -460,6 +460,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires localhost TCP bind/connect; run via `cargo test -p prometeu-host-desktop-winit --lib -- --ignored`"]
|
||||
fn test_debug_reconnection() {
|
||||
let mut runner = HostRunner::new(None, None);
|
||||
let port = 9998;
|
||||
@@ -502,6 +503,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires localhost TCP bind/connect; run via `cargo test -p prometeu-host-desktop-winit --lib -- --ignored`"]
|
||||
fn test_debug_refuse_second_connection() {
|
||||
let mut runner = HostRunner::new(None, None);
|
||||
let port = 9997;
|
||||
@@ -537,6 +539,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires localhost TCP bind/connect; run via `cargo test -p prometeu-host-desktop-winit --lib -- --ignored`"]
|
||||
fn test_get_state_returns_response() {
|
||||
let mut runner = HostRunner::new(None, None);
|
||||
let port = 9996;
|
||||
@@ -581,6 +584,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires localhost TCP bind/connect; run via `cargo test -p prometeu-host-desktop-winit --lib -- --ignored`"]
|
||||
fn test_debug_resume_on_disconnect() {
|
||||
let mut runner = HostRunner::new(None, None);
|
||||
let port = 9995;
|
||||
|
||||
@@ -11,6 +11,12 @@ pub struct HostStats {
|
||||
pub audio_load_samples: u64,
|
||||
}
|
||||
|
||||
impl Default for HostStats {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl HostStats {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user