-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for reporting service information #131
Changes from all commits
5d08a80
5665d6f
4d75e3c
b29ec9a
f59fce4
f0325df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Booster NGFW build script | ||
//! | ||
//! # Copyright | ||
//! Copyright (C) 2020 QUARTIQ GmbH - All Rights Reserved | ||
//! Unauthorized usage, editing, or copying is strictly prohibited. | ||
//! Proprietary and confidential. | ||
//! | ||
//! # Note | ||
//! This build script is run immediately before the build is completed and is used to inject | ||
//! environment variables into the build. | ||
use std::process::Command; | ||
|
||
fn main() { | ||
// Inject the git revision into an environment variable for compilation. | ||
let dirty_flag = if !Command::new("git") | ||
.args(&["diff", "--quiet"]) | ||
.status() | ||
.unwrap() | ||
.success() | ||
{ | ||
"-dirty" | ||
} else { | ||
"" | ||
}; | ||
|
||
let output = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let revision = String::from_utf8(output.stdout).unwrap(); | ||
println!( | ||
"cargo:rustc-env=GIT_REVISION={}{}", | ||
revision.trim(), | ||
dirty_flag | ||
); | ||
|
||
let output = Command::new("git") | ||
.args(&["describe", "--tags"]) | ||
.output() | ||
.unwrap(); | ||
let version = String::from_utf8(output.stdout).unwrap(); | ||
println!("cargo:rustc-env=VERSION={}", version.trim()); | ||
|
||
// Collect all of the enabled features and inject them as an environment variable. | ||
let mut features: Vec<String> = Vec::new(); | ||
for (key, _) in std::env::vars() { | ||
let strings: Vec<&str> = key.split("CARGO_FEATURE_").collect(); | ||
if strings.len() > 1 { | ||
println!("{}", strings[1]); | ||
features.push(String::from(strings[1])); | ||
} | ||
} | ||
|
||
println!("cargo:rustc-env=ALL_FEATURES={}", features.join(", ")); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,9 @@ enum Token { | |
|
||
#[regex(r"[a-zA-Z0-9]+")] | ||
DeviceIdentifier, | ||
|
||
#[token("service")] | ||
ServiceInfo, | ||
} | ||
|
||
#[derive(PartialEq)] | ||
|
@@ -74,6 +77,7 @@ pub enum Request { | |
ResetBootloader, | ||
Help, | ||
Read(Property), | ||
ServiceInfo, | ||
WriteIpAddress(Property, Ipv4Addr), | ||
WriteIdentifier(String<consts::U32>), | ||
} | ||
|
@@ -152,6 +156,61 @@ impl SerialTerminal { | |
); | ||
} | ||
|
||
Request::ServiceInfo => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also print version, release/debug, features and commit hash (through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Service command has now become much more comprehensive:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jordens I was poking around with
Necessary cargo changes were merged recently, but we'd have to move to nightly cargo. We can move over to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. I wasn't aware that crate features were also unified between dependencies and build-dependencies. That sounds bad. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bug that just recently got fixed, but is not quite yet on stable cargo |
||
let mut msg: String<consts::U256> = String::new(); | ||
write!(&mut msg, "{:<20}: {}\n", "Version", env!("VERSION")).unwrap_or_else( | ||
|_| { | ||
msg = String::from("Version: too long"); | ||
}, | ||
); | ||
self.write(msg.as_bytes()); | ||
|
||
msg.clear(); | ||
write!( | ||
&mut msg, | ||
"{:<20}: {}\n", | ||
"Git revision", | ||
env!("GIT_REVISION") | ||
) | ||
.unwrap_or_else(|_| { | ||
msg = String::from("Git revision: too long"); | ||
}); | ||
self.write(msg.as_bytes()); | ||
|
||
msg.clear(); | ||
write!(&mut msg, "{:<20}: {}\n", "Features", env!("ALL_FEATURES")) | ||
.unwrap_or_else(|_| { | ||
msg = String::from("Features: too long"); | ||
}); | ||
self.write(msg.as_bytes()); | ||
|
||
msg.clear(); | ||
// Note(unwrap): The msg size is long enough to always contain the provided | ||
// string. | ||
write!(&mut msg, "{:<20}: ", "Panic Info").unwrap(); | ||
self.write(msg.as_bytes()); | ||
self.write( | ||
panic_persist::get_panic_message_bytes().unwrap_or("None".as_bytes()), | ||
); | ||
self.write("\n".as_bytes()); | ||
|
||
msg.clear(); | ||
// Note(unwrap): The msg size is long enough to be sufficient for all possible | ||
// formats. | ||
write!( | ||
&mut msg, | ||
"{:<20}: {}\n", | ||
"Watchdog Detected", | ||
platform::watchdog_detected() | ||
) | ||
.unwrap(); | ||
self.write(msg.as_bytes()); | ||
|
||
// Reading the panic message above clears the panic message, so similarly, we | ||
// should also clear the watchdog once read. | ||
platform::clear_reset_flags(); | ||
} | ||
|
||
Request::WriteIpAddress(prop, addr) => match prop { | ||
Property::SelfAddress => self.settings.set_ip_address(addr), | ||
Property::BrokerAddress => self.settings.set_broker(addr), | ||
|
@@ -312,6 +371,7 @@ gateway, netmask] | |
netmask, gateway] and <IP> must be an IP address (e.g. 192.168.1.1) | ||
* `write id <ID>` - Write the MQTT client ID of the device. <ID> must be 23 or less ASCII \ | ||
characters. | ||
* `service` - Read the service information. Service infromation clears once read. | ||
".as_bytes(), | ||
); | ||
} | ||
|
@@ -335,6 +395,7 @@ characters. | |
Token::Reset => Request::Reset, | ||
Token::Dfu => Request::ResetBootloader, | ||
Token::Help => Request::Help, | ||
Token::ServiceInfo => Request::ServiceInfo, | ||
Token::Read => { | ||
// Validate that there is one valid token following. | ||
let property_token = lex.next().ok_or("Malformed command")?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James Munns said he would push the
master
branch to a new release later today, so we should wait and update when that gets pushed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Let's wait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deferring to #136