diff --git a/Cargo.lock b/Cargo.lock index a23fba34..75b02198 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,18 +1197,18 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opslang-ast" -version = "0.2.1" +version = "0.3.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae4c0ff39acd1a3906e9b76840fd6c6621d6b9c92e4bdac59fcf494dd2e23b28" +checksum = "6ac257feba94b0478cd25a563d167af91b14348313f1ba08fac680d66f8c410c" dependencies = [ "chrono", ] [[package]] name = "opslang-parser" -version = "0.2.1" +version = "0.3.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a1dba971ae003dbfd8bc0423f78d89b7e82e658c73fcf29f5e83233db64d45d" +checksum = "fc899fb2b811f7fce452ad720513b08e60c3af5353142130cc612207b66ff96c" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 09780be5..93e0dd47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,4 @@ structpack = "1.0" gaia-stub = "1.0" gaia-ccsds-c2a = "1.0" gaia-tmtc = "1.0" -c2a-devtools-frontend = "1.0" +c2a-devtools-frontend = { path = "devtools-frontend" } diff --git a/devtools-frontend/crates/Cargo.lock b/devtools-frontend/crates/Cargo.lock index d6e88a9a..f8464d66 100644 --- a/devtools-frontend/crates/Cargo.lock +++ b/devtools-frontend/crates/Cargo.lock @@ -164,18 +164,18 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opslang-ast" -version = "0.2.1" +version = "0.3.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae4c0ff39acd1a3906e9b76840fd6c6621d6b9c92e4bdac59fcf494dd2e23b28" +checksum = "6ac257feba94b0478cd25a563d167af91b14348313f1ba08fac680d66f8c410c" dependencies = [ "chrono", ] [[package]] name = "opslang-parser" -version = "0.2.1" +version = "0.3.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a1dba971ae003dbfd8bc0423f78d89b7e82e658c73fcf29f5e83233db64d45d" +checksum = "fc899fb2b811f7fce452ad720513b08e60c3af5353142130cc612207b66ff96c" dependencies = [ "anyhow", "chrono", diff --git a/devtools-frontend/crates/Cargo.toml b/devtools-frontend/crates/Cargo.toml deleted file mode 100644 index 04d3bba0..00000000 --- a/devtools-frontend/crates/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[workspace] -resolver = "2" - -members = [ - "opslang-wasm", -] - -[workspace.package] -version = "1.0.0" -description = "A command and control system for C2A-based satellites" -repository = "https://github.com/arkedge/gaia" -license = "MPL-2.0" - -# profile config should be set in workspace root -[profile.release] -# Tell `rustc` to optimize for small code size. -opt-level = "s" diff --git a/devtools-frontend/crates/opslang-wasm/Cargo.toml b/devtools-frontend/crates/opslang-wasm/Cargo.toml index 045f25fe..35c71d4a 100644 --- a/devtools-frontend/crates/opslang-wasm/Cargo.toml +++ b/devtools-frontend/crates/opslang-wasm/Cargo.toml @@ -18,8 +18,8 @@ default = ["console_error_panic_hook"] wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" web-sys = { version = "0.3.69", features = ["console"] } -opslang-ast = "0.2.1" -opslang-parser = "0.2.1" +opslang-ast = "0.3.0-alpha.1" +opslang-parser = "0.3.0-alpha.1" async-recursion = "1.1.0" # The `console_error_panic_hook` crate provides better debugging of panics by diff --git a/devtools-frontend/crates/opslang-wasm/js/union.js b/devtools-frontend/crates/opslang-wasm/js/union.js index ec8c100f..eff7e794 100644 --- a/devtools-frontend/crates/opslang-wasm/js/union.js +++ b/devtools-frontend/crates/opslang-wasm/js/union.js @@ -12,6 +12,7 @@ export const asInt = asKind("integer"); export const asDouble = asKind("double"); export const asBool = asKind("bool"); export const asArray = asKind("array"); +export const asBytes = asKind("bytes"); export const asString = asKind("string"); export const asDuration = asKind("duration"); export const asDateTime = asKind("datetime"); @@ -29,6 +30,7 @@ export const makeInt = make("integer"); export const makeDouble = make("double"); export const makeBool = make("bool"); export const makeArray = make("array"); +export const makeBytes = make("bytes"); export const makeString = make("string"); export const makeDuration = make("duration"); export const makeDateTime = make("datetime"); diff --git a/devtools-frontend/crates/opslang-wasm/src/lib.rs b/devtools-frontend/crates/opslang-wasm/src/lib.rs index e4376c97..94764542 100644 --- a/devtools-frontend/crates/opslang-wasm/src/lib.rs +++ b/devtools-frontend/crates/opslang-wasm/src/lib.rs @@ -225,6 +225,7 @@ impl Runner { .collect::>() .map(Value::Array), Numeric(num, s) => self.numeric(num, s), + Bytes(b) => Ok(Value::Bytes(b.clone())), String(s) => Ok(Value::String((*s).to_owned())), DateTime(d) => Ok(Value::DateTime(*d)), TlmId(tlm_id) => { @@ -386,7 +387,7 @@ impl Runner { Double(x) => Ok(Double(-x)), Bool(x) => Ok(Bool(!x)), Duration(x) => Ok(Duration(-x)), - Array(_) | String(_) | DateTime(_) => { + Array(_) | String(_) | DateTime(_) | Bytes(_) => { type_err("numeric, bool, or duration", &v) } } @@ -401,6 +402,7 @@ impl Runner { Double(x) => x.partial_cmp(&right.double()?), Bool(x) => Some(x.cmp(&right.bool()?)), Array(_) => return type_err("comparable", left), + Bytes(_) => return type_err("comparable", left), String(x) => Some(x[..].cmp(right.string()?)), Duration(x) => Some(x.cmp(&right.duration()?)), DateTime(x) => Some(x.cmp(&right.datetime()?)), diff --git a/devtools-frontend/crates/opslang-wasm/src/union_value.rs b/devtools-frontend/crates/opslang-wasm/src/union_value.rs index 7c4e1856..5e156e21 100644 --- a/devtools-frontend/crates/opslang-wasm/src/union_value.rs +++ b/devtools-frontend/crates/opslang-wasm/src/union_value.rs @@ -6,6 +6,7 @@ type Value = {kind : "double", value : number} | {kind : "bool", value : boolean } | {kind: "array", value : Value[] } | + {kind: "bytes", value : Uint8Array } | {kind: "string", value: string } | {kind: "duration", value: bigint } | {kind: "datetime", value: bigint } @@ -24,6 +25,8 @@ extern "C" { fn as_bool(_: &UnionValue) -> Option; #[wasm_bindgen(js_name = "asArray")] fn as_array(_: &UnionValue) -> Option>; + #[wasm_bindgen(js_name = "asBytes")] + fn as_bytes(_: &UnionValue) -> Option>; #[wasm_bindgen(js_name = "asString")] fn as_string(_: &UnionValue) -> Option; #[wasm_bindgen(js_name = "asDuration")] @@ -39,6 +42,8 @@ extern "C" { fn make_bool(_: bool) -> UnionValue; #[wasm_bindgen(js_name = "makeArray")] fn make_array(_: Vec) -> UnionValue; + #[wasm_bindgen(js_name = "makeBytes")] + fn make_bytes(_: Vec) -> UnionValue; #[wasm_bindgen(js_name = "makeString")] fn make_string(_: std::string::String) -> UnionValue; #[wasm_bindgen(js_name = "makeDuration")] @@ -61,6 +66,8 @@ impl From for Value { } else if let Some(vs) = as_array(&v) { let vs = vs.into_iter().map(Into::into).collect(); Array(vs) + } else if let Some(v) = as_bytes(&v) { + Bytes(v) } else if let Some(v) = as_string(&v) { String(v) } else if let Some(v) = as_duration(&v) { @@ -83,6 +90,7 @@ impl From for UnionValue { let vs = vs.into_iter().map(Into::into).collect(); make_array(vs) } + Bytes(v) => make_bytes(v), String(v) => make_string(v), Duration(v) => make_duration(v.num_milliseconds()), DateTime(v) => make_datetime(v.timestamp_millis()), diff --git a/devtools-frontend/crates/opslang-wasm/src/value.rs b/devtools-frontend/crates/opslang-wasm/src/value.rs index 9b11a9a3..80f3321e 100644 --- a/devtools-frontend/crates/opslang-wasm/src/value.rs +++ b/devtools-frontend/crates/opslang-wasm/src/value.rs @@ -7,6 +7,7 @@ pub(crate) enum Value { Double(f64), Bool(bool), Array(Vec), + Bytes(Vec), String(String), Duration(chrono::Duration), DateTime(chrono::DateTime), @@ -50,6 +51,7 @@ impl Value { Double(_) => "double", Bool(_) => "bool", Array(_) => "array", + Bytes(_) => "bytes", String(_) => "string", Duration(_) => "duration", DateTime(_) => "datetime", @@ -82,6 +84,13 @@ impl Value { } } + pub fn bytes(&self) -> Result<&[u8]> { + match self { + Value::Bytes(x) => Ok(x), + _ => type_err("bytes", self), + } + } + pub fn duration(&self) -> Result { self.cast() } diff --git a/devtools-frontend/package.json b/devtools-frontend/package.json index 2d6f18ea..ff7ddae6 100644 --- a/devtools-frontend/package.json +++ b/devtools-frontend/package.json @@ -32,6 +32,7 @@ "@protobuf-ts/grpcweb-transport": "^2.8.2", "@protobuf-ts/runtime": "^2.9.3", "@protobuf-ts/runtime-rpc": "^2.9.3", + "c2a-devtools": "link:", "monaco-editor": "^0.48.0", "react": "18.3.0", "react-dom": "18.3.0", diff --git a/devtools-frontend/pnpm-lock.yaml b/devtools-frontend/pnpm-lock.yaml index 67f02945..803a8f98 100644 --- a/devtools-frontend/pnpm-lock.yaml +++ b/devtools-frontend/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: '@protobuf-ts/runtime-rpc': specifier: ^2.9.3 version: 2.9.4 + c2a-devtools: + specifier: 'link:' + version: 'link:' monaco-editor: specifier: ^0.48.0 version: 0.48.0 diff --git a/devtools-frontend/src/components/CommandView.tsx b/devtools-frontend/src/components/CommandView.tsx index 773bf8eb..971e275b 100644 --- a/devtools-frontend/src/components/CommandView.tsx +++ b/devtools-frontend/src/components/CommandView.tsx @@ -261,7 +261,7 @@ class Driver implements opslang.Driver { executorComponent, command, }, - parameters: fullParams.map((arg): ParameterValue => { + parameters: fullParams.map((arg: opslang.Value): ParameterValue => { if (arg.kind === "integer") { return { type: "integer", @@ -272,6 +272,12 @@ class Driver implements opslang.Driver { type: "double", double: arg.value, }; + } else if (arg.kind === "bytes") { + return { + type: "bytes", + bytes: arg.value, + bigint: BigInt(0), // dummy ??? + }; } else if (arg.kind === "datetime") { const datetimeOrigin = this.datetimeOrigin.get(receiverComponent); if (datetimeOrigin === undefined) {