Add app-layer params field to device-profile API.
Some checks failed
CI / tests (postgres) (push) Has been cancelled
CI / tests (sqlite) (push) Has been cancelled
CI / dist (postgres) (push) Has been cancelled
CI / dist (sqlite) (push) Has been cancelled

This commit is contained in:
Orne Brocaar 2025-01-16 12:13:29 +00:00
parent 9411cc94c1
commit 505d103de5
5 changed files with 151 additions and 4 deletions

View File

@ -98,6 +98,30 @@ enum RelayModeActivation {
END_DEVICE_CONTROLLED = 3;
}
enum Ts003Version {
// Not implemented.
TS003_NOT_IMPLEMENTED = 0;
// v1.0.0.
TS003_V100 = 1;
}
enum Ts004Version {
// Not implemented.
TS004_NOT_IMPLEMENTED = 0;
// v1.0.0.
TS004_V100 = 1;
}
enum Ts005Version {
// Not implemented.
TS005_NOT_IMPLEMENTED = 0;
// v1.0.0.
TS005_V100 = 1;
}
// DeviceProfileService is the service providing API methods for managing
// device-profiles.
service DeviceProfileService {
@ -421,6 +445,9 @@ message DeviceProfile {
// it.
// Valid options are 1 - 15 (0 = always use system RX1 Delay).
uint32 rx1_delay = 53;
// Application Layer parameters.
AppLayerParams app_layer_params = 54;
}
message Measurement {
@ -431,6 +458,17 @@ message Measurement {
MeasurementKind kind = 3;
}
message AppLayerParams {
// TS003 version (Application Layer Clock Sync).
Ts003Version ts003_version = 1;
// TS004 version (Fragmented Data Block Transport).
Ts004Version ts004_version = 2;
// TS005 version (Remote Multicast Setup).
Ts005Version ts005_version = 3;
}
message DeviceProfileListItem {
// Device-profile ID (UUID).
string id = 1;

View File

@ -98,6 +98,30 @@ enum RelayModeActivation {
END_DEVICE_CONTROLLED = 3;
}
enum Ts003Version {
// Not implemented.
TS003_NOT_IMPLEMENTED = 0;
// v1.0.0.
TS003_V100 = 1;
}
enum Ts004Version {
// Not implemented.
TS004_NOT_IMPLEMENTED = 0;
// v1.0.0.
TS004_V100 = 1;
}
enum Ts005Version {
// Not implemented.
TS005_NOT_IMPLEMENTED = 0;
// v1.0.0.
TS005_V100 = 1;
}
// DeviceProfileService is the service providing API methods for managing
// device-profiles.
service DeviceProfileService {
@ -421,6 +445,9 @@ message DeviceProfile {
// it.
// Valid options are 1 - 15 (0 = always use system RX1 Delay).
uint32 rx1_delay = 53;
// Application Layer parameters.
AppLayerParams app_layer_params = 54;
}
message Measurement {
@ -431,6 +458,17 @@ message Measurement {
MeasurementKind kind = 3;
}
message AppLayerParams {
// TS003 version (Application Layer Clock Sync).
Ts003Version ts003_version = 1;
// TS004 version (Fragmented Data Block Transport).
Ts004Version ts004_version = 2;
// TS005 version (Remote Multicast Setup).
Ts005Version ts005_version = 3;
}
message DeviceProfileListItem {
// Device-profile ID (UUID).
string id = 1;

View File

@ -140,6 +140,15 @@ impl DeviceProfileService for DeviceProfile {
} else {
None
},
app_layer_params: {
let app_layer_params = req_dp.app_layer_params.unwrap_or_default();
fields::AppLayerParams {
ts003_version: app_layer_params.ts003_version().from_proto(),
ts004_version: app_layer_params.ts004_version().from_proto(),
ts005_version: app_layer_params.ts005_version().from_proto(),
}
},
..Default::default()
};
@ -252,6 +261,11 @@ impl DeviceProfileService for DeviceProfile {
as u32,
allow_roaming: dp.allow_roaming,
rx1_delay: dp.rx1_delay as u32,
app_layer_params: Some(api::AppLayerParams {
ts003_version: dp.app_layer_params.ts003_version.to_proto().into(),
ts004_version: dp.app_layer_params.ts004_version.to_proto().into(),
ts005_version: dp.app_layer_params.ts005_version.to_proto().into(),
}),
}),
created_at: Some(helpers::datetime_to_prost_timestamp(&dp.created_at)),
updated_at: Some(helpers::datetime_to_prost_timestamp(&dp.updated_at)),
@ -568,6 +582,7 @@ pub mod test {
mac_version: common::MacVersion::Lorawan103.into(),
reg_params_revision: common::RegParamsRevision::A.into(),
adr_algorithm_id: "default".into(),
app_layer_params: Some(api::AppLayerParams::default()),
..Default::default()
}),
get_resp.get_ref().device_profile
@ -608,6 +623,7 @@ pub mod test {
mac_version: common::MacVersion::Lorawan103.into(),
reg_params_revision: common::RegParamsRevision::A.into(),
adr_algorithm_id: "default".into(),
app_layer_params: Some(api::AppLayerParams::default()),
..Default::default()
}),
get_resp.get_ref().device_profile

View File

@ -1,11 +1,12 @@
use chrono::{DateTime, Utc};
use crate::codec::Codec;
use crate::storage::fields::{MeasurementKind, MulticastGroupSchedulingType};
use crate::storage::{device::DeviceClass, metrics::Aggregation};
use chirpstack_api::{api, common};
use lrwn::region::{CommonName, MacVersion, Revision};
use crate::codec::Codec;
use crate::storage::fields::{self, MeasurementKind, MulticastGroupSchedulingType};
use crate::storage::{device::DeviceClass, metrics::Aggregation};
pub trait FromProto<T> {
#[allow(clippy::wrong_self_convention)]
fn from_proto(self) -> T;
@ -263,6 +264,60 @@ impl ToProto<common::DeviceClass> for DeviceClass {
}
}
impl ToProto<api::Ts003Version> for Option<fields::device_profile::Ts003Version> {
fn to_proto(self) -> api::Ts003Version {
match self {
None => api::Ts003Version::Ts003NotImplemented,
Some(fields::device_profile::Ts003Version::V100) => api::Ts003Version::Ts003V100,
}
}
}
impl FromProto<Option<fields::device_profile::Ts003Version>> for api::Ts003Version {
fn from_proto(self) -> Option<fields::device_profile::Ts003Version> {
match self {
api::Ts003Version::Ts003NotImplemented => None,
api::Ts003Version::Ts003V100 => Some(fields::device_profile::Ts003Version::V100),
}
}
}
impl ToProto<api::Ts004Version> for Option<fields::device_profile::Ts004Version> {
fn to_proto(self) -> api::Ts004Version {
match self {
None => api::Ts004Version::Ts004NotImplemented,
Some(fields::device_profile::Ts004Version::V100) => api::Ts004Version::Ts004V100,
}
}
}
impl FromProto<Option<fields::device_profile::Ts004Version>> for api::Ts004Version {
fn from_proto(self) -> Option<fields::device_profile::Ts004Version> {
match self {
api::Ts004Version::Ts004NotImplemented => None,
api::Ts004Version::Ts004V100 => Some(fields::device_profile::Ts004Version::V100),
}
}
}
impl ToProto<api::Ts005Version> for Option<fields::device_profile::Ts005Version> {
fn to_proto(self) -> api::Ts005Version {
match self {
None => api::Ts005Version::Ts005NotImplemented,
Some(fields::device_profile::Ts005Version::V100) => api::Ts005Version::Ts005V100,
}
}
}
impl FromProto<Option<fields::device_profile::Ts005Version>> for api::Ts005Version {
fn from_proto(self) -> Option<fields::device_profile::Ts005Version> {
match self {
api::Ts005Version::Ts005NotImplemented => None,
api::Ts005Version::Ts005V100 => Some(fields::device_profile::Ts005Version::V100),
}
}
}
pub fn datetime_to_prost_timestamp(dt: &DateTime<Utc>) -> prost_types::Timestamp {
let ts = dt.timestamp_nanos_opt().unwrap_or_default();

View File

@ -1,6 +1,6 @@
mod big_decimal;
mod dev_nonces;
mod device_profile;
pub mod device_profile;
mod device_session;
mod key_value;
mod measurements;