Skip to content

Commit

Permalink
implement GetUnitPosition method
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Jul 9, 2021
1 parent dae5d61 commit 5ee21bd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lua/exporters/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ local function toLatLonPosition(pos)
}
end

GRPC.exporters.position = toLatLonPosition

GRPC.exporters.unit = function(unit)
return {
id = tonumber(unit:getID()),
name = unit:getName(),
callsign = unit:getCallsign(),
coalition = unit:getCoalition(),
type = unit:getTypeName(),
position = toLatLonPosition(unit:getPoint()),
playerName = unit:getPlayerName()
}
end
Expand Down
15 changes: 14 additions & 1 deletion lua/methods/unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ GRPC.methods.getRadar = function(params)
active = active,
target = grpcTable
})
end
end

GRPC.methods.getUnitPosition = function(params)
-- https://wiki.hoggitworld.com/view/DCS_func_getByName
local unit = Unit.getByName(params.name)
if unit == nil then
return GRPC.errorNotFound("unit does not exist")
end

return GRPC.success({
-- https://wiki.hoggitworld.com/view/DCS_func_getPoint
position = GRPC.exporters.position(unit:getPoint()),
})
end
3 changes: 1 addition & 2 deletions protos/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ message Unit {
string callsign = 3;
Coalition coalition = 4;
string type = 5;
Position position = 6;
optional string playerName = 7;
optional string playerName = 6;
}

message Group {
Expand Down
3 changes: 3 additions & 0 deletions protos/dcs_mission.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ service Mission {
// https://wiki.hoggitworld.com/view/DCS_func_getUnits
rpc GetUnits(GetUnitsRequest) returns (GetUnitsResponse) {}

// https://wiki.hoggitworld.com/view/DCS_func_getPoint
rpc GetUnitPosition(GetUnitPositionRequest) returns (GetUnitPositionResponse) {}

// DCT Function
rpc RequestMissionAssignment(MissionAssignmentRequest) returns (MissionAssignmentResponse) {}

Expand Down
10 changes: 9 additions & 1 deletion protos/unit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ message GetRadarResponse {
Airbase airbase = 7;
Cargo cargo = 8;
}
}
}

message GetUnitPositionRequest {
string name = 1;
}

message GetUnitPositionResponse {
Position position = 1;
}
8 changes: 8 additions & 0 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ impl Mission for RPC {
Ok(Response::new(res))
}

async fn get_unit_position(
&self,
request: Request<GetUnitPositionRequest>,
) -> Result<Response<GetUnitPositionResponse>, Status> {
let res: GetUnitPositionResponse = self.request("getUnitPosition", request).await?;
Ok(Response::new(res))
}

async fn request_mission_assignment(
&self,
request: Request<MissionAssignmentRequest>,
Expand Down

0 comments on commit 5ee21bd

Please sign in to comment.