Skip to content

Commit

Permalink
Add reset-pin and device paths as override config options.
Browse files Browse the repository at this point in the history
For certain scenarios, it is needed to override the device paths (SPI,
GNSS, I2C, USB) or reset pin configuration. This documents the override
options (commented out example) and makes it possible to override these
settings for each gateway model.
  • Loading branch information
brocaar committed Sep 20, 2024
1 parent 1adae5a commit 0af7d7c
Show file tree
Hide file tree
Showing 37 changed files with 134 additions and 241 deletions.
12 changes: 12 additions & 0 deletions chirpstack-concentratord-2g4/src/cmd/configfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ pub fn run(config: &config::Configuration) {
# GNSS fix, use the system-time for setting the 'time' field on RX.
time_fallback_enabled={{ gateway.time_fallback_enabled }}
# Device and pin configuration.
#
# Only set this configuration if you need to override the default
# configuration provided by the model configuration and you know
# the device and pin mapping. In any other case, leave this commented
# out.
# com_dev_path="/dev/ttyACM0"
# mcu_reset_chip="/dev/gpiochip0"
# mcu_reset_pin=32
# mcu_boot_chip="/dev/gpiochip0"
# mcu_boot_pin=18
# LoRa concentrator configuration.
[gateway.concentrator]
Expand Down
6 changes: 6 additions & 0 deletions chirpstack-concentratord-2g4/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ pub struct Gateway {
}

impl Gateway {
pub fn get_com_dev_path(&self, com_dev_path: &str) -> String {
self.com_dev_path
.clone()
.unwrap_or(com_dev_path.to_string())
}

pub fn get_mcu_reset_pin(&self, default_chip: &str, default_pin: u32) -> Option<(String, u32)> {
let chip = self
.mcu_reset_chip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::super::super::super::config;
use super::super::Configuration;

pub fn new(_conf: &config::Configuration) -> Configuration {
pub fn new(conf: &config::Configuration) -> Configuration {
Configuration {
tty_path: "/dev/ttyACM0".to_string(),
tty_path: conf.gateway.get_com_dev_path("/dev/ttyACM0"),
min_max_tx_freq: (2400000000, 2483500000),
reset_pin: None,
boot0_pin: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ use super::super::Configuration;

pub fn new(conf: &config::Configuration) -> Configuration {
Configuration {
tty_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/ttyACM0".to_string()),
tty_path: conf.gateway.get_com_dev_path("/dev/ttyACM0"),
min_max_tx_freq: (2400000000, 2483500000),
reset_pin: None,
boot0_pin: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ use super::super::Configuration;

pub fn new(conf: &config::Configuration) -> Configuration {
Configuration {
tty_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/ttyACM0".to_string()),
tty_path: conf.gateway.get_com_dev_path("/dev/ttyACM0"),
min_max_tx_freq: (2400000000, 2483500000),
// pin configuration taken from:
// https://github.com/Lora-net/gateway_2g4_hal/blob/master/tools/rpi_configure_gpio.sh
Expand Down
11 changes: 11 additions & 0 deletions chirpstack-concentratord-sx1301/src/cmd/configfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ pub fn run(config: &config::Configuration) {
# GNSS fix, use the system-time for setting the 'time' field on RX.
time_fallback_enabled={{ gateway.time_fallback_enabled }}
# Device and pin configuration.
#
# Only set this configuration if you need to override the default
# configuration provided by the model configuration and you know
# the device and pin mapping. In any other case, leave this commented
# out.
# gnss_dev_path="/dev/ttyAMA0"
# com_dev_path="/dev/spidev0.0"
# sx1301_reset_chip="/dev/gpiochip0"
# sx1301_reset_pin=17
# LoRa concentrator configuration.
[gateway.concentrator]
Expand Down
12 changes: 12 additions & 0 deletions chirpstack-concentratord-sx1301/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ impl Default for Gateway {
}

impl Gateway {
pub fn get_gnss_dev_path(&self, gnss_dev_path: &str) -> String {
self.gnss_dev_path
.clone()
.unwrap_or(gnss_dev_path.to_string())
}

pub fn get_com_dev_path(&self, com_dev_path: &str) -> String {
self.com_dev_path
.clone()
.unwrap_or(com_dev_path.to_string())
}

pub fn get_sx1301_reset_pin(
&self,
default_chip: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
dac_gain: 3,
},
],
spidev_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 5),
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
dac_gain: 3,
},
],
spidev_path: "/dev/spidev0.0".to_string(),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
..Default::default()
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
false => Gps::None,
},
spidev_path: match port {
Port::AP1 => "/dev/spidev0.2".to_string(),
Port::AP2 => "/dev/spidev1.2".to_string(),
Port::AP1 => conf.gateway.get_com_dev_path("/dev/spidev0.2"),
Port::AP2 => conf.gateway.get_com_dev_path("/dev/spidev1.2"),
},
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
false => Gps::None,
},
spidev_path: match port {
Port::AP1 => "/dev/spidev0.2".to_string(),
Port::AP2 => "/dev/spidev1.2".to_string(),
Port::AP1 => conf.gateway.get_com_dev_path("/dev/spidev0.2"),
Port::AP2 => conf.gateway.get_com_dev_path("/dev/spidev1.2"),
},
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
dac_gain: 3,
},
],
spidev_path: "/dev/spidev0.0".to_string(),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
..Default::default()
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
dac_gain: 3,
},
],
spidev_path: "/dev/spidev0.0".to_string(),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
..Default::default()
})
}
13 changes: 2 additions & 11 deletions chirpstack-concentratord-sx1301/src/config/vendor/rak/rak2245.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +478,10 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
radio_tx_notch_freq: vec![0, 0],
lora_multi_sf_bandwidth: 125000,
gps: match gps {
true => Gps::TtyPath(
conf.gateway
.gnss_dev_path
.clone()
.unwrap_or("/dev/ttyAMA0".to_string()),
),
true => Gps::TtyPath(conf.gateway.get_gnss_dev_path("/dev/ttyAMA0")),
false => Gps::None,
},
spidev_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 17),
})
}
13 changes: 2 additions & 11 deletions chirpstack-concentratord-sx1301/src/config/vendor/rak/rak2246.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,10 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
radio_tx_notch_freq: vec![0, 0],
lora_multi_sf_bandwidth: 125000,
gps: match gps {
true => Gps::TtyPath(
conf.gateway
.gnss_dev_path
.clone()
.unwrap_or("/dev/ttyAMA0".to_string()),
),
true => Gps::TtyPath(conf.gateway.get_gnss_dev_path("/dev/ttyAMA0")),
false => Gps::None,
},
spidev_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 17),
})
}
14 changes: 2 additions & 12 deletions chirpstack-concentratord-sx1301/src/config/vendor/rak/rak2247.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,20 +607,10 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
radio_tx_notch_freq: vec![0, 0],
lora_multi_sf_bandwidth: 125000,
gps: match gps {
true => Gps::TtyPath(
conf.gateway
.gnss_dev_path
.clone()
.unwrap_or("/dev/ttyAMA0".to_string()),
),
true => Gps::TtyPath(conf.gateway.get_gnss_dev_path("/dev/ttyAMA0")),
false => Gps::None,
},
spidev_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),

spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 17),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
dac_gain: 3,
},
],
spidev_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 7),
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
radio_type: vec![hal::RadioType::SX1257, hal::RadioType::SX1257],
radio_tx_notch_freq: vec![0, 0],
lora_multi_sf_bandwidth: 125000,
spidev_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 25),
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
} else {
panic!("Invalid antenna_gain: {}", conf.gateway.antenna_gain);
},
spidev_path: "/dev/spidev0.0".to_string(),
spidev_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
reset_pin: conf.gateway.get_sx1301_reset_pin("/dev/gpiochip0", 1),
..Default::default()
})
Expand Down
16 changes: 16 additions & 0 deletions chirpstack-concentratord-sx1302/src/cmd/configfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ pub fn run(config: &config::Configuration) {
# GNSS fix, use the system-time for setting the 'time' field on RX.
time_fallback_enabled={{ gateway.time_fallback_enabled }}
# Device and pin configuration.
#
# Only set this configuration if you need to override the default
# configuration provided by the model configuration and you know
# the device and pin mapping. In any other case, leave this commented
# out.
# gnss_dev_path="/dev/ttyAMA0"
# com_dev_path="/dev/spidev0.0"
# i2c_dev_path="/dev/i2c-1"
# sx1302_reset_chip="/dev/gpiochip0"
# sx1302_reset_pin=17
# sx1302_power_en_chip="/dev/gpiochip0"
# sx1302_power_en_pin=18
# sx1261_reset_chip="/dev/gpiochip0"
# sx1261_reset_pin=19
# LoRa concentrator configuration.
[gateway.concentrator]
Expand Down
18 changes: 18 additions & 0 deletions chirpstack-concentratord-sx1302/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ impl Gateway {
let pin = self.sx1261_reset_pin.unwrap_or(default_pin);
Some((chip, pin))
}

pub fn get_gnss_dev_path(&self, gnss_dev_path: &str) -> String {
self.gnss_dev_path
.clone()
.unwrap_or(gnss_dev_path.to_string())
}

pub fn get_com_dev_path(&self, com_dev_path: &str) -> String {
self.com_dev_path
.clone()
.unwrap_or(com_dev_path.to_string())
}

pub fn get_i2c_dev_path(&self, i2c_dev_path: &str) -> String {
self.i2c_dev_path
.clone()
.unwrap_or(i2c_dev_path.to_string())
}
}

#[derive(Default, Serialize, Deserialize, Debug, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
],
gps: Gps::None,
com_type: ComType::Spi,
com_path: conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
com_path: conf.gateway.get_com_dev_path("/dev/spidev0.0"),
sx1302_reset_pin: conf.gateway.get_sx1302_reset_pin("/dev/gpiochip0", 23),
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,10 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
false => ComType::Spi,
},
com_path: match usb {
true => conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/ttyACM0".to_string()),
false => conf
.gateway
.com_dev_path
.clone()
.unwrap_or("/dev/spidev0.0".to_string()),
true => conf.gateway.get_com_dev_path("/dev/ttyACM0"),
false => conf.gateway.get_com_dev_path("/dev/spidev0.0"),
},
i2c_path: Some(
conf.gateway
.i2c_dev_path
.clone()
.unwrap_or("/dev/i2c-1".to_string()),
),
i2c_path: Some(conf.gateway.get_i2c_dev_path("/dev/i2c-1")),
i2c_temp_sensor_addr: Some(0x3B),
sx1302_reset_pin: conf.gateway.get_sx1302_reset_pin("/dev/gpiochip0", 4),
sx1302_power_en_pin: conf.gateway.get_sx1302_power_en_pin("/dev/gpiochip0", 17),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
},
com_type: ComType::Spi,
com_path: match port {
Port::AP1 => "/dev/spidev0.0".to_string(),
Port::AP2 => "/dev/spidev1.0".to_string(),
Port::AP1 => conf.gateway.get_com_dev_path("/dev/spidev0.0"),
Port::AP2 => conf.gateway.get_com_dev_path("/dev/spidev1.0"),
},
i2c_path: Some("/dev/i2c-1".to_string()),
i2c_path: Some(conf.gateway.get_i2c_dev_path("/dev/i2c-1")),
i2c_temp_sensor_addr: match port {
Port::AP1 => Some(0x48),
Port::AP2 => Some(0x49),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
},
com_type: ComType::Spi,
com_path: match port {
Port::AP1 => "/dev/spidev0.0".to_string(),
Port::AP2 => "/dev/spidev1.0".to_string(),
Port::AP1 => conf.gateway.get_com_dev_path("/dev/spidev0.0"),
Port::AP2 => conf.gateway.get_com_dev_path("/dev/spidev1.0"),
},
i2c_path: Some("/dev/i2c-1".to_string()),
i2c_path: Some(conf.gateway.get_i2c_dev_path("/dev/i2c-1")),
i2c_temp_sensor_addr: match port {
Port::AP1 => Some(0x48),
Port::AP2 => Some(0x49),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn new(conf: &config::Configuration) -> Result<Configuration> {
],
gps: Gps::None,
com_type: ComType::Spi,
com_path: "/dev/spidev1.0".to_string(),
com_path: conf.gateway.get_com_dev_path("/dev/spidev1.0"),
reset_commands: Some(vec![
(
"mts-io-sysfs".to_string(),
Expand Down
Loading

0 comments on commit 0af7d7c

Please sign in to comment.