From 1be499d77a22279cc05e1b7547de7b2cd874015f Mon Sep 17 00:00:00 2001 From: Krzysztof Piotrowski Date: Wed, 24 Jul 2024 17:19:51 +0000 Subject: [PATCH] feat: create command payload for device profile Signed-off-by: Krzysztof Piotrowski --- crates/core/tedge_api/src/commands.rs | 16 +++++- crates/core/tedge_api/src/device_profile.rs | 59 +++++++++++++++++++++ crates/core/tedge_api/src/lib.rs | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 crates/core/tedge_api/src/device_profile.rs diff --git a/crates/core/tedge_api/src/commands.rs b/crates/core/tedge_api/src/commands.rs index 0d5f268b48a..64ee2aac1a3 100644 --- a/crates/core/tedge_api/src/commands.rs +++ b/crates/core/tedge_api/src/commands.rs @@ -545,6 +545,12 @@ impl SoftwareUpdateCommand { } } +#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct SoftwareInfo { + pub update_list: Vec, +} + /// Sub list of modules grouped by plugin type. #[derive(Debug, Clone, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] @@ -903,10 +909,18 @@ impl ConfigUpdateCmdPayload { } } +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ConfigInfo { + #[serde(rename = "type")] + pub config_type: String, + pub remote_url: Option, +} + /// Command to update the device firmware pub type FirmwareUpdateCmd = Command; -#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)] #[serde(rename_all = "camelCase")] pub struct FirmwareInfo { pub name: Option, diff --git a/crates/core/tedge_api/src/device_profile.rs b/crates/core/tedge_api/src/device_profile.rs new file mode 100644 index 00000000000..2a0e6e6e47d --- /dev/null +++ b/crates/core/tedge_api/src/device_profile.rs @@ -0,0 +1,59 @@ +use crate::commands::Command; +use crate::commands::CommandPayload; +use crate::commands::ConfigInfo; +use crate::commands::FirmwareInfo; +use crate::commands::SoftwareInfo; +use crate::mqtt_topics::OperationType; +use crate::CommandStatus; +use crate::Jsonify; + +use serde::Deserialize; +use serde::Serialize; + +/// Command for device profile +pub type DeviceProfileCmd = Command; + +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)] +#[serde(rename_all = "camelCase")] +pub struct DeviceProfileCmdPayload { + #[serde(flatten)] + pub status: CommandStatus, + pub name: String, + pub operations: Vec, +} + +impl Jsonify for DeviceProfileCmdPayload {} + +impl CommandPayload for DeviceProfileCmdPayload { + fn operation_type() -> OperationType { + OperationType::DeviceProfile + } + + fn status(&self) -> CommandStatus { + self.status.clone() + } + + fn set_status(&mut self, status: CommandStatus) { + self.status = status + } +} + +#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)] +#[serde(rename_all = "camelCase")] +pub struct DeviceProfileOperation { + operation: OperationType, + skip: bool, + #[serde(flatten)] + payload: OperationPayload, +} + +#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub enum OperationPayload { + #[serde(rename = "payload")] + Firmware(FirmwareInfo), + #[serde(rename = "payload")] + Software(SoftwareInfo), + #[serde(rename = "payload")] + Config(ConfigInfo), +} diff --git a/crates/core/tedge_api/src/lib.rs b/crates/core/tedge_api/src/lib.rs index 7f97bc97a3c..d35d8b75390 100644 --- a/crates/core/tedge_api/src/lib.rs +++ b/crates/core/tedge_api/src/lib.rs @@ -1,5 +1,6 @@ pub mod alarm; pub mod commands; +pub mod device_profile; pub mod entity_store; pub mod error; pub mod event;