From 46979827c9772a5012d5aeb9a9cf7c2047c7e315 Mon Sep 17 00:00:00 2001 From: veso266 Date: Tue, 24 Sep 2019 13:03:47 +0200 Subject: [PATCH] Added RDS Spy External RDS Decoder support --- SDRSharp.XDR/AdvancedRDSWindow.cs | 22 ++++++- SDRSharp.XDR/RDS/RDSFunctions.cs | 8 +-- SDRSharp.XDR/SerialCommands.cs | 13 ++-- SDRSharp.XDR/Tools/CustomTooltip.cs | 4 +- SDRSharp.XDR/UDP.cs | 95 ++--------------------------- SDRSharp.XDR/XDRPlugin.cs | 9 +++ 6 files changed, 46 insertions(+), 105 deletions(-) diff --git a/SDRSharp.XDR/AdvancedRDSWindow.cs b/SDRSharp.XDR/AdvancedRDSWindow.cs index 6f9df79..5c0cb18 100644 --- a/SDRSharp.XDR/AdvancedRDSWindow.cs +++ b/SDRSharp.XDR/AdvancedRDSWindow.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using System.Threading; using SDRSharp.XDR.Tools; +using SDRSharp.Radio; namespace SDRSharp.XDR { @@ -20,7 +21,7 @@ private AdvancedRDSWindow() { InitializeComponent(); } - + public static AdvancedRDSWindow Instance { //singleton design pattern to return always the same instance of a form @@ -30,11 +31,15 @@ public static AdvancedRDSWindow Instance { form2 = new AdvancedRDSWindow(); form2.Text = "Advanced RDS Settings"; - form2.NonClientMouseHover += form2.TitleHoveredEvent; //Hook into TitleHover event + XDRPlugin.EsterEgg = Utils.GetBooleanSetting("EsterEgg", true); + if (XDRPlugin.EsterEgg) + form2.NonClientMouseHover += form2.TitleHoveredEvent; //Hook into TitleHover event if (!XDRPlugin.ExternalRDS) form2.internalrds.Checked = true; else + { form2.rdsspy.Checked = true; + } } return form2; @@ -63,6 +68,19 @@ private void internalrds_CheckedChanged(object sender, EventArgs e) private void UDPListen_Click(object sender, EventArgs e) + { + StartServer(); + UDPListen.Text = "Connected, don't click me again!!"; + UDPListen.Enabled = false; + } + public static void StartServer(int listenPort) + { + UDPServer.listenPort = listenPort; + Thread RecieveUDP = new Thread(UDPServer.Serve); + RecieveUDP.Start(); + RecieveUDP.IsBackground = true; //if this is not true we won't be able to close the SDR# because this will keep running and we don't want that + } + private void StartServer() { UDPServer.listenPort = Convert.ToInt32(textBox2.Text); Thread RecieveUDP = new Thread(UDPServer.Serve); diff --git a/SDRSharp.XDR/RDS/RDSFunctions.cs b/SDRSharp.XDR/RDS/RDSFunctions.cs index 86c8b9f..6af403a 100644 --- a/SDRSharp.XDR/RDS/RDSFunctions.cs +++ b/SDRSharp.XDR/RDS/RDSFunctions.cs @@ -71,13 +71,13 @@ private enum groupType : byte public static void ParseData(string data) { //We are parsing ASCII G Protocol - string[] DataArr = data.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + string[] DataArr = data.Split(new char[] { '\r', '\n' }, StringSplitOptions.None); if (DataArr[0] == "G:") //just check if we are not sending garbage or someone else is trying to poison our message :) { - string RDSGroup = DataArr[1]; - ushort PI = ushort.Parse(RDSGroup.Substring(0, 4)); //Short is 4 bytes long so it should never fail + string RDSGroup = DataArr[2]; + ushort PI = (ushort)Convert.ToUInt32(RDSGroup.Substring(0, 4), 16); XDRPlugin.RDS_PI = PI; - XDRPlugin.RDS_Group = RDSGroup; + XDRPlugin.RDS_Spy_Group = RDSGroup.Substring(4); } } } diff --git a/SDRSharp.XDR/SerialCommands.cs b/SDRSharp.XDR/SerialCommands.cs index 559f9fd..ab6785c 100644 --- a/SDRSharp.XDR/SerialCommands.cs +++ b/SDRSharp.XDR/SerialCommands.cs @@ -213,7 +213,7 @@ public static void ComThreadEngine() SP.Write((XDRPlugin._sdr.FmPilotIsDetected) ? "S" : "M"); //M = Forced Mono, m = normal Mono } serial_signal(XDRPlugin._sdr.VisualSNR, 2); //Signal - SP.Write("\r\n"); + SP.Write("\n"); //RDS @@ -224,21 +224,22 @@ public static void ComThreadEngine() serial_pi(XDRPlugin._sdr.RdsPICode, PI_CORRECT); SP.Write("R"); SP.Write(XDRPlugin.RDS_Group + "00"); //00 at the end are error correction: 0 - no errors 1 - max 2-bit correction 2 - max 5-bit correction - SP.Write("\r\n"); + SP.Write("\n"); } + //XDRPlugin._sdr.RdsPICode = 0; XDRPlugin.RDS_Group = null; } + else //We are using RDSSpy as RDS Decoder { if (XDRPlugin.RDSDetected) { serial_pi(XDRPlugin.RDS_PI, PI_CORRECT); SP.Write("R"); - SP.Write(XDRPlugin.RDS_Group + "00"); //00 at the end are error correction: 0 - no errors 1 - max 2-bit correction 2 - max 5-bit correction - SP.Write("\r\n"); + SP.Write(XDRPlugin.RDS_Spy_Group + "00"); //00 at the end are error correction: 0 - no errors 1 - max 2-bit correction 2 - max 5-bit correction + SP.Write("\n"); } - //XDRPlugin._sdr.RdsPICode = 0; - XDRPlugin.RDS_Group = null; + XDRPlugin.RDS_Spy_Group = null; } } } diff --git a/SDRSharp.XDR/Tools/CustomTooltip.cs b/SDRSharp.XDR/Tools/CustomTooltip.cs index f97accc..40a9fb4 100644 --- a/SDRSharp.XDR/Tools/CustomTooltip.cs +++ b/SDRSharp.XDR/Tools/CustomTooltip.cs @@ -31,9 +31,9 @@ private void OnPopup(object sender, PopupEventArgs e) private void OnDraw(object sender, DrawToolTipEventArgs e) { - - e.Graphics.DrawImage(img, 0, 0); + var YourTipTextPoint = new Point(0, 0); + e.Graphics.DrawString("When wolves imprint only death tears them apart", SystemFonts.DefaultFont, Brushes.White, YourTipTextPoint); } } } diff --git a/SDRSharp.XDR/UDP.cs b/SDRSharp.XDR/UDP.cs index 5fb0eef..1675755 100644 --- a/SDRSharp.XDR/UDP.cs +++ b/SDRSharp.XDR/UDP.cs @@ -14,22 +14,20 @@ class UDPServer public static int listenPort = 8888; public static void Serve() { - bool done = false; UdpClient listener = new UdpClient(listenPort); IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort); byte[] receive_byte_array; try { - while (!done) + while (true) { - Debug.WriteLine("Waiting for broadcast"); - receive_byte_array = listener.Receive(ref groupEP); - if (groupEP != null) //If we have any data on UDP we have RDS + string data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length); + if (!data.Contains("NO-RDS")) //If we have any data on UDP we have RDS if only it would be null if there is no data but once it is filled with data it stays filled with data { XDRPlugin.RDSDetected = true; - SerialCommands.ParseData(Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length)); + SerialCommands.ParseData(data); } else { @@ -44,89 +42,4 @@ public static void Serve() listener.Close(); } } - class UDPClient - { - class Program - - { - static void test(string[] args) - { - Boolean done = false; - Boolean exception_thrown = false; - - Socket sending_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, - ProtocolType.Udp); - - IPAddress send_to_address = IPAddress.Parse("192.168.2.255"); - - IPEndPoint sending_end_point = new IPEndPoint(send_to_address, 11000); - - #region comments - // The below three lines of code will not work. They appear to load - - // the variable broadcast_string witha broadcast address. But that - - // address causes an exception when performing the send. - - // - - //string broadcast_string = IPAddress.Broadcast.ToString(); - - //Console.WriteLine("broadcast_string contains {0}", broadcast_string); - - //send_to_address = IPAddress.Parse(broadcast_string); - - #endregion - - Console.WriteLine("Enter text to broadcast via UDP."); - Console.WriteLine("Enter a blank line to exit the program."); - while (!done) - { - Console.WriteLine("Enter text to send, blank line to quit"); - string text_to_send = Console.ReadLine(); - if (text_to_send.Length == 0) - { - done = true; - } - else - - { - // the socket object must have an array of bytes to send. - - // this loads the string entered by the user into an array of bytes. - - byte[] send_buffer = Encoding.ASCII.GetBytes(text_to_send); - - // Remind the user of where this is going. - - Console.WriteLine("sending to address: {0} port: {1}", - sending_end_point.Address, - sending_end_point.Port); - try - - { - sending_socket.SendTo(send_buffer, sending_end_point); - } - catch (Exception send_exception) - { - exception_thrown = true; - Console.WriteLine(" Exception {0}", send_exception.Message); - } - if (exception_thrown == false) - { - Console.WriteLine("Message has been sent to the broadcast address"); - } - else - - { - exception_thrown = false; - Console.WriteLine("The exception indicates the message was not sent."); - } - } - } // end of while (!done) - - } // end of main() - - } // end of class Program - } } diff --git a/SDRSharp.XDR/XDRPlugin.cs b/SDRSharp.XDR/XDRPlugin.cs index f6f8ac1..4ada3b3 100644 --- a/SDRSharp.XDR/XDRPlugin.cs +++ b/SDRSharp.XDR/XDRPlugin.cs @@ -49,6 +49,9 @@ public void Initialize(ISharpControl control) //Hook into RDS stream XDRPlugin._sdr.RegisterStreamHook(new RDSHandle(), ProcessorType.RDSBitStream); + ExternalRDS = Utils.GetBooleanSetting("ExternalRDS", false); + if (ExternalRDS) + AdvancedRDSWindow.StartServer(8888); //If RDS Spy is selected we want to start the server immediately } // When you close SDR# it calls this @@ -57,6 +60,8 @@ public void Close() Utils.SaveSetting("enableXdr", this._controlPanel.XdrEnabled); Utils.SaveSetting("XdrComIndex", this._controlPanel.comIndex); Utils.SaveSetting("BaudIndex", this._controlPanel.BaudIndex); + Utils.SaveSetting("ExternalRDS", ExternalRDS); + Utils.SaveSetting("EsterEgg", EsterEgg); if (XDRPlugin._continue) { XDRPlugin._waiting = true; @@ -89,9 +94,13 @@ public void Close() //for RDS public static ushort RDS_PI; public static string RDS_Group = null; + public static string RDS_Spy_Group = null; //I have to sleep but .... agrrrr public static bool RDSDetected = false; //For AdvancedRDSWindow public static bool ExternalRDS = false; + + //Easter egg + public static bool EsterEgg = true; } }