94 lines
2.2 KiB
Rust
94 lines
2.2 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use chrono::NaiveDateTime;
|
|
use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
|
use sqlx::types::mac_address::MacAddress;
|
|
use strum::{Display, EnumString};
|
|
|
|
#[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)]
|
|
pub struct ValueMessageFromDevice {
|
|
pub value: f64,
|
|
pub value_id: i32,
|
|
pub active_errors: i32,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Serialize)]
|
|
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: String,
|
|
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
|
|
}
|
|
|
|
#[derive(serde::Serialize, EnumString, PartialEq, Debug, Display)]
|
|
pub enum BoardConfig {
|
|
INA226,
|
|
INA233
|
|
} |