Skip to content

Commit

Permalink
Added RDS Spy External RDS Decoder support
Browse files Browse the repository at this point in the history
  • Loading branch information
veso266 committed Sep 24, 2019
1 parent c33e7eb commit 4697982
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 105 deletions.
22 changes: 20 additions & 2 deletions SDRSharp.XDR/AdvancedRDSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.Threading;
using SDRSharp.XDR.Tools;
using SDRSharp.Radio;

namespace SDRSharp.XDR
{
Expand All @@ -20,7 +21,7 @@ private AdvancedRDSWindow()
{
InitializeComponent();
}

public static AdvancedRDSWindow Instance
{
//singleton design pattern to return always the same instance of a form
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions SDRSharp.XDR/RDS/RDSFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions SDRSharp.XDR/SerialCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions SDRSharp.XDR/Tools/CustomTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
95 changes: 4 additions & 91 deletions SDRSharp.XDR/UDP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
}
}
9 changes: 9 additions & 0 deletions SDRSharp.XDR/XDRPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 4697982

Please sign in to comment.