Skip to content

Commit

Permalink
Merge pull request #19 from TheCacophonyProject/audio-mode
Browse files Browse the repository at this point in the history
Audio mode
  • Loading branch information
gferraro authored Aug 28, 2024
2 parents 1a57158 + bc598ad commit 4e06ac3
Show file tree
Hide file tree
Showing 4 changed files with 629 additions and 643 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ addons:

env:
global:
- RP2040_FIRMWARE_VERSION=0.2.13
- RP2040_FIRMWARE_VERSION=0.2.14

before_script:
- rustup target add aarch64-unknown-linux-musl
Expand Down
6 changes: 3 additions & 3 deletions src/device_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl DeviceConfig {
std::process::exit(1);
}
info!("Got config {:?}", device_config);
if !device_config.is_audio_device() {
if device_config.audio_info.audio_mode != AudioMode::AudioOnly {
let inside_recording_window =
device_config.time_is_in_recording_window(&Utc::now().naive_utc());
info!("Inside recording window: {}", inside_recording_window);
Expand Down Expand Up @@ -880,8 +880,8 @@ impl DeviceConfig {
let mut buf = Cursor::new(output);
let device_id = self.device_id();
buf.write_u32::<LittleEndian>(device_id).unwrap();
buf.write_u8(if self.is_audio_device() { 1 } else { 0 })
.unwrap();
let audio_mode: u8 = self.audio_info.audio_mode.clone().into();
buf.write_u8(audio_mode).unwrap();
let (latitude, longitude) = self.lat_lng();
buf.write_f32::<LittleEndian>(latitude).unwrap();
buf.write_f32::<LittleEndian>(longitude).unwrap();
Expand Down
71 changes: 67 additions & 4 deletions src/event_logger.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
use rustbus::{DuplexConn, MessageBuilder};

#[repr(u8)]
#[derive(Debug, Clone, Copy)]

pub enum WakeReason {
Unknown = 0,
ThermalOffload = 1,
ThermalOffloadAfter24Hours = 2,
ThermalHighPower = 3,
AudioThermalEnded = 4,
AudioShouldOffload = 5,
}
impl std::fmt::Display for WakeReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

impl TryFrom<u8> for WakeReason {
type Error = ();

fn try_from(value: u8) -> Result<Self, Self::Error> {
use WakeReason::*;

match value {
0 => Ok(Unknown),
1 => Ok(ThermalOffload),
2 => Ok(ThermalOffloadAfter24Hours),
3 => Ok(ThermalHighPower),
4 => Ok(AudioThermalEnded),
5 => Ok(AudioShouldOffload),
_ => Err(()),
}
}
}

#[derive(Debug)]
pub enum LoggerEventKind {
Rp2040Sleep,
Expand All @@ -11,7 +46,7 @@ pub enum LoggerEventKind {
ToldRpiToSleep,
GotRpiPoweredDown,
GotRpiPoweredOn,
ToldRpiToWake,
ToldRpiToWake(WakeReason),
LostSync,
SetAlarm(u64), // Also has a time that the alarm is set for as additional data? Events can be bigger
GotPowerOnTimeout,
Expand All @@ -24,6 +59,14 @@ pub enum LoggerEventKind {
Rp2040MissedAudioAlarm(u64),
AudioRecordingFailed,
ErasePartialOrCorruptRecording,
StartedAudioRecording,
ThermalMode,
AudioMode,
RecordingNotFinished,
FileOffloadFailed,
LogOffloadFailed,
OffloadedLogs,
CorruptFile,
}

impl Into<u16> for LoggerEventKind {
Expand All @@ -39,7 +82,7 @@ impl Into<u16> for LoggerEventKind {
ToldRpiToSleep => 7,
GotRpiPoweredDown => 8,
GotRpiPoweredOn => 9,
ToldRpiToWake => 10,
ToldRpiToWake(_) => 10,
LostSync => 11,
SetAlarm(_) => 12,
GotPowerOnTimeout => 13,
Expand All @@ -52,6 +95,14 @@ impl Into<u16> for LoggerEventKind {
Rp2040MissedAudioAlarm(_) => 20,
AudioRecordingFailed => 21,
ErasePartialOrCorruptRecording => 22,
StartedAudioRecording => 23,
ThermalMode => 24,
AudioMode => 25,
RecordingNotFinished => 26,
FileOffloadFailed => 27,
OffloadedLogs => 28,
LogOffloadFailed => 29,
CorruptFile => 30,
}
}
}
Expand All @@ -71,7 +122,7 @@ impl TryFrom<u16> for LoggerEventKind {
7 => Ok(ToldRpiToSleep),
8 => Ok(GotRpiPoweredDown),
9 => Ok(GotRpiPoweredOn),
10 => Ok(ToldRpiToWake),
10 => Ok(ToldRpiToWake(WakeReason::Unknown)),
11 => Ok(LostSync),
12 => Ok(SetAlarm(0)),
13 => Ok(GotPowerOnTimeout),
Expand All @@ -84,11 +135,18 @@ impl TryFrom<u16> for LoggerEventKind {
20 => Ok(Rp2040MissedAudioAlarm(0)),
21 => Ok(AudioRecordingFailed),
22 => Ok(ErasePartialOrCorruptRecording),
23 => Ok(StartedAudioRecording),
24 => Ok(ThermalMode),
25 => Ok(AudioMode),
26 => Ok(RecordingNotFinished),
27 => Ok(FileOffloadFailed),
28 => Ok(OffloadedLogs),
29 => Ok(LogOffloadFailed),
30 => Ok(CorruptFile),
_ => Err(()),
}
}
}

pub struct LoggerEvent {
timestamp: u64,
event: LoggerEventKind,
Expand Down Expand Up @@ -117,6 +175,11 @@ impl LoggerEvent {
.push_param(format!(r#"{{ "alarm-time": {} }}"#, alarm * 1000))
.unwrap(); // Microseconds to nanoseconds
call.body.push_param("Rp2040MissedAudioAlarm").unwrap();
} else if let LoggerEventKind::ToldRpiToWake(reason) = self.event {
call.body
.push_param(format!(r#"{{ "wakeup-reason": "{}" }}"#, reason))
.unwrap();
call.body.push_param("ToldRpiToWake").unwrap();
} else {
call.body
.push_param(json_payload.unwrap_or(String::from("{}")))
Expand Down
Loading

0 comments on commit 4e06ac3

Please sign in to comment.