From 724db3b01551afff9e886c3636100787a4f4a28d Mon Sep 17 00:00:00 2001 From: mobot-gh Date: Fri, 19 Jan 2024 21:38:13 +0000 Subject: [PATCH 1/6] Add getUnitAgl rpc and update streamunits with same --- lua/DCS-gRPC/exporters/object.lua | 11 ++++++++++- lua/DCS-gRPC/methods/unit.lua | 16 ++++++++++++++++ protos/dcs/common/v0/common.proto | 2 ++ protos/dcs/unit/v0/unit.proto | 10 ++++++++++ src/rpc/unit.rs | 8 ++++++++ src/stream.rs | 15 ++++++++++++++- stubs/src/common.rs | 3 +++ stubs/src/lib.rs | 1 + 8 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lua/DCS-gRPC/exporters/object.lua b/lua/DCS-gRPC/exporters/object.lua index cc791e45..d080a373 100644 --- a/lua/DCS-gRPC/exporters/object.lua +++ b/lua/DCS-gRPC/exporters/object.lua @@ -17,6 +17,14 @@ GRPC.exporters.position = function(pos) end GRPC.exporters.unit = function(unit) + local locgroup = Unit.getGroup(unit) + if locgroup then + locgroup = GRPC.exporters.group(locgroup) + end + local pos = unit:getPoint() + local alt = pos.y + local land = land.getHeight({x = pos.x, y = pos.z}) or 0 + alt = alt - land return { id = tonumber(unit:getID()), name = unit:getName(), @@ -24,9 +32,10 @@ GRPC.exporters.unit = function(unit) coalition = unit:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum type = unit:getTypeName(), playerName = Unit.getPlayerName(unit), - group = GRPC.exporters.group(Unit.getGroup(unit)), + group = locgroup, numberInGroup = unit:getNumber(), rawTransform = GRPC.exporters.rawTransform(unit), + agl = alt, } end diff --git a/lua/DCS-gRPC/methods/unit.lua b/lua/DCS-gRPC/methods/unit.lua index f0bcb4ed..a6ac93e0 100644 --- a/lua/DCS-gRPC/methods/unit.lua +++ b/lua/DCS-gRPC/methods/unit.lua @@ -149,3 +149,19 @@ GRPC.methods.unitDestroy = function(params) unit:destroy() return GRPC.success({}) end + +GRPC.methods.getUnitAgl = function (params) + local unit = Unit.getByName(params.name) + if unit == nil then + return GRPC.errorNotFound("unit `" .. tostring(params.name) .. "` does not exist") + end + + local pos = unit:getPoint() + local asl = pos.y + local surfaceheight = land.getHeight({x = pos.x, y = pos.z}) or 0 + if surfaceheight < 0 then + surfaceheight = 0 + end + local agl = asl - surfaceheight + return GRPC.success({agl = agl}) +end \ No newline at end of file diff --git a/protos/dcs/common/v0/common.proto b/protos/dcs/common/v0/common.proto index c9e13f79..b4f21dde 100644 --- a/protos/dcs/common/v0/common.proto +++ b/protos/dcs/common/v0/common.proto @@ -236,6 +236,8 @@ message Unit { // The number of this unit in the group. Does not change as units are // destroyed uint32 number_in_group = 11; + // Altitude of unit above ground level + double agl = 12; } /** diff --git a/protos/dcs/unit/v0/unit.proto b/protos/dcs/unit/v0/unit.proto index 75ef9bdc..310521d0 100644 --- a/protos/dcs/unit/v0/unit.proto +++ b/protos/dcs/unit/v0/unit.proto @@ -34,6 +34,8 @@ service UnitService { // https://wiki.hoggitworld.com/view/DCS_func_getDrawArgumentValue rpc GetDrawArgumentValue(GetDrawArgumentValueRequest) returns (GetDrawArgumentValueResponse) {} + + rpc GetAgl(GetAglRequest) returns (GetAglResponse) {} } message GetRadarRequest { @@ -115,4 +117,12 @@ message DestroyRequest { } message DestroyResponse { +} + +message GetAglRequest { + string name = 1; +} + +message GetAglResponse { + double agl = 1; } \ No newline at end of file diff --git a/src/rpc/unit.rs b/src/rpc/unit.rs index 13521f66..cf064d36 100644 --- a/src/rpc/unit.rs +++ b/src/rpc/unit.rs @@ -77,4 +77,12 @@ impl UnitService for MissionRpc { let res = self.request("unitDestroy", request).await?; Ok(Response::new(res)) } + + async fn get_agl( + &self, + request: Request, + ) -> Result, Status> { + let res = self.request("getUnitAgl", request).await?; + Ok(Response::new(res)) + } } diff --git a/src/stream.rs b/src/stream.rs index bb60f0d2..f303e32d 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -13,7 +13,7 @@ use stubs::mission::v0::stream_events_response::{BirthEvent, DeadEvent, Event}; use stubs::mission::v0::stream_units_response::{UnitGone, Update}; use stubs::mission::v0::{StreamUnitsRequest, StreamUnitsResponse}; use stubs::unit::v0::unit_service_server::UnitService; -use stubs::unit::v0::{GetTransformRequest, GetTransformResponse}; +use stubs::unit::v0::{GetTransformRequest, GetTransformResponse, GetAglRequest, GetAglResponse}; use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::error::SendError; use tokio::time::MissedTickBehavior; @@ -309,6 +309,19 @@ impl UnitState { velocity, } = res.into_inner(); + let res = UnitService::get_agl( + &ctx.rpc, + Request::new(GetAglRequest { + name: self.unit.name.clone(), + }), + ) + .await?; + let GetAglResponse { + agl + } = res.into_inner(); + + self.unit.agl = agl; + self.update_time = time; if let Some((before, after)) = self.unit.position.as_mut().zip(position) { diff --git a/stubs/src/common.rs b/stubs/src/common.rs index 89577558..07544801 100644 --- a/stubs/src/common.rs +++ b/stubs/src/common.rs @@ -91,6 +91,7 @@ pub mod v0 { group: Option, number_in_group: u32, raw_transform: Option, + agl: f64, } impl From for Unit { @@ -105,6 +106,7 @@ pub mod v0 { group, number_in_group, raw_transform, + agl } = i; let transform = Transform::from(raw_transform.unwrap_or_default()); Unit { @@ -119,6 +121,7 @@ pub mod v0 { player_name, group, number_in_group, + agl, } } } diff --git a/stubs/src/lib.rs b/stubs/src/lib.rs index 03e65040..b587865e 100644 --- a/stubs/src/lib.rs +++ b/stubs/src/lib.rs @@ -111,6 +111,7 @@ mod tests { speed: Default::default(), velocity: Some(Default::default()) }), + agl: 0.0, })) }), visibility: Some(event::mark_add_event::Visibility::Coalition( From 83aa8431de5d471bce4d1d8b6a3104cd2307d6a7 Mon Sep 17 00:00:00 2001 From: mobot-gh Date: Tue, 5 May 2026 13:22:42 +0100 Subject: [PATCH 2/6] adjustments for linter --- src/authentication.rs | 11 ++++++----- src/rpc/custom.rs | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/authentication.rs b/src/authentication.rs index 5c37db9d..66299b4b 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -26,11 +26,12 @@ impl RequestInterceptor for AuthInterceptor { } } - if client.is_some() { - log::debug!("Authenticated client: {}", client.unwrap()); - Ok(req) - } else { - Err(Status::unauthenticated("Unauthenticated")) + match client { + Some(client_name) => { + log::debug!("Authenticated client: {}", client_name); + Ok(req) + } + _ => Err(Status::unauthenticated("Unauthenticated")), } } _ => Err(Status::unauthenticated("Unauthenticated")), diff --git a/src/rpc/custom.rs b/src/rpc/custom.rs index 336c3a61..1acfe7a2 100644 --- a/src/rpc/custom.rs +++ b/src/rpc/custom.rs @@ -52,6 +52,7 @@ impl CustomService for MissionRpc { Ok(Response::new(custom::v0::EvalResponse { json })) } + #[allow(clippy::result_large_err)] async fn get_magnetic_declination( &self, request: Request, From 4247a0872c89eddc7d3031d2650b13d82d939903 Mon Sep 17 00:00:00 2001 From: mobot-gh Date: Tue, 5 May 2026 20:21:41 +0100 Subject: [PATCH 3/6] fixup for test_enum_deserialization --- stubs/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/src/lib.rs b/stubs/src/lib.rs index b587865e..fdba881b 100644 --- a/stubs/src/lib.rs +++ b/stubs/src/lib.rs @@ -62,7 +62,8 @@ mod tests { "coalition": 3, "type": "FA-18C_hornet", "playerName": "New callsign", - "numberInGroup": 1 + "numberInGroup": 1, + "agl": 0.0 } } }, From 5ecb595629e73b659c1d15bfc5f500bb690d9ce1 Mon Sep 17 00:00:00 2001 From: mobot-gh Date: Tue, 5 May 2026 21:16:15 +0100 Subject: [PATCH 4/6] fixup formatting --- src/stream.rs | 6 ++---- stubs/src/common.rs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index f303e32d..dcc816b9 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -13,7 +13,7 @@ use stubs::mission::v0::stream_events_response::{BirthEvent, DeadEvent, Event}; use stubs::mission::v0::stream_units_response::{UnitGone, Update}; use stubs::mission::v0::{StreamUnitsRequest, StreamUnitsResponse}; use stubs::unit::v0::unit_service_server::UnitService; -use stubs::unit::v0::{GetTransformRequest, GetTransformResponse, GetAglRequest, GetAglResponse}; +use stubs::unit::v0::{GetAglRequest, GetAglResponse, GetTransformRequest, GetTransformResponse}; use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::error::SendError; use tokio::time::MissedTickBehavior; @@ -316,9 +316,7 @@ impl UnitState { }), ) .await?; - let GetAglResponse { - agl - } = res.into_inner(); + let GetAglResponse { agl } = res.into_inner(); self.unit.agl = agl; diff --git a/stubs/src/common.rs b/stubs/src/common.rs index 07544801..49a97a7f 100644 --- a/stubs/src/common.rs +++ b/stubs/src/common.rs @@ -106,7 +106,7 @@ pub mod v0 { group, number_in_group, raw_transform, - agl + agl, } = i; let transform = Transform::from(raw_transform.unwrap_or_default()); Unit { From 0f129dbd08bbbe7dad05c20d3bdf500cc73ead1e Mon Sep 17 00:00:00 2001 From: mobot-gh Date: Sat, 9 May 2026 10:23:14 +0100 Subject: [PATCH 5/6] fixup to avoid merge conflict --- lua/DCS-gRPC/exporters/object.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lua/DCS-gRPC/exporters/object.lua b/lua/DCS-gRPC/exporters/object.lua index d080a373..f3e284ef 100644 --- a/lua/DCS-gRPC/exporters/object.lua +++ b/lua/DCS-gRPC/exporters/object.lua @@ -17,10 +17,6 @@ GRPC.exporters.position = function(pos) end GRPC.exporters.unit = function(unit) - local locgroup = Unit.getGroup(unit) - if locgroup then - locgroup = GRPC.exporters.group(locgroup) - end local pos = unit:getPoint() local alt = pos.y local land = land.getHeight({x = pos.x, y = pos.z}) or 0 @@ -32,7 +28,7 @@ GRPC.exporters.unit = function(unit) coalition = unit:getCoalition() + 1, -- Increment for non zero-indexed gRPC enum type = unit:getTypeName(), playerName = Unit.getPlayerName(unit), - group = locgroup, + group = GRPC.exporters.group(Unit.getGroup(unit)), numberInGroup = unit:getNumber(), rawTransform = GRPC.exporters.rawTransform(unit), agl = alt, From 8c8a321b3049e07253228f926fe870e906df2d9d Mon Sep 17 00:00:00 2001 From: mobot-gh Date: Fri, 15 May 2026 12:34:34 +0100 Subject: [PATCH 6/6] add entry for CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be50302b..ca9c67ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Request uses `dcs.common.v0.ObjectCategory[]` and `SearchVolume` (with `InputPosition` for geo points). - Response returns `dcs.common.v0.Target[]` for consistent object union across services. - Lua implementation unwraps grpcui oneof wrapper (`volume.shape`) and supports both wrapped and flattened shapes. +- Added `UnitService.GetAgl` RPC and updated unit stream with same. ## [0.8.1] 2024-11-05