Initial commit.

This commit is contained in:
Orne Brocaar
2022-04-06 21:18:32 +01:00
commit 96fe672fc7
709 changed files with 335482 additions and 0 deletions

3
api/rust/src/api.rs Normal file
View File

@ -0,0 +1,3 @@
tonic::include_proto!("api/api");
pub const DESCRIPTOR: &[u8] = tonic::include_file_descriptor_set!("api/proto_descriptor");

145
api/rust/src/common.rs Normal file
View File

@ -0,0 +1,145 @@
use std::error::Error;
use std::fmt;
use std::str::FromStr;
tonic::include_proto!("common/common");
include!(concat!(env!("OUT_DIR"), "/common/common.serde.rs"));
#[allow(clippy::from_over_into)]
impl Into<String> for MType {
fn into(self) -> String {
match self {
MType::JoinRequest => "JoinRequest",
MType::JoinAccept => "JoinAccept",
MType::UnconfirmedDataUp => "UnconfirmedDataUp",
MType::UnconfirmedDataDown => "UnconfirmedDataDown",
MType::ConfirmedDataUp => "ConfirmedDataUp",
MType::ConfirmedDataDown => "ConfirmedDataDown",
MType::RejoinRequest => "RejoinRequest",
MType::Proprietary => "Proprietary",
}
.to_string()
}
}
#[allow(clippy::from_over_into)]
impl Into<String> for Region {
fn into(self) -> String {
match self {
Region::Eu868 => "EU868",
Region::Us915 => "US915",
Region::Cn779 => "CN779",
Region::Eu433 => "EU433",
Region::Au915 => "AU915",
Region::Cn470 => "CN470",
Region::As923 => "AS923",
Region::As9232 => "AS923_2",
Region::As9233 => "AS923_3",
Region::As9234 => "AS923_4",
Region::Kr920 => "KR920",
Region::In865 => "IN865",
Region::Ru864 => "RU864",
Region::Ism2400 => "ISM2400",
}
.to_string()
}
}
impl FromStr for Region {
type Err = Box<dyn Error>;
fn from_str(s: &str) -> Result<Self, Box<dyn Error>> {
Ok(match s {
"EU868" => Region::Eu868,
"US915" => Region::Us915,
"CN779" => Region::Cn779,
"EU433" => Region::Eu433,
"AU915" => Region::Au915,
"CN470" => Region::Cn470,
"AS923" => Region::As923,
"AS923_2" => Region::As9232,
"AS923_3" => Region::As9233,
"AS923_4" => Region::As9234,
"KR920" => Region::Kr920,
"IN865" => Region::In865,
"RU864" => Region::Ru864,
"ISM2400" => Region::Ism2400,
_ => {
return Err("invalid region".into());
}
})
}
}
#[allow(clippy::from_over_into)]
impl Into<String> for MacVersion {
fn into(self) -> String {
match self {
MacVersion::Lorawan100 => "1.0.0",
MacVersion::Lorawan101 => "1.0.1",
MacVersion::Lorawan102 => "1.0.2",
MacVersion::Lorawan103 => "1.0.3",
MacVersion::Lorawan104 => "1.0.4",
MacVersion::Lorawan110 => "1.1.0",
}
.to_string()
}
}
impl fmt::Display for MacVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: String = (*self).into();
write!(f, "{}", s)
}
}
impl FromStr for MacVersion {
type Err = Box<dyn Error>;
fn from_str(s: &str) -> Result<Self, Box<dyn Error>> {
Ok(match s {
"1.0.0" => MacVersion::Lorawan100,
"1.0.1" => MacVersion::Lorawan101,
"1.0.2" => MacVersion::Lorawan102,
"1.0.3" => MacVersion::Lorawan103,
"1.0.4" => MacVersion::Lorawan104,
"1.1.0" => MacVersion::Lorawan110,
_ => {
return Err("invalid mac-version".into());
}
})
}
}
#[allow(clippy::from_over_into)]
impl Into<String> for RegParamsRevision {
fn into(self) -> String {
match self {
RegParamsRevision::A => "A",
RegParamsRevision::B => "B",
RegParamsRevision::Rp002100 => "RP002_1.0.0",
RegParamsRevision::Rp002101 => "RP002_1.0.1",
RegParamsRevision::Rp002102 => "RP002_1.0.2",
RegParamsRevision::Rp002103 => "RP002_1.0.3",
}
.to_string()
}
}
impl FromStr for RegParamsRevision {
type Err = Box<dyn Error>;
fn from_str(s: &str) -> Result<Self, Box<dyn Error>> {
Ok(match s {
"A" => RegParamsRevision::A,
"B" => RegParamsRevision::B,
"RP002_1.0.0" => RegParamsRevision::Rp002100,
"RP002_1.0.1" => RegParamsRevision::Rp002101,
"RP002_1.0.2" => RegParamsRevision::Rp002102,
"RP002_1.0.3" => RegParamsRevision::Rp002103,
_ => {
return Err("invalid reg param revision".into());
}
})
}
}

22
api/rust/src/gw.rs Normal file
View File

@ -0,0 +1,22 @@
tonic::include_proto!("gw/gw");
include!(concat!(env!("OUT_DIR"), "/gw/gw.serde.rs"));
#[allow(clippy::from_over_into)]
impl Into<String> for TxAckStatus {
fn into(self) -> String {
match self {
TxAckStatus::Ignored => "IGNORED",
TxAckStatus::Ok => "OK",
TxAckStatus::TooLate => "TOO_LATE",
TxAckStatus::TooEarly => "TOO_EARLY",
TxAckStatus::CollisionPacket => "COLLISION_PACKET",
TxAckStatus::CollisionBeacon => "COLLISION_BEACON",
TxAckStatus::TxFreq => "TX_FREQ",
TxAckStatus::TxPower => "TX_POWER",
TxAckStatus::GpsUnlocked => "GPS_UNLOCKED",
TxAckStatus::QueueFull => "QUEUE_FULL",
TxAckStatus::InternalError => "INTERNAL_ERROR",
}
.to_string()
}
}

View File

@ -0,0 +1,35 @@
tonic::include_proto!("integration/integration");
include!(concat!(
env!("OUT_DIR"),
"/integration/integration.serde.rs"
));
#[allow(clippy::from_over_into)]
impl Into<String> for LogLevel {
fn into(self) -> String {
match self {
LogLevel::Info => "INFO",
LogLevel::Warning => "WARNING",
LogLevel::Error => "ERROR",
}
.to_string()
}
}
#[allow(clippy::from_over_into)]
impl Into<String> for LogCode {
fn into(self) -> String {
match self {
LogCode::Unknown => "UNKNOWN",
LogCode::DownlinkPayloadSize => "DOWNLINK_PAYLOAD_SIZE",
LogCode::UplinkCodec => "UPLINK_CODEC",
LogCode::DownlinkCodec => "DOWNLINK_CODEC",
LogCode::Otaa => "OTAA",
LogCode::UplinkFCntReset => "UPLINK_F_CNT_RESET",
LogCode::UplinkMic => "UPLINK_MIC",
LogCode::UplinkFCntRetransmission => "UPLINK_F_CNT_RETRANSMISSION",
LogCode::DownlinkGateway => "DOWNLINK_GATEWAY",
}
.to_string()
}
}

2
api/rust/src/internal.rs Normal file
View File

@ -0,0 +1,2 @@
tonic::include_proto!("internal/internal");
include!(concat!(env!("OUT_DIR"), "/internal/internal.serde.rs"));

8
api/rust/src/lib.rs Normal file
View File

@ -0,0 +1,8 @@
#[cfg(feature = "api")]
pub mod api;
pub mod common;
pub mod gw;
pub mod integration;
#[cfg(feature = "internal")]
pub mod internal;
pub mod meta;

2
api/rust/src/meta.rs Normal file
View File

@ -0,0 +1,2 @@
tonic::include_proto!("meta/meta");
include!(concat!(env!("OUT_DIR"), "/meta/meta.serde.rs"));