Skip to content

Commit

Permalink
[AUTO-7425] Add an API command for canceling destination
Browse files Browse the repository at this point in the history
  • Loading branch information
daviduhm authored and EricBoiseLGSVL committed Aug 25, 2021
1 parent 1dac0bb commit 4656555
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Assets/Scripts/Api/Commands/VehicleCancelDestination.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2021 LG Electronics, Inc.
*
* This software contains code licensed as described in LICENSE.
*
*/

using SimpleJSON;
using UnityEngine;
using System.Linq;
using System.Reflection;
using Simulator.Utilities;
using Simulator.Sensors;

namespace Simulator.Api.Commands
{
class VehicleCancelDestination : ICommand
{
public string Name => "vehicle/cancel_destination";

public void Execute(JSONNode args)
{
var uid = args["uid"].Value;

var api = ApiManager.Instance;
if (api.Agents.TryGetValue(uid, out GameObject obj))
{
var sensors = obj.GetComponentsInChildren<SensorBase>();
var destination_sensor = sensors.FirstOrDefault(s => s.GetType().GetCustomAttribute<SensorType>().Name == "Destination");

if (destination_sensor == null)
{
api.SendError(this, $"Agent '{uid}' does not have Destination Sensor");
return;
}

destination_sensor.GetType().GetMethod("CancelDestination").Invoke(destination_sensor, new object[] {});
api.SendResult(this);
}
else
{
api.SendError(this, $"Agent '{uid}' not found");
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Api/Commands/VehicleCancelDestination.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4656555

Please sign in to comment.