Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes datarate errors debug only on decode #468

Merged
merged 3 commits into from Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/error.rs
Expand Up @@ -55,8 +55,10 @@ pub enum DecodeError {
Prost(#[from] prost::DecodeError),
#[error("lorawan decode: {0}")]
LoraWan(#[from] lorawan::LoraWanError),
#[error("packet crc")]
InvalidCrc,
#[error("crc is invalid and packet may be corrupted")]
CrcInvalid,
#[error("crc is disabled")]
CrcDisabled,
#[error("unexpected transaction in envelope")]
InvalidEnvelope,
#[error("no rx1 window in downlink packet")]
Expand Down Expand Up @@ -128,8 +130,12 @@ impl DecodeError {
Error::Decode(DecodeError::InvalidEnvelope)
}

pub fn invalid_crc() -> Error {
Error::Decode(DecodeError::InvalidCrc)
pub fn crc_invalid() -> Error {
Error::Decode(DecodeError::CrcInvalid)
}

pub fn crc_disabled() -> Error {
Error::Decode(DecodeError::CrcInvalid)
}

pub fn prost_decode(msg: &'static str) -> Error {
Expand Down
10 changes: 8 additions & 2 deletions src/gateway.rs
@@ -1,6 +1,6 @@
use crate::{
beaconer, packet, packet_router, region_watcher, sync, PacketDown, PacketUp, PublicKey,
RegionParams, Result, Settings,
beaconer, packet, packet_router, region_watcher, sync, DecodeError, Error, PacketDown,
PacketUp, PublicKey, RegionParams, Result, Settings,
};
use beacon::Beacon;
use lorawan::PHYPayload;
Expand Down Expand Up @@ -149,6 +149,12 @@ impl Gateway {
Ok(packet) => {
info!(%packet, "ignoring non-uplink packet");
}
Err(Error::Decode(DecodeError::CrcDisabled)) => {
debug!("ignoring packet with disabled crc");
}
Err(Error::Decode(DecodeError::InvalidDataRate(datarate))) => {
debug!(%datarate, "ignoring packet with invalid datarate");
}
Err(err) => {
warn!(%err, "ignoring push_data");
}
Expand Down
7 changes: 5 additions & 2 deletions src/packet.rs
Expand Up @@ -85,9 +85,12 @@ impl TryFrom<PacketUp> for poc_lora::LoraWitnessReportReqV1 {

impl PacketUp {
pub fn from_rxpk(rxpk: push_data::RxPk, gateway: &PublicKey, region: Region) -> Result<Self> {
if rxpk.get_crc_status() != &CRC::OK {
return Err(DecodeError::invalid_crc());
match rxpk.get_crc_status() {
CRC::OK => (),
CRC::Disabled => return Err(DecodeError::crc_disabled()),
CRC::Fail => return Err(DecodeError::crc_invalid()),
}

let rssi = rxpk
.get_signal_rssi()
.unwrap_or_else(|| rxpk.get_channel_rssi());
Expand Down