Skip to content

Commit

Permalink
Migrate to ChirpStack v4 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Aug 3, 2022
1 parent c013f0c commit 039b0b0
Show file tree
Hide file tree
Showing 31 changed files with 1,089 additions and 1,070 deletions.
629 changes: 386 additions & 243 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Dockerfile-devel
@@ -1,13 +1,13 @@
FROM rust:1.45-stretch
FROM rust:1.62.1-buster

# required by bingen
RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
clang-3.9 \
libclang-3.9-dev \
llvm-3.9-dev \
clang \
libclang-dev \
llvm-dev \
gcc-arm-linux-gnueabi \
g++-arm-linux-gnueabi \
gcc-arm-linux-gnueabihf \
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Orne Brocaar
Copyright (c) 2022 Orne Brocaar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 3 additions & 6 deletions README.md
Expand Up @@ -10,13 +10,10 @@ in a separate daemon and exposing this over a ZeroMQ based API, the packet
forwarding application can be completely decoupled from the gateway hardware.
It also allows for running multiple packet forwarding applications simultaniously.

## Architecture
## Documentation

![architecture](https://www.chirpstack.io/static/img/graphs/architecture.dot.png)

## Links

* [Documentation](https://www.chirpstack.io/concentratord/)
Please refer to the [ChirpStack documentation](https://www.chirpstack.io/) for
more information.

## License

Expand Down
10 changes: 5 additions & 5 deletions chirpstack-concentratord-2g4/Cargo.toml
Expand Up @@ -2,15 +2,15 @@
name = "chirpstack-concentratord-2g4"
repository="https://github.com/brocaar/chirpstack-concentratord/"
license="MIT"
version = "3.3.3"
version = "4.0.0-test.1"
authors = ["Orne Brocaar <info@brocaar.com>"]
edition = "2018"
publish = false

[dependencies]
libloragw-2g4 = {path = "../libloragw-2g4"}
libconcentratord = {path = "../libconcentratord"}
chirpstack_api = { version = "3.10", default-features = false }
chirpstack_api = { version = "4.0.0-test.13", default-features = false }
serde = { version = "1.0", features = ["derive"] }
toml = "0.5"
clap = "2.33"
Expand All @@ -19,14 +19,14 @@ simple_logger = "1.11"
zmq = "0.9"
hex = "0.4"
lazy_static = "1.4"
uuid = { version = "0.8", features = ["v4"] }
chrono = "0.4"
humantime-serde = "1.0"
syslog = "5.0"
prost = "0.8"
prost-types = "0.8"
prost = "0.10"
pbjson-types = "0.3.2"
signal-hook = "0.3"
handlebars = "4.1"
rand = "0.8"

[features]
default = ['zmq/vendored']
20 changes: 5 additions & 15 deletions chirpstack-concentratord-2g4/src/handler/command.rs
Expand Up @@ -6,7 +6,6 @@ use libconcentratord::signals::Signal;
use libconcentratord::{commands, jitqueue, stats};
use libloragw_2g4::hal;
use prost::Message;
use uuid::Uuid;

use super::super::config::vendor;
use super::super::wrapper;
Expand Down Expand Up @@ -74,20 +73,11 @@ fn handle_downlink(
queue: &Arc<Mutex<jitqueue::Queue<wrapper::TxPacket>>>,
pl: &chirpstack_api::gw::DownlinkFrame,
) -> Result<Vec<u8>, ()> {
let id = match Uuid::from_slice(&pl.downlink_id) {
Ok(v) => v,
Err(err) => {
error!("Decode downlink_id error: {}", err);
return Err(());
}
};

stats::inc_tx_packets_received();

let mut tx_ack = chirpstack_api::gw::DownlinkTxAck {
gateway_id: gateway_id.to_vec(),
token: pl.token,
downlink_id: pl.downlink_id.to_vec(),
gateway_id: hex::encode(gateway_id),
downlink_id: pl.downlink_id,
items: vec![Default::default(); pl.items.len()],
..Default::default()
};
Expand All @@ -100,7 +90,7 @@ fn handle_downlink(
Err(error) => {
error!(
"Convert downlink protobuf to HAL struct error, downlink_id: {}, error: {}",
id, error,
pl.downlink_id, error,
);
return Err(());
}
Expand All @@ -109,7 +99,7 @@ fn handle_downlink(
// validate frequency range
let freqs = vendor_config.min_max_tx_freq;
if tx_packet.freq_hz < freqs.0 || tx_packet.freq_hz > freqs.1 {
error!("Frequency is not within min/max gateway frequency, downlink_id: {}, min_freq: {}, max_freq: {}", id, freqs.0, freqs.1);
error!("Frequency is not within min/max gateway frequency, downlink_id: {}, min_freq: {}, max_freq: {}", pl.downlink_id, freqs.0, freqs.1);
tx_ack.items[i].set_status(chirpstack_api::gw::TxAckStatus::TxFreq);

// try next
Expand All @@ -119,7 +109,7 @@ fn handle_downlink(
// try enqueue
match queue.lock().unwrap().enqueue(
hal::get_instcnt().expect("get concentrator count error"),
wrapper::TxPacket::new(id, tx_packet),
wrapper::TxPacket::new(pl.downlink_id, tx_packet),
) {
Ok(_) => {
tx_ack.items[i].set_status(chirpstack_api::gw::TxAckStatus::Ok);
Expand Down
16 changes: 8 additions & 8 deletions chirpstack-concentratord-2g4/src/handler/config.rs
Expand Up @@ -59,10 +59,10 @@ mod tests {
channels: vec![
chirpstack_api::gw::ChannelConfiguration{
frequency: 2403000000,
modulation: chirpstack_api::common::Modulation::Lora as i32,
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoRaModulationConfig{
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoraModulationConfig{
bandwidth: 812000,
spreading_factors: vec![12],
..Default::default()
})),
..Default::default()
},
Expand All @@ -86,28 +86,28 @@ mod tests {
channels: vec![
chirpstack_api::gw::ChannelConfiguration{
frequency: 2403000000,
modulation: chirpstack_api::common::Modulation::Lora as i32,
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoRaModulationConfig{
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoraModulationConfig{
bandwidth: 812000,
spreading_factors: vec![12],
..Default::default()
})),
..Default::default()
},
chirpstack_api::gw::ChannelConfiguration{
frequency: 2479000000,
modulation: chirpstack_api::common::Modulation::Lora as i32,
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoRaModulationConfig{
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoraModulationConfig{
bandwidth: 812000,
spreading_factors: vec![12],
..Default::default()
})),
..Default::default()
},
chirpstack_api::gw::ChannelConfiguration{
frequency: 2425000000,
modulation: chirpstack_api::common::Modulation::Lora as i32,
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoRaModulationConfig{
modulation_config: Some(chirpstack_api::gw::channel_configuration::ModulationConfig::LoraModulationConfig(chirpstack_api::gw::LoraModulationConfig{
bandwidth: 812000,
spreading_factors: vec![12],
..Default::default()
})),
..Default::default()
},
Expand Down
4 changes: 1 addition & 3 deletions chirpstack-concentratord-2g4/src/handler/uplink.rs
Expand Up @@ -5,7 +5,6 @@ use std::time::Duration;
use libconcentratord::signals::Signal;
use libconcentratord::{events, stats};
use libloragw_2g4::hal;
use uuid::Uuid;

use super::super::wrapper;

Expand Down Expand Up @@ -39,11 +38,10 @@ pub fn handle_loop(gateway_id: &[u8], stop_receive: Receiver<Signal>) {
};

let rx_info = proto.rx_info.as_ref().unwrap();
let uuid = Uuid::from_slice(&rx_info.uplink_id).unwrap();

info!(
"Frame received, uplink_id: {}, count_us: {}, freq: {}, bw: {}, mod: {:?}, dr: {:?}",
uuid,
rx_info.uplink_id,
frame.count_us,
frame.freq_hz,
frame.bandwidth,
Expand Down
1 change: 1 addition & 0 deletions chirpstack-concentratord-2g4/src/main.rs
Expand Up @@ -71,6 +71,7 @@ fn main() {
.unwrap();
} else {
SimpleLogger::new()
.with_utc_timestamps()
.with_level(
log::Level::from_str(&config.concentratord.log_level)
.unwrap()
Expand Down

0 comments on commit 039b0b0

Please sign in to comment.