Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Fixes and New Controls
Browse files Browse the repository at this point in the history
Fixed UDP unicast mode for the SimpleRadio status panel
Added new volume control interaction for FC3 aircraft - bar is now
draggable
Added new select click to status dot and frequency display for fc3
Code cleanup and changes to Status display when connection to DCS is
lost
  • Loading branch information
Ciaran Fisher committed Sep 12, 2015
1 parent 164a260 commit 8cb92b5
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 144 deletions.
42 changes: 34 additions & 8 deletions Plugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static SimpleRadio::Plugin plugin;
namespace SimpleRadio
{
const char* Plugin::NAME = "DCS-SimpleRadio";
const char* Plugin::VERSION = "1.0.9";
const char* Plugin::VERSION = "1.1.3";
const char* Plugin::AUTHOR = "Ciribob - GitHub.com/ciribob";
const char* Plugin::DESCRIPTION = "DCS-SimpleRadio ";
const char* Plugin::COMMAND_KEYWORD = "sr";
Expand Down Expand Up @@ -748,14 +748,14 @@ namespace SimpleRadio
return select(0, &fds, 0, 0, &timeout);
}

SOCKET Plugin::mksocket(struct sockaddr_in *addr)
SOCKET Plugin::mksocket(struct sockaddr_in *addr, bool reuse)
{
SOCKET sock = INVALID_SOCKET;
int opt = 1;
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
return NULL;

if (this->switchToUnicast == false)
if (reuse)
{
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt)) < 0)
return NULL;
Expand Down Expand Up @@ -805,7 +805,7 @@ namespace SimpleRadio

addr.sin_addr.s_addr = htonl(INADDR_ANY);

ReceivingSocket = mksocket(&addr);
ReceivingSocket = mksocket(&addr,!this->switchToUnicast);

/* use setsockopt() to request that the kernel join a multicast group */

Expand Down Expand Up @@ -998,10 +998,18 @@ namespace SimpleRadio
struct sockaddr_in addr;

addr.sin_family = AF_INET;
addr.sin_port = htons(5060);
if (this->switchToUnicast == false)
{
addr.sin_port = htons(5060);
}
else
{
addr.sin_port = htons(5061);
}

addr.sin_addr.s_addr = htonl(INADDR_ANY);

ReceivingSocket = mksocket(&addr);
ReceivingSocket = mksocket(&addr, !this->switchToUnicast);

/* use setsockopt() to request that the kernel join a multicast group */

Expand Down Expand Up @@ -1038,9 +1046,27 @@ namespace SimpleRadio

if (updateCommand.radio >= 0)
{
//reset all the radios
this->teamSpeakControlledClientData.radio[updateCommand.radio].frequency += updateCommand.freq;
/*
FREQUENCY=1,
VOLUME=2,
SELECT=3,
*/
switch (updateCommand.cmdType) {
case 1:
this->teamSpeakControlledClientData.radio[updateCommand.radio].frequency += updateCommand.freq;
break;
case 2:
this->teamSpeakControlledClientData.radio[updateCommand.radio].volume = updateCommand.volume;
break;
case 3:
this->teamSpeakControlledClientData.selected = updateCommand.radio;
break;
default:
break;

}
}

}


Expand Down
2 changes: 1 addition & 1 deletion Plugin/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace SimpleRadio

int recvfromTimeOutUDP(SOCKET socket, long sec, long usec);

SOCKET mksocket(struct sockaddr_in *addr);
SOCKET mksocket(struct sockaddr_in *addr, bool reuse);

void UDPListener();

Expand Down
Binary file modified Plugin/Plugin.rc
Binary file not shown.
2 changes: 2 additions & 0 deletions Plugin/RadioUpdateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace SimpleRadio
{
data.freq = root["freq"].asDouble();
data.radio = root["radio"].asInt();
data.volume = root["volume"].asFloat();
data.cmdType = root["cmdType"].asInt();
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions Plugin/RadioUpdateCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace SimpleRadio

double freq;
int radio;
float volume;
int cmdType;

RadioUpdateCommand();
~RadioUpdateCommand();
Expand Down
157 changes: 55 additions & 102 deletions RadioGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,18 @@ public partial class MainWindow : Window

public MainWindow()
{

InitializeComponent();

//allows click and drag anywhere on the window
this.containerPanel.MouseLeftButtonDown += WrapPanel_MouseLeftButtonDown;

radio1.radioId = 0;
radio1.radioFrequency.Text = "Unknown";


radio2.radioId = 1;
radio2.radioFrequency.Text = "Unknown";


radio3.radioId = 2;
radio3.radioFrequency.Text = "Unknown";


//setup UDP
this.udpClient = new UdpClient();
this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
Expand All @@ -68,7 +65,7 @@ public MainWindow()
{
using (udpClient)
{

while (!end)
{
try
Expand All @@ -81,120 +78,76 @@ public MainWindow()
lastUpdate = JsonConvert.DeserializeObject<RadioUpdate>(Encoding.UTF8.GetString(receivedResults));

lastUpdateTime = DateTime.Now;

}
catch(Exception e)
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
}


}

this.udpClient.Close();
}
});

Task.Run(() =>
{


while (!end)
{
Thread.Sleep(100);

//check
if (lastUpdate != null && lastUpdate.name !=null)
{
Application.Current.Dispatcher.Invoke(new Action(() => {

//check if current
long elapsedTicks = DateTime.Now.Ticks - lastUpdateTime.Ticks;
TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

if(elapsedSpan.Seconds > 3)
{
this.statusIndicator.Fill = new SolidColorBrush(Colors.Red);
this.statusLabel.Content = "Radio Disabled";
}
else
{
this.statusIndicator.Fill = new SolidColorBrush(Colors.Green);
this.statusLabel.Content = "OK";
}

if (lastUpdate.allowNonPlayers)
{
this.allowNonPlayersIndicator.Fill = new SolidColorBrush(Colors.Green);
this.allowNonPlayers.Content = "Mute OFF";
}
else
{
this.allowNonPlayersIndicator.Fill = new SolidColorBrush(Colors.Red);
this.allowNonPlayers.Content = "Mute ON";
}




switch (lastUpdate.selected)
{
case 0:
radio1.radioActive.Fill = new SolidColorBrush(Colors.Green);
radio2.radioActive.Fill = new SolidColorBrush(Colors.Orange);
radio3.radioActive.Fill = new SolidColorBrush(Colors.Orange);
break;
case 1:
radio1.radioActive.Fill = new SolidColorBrush(Colors.Orange);
radio2.radioActive.Fill = new SolidColorBrush(Colors.Green);
radio3.radioActive.Fill = new SolidColorBrush(Colors.Orange);
break;
case 2:
radio1.radioActive.Fill = new SolidColorBrush(Colors.Orange);
radio2.radioActive.Fill = new SolidColorBrush(Colors.Orange);
radio3.radioActive.Fill = new SolidColorBrush(Colors.Green);
break;
default:
radio1.radioActive.Fill = new SolidColorBrush(Colors.Orange);
radio2.radioActive.Fill = new SolidColorBrush(Colors.Orange);
radio3.radioActive.Fill = new SolidColorBrush(Colors.Orange);
break;

}



radio1.radioFrequency.Text = (lastUpdate.radios[0].frequency/MHZ).ToString("0.000") + (lastUpdate.radios[0].modulation==0?"AM":"FM");
radio1.radioLabel.Content = lastUpdate.radios[0].name;
radio1.radioVolume.Value = (lastUpdate.radios[0].volume*100.0);

radio2.radioFrequency.Text = (lastUpdate.radios[1].frequency / MHZ).ToString("0.000") + (lastUpdate.radios[1].modulation == 0 ? "AM" : "FM");
radio2.radioLabel.Content = lastUpdate.radios[1].name;
radio2.radioVolume.Value = (lastUpdate.radios[1].volume * 100.0);

radio3.radioFrequency.Text = (lastUpdate.radios[2].frequency / MHZ).ToString("0.000") + (lastUpdate.radios[2].modulation == 0 ? "AM" : "FM");
radio3.radioLabel.Content = lastUpdate.radios[2].name;
radio3.radioVolume.Value = (lastUpdate.radios[2].volume * 100.0);

}));
}
Task.Run(() =>
{



while (!end)
{
Thread.Sleep(100);

}

});
//check
if (lastUpdate != null && lastUpdate.name != null)
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{

//check if current
long elapsedTicks = DateTime.Now.Ticks - lastUpdateTime.Ticks;
TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

if (lastUpdate.allowNonPlayers)
{
this.allowNonPlayersIndicator.Fill = new SolidColorBrush(Colors.Green);
this.allowNonPlayers.Content = "Mute OFF";
}
else
{
this.allowNonPlayersIndicator.Fill = new SolidColorBrush(Colors.Red);
this.allowNonPlayers.Content = "Mute ON";
}

if (elapsedSpan.Seconds > 5)
{
this.statusIndicator.Fill = new SolidColorBrush(Colors.Red);
this.statusLabel.Content = "Radio Disabled";
}
else
{
this.statusIndicator.Fill = new SolidColorBrush(Colors.Green);
this.statusLabel.Content = "OK";
}


radio1.update(lastUpdate, elapsedSpan);
radio2.update(lastUpdate, elapsedSpan);
radio3.update(lastUpdate, elapsedSpan);

}));
}
}
});
}

private void WrapPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}



protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
Expand All @@ -210,5 +163,5 @@ protected override void OnClosing(CancelEventArgs e)
}

}

}
4 changes: 2 additions & 2 deletions RadioGui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 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.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.1.3.0")]
[assembly: AssemblyFileVersion("1.1.3.0")]
10 changes: 9 additions & 1 deletion RadioGui/RadioCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ namespace RadioGui
{
class RadioCommand
{
public double freq;
public enum CmdType
{
FREQUENCY=1,
VOLUME=2,
SELECT=3,
}
public double freq = 1;
public int radio;
public float volume = 1.0f;
public CmdType cmdType;
}
}
20 changes: 11 additions & 9 deletions RadioGui/RadioControlGroup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
<WrapPanel>

<Label x:Name="radioLabel" Content="No Radio" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="10" Width="110" Margin="2"/>
<Button HorizontalAlignment="Center" x:Name="up10" Content="" Width="10" Height="10" Margin="25,0,0,0" ToolTip="+10MHz" Click="up10_Click"/>
<Button HorizontalAlignment="Center" x:Name="up1" Content="" Width="10" Height="10" ToolTip="+1MHZ" Click="up1_Click"/>
<Button HorizontalAlignment="Center" x:Name="up01" Content="" Width="10" Height="10" Margin="0,0,0,0" ToolTip="+0.1MHz" Click="up01_Click"/>
<Button HorizontalAlignment="Center" x:Name="up10" Content="" Width="10" Height="10" Margin="25,0,0,0" ToolTip="+10MHz" Click="up10_Click" IsEnabled="False"/>
<Button HorizontalAlignment="Center" x:Name="up1" Content="" Width="10" Height="10" ToolTip="+1MHZ" Click="up1_Click" IsEnabled="False"/>
<Button HorizontalAlignment="Center" x:Name="up01" Content="" Width="10" Height="10" Margin="0,0,0,0" ToolTip="+0.1MHz" Click="up01_Click" IsEnabled="False"/>

<TextBlock x:Name="radioFrequency" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"
<TextBlock x:Name="radioFrequency" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"
Margin="2"
MouseDown="radioFrequencyText_Click"
Background="Black" Foreground="Orange" Text="000.00AM"/>
<Ellipse x:Name="radioActive" Fill="#FF9900" HorizontalAlignment="Left" Height="12" Stroke="Black" VerticalAlignment="Center" Width="12" Margin="2" />

<Ellipse x:Name="radioActive" Fill="#FF9900" HorizontalAlignment="Left" Height="12" Stroke="Black" VerticalAlignment="Center" Width="12" Margin="2" MouseDown="radioSelectSwitch" />

<Button HorizontalAlignment="Center" x:Name="down10" Content="" Width="10" Height="10" Margin="25,0,0,0" ToolTip="-10MHZ" Click="down10_Click"/>
<Button HorizontalAlignment="Center" x:Name="down1" Content="" Width="10" Height="10" ToolTip="-1MHz" Click="down1_Click"/>
<Button HorizontalAlignment="Center" x:Name="down01" Content="" Width="10" Height="10" Margin="0,0,0,0" ToolTip="-0.1MHz" Click="down01_Click"/>
<Slider x:Name="radioVolume" Width="110" Margin="2" Maximum="100" IsEnabled="False" Height="10" />
<Button HorizontalAlignment="Center" x:Name="down10" Content="" Width="10" Height="10" Margin="25,0,0,0" ToolTip="-10MHZ" Click="down10_Click" IsEnabled="False"/>
<Button HorizontalAlignment="Center" x:Name="down1" Content="" Width="10" Height="10" ToolTip="-1MHz" Click="down1_Click" IsEnabled="False"/>
<Button HorizontalAlignment="Center" x:Name="down01" Content="" Width="10" Height="10" Margin="0,0,0,0" ToolTip="-0.1MHz" Click="down01_Click" IsEnabled="False"/>
<Slider x:Name="radioVolume" Width="110" Margin="2" Maximum="100" IsEnabled="False" Height="10" Thumb.DragCompleted="radioVolume_DragCompleted" Thumb.DragStarted="radioVolume_DragStarted" />

</WrapPanel>
</UserControl>
Loading

0 comments on commit 8cb92b5

Please sign in to comment.