119 lines
2.9 KiB
Rust
119 lines
2.9 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use chrono::NaiveDateTime;
|
|
use semver::Version;
|
|
use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
|
use sqlx::types::mac_address::MacAddress;
|
|
use strum::{Display, EnumString};
|
|
|
|
use crate::database::Database;
|
|
|
|
#[derive(Deserialize, Debug, Serialize)]
|
|
pub struct TelemetryMessage {
|
|
pub uptime: i32,
|
|
pub voltage: Option<f64>,
|
|
pub temperature: Option<f64>,
|
|
pub software_version: i32,
|
|
pub timestamp: NaiveDateTime,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Serialize)]
|
|
pub struct TelemetryMessageFromDevice {
|
|
pub uptime: i32,
|
|
pub voltage: Option<f64>,
|
|
pub temperature: Option<f64>,
|
|
pub software_version: i32,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Serialize, PartialEq)]
|
|
pub struct ValueMessageFromDevice {
|
|
pub value: f64,
|
|
pub value_id: i32,
|
|
pub active_errors: i32,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Serialize, PartialEq)]
|
|
pub struct ValueMessage {
|
|
pub value: f64,
|
|
pub value_id: i32,
|
|
pub timestamp: NaiveDateTime,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct Device {
|
|
pub display_name: Option<String>,
|
|
pub id: MacAddress,
|
|
}
|
|
|
|
impl Serialize for Device {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: serde::Serializer,
|
|
{
|
|
let mut state = serializer.serialize_struct("Device", 2)?;
|
|
|
|
// Serialize each field with custom logic
|
|
let bytes = self.id.bytes();
|
|
state.serialize_field("display_name", &self.display_name)?;
|
|
state.serialize_field(
|
|
"id",
|
|
&format!(
|
|
"{}{}{}{}{}{}",
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]
|
|
),
|
|
)?;
|
|
|
|
// End the serialization process
|
|
state.end()
|
|
}
|
|
}
|
|
|
|
#[derive(serde::Serialize)]
|
|
#[serde(rename_all = "PascalCase")]
|
|
pub struct OTAConfigurationList {
|
|
pub configurations: Vec<OTAConfiguration>,
|
|
}
|
|
|
|
#[derive(serde::Serialize, PartialEq, Debug)]
|
|
#[serde(rename_all = "PascalCase")]
|
|
pub struct OTAConfiguration {
|
|
pub version: Version,
|
|
#[serde(rename = "URL")]
|
|
pub url: String,
|
|
pub board: Option<BoardType>,
|
|
pub config: Option<BoardConfig>,
|
|
}
|
|
|
|
#[derive(serde::Serialize, EnumString, PartialEq, Debug, Display)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum BoardType {
|
|
Waterlevel,
|
|
WaterlevelFilesystem,
|
|
}
|
|
|
|
#[derive(serde::Serialize, EnumString, PartialEq, Debug, Display)]
|
|
#[strum(ascii_case_insensitive, serialize_all = "SCREAMING_SNAKE_CASE")]
|
|
pub enum BoardConfig {
|
|
INA226,
|
|
INA233,
|
|
Generic,
|
|
}
|
|
|
|
pub struct AppState {
|
|
pub db: Database,
|
|
pub firmwares_path: PathBuf,
|
|
pub hostname: String,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub struct DeviceMetadata {
|
|
pub display_name: String,
|
|
}
|
|
|
|
#[derive(EnumString, PartialEq, Debug, Display, Serialize)]
|
|
#[strum(ascii_case_insensitive, serialize_all = "snake_case")]
|
|
pub enum Services {
|
|
Firmware,
|
|
Filesystem,
|
|
} |