From 2e1eecfdad60f0d706b84d7d9ad4d2e9500f6e1c Mon Sep 17 00:00:00 2001 From: soul-walker <31162815+soul-walker@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=E5=A4=A7?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .vscode/launch.json | 16 + .vscode/settings.json | 2 + Cargo.lock | 215 ++++--- Cargo.toml | 32 +- crates/rtss_api/src/apis/simulation.rs | 105 ---- .../src/apis/simulation_definition.rs | 35 -- crates/rtss_db/Cargo.toml | 1 + crates/rtss_db/src/db_access/draft_data.rs | 2 +- crates/rtss_db/src/db_access/feature.rs | 10 +- crates/rtss_db/src/db_access/mod.rs | 28 + crates/rtss_db/src/db_access/release_data.rs | 10 +- crates/rtss_db/src/db_access/user.rs | 10 +- crates/rtss_dto/Cargo.toml | 1 + crates/rtss_dto/build.rs | 1 + crates/rtss_dto/src/lib.rs | 24 + crates/rtss_dto/src/pb/iscs_graphic_data.rs | 525 ++++++++++++++++-- crates/rtss_dto/src/pb/mod.rs | 1 + crates/rtss_dto/src/pb/simulation.rs | 77 +++ crates/rtss_mqtt/Cargo.toml | 3 +- crates/rtss_mqtt/src/lib.rs | 236 +++++--- manager/Cargo.toml | 15 + {conf => manager/conf}/default.toml | 0 {conf => manager/conf}/dev.toml | 0 {conf => manager/conf}/local_test.toml | 0 .../crates}/rtss_api/Cargo.toml | 9 +- .../rtss_api/src/apis/data_options_def.rs | 0 .../crates}/rtss_api/src/apis/draft_data.rs | 0 .../crates}/rtss_api/src/apis/feature.rs | 0 .../rtss_api/src/apis/feature_config_def.rs | 0 .../crates}/rtss_api/src/apis/mod.rs | 3 - .../crates}/rtss_api/src/apis/release_data.rs | 0 .../crates}/rtss_api/src/apis/sys_info.rs | 0 .../crates}/rtss_api/src/apis/user.rs | 0 .../crates}/rtss_api/src/lib.rs | 0 .../crates}/rtss_api/src/loader/mod.rs | 0 .../crates}/rtss_api/src/server.rs | 0 .../rtss_api/src/user_auth/jwt_auth.rs | 0 .../crates}/rtss_api/src/user_auth/mod.rs | 0 {src => manager/src}/app_config.rs | 0 {src => manager/src/commands}/cmd.rs | 4 +- {src => manager/src/commands}/db.rs | 0 src/lib.rs => manager/src/commands/mod.rs | 1 - manager/src/lib.rs | 4 + {src => manager/src}/main.rs | 2 +- rtss-proto-msg | 2 +- simulation/Cargo.toml | 24 + simulation/conf/default.toml | 9 + simulation/conf/dev.toml | 7 + simulation/conf/local_test.toml | 10 + .../crates}/rtss_ci/Cargo.toml | 0 .../crates}/rtss_ci/src/lib.rs | 0 .../crates}/rtss_common/Cargo.toml | 0 .../crates}/rtss_common/src/lib.rs | 0 .../crates}/rtss_iscs/Cargo.toml | 0 .../crates}/rtss_iscs/src/lib.rs | 0 .../crates}/rtss_sim_manage/Cargo.toml | 2 +- .../rtss_sim_manage/src/config_plugins.rs | 0 .../crates}/rtss_sim_manage/src/lib.rs | 0 simulation/crates/rtss_sim_manage/src/main.rs | 4 + .../crates}/rtss_sim_manage/src/simulation.rs | 0 .../crates}/rtss_trackside/Cargo.toml | 2 +- .../rtss_trackside/src/components/bundle.rs | 0 .../src/components/equipment.rs | 0 .../rtss_trackside/src/components/mod.rs | 0 .../rtss_trackside/src/events/equipment.rs | 0 .../crates}/rtss_trackside/src/events/mod.rs | 0 .../crates}/rtss_trackside/src/lib.rs | 0 .../crates}/rtss_trackside/src/plugin.rs | 0 .../rtss_trackside/src/resources/mod.rs | 0 .../rtss_trackside/src/systems/common.rs | 0 .../rtss_trackside/src/systems/loading.rs | 0 .../crates}/rtss_trackside/src/systems/mod.rs | 0 .../rtss_trackside/src/systems/turnout.rs | 0 simulation/src/app_config.rs | 87 +++ simulation/src/commands/cmd.rs | 48 ++ simulation/src/commands/db.rs | 29 + simulation/src/commands/mod.rs | 12 + simulation/src/components/mod.rs | 93 ++++ simulation/src/error.rs | 9 + simulation/src/lib.rs | 6 + simulation/src/main.rs | 9 + simulation/src/manage/data_loading_plugin.rs | 18 + simulation/src/manage/mod.rs | 5 + simulation/src/manage/simulation.rs | 157 ++++++ .../src/manage/simulation_control_plugin.rs | 61 ++ simulation/src/modules/ci/mod.rs | 3 + simulation/src/modules/ci/plugin.rs | 10 + simulation/src/modules/mod.rs | 2 + .../modules/trackside/components/bundle.rs | 21 + .../modules/trackside/components/equipment.rs | 40 ++ .../src/modules/trackside/components/mod.rs | 4 + .../src/modules/trackside/events/equipment.rs | 10 + .../src/modules/trackside/events/mod.rs | 2 + simulation/src/modules/trackside/mod.rs | 7 + simulation/src/modules/trackside/plugin.rs | 26 + .../src/modules/trackside/resources/mod.rs | 15 + .../src/modules/trackside/systems/common.rs | 31 ++ .../src/modules/trackside/systems/loading.rs | 17 + .../src/modules/trackside/systems/mod.rs | 6 + .../src/modules/trackside/systems/turnout.rs | 81 +++ 101 files changed, 1823 insertions(+), 419 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 crates/rtss_api/src/apis/simulation.rs delete mode 100644 crates/rtss_api/src/apis/simulation_definition.rs create mode 100644 crates/rtss_dto/src/pb/simulation.rs create mode 100644 manager/Cargo.toml rename {conf => manager/conf}/default.toml (100%) rename {conf => manager/conf}/dev.toml (100%) rename {conf => manager/conf}/local_test.toml (100%) rename {crates => manager/crates}/rtss_api/Cargo.toml (75%) rename {crates => manager/crates}/rtss_api/src/apis/data_options_def.rs (100%) rename {crates => manager/crates}/rtss_api/src/apis/draft_data.rs (100%) rename {crates => manager/crates}/rtss_api/src/apis/feature.rs (100%) rename {crates => manager/crates}/rtss_api/src/apis/feature_config_def.rs (100%) rename {crates => manager/crates}/rtss_api/src/apis/mod.rs (96%) rename {crates => manager/crates}/rtss_api/src/apis/release_data.rs (100%) rename {crates => manager/crates}/rtss_api/src/apis/sys_info.rs (100%) rename {crates => manager/crates}/rtss_api/src/apis/user.rs (100%) rename {crates => manager/crates}/rtss_api/src/lib.rs (100%) rename {crates => manager/crates}/rtss_api/src/loader/mod.rs (100%) rename {crates => manager/crates}/rtss_api/src/server.rs (100%) rename {crates => manager/crates}/rtss_api/src/user_auth/jwt_auth.rs (100%) rename {crates => manager/crates}/rtss_api/src/user_auth/mod.rs (100%) rename {src => manager/src}/app_config.rs (100%) rename {src => manager/src/commands}/cmd.rs (95%) rename {src => manager/src/commands}/db.rs (100%) rename src/lib.rs => manager/src/commands/mod.rs (92%) create mode 100644 manager/src/lib.rs rename {src => manager/src}/main.rs (77%) create mode 100644 simulation/Cargo.toml create mode 100644 simulation/conf/default.toml create mode 100644 simulation/conf/dev.toml create mode 100644 simulation/conf/local_test.toml rename {crates => simulation/crates}/rtss_ci/Cargo.toml (100%) rename {crates => simulation/crates}/rtss_ci/src/lib.rs (100%) rename {crates => simulation/crates}/rtss_common/Cargo.toml (100%) rename {crates => simulation/crates}/rtss_common/src/lib.rs (100%) rename {crates => simulation/crates}/rtss_iscs/Cargo.toml (100%) rename {crates => simulation/crates}/rtss_iscs/src/lib.rs (100%) rename {crates => simulation/crates}/rtss_sim_manage/Cargo.toml (88%) rename {crates => simulation/crates}/rtss_sim_manage/src/config_plugins.rs (100%) rename {crates => simulation/crates}/rtss_sim_manage/src/lib.rs (100%) create mode 100644 simulation/crates/rtss_sim_manage/src/main.rs rename {crates => simulation/crates}/rtss_sim_manage/src/simulation.rs (100%) rename {crates => simulation/crates}/rtss_trackside/Cargo.toml (84%) rename {crates => simulation/crates}/rtss_trackside/src/components/bundle.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/components/equipment.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/components/mod.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/events/equipment.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/events/mod.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/lib.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/plugin.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/resources/mod.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/systems/common.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/systems/loading.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/systems/mod.rs (100%) rename {crates => simulation/crates}/rtss_trackside/src/systems/turnout.rs (100%) create mode 100644 simulation/src/app_config.rs create mode 100644 simulation/src/commands/cmd.rs create mode 100644 simulation/src/commands/db.rs create mode 100644 simulation/src/commands/mod.rs create mode 100644 simulation/src/components/mod.rs create mode 100644 simulation/src/error.rs create mode 100644 simulation/src/lib.rs create mode 100644 simulation/src/main.rs create mode 100644 simulation/src/manage/data_loading_plugin.rs create mode 100644 simulation/src/manage/mod.rs create mode 100644 simulation/src/manage/simulation.rs create mode 100644 simulation/src/manage/simulation_control_plugin.rs create mode 100644 simulation/src/modules/ci/mod.rs create mode 100644 simulation/src/modules/ci/plugin.rs create mode 100644 simulation/src/modules/mod.rs create mode 100644 simulation/src/modules/trackside/components/bundle.rs create mode 100644 simulation/src/modules/trackside/components/equipment.rs create mode 100644 simulation/src/modules/trackside/components/mod.rs create mode 100644 simulation/src/modules/trackside/events/equipment.rs create mode 100644 simulation/src/modules/trackside/events/mod.rs create mode 100644 simulation/src/modules/trackside/mod.rs create mode 100644 simulation/src/modules/trackside/plugin.rs create mode 100644 simulation/src/modules/trackside/resources/mod.rs create mode 100644 simulation/src/modules/trackside/systems/common.rs create mode 100644 simulation/src/modules/trackside/systems/loading.rs create mode 100644 simulation/src/modules/trackside/systems/mod.rs create mode 100644 simulation/src/modules/trackside/systems/turnout.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..fedaa2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.env diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8a27c6a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/", + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index f15e1ed..2399fec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,6 +18,7 @@ "Neng", "nextval", "oneshot", + "otype", "plpgsql", "prost", "proto", @@ -25,6 +26,7 @@ "protos", "repr", "reqwest", + "rtsa", "rtss", "rumqtt", "rumqttc", diff --git a/Cargo.lock b/Cargo.lock index 0d1b94f..ef449a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,9 +121,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.90" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95" +checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" + +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" [[package]] name = "ascii_utils" @@ -133,9 +139,9 @@ checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" [[package]] name = "async-executor" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7ebdfa2ebdab6b1760375fa7d6f382b9f486eac35fc994625a00e89280bdbb7" +checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec" dependencies = [ "async-task", "concurrent-queue", @@ -564,7 +570,7 @@ dependencies = [ "ahash", "bevy_utils_proc_macros", "getrandom", - "hashbrown 0.14.5", + "hashbrown", "thread_local", "tracing", "web-time", @@ -619,9 +625,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" dependencies = [ "serde", ] @@ -713,14 +719,13 @@ dependencies = [ [[package]] name = "config" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" +checksum = "68578f196d2a33ff61b27fae256c3164f65e36382648e30666dde05b8cc9dfdf" dependencies = [ "async-trait", "convert_case", "json5", - "lazy_static", "nom", "pathdiff", "ron", @@ -728,7 +733,7 @@ dependencies = [ "serde", "serde_json", "toml", - "yaml-rust", + "yaml-rust2", ] [[package]] @@ -1076,9 +1081,9 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" [[package]] name = "flume" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" dependencies = [ "futures-core", "futures-sink", @@ -1246,12 +1251,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" - [[package]] name = "hashbrown" version = "0.14.5" @@ -1263,13 +1262,22 @@ dependencies = [ "serde", ] +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown", +] + [[package]] name = "hashlink" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ - "hashbrown 0.14.5", + "hashbrown", ] [[package]] @@ -1491,7 +1499,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown", "serde", ] @@ -1589,12 +1597,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1623,7 +1625,22 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" dependencies = [ - "hashbrown 0.14.5", + "hashbrown", +] + +[[package]] +name = "manager" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "config", + "enum_dispatch", + "rtss_api", + "rtss_db", + "rtss_log", + "serde", + "tokio", ] [[package]] @@ -1834,12 +1851,12 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "ordered-multimap" -version = "0.6.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" +checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" dependencies = [ "dlv-list", - "hashbrown 0.13.2", + "hashbrown", ] [[package]] @@ -2392,15 +2409,12 @@ dependencies = [ "axum", "axum-extra", "base64 0.22.1", - "bevy_ecs", "chrono", "jsonwebtoken", "reqwest", "rtss_db", "rtss_dto", "rtss_log", - "rtss_sim_manage", - "rtss_trackside", "serde", "serde_json", "sysinfo", @@ -2408,22 +2422,12 @@ dependencies = [ "tower-http", ] -[[package]] -name = "rtss_ci" -version = "0.1.0" - -[[package]] -name = "rtss_common" -version = "0.1.0" -dependencies = [ - "bevy_ecs", -] - [[package]] name = "rtss_db" version = "0.1.0" dependencies = [ "anyhow", + "lazy_static", "rtss_dto", "rtss_log", "serde", @@ -2439,14 +2443,11 @@ dependencies = [ "async-graphql", "prost", "prost-build", + "prost-types", "serde", "sqlx", ] -[[package]] -name = "rtss_iscs" -version = "0.1.0" - [[package]] name = "rtss_log" version = "0.1.0" @@ -2463,55 +2464,12 @@ dependencies = [ "async-trait", "bytes", "lazy_static", - "rtss_db", "rtss_log", "rumqttc", "thiserror", "tokio", ] -[[package]] -name = "rtss_sim_manage" -version = "0.1.0" -dependencies = [ - "bevy_app", - "bevy_core", - "bevy_ecs", - "bevy_time", - "rayon", - "rtss_common", - "rtss_log", - "rtss_trackside", - "thiserror", -] - -[[package]] -name = "rtss_simulation" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "config", - "enum_dispatch", - "rtss_api", - "rtss_db", - "rtss_log", - "serde", - "tokio", -] - -[[package]] -name = "rtss_trackside" -version = "0.1.0" -dependencies = [ - "bevy_app", - "bevy_core", - "bevy_ecs", - "bevy_time", - "rtss_common", - "rtss_log", -] - [[package]] name = "rumqttc" version = "0.24.0" @@ -2533,9 +2491,9 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" +checksum = "3e0698206bcb8882bf2a9ecb4c1e7785db57ff052297085a6efd4fe42302068a" dependencies = [ "cfg-if", "ordered-multimap", @@ -2686,18 +2644,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.213" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.213" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" dependencies = [ "proc-macro2", "quote", @@ -2706,9 +2664,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.131" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67d42a0bd4ac281beff598909bb56a86acaf979b84483e1c79c10dcaf98f8cf3" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -2806,6 +2764,29 @@ dependencies = [ "time", ] +[[package]] +name = "simulation" +version = "0.1.0" +dependencies = [ + "anyhow", + "bevy_app", + "bevy_core", + "bevy_ecs", + "bevy_time", + "clap", + "config", + "enum_dispatch", + "lazy_static", + "rayon", + "rtss_db", + "rtss_dto", + "rtss_log", + "rtss_mqtt", + "serde", + "thiserror", + "tokio", +] + [[package]] name = "slab" version = "0.4.9" @@ -2904,8 +2885,8 @@ dependencies = [ "futures-intrusive", "futures-io", "futures-util", - "hashbrown 0.14.5", - "hashlink", + "hashbrown", + "hashlink 0.9.1", "hex", "indexmap", "log", @@ -3127,9 +3108,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.76" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -3180,18 +3161,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", @@ -3265,9 +3246,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" dependencies = [ "backtrace", "bytes", @@ -3536,9 +3517,9 @@ dependencies = [ [[package]] name = "typeid" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "059d83cc991e7a42fc37bd50941885db0888e34209f8cfd9aab07ddec03bc9cf" +checksum = "0e13db2e0ccd5e14a544e8a246ba2312cd25223f616442d7f2cb0e3db614236e" [[package]] name = "typenum" @@ -4054,12 +4035,14 @@ dependencies = [ ] [[package]] -name = "yaml-rust" -version = "0.4.5" +name = "yaml-rust2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +checksum = "8902160c4e6f2fb145dbe9d6760a75e3c9522d8bf796ed7047c85919ac7115f8" dependencies = [ - "linked-hash-map", + "arraydeque", + "encoding_rs", + "hashlink 0.8.4", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f1988e0..37061c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,7 @@ -[package] -name = "rtss_simulation" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace] -members = ["crates/*"] +members = ["crates/*", "manager/crates/*", "manager", "simulation"] +resolver = "2" [workspace.dependencies] bevy_app = "0.14" @@ -14,29 +9,20 @@ bevy_core = "0.14" bevy_ecs = "0.14" bevy_time = "0.14" rayon = "1.10" -tokio = { version = "1.40", features = ["macros", "rt-multi-thread"] } -thiserror = "1.0.64" +tokio = { version = "1.41.0", features = ["macros", "rt-multi-thread"] } +thiserror = "1.0.65" sqlx = { version = "0.8", features = [ "runtime-tokio", "postgres", "json", "chrono", ] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.131" -anyhow = "1.0.90" +serde = { version = "1.0.213", features = ["derive"] } +serde_json = "1.0.132" +anyhow = "1.0.91" async-trait = "0.1.83" -bytes = "1.7.2" +bytes = "1.8.0" lazy_static = "1.5.0" - - -[dependencies] -tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] } -rtss_log = { path = "crates/rtss_log" } -rtss_api = { path = "crates/rtss_api" } -rtss_db = { path = "crates/rtss_db" } -serde = { workspace = true } -config = "0.14.0" +config = "0.14.1" clap = { version = "4.5.20", features = ["derive"] } enum_dispatch = "0.3" -anyhow = { workspace = true } diff --git a/crates/rtss_api/src/apis/simulation.rs b/crates/rtss_api/src/apis/simulation.rs deleted file mode 100644 index 7dfd557..0000000 --- a/crates/rtss_api/src/apis/simulation.rs +++ /dev/null @@ -1,105 +0,0 @@ -use async_graphql::{Context, InputObject, Object}; -use rtss_sim_manage::{AvailablePlugins, SimulationBuilder}; - -use super::{MutexSimulationManager, SimulationOperation}; - -#[derive(Default)] -pub struct SimulationQuery; - -#[Object] -impl SimulationQuery { - async fn simulations<'ctx>(&self, ctx: &Context<'ctx>) -> usize { - let sim = ctx.data::().unwrap(); - sim.lock().await.count() - } -} - -#[derive(Default)] -pub struct SimulationMutation; - -#[Object] -impl SimulationMutation { - async fn start_simulation<'ctx>( - &self, - ctx: &Context<'ctx>, - req: StartSimulationRequest, - ) -> async_graphql::Result { - // let claims = ctx.data::>().unwrap(); - // match claims { - // Some(claims) => { - // info!("User {claims:?} started simulation"); - // } - // _ => return Err("Unauthorized".into()), - // } - let sim = ctx.data::().unwrap(); - let id = sim.lock().await.start_simulation( - SimulationBuilder::default() - .id(req.user_id) - .plugins(vec![AvailablePlugins::TrackSideEquipmentPlugin]), - )?; - Ok(id) - } - - async fn exit_simulation<'ctx>( - &self, - ctx: &Context<'ctx>, - id: String, - ) -> async_graphql::Result { - let sim = ctx.data::().unwrap(); - sim.lock().await.exit_simulation(id)?; - Ok(true) - } - - async fn pause_simulation<'ctx>( - &self, - ctx: &Context<'ctx>, - id: String, - ) -> async_graphql::Result { - let sim = ctx.data::().unwrap(); - sim.lock().await.pause_simulation(id)?; - Ok(true) - } - - async fn resume_simulation<'ctx>( - &self, - ctx: &Context<'ctx>, - id: String, - ) -> async_graphql::Result { - let sim = ctx.data::().unwrap(); - sim.lock().await.resume_simulation(id)?; - Ok(true) - } - - async fn update_simulation_speed<'ctx>( - &self, - ctx: &Context<'ctx>, - id: String, - speed: f32, - ) -> async_graphql::Result { - let sim = ctx.data::().unwrap(); - sim.lock().await.update_simulation_speed(id, speed)?; - Ok(true) - } - - async fn trigger_simulation_operation<'ctx>( - &self, - ctx: &Context<'ctx>, - id: String, - entity_uid: String, - operation: SimulationOperation, - ) -> async_graphql::Result { - let sim = ctx.data::().unwrap(); - sim.lock().await.trigger_entity_operation( - id, - entity_uid, - operation.to_operation_event(), - )?; - Ok(true) - } -} - -#[derive(InputObject)] -struct StartSimulationRequest { - user_id: String, - sim_def_id: String, -} diff --git a/crates/rtss_api/src/apis/simulation_definition.rs b/crates/rtss_api/src/apis/simulation_definition.rs deleted file mode 100644 index 30fdc16..0000000 --- a/crates/rtss_api/src/apis/simulation_definition.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::ops::Deref; - -use async_graphql::Enum; -use bevy_ecs::event::Event; -use rtss_sim_manage::SimulationManager; -use tokio::sync::Mutex; - -pub struct MutexSimulationManager(Mutex); -impl Default for MutexSimulationManager { - fn default() -> Self { - Self(Mutex::new(SimulationManager::default())) - } -} -impl Deref for MutexSimulationManager { - type Target = Mutex; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[derive(Enum, Copy, Clone, Eq, PartialEq, Debug)] -pub enum SimulationOperation { - TurnoutControlDC, - TurnoutControlFC, -} - -impl SimulationOperation { - pub fn to_operation_event(self) -> impl Event + Copy { - match self { - SimulationOperation::TurnoutControlDC => rtss_trackside::TurnoutControlEvent::DC, - SimulationOperation::TurnoutControlFC => rtss_trackside::TurnoutControlEvent::FC, - } - } -} diff --git a/crates/rtss_db/Cargo.toml b/crates/rtss_db/Cargo.toml index 8fc0590..27ebb7f 100644 --- a/crates/rtss_db/Cargo.toml +++ b/crates/rtss_db/Cargo.toml @@ -17,6 +17,7 @@ sqlx = { workspace = true, features = [ "uuid", ] } thiserror = { workspace = true } +lazy_static = { workspace = true } rtss_dto = { path = "../rtss_dto" } rtss_log = { path = "../rtss_log" } diff --git a/crates/rtss_db/src/db_access/draft_data.rs b/crates/rtss_db/src/db_access/draft_data.rs index 6d4a508..dfe4b70 100644 --- a/crates/rtss_db/src/db_access/draft_data.rs +++ b/crates/rtss_db/src/db_access/draft_data.rs @@ -458,7 +458,7 @@ mod tests { id: i + 1, name: format!("user{}", i + 1), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::User]).unwrap(), email: None, mobile: None, created_at: Local::now(), diff --git a/crates/rtss_db/src/db_access/feature.rs b/crates/rtss_db/src/db_access/feature.rs index f5a1e2e..534c127 100644 --- a/crates/rtss_db/src/db_access/feature.rs +++ b/crates/rtss_db/src/db_access/feature.rs @@ -236,7 +236,7 @@ mod tests { id: i + 1, name: format!("user{}", i + 1), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::User]).unwrap(), email: None, mobile: None, created_at: Local::now(), @@ -260,7 +260,7 @@ mod tests { println!("create feature: {:?}", feature); assert_eq!(feature.creator_id, creator_id); assert_eq!(feature.updater_id, creator_id); - assert_eq!(feature.is_published, true); + assert!(feature.is_published); assert_eq!(feature.config, create_config); let feature_id = feature.id; // 获取功能特性测试 @@ -269,7 +269,7 @@ mod tests { assert_eq!(feature.id, feature_id); assert_eq!(feature.creator_id, creator_id); assert_eq!(feature.updater_id, creator_id); - assert_eq!(feature.is_published, true); + assert!(feature.is_published); assert_eq!(feature.config, create_config); // 更新测试 let updater_id = 2; @@ -279,7 +279,7 @@ mod tests { name: "test update".to_string(), description: "test update".to_string(), config: config.clone(), - updater_id: updater_id, + updater_id, }; let feature = accessor.update_feature(&feature).await?; println!("update feature: {:?}", feature); @@ -289,7 +289,7 @@ mod tests { // 上下架测试 let feature = accessor.set_feature_published(feature_id, false).await?; println!("set feature published: {:?}", feature); - assert_eq!(feature.is_published, false); + assert!(!feature.is_published); // 分页查询测试 // 创建10个功能特性,5个发布的,5个未发布的 for i in 0..10 { diff --git a/crates/rtss_db/src/db_access/mod.rs b/crates/rtss_db/src/db_access/mod.rs index adaa4d4..7566fd0 100644 --- a/crates/rtss_db/src/db_access/mod.rs +++ b/crates/rtss_db/src/db_access/mod.rs @@ -1,14 +1,42 @@ mod draft_data; +use std::sync::Mutex; + pub use draft_data::*; mod release_data; pub use release_data::*; mod user; +use rtss_log::tracing::error; pub use user::*; mod feature; pub use feature::*; +use lazy_static::lazy_static; use crate::{model::MqttClientIdSeq, DbAccessError}; +lazy_static! { + static ref RDA: Mutex> = Mutex::new(None); +} + +/// 初始化全局默认数据库访问器 +pub async fn init_default_db_accessor(url: &str) { + if RDA.lock().unwrap().is_some() { + error!("数据库访问器已初始化,请勿重复初始化"); + return; + } + let accessor = get_db_accessor(url).await; + let mut rda = RDA.lock().unwrap(); + *rda = Some(accessor); +} + +/// 获取默认数据库访问器 +pub fn get_default_db_accessor() -> RtssDbAccessor { + let rda = RDA.lock().unwrap(); + if rda.is_none() { + panic!("数据库访问器未初始化"); + } + rda.as_ref().unwrap().clone() +} + #[derive(Clone)] pub struct RtssDbAccessor { pool: sqlx::PgPool, diff --git a/crates/rtss_db/src/db_access/release_data.rs b/crates/rtss_db/src/db_access/release_data.rs index 6470f6a..7fc727f 100644 --- a/crates/rtss_db/src/db_access/release_data.rs +++ b/crates/rtss_db/src/db_access/release_data.rs @@ -704,7 +704,7 @@ mod tests { id: i + 1, name: format!("user{}", i + 1), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::User]).unwrap(), email: None, mobile: None, created_at: Local::now(), @@ -745,7 +745,7 @@ mod tests { // 发布新版本 let (release_data, version1) = accessor - .release_new_from_draft(draft.id, name, &description, None) + .release_new_from_draft(draft.id, name, description, None) .await?; assert_eq!(release_data.name, name); // 检查使用版本是刚刚发布的版本 @@ -759,7 +759,7 @@ mod tests { // 检查版本描述 assert_eq!(version1.description, description); // 检查上架状态 - assert_eq!(release_data.is_published, true); + assert!(release_data.is_published); // 检查草稿数据的默认发布数据id let draft = accessor.query_draft_data_by_id(draft.id).await?; assert_eq!(draft.default_release_data_id, Some(release_data.id)); @@ -769,7 +769,7 @@ mod tests { let exist = accessor .is_release_data_name_exist(rtss_dto::common::DataType::Iscs, name) .await?; - assert_eq!(exist, true); + assert!(exist); // 修改草稿数据 let data = "test2".as_bytes(); @@ -798,7 +798,7 @@ mod tests { let release_data = accessor .set_release_data_published(release_data.id, false) .await?; - assert_eq!(release_data.is_published, false); + assert!(!release_data.is_published); assert!(release_data.updated_at > release_data.created_at); println!("更新发布数据上架状态测试成功"); diff --git a/crates/rtss_db/src/db_access/user.rs b/crates/rtss_db/src/db_access/user.rs index f6e688f..ef473b3 100644 --- a/crates/rtss_db/src/db_access/user.rs +++ b/crates/rtss_db/src/db_access/user.rs @@ -300,7 +300,7 @@ mod tests { id: 1, name: "test1".to_string(), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::User]).unwrap(), email: None, mobile: None, created_at: Local::now(), @@ -310,7 +310,7 @@ mod tests { id: 2, name: "test2".to_string(), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::Admin]).unwrap(), + roles: serde_json::to_value(vec![Role::Admin]).unwrap(), email: None, mobile: None, created_at: Local::now(), @@ -342,7 +342,7 @@ mod tests { id: 1, name: "test1".to_string(), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::User]).unwrap(), email: Some("walker@163.com".to_string()), mobile: None, created_at: Local::now() - Duration::from_secs(60), @@ -352,7 +352,7 @@ mod tests { id: 2, name: "test2".to_string(), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::Admin, Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::Admin, Role::User]).unwrap(), email: None, mobile: Some("123456789".to_string()), created_at: Local::now() - Duration::from_secs(60), @@ -362,7 +362,7 @@ mod tests { id: 3, name: "test3".to_string(), password: "password".to_string(), - roles: serde_json::to_value(&vec![Role::User]).unwrap(), + roles: serde_json::to_value(vec![Role::User]).unwrap(), email: None, mobile: None, created_at: Local::now(), diff --git a/crates/rtss_dto/Cargo.toml b/crates/rtss_dto/Cargo.toml index 63f5c80..0f95f08 100644 --- a/crates/rtss_dto/Cargo.toml +++ b/crates/rtss_dto/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] prost = "0.13" +prost-types = "0.13" async-graphql = { version = "7.0.7", features = ["chrono"] } sqlx = { workspace = true } serde = { workspace = true } diff --git a/crates/rtss_dto/build.rs b/crates/rtss_dto/build.rs index c7b8224..32d375e 100644 --- a/crates/rtss_dto/build.rs +++ b/crates/rtss_dto/build.rs @@ -42,6 +42,7 @@ fn main() { "../../rtss-proto-msg/src/em_data.proto", "../../rtss-proto-msg/src/common.proto", "../../rtss-proto-msg/src/iscs_graphic_data.proto", + "../../rtss-proto-msg/src/simulation.proto", ], &["../../rtss-proto-msg/src/"], ) diff --git a/crates/rtss_dto/src/lib.rs b/crates/rtss_dto/src/lib.rs index 4f41e23..551b05f 100644 --- a/crates/rtss_dto/src/lib.rs +++ b/crates/rtss_dto/src/lib.rs @@ -1,3 +1,27 @@ mod pb; pub use pb::*; + +#[cfg(test)] +mod tests { + + use crate::simulation::{self, operation, SetSpeedParam}; + + #[test] + fn test_prost_any() { + let op = simulation::Operation { + otype: simulation::OperationType::SetSpeed as i32, + param: Some(operation::Param::SetSpeedParam(SetSpeedParam { + speed: 1.0, + })), + }; + println!("{:?}", op); + if let Some(param) = op.param { + match param { + operation::Param::SetSpeedParam(ssp) => { + assert_eq!(ssp.speed, 1.0); + } + } + } + } +} diff --git a/crates/rtss_dto/src/pb/iscs_graphic_data.rs b/crates/rtss_dto/src/pb/iscs_graphic_data.rs index 7d5bd74..6b9e813 100644 --- a/crates/rtss_dto/src/pb/iscs_graphic_data.rs +++ b/crates/rtss_dto/src/pb/iscs_graphic_data.rs @@ -3,11 +3,15 @@ #[derive(Clone, PartialEq, ::prost::Message)] pub struct IscsGraphicStorage { #[prost(message, repeated, tag = "1")] - pub cctv_of_station_control_storages: ::prost::alloc::vec::Vec< - CctvOfStationControlStorage, + pub cctv_of_equipment_layout_storages: ::prost::alloc::vec::Vec< + CctvOfEquipmentLayoutStorage, >, #[prost(message, repeated, tag = "2")] - pub fas_platform_alarm_storages: ::prost::alloc::vec::Vec, + pub fas_of_platform_alarm_storages: ::prost::alloc::vec::Vec< + FasOfPlatformAlarmStorage, + >, + #[prost(message, repeated, tag = "3")] + pub bas_of_escalator_storages: ::prost::alloc::vec::Vec, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -24,6 +28,22 @@ pub struct UniqueIdOfStationLayout { } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] +pub struct CommonGraphicStorage { + #[prost(message, repeated, tag = "1")] + pub arrows: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "2")] + pub texts: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "3")] + pub rects: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "4")] + pub lines: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "5")] + pub circles: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "6")] + pub buttons: ::prost::alloc::vec::Vec