ng_gateway_connector/
modbus.rs

1use crate::{NGConverter, NGDriver};
2use anyhow::anyhow;
3use async_trait::async_trait;
4use std::any::Any;
5
6pub struct ModbusConverter;
7
8impl NGConverter for ModbusConverter {
9    fn convert_in(&self, input: Box<dyn Any + Send>) -> Result<Box<dyn Any + Send>, anyhow::Error> {
10        if let Some(input) = input.downcast_ref::<String>() {
11            Ok(Box::new(format!("Processed Downlink: {}", input)))
12        } else if let Some(input) = input.downcast_ref::<i32>() {
13            Ok(Box::new(format!("Processed Downlink: {}", input)))
14        } else if let Some(input) = input.downcast_ref::<f64>() {
15            Ok(Box::new(format!("Processed Downlink: {:.2}", input)))
16        } else {
17            Err(anyhow!("Invalid input type"))
18        }
19    }
20
21    fn convert_out(
22        &self,
23        output: Box<dyn Any + Send>,
24    ) -> Result<Box<dyn Any + Send>, anyhow::Error> {
25        Ok(Box::new("Processed Uplink".to_string()))
26    }
27}
28
29#[derive(Debug, Clone)]
30pub struct ModbusDriver {}
31
32#[async_trait]
33impl NGDriver for ModbusDriver {
34    async fn initialize(&self) -> Result<(), anyhow::Error> {
35        todo!()
36    }
37
38    async fn run(&self) -> Result<(), anyhow::Error> {
39        todo!()
40    }
41
42    async fn execute_command(
43        &self,
44        device_id: i32,
45        command: &str,
46        params: Box<dyn Any + Send>,
47    ) -> Result<Box<dyn Any + Send>, anyhow::Error> {
48        todo!()
49    }
50
51    async fn shutdown(&self) -> Result<(), anyhow::Error> {
52        todo!()
53    }
54
55    fn converter(&self) -> Box<dyn NGConverter> {
56        todo!()
57    }
58
59    fn name(&self) -> &'static str {
60        "modbus"
61    }
62}
63
64impl ModbusDriver {
65    pub fn new() -> Self {
66        ModbusDriver {}
67    }
68}