diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonCommunicator.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonCommunicator.cs index 8609a7e..f6d35a8 100644 --- a/RaceLapTimer/IrDaemonNotifier/IrDaemonCommunicator.cs +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonCommunicator.cs @@ -10,7 +10,7 @@ namespace IrDaemonNotifier private const int IRDAEMON_PORT_NO = 3006; private const int IRDAEMON_PROPERTY_PORT_NO = 3007; - private ILoggerService _logger; + private readonly ILoggerService _logger; public IrDaemonCommunicator(ILoggerService logger) { @@ -24,7 +24,7 @@ namespace IrDaemonNotifier //TODO: convert to use an enum value perhaps? "supported command" style? public void SendCommand(string command) { - var formattedCommand = FormatCommand(command); + var formattedCommand = command;//FormatCommand(command); //seems we may not actually need any formatting.. //---create a TCPClient object at the IP and port no.--- var client = new TcpClient(IRDAEMON_SERVER_IP, IRDAEMON_PORT_NO); @@ -131,7 +131,8 @@ namespace IrDaemonNotifier public const string GetLastToken = "LAST_SCANNED_TOKEN"; } - public const string Shutdown = "SHUTDOWN"; - public const string Reset = "RESET"; + public const string Shutdown = "SHUTDOWN#"; + public const string Reset = "RESET#"; + public const string StartNewRace = "START_NEW_RACE#"; } } diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonController.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonController.cs index e44b282..1a148ff 100644 --- a/RaceLapTimer/IrDaemonNotifier/IrDaemonController.cs +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonController.cs @@ -1,13 +1,30 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using Interfaces; namespace IrDaemonNotifier { public class IrDaemonController:ISystemControlProvider { + private readonly ILoggerService _logger; + + public IrDaemonController(ILoggerService logger) + { + _logger = logger; + } + public void Shutdown() { - Debug.WriteLine("test"); + Debug.WriteLine("Shutdown controller"); + try + { + var communicator = new IrDaemonCommunicator(_logger); + communicator.SendCommand(Commands.Shutdown); + } + catch (Exception ex) + { + _logger.Error(ex, "IrDaemonController Shutdown Error"); + } } public PluginDetails GetPluginDetails() diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonControllerProviderFactory.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonControllerProviderFactory.cs index e5ecb39..02871b8 100644 --- a/RaceLapTimer/IrDaemonNotifier/IrDaemonControllerProviderFactory.cs +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonControllerProviderFactory.cs @@ -4,9 +4,16 @@ namespace IrDaemonNotifier { public class IrDaemonControllerProviderFactory : ISystemControlProviderFactory { + private readonly ILoggerService _logger; + + public IrDaemonControllerProviderFactory(ILoggerService logger) + { + _logger = logger; + } + public ISystemControlProvider GetProvider() { - return new IrDaemonController(); + return new IrDaemonController(_logger); } } } \ No newline at end of file diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs index 86b1fd6..90bdde5 100644 --- a/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs @@ -27,11 +27,11 @@ namespace IrDaemonNotifier try { var communicator = new IrDaemonCommunicator(_logger); - communicator.SendCommand(Commands.Reset); + communicator.SendCommand(Commands.StartNewRace); } catch (Exception ex) { - _logger.Error(ex, "IrDaemonNotifier Error"); + _logger.Error(ex, "IrDaemonNotifier NotifyRaceStarted Error"); } } @@ -49,6 +49,15 @@ namespace IrDaemonNotifier public void NotifyRaceFinished(NotificationEventArgs args) { + try + { + var communicator = new IrDaemonCommunicator(_logger); + communicator.SendCommand(Commands.Reset); + } + catch (Exception ex) + { + _logger.Error(ex, "IrDaemonNotifier NotifyRaceFinished Error"); + } } } diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonTransponderUtilities.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonTransponderUtilities.cs index 087f97c..7519b55 100644 --- a/RaceLapTimer/IrDaemonNotifier/IrDaemonTransponderUtilities.cs +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonTransponderUtilities.cs @@ -5,6 +5,8 @@ using Interfaces; namespace IrDaemonNotifier { + // TODO: The irDaemon will support tcp connections so that it will publish tokens + // TODO: as they get received rather than need to request them. public class IrDaemonTransponderUtilities : ITransponderUtilityProvider { private readonly ILoggerService _logger; diff --git a/RaceLapTimer/IrDaemonNotifier/Resources.cs b/RaceLapTimer/IrDaemonNotifier/Resources.cs index d21b61b..52c183e 100644 --- a/RaceLapTimer/IrDaemonNotifier/Resources.cs +++ b/RaceLapTimer/IrDaemonNotifier/Resources.cs @@ -4,6 +4,6 @@ namespace IrDaemonNotifier { public static class Resources { - public static readonly PluginDetails Details = new PluginDetails("IrDaemonNotifier", "Chris Watts", "IR Daemon Interface", "1.0.0.0"); + public static readonly PluginDetails Details = new PluginDetails("IrDaemonNotifier", "Chris Watts", "IR Daemon Interface", "1.0.0.0", "IR Daemon Notifier"); } } \ No newline at end of file