From 8e831a219829ba2c8f08331a87231249e54f6ab8 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 16 Jan 2025 12:13:29 +0000 Subject: [PATCH] Add app-layer params field to device-profile API. --- api/proto/api/device_profile.proto | 38 ++++++++++++ .../proto/chirpstack/api/device_profile.proto | 38 ++++++++++++ chirpstack/src/api/device_profile.rs | 16 +++++ chirpstack/src/api/helpers.rs | 61 ++++++++++++++++++- chirpstack/src/storage/fields/mod.rs | 2 +- 5 files changed, 151 insertions(+), 4 deletions(-) diff --git a/api/proto/api/device_profile.proto b/api/proto/api/device_profile.proto index 102dcc2c..3709fc05 100644 --- a/api/proto/api/device_profile.proto +++ b/api/proto/api/device_profile.proto @@ -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; diff --git a/api/rust/proto/chirpstack/api/device_profile.proto b/api/rust/proto/chirpstack/api/device_profile.proto index 102dcc2c..3709fc05 100644 --- a/api/rust/proto/chirpstack/api/device_profile.proto +++ b/api/rust/proto/chirpstack/api/device_profile.proto @@ -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; diff --git a/chirpstack/src/api/device_profile.rs b/chirpstack/src/api/device_profile.rs index fdf3013c..da94fe59 100644 --- a/chirpstack/src/api/device_profile.rs +++ b/chirpstack/src/api/device_profile.rs @@ -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 diff --git a/chirpstack/src/api/helpers.rs b/chirpstack/src/api/helpers.rs index 3164e0e8..6c66c438 100644 --- a/chirpstack/src/api/helpers.rs +++ b/chirpstack/src/api/helpers.rs @@ -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 { #[allow(clippy::wrong_self_convention)] fn from_proto(self) -> T; @@ -263,6 +264,60 @@ impl ToProto for DeviceClass { } } +impl ToProto for Option { + fn to_proto(self) -> api::Ts003Version { + match self { + None => api::Ts003Version::Ts003NotImplemented, + Some(fields::device_profile::Ts003Version::V100) => api::Ts003Version::Ts003V100, + } + } +} + +impl FromProto> for api::Ts003Version { + fn from_proto(self) -> Option { + match self { + api::Ts003Version::Ts003NotImplemented => None, + api::Ts003Version::Ts003V100 => Some(fields::device_profile::Ts003Version::V100), + } + } +} + +impl ToProto for Option { + fn to_proto(self) -> api::Ts004Version { + match self { + None => api::Ts004Version::Ts004NotImplemented, + Some(fields::device_profile::Ts004Version::V100) => api::Ts004Version::Ts004V100, + } + } +} + +impl FromProto> for api::Ts004Version { + fn from_proto(self) -> Option { + match self { + api::Ts004Version::Ts004NotImplemented => None, + api::Ts004Version::Ts004V100 => Some(fields::device_profile::Ts004Version::V100), + } + } +} + +impl ToProto for Option { + fn to_proto(self) -> api::Ts005Version { + match self { + None => api::Ts005Version::Ts005NotImplemented, + Some(fields::device_profile::Ts005Version::V100) => api::Ts005Version::Ts005V100, + } + } +} + +impl FromProto> for api::Ts005Version { + fn from_proto(self) -> Option { + match self { + api::Ts005Version::Ts005NotImplemented => None, + api::Ts005Version::Ts005V100 => Some(fields::device_profile::Ts005Version::V100), + } + } +} + pub fn datetime_to_prost_timestamp(dt: &DateTime) -> prost_types::Timestamp { let ts = dt.timestamp_nanos_opt().unwrap_or_default(); diff --git a/chirpstack/src/storage/fields/mod.rs b/chirpstack/src/storage/fields/mod.rs index 1db3dc58..d4e2dbb2 100644 --- a/chirpstack/src/storage/fields/mod.rs +++ b/chirpstack/src/storage/fields/mod.rs @@ -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;