Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lua/DCS-gRPC/exporters/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ GRPC.exporters.position = function(pos)
end

GRPC.exporters.unit = function(unit)
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(),
Expand All @@ -27,6 +31,7 @@ GRPC.exporters.unit = function(unit)
group = GRPC.exporters.group(Unit.getGroup(unit)),
numberInGroup = unit:getNumber(),
rawTransform = GRPC.exporters.rawTransform(unit),
agl = alt,
}
end

Expand Down
16 changes: 16 additions & 0 deletions lua/DCS-gRPC/methods/unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions protos/dcs/common/v0/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions protos/dcs/unit/v0/unit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -115,4 +117,12 @@ message DestroyRequest {
}

message DestroyResponse {
}

message GetAglRequest {
string name = 1;
}

message GetAglResponse {
double agl = 1;
}
11 changes: 6 additions & 5 deletions src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
1 change: 1 addition & 0 deletions src/rpc/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<custom::v0::GetMagneticDeclinationRequest>,
Expand Down
8 changes: 8 additions & 0 deletions src/rpc/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<unit::v0::GetAglRequest>,
) -> Result<Response<unit::v0::GetAglResponse>, Status> {
let res = self.request("getUnitAgl", request).await?;
Ok(Response::new(res))
}
}
13 changes: 12 additions & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{GetAglRequest, GetAglResponse, GetTransformRequest, GetTransformResponse};
use tokio::sync::mpsc::Sender;
use tokio::sync::mpsc::error::SendError;
use tokio::time::MissedTickBehavior;
Expand Down Expand Up @@ -309,6 +309,17 @@ 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) {
Expand Down
3 changes: 3 additions & 0 deletions stubs/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub mod v0 {
group: Option<Group>,
number_in_group: u32,
raw_transform: Option<RawTransform>,
agl: f64,
}

impl From<UnitIntermediate> for Unit {
Expand All @@ -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 {
Expand All @@ -119,6 +121,7 @@ pub mod v0 {
player_name,
group,
number_in_group,
agl,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion stubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ mod tests {
"coalition": 3,
"type": "FA-18C_hornet",
"playerName": "New callsign",
"numberInGroup": 1
"numberInGroup": 1,
"agl": 0.0
}
}
},
Expand Down Expand Up @@ -111,6 +112,7 @@ mod tests {
speed: Default::default(),
velocity: Some(Default::default())
}),
agl: 0.0,
}))
}),
visibility: Some(event::mark_add_event::Visibility::Coalition(
Expand Down
Loading