From 79a2dcd215b30680ca9325a8ffb1e8223273b505 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:41:42 -0400 Subject: [PATCH 1/9] Bump clap from 4.5.17 to 4.5.18 (#52) Bumps [clap](https://github.com/clap-rs/clap) from 4.5.17 to 4.5.18. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.17...clap_complete-v4.5.18) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2265bf..5f50f4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" dependencies = [ "clap_builder", "clap_derive", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" dependencies = [ "anstream", "anstyle", @@ -164,9 +164,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index cca0273..88b6cf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ paho-mqtt = "0.12.5" protobuf-codegen = "3.5.1" protobuf = "3.5.1" bitstream-io = "2.5.3" -clap = { version = "4.5.17", features = ["derive", "env"] } +clap = { version = "4.5.18", features = ["derive", "env"] } [build-dependencies] From 2d6d467effb66c8a549e15e89645cd6bad02bef2 Mon Sep 17 00:00:00 2001 From: tszwingli <43227796+tszwinglitw@users.noreply.github.com> Date: Sun, 29 Sep 2024 18:32:10 -0400 Subject: [PATCH 2/9] allow read_can to reconnect on Siren connection failure (#51) * allow read_can to reconnect on failure * syntax fix according to clippy * expanded reconnection to read_siren * update read_siren reconnect * read_siren add re-subscription * cleanup --- src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index ff8d2a2..5cc647c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,10 +49,23 @@ struct CalypsoArgs { fn read_can(pub_path: &str, can_interface: &str) -> JoinHandle { //open can socket channel at name can_interface let mut client = MqttClient::new(pub_path, "calypso-decoder"); - client.connect().expect("Could not connect to Siren!"); + if client.connect().is_err() { + println!("Unable to connect to Siren, going into reconnection mode."); + if client.reconnect().is_ok() { + println!("Reconnected to Siren!"); + } + } + let socket = CanSocket::open(can_interface).expect("Failed to open CAN socket!"); thread::spawn(move || loop { + if !client.is_connected() { + println!("[read_can] Unable to connect to Siren, going into reconnection mode."); + if client.reconnect().is_ok() { + println!("[read_can] Reconnected to Siren!"); + } + } + let msg = match socket.read_frame() { Ok(CanFrame::Data(msg)) => msg, Ok(CanFrame::Remote(_)) => { @@ -82,14 +95,18 @@ fn read_can(pub_path: &str, can_interface: &str) -> JoinHandle { payload.unit = data.unit.to_string(); payload.value = data.value.iter().map(|x| x.to_string()).collect(); - client + if client .publish( data.topic.to_string(), protobuf::Message::write_to_bytes(&payload).unwrap_or_else(|e| { format!("failed to serialize {}", e).as_bytes().to_vec() }), ) - .expect("Could not publish!"); + .is_err() + { + println!("[read_can] Failed to publish to Siren."); + } + // TODO: investigate disabling this thread::sleep(Duration::from_micros(100)); } @@ -101,7 +118,15 @@ fn read_can(pub_path: &str, can_interface: &str) -> JoinHandle { */ fn read_siren(pub_path: &str, send_map: Arc>>) -> JoinHandle<()> { let mut client = MqttClient::new(pub_path, "calypso-encoder"); - client.connect().expect("Could not connect to Siren!"); + + let _ = client.connect(); + while !client.is_connected() { + println!("[read_siren] Unable to connect to Siren, going into reconnection mode."); + if client.reconnect().is_ok() { + println!("[read_siren] Reconnected to Siren!"); + } + } + let reciever = client.start_consumer().expect("Could not begin consuming"); client .subscribe(ENCODER_MAP_SUB) @@ -141,18 +166,17 @@ fn read_siren(pub_path: &str, send_map: Arc>>) - .expect("Could not modify send messages!") .insert(ret.id, ret); } else { - // the code doesnt work without this else statement - // idk why but never remove this else statement - let is_conn = client.is_connected(); - println!("Client is {}", is_conn); - if !is_conn { - println!("Trying to reconnect"); - match client.reconnect() { - Ok(_) => println!("Reconnected!"), - Err(_) => println!("Could not reconnect!"), + while !client.is_connected() { + println!( + "[read_siren] Unable to connect to Siren, going into reconnection mode." + ); + if client.reconnect().is_ok() { + println!("[read_siren] Reconnected to Siren!"); } - continue; } + client + .subscribe(ENCODER_MAP_SUB) + .expect("Could not subscribe!"); } } }) From 80b17cd0bc979b062c10ee8a8c528e5e75057fc0 Mon Sep 17 00:00:00 2001 From: Harrison Eckert <65581761+harrison-e@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:16:22 -0400 Subject: [PATCH 3/9] Handle CANErrorFrame, move decode logic up to read_frame match (#54) * Added my format script to gitignore * Experimental handling of CAN Error Frame * Changes * Handle Remote frame * Set CAN Socket to accept errors * SocketOptions now included --------- Co-authored-by: Jack Rubacha --- .gitignore | 3 +++ src/main.rs | 76 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index a6a75d4..a9d34ae 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ decode_data.rs encode_data.rs encode_master_mapping.rs format_data.rs + +# my dumb script +./format diff --git a/src/main.rs b/src/main.rs index 5cc647c..6a0778a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,13 +6,13 @@ use std::{ }; use calypso::{ - command_data, data::EncodeData, decodable_message::DecodableMessage, + command_data, data::DecodeData, data::EncodeData, decodable_message::DecodableMessage, encodable_message::EncodableMessage, encode_master_mapping::ENCODABLE_KEY_LIST, mqtt::MqttClient, serverdata, }; use clap::Parser; use protobuf::Message; -use socketcan::{CanFrame, CanSocket, EmbeddedFrame, Id, Socket}; +use socketcan::{CanError, CanFrame, CanSocket, EmbeddedFrame, Frame, Id, Socket, SocketOptions}; const ENCODER_MAP_SUB: &str = "Calypso/Bidir/Command/#"; @@ -47,7 +47,7 @@ struct CalypsoArgs { * Reads the can socket and publishes the data to the given client. */ fn read_can(pub_path: &str, can_interface: &str) -> JoinHandle { - //open can socket channel at name can_interface + // Open CAN socket channel at name can_interface let mut client = MqttClient::new(pub_path, "calypso-decoder"); if client.connect().is_err() { println!("Unable to connect to Siren, going into reconnection mode."); @@ -57,6 +57,7 @@ fn read_can(pub_path: &str, can_interface: &str) -> JoinHandle { } let socket = CanSocket::open(can_interface).expect("Failed to open CAN socket!"); + socket.set_error_filter_accept_all().expect("Failed to set error mask on CAN socket!"); thread::spawn(move || loop { if !client.is_connected() { @@ -65,31 +66,62 @@ fn read_can(pub_path: &str, can_interface: &str) -> JoinHandle { println!("[read_can] Reconnected to Siren!"); } } - - let msg = match socket.read_frame() { - Ok(CanFrame::Data(msg)) => msg, - Ok(CanFrame::Remote(_)) => { - println!("Ignoring remote frame"); - continue; + // Read from MQTT socket + let decoded_data = match socket.read_frame() { + // CanDataFrame + Ok(CanFrame::Data(data_frame)) => { + let data = data_frame.data(); + let message = DecodableMessage::new( + match data_frame.id() { + socketcan::Id::Standard(std) => std.as_raw().into(), + socketcan::Id::Extended(ext) => ext.as_raw(), + }, + data.to_vec(), + ); + message.decode() } - Ok(CanFrame::Error(_)) => { - println!("Ignoring error frame"); - continue; + // CanRemoteFrame + Ok(CanFrame::Remote(remote_frame)) => { + // Send frame ID for Remote + vec![DecodeData::new( + vec![remote_frame.raw_id() as f32], + "Calypso/Events/RemoteFrame", + "id", + )] } + // CanErrorFrame + Ok(CanFrame::Error(error_frame)) => { + // Publish enum index of error onto CAN + // TODO: Look into string representation with Display + // TODO: Ask `const` impl for Display or enum? + // Impl from ErrorFrame -> f32 + let error_index: f32 = match CanError::from(error_frame) { + CanError::TransmitTimeout => 0.0, + CanError::LostArbitration(_) => 1.0, + CanError::ControllerProblem(_) => 2.0, + CanError::ProtocolViolation { .. } => 3.0, + CanError::TransceiverError => 4.0, + CanError::NoAck => 5.0, + CanError::BusOff => 6.0, + CanError::BusError => 7.0, + CanError::Restarted => 8.0, + CanError::DecodingFailure(_) => 9.0, + CanError::Unknown(_) => 10.0, + }; + vec![DecodeData::new( + vec![error_index], + "Calypso/Events/ErrorFrame", + "CanError enum", + )] + } + // Socket failure Err(err) => { - println!("Failed to read CAN frame: {}", err); + println!("CAN Socket failure: {}", err); continue; } }; - let data = msg.data(); - let message = DecodableMessage::new( - match msg.id() { - socketcan::Id::Standard(std) => std.as_raw().into(), - socketcan::Id::Extended(ext) => ext.as_raw(), - }, - data.to_vec(), - ); - let decoded_data = message.decode(); + + // Convert decoded CAN to Protobuf and publish over MQTT for data in decoded_data.iter() { let mut payload = serverdata::ServerData::new(); payload.unit = data.unit.to_string(); From 5304a7293fa9766c3bec7a9afd5c6143dcc19995 Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Thu, 3 Oct 2024 19:57:43 -0400 Subject: [PATCH 4/9] add template (#58) --- .github/ISSUE_TEMPLATE/bug-form.yml | 34 ++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/epic.yml | 64 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature-request.yml | 26 +++++++++ .github/ISSUE_TEMPLATE/other.yml | 18 ++++++ .github/ISSUE_TEMPLATE/spike.yml | 38 +++++++++++++ .github/ISSUE_TEMPLATE/task.yml | 25 +++++++++ .github/pull_request_template.md | 35 ++++++++++++ 8 files changed, 241 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-form.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/epic.yml create mode 100644 .github/ISSUE_TEMPLATE/feature-request.yml create mode 100644 .github/ISSUE_TEMPLATE/other.yml create mode 100644 .github/ISSUE_TEMPLATE/spike.yml create mode 100644 .github/ISSUE_TEMPLATE/task.yml create mode 100644 .github/pull_request_template.md diff --git a/.github/ISSUE_TEMPLATE/bug-form.yml b/.github/ISSUE_TEMPLATE/bug-form.yml new file mode 100644 index 0000000..f3df30d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-form.yml @@ -0,0 +1,34 @@ +name: Bug +description: For any issue related to a bug +title: '[Area] - Short Description' +labels: [bug] +body: + - type: textarea + id: observed-behavior + attributes: + label: Observed Behavior + description: What happened? + validations: + required: true + - type: textarea + id: expected-behavior + attributes: + label: Expected Behavior + description: What should have happened? + validations: + required: true + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to Reproduce + description: How could someone reproduce this bug? + value: "1. \n2. \n3. " + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots (as needed) + description: Add screenshots of the bug if applicable + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..0086358 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: true diff --git a/.github/ISSUE_TEMPLATE/epic.yml b/.github/ISSUE_TEMPLATE/epic.yml new file mode 100644 index 0000000..1827d9e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/epic.yml @@ -0,0 +1,64 @@ +name: Epic +description: A collection of many tasks +title: '[Area] - Short Description' +labels: [epic] +body: + - type: textarea + id: overview + attributes: + label: Overview + description: Provide a brief summary of this epic + validations: + required: true + - type: textarea + id: stakeholders + attributes: + label: Stakeholders + description: Who to contact for this epic? + value: | + Product Stakeholder: + Software Stakeholder: + Reference Users: + - type: textarea + id: metrics + attributes: + label: Success Metrics + description: What are the metrics we will use to determine if this is successful? + validations: + required: true + - type: textarea + id: rollout + attributes: + label: Rollout Plan + description: How will this be released? All at once? In parts? + validations: + required: true + - type: textarea + id: scope + attributes: + label: Out of Scope + description: What is not included in this epic? + validations: + required: true + - type: textarea + id: background-context + attributes: + label: Background / Context + description: What is the context for this epic? What already exists? + validations: + required: true + - type: textarea + id: acceptance + attributes: + label: Acceptance Criteria + description: How are we evaluating the success of this epic? + validations: + required: true + - type: textarea + id: tickets + attributes: + label: Tickets + description: What tickets will be a part of this epic? + value: " - [ ] #\n - [ ] #" + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..4b491b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,26 @@ +name: Feature Request +description: Suggest a new feature for the project +title: '[Area] - Short Description' +labels: [new feature] +body: + - type: textarea + id: current-features + attributes: + label: Current Features + description: What exists currently? + validations: + required: true + - type: textarea + id: desired-features + attributes: + label: Desired Additional Features + description: What features do you want to add? + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots (as needed) + description: Add screenshots of the current or desired state if applicable + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/other.yml b/.github/ISSUE_TEMPLATE/other.yml new file mode 100644 index 0000000..7df8945 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other.yml @@ -0,0 +1,18 @@ +name: Other +description: For issues that don't fit the other categories +title: '[Area] - Short Description' +body: + - type: textarea + id: desired-changes + attributes: + label: Desired Changes + description: What changes do you want to make? + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots (as needed) + description: Add screenshots if applicable + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/spike.yml b/.github/ISSUE_TEMPLATE/spike.yml new file mode 100644 index 0000000..f5dc1c4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/spike.yml @@ -0,0 +1,38 @@ +name: Spike +description: For any research or investigation into a feature or our current architecture +title: '[Area] - Short Description' +labels: [spike] +body: + - type: markdown + attributes: + value: For a spike ticket, please make sure to remember to add links to the resources you are pulling information from so others who are reviewing and giving feedback can also take a look at the same information you are looking at. + - type: dropdown + id: spike-type + attributes: + label: Spike Type + description: Is this spike about the product (functional) or the implementation of the product (technical)? + multiple: true + options: + - Functional + - Technical + - type: textarea + id: goal + attributes: + label: Goal + description: What is this spike ticket looking into/trying to solve? Is this about enhancing something we currently do or looking into a new feature? + validations: + required: true + - type: textarea + id: purpose + attributes: + label: Reason for Spike + description: Why is this spike ticket necessary? + validations: + required: true + - type: textarea + id: sidenotes + attributes: + label: Additional notes + description: Add any extra comments related to the spike. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/task.yml b/.github/ISSUE_TEMPLATE/task.yml new file mode 100644 index 0000000..81bd791 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/task.yml @@ -0,0 +1,25 @@ +name: Task +description: Create a task that a developer can complete. +title: '[Area] - Short Description' +body: + - type: textarea + id: description + attributes: + label: Description + description: Provide a brief summary of this issue + validations: + required: true + - type: textarea + id: acceptance-criteria + attributes: + label: Acceptance Criteria + description: What are the conditions that need to be satisified to complete this task? + validations: + required: true + - type: textarea + id: proposed-solution + attributes: + label: Proposed Solution + description: How will this solution be implemented? What will be changed or added? + validations: + required: true diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..0a8fc14 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,35 @@ +## Changes + +_Explanation of changes goes here_ + +## Notes + +_Any other notes go here_ + +## Test Cases + +- Case A +- Edge case +- ... + +## To Do + +_Any remaining things that need to get done_ + +- [ ] item 1 +- [ ] ... + +## Checklist + +It can be helpful to check the `Checks` and `Files changed` tabs. +Please reach out to your Project Lead if anything is unclear. +Please request reviewers and ping on slack only after you've gone through this whole checklist. + +- [ ] No merge conflicts +- [ ] All checks passing +- [ ] Remove any non-applicable sections of this template +- [ ] Assign the PR to yourself +- [ ] Request reviewers & ping on Slack +- [ ] PR is linked to the ticket (fill in the closes line below) + +Closes # (issue #) From 547a8da764e5e77cd18cf62e996b3edae8076f4f Mon Sep 17 00:00:00 2001 From: Harrison Eckert <65581761+harrison-e@users.noreply.github.com> Date: Thu, 3 Oct 2024 20:44:10 -0400 Subject: [PATCH 5/9] Generate decode and encode from JSON over YAML, (#60) * Added my format script to gitignore * Experimental handling of CAN Error Frame * Changes * Now using JSON over YAML * Handle Remote frame * Set CAN Socket to accept errors * SocketOptions now included * Updated submodule ref * Fixed ref? --------- Co-authored-by: Jack Rubacha --- .gitmodules | 2 +- Embedded-Base | 2 +- calypsogen.py | 31 ++++++++++++++++--------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.gitmodules b/.gitmodules index f35c7f6..f18e99b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "Embedded-Base"] path = Embedded-Base - url = https://github.com/Northeastern-Electric-Racing/Embedded-Base + url = ../Embedded-Base diff --git a/Embedded-Base b/Embedded-Base index fdfdca7..1592f6c 160000 --- a/Embedded-Base +++ b/Embedded-Base @@ -1 +1 @@ -Subproject commit fdfdca783209c293807b1e71efc5447d754050eb +Subproject commit 1592f6c722204c5aae6f9e9b43c5442216b34e0a diff --git a/calypsogen.py b/calypsogen.py index 4f883d5..20c326b 100644 --- a/calypsogen.py +++ b/calypsogen.py @@ -1,4 +1,5 @@ import importlib.util +import json import sys # Full path to the directory containing the cangen module @@ -16,7 +17,7 @@ cangen = importlib.util.module_from_spec(spec) spec.loader.exec_module(cangen) -decode_data = open("./src/decode_data.rs", "w") +decode_data = open("./src/decode_data.rs", "w") or field["send"] decode_master_mapping = open("./src/decode_master_mapping.rs", "w") encode_data = open("./src/encode_data.rs", "w") @@ -25,23 +26,23 @@ format_data = open("./src/format_data.rs", "w") -bms_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/bms.yaml", "r")) -mpu_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/mpu.yaml", "r")) -wheel_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/wheel.yaml", "r")) -dti_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/dti.yaml", "r")) -calypso_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/calypso_cmd.yaml", "r")) -charger_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/charger.yaml", "r")) -msb_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/msb.yaml", "r")) +bms_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/bms.json", "r")) +mpu_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/mpu.json", "r")) +wheel_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/wheel.json", "r")) +dti_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/dti.json", "r")) +calypso_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/calypso_cmd.json", "r")) +charger_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/charger.json", "r")) +msb_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/msb.json", "r")) -bms_messages.msgs.extend(mpu_messages.msgs) -bms_messages.msgs.extend(wheel_messages.msgs) -bms_messages.msgs.extend(dti_messages.msgs) -bms_messages.msgs.extend(charger_messages.msgs) -bms_messages.msgs.extend(calypso_messages.msgs) -bms_messages.msgs.extend(msb_messages.msgs) +bms_messages.extend(mpu_messages) +bms_messages.extend(wheel_messages) +bms_messages.extend(dti_messages) +bms_messages.extend(charger_messages) +bms_messages.extend(calypso_messages) +bms_messages.extend(msb_messages) -result = cangen.RustSynth().parse_messages(bms_messages.msgs) +result = cangen.RustSynthFromJSON().parse_messages(bms_messages) decode_data.write(result.decode_data) decode_data.close() From 29b62724cee0383ade4c96b1e4eb209445514c13 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:49:53 -0400 Subject: [PATCH 6/9] Bump clap from 4.5.18 to 4.5.19 (#62) Bumps [clap](https://github.com/clap-rs/clap) from 4.5.18 to 4.5.19. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.18...clap_complete-v4.5.19) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f50f4c..e92da5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.18" +version = "4.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" +checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" dependencies = [ "clap_builder", "clap_derive", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.18" +version = "4.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" +checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" dependencies = [ "anstream", "anstyle", diff --git a/Cargo.toml b/Cargo.toml index 88b6cf6..aa39f6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ paho-mqtt = "0.12.5" protobuf-codegen = "3.5.1" protobuf = "3.5.1" bitstream-io = "2.5.3" -clap = { version = "4.5.18", features = ["derive", "env"] } +clap = { version = "4.5.19", features = ["derive", "env"] } [build-dependencies] From 0a2cf21a0ab314f6627af528f72bc58c34fd5b4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:31:13 -0400 Subject: [PATCH 7/9] Bump clap from 4.5.19 to 4.5.20 (#65) Bumps [clap](https://github.com/clap-rs/clap) from 4.5.19 to 4.5.20. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.19...clap_complete-v4.5.20) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e92da5e..b5b1639 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.19" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.19" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", diff --git a/Cargo.toml b/Cargo.toml index aa39f6a..8e6f8f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ paho-mqtt = "0.12.5" protobuf-codegen = "3.5.1" protobuf = "3.5.1" bitstream-io = "2.5.3" -clap = { version = "4.5.19", features = ["derive", "env"] } +clap = { version = "4.5.20", features = ["derive", "env"] } [build-dependencies] From bcc1a76deeabb0e57650954b56844174ff6c2ce3 Mon Sep 17 00:00:00 2001 From: tszwingli <43227796+tszwinglitw@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:36:44 -0400 Subject: [PATCH 8/9] Add a way to simulate messages (#61) * cangen simulation structure * moved simulate into a separate binary * added sim code genreation * improved new value generation * bug fixes * added struct for param passing, removed format and signed * fixed value initialization for boolean values * added rounding for nicer numbers and boolean cases * updated submodule pointer * ok cargo clippy * fixed NaN values * limit retry attempts; refactoring and cleanup * update embedded-base pointer * bump submodule --------- Co-authored-by: Jack Rubacha --- .gitignore | 2 + Cargo.lock | 78 ++++++++++++++++++++ Cargo.toml | 2 + Embedded-Base | 2 +- README.md | 6 ++ calypsogen.py | 5 ++ src/bin/simulate.rs | 69 ++++++++++++++++++ src/lib.rs | 2 + src/main.rs | 2 +- src/simulatable_message.rs | 142 +++++++++++++++++++++++++++++++++++++ 10 files changed, 308 insertions(+), 2 deletions(-) create mode 100644 src/bin/simulate.rs create mode 100644 src/simulatable_message.rs diff --git a/.gitignore b/.gitignore index a9d34ae..b03ed33 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,8 @@ decode_data.rs encode_data.rs encode_master_mapping.rs format_data.rs +simulate_data.rs # my dumb script ./format +/privatetest/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index b5b1639..efaf138 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,6 +122,7 @@ dependencies = [ "paho-mqtt", "protobuf", "protobuf-codegen", + "rand", "socketcan", ] @@ -361,6 +362,17 @@ dependencies = [ "slab", ] +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -552,6 +564,15 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.70" @@ -621,6 +642,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -799,6 +850,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "which" version = "4.4.2" @@ -876,3 +933,24 @@ name = "windows_x86_64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/Cargo.toml b/Cargo.toml index 8e6f8f8..8b7eac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "calypso" version = "0.1.0" edition = "2021" rust-version = "1.79" +default-run = "calypso" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -13,6 +14,7 @@ protobuf-codegen = "3.5.1" protobuf = "3.5.1" bitstream-io = "2.5.3" clap = { version = "4.5.20", features = ["derive", "env"] } +rand = "0.8" [build-dependencies] diff --git a/Embedded-Base b/Embedded-Base index 1592f6c..bbc8ace 160000 --- a/Embedded-Base +++ b/Embedded-Base @@ -1 +1 @@ -Subproject commit 1592f6c722204c5aae6f9e9b43c5442216b34e0a +Subproject commit bbc8ace5ce8f79e7557bd57c8b393c6bf6a4b5a3 diff --git a/README.md b/README.md index 56a75f8..c5cc0bc 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ Ex. `cansend vcan0 702#01010101FFFFFFFF` Now view calypso interpret the can message and broadcast it on `mqttui` +### Simulation Mode +- Same setup as above, then use the entry point `simulate` instead of `main` +- ```cargo run --bin simulate``` +- ```cargo run --bin simulate -- -u localhost:1883``` + + ### Generate Proto diff --git a/calypsogen.py b/calypsogen.py index 20c326b..05da017 100644 --- a/calypsogen.py +++ b/calypsogen.py @@ -23,6 +23,8 @@ encode_data = open("./src/encode_data.rs", "w") encode_master_mapping = open("./src/encode_master_mapping.rs", "w") +simulate_data = open("./src/simulate_data.rs", "w") + format_data = open("./src/format_data.rs", "w") @@ -56,6 +58,9 @@ encode_master_mapping.write(result.encode_master_mapping) encode_master_mapping.close() +simulate_data.write(result.simulate_data) +simulate_data.close() + format_data.write(result.format_data) format_data.close() diff --git a/src/bin/simulate.rs b/src/bin/simulate.rs new file mode 100644 index 0000000..1cbaaa0 --- /dev/null +++ b/src/bin/simulate.rs @@ -0,0 +1,69 @@ +use std::{ + thread::{self}, + time::Duration, +}; + +use calypso::{ + mqtt::MqttClient, serverdata, simulatable_message::SimulatedComponent, simulate_data::create_simulated_components +}; +use clap::Parser; + + +/// Calypso command line arguments +#[derive(Parser, Debug)] +#[command(version)] +struct CalypsoArgs { + /// The host url of the siren, including port and excluding protocol prefix + #[arg( + short = 'u', + long, + env = "CALYPSO_SIREN_HOST_URL", + default_value = "localhost:1883" + )] + siren_host_url: String, +} + + +fn simulate_out(pub_path: &str) { + let mut client = MqttClient::new(pub_path, "calypso-simulator"); + let _ = client.connect(); // todo: add error handling + let sleep_time = Duration::from_millis(10); + + // todo: a way to turn individual components on and off + let mut simulated_components: Vec = create_simulated_components(); + + // loop through the simulated components, if they should update, update them and publish the data + loop { + for component in simulated_components.iter_mut() { + if component.should_update() { + component.update(); + let data: calypso::data::DecodeData = component.get_data(); + let mut payload = serverdata::ServerData::new(); + payload.unit = data.unit.to_string(); + payload.value = data.value.iter().map(|x| x.to_string()).collect(); + + client + .publish( + data.topic.to_string(), + protobuf::Message::write_to_bytes(&payload).unwrap_or_else(|e| { + format!("failed to serialize {}", e).as_bytes().to_vec() + }), + ) + .expect("Could not publish!"); + } + } + // sleep for a bit + thread::sleep(sleep_time); + } +} + + + +/** + * Main Function + * Calls the `simulate_out` function with the siren host URL from the command line arguments. + */ +fn main() { + let cli = CalypsoArgs::parse(); + simulate_out(&cli.siren_host_url); +} diff --git a/src/lib.rs b/src/lib.rs index 46b7483..c7e64fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,3 +9,5 @@ pub mod encode_master_mapping; pub mod format_data; pub mod mqtt; pub mod serverdata; +pub mod simulate_data; +pub mod simulatable_message; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6a0778a..a7bfce7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -283,4 +283,4 @@ fn main() { can_handle.join().expect("Decoder failed with "); println!("Decoder ended"); -} +} \ No newline at end of file diff --git a/src/simulatable_message.rs b/src/simulatable_message.rs new file mode 100644 index 0000000..2b2eff6 --- /dev/null +++ b/src/simulatable_message.rs @@ -0,0 +1,142 @@ +use super::data::DecodeData; +use rand::prelude::*; +use std::time::Instant; + +/** + * Wrapper class for an individual message. + */ +pub struct SimulatedComponent { + value: Vec, // DecodeData.value + topic: String, // DecodeData.topic + unit: String, // DecodeData.unit + last_update: Instant, // when the data was last updated + #[allow(dead_code)] + n_canpoints: u32, // number of can points + sim_min: f32, // min value + sim_max: f32, // max value + sim_inc_min: f32, // min increment step + sim_inc_max: f32, // max increment step + sim_freq: f32, // Frequency in ms + // format: String, // e.g. "divide10" + #[allow(dead_code)] + id: String, // e.g. "0x80" (or should this be a uint32?) + // signed: bool, // is the value signed? + // size: u8, // size of the value in bits +} + + +pub struct SimulatedComponentAttr { + pub sim_min: f32, + pub sim_max: f32, + pub sim_inc_min: f32, + pub sim_inc_max: f32, + pub sim_freq: f32, + pub n_canpoints: u32, + pub id: String, +} + +/** + * Implementation of SimulatedComponents. + */ +impl SimulatedComponent { + pub fn should_update(&self) -> bool { + self.last_update.elapsed().as_millis() > self.sim_freq as u128 + } + + pub fn new( + topic: String, + unit: String, + attr: SimulatedComponentAttr + ) -> Self { + + let sim_min: f32 = attr.sim_min; + let sim_max: f32 = attr.sim_max; + let sim_inc_min: f32 = attr.sim_inc_min; + let sim_inc_max: f32 = attr.sim_inc_max; + let sim_freq: f32 = attr.sim_freq; + let n_canpoints: u32 = attr.n_canpoints; + let id: String = attr.id; + + let mut value = vec![0.0; n_canpoints as usize]; + + // initialize value with random values between sim_min and sim_max + let mut rng = rand::thread_rng(); + for item in value.iter_mut().take(n_canpoints as usize) { + *item = rng.gen_range(sim_min..sim_max); + if sim_inc_min != 0.0 { + *item = (*item / sim_inc_min).round() * sim_inc_min; + } + } + + Self { + value, + topic, + unit, + last_update: Instant::now(), + n_canpoints, + sim_min, + sim_max, + sim_inc_min, + sim_inc_max, + sim_freq, + id, + } + } + + /** + * Get a random offset within the range of sim_inc_min and sim_inc_max with a random sign. + * Use sim_inc_min as the offset if sim_inc_min == sim_inc_max. + * Rounds the offset to the nearest sim_inc_min if sim_inc_min is not 0. + */ + fn get_rand_offset(&self) -> f32 { + let mut rng = rand::thread_rng(); + let sign = if rng.gen_bool(0.5) { 1.0 } else { -1.0 }; + let offset: f32 = if self.sim_inc_min == self.sim_inc_max { + self.sim_inc_min + } else { + let rand_offset = rng.gen_range(self.sim_inc_min..self.sim_inc_max); + if self.sim_inc_min != 0.0 { + (rand_offset / self.sim_inc_min).round() * self.sim_inc_min + } + else { + rand_offset + } + }; + offset * sign + } + + /** + * Update the value of the simulated component. + * Ensures the value is within the range of sim_min and sim_max, and rounds the value to the nearest sim_inc_min if sim_inc_min is not 0. + */ + pub fn update(&mut self) { + const MAX_ATTEMPTS: u8 = 10; + self.last_update = Instant::now(); + for i in 0..self.value.len() { + let mut new_value = self.value[i] + self.get_rand_offset(); + + // ensuring value is within range AND limit to 5 attempts + let mut attempts = 0; + while (new_value < self.sim_min || new_value > self.sim_max) && attempts < MAX_ATTEMPTS { + new_value = self.value[i] + self.get_rand_offset(); + attempts += 1; + } + + // give up if all attempts failed + if attempts >= MAX_ATTEMPTS { + return; + } + + // rounding the new value + if self.sim_inc_min != 0.0 { + new_value = (new_value / self.sim_inc_min).round() * self.sim_inc_min; + } + + self.value[i] = new_value; + } + } + + pub fn get_data(&self) -> DecodeData { + DecodeData::new(self.value.clone(), &self.topic, &self.unit) + } +} From 88d02e01812252ac44fc4a1e3c3bd57245f2507f Mon Sep 17 00:00:00 2001 From: tszwingli <43227796+tszwinglitw@users.noreply.github.com> Date: Thu, 24 Oct 2024 21:55:17 -0400 Subject: [PATCH 9/9] #37 Docker for Calypso (#66) * added Dockerfile * added github action script * update action script * update action script * update readme, action script * bump embedded base * make build more often * amend when it builds --------- Co-authored-by: Jack Rubacha --- .github/workflows/calypso-build.yml | 58 +++++++++++++++++++++++++++++ Dockerfile | 19 ++++++++++ Embedded-Base | 2 +- README.md | 6 +++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/calypso-build.yml create mode 100644 Dockerfile diff --git a/.github/workflows/calypso-build.yml b/.github/workflows/calypso-build.yml new file mode 100644 index 0000000..62d53d7 --- /dev/null +++ b/.github/workflows/calypso-build.yml @@ -0,0 +1,58 @@ +# +name: Create and publish Calypso docker image + +on: + push: + branches: ['Develop'] + path: + - "Dockerfile" + workflow_dispatch: + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@v3.2.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image for Calypso + uses: docker/build-push-action@v5.4.0 + with: + context: ./ + push: true + platforms: linux/arm64,linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # for caching + # cache-from: type=gha + # cache-to: type=gha,mode=max + # https://github.com/docker/build-push-action/issues/820 + provenance: false diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..06a2dfb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM rust AS builder + +WORKDIR /usr/src/calypso +COPY . . + +RUN git submodule update --init +RUN apt-get update && apt-get install -y libssl-dev build-essential cmake +RUN cargo install --path . + +FROM debian:bookworm-slim +RUN apt update +RUN apt install openssl -y + +COPY --from=builder /usr/local/cargo/bin/calypso /usr/local/bin/calypso +COPY --from=builder /usr/local/cargo/bin/simulate /usr/local/bin/simulate + +CMD ["simulate"] + +# START WITH: sudo docker run -d --rm --network host calypso \ No newline at end of file diff --git a/Embedded-Base b/Embedded-Base index bbc8ace..d87a3e0 160000 --- a/Embedded-Base +++ b/Embedded-Base @@ -1 +1 @@ -Subproject commit bbc8ace5ce8f79e7557bd57c8b393c6bf6a4b5a3 +Subproject commit d87a3e0f5073cf98b7a07d6e151d86f61574ae01 diff --git a/README.md b/README.md index c5cc0bc..5a394e7 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,16 @@ Now view calypso interpret the can message and broadcast it on `mqttui` ### Simulation Mode +#### Run from build - Same setup as above, then use the entry point `simulate` instead of `main` - ```cargo run --bin simulate``` - ```cargo run --bin simulate -- -u localhost:1883``` +#### Run from Docker +- ```docker pull ghcr.io/northeastern-electric-racing/calypso:Develop``` +- ```docker run -d --rm --network host ghcr.io/northeastern-electric-racing/calypso:Develop``` +- ```docker run -d --rm -e CALYPSO_SIREN_HOST_URL=127.0.0.1:1883 --network host ghcr.io/northeastern-electric-racing/calypso:Develop``` + ### Generate Proto