Skip to content
Open
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: 1 addition & 1 deletion apps-aarch64.checksum
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ a68d47287841723eba52b121a813c9a5692fbf73 target-aarch64/acap/reverse_proxy_0_0_
b0c8fca9b106b66129e605f01a4b05d1bec65fad target-aarch64/acap/send_event_1_0_0_aarch64.eap
a4ae28f3a46338f51ed865ca7b2308c7aa34d0f7 target-aarch64/acap/subscribe_to_event_1_0_0_aarch64.eap
5dd0f42234896ded99382717a2e69c3acf73d8ca target-aarch64/acap/using_a_build_script_0_0_0_aarch64.eap
1332ff6dad31bee166ef708cb9b8341e8939035d target-aarch64/acap/vapix_access_0_0_0_aarch64.eap
4de1cb2176403d5cf39e967035469ee20f62a389 target-aarch64/acap/vapix_access_0_0_0_aarch64.eap
ba4b41f8380c0f5349195626a1fc68616c9f13de target-aarch64/acap/vdoencodeclient_1_0_0_aarch64.eap
2 changes: 1 addition & 1 deletion apps-aarch64.filesize
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
3461 target-aarch64/acap/send_event_1_0_0_aarch64.eap
3440 target-aarch64/acap/subscribe_to_event_1_0_0_aarch64.eap
899 target-aarch64/acap/using_a_build_script_0_0_0_aarch64.eap
11421 target-aarch64/acap/vapix_access_0_0_0_aarch64.eap
11436 target-aarch64/acap/vapix_access_0_0_0_aarch64.eap
2834 target-aarch64/acap/vdoencodeclient_1_0_0_aarch64.eap
45 changes: 34 additions & 11 deletions crates/acap-vapix/src/apis/systemready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ use serde_json::json;

use crate::ajr_http;

#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(try_from = "String", into = "String")]
struct Seconds(Duration);

impl TryFrom<String> for Seconds {
type Error = std::num::ParseIntError;

fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self(Duration::from_secs(value.parse()?)))
}
}

impl From<Seconds> for String {
fn from(value: Seconds) -> Self {
value.0.as_secs().to_string()
}
}

const PATH: &str = "axis-cgi/systemready.cgi";
const API_VERSION: &str = "1";
#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -23,9 +41,9 @@ enum Data {
pub struct SystemreadyData {
systemready: EnglishBool,
needsetup: EnglishBool,
uptime: Option<String>,
uptime: Option<Seconds>,
bootid: Option<String>,
previewmode: Option<String>,
previewmode: Option<Seconds>,
}

impl SystemreadyData {
Expand All @@ -41,10 +59,7 @@ impl SystemreadyData {

/// Elapsed since device started?
pub fn uptime(&self) -> Option<Duration> {
// TODO: Ensure at parsing
self.uptime
.as_ref()
.map(|t| Duration::from_secs(t.parse().unwrap()))
self.uptime.map(|s| s.0)
}

// A unique id generated at each boot?
Expand All @@ -54,10 +69,7 @@ impl SystemreadyData {

/// Total or remaining?
pub fn preview_mode(&self) -> Option<Duration> {
// TODO: Ensure at parsing
self.uptime
.as_ref()
.map(|t| Duration::from_secs(t.parse().unwrap()))
self.previewmode.map(|s| s.0)
}
}

Expand Down Expand Up @@ -99,7 +111,7 @@ impl SystemreadyRequest {
let params = if let Some(timeout) = self.timeout {
json!({"timeout":timeout})
} else {
json!("{}")
json!({})
};
let Data::Systemready(data) =
ajr_http::execute_params(PATH, API_VERSION, "systemready", params, client).await?;
Expand All @@ -113,8 +125,19 @@ pub fn systemready() -> SystemreadyRequest {

#[cfg(test)]
mod tests {
use std::time::Duration;

use crate::{ajr::ResponseEnvelope, systemready::Data};

#[test]
fn preview_mode_returns_previewmode_not_uptime() {
let text = include_str!("systemready/11_11_initial_response.json");
let envelope: ResponseEnvelope<Data> = serde_json::from_str(text).unwrap();
let Data::Systemready(data) = envelope.data().unwrap();
assert_eq!(data.preview_mode(), Some(Duration::from_secs(7200)));
assert_eq!(data.uptime(), Some(Duration::from_secs(65)));
}

#[test]
fn data_serialization_roundtrip() {
let texts = vec![
Expand Down