diff --git a/chirpstack-concentratord-2g4/src/cmd/root.rs b/chirpstack-concentratord-2g4/src/cmd/root.rs index b8f0bb44..dc02243d 100644 --- a/chirpstack-concentratord-2g4/src/cmd/root.rs +++ b/chirpstack-concentratord-2g4/src/cmd/root.rs @@ -85,11 +85,12 @@ pub fn run( // jit thread threads.push(thread::spawn({ let queue = Arc::clone(&queue); + let antenna_gain_dbi = config.gateway.antenna_gain; let stop_receive = signal_pool.new_receiver(); let stop_send = stop_send.clone(); move || { - if let Err(e) = handler::jit::jit_loop(queue, stop_receive) { + if let Err(e) = handler::jit::jit_loop(queue, antenna_gain_dbi, stop_receive) { error!("JIT loop error: {}", e); stop_send.send(Signal::Stop).unwrap(); } @@ -106,14 +107,12 @@ pub fn run( let stop_send = stop_send.clone(); let stop_send_err = stop_send.clone(); let lorawan_public = config.gateway.lorawan_public; - let antenna_gain = config.gateway.antenna_gain; move || { if let Err(e) = handler::command::handle_loop( lorawan_public, &vendor_config, &gateway_id, - antenna_gain, queue, rep_sock, stop_receive, diff --git a/chirpstack-concentratord-2g4/src/handler/command.rs b/chirpstack-concentratord-2g4/src/handler/command.rs index 87302772..c16c2235 100644 --- a/chirpstack-concentratord-2g4/src/handler/command.rs +++ b/chirpstack-concentratord-2g4/src/handler/command.rs @@ -16,7 +16,6 @@ pub fn handle_loop( lorawan_public: bool, vendor_config: &vendor::Configuration, gateway_id: &[u8], - anteanna_gain: i8, queue: Arc>>, rep_sock: zmq::Socket, stop_receive: Receiver, @@ -38,14 +37,7 @@ pub fn handle_loop( continue; } commands::Command::Downlink(pl) => { - match handle_downlink( - lorawan_public, - vendor_config, - gateway_id, - &queue, - &pl, - anteanna_gain, - ) { + match handle_downlink(lorawan_public, vendor_config, gateway_id, &queue, &pl) { Ok(v) => v, Err(_) => Vec::new(), } @@ -79,7 +71,6 @@ fn handle_downlink( gateway_id: &[u8], queue: &Arc>>, pl: &chirpstack_api::gw::DownlinkFrame, - anteanna_gain: i8, ) -> Result> { stats::inc_tx_packets_received(); @@ -93,7 +84,7 @@ fn handle_downlink( for (i, item) in pl.items.iter().enumerate() { // convert protobuf to hal struct - let mut tx_packet = match wrapper::downlink_from_proto(lorawan_public, item) { + let tx_packet = match wrapper::downlink_from_proto(lorawan_public, item) { Ok(v) => v, Err(err) => { error!( @@ -103,7 +94,6 @@ fn handle_downlink( return Err(err); } }; - tx_packet.rf_power -= anteanna_gain; // validate frequency range let freqs = vendor_config.min_max_tx_freq; diff --git a/chirpstack-concentratord-2g4/src/handler/jit.rs b/chirpstack-concentratord-2g4/src/handler/jit.rs index 88ae7fb9..69abdfd3 100644 --- a/chirpstack-concentratord-2g4/src/handler/jit.rs +++ b/chirpstack-concentratord-2g4/src/handler/jit.rs @@ -13,6 +13,7 @@ use super::super::wrapper; pub fn jit_loop( queue: Arc>>, + antenna_gain_dbi: i8, stop_receive: Receiver, ) -> Result<()> { debug!("Start JIT queue loop"); @@ -31,7 +32,8 @@ pub fn jit_loop( }; let downlink_id = tx_packet.get_id(); - let tx_packet = tx_packet.tx_packet(); + let mut tx_packet = tx_packet.tx_packet(); + tx_packet.rf_power -= antenna_gain_dbi; match hal::send(&tx_packet) { Ok(_) => { diff --git a/chirpstack-concentratord-sx1301/src/cmd/root.rs b/chirpstack-concentratord-sx1301/src/cmd/root.rs index 3664bdee..899990c2 100644 --- a/chirpstack-concentratord-sx1301/src/cmd/root.rs +++ b/chirpstack-concentratord-sx1301/src/cmd/root.rs @@ -96,11 +96,12 @@ pub fn run( // jit thread threads.push(thread::spawn({ let queue = Arc::clone(&queue); + let antenna_gain_dbi = config.gateway.antenna_gain; let stop_receive = signal_pool.new_receiver(); let stop_send = stop_send.clone(); move || { - if let Err(e) = handler::jit::jit_loop(queue, stop_receive) { + if let Err(e) = handler::jit::jit_loop(queue, antenna_gain_dbi, stop_receive) { error!("JIT loop error: {}", e); stop_send.send(Signal::Stop).unwrap(); } @@ -118,13 +119,10 @@ pub fn run( let stop_send = stop_send.clone(); let stop_send_err = stop_send.clone(); - let antenna_gain = config.gateway.antenna_gain; - move || { if let Err(e) = handler::command::handle_loop( &vendor_config, &gateway_id, - antenna_gain, queue, rep_sock, stop_receive, diff --git a/chirpstack-concentratord-sx1301/src/handler/command.rs b/chirpstack-concentratord-sx1301/src/handler/command.rs index 77631a76..c304ef65 100644 --- a/chirpstack-concentratord-sx1301/src/handler/command.rs +++ b/chirpstack-concentratord-sx1301/src/handler/command.rs @@ -14,7 +14,6 @@ use super::timersync; pub fn handle_loop( vendor_config: &vendor::Configuration, gateway_id: &[u8], - antenna_gain: i8, queue: Arc>>, rep_sock: zmq::Socket, stop_receive: Receiver, @@ -36,7 +35,7 @@ pub fn handle_loop( continue; } commands::Command::Downlink(pl) => { - match handle_downlink(vendor_config, gateway_id, &queue, &pl, antenna_gain) { + match handle_downlink(vendor_config, gateway_id, &queue, &pl) { Ok(v) => v, Err(e) => { error!("Handle downlink error: {}", e); @@ -75,7 +74,6 @@ fn handle_downlink( gateway_id: &[u8], queue: &Arc>>, pl: &chirpstack_api::gw::DownlinkFrame, - antenna_gain: i8, ) -> Result> { stats::inc_tx_packets_received(); @@ -89,7 +87,7 @@ fn handle_downlink( for (i, item) in pl.items.iter().enumerate() { // convert protobuf to hal struct - let mut tx_packet = match wrapper::downlink_from_proto(item) { + let tx_packet = match wrapper::downlink_from_proto(item) { Ok(v) => v, Err(err) => { error!( @@ -99,7 +97,6 @@ fn handle_downlink( return Err(err); } }; - tx_packet.rf_power -= antenna_gain; // validate frequency range let freqs = vendor_config.radio_min_max_tx_freq[tx_packet.rf_chain as usize]; diff --git a/chirpstack-concentratord-sx1301/src/handler/jit.rs b/chirpstack-concentratord-sx1301/src/handler/jit.rs index 711e0507..2ddf2454 100644 --- a/chirpstack-concentratord-sx1301/src/handler/jit.rs +++ b/chirpstack-concentratord-sx1301/src/handler/jit.rs @@ -14,6 +14,7 @@ use super::timersync; pub fn jit_loop( queue: Arc>>, + antenna_gain_dbi: i8, stop_receive: Receiver, ) -> Result<()> { debug!("Starting JIT queue loop"); @@ -32,7 +33,8 @@ pub fn jit_loop( }; let downlink_id = tx_packet.get_id(); - let tx_packet = tx_packet.tx_packet(); + let mut tx_packet = tx_packet.tx_packet(); + tx_packet.rf_power -= antenna_gain_dbi; match hal::send(&tx_packet) { Ok(_) => { diff --git a/chirpstack-concentratord-sx1302/src/cmd/root.rs b/chirpstack-concentratord-sx1302/src/cmd/root.rs index ef976708..75be8609 100644 --- a/chirpstack-concentratord-sx1302/src/cmd/root.rs +++ b/chirpstack-concentratord-sx1302/src/cmd/root.rs @@ -91,11 +91,12 @@ pub fn run( // jit thread threads.push(thread::spawn({ let queue = Arc::clone(&queue); + let antenna_gain_dbi = config.gateway.antenna_gain; let stop_receive = signal_pool.new_receiver(); let stop_send = stop_send.clone(); move || { - if let Err(e) = handler::jit::jit_loop(queue, stop_receive) { + if let Err(e) = handler::jit::jit_loop(queue, antenna_gain_dbi, stop_receive) { error!("JIT loop error: {}", e); stop_send.send(Signal::Stop).unwrap(); } @@ -111,13 +112,11 @@ pub fn run( let stop_receive = signal_pool.new_receiver(); let stop_send = stop_send.clone(); let stop_send_err = stop_send.clone(); - let antenna_gain = config.gateway.antenna_gain; move || { if let Err(e) = handler::command::handle_loop( &vendor_config, &gateway_id, - antenna_gain, queue, rep_sock, stop_receive, diff --git a/chirpstack-concentratord-sx1302/src/handler/command.rs b/chirpstack-concentratord-sx1302/src/handler/command.rs index 4ed95274..e33c05bf 100644 --- a/chirpstack-concentratord-sx1302/src/handler/command.rs +++ b/chirpstack-concentratord-sx1302/src/handler/command.rs @@ -14,7 +14,6 @@ use super::super::wrapper; pub fn handle_loop( vendor_config: &vendor::Configuration, gateway_id: &[u8], - antenna_gain: i8, queue: Arc>>, rep_sock: zmq::Socket, stop_receive: Receiver, @@ -36,7 +35,7 @@ pub fn handle_loop( continue; } commands::Command::Downlink(pl) => { - match handle_downlink(vendor_config, gateway_id, &queue, &pl, antenna_gain) { + match handle_downlink(vendor_config, gateway_id, &queue, &pl) { Ok(v) => v, Err(e) => { error!("Handle downlink error: {}", e); @@ -75,7 +74,6 @@ fn handle_downlink( gateway_id: &[u8], queue: &Arc>>, pl: &chirpstack_api::gw::DownlinkFrame, - antenna_gain: i8, ) -> Result> { stats::inc_tx_packets_received(); @@ -89,7 +87,7 @@ fn handle_downlink( for (i, item) in pl.items.iter().enumerate() { // convert protobuf to hal struct - let mut tx_packet = match wrapper::downlink_from_proto(item) { + let tx_packet = match wrapper::downlink_from_proto(item) { Ok(v) => v, Err(err) => { error!( @@ -99,7 +97,6 @@ fn handle_downlink( return Err(err); } }; - tx_packet.rf_power -= antenna_gain; // validate frequency range match vendor_config.radio_config.get(tx_packet.rf_chain as usize) { diff --git a/chirpstack-concentratord-sx1302/src/handler/jit.rs b/chirpstack-concentratord-sx1302/src/handler/jit.rs index a9cb825b..94d20c10 100644 --- a/chirpstack-concentratord-sx1302/src/handler/jit.rs +++ b/chirpstack-concentratord-sx1302/src/handler/jit.rs @@ -13,6 +13,7 @@ use super::super::wrapper; pub fn jit_loop( queue: Arc>>, + antenna_gain_dbi: i8, stop_receive: Receiver, ) -> Result<()> { debug!("Starting JIT queue loop"); @@ -31,7 +32,8 @@ pub fn jit_loop( }; let downlink_id = tx_packet.get_id(); - let tx_packet = tx_packet.tx_packet(); + let mut tx_packet = tx_packet.tx_packet(); + tx_packet.rf_power -= antenna_gain_dbi; match hal::send(&tx_packet) { Ok(_) => { diff --git a/libconcentratord/src/regulation/standard/etsi_en_300_220.rs b/libconcentratord/src/regulation/standard/etsi_en_300_220.rs index b873d709..fc3678bb 100644 --- a/libconcentratord/src/regulation/standard/etsi_en_300_220.rs +++ b/libconcentratord/src/regulation/standard/etsi_en_300_220.rs @@ -11,49 +11,49 @@ pub fn new() -> Configuration { frequency_min: 863000000, frequency_max: 865000000, duty_cycle_permille_max: 1, - tx_power_max: 14, + tx_power_max_eirp: 14 + 2, }, Band { label: "L".into(), frequency_min: 865000000, frequency_max: 868000000, duty_cycle_permille_max: 10, - tx_power_max: 14, + tx_power_max_eirp: 14 + 2, }, Band { label: "M".into(), frequency_min: 868000000, frequency_max: 868600000, duty_cycle_permille_max: 10, - tx_power_max: 14, + tx_power_max_eirp: 14 + 2, }, Band { label: "N".into(), frequency_min: 868700000, frequency_max: 869200000, duty_cycle_permille_max: 1, - tx_power_max: 14, + tx_power_max_eirp: 14 + 2, }, Band { label: "P".into(), frequency_min: 869400000, frequency_max: 869650000, duty_cycle_permille_max: 100, - tx_power_max: 27, + tx_power_max_eirp: 27 + 2, }, Band { label: "P".into(), frequency_min: 869700000, frequency_max: 870000000, duty_cycle_permille_max: 1000, - tx_power_max: 7, + tx_power_max_eirp: 7 + 2, }, Band { label: "Q".into(), frequency_min: 869700000, frequency_max: 870000000, duty_cycle_permille_max: 10, - tx_power_max: 14, + tx_power_max_eirp: 14 + 2, }, ], window_time: Duration::from_secs(60 * 60), diff --git a/libconcentratord/src/regulation/standard/mod.rs b/libconcentratord/src/regulation/standard/mod.rs index 15d0286a..c41e1f16 100644 --- a/libconcentratord/src/regulation/standard/mod.rs +++ b/libconcentratord/src/regulation/standard/mod.rs @@ -27,7 +27,7 @@ pub struct Band { pub frequency_min: u32, pub frequency_max: u32, pub duty_cycle_permille_max: u32, - pub tx_power_max: i8, + pub tx_power_max_eirp: i8, } impl fmt::Display for Band { @@ -56,15 +56,17 @@ impl Configuration { } } - pub fn get_band(&self, tx_freq: u32, tx_power: i8) -> Result { + pub fn get_band(&self, tx_freq: u32, tx_power_eirp: i8) -> Result { for b in &self.bands { - if b.frequency_min <= tx_freq && tx_freq < b.frequency_max && tx_power <= b.tx_power_max + if b.frequency_min <= tx_freq + && tx_freq < b.frequency_max + && tx_power_eirp <= b.tx_power_max_eirp { return Ok(b.clone()); } } - Err(Error::BandNotFound(tx_freq, tx_power)) + Err(Error::BandNotFound(tx_freq, tx_power_eirp)) } pub fn get_regulation(&self) -> Regulation { @@ -87,20 +89,20 @@ mod test { struct Test { name: String, freq: u32, - tx_power: i8, + tx_power_eirp: i8, expected_band: Option, } let tests = vec![Test { name: "M band".into(), freq: 868100000, - tx_power: 14, + tx_power_eirp: 16, expected_band: Some(Band { label: "M".into(), frequency_min: 868000000, frequency_max: 868600000, duty_cycle_permille_max: 10, - tx_power_max: 14, + tx_power_max_eirp: 16, }), }]; @@ -108,7 +110,7 @@ mod test { for tst in &tests { println!("> {}", tst.name); - let res = c.get_band(tst.freq, tst.tx_power); + let res = c.get_band(tst.freq, tst.tx_power_eirp); if tst.expected_band.is_none() { assert!(res.is_err()); } else { diff --git a/libconcentratord/src/regulation/tracker.rs b/libconcentratord/src/regulation/tracker.rs index f1e186f5..a248ae8a 100644 --- a/libconcentratord/src/regulation/tracker.rs +++ b/libconcentratord/src/regulation/tracker.rs @@ -45,7 +45,7 @@ impl Tracker { } }; - info!("Item tracked, band: {}, freq: {}, tx_power: {}, start_counter_us: {}, end_counter_us: {}, duration: {:?}", band, tx_freq, tx_power, item.start_time.to_concentrator_count(), item.end_time.to_concentrator_count(), item.duration()); + info!("Item tracked, band: {}, freq: {}, tx_power_eirp: {}, start_counter_us: {}, end_counter_us: {}, duration: {:?}", band, tx_freq, tx_power, item.start_time.to_concentrator_count(), item.end_time.to_concentrator_count(), item.duration()); Ok(()) } @@ -81,7 +81,7 @@ mod test { struct Item { tx_freq: u32, - tx_power: i8, + tx_power_eirp: i8, start_time: Duration, end_time: Duration, } @@ -99,7 +99,7 @@ mod test { name: "K - 0.1%".into(), items: vec![Item { tx_freq: 863000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(0), end_time: Duration::from_millis(3600), }], @@ -109,7 +109,7 @@ mod test { name: "K - > 0.1%".into(), items: vec![Item { tx_freq: 863000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(0), end_time: Duration::from_millis(3601), }], @@ -119,7 +119,7 @@ mod test { name: "M - 1%".into(), items: vec![Item { tx_freq: 868000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(0), end_time: Duration::from_millis(36000), }], @@ -129,7 +129,7 @@ mod test { name: "M - >1%".into(), items: vec![Item { tx_freq: 868000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(0), end_time: Duration::from_millis(36001), }], @@ -140,13 +140,13 @@ mod test { items: vec![ Item { tx_freq: 865000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(0), end_time: Duration::from_millis(36000), }, Item { tx_freq: 868000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(36000), end_time: Duration::from_millis(72000), }, @@ -157,7 +157,7 @@ mod test { name: "Invalid freq".into(), items: vec![Item { tx_freq: 920000000, - tx_power: 14, + tx_power_eirp: 16, start_time: Duration::from_millis(0), end_time: Duration::from_millis(1), }], @@ -167,7 +167,7 @@ mod test { name: "K - invalid tx_power".into(), items: vec![Item { tx_freq: 863000000, - tx_power: 15, + tx_power_eirp: 17, start_time: Duration::from_millis(0), end_time: Duration::from_millis(3600), }], @@ -177,7 +177,7 @@ mod test { name: "K - lower tx_power (valid)".into(), items: vec![Item { tx_freq: 863000000, - tx_power: 10, + tx_power_eirp: 12, start_time: Duration::from_millis(0), end_time: Duration::from_millis(3600), }], @@ -194,7 +194,7 @@ mod test { tracker .try_insert( item.tx_freq, - item.tx_power, + item.tx_power_eirp, dutycycle::Item { start_time: item.start_time, end_time: item.end_time