{"id":23956845,"url":"https://github.com/mk590901/switch-tc-rust","last_synced_at":"2026-06-17T19:02:31.624Z","repository":{"id":270447348,"uuid":"910411025","full_name":"mk590901/Switch-TC-Rust","owner":"mk590901","description":"The repository contains app demonstrates the use of threaded code for state machine on Rust","archived":false,"fork":false,"pushed_at":"2025-01-01T05:53:28.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T10:48:19.020Z","etag":null,"topics":["hsm","rust","state-machine","threaded-code"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mk590901.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-31T07:43:08.000Z","updated_at":"2025-01-01T05:53:30.000Z","dependencies_parsed_at":"2025-02-24T10:46:44.923Z","dependency_job_id":"9e374eb2-62cb-4750-9f29-81ed64d8d218","html_url":"https://github.com/mk590901/Switch-TC-Rust","commit_stats":null,"previous_names":["mk590901/switch-tc-rust"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mk590901/Switch-TC-Rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2FSwitch-TC-Rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2FSwitch-TC-Rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2FSwitch-TC-Rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2FSwitch-TC-Rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mk590901","download_url":"https://codeload.github.com/mk590901/Switch-TC-Rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk590901%2FSwitch-TC-Rust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34461618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hsm","rust","state-machine","threaded-code"],"created_at":"2025-01-06T16:19:28.384Z","updated_at":"2026-06-17T19:02:31.605Z","avatar_url":"https://github.com/mk590901.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Switch-TC-Rust\n\nThe application tests threaded code generated by the editor of hierarchical state machines. The original scheme can be seen on the __switch_reset.svg__ attached to the project. It's model of a switch affected by two events: __TURN__ and __RESET__. The first switches two states __ON__ and __OFF__, the second resets the state machine to the __OFF__ state regardless of what state it was in before.\n\n## Precondition\n\nThe editor's __Planner__ module was supplemented with __Rust__ code generator, which automatically create the __switch_reset_helper.rs__ file with the transfer functions. This file also contain function __create_helper__ builds QHsmHelper structure for processing these functions. A core has also been added to the application, which services the launch of threaded code and the impact of events on it. This is a set of several very simple structures placed to the __core.rs__ file: __EventWrapper__, which describes and keep an event, __QHsmHelper__ with the __IQHsmStateMachineHelper__ interface, which contains a container of threaded codes and ensures its execution under the influence of events, __ThreadedCodeExecutor__ - a structure ensures the launch of threaded code for a specific state and event.\n\n## Code modification\n\nThe generated __switch_reset_helper.rs__ file is a skeleton for the logical part of the application, namely the list and bodies of empty transfer functions that can and should be filled with some content. For example, with trace elements in the simplest case. Some functions may not be used and should be deleted or commented out:\n\n```rust\n\n//\tFile switch_reset_helper.rs automatically generated at 2024-12-31 14:10:12\n\nuse std::sync::Arc;\nuse crate::core::{QHsmHelper, ThreadedCodeExecutor};\nuse std::any::Any;\n\n// pub fn switch_entry(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n// }\n\n// pub fn switch_init(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n// }\n\npub fn off_entry(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n    println!(\"OFF\");\n}\n\npub fn off_reset(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n    println!(\"@RESET\");\n}\n\n// pub fn off_exit(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n// }\n\npub fn off_turn(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n    println!(\"OFF: TURN\");\n}\n\npub fn on_entry(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n    println!(\"ON\");\n}\n\n// pub fn on_exit(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n// }\n\npub fn on_turn(_data: Option\u003c\u0026Box\u003cdyn Any\u003e\u003e) {\n    println!(\"ON:  TURN\");\n}\n\npub fn create_helper(helper: \u0026Arc\u003cQHsmHelper\u003e) {\n    let switch_init_functions: Vec\u003cBox\u003cdyn Fn(Option\u003c\u0026Box\u003cdyn Any\u003e\u003e)\u003e\u003e = vec![\n        // Box::new(switch_entry),\n        // Box::new(switch_init),\n        Box::new(off_entry)\n        ];\n    helper.insert(\"switch\".to_string(), \"init\".to_string(), Arc::new(ThreadedCodeExecutor::new(switch_init_functions, \"off\".to_string())));\n\n    let off_reset_functions: Vec\u003cBox\u003cdyn Fn(Option\u003c\u0026Box\u003cdyn Any\u003e\u003e)\u003e\u003e = vec![\n        Box::new(off_reset),\n        // Box::new(off_exit),\n        // Box::new(switch_init),\n        Box::new(off_entry)\n        ];\n    helper.insert(\"off\".to_string(), \"RESET\".to_string(), Arc::new(ThreadedCodeExecutor::new(off_reset_functions, \"off\".to_string())));\n\n    let off_turn_functions: Vec\u003cBox\u003cdyn Fn(Option\u003c\u0026Box\u003cdyn Any\u003e\u003e)\u003e\u003e = vec![\n        Box::new(off_turn), \n        Box::new(on_entry)\n        ];\n    helper.insert(\"off\".to_string(), \"TURN\".to_string(), Arc::new(ThreadedCodeExecutor::new(off_turn_functions, \"on\".to_string())));\n\n    let on_reset_functions: Vec\u003cBox\u003cdyn Fn(Option\u003c\u0026Box\u003cdyn Any\u003e\u003e)\u003e\u003e = vec![\n        Box::new(off_reset),\n        // Box::new(on_exit),\n        // Box::new(off_exit),\n        // Box::new(switch_init),\n        Box::new(off_entry)\n        ];\n    helper.insert(\"on\".to_string(), \"RESET\".to_string(), Arc::new(ThreadedCodeExecutor::new(on_reset_functions, \"off\".to_string())));\n\n    let on_turn_functions: Vec\u003cBox\u003cdyn Fn(Option\u003c\u0026Box\u003cdyn Any\u003e\u003e)\u003e\u003e = vec![\n        Box::new(on_turn),\n        // Box::new(on_exit),\n        // Box::new(off_exit),\n        // Box::new(switch_init),\n        Box::new(off_entry)\n        ];\n    helper.insert(\"on\".to_string(), \"TURN\".to_string(), Arc::new(ThreadedCodeExecutor::new(on_turn_functions, \"off\".to_string())));\n}\n\n```\n\n## Additional modules\n\nTo test the threaded code for hierarchical state machine, need to manually create two small modules that ensure the launch of the application:\n\n\u003etest.rs\n\u003e\n```rust\n\nuse std::sync::Arc;\nuse crate::core::{QHsmHelper, Runner, post};\nuse crate::switch_reset_helper::create_helper;\n\npub fn test_switch() {\n    let helper = Arc::new(QHsmHelper::new(\"switch\".to_string()));\n    let runner = Runner::new(helper.clone());\n    create_helper(\u0026helper);\n\n    post(\u0026runner, \"init\".to_string(), None);\n    post(\u0026runner, \"TURN\".to_string(), None);\n    post(\u0026runner, \"RESET\".to_string(), None);\n    post(\u0026runner, \"TURN\".to_string(), None);\n    post(\u0026runner, \"TURN\".to_string(), None);\n    post(\u0026runner, \"RESET\".to_string(), None);\n}\n```\n\n\u003emain.rs\n\u003e\n```rust\n\nmod core;\nmod test;\nmod switch_reset_helper;\n\nuse test::test_switch;\n\nfn main() {\n    test_switch();\n}\n```\n\n## Description of the application\n\nThe application is created as a __ubuntu console application__ and can be launched in terminal mode. There are two ways to launch the application:\n\n\u003e In debug mode\n\n```\n\nmicrcx@micrcx-desktop:~/rust/switch_tc$ cargo run\nwarning: unused manifest key: core\n    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s\n     Running `target/debug/switch_tc`\nOFF\nOFF: TURN\nON\n@RESET\nOFF\nOFF: TURN\nON\nON:  TURN\nOFF\n@RESET\nOFF\nmicrcx@micrcx-desktop:~/rust/switch_tc$\n\n```\n\u003e In release mode\n\n```\n\nmicrcx@micrcx-desktop:~/rust/switch_tc$\n\nmicrcx@micrcx-desktop:~/rust/switch_tc$ cargo build --release\nwarning: unused manifest key: core\n    Finished `release` profile [optimized] target(s) in 0.02s\nmicrcx@micrcx-desktop:~/rust/switch_tc$\n\nmicrcx@micrcx-desktop:~/rust/switch_tc$ cd target/release\nmicrcx@micrcx-desktop:~/rust/switch_tc/target/release$ ./switch_tc\nOFF\nOFF: TURN\nON\n@RESET\nOFF\nOFF: TURN\nON\nON:  TURN\nOFF\n@RESET\nOFF\nmicrcx@micrcx-desktop:~/rust/switch_tc/target/release$\n\n```\n## Movie\n\n[rust.webm](https://github.com/user-attachments/assets/7b3b659e-487a-4e36-9ad9-b581873c595a)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmk590901%2Fswitch-tc-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmk590901%2Fswitch-tc-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmk590901%2Fswitch-tc-rust/lists"}