From ec05233e79ab8bb93c65bf1a330ca279171d2b59 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Mon, 19 Jun 2017 21:59:01 +0100 Subject: [PATCH] create IrDaemonNotifier project, that transmits to the irdaemon code to start race --- .../IrDaemonNotifier/IrDaemonNotifier.cs | 77 +++++++++++++++++++ .../IrDaemonNotifier/IrDaemonNotifier.csproj | 61 +++++++++++++++ .../IrDaemonNotifierProviderFactory.cs | 28 +++++++ .../Properties/AssemblyInfo.cs | 36 +++++++++ RaceLapTimer/RaceLapTimer.sln | 7 ++ 5 files changed, 209 insertions(+) create mode 100644 RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs create mode 100644 RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.csproj create mode 100644 RaceLapTimer/IrDaemonNotifier/IrDaemonNotifierProviderFactory.cs create mode 100644 RaceLapTimer/IrDaemonNotifier/Properties/AssemblyInfo.cs diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs new file mode 100644 index 0000000..71c8e06 --- /dev/null +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using Interfaces; + +namespace IrDaemonNotifier +{ + public class IrDaemonNotifier : INotifierProvider + { + private const int REMOTE_PORT_NO = 3006; + private const string REMOTE_SERVER_IP = "127.0.0.1"; + + private readonly ILoggerService _logger; + + public IrDaemonNotifier(ILoggerService logger) + { + _logger = logger; + } + + public string GetDisplayName() + { + return "Ir Daemon Notifier"; + } + + public string GetNotifierType() + { + return nameof(IrDaemonNotifier); + } + + public void NotifyRaceStarted(NotificationEventArgs args) + { + try + { + //---data to send to the server--- + var message = string.Format("#{0}#\n", "RESET"); + + //---create a TCPClient object at the IP and port no.--- + var client = new TcpClient(REMOTE_SERVER_IP, REMOTE_PORT_NO); + var nwStream = client.GetStream(); + var bytesToSend = Encoding.ASCII.GetBytes(message); + + //---send the text--- + _logger.Trace("Sending: {0}", message); + nwStream.Write(bytesToSend, 0, bytesToSend.Length); + + //---read back the text--- + var bytesToRead = new byte[client.ReceiveBufferSize]; + var bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize); + _logger.Trace("Received: {0}", Encoding.ASCII.GetString(bytesToRead, 0, bytesRead)); + client.Close(); + } + catch (Exception ex) + { + _logger.Error(ex, "IrDaemonNotifier Error"); + } + } + + public void NotifyRaceStarting(NotificationEventArgs args) + { + } + + public void NotifyRaceLapEvent(NotificationEventArgs args, Pilot pilot) + { + } + + public void NotifyRaceWinner(NotificationEventArgs args, Pilot pilot) + { + } + + public void NotifyRaceFinished(NotificationEventArgs args) + { + } + } +} diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.csproj b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.csproj new file mode 100644 index 0000000..687c386 --- /dev/null +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifier.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {916994F6-1711-4AEB-8DE6-4AB6FCB3F080} + Library + Properties + IrDaemonNotifier + IrDaemonNotifier + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + {5C6DCC59-19F3-46AD-A479-926610F36257} + Interfaces + + + + + \ No newline at end of file diff --git a/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifierProviderFactory.cs b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifierProviderFactory.cs new file mode 100644 index 0000000..da2dce9 --- /dev/null +++ b/RaceLapTimer/IrDaemonNotifier/IrDaemonNotifierProviderFactory.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Interfaces; + +namespace IrDaemonNotifier +{ + public class IrDaemonNotifierProviderFactory:INotifierProviderFactory + { + private readonly ILoggerService _logger; + + public IrDaemonNotifierProviderFactory(ILoggerService logger) + { + _logger = logger; + } + public INotifierProvider CreateProvider() + { + return new IrDaemonNotifier(_logger); + } + + public new string GetType() + { + return nameof(IrDaemonNotifierProviderFactory); + } + } +} diff --git a/RaceLapTimer/IrDaemonNotifier/Properties/AssemblyInfo.cs b/RaceLapTimer/IrDaemonNotifier/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e6374c5 --- /dev/null +++ b/RaceLapTimer/IrDaemonNotifier/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("IrDaemonNotifier")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IrDaemonNotifier")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("916994f6-1711-4aeb-8de6-4ab6fcb3f080")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/RaceLapTimer/RaceLapTimer.sln b/RaceLapTimer/RaceLapTimer.sln index a1a9182..8be1aaa 100644 --- a/RaceLapTimer/RaceLapTimer.sln +++ b/RaceLapTimer/RaceLapTimer.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UdpNotifier", "UdpNotifier\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Logger", "Logger", "{36BDEE78-985C-4AF5-A39B-3BE89FAEB281}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IrDaemonNotifier", "IrDaemonNotifier\IrDaemonNotifier.csproj", "{916994F6-1711-4AEB-8DE6-4AB6FCB3F080}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {734097B0-A764-40AD-957A-43FE4F085B65}.Debug|Any CPU.Build.0 = Debug|Any CPU {734097B0-A764-40AD-957A-43FE4F085B65}.Release|Any CPU.ActiveCfg = Release|Any CPU {734097B0-A764-40AD-957A-43FE4F085B65}.Release|Any CPU.Build.0 = Release|Any CPU + {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Debug|Any CPU.Build.0 = Debug|Any CPU + {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Release|Any CPU.ActiveCfg = Release|Any CPU + {916994F6-1711-4AEB-8DE6-4AB6FCB3F080}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,5 +62,6 @@ Global GlobalSection(NestedProjects) = preSolution {9A93A12F-7591-406A-A4F3-41AA8299C4B4} = {36BDEE78-985C-4AF5-A39B-3BE89FAEB281} {734097B0-A764-40AD-957A-43FE4F085B65} = {CDAC76D5-5EC6-4357-A27C-0095BF98FDDF} + {916994F6-1711-4AEB-8DE6-4AB6FCB3F080} = {CDAC76D5-5EC6-4357-A27C-0095BF98FDDF} EndGlobalSection EndGlobal