mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-04-29 15:39:40 +00:00
Cleanup clippy warnings.
This commit is contained in:
parent
4d665d3ded
commit
b187efe84c
@ -135,7 +135,7 @@ impl Handler for Algorithm {
|
|||||||
resp.dr = drs
|
resp.dr = drs
|
||||||
.choose(&mut rand::thread_rng())
|
.choose(&mut rand::thread_rng())
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(anyhow!("Random returned None"))?;
|
.ok_or_else(|| anyhow!("Random returned None"))?;
|
||||||
resp.nb_trans = 1; // 1 is the recommeded value
|
resp.nb_trans = 1; // 1 is the recommeded value
|
||||||
resp.tx_power_index = 0; // for now this ADR algorithm only controls the DR
|
resp.tx_power_index = 0; // for now this ADR algorithm only controls the DR
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ impl DeviceService for Device {
|
|||||||
let start = SystemTime::try_from(
|
let start = SystemTime::try_from(
|
||||||
req.start
|
req.start
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("start is None"))
|
.ok_or_else(|| anyhow!("start is None"))
|
||||||
.map_err(|e| e.status())?
|
.map_err(|e| e.status())?
|
||||||
.clone(),
|
.clone(),
|
||||||
)
|
)
|
||||||
@ -590,7 +590,7 @@ impl DeviceService for Device {
|
|||||||
let end = SystemTime::try_from(
|
let end = SystemTime::try_from(
|
||||||
req.end
|
req.end
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("end is None"))
|
.ok_or_else(|| anyhow!("end is None"))
|
||||||
.map_err(|e| e.status())?
|
.map_err(|e| e.status())?
|
||||||
.clone(),
|
.clone(),
|
||||||
)
|
)
|
||||||
@ -690,7 +690,7 @@ impl DeviceService for Device {
|
|||||||
let start = SystemTime::try_from(
|
let start = SystemTime::try_from(
|
||||||
req.start
|
req.start
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("start is None"))
|
.ok_or_else(|| anyhow!("start is None"))
|
||||||
.map_err(|e| e.status())?
|
.map_err(|e| e.status())?
|
||||||
.clone(),
|
.clone(),
|
||||||
)
|
)
|
||||||
@ -699,7 +699,7 @@ impl DeviceService for Device {
|
|||||||
let end = SystemTime::try_from(
|
let end = SystemTime::try_from(
|
||||||
req.end
|
req.end
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("end is None"))
|
.ok_or_else(|| anyhow!("end is None"))
|
||||||
.map_err(|e| e.status())?
|
.map_err(|e| e.status())?
|
||||||
.clone(),
|
.clone(),
|
||||||
)
|
)
|
||||||
|
@ -279,7 +279,7 @@ impl GatewayService for Gateway {
|
|||||||
let start = SystemTime::try_from(
|
let start = SystemTime::try_from(
|
||||||
req.start
|
req.start
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("start is None"))
|
.ok_or_else(|| anyhow!("start is None"))
|
||||||
.map_err(|e| e.status())?
|
.map_err(|e| e.status())?
|
||||||
.clone(),
|
.clone(),
|
||||||
)
|
)
|
||||||
@ -288,7 +288,7 @@ impl GatewayService for Gateway {
|
|||||||
let end = SystemTime::try_from(
|
let end = SystemTime::try_from(
|
||||||
req.end
|
req.end
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("end is None"))
|
.ok_or_else(|| anyhow!("end is None"))
|
||||||
.map_err(|e| e.status())?
|
.map_err(|e| e.status())?
|
||||||
.clone(),
|
.clone(),
|
||||||
)
|
)
|
||||||
|
@ -75,17 +75,6 @@ pub async fn callback_handler(args: CallbackArgs) -> Result<impl Reply, Rejectio
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_error<T: std::error::Error>(fail: &T, msg: &'static str) {
|
|
||||||
let mut err_msg = format!("ERROR: {}", msg);
|
|
||||||
let mut cur_fail: Option<&dyn std::error::Error> = Some(fail);
|
|
||||||
while let Some(cause) = cur_fail {
|
|
||||||
err_msg += &format!("\n caused by: {}", cause);
|
|
||||||
cur_fail = cause.source();
|
|
||||||
}
|
|
||||||
println!("{}", err_msg);
|
|
||||||
panic!("boom");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_user(code: &str, state: &str) -> Result<User> {
|
pub async fn get_user(code: &str, state: &str) -> Result<User> {
|
||||||
let state = CsrfToken::new(state.to_string());
|
let state = CsrfToken::new(state.to_string());
|
||||||
let nonce = get_nonce(&state).await?;
|
let nonce = get_nonce(&state).await?;
|
||||||
@ -94,11 +83,7 @@ pub async fn get_user(code: &str, state: &str) -> Result<User> {
|
|||||||
let token_response = client
|
let token_response = client
|
||||||
.exchange_code(AuthorizationCode::new(code.to_string()))
|
.exchange_code(AuthorizationCode::new(code.to_string()))
|
||||||
.request_async(async_http_client)
|
.request_async(async_http_client)
|
||||||
.await
|
.await?;
|
||||||
.unwrap_or_else(|err| {
|
|
||||||
handle_error(&err, "token extahcnage");
|
|
||||||
unreachable!();
|
|
||||||
});
|
|
||||||
|
|
||||||
let id_token_verifier: CoreIdTokenVerifier = client.id_token_verifier();
|
let id_token_verifier: CoreIdTokenVerifier = client.id_token_verifier();
|
||||||
let _id_token_claims: &CoreIdTokenClaims = token_response
|
let _id_token_claims: &CoreIdTokenClaims = token_response
|
||||||
|
@ -717,9 +717,9 @@ impl CayenneLpp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(prost_types::value::Kind::StructValue(s)) = &v.kind {
|
if let Some(prost_types::value::Kind::StructValue(s)) = &v.kind {
|
||||||
let x = s.fields.get("x").ok_or(anyhow!("x field is missing"))?;
|
let x = s.fields.get("x").ok_or_else(|| anyhow!("x field is missing"))?;
|
||||||
let y = s.fields.get("y").ok_or(anyhow!("y field is missing"))?;
|
let y = s.fields.get("y").ok_or_else(|| anyhow!("y field is missing"))?;
|
||||||
let z = s.fields.get("z").ok_or(anyhow!("z field is missing"))?;
|
let z = s.fields.get("z").ok_or_else(|| anyhow!("z field is missing"))?;
|
||||||
|
|
||||||
if let Some(prost_types::value::Kind::NumberValue(v)) = &x.kind {
|
if let Some(prost_types::value::Kind::NumberValue(v)) = &x.kind {
|
||||||
item.x = *v;
|
item.x = *v;
|
||||||
@ -789,9 +789,9 @@ impl CayenneLpp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(prost_types::value::Kind::StructValue(s)) = &v.kind {
|
if let Some(prost_types::value::Kind::StructValue(s)) = &v.kind {
|
||||||
let x = s.fields.get("x").ok_or(anyhow!("x field is missing"))?;
|
let x = s.fields.get("x").ok_or_else(|| anyhow!("x field is missing"))?;
|
||||||
let y = s.fields.get("y").ok_or(anyhow!("y field is missing"))?;
|
let y = s.fields.get("y").ok_or_else(|| anyhow!("y field is missing"))?;
|
||||||
let z = s.fields.get("z").ok_or(anyhow!("z field is missing"))?;
|
let z = s.fields.get("z").ok_or_else(|| anyhow!("z field is missing"))?;
|
||||||
|
|
||||||
if let Some(prost_types::value::Kind::NumberValue(v)) = &x.kind {
|
if let Some(prost_types::value::Kind::NumberValue(v)) = &x.kind {
|
||||||
item.x = *v;
|
item.x = *v;
|
||||||
@ -849,15 +849,15 @@ impl CayenneLpp {
|
|||||||
let lat = s
|
let lat = s
|
||||||
.fields
|
.fields
|
||||||
.get("latitude")
|
.get("latitude")
|
||||||
.ok_or(anyhow!("latitude field is missing"))?;
|
.ok_or_else(|| anyhow!("latitude field is missing"))?;
|
||||||
let lon = s
|
let lon = s
|
||||||
.fields
|
.fields
|
||||||
.get("longitude")
|
.get("longitude")
|
||||||
.ok_or(anyhow!("longitude field is missing"))?;
|
.ok_or_else(|| anyhow!("longitude field is missing"))?;
|
||||||
let alt = s
|
let alt = s
|
||||||
.fields
|
.fields
|
||||||
.get("altitude")
|
.get("altitude")
|
||||||
.ok_or(anyhow!("altitude field is missing"))?;
|
.ok_or_else(|| anyhow!("altitude field is missing"))?;
|
||||||
|
|
||||||
if let Some(prost_types::value::Kind::NumberValue(v)) = &lat.kind {
|
if let Some(prost_types::value::Kind::NumberValue(v)) = &lat.kind {
|
||||||
item.latitude = *v;
|
item.latitude = *v;
|
||||||
|
@ -44,11 +44,11 @@ impl Data {
|
|||||||
|
|
||||||
let region_name = uplink_rx_info[0]
|
let region_name = uplink_rx_info[0]
|
||||||
.get_metadata_string("region_name")
|
.get_metadata_string("region_name")
|
||||||
.ok_or(anyhow!("No region_name in metadata"))?;
|
.ok_or_else(|| anyhow!("No region_name in metadata"))?;
|
||||||
|
|
||||||
let region_common_name = uplink_rx_info[0]
|
let region_common_name = uplink_rx_info[0]
|
||||||
.get_metadata_string("region_common_name")
|
.get_metadata_string("region_common_name")
|
||||||
.ok_or(anyhow!("No region_common_name in metadata"))?;
|
.ok_or_else(|| anyhow!("No region_common_name in metadata"))?;
|
||||||
let region_common_name = CommonName::from_str(®ion_common_name)?;
|
let region_common_name = CommonName::from_str(®ion_common_name)?;
|
||||||
|
|
||||||
let mut ctx = Data {
|
let mut ctx = Data {
|
||||||
@ -78,7 +78,7 @@ impl Data {
|
|||||||
.uplink_rx_info
|
.uplink_rx_info
|
||||||
.first()
|
.first()
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(anyhow!("rx_info is empty"))?;
|
.ok_or_else(|| anyhow!("rx_info is empty"))?;
|
||||||
|
|
||||||
self.downlink_frame.gateway_id = rx_info.gateway_id.clone();
|
self.downlink_frame.gateway_id = rx_info.gateway_id.clone();
|
||||||
if self.dl_meta_data.dl_freq_1.is_some()
|
if self.dl_meta_data.dl_freq_1.is_some()
|
||||||
|
@ -77,7 +77,7 @@ impl Multicast {
|
|||||||
let region_name = &*(gw.properties)
|
let region_name = &*(gw.properties)
|
||||||
.get("region_name")
|
.get("region_name")
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(anyhow!("Gateway does not have region_name property"))?;
|
.ok_or_else(|| anyhow!("Gateway does not have region_name property"))?;
|
||||||
self.region_name = region_name.to_string();
|
self.region_name = region_name.to_string();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -126,7 +126,7 @@ impl TxAck {
|
|||||||
let gw_df = &df
|
let gw_df = &df
|
||||||
.downlink_frame
|
.downlink_frame
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("downlink_frame is None"))?;
|
.ok_or_else(|| anyhow!("downlink_frame is None"))?;
|
||||||
|
|
||||||
// Validate that we don't receive more ack items than downlink items that were
|
// Validate that we don't receive more ack items than downlink items that were
|
||||||
// sent to the gateway. Receiving less acks is valid, e.g. the gateway might
|
// sent to the gateway. Receiving less acks is valid, e.g. the gateway might
|
||||||
@ -384,7 +384,7 @@ impl TxAck {
|
|||||||
let gw_df = df
|
let gw_df = df
|
||||||
.downlink_frame
|
.downlink_frame
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("downlink_frame is None"))?;
|
.ok_or_else(|| anyhow!("downlink_frame is None"))?;
|
||||||
let dfi = self.downlink_frame_item.as_ref().unwrap();
|
let dfi = self.downlink_frame_item.as_ref().unwrap();
|
||||||
let phy = self.phy_payload.as_mut().unwrap();
|
let phy = self.phy_payload.as_mut().unwrap();
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ impl Integration {
|
|||||||
let client = aws_sdk_sns::Client::new(&config);
|
let client = aws_sdk_sns::Client::new(&config);
|
||||||
|
|
||||||
Ok(Integration {
|
Ok(Integration {
|
||||||
json: match Encoding::from_i32(conf.encoding).ok_or(anyhow!("Invalid encoding"))? {
|
json: match Encoding::from_i32(conf.encoding).ok_or_else(|| anyhow!("Invalid encoding"))? {
|
||||||
Encoding::Json => true,
|
Encoding::Json => true,
|
||||||
Encoding::Protobuf => false,
|
Encoding::Protobuf => false,
|
||||||
},
|
},
|
||||||
|
@ -32,7 +32,7 @@ impl Integration {
|
|||||||
|
|
||||||
Ok(Integration {
|
Ok(Integration {
|
||||||
timeout: Duration::from_secs(5),
|
timeout: Duration::from_secs(5),
|
||||||
json: match Encoding::from_i32(conf.encoding).ok_or(anyhow!("Invalid encoding"))? {
|
json: match Encoding::from_i32(conf.encoding).ok_or_else(|| anyhow!("Invalid encoding"))? {
|
||||||
Encoding::Json => true,
|
Encoding::Json => true,
|
||||||
Encoding::Protobuf => false,
|
Encoding::Protobuf => false,
|
||||||
},
|
},
|
||||||
|
@ -48,7 +48,7 @@ impl Integration {
|
|||||||
let auth_manager = AuthenticationManager::from(service_account);
|
let auth_manager = AuthenticationManager::from(service_account);
|
||||||
|
|
||||||
Ok(Integration {
|
Ok(Integration {
|
||||||
json: match Encoding::from_i32(conf.encoding).ok_or(anyhow!("Invalid encoding"))? {
|
json: match Encoding::from_i32(conf.encoding).ok_or_else(|| anyhow!("Invalid encoding"))? {
|
||||||
Encoding::Json => true,
|
Encoding::Json => true,
|
||||||
Encoding::Protobuf => false,
|
Encoding::Protobuf => false,
|
||||||
},
|
},
|
||||||
|
@ -38,13 +38,13 @@ impl Integration {
|
|||||||
Ok(Integration {
|
Ok(Integration {
|
||||||
timeout: Duration::from_secs(5),
|
timeout: Duration::from_secs(5),
|
||||||
endpoint: conf.endpoint.clone(),
|
endpoint: conf.endpoint.clone(),
|
||||||
version: InfluxDbVersion::from_i32(conf.version).ok_or(anyhow!("Invalid version"))?,
|
version: InfluxDbVersion::from_i32(conf.version).ok_or_else(|| anyhow!("Invalid version"))?,
|
||||||
db: conf.db.clone(),
|
db: conf.db.clone(),
|
||||||
username: conf.username.clone(),
|
username: conf.username.clone(),
|
||||||
password: conf.password.clone(),
|
password: conf.password.clone(),
|
||||||
retention_policy_name: conf.retention_policy_name.clone(),
|
retention_policy_name: conf.retention_policy_name.clone(),
|
||||||
precision: match InfluxDbPrecision::from_i32(conf.precision)
|
precision: match InfluxDbPrecision::from_i32(conf.precision)
|
||||||
.ok_or(anyhow!("Invalid precision"))?
|
.ok_or_else(|| anyhow!("Invalid precision"))?
|
||||||
{
|
{
|
||||||
InfluxDbPrecision::Ns => "ns",
|
InfluxDbPrecision::Ns => "ns",
|
||||||
InfluxDbPrecision::U => "u",
|
InfluxDbPrecision::U => "u",
|
||||||
|
@ -201,7 +201,7 @@ pub async fn uplink_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -226,7 +226,7 @@ pub async fn join_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -251,7 +251,7 @@ pub async fn ack_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -276,7 +276,7 @@ pub async fn txack_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -301,7 +301,7 @@ pub async fn log_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -326,7 +326,7 @@ pub async fn status_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -351,7 +351,7 @@ pub async fn location_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -376,7 +376,7 @@ pub async fn integration_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in join_all(futures).await {
|
for e in join_all(futures).await {
|
||||||
let _ = e?;
|
e?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -423,7 +423,7 @@ async fn handle_down_command(application_id: String, pl: integration::DownlinkCo
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = device_queue::enqueue_item(qi).await?;
|
device_queue::enqueue_item(qi).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "up")?;
|
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "up")?;
|
||||||
let b = match self.json {
|
let b = match self.json {
|
||||||
@ -221,7 +221,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "join")?;
|
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "join")?;
|
||||||
let b = match self.json {
|
let b = match self.json {
|
||||||
@ -240,7 +240,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "ack")?;
|
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "ack")?;
|
||||||
let b = match self.json {
|
let b = match self.json {
|
||||||
@ -259,7 +259,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "txack")?;
|
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "txack")?;
|
||||||
let b = match self.json {
|
let b = match self.json {
|
||||||
@ -278,7 +278,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "log")?;
|
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "log")?;
|
||||||
let b = match self.json {
|
let b = match self.json {
|
||||||
@ -297,7 +297,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "status")?;
|
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "status")?;
|
||||||
let b = match self.json {
|
let b = match self.json {
|
||||||
@ -316,7 +316,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic =
|
let topic =
|
||||||
self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "location")?;
|
self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "location")?;
|
||||||
@ -336,7 +336,7 @@ impl IntegrationTrait for Integration<'_> {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
|
|
||||||
let topic =
|
let topic =
|
||||||
self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "integration")?;
|
self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "integration")?;
|
||||||
|
@ -28,7 +28,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("up", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("up", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("join", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("join", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("ack", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("ack", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("txack", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("txack", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("log", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("log", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("status", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("status", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("location", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("location", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ impl IntegrationTrait for Integration {
|
|||||||
let dev_info = pl
|
let dev_info = pl
|
||||||
.device_info
|
.device_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("device_info is None"))?;
|
.ok_or_else(|| anyhow!("device_info is None"))?;
|
||||||
let b = pl.encode_to_vec();
|
let b = pl.encode_to_vec();
|
||||||
eventlog::log_event_for_device("integration", &dev_info.dev_eui, &b).await
|
eventlog::log_event_for_device("integration", &dev_info.dev_eui, &b).await
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ pub async fn handle(
|
|||||||
dev: &device::Device,
|
dev: &device::Device,
|
||||||
block: &lrwn::MACCommandSet,
|
block: &lrwn::MACCommandSet,
|
||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let mac = (&**block).first().ok_or(anyhow!("Expected DevStatusAns"))?;
|
let mac = (&**block).first().ok_or_else(|| anyhow!("Expected DevStatusAns"))?;
|
||||||
if let lrwn::MACCommand::DevStatusAns(pl) = mac {
|
if let lrwn::MACCommand::DevStatusAns(pl) = mac {
|
||||||
info!(dev_eui = %dev.dev_eui, battery = pl.battery, margin = pl.margin, "DevStatusAns received");
|
info!(dev_eui = %dev.dev_eui, battery = pl.battery, margin = pl.margin, "DevStatusAns received");
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ pub async fn handle(
|
|||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let mac = (&**block)
|
let mac = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("Expected DeviceModeInd"))?;
|
.ok_or_else(|| anyhow!("Expected DeviceModeInd"))?;
|
||||||
if let lrwn::MACCommand::DeviceModeInd(pl) = mac {
|
if let lrwn::MACCommand::DeviceModeInd(pl) = mac {
|
||||||
device::set_enabled_class(&dev.dev_eui, &pl.class.to_string()).await?;
|
device::set_enabled_class(&dev.dev_eui, &pl.class.to_string()).await?;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub fn handle(
|
|||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let _ = (&**block)
|
let _ = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("Expected DeviceTimeReq"))?;
|
.ok_or_else(|| anyhow!("Expected DeviceTimeReq"))?;
|
||||||
|
|
||||||
let rx_time: DateTime<Utc> = helpers::get_rx_timestamp(&uplink_frame_set.rx_info_set).into();
|
let rx_time: DateTime<Utc> = helpers::get_rx_timestamp(&uplink_frame_set.rx_info_set).into();
|
||||||
let gps_time = rx_time.to_gps_time();
|
let gps_time = rx_time.to_gps_time();
|
||||||
|
@ -11,7 +11,7 @@ pub fn handle(
|
|||||||
dev: &device::Device,
|
dev: &device::Device,
|
||||||
block: &lrwn::MACCommandSet,
|
block: &lrwn::MACCommandSet,
|
||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let _ = (&**block).first().ok_or(anyhow!("Expected LinkCheckReq"));
|
let _ = (&**block).first().ok_or_else(|| anyhow!("Expected LinkCheckReq"));
|
||||||
|
|
||||||
info!(dev_eui = %dev.dev_eui, "Received LinkCheckReq");
|
info!(dev_eui = %dev.dev_eui, "Received LinkCheckReq");
|
||||||
|
|
||||||
@ -19,11 +19,11 @@ pub fn handle(
|
|||||||
.tx_info
|
.tx_info
|
||||||
.modulation
|
.modulation
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("modulation can not be None"))?;
|
.ok_or_else(|| anyhow!("modulation can not be None"))?;
|
||||||
let mod_params = mod_info
|
let mod_params = mod_info
|
||||||
.parameters
|
.parameters
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("parameters can not be None"))?;
|
.ok_or_else(|| anyhow!("parameters can not be None"))?;
|
||||||
|
|
||||||
if let gw::modulation::Parameters::Lora(pl) = mod_params {
|
if let gw::modulation::Parameters::Lora(pl) = mod_params {
|
||||||
let required_snr = config::get_required_snr_for_sf(pl.spreading_factor as u8)?;
|
let required_snr = config::get_required_snr_for_sf(pl.spreading_factor as u8)?;
|
||||||
|
@ -24,7 +24,7 @@ pub fn handle(
|
|||||||
let pending_macs = &**pending.unwrap();
|
let pending_macs = &**pending.unwrap();
|
||||||
|
|
||||||
let req_pl = if let lrwn::MACCommand::PingSlotChannelReq(pl) =
|
let req_pl = if let lrwn::MACCommand::PingSlotChannelReq(pl) =
|
||||||
pending_macs.first().ok_or(anyhow!("Empty MACCommandSet"))?
|
pending_macs.first().ok_or_else(|| anyhow!("Empty MACCommandSet"))?
|
||||||
{
|
{
|
||||||
pl
|
pl
|
||||||
} else {
|
} else {
|
||||||
@ -32,7 +32,7 @@ pub fn handle(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let ans_pl = if let lrwn::MACCommand::PingSlotChannelAns(pl) =
|
let ans_pl = if let lrwn::MACCommand::PingSlotChannelAns(pl) =
|
||||||
block_macs.first().ok_or(anyhow!("Empty MACCommandSet"))?
|
block_macs.first().ok_or_else(|| anyhow!("Empty MACCommandSet"))?
|
||||||
{
|
{
|
||||||
pl
|
pl
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,7 +11,7 @@ pub fn handle(
|
|||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let mac = (&**block)
|
let mac = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
|
|
||||||
let pl = if let lrwn::MACCommand::PingSlotInfoReq(pl) = &mac {
|
let pl = if let lrwn::MACCommand::PingSlotInfoReq(pl) = &mac {
|
||||||
pl
|
pl
|
||||||
|
@ -25,10 +25,10 @@ pub fn handle(
|
|||||||
|
|
||||||
let ans_mac = (&**block)
|
let ans_mac = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
let req_mac = (&**pending.unwrap())
|
let req_mac = (&**pending.unwrap())
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
|
|
||||||
let req_pl = if let lrwn::MACCommand::RejoinParamSetupReq(pl) = req_mac {
|
let req_pl = if let lrwn::MACCommand::RejoinParamSetupReq(pl) = req_mac {
|
||||||
pl
|
pl
|
||||||
|
@ -11,7 +11,7 @@ pub fn handle(
|
|||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let block_mac = (&**block)
|
let block_mac = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
|
|
||||||
let req_pl = if let lrwn::MACCommand::RekeyInd(pl) = block_mac {
|
let req_pl = if let lrwn::MACCommand::RekeyInd(pl) = block_mac {
|
||||||
pl
|
pl
|
||||||
|
@ -14,7 +14,7 @@ pub fn handle(
|
|||||||
) -> Result<Option<lrwn::MACCommandSet>> {
|
) -> Result<Option<lrwn::MACCommandSet>> {
|
||||||
let block_mac = (&**block)
|
let block_mac = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
let block_pl = if let lrwn::MACCommand::ResetInd(pl) = block_mac {
|
let block_pl = if let lrwn::MACCommand::ResetInd(pl) = block_mac {
|
||||||
pl
|
pl
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,10 +29,10 @@ pub fn handle(
|
|||||||
|
|
||||||
let req_mac = (&**pending.unwrap())
|
let req_mac = (&**pending.unwrap())
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
let ans_mac = (&**block)
|
let ans_mac = (&**block)
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
|
|
||||||
let req_pl = if let lrwn::MACCommand::RxParamSetupReq(pl) = req_mac {
|
let req_pl = if let lrwn::MACCommand::RxParamSetupReq(pl) = req_mac {
|
||||||
pl
|
pl
|
||||||
|
@ -22,7 +22,7 @@ pub fn handle(
|
|||||||
|
|
||||||
let req_mac = (&**pending.unwrap())
|
let req_mac = (&**pending.unwrap())
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
|
|
||||||
let req_pl = if let lrwn::MACCommand::RxTimingSetupReq(pl) = req_mac {
|
let req_pl = if let lrwn::MACCommand::RxTimingSetupReq(pl) = req_mac {
|
||||||
pl
|
pl
|
||||||
|
@ -40,7 +40,7 @@ pub fn handle(
|
|||||||
|
|
||||||
let req_mac = (&**pending.unwrap())
|
let req_mac = (&**pending.unwrap())
|
||||||
.first()
|
.first()
|
||||||
.ok_or(anyhow!("MACCommandSet is empty"))?;
|
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
|
||||||
|
|
||||||
let req_pl = if let lrwn::MACCommand::TxParamSetupReq(pl) = req_mac {
|
let req_pl = if let lrwn::MACCommand::TxParamSetupReq(pl) = req_mac {
|
||||||
pl
|
pl
|
||||||
|
@ -10,7 +10,7 @@ use super::error::Error;
|
|||||||
use super::schema::api_key;
|
use super::schema::api_key;
|
||||||
use super::{error, get_db_conn};
|
use super::{error, get_db_conn};
|
||||||
|
|
||||||
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug)]
|
#[derive(Queryable, Insertable, PartialEq, Debug)]
|
||||||
#[diesel(table_name = api_key)]
|
#[diesel(table_name = api_key)]
|
||||||
pub struct ApiKey {
|
pub struct ApiKey {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
@ -19,7 +19,7 @@ use super::error::Error;
|
|||||||
use super::get_db_conn;
|
use super::get_db_conn;
|
||||||
use super::schema::{application, application_integration};
|
use super::schema::{application, application_integration};
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Insertable, AsChangeset, PartialEq, Debug)]
|
#[derive(Clone, Queryable, Insertable, PartialEq, Debug)]
|
||||||
#[diesel(table_name = application)]
|
#[diesel(table_name = application)]
|
||||||
pub struct Application {
|
pub struct Application {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
@ -255,7 +255,7 @@ pub struct IftttConfiguration {
|
|||||||
pub uplink_values: [String; 2], // The first value is reserved for the DevEUI
|
pub uplink_values: [String; 2], // The first value is reserved for the DevEUI
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Insertable, AsChangeset, PartialEq, Debug)]
|
#[derive(Clone, Queryable, Insertable, PartialEq, Debug)]
|
||||||
#[diesel(table_name = application_integration)]
|
#[diesel(table_name = application_integration)]
|
||||||
pub struct Integration {
|
pub struct Integration {
|
||||||
pub application_id: Uuid,
|
pub application_id: Uuid,
|
||||||
|
@ -15,7 +15,7 @@ use super::schema::{application, device, device_profile, multicast_group_device,
|
|||||||
use super::{error::Error, fields, get_db_conn, get_redis_conn, redis_key};
|
use super::{error::Error, fields, get_db_conn, get_redis_conn, redis_key};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
||||||
#[derive(Queryable, QueryableByName, Insertable, AsChangeset, PartialEq, Debug, Clone)]
|
#[derive(Queryable, QueryableByName, Insertable, PartialEq, Debug, Clone)]
|
||||||
#[diesel(table_name = device)]
|
#[diesel(table_name = device)]
|
||||||
pub struct Device {
|
pub struct Device {
|
||||||
pub dev_eui: EUI64,
|
pub dev_eui: EUI64,
|
||||||
|
@ -16,7 +16,7 @@ use super::{error, fields, get_db_conn};
|
|||||||
use crate::codec::Codec;
|
use crate::codec::Codec;
|
||||||
use chirpstack_api::internal;
|
use chirpstack_api::internal;
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
|
#[derive(Clone, Queryable, Insertable, Debug, PartialEq)]
|
||||||
#[diesel(table_name = device_profile)]
|
#[diesel(table_name = device_profile)]
|
||||||
pub struct DeviceProfile {
|
pub struct DeviceProfile {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
@ -15,7 +15,7 @@ use super::schema::device_profile_template;
|
|||||||
use super::{error, fields, get_db_conn};
|
use super::{error, fields, get_db_conn};
|
||||||
use crate::codec::Codec;
|
use crate::codec::Codec;
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
|
#[derive(Clone, Queryable, Insertable, Debug, PartialEq)]
|
||||||
#[diesel(table_name = device_profile_template)]
|
#[diesel(table_name = device_profile_template)]
|
||||||
pub struct DeviceProfileTemplate {
|
pub struct DeviceProfileTemplate {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
@ -10,7 +10,7 @@ use super::get_db_conn;
|
|||||||
use super::schema::device_queue_item;
|
use super::schema::device_queue_item;
|
||||||
use lrwn::EUI64;
|
use lrwn::EUI64;
|
||||||
|
|
||||||
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug, Clone)]
|
#[derive(Queryable, Insertable, PartialEq, Debug, Clone)]
|
||||||
#[diesel(table_name = device_queue_item)]
|
#[diesel(table_name = device_queue_item)]
|
||||||
pub struct DeviceQueueItem {
|
pub struct DeviceQueueItem {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
@ -13,7 +13,7 @@ use lrwn::EUI64;
|
|||||||
use super::schema::{gateway, tenant};
|
use super::schema::{gateway, tenant};
|
||||||
use super::{error::Error, fields, get_db_conn};
|
use super::{error::Error, fields, get_db_conn};
|
||||||
|
|
||||||
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug)]
|
#[derive(Queryable, Insertable, PartialEq, Debug)]
|
||||||
#[diesel(table_name = gateway)]
|
#[diesel(table_name = gateway)]
|
||||||
pub struct Gateway {
|
pub struct Gateway {
|
||||||
pub gateway_id: EUI64,
|
pub gateway_id: EUI64,
|
||||||
|
@ -15,7 +15,7 @@ use super::schema::{device, multicast_group, multicast_group_device, multicast_g
|
|||||||
use crate::downlink::classb;
|
use crate::downlink::classb;
|
||||||
use crate::{config, gpstime::ToDateTime, gpstime::ToGpsTime};
|
use crate::{config, gpstime::ToDateTime, gpstime::ToGpsTime};
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
|
#[derive(Clone, Queryable, Insertable, Debug, PartialEq)]
|
||||||
#[diesel(table_name = multicast_group)]
|
#[diesel(table_name = multicast_group)]
|
||||||
pub struct MulticastGroup {
|
pub struct MulticastGroup {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
@ -10,7 +10,7 @@ use super::error::Error;
|
|||||||
use super::get_db_conn;
|
use super::get_db_conn;
|
||||||
use super::schema::{tenant, tenant_user, user};
|
use super::schema::{tenant, tenant_user, user};
|
||||||
|
|
||||||
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug, Clone)]
|
#[derive(Queryable, Insertable, PartialEq, Debug, Clone)]
|
||||||
#[diesel(table_name = tenant)]
|
#[diesel(table_name = tenant)]
|
||||||
pub struct Tenant {
|
pub struct Tenant {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
@ -16,7 +16,7 @@ use super::error::Error;
|
|||||||
use super::get_db_conn;
|
use super::get_db_conn;
|
||||||
use super::schema::user;
|
use super::schema::user;
|
||||||
|
|
||||||
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug, Clone)]
|
#[derive(Queryable, Insertable, PartialEq, Debug, Clone)]
|
||||||
#[diesel(table_name = user)]
|
#[diesel(table_name = user)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
@ -13,12 +13,12 @@ pub fn get_uplink_dr(region_name: &str, tx_info: &chirpstack_api::gw::UplinkTxIn
|
|||||||
let mod_info = tx_info
|
let mod_info = tx_info
|
||||||
.modulation
|
.modulation
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("modulation must not be None"))?;
|
.ok_or_else(|| anyhow!("modulation must not be None"))?;
|
||||||
|
|
||||||
let mod_params = mod_info
|
let mod_params = mod_info
|
||||||
.parameters
|
.parameters
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("parameters must not be None"))?;
|
.ok_or_else(|| anyhow!("parameters must not be None"))?;
|
||||||
|
|
||||||
let dr_modulation = match &mod_params {
|
let dr_modulation = match &mod_params {
|
||||||
chirpstack_api::gw::modulation::Parameters::Lora(v) => {
|
chirpstack_api::gw::modulation::Parameters::Lora(v) => {
|
||||||
|
@ -104,7 +104,7 @@ impl JoinRequest {
|
|||||||
ctx.set_pr_start_ans_payload()?;
|
ctx.set_pr_start_ans_payload()?;
|
||||||
|
|
||||||
ctx.pr_start_ans
|
ctx.pr_start_ans
|
||||||
.ok_or(anyhow!("PRStartAnsPayload is not set"))
|
.ok_or_else(|| anyhow!("PRStartAnsPayload is not set"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_join_request_payload(&mut self) -> Result<()> {
|
fn get_join_request_payload(&mut self) -> Result<()> {
|
||||||
|
@ -264,11 +264,11 @@ pub async fn handle_uplink(deduplication_id: Uuid, uplink: gw::UplinkFrameSet) -
|
|||||||
|
|
||||||
let region_name = rx_info
|
let region_name = rx_info
|
||||||
.get_metadata_string("region_name")
|
.get_metadata_string("region_name")
|
||||||
.ok_or(anyhow!("No region_name in metadata"))?;
|
.ok_or_else(|| anyhow!("No region_name in metadata"))?;
|
||||||
|
|
||||||
let common_name = rx_info
|
let common_name = rx_info
|
||||||
.get_metadata_string("region_common_name")
|
.get_metadata_string("region_common_name")
|
||||||
.ok_or(anyhow!("No region_common_name in metadata"))?;
|
.ok_or_else(|| anyhow!("No region_common_name in metadata"))?;
|
||||||
|
|
||||||
let common_name = CommonName::from_str(&common_name)?;
|
let common_name = CommonName::from_str(&common_name)?;
|
||||||
|
|
||||||
@ -354,18 +354,18 @@ fn filter_rx_info_by_tenant_id(tenant_id: &Uuid, uplink: &mut UplinkFrameSet) ->
|
|||||||
let gateway_id = EUI64::from_str(&rx_info.gateway_id)?;
|
let gateway_id = EUI64::from_str(&rx_info.gateway_id)?;
|
||||||
let region_name = rx_info
|
let region_name = rx_info
|
||||||
.get_metadata_string("region_name")
|
.get_metadata_string("region_name")
|
||||||
.ok_or(anyhow!("No region_name in rx_info metadata"))?;
|
.ok_or_else(|| anyhow!("No region_name in rx_info metadata"))?;
|
||||||
let force_gws_private = config::get_force_gws_private(®ion_name)?;
|
let force_gws_private = config::get_force_gws_private(®ion_name)?;
|
||||||
|
|
||||||
if !(*uplink
|
if !(*uplink
|
||||||
.gateway_private_map
|
.gateway_private_map
|
||||||
.get(&gateway_id)
|
.get(&gateway_id)
|
||||||
.ok_or(anyhow!("gateway_id missing in gateway_private_map"))?
|
.ok_or_else(|| anyhow!("gateway_id missing in gateway_private_map"))?
|
||||||
|| force_gws_private)
|
|| force_gws_private)
|
||||||
|| uplink
|
|| uplink
|
||||||
.gateway_tenant_id_map
|
.gateway_tenant_id_map
|
||||||
.get(&gateway_id)
|
.get(&gateway_id)
|
||||||
.ok_or(anyhow!("gateway_id is missing in gateway_tenant_id_map"))?
|
.ok_or_else(|| anyhow!("gateway_id is missing in gateway_tenant_id_map"))?
|
||||||
== tenant_id
|
== tenant_id
|
||||||
{
|
{
|
||||||
rx_info_set.push(rx_info.clone());
|
rx_info_set.push(rx_info.clone());
|
||||||
@ -388,7 +388,7 @@ fn filter_rx_info_by_public_only(uplink: &mut UplinkFrameSet) -> Result<()> {
|
|||||||
if !(*uplink
|
if !(*uplink
|
||||||
.gateway_private_map
|
.gateway_private_map
|
||||||
.get(&gateway_id)
|
.get(&gateway_id)
|
||||||
.ok_or(anyhow!("gateway_id missing in gateway_private_map"))?)
|
.ok_or_else(|| anyhow!("gateway_id missing in gateway_private_map"))?)
|
||||||
{
|
{
|
||||||
rx_info_set.push(rx_info.clone());
|
rx_info_set.push(rx_info.clone());
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl Stats {
|
|||||||
|
|
||||||
async fn _handle(gateway_id: EUI64, s: gw::GatewayStats) -> Result<()> {
|
async fn _handle(gateway_id: EUI64, s: gw::GatewayStats) -> Result<()> {
|
||||||
let mut ctx = Stats {
|
let mut ctx = Stats {
|
||||||
gateway_id: gateway_id,
|
gateway_id,
|
||||||
stats: s,
|
stats: s,
|
||||||
gateway: None,
|
gateway: None,
|
||||||
};
|
};
|
||||||
@ -96,7 +96,7 @@ impl Stats {
|
|||||||
.stats
|
.stats
|
||||||
.meta_data
|
.meta_data
|
||||||
.get("region_name")
|
.get("region_name")
|
||||||
.ok_or(anyhow!("No region_name in meta-data"))?;
|
.ok_or_else(|| anyhow!("No region_name in meta-data"))?;
|
||||||
|
|
||||||
let tx_per_dr =
|
let tx_per_dr =
|
||||||
per_modultation_to_per_dr(region_name, false, &self.stats.tx_packets_per_modulation)
|
per_modultation_to_per_dr(region_name, false, &self.stats.tx_packets_per_modulation)
|
||||||
@ -244,11 +244,11 @@ fn per_modultation_to_per_dr(
|
|||||||
let modu = item
|
let modu = item
|
||||||
.modulation
|
.modulation
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("modulation is None"))?;
|
.ok_or_else(|| anyhow!("modulation is None"))?;
|
||||||
let params = modu
|
let params = modu
|
||||||
.parameters
|
.parameters
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(anyhow!("parameters is None"))?;
|
.ok_or_else(|| anyhow!("parameters is None"))?;
|
||||||
|
|
||||||
let dr_modulation = match params {
|
let dr_modulation = match params {
|
||||||
gw::modulation::Parameters::Lora(v) => {
|
gw::modulation::Parameters::Lora(v) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user