rust

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
rust [2021/08/11 12:56]
wikiadmin
rust [2024/05/21 17:01] (current)
wikiadmin
Line 49: Line 49:
 <code rust> <code rust>
 //! Simple GEM host example showing how to start a host and subscribe to some variables //! Simple GEM host example showing how to start a host and subscribe to some variables
- 
 use transsecs::transsecs_wrapper::TransSecsWrapper; use transsecs::transsecs_wrapper::TransSecsWrapper;
-use transsecs::value_object::{Value};+use transsecs::value_object::Value;
 use std::{thread, time}; use std::{thread, time};
- +use serde::{Deserialize, Serialize, Serializer}; 
-use serde::{Serialize, Deserialize}; +use serde::ser::SerializeStruct; 
 +use anyhow::Result;
 #[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
 struct LoadedCeid { struct LoadedCeid {
Line 61: Line 60:
     reports:Vec<Report>     reports:Vec<Report>
 } }
- 
- 
 #[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
 struct Report { struct Report {
-    #[serde(rename="RPTID103")]+    #[serde(rename="LOADED_REPORT")]
     values:Vec<ReportValue>     values:Vec<ReportValue>
 } }
- 
 #[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
 #[serde(untagged)] #[serde(untagged)]
Line 74: Line 70:
     LotID{     LotID{
         #[serde(rename="LOTID")]         #[serde(rename="LOTID")]
-        lot_id:String, +        lot_id:String,
         #[serde(rename="type")]         #[serde(rename="type")]
         type_int:i32         type_int:i32
     },     },
-    PPID+    CLOCK
-        #[serde(rename="PPID")] +        #[serde(rename="CLOCK")] 
-        ppid:String, +        clock:String,
         #[serde(rename="type")]         #[serde(rename="type")]
         type_int:i32         type_int:i32
-    }, +    } 
-    WaferCount+
-        #[serde(rename="WaferCount")] +#[derive(Deserialize)] 
-        wafer_count:String,  +struct SecsValue { 
-        #[serde(rename="type")] +    value: String, 
-        type_int:i32}+
 +impl Serialize for SecsValue { 
 +    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 
 +    where 
 +        S: Serializer
 +    { 
 +        let mut s = serializer.serialize_struct("SecsValue", 2)?; 
 +        s.serialize_field("value", &self.value)?; 
 +        s.serialize_field("type", &20)?; 
 +        s.end() 
 +    } 
 +
 +#[derive(Deserialize)] 
 +struct CommandParams { 
 +    values: Vec<(SecsValue, SecsValue)>, 
 +
 +struct TupleAsObject<'a>(&'a (SecsValue, SecsValue)); 
 +impl<'a> Serialize for TupleAsObject<'a>
 +    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 
 +    where 
 +        S: Serializer, 
 +    { 
 +        let mut s serializer.serialize_struct("TupleAsObject", 2)?; 
 +        s.serialize_field("values", &vec![&self.0 .0.value, &self.0 .1.value])?; 
 +        s.serialize_field("type", &20)?; 
 +        s.end() 
 +    } 
 +
 +impl Serialize for CommandParams { 
 +    fn serialize<S>(&self, serializerS) -> Result<S::OkS::Error> 
 +    where 
 +        S: Serializer, 
 +    { 
 +        let values: Vec<_> = self.values.iter().map(TupleAsObject).collect(); 
 +        let mut s = serializer.serialize_struct("CommandParams", 1)?; 
 +        s.serialize_field("values", &values)?; 
 +        s.end() 
 +    } 
 +
 +#[derive(Serialize, Deserialize)] 
 +struct S2F41 { 
 +    #[serde(rename = "Command")] 
 +    commandSecsValue, 
 +    #[serde(rename = "CommandParams")] 
 +    command_params: CommandParams,
 } }
- 
 // examples/gem_host_example.rs // examples/gem_host_example.rs
-fn main() { +fn main() -> Result<()>
-    let wrapper = TransSecsWrapper::new("./GEMHostRuntime.jar").unwrap(); +    let mut wrapper = TransSecsWrapper::new::<String>(None)?;
     let port = 5010;     let port = 5010;
     wrapper.publish_string("gemhost/configuration/persistencefilename", "/tmp/testpersistence").unwrap();     wrapper.publish_string("gemhost/configuration/persistencefilename", "/tmp/testpersistence").unwrap();
Line 100: Line 138:
     wrapper.publish_int("gemhost/configuration/deviceid", 1).unwrap();     wrapper.publish_int("gemhost/configuration/deviceid", 1).unwrap();
     wrapper.publish_int("gemhost/configuration/activeport", port).unwrap();     wrapper.publish_int("gemhost/configuration/activeport", port).unwrap();
- 
     wrapper.start_main("GEMHost").unwrap();     wrapper.start_main("GEMHost").unwrap();
- 
     wrapper.subscribe("gemhost/variables/ceid/loaded", |topic,value| {     wrapper.subscribe("gemhost/variables/ceid/loaded", |topic,value| {
         println!("Callback called on {}:", topic);         println!("Callback called on {}:", topic);
Line 112: Line 148:
         }         }
     }).unwrap();     }).unwrap();
- +    wrapper.subscribe("gemhost/variables/vid/clock", |topic,value| {
-    wrapper.subscribe("gemhost/variables/vid/ppid", |topic,value| {+
         println!("Callback called on {} with {:?}", topic, value)         println!("Callback called on {} with {:?}", topic, value)
     }).unwrap();     }).unwrap();
- 
     wrapper.subscribe("gemhost/variables/vid/lotid", |topic,value| {     wrapper.subscribe("gemhost/variables/vid/lotid", |topic,value| {
         println!("Callback called on {} with {:?}", topic, value)         println!("Callback called on {} with {:?}", topic, value)
     }).unwrap();     }).unwrap();
-    +    let gem_model_json = include_str!("../GEMHostModel.json"); 
 +    wrapper.set_gem_model(gem_model_json).unwrap();
     loop{     loop{
 +        let host_command_start = S2F41 {
 +            command: SecsValue {
 +                value: "START".to_string(),
 +            },
 +            command_params: CommandParams {
 +                values: vec![
 +                    (SecsValue {
 +                        value: "PPID".to_string(),
 +                    },
 +                    SecsValue {
 +                        value: "warm".to_string(),
 +                    })
 +                ]
 +            },
 +        };
 +        // wrapper.publish_json("gemhost/hostcommand/sendmessage", serde_json::to_string(&host_command_start).unwrap()).unwrap();
 +        // wrapper.publish_json("gemhost/svidrequest/sendmessage", "{\"SVID\": { \"value\":\"33003\", \"type\":54 }}").unwrap();
 +        let complicated_s2f41 = include_str!("../s2f41.json");
 +        wrapper.publish_json("gemhost/hostcommand/sendmessage", complicated_s2f41).unwrap();
         thread::sleep(time::Duration::from_secs(10));         thread::sleep(time::Duration::from_secs(10));
     } // If we drop the wrapper, it will cleanup the jvm     } // If we drop the wrapper, it will cleanup the jvm
 } }
 </code> </code>
  • rust.1628704576.txt.gz
  • Last modified: 2021/08/11 12:56
  • by wikiadmin