Commit 1a34fc70 by wzc-a

Merge remote-tracking branch 'origin/master'

parents 04ad946d 600bff40
......@@ -12,8 +12,8 @@ byteorder = "1.5"
csv = "1.3"
protobuf = { version = "3.5", features = ["with-bytes"] }
serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11"
serde_json = "1.0"
ciborium = "0.2"
petgraph = "0.6"
rayon = "1.10"
num-traits = "0.2"
......
......@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
[dependencies]
log = "0.4"
serde_json = "1.0"
serde_cbor = "0.11"
ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] }
csv = "1.3.0"
num-complex = "0.4"
......@@ -18,4 +18,5 @@ nalgebra = "0.33"
ds-common = { path = "../ds-common" }
eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" }
\ No newline at end of file
mems = { path = "../../../mems" }
bytes = "1.6.1"
\ No newline at end of file
......@@ -3,24 +3,26 @@
use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use ndarray::Array2;
use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo};
use ds_common::{DEV_CONDUCTOR_DF_NAME, DEV_TOPO_DF_NAME, DS_PF_NLP_CONS, DS_PF_NLP_OBJ, DYN_TOPO_DF_NAME, TN_INPUT_DF_NAME};
use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo};
use ds_common::tn_input::read_tn_input;
use mems::model::{get_wasm_result, PluginInput, PluginOutput};
use mems::model::{PluginInput, PluginOutput};
use crate::read::read_dev_ohm;
mod read;
mod nlp;
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串
let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap();
let input: PluginInput = ciborium::from_reader(slice).unwrap();
input
};
let from = 0;
......@@ -81,13 +83,12 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
}
}
}
if error.is_some() {
let output = PluginOutput {
let output = if error.is_some() {
PluginOutput {
error_msg: error,
schema: None,
csv_bytes: vec![],
};
get_wasm_result(output)
}
} else {
let mut obj_csv_str = String::from("cn,tn\n");
// build schema
......@@ -105,11 +106,17 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
(DS_PF_NLP_OBJ.to_string(), obj_csv_str.into_bytes()),
(DS_PF_NLP_CONS.to_string(), cons_csv_str.into_bytes()),
];
let output = PluginOutput {
PluginOutput {
error_msg: None,
schema: Some(vec![obj_schema, cons_schema]),
csv_bytes,
};
get_wasm_result(output)
}
}
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
}
\ No newline at end of file
......@@ -9,10 +9,11 @@ crate-type = ["cdylib"]
[dependencies]
log = "0.4"
serde_json = "1.0"
serde_cbor = "0.11"
ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] }
petgraph = "0.6"
eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" }
csv = "1.3.0"
ndarray = "0.15"
bytes = "1.6.1"
use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use csv::StringRecordsIter;
use log::{info, warn};
use ndarray::{Array2, ArrayBase, Ix2, OwnedRepr};
use eig_domain::PropValue;
use mems::model::{get_csv_str, get_df_from_in_plugin, get_island_from_plugin_input, get_wasm_result, PluginInput, PluginOutput};
use mems::model::{get_csv_str, get_df_from_in_plugin, get_island_from_plugin_input, PluginInput, PluginOutput};
use mems::model::dev::PsRsrType;
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 {
info!("Read plugin input firstly");
// 从内存中获取字符串
let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap();
let input: PluginInput = ciborium::from_reader(slice).unwrap();
input
};
let mut error = None;
......@@ -76,27 +80,32 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
}
}
}
if error.is_none() {
let output = if error.is_none() {
// build schema
let schema = Schema::new(vec![
Field::new("dev_id", DataType::UInt64, false),
Field::new("ohm", DataType::Utf8, false),
]);
let csv_bytes = vec![("".to_string(), csv_str.into_bytes())];
let output = PluginOutput {
PluginOutput {
error_msg: None,
schema: Some(vec![schema]),
csv_bytes,
};
get_wasm_result(output)
}
} else {
let output = PluginOutput {
PluginOutput {
error_msg: error,
schema: None,
csv_bytes: vec![],
};
get_wasm_result(output)
}
}
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
}
fn read_config(records: &mut StringRecordsIter<&[u8]>)
......
......@@ -9,8 +9,9 @@ crate-type = ["cdylib"]
[dependencies]
log = "0.4"
csv = "1.3.0"
serde_cbor = "0.11"
ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] }
eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" }
ds-common = { path = "../ds-common" }
\ No newline at end of file
ds-common = { path = "../ds-common" }
bytes = "1.6.1"
\ No newline at end of file
use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use ds_common::{DEV_TOPO_DF_NAME, DYN_TOPO_DF_NAME, POINT_DF_NAME, STATIC_TOPO_DF_NAME, TERMINAL_DF_NAME};
use ds_common::static_topo::{read_static_topo, read_point_terminal, read_terminal_cn_dev};
use ds_common::static_topo::{read_point_terminal, read_static_topo, read_terminal_cn_dev};
use eig_domain::DataUnit;
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, get_wasm_result, ModelType, PluginInput, PluginOutput};
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, ModelType, PluginInput, PluginOutput};
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串
let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap();
let input: PluginInput = ciborium::from_reader(slice).unwrap();
input
};
let mut error = None;
......@@ -60,7 +62,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
}
}
}
if error.is_none() {
let output = if error.is_none() {
let (meas, units) = r1.unwrap();
let mut point_map: HashMap<u64, u64> = HashMap::with_capacity(points.len());
let mut terminal_cn: HashMap<u64, u64> = HashMap::with_capacity(points.len());
......@@ -195,18 +197,23 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
csv_bytes.push((DEV_TOPO_DF_NAME.to_string(), dev_csv.into_bytes()));
schema.push(dev_schema);
}
let output = PluginOutput {
PluginOutput {
error_msg: None,
schema: Some(schema),
csv_bytes,
};
get_wasm_result(output)
}
} else {
let output = PluginOutput {
PluginOutput {
error_msg: error,
schema: None,
csv_bytes: vec![],
};
get_wasm_result(output)
}
}
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
}
\ No newline at end of file
......@@ -9,8 +9,9 @@ crate-type = ["cdylib"]
[dependencies]
log = "0.4"
csv = "1.3.0"
serde_cbor = "0.11"
ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] }
ds-common = { path = "../ds-common" }
eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" }
\ No newline at end of file
mems = { path = "../../../mems" }
bytes = "1.6.1"
\ No newline at end of file
......@@ -4,21 +4,24 @@ use std::io::Write;
use std::path::PathBuf;
use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use ds_common::{DEV_TOPO_DF_NAME, POINT_DF_NAME, SHUNT_MEAS_DF_NAME, TERMINAL_DF_NAME, TN_INPUT_DF_NAME};
use ds_common::dyn_topo::read_dev_topo;
use ds_common::static_topo::{read_point_terminal, read_terminal_cn_dev};
use ds_common::tn_input::read_shunt_measures;
use eig_domain::{DataUnit, MeasureValue};
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, get_wasm_result, PluginInput, PluginOutput};
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, PluginInput, PluginOutput};
use mems::model::dev::{MeasPhase, PsRsrType};
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串
let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap();
let input: PluginInput = ciborium::from_reader(slice).unwrap();
input
};
let r2 = get_df_from_in_plugin(&input);
......@@ -82,13 +85,12 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
from += size;
}
}
if error.is_some() {
let output = PluginOutput {
let output = if error.is_some() {
PluginOutput {
error_msg: error,
schema: None,
csv_bytes: vec![],
};
get_wasm_result(output)
}
} else {
if with_static {
let mut csv_str = String::from("point,terminal,phase\n");
......@@ -138,24 +140,22 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
}
// write graph
let csv_bytes = vec![(SHUNT_MEAS_DF_NAME.to_string(), csv_str.into_bytes())];
let output = PluginOutput {
PluginOutput {
error_msg: None,
schema: Some(vec![schema]),
csv_bytes,
};
get_wasm_result(output)
}
} else {
let r1 = get_meas_from_plugin_input(&input);
if let Err(s) = &r1 {
error = Some(s.clone());
}
if error.is_some() {
let output = PluginOutput {
PluginOutput {
error_msg: error,
schema: None,
csv_bytes: vec![],
};
get_wasm_result(output)
}
} else {
let (meas, units) = r1.unwrap();
let len = terminal_of_shunt_dev.len();
......@@ -253,15 +253,21 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
let _ = file.sync_all();
}
let csv_bytes = vec![(TN_INPUT_DF_NAME.to_string(), csv_str.into_bytes())];
let output = PluginOutput {
PluginOutput {
error_msg: None,
schema: Some(vec![schema]),
csv_bytes,
};
get_wasm_result(output)
}
}
}
}
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
}
unsafe fn create_measure(m: &MeasureValue, phase: &MeasPhase, ratio: f64,
......
......@@ -8,7 +8,8 @@ crate-type = ["cdylib"]
[dependencies]
log = "0.4"
serde_cbor = "0.11"
ciborium = "0.2"
arrow-schema = { version = "52.1", features = ["serde"] }
petgraph = "0.6"
mems = { path = "../../../mems" }
\ No newline at end of file
mems = { path = "../../../mems" }
bytes = "1.6.1"
\ No newline at end of file
use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema};
use bytes::{Buf, BufMut, BytesMut};
use petgraph::graph::UnGraph;
use mems::model::{get_csv_str, get_island_from_plugin_input, get_wasm_result, ModelType, PluginInput, PluginOutput};
use mems::model::{get_csv_str, get_island_from_plugin_input, ModelType, PluginInput, PluginOutput};
use mems::model::dev::{CN, Island, PropDefine, PsRsrType, RsrDefine};
// use std::fs;
......@@ -14,13 +15,14 @@ const NORMAL_OPEN: &str = "normalOpen";
const STATIC_TOPO_DF_NAME: &str = "static_topo";
const TERMINAL_DF_NAME: &str = "terminal_cn_dev";
const POINT_DF_NAME: &str = "point_terminal_phase";
static mut OUTPUT: Vec<u8> = vec![];
#[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串
let input = unsafe {
let slice = std::slice::from_raw_parts(ptr as _, len as _);
let input: PluginInput = serde_cbor::from_slice(slice).unwrap();
let input: PluginInput =ciborium::from_reader(slice).unwrap();
input
};
let mut error = None;
......@@ -28,7 +30,7 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
if let Err(s) = &r {
error = Some(s.clone());
}
if error.is_none() {
let output = if error.is_none() {
let (island, prop_defs, defines) = r.unwrap();
let mut outgoing = vec![];
for model_input in &input.model {
......@@ -114,20 +116,25 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
if !is_matched {
create_static_topo(&island, &prop_defs, &defines, &mut csv_bytes, &mut schema);
}
let output = PluginOutput {
PluginOutput {
error_msg: None,
schema: Some(schema),
csv_bytes,
};
get_wasm_result(output)
}
} else {
let output = PluginOutput {
PluginOutput {
error_msg: error,
schema: None,
csv_bytes: vec![],
};
get_wasm_result(output)
}
}
};
ciborium::into_writer(&output, &mut OUTPUT).unwrap();
let offset = OUTPUT.as_ptr() as i32;
let len = OUTPUT.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
}
fn create_static_topo(island: &Island, prop_defs: &[PropDefine], defines: &HashMap<u64, RsrDefine>, csv_bytes: &mut Vec<(String, Vec<u8>)>, schema: &mut Vec<Schema>) {
......
use std::collections::HashMap;
use bytes::{Buf, BufMut, BytesMut};
use serde::{Deserialize, Serialize};
use eig_aoe::aoe::AoeModel;
......@@ -301,7 +301,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec<
}
let size = input.model_len[index] as usize;
let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]);
let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() {
return Err(format!("{:?}", r));
}
......@@ -313,7 +313,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec<
}
let size = input.model_len[index] as usize;
let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]);
let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() {
return Err(format!("{:?}", r));
}
......@@ -325,7 +325,7 @@ pub fn get_island_from_plugin_input(input: &PluginInput) -> Result<(Island, Vec<
}
let size = input.model_len[index] as usize;
let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]);
let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() {
return Err(format!("{:?}", r));
}
......@@ -359,7 +359,7 @@ pub fn get_meas_from_plugin_input(input: &PluginInput) -> Result<(Vec<MeasureVal
}
let size = input.model_len[index] as usize;
let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]);
let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() {
return Err(format!("{:?}", r));
}
......@@ -371,7 +371,7 @@ pub fn get_meas_from_plugin_input(input: &PluginInput) -> Result<(Vec<MeasureVal
}
let size = input.model_len[index] as usize;
let end = from + size;
let r = serde_cbor::from_slice(&input.bytes[from..end]);
let r = ciborium::from_reader(&input.bytes[from..end]);
if r.is_err() {
return Err(format!("{:?}", r));
}
......@@ -431,17 +431,19 @@ pub fn get_df_from_in_plugin(input: &PluginInput) -> Result<usize, String> {
Ok(from)
}
#[inline]
pub fn get_wasm_result(output: PluginOutput) -> u64 {
// 下面的unwrap是必要的,否则输出的字节无法解析
let v = serde_cbor::to_vec(&output).unwrap();
let offset = v.as_ptr() as i32;
let len = v.len() as u32;
let mut bytes = BytesMut::with_capacity(8);
bytes.put_i32(offset);
bytes.put_u32(len);
return bytes.get_u64();
}
// #[inline]
// pub fn get_wasm_result(output: PluginOutput) -> u64 {
// // 下面的unwrap是必要的,否则输出的字节无法解析
// let mut v = Vec::new();
// ciborium::into_writer(&output, &mut v).unwrap();
// v.shrink_to_fit();
// let offset = v.as_ptr() as i32;
// let len = v.len() as u32;
// let mut bytes = BytesMut::with_capacity(8);
// bytes.put_i32(offset);
// bytes.put_u32(len);
// return bytes.get_u64();
// }
#[inline]
pub fn get_csv_str(s: &str) -> String {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论