Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long recording #29

Merged
merged 10 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ authors = ["Cacophony Developers <[email protected]>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
framebuffer = "0.3.1"
rppal = "0.19.0"
chrono = { version = "0.4.38", features = ["serde"] }
byteorder = "1.4.3"
Expand All @@ -33,7 +32,6 @@ sha256 = "1.5.0"

[target.aarch64-unknown-linux-musl]
# applies to target-specific builds

# rPi3
rustflags = "-C target-cpu=cortex-a53"

Expand Down
31 changes: 25 additions & 6 deletions src/camera_transfer_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,25 @@ pub fn enter_camera_transfer_loop(
let crc_from_remote_dup = LittleEndian::read_u16(&header_slice[12..14]);
let crc_from_remote_inv = LittleEndian::read_u16(&header_slice[14..16]);
let crc_from_remote_inv_dup = LittleEndian::read_u16(&header_slice[16..=17]);
let transfer_type_check = transfer_type == transfer_type_dup;
let mut transfer_block = 0;
let is_file_transfer_message = transfer_type_check
&& transfer_type >= CAMERA_BEGIN_FILE_TRANSFER
&& transfer_type <= CAMERA_BEGIN_AND_END_FILE_TRANSFER;
let is_file_transfer_progress_message = transfer_type_check
&& (transfer_type == CAMERA_BEGIN_FILE_TRANSFER
|| transfer_type == CAMERA_END_FILE_TRANSFER);
let header_crc_check = if is_file_transfer_progress_message {
transfer_block = crc_from_remote_dup;

crc_from_remote_inv_dup == crc_from_remote_inv
&& crc_from_remote_inv.not() == crc_from_remote
} else {
crc_from_remote == crc_from_remote_dup
&& crc_from_remote_inv_dup == crc_from_remote_inv
&& crc_from_remote_inv.not() == crc_from_remote
};
let num_bytes_check = num_bytes == num_bytes_dup;
let header_crc_check = crc_from_remote == crc_from_remote_dup
&& crc_from_remote_inv_dup == crc_from_remote_inv
&& crc_from_remote_inv.not() == crc_from_remote;
let transfer_type_check = transfer_type == transfer_type_dup;
if !num_bytes_check || !header_crc_check || !transfer_type_check {
// Just log the *first* time the header integrity check fails in a session.
if !header_integrity_check_has_failed {
Expand Down Expand Up @@ -325,6 +338,12 @@ pub fn enter_camera_transfer_loop(
// Always write the return buffer
spi.write(&return_payload_buf).unwrap();
if crc == crc_from_remote {
if is_file_transfer_progress_message {
recording_state.update_offload_progress(transfer_block);
} else if !is_file_transfer_message && recording_state.is_offloading() {
recording_state.end_offload();
}

match transfer_type {
CAMERA_CONNECT_INFO => {
radiometry_enabled = LittleEndian::read_u32(&chunk[0..4]) == 2;
Expand Down Expand Up @@ -692,10 +711,10 @@ fn maybe_make_test_audio_recording(

// If the user requested a test audio recording, trigger the test audio recording, and
// launch a thread to track when that recording has completed.
if recording_state.user_requested_test_audio_recording() {
if recording_state.user_requested_audio_recording() {
recording_state.sync_state_from_attiny(dbus_conn);
if !recording_state.is_recording()
&& recording_state.request_test_audio_recording_from_rp2040(dbus_conn)
&& recording_state.request_audio_recording_from_rp2040(dbus_conn)
{
let _ = restart_rp2040_channel_tx.send(true);
info!("Telling rp2040 to take test recording and restarting");
Expand Down
61 changes: 48 additions & 13 deletions src/dbus_audio.rs → src/dbus_managementd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustbus::{get_system_bus_path, DispatchConn, DuplexConn};
use std::{process, thread};
use thread_priority::{ThreadBuilderExt, ThreadPriority};

// TC2-Agent dbus audio service
// TC2-Agent dbus managementd service
type MyHandleEnv<'a, 'b> = HandleEnvironment<RecordingState, ()>;

fn default_handler(
Expand All @@ -19,28 +19,62 @@ fn default_handler(
Ok(None)
}

fn audio_handler(
fn managementd_handler(
recording_state_ctx: &mut RecordingState,
_matches: Matches,
msg: &MarshalledMessage,
_env: &mut MyHandleEnv,
) -> HandleResult<()> {
if msg.dynheader.member.as_ref().unwrap() == "testaudio" {
let message = if !recording_state_ctx.is_taking_test_audio_recording() {
let message = if recording_state_ctx.is_taking_test_audio_recording() {
"Already making a test recording"
} else if recording_state_ctx.is_taking_long_audio_recording() {
"Already making a 5 minute recording"
} else {
recording_state_ctx.request_test_audio_recording();
"Asked for a test recording"
};
let mut resp = msg.dynheader.make_response();
resp.body.push_param(message)?;
Ok(Some(resp))
} else if msg.dynheader.member.as_ref().unwrap() == "longaudiorecording" {
let message = if recording_state_ctx.is_taking_long_audio_recording() {
"Already making a 5 minute recording"
} else if recording_state_ctx.is_taking_test_audio_recording() {
"Already making a 5 test recording"
} else {
"Already making a test recording"
recording_state_ctx.request_long_audio_recording();
"Asked for a 5 minute recording"
};
let mut resp = msg.dynheader.make_response();
resp.body.push_param(message)?;
Ok(Some(resp))
} else if msg.dynheader.member.as_ref().unwrap() == "audiostatus" {
let mut response = msg.dynheader.make_response();
let status = recording_state_ctx.get_audio_status();
response.body.push_param(if recording_state_ctx.is_in_audio_mode() { 1 } else { 0 })?;
response
.body
.push_param(if recording_state_ctx.is_in_audio_mode() {
1
} else {
0
})?;
response.body.push_param(status as u8)?;
Ok(Some(response))
} else if msg.dynheader.member.as_ref().unwrap() == "offloadstatus" {
let mut response = msg.dynheader.make_response();
if let Some((percent_complete, remaining_seconds)) =
recording_state_ctx.get_offload_status()
{
response.body.push_param(1)?;
response.body.push_param(0)?; // percent_complete
response.body.push_param(0)?; // remaining_seconds
} else {
response.body.push_param(0)?;
response.body.push_param(0)?;
response.body.push_param(0)?;
}
Ok(Some(response))
} else {
Ok(None)
}
Expand All @@ -51,16 +85,18 @@ pub enum AudioStatus {
WaitingToTakeTestRecording = 2,
TakingTestRecording = 3,
Recording = 4,
TakingLongRecording = 5,
WaitingToTakeLongRecording = 6,
}

pub fn setup_dbus_test_audio_recording_service(recording_state: &RecordingState) {
pub fn setup_dbus_managementd_recording_service(recording_state: &RecordingState) {
// set up dbus service for handling messages between managementd and tc2-agent about when
// to make test audio recordings.
// to make test audio recordings, and for getting the status of any file offloads
let recording_state = recording_state.clone();
let session_path = get_system_bus_path().unwrap();
let _dbus_thread = thread::Builder::new().name("dbus-service".to_string()).spawn_with_priority(
ThreadPriority::Max,
move |_| {
let _dbus_thread = thread::Builder::new()
.name("dbus-managementd-service".to_string())
.spawn_with_priority(ThreadPriority::Max, move |_| {
let mut dbus_conn =
DuplexConn::connect_to_bus(session_path, false).unwrap_or_else(|e| {
error!("Error connecting to system DBus: {}", e);
Expand All @@ -82,8 +118,7 @@ pub fn setup_dbus_test_audio_recording_service(recording_state: &RecordingState)

let mut dispatch_conn =
DispatchConn::new(dbus_conn, recording_state, Box::new(default_handler));
dispatch_conn.add_handler("/org/cacophony/TC2Agent", Box::new(audio_handler));
dispatch_conn.add_handler("/org/cacophony/TC2Agent", Box::new(managementd_handler));
dispatch_conn.run().unwrap();
},
);
});
}
Loading
Loading