Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Nov 17, 2023
1 parent 990efd2 commit 1e54909
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 8 additions & 19 deletions mobile_verifier/src/cell_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum CellType {
pub enum CellTypeLabel {
CellTypeLabelNone = 0,
CBRS = 1,
Wifi = 2,
WifiIndoor = 2,
}

impl CellType {
Expand All @@ -51,7 +51,7 @@ impl CellType {
Self::SercommIndoor => CellTypeLabel::CBRS,
Self::SercommOutdoor => CellTypeLabel::CBRS,
Self::CellTypeNone => CellTypeLabel::CellTypeLabelNone,
Self::NovaGenericWifiIndoor => CellTypeLabel::Wifi,
Self::NovaGenericWifiIndoor => CellTypeLabel::WifiIndoor,
}
}

Expand Down Expand Up @@ -104,24 +104,13 @@ impl From<CellType> for CellTypeProto {
}
}

impl CellTypeLabel {
pub fn from_asserted(device_type: &String) -> Option<Self> {
match device_type {
device_type if device_type.eq("wifiIndoor") => Some(CellTypeLabel::Wifi),
device_type if device_type.eq("cbrs") => Some(CellTypeLabel::CBRS),
_ => None,
}
}
}

impl FromStr for CellTypeLabel {
type Err = ();
fn from_str(input: &str) -> Result<CellTypeLabel, Self::Err> {
match input {
"wifiIndoor" => Ok(CellTypeLabel::Wifi),
"cbrs" => Ok(CellTypeLabel::CBRS),
_ => Err(())
type Err = anyhow::Error;
fn from_str(s: &str) -> anyhow::Result<CellTypeLabel> {
match s {
"wifiIndoor" => Ok(CellTypeLabel::WifiIndoor),
"cbrs" => Ok(CellTypeLabel::CBRS),
_ => anyhow::bail!("unknown cell type"),
}
}
}

7 changes: 4 additions & 3 deletions mobile_verifier/src/heartbeats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use helium_proto::services::poc_mobile as proto;
use retainer::Cache;
use rust_decimal::{prelude::ToPrimitive, Decimal};
use sqlx::{postgres::PgTypeInfo, Decode, Encode, Postgres, Transaction, Type};
use std::str::FromStr;
use std::{ops::Range, pin::pin, time};
use uuid::Uuid;

Expand Down Expand Up @@ -247,7 +248,7 @@ impl HeartbeatReward {
.cbsd_id
.clone()
.ok_or_else(|| anyhow!("expected cbsd_id, found none"))?),
CellTypeLabel::Wifi => Ok(self.hotspot_key.to_string()),
CellTypeLabel::WifiIndoor => Ok(self.hotspot_key.to_string()),
_ => Err(anyhow!("failed to derive label from cell type")),
}
}
Expand Down Expand Up @@ -507,12 +508,12 @@ pub async fn validate_heartbeat(
GatewayResolution::GatewayAsserted(metadata) if heartbeat.hb_type == HbType::Wifi => {
// for wifi HBs, check the asserted device type matches that defined in the HB
let asserted_celltype_label = CellTypeLabel::from_str(&metadata.device_type)?;
if asserted_celltype_label == CellTypeLabel::Wifi
if asserted_celltype_label == CellTypeLabel::WifiIndoor
&& cell_type.to_label() != asserted_celltype_label
{
return Ok((cell_type, None, None, proto::HeartbeatValidity::BadCellType));
};
Some(heartbeat.asserted_distance(location)?)
Some(heartbeat.asserted_distance(metadata.location)?)
}
_ => None,
};
Expand Down

0 comments on commit 1e54909

Please sign in to comment.