Skip to content

Commit

Permalink
Allow device parameters to be overridden via environment variables
Browse files Browse the repository at this point in the history
Allow the following parameters to be overridden from their default
values via environment variables:
* Advertised name (for advertising and GAP device name)
* Device id (response to `GetProgressorID` control message)
* Device version number (response to `GetAppVersion` control message)

This allows unique values to be set without committing them to the
repository.
  • Loading branch information
kesyog committed Oct 4, 2023
1 parent a870b6a commit b51eb88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ runner = "probe-run --chip nRF52832_xxAA"

[build]
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

[env]
ADVERTISED_NAME = "Progressor_1719"
DEVICE_ID = "42"
DEVICE_VERSION_NUMBER = "1.2.3.4"
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ fn main() {

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rerun-if-env-changed=ADVERTISED_NAME");
println!("cargo:rerun-if-env-changed=DEVICE_ID");
println!("cargo:rerun-if-env-changed=DEVICE_VERSION_NUMBER");
}
17 changes: 12 additions & 5 deletions src/ble/gatt_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ use nrf_softdevice::ble::Connection;
use nrf_softdevice::Softdevice;
use once_cell::sync::OnceCell;

const DUMMY_VERSION_NUMBER: &[u8] = b"1.2.3.4";
const DUMMY_ID: u32 = 42;

#[nrf_softdevice::gatt_server]
struct Server {
progressor: ProgressorService,
Expand Down Expand Up @@ -129,12 +126,22 @@ fn on_control_message(message: ControlOpcode, conn: &Connection, measure_ch: &Me
}
}
ControlOpcode::GetAppVersion => {
if notify_data(DataOpcode::AppVersion(DUMMY_VERSION_NUMBER), conn).is_err() {
if notify_data(
DataOpcode::AppVersion(env!("DEVICE_VERSION_NUMBER").as_bytes()),
conn,
)
.is_err()
{
defmt::error!("Response to GetAppVersion failed");
};
}
ControlOpcode::GetProgressorID => {
if notify_data(DataOpcode::ProgressorId(DUMMY_ID), conn).is_err() {
if notify_data(
DataOpcode::ProgressorId(env!("DEVICE_ID").parse().unwrap()),
conn,
)
.is_err()
{
defmt::error!("Response to GetProgressorID failed");
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/ble/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type MeasureChannel = Sender<'static, NoopRawMutex, weight::Command, MEASURE_COM

/// Device name to be used in GAP and advertising data. The Tindeq app requires this to be
/// something of this form.
const ADVERTISED_NAME: &[u8] = b"Progressor_1719";
const ADVERTISED_NAME: &[u8] = env!("ADVERTISED_NAME").as_bytes();

fn softdevice_config() -> nrf_softdevice::Config {
use nrf_softdevice::raw;
Expand Down

0 comments on commit b51eb88

Please sign in to comment.