Skip to content

Commit

Permalink
Add csv-register-recorder-msr-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Oct 10, 2021
1 parent ed111d4 commit ce54709
Show file tree
Hide file tree
Showing 8 changed files with 1,223 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"crates/msr-legacy",
"crates/msr-plugin",
"plugins/csv-event-journal-msr-plugin",
"plugins/csv-register-recorder-msr-plugin",
]

[patch.crates-io]
Expand All @@ -13,3 +14,4 @@ msr-core = { path = "crates/msr-core" }
msr-legacy = { path = "crates/msr-legacy" }
msr-plugin = { path = "crates/msr-plugin" }
csv-event-journal-msr-plugin = { path = "plugins/csv-event-journal-msr-plugin" }
csv-register-recorder-msr-plugin = { path = "plugins/csv-register-recorder-msr-plugin" }
18 changes: 18 additions & 0 deletions plugins/csv-register-recorder-msr-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "csv-register-recorder-msr-plugin"
version = "0.0.0"
description = "slowtec Industrial Automation Runtime - CSV Register Recorder Plugins"
authors = ["slowtec GmbH <[email protected]>"]
edition = "2018"
publish = false

[dependencies]
anyhow = "*"
bs58 = "*"
log = "*"
thiserror = "*"
tokio = { version = "*", default_features = false, features = ["rt-multi-thread"] }

# Workspace dependencies
msr-core = "*"
msr-plugin = "*"
107 changes: 107 additions & 0 deletions plugins/csv-register-recorder-msr-plugin/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use msr_plugin::{reply_channel, send_message_receive_result};

use super::*;

pub use super::Message;

pub async fn command_replace_config(
message_tx: &MessageSender,
new_config: Config,
) -> PluginResult<Config> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Command(Command::ReplaceConfig(reply_tx, new_config));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn command_replace_register_group_config(
message_tx: &MessageSender,
register_group_id: RegisterGroupId,
new_config: RegisterGroupConfig,
) -> PluginResult<Option<RegisterGroupConfig>> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Command(Command::ReplaceRegisterGroupConfig(
reply_tx,
register_group_id,
new_config,
));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn command_switch_state(
message_tx: &MessageSender,
new_state: State,
) -> PluginResult<()> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Command(Command::SwitchState(reply_tx, new_state));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn command_record_observed_register_group_values(
message_tx: &MessageSender,
register_group_id: RegisterGroupId,
observed_register_values: ObservedRegisterValues,
) -> PluginResult<()> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Command(Command::RecordObservedRegisterGroupValues(
reply_tx,
register_group_id,
observed_register_values,
));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn command_shutdown(message_tx: &MessageSender) -> PluginResult<()> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Command(Command::Shutdown(reply_tx));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn command_smoke_test(message_tx: &MessageSender) -> PluginResult<()> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Command(Command::SmokeTest(reply_tx));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn query_config(message_tx: &MessageSender) -> PluginResult<Config> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Query(Query::Config(reply_tx));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn query_register_group_config(
message_tx: &MessageSender,
register_group_id: RegisterGroupId,
) -> PluginResult<Option<RegisterGroupConfig>> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Query(Query::RegisterGroupConfig(reply_tx, register_group_id));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn query_status(
message_tx: &MessageSender,
request: QueryStatusRequest,
) -> PluginResult<Status> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Query(Query::Status(reply_tx, request));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn query_recent_records(
message_tx: &MessageSender,
register_group_id: RegisterGroupId,
req: RecentRecordsRequest,
) -> PluginResult<Vec<StoredRecord>> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Query(Query::RecentRecords(reply_tx, register_group_id, req));
send_message_receive_result(message, message_tx, reply_rx).await
}

pub async fn query_filter_records(
message_tx: &MessageSender,
register_group_id: RegisterGroupId,
req: FilterRecordsRequest,
) -> PluginResult<Vec<StoredRecord>> {
let (reply_tx, reply_rx) = reply_channel();
let message = Message::Query(Query::FilterRecords(reply_tx, register_group_id, req));
send_message_receive_result(message, message_tx, reply_rx).await
}
Loading

0 comments on commit ce54709

Please sign in to comment.