Skip to content

Commit

Permalink
feat: create command payload for device profile
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Piotrowski <[email protected]>
  • Loading branch information
Ruadhri17 committed Aug 6, 2024
1 parent 90d023f commit 1be499d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/core/tedge_api/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ impl SoftwareUpdateCommand {
}
}

#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SoftwareInfo {
pub update_list: Vec<SoftwareRequestResponseSoftwareList>,
}

/// Sub list of modules grouped by plugin type.
#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -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<String>,
}

/// Command to update the device firmware
pub type FirmwareUpdateCmd = Command<FirmwareUpdateCmdPayload>;

#[derive(Debug, Deserialize, Serialize, Eq, PartialEq)]
#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FirmwareInfo {
pub name: Option<String>,
Expand Down
59 changes: 59 additions & 0 deletions crates/core/tedge_api/src/device_profile.rs
Original file line number Diff line number Diff line change
@@ -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<DeviceProfileCmdPayload>;

#[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<DeviceProfileOperation>,
}

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),
}
1 change: 1 addition & 0 deletions crates/core/tedge_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod alarm;
pub mod commands;
pub mod device_profile;
pub mod entity_store;
pub mod error;
pub mod event;
Expand Down

0 comments on commit 1be499d

Please sign in to comment.