Skip to content

Commit

Permalink
Trigger robot available when robot comes online
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Jul 25, 2024
1 parent 0598a6f commit 71d78e0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/api/EventHandlers/IsarConnectionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Api.Mqtt.Events;
using Api.Mqtt.MessageModels;
using Api.Services;
using Api.Services.Events;
using Api.Utilities;
using Timer = System.Timers.Timer;
namespace Api.EventHandlers
Expand Down Expand Up @@ -42,6 +43,9 @@ IConfiguration config
private IMissionRunService MissionRunService =>
_scopeFactory.CreateScope().ServiceProvider.GetRequiredService<IMissionRunService>();

private IMissionSchedulingService MissionSchedulingService =>
_scopeFactory.CreateScope().ServiceProvider.GetRequiredService<IMissionSchedulingService>();

public override void Subscribe()
{
MqttService.MqttIsarRobotHeartbeatReceived += OnIsarRobotHeartbeat;
Expand Down Expand Up @@ -97,6 +101,10 @@ private async void OnIsarRobotHeartbeat(object? sender, MqttReceivedArgs mqttArg
);
return;
}

// If the robot became available while the connection was not active, then this will not be triggered
// It will however be triggered if the robot lost connection while restarting or while idle
if (robot.Status == RobotStatus.Available) MissionSchedulingService.TriggerRobotAvailable(new RobotAvailableEventArgs(robot.Id));
}

private void AddTimerForRobot(IsarRobotHeartbeatMessage isarRobotHeartbeat, Robot robot)
Expand Down

0 comments on commit 71d78e0

Please sign in to comment.