Skip to content

Commit

Permalink
sx1302: Provide option to override SX1302/3 embedded Gateway ID. (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-juteau authored Oct 29, 2024
1 parent 073b03c commit 8bb21f1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions chirpstack-concentratord-sx1302/config/concentratord.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ model=""

# Gateway vendor / model flags.
model_flags=[]

# Gateway ID.
#
# Only set this if you would like to override the Gateway ID provided by the SX1302/3.
gateway_id=""
5 changes: 5 additions & 0 deletions chirpstack-concentratord-sx1302/src/cmd/configfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub fn run(config: &config::Configuration) {
# USB - Use USB for concentrator communication (default is SPI)
model_flags=[{{#each gateway.model_flags}}"{{ this }},{{/each}}]
# Gateway ID.
#
# Only set this if you would like to override the Gateway ID provided by the SX1302/3.
gateway_id="{{ gateway.gateway_id }}"
# Time fallback.
#
# In case the gateway does not have a GNSS module or is unable to aquire a
Expand Down
7 changes: 6 additions & 1 deletion chirpstack-concentratord-sx1302/src/cmd/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ pub fn run(
);

// get concentrator eui
let gateway_id = concentrator::get_eui().unwrap();
let gateway_id = if let Some(gateway_id) = config.gateway.gateway_id_bytes {
gateway_id
}
else {
concentrator::get_eui().unwrap()
};

info!(
"Gateway ID retrieved, gateway_id: {:x?}",
Expand Down
15 changes: 15 additions & 0 deletions chirpstack-concentratord-sx1302/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct Gateway {
pub region: Option<Region>,
pub model: String,
pub model_flags: Vec<String>,
pub gateway_id: Option<String>,

pub time_fallback_enabled: bool,
pub concentrator: Concentrator,
Expand All @@ -110,6 +111,8 @@ pub struct Gateway {
pub com_dev_path: Option<String>,
pub i2c_dev_path: Option<String>,

#[serde(skip)]
pub gateway_id_bytes: Option<[u8; 8]>,
#[serde(skip)]
pub model_config: vendor::Configuration,
#[serde(skip)]
Expand All @@ -124,6 +127,7 @@ impl Default for Gateway {
region: None,
model: "".into(),
model_flags: vec![],
gateway_id: None,
time_fallback_enabled: false,
concentrator: Concentrator::default(),
beacon: Beacon::default(),
Expand All @@ -135,6 +139,7 @@ impl Default for Gateway {
sx1302_power_en_pin: None,
sx1261_reset_chip: None,
sx1261_reset_pin: None,
gateway_id_bytes: None,
gnss_dev_path: None,
com_dev_path: None,
i2c_dev_path: None,
Expand Down Expand Up @@ -321,6 +326,16 @@ pub fn get(filenames: Vec<String>) -> Configuration {

let mut config: Configuration = toml::from_str(&content).expect("Error parsing config file");

// decode gateway id
if let Some(gateway_id) = &config.gateway.gateway_id {
let bytes = hex::decode(gateway_id).expect("Could not decode gateway_id");
if bytes.len() != 8 {
panic!("gateway_id must be exactly 8 bytes");
}
let id = bytes.as_slice();
config.gateway.gateway_id_bytes = Some(id[0..8].try_into().unwrap());
}

// get model configuration
config.gateway.model_config = match config.gateway.model.as_ref() {
"dragino_pg1302" => vendor::dragino::pg1302::new(&config).unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ DAEMON_PID=/var/run/$NAME.pid
read_lora_hw_info() {
lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null)
lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null)
lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null)
# remove all colons
lora_eui_raw=${lora_eui//:/}
}

hardware_found() {
Expand Down Expand Up @@ -43,6 +46,7 @@ copy_config() {

sed -i "s/region=.*/region=\"${region}\"/" $DAEMON_CONF_DIR/concentratord.toml
sed -i "s/model=.*/model=\"multitech_${model}\"/" $DAEMON_CONF_DIR/concentratord.toml
sed -i "s/gateway_id=.*/gateway_id=\"${lora_eui_raw}\"/" $DAEMON_CONF_DIR/concentratord.toml
}

do_start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ model=""
model_flags=[]

# Gateway ID.
#
# Only set this if you would like to override the Gateway ID provided by the SX1302/3.
gateway_id=""

# Time fallback.
time_fallback_enabled=true
time_fallback_enabled=true

0 comments on commit 8bb21f1

Please sign in to comment.