Skip to content

Commit

Permalink
Merge pull request #2 from BunnyTub/cutting-edge
Browse files Browse the repository at this point in the history
Merge 2.0-c into master as 2.0
  • Loading branch information
BunnyTub authored Oct 20, 2024
2 parents b1677bb + a2e382d commit 55f4ea2
Show file tree
Hide file tree
Showing 24 changed files with 2,721 additions and 1,717 deletions.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
# SharpENDEC
# SharpENDEC

### Credits
```
BunnyTub - Main Developer
ApatheticDELL - Logo Designer
Google Translate / Microsoft Translator - Translations
```

### Libraries
```
Costura.Fody
Fody
NAudio
Newtonsoft.Json
```

> [!NOTE]
> Although SharpENDEC is meant to replicate an ENDEC, it is **not** meant to be a complete ENDEC replacement.
> Physical hardware is usually more stable, and more capable in terms of processing.
## What is it anyway?
SharpENDEC is a Canadian software CAP (Common Alerting Protocol) receiver for alerting.
If you're a little confused, imagine something similar to a physical ENDEC, but based in software.

## How do I install it?
Well, it's simple! You don't need to. Simply put the executable into a directory of your choice, then run it. If you run into a problem, or you're on an older version of Windows, you'll most likely need to [install .NET Framework 4.8.1](https://dotnet.microsoft.com/en-us/download/dotnet-framework/net481), or fully update Windows. Once you've done that, there isn't anything else that you will need to install or change.

## How do I set it up?
Well, you don't have to. But you should! There's a lot of stuff that could be of use. But... you should look over [this PDF document from Pelmorex (2021/06)](https://alerts.pelmorex.com/wp-content/uploads/2021/06/NAADS-LMD-User-Guide-R10.0.pdf) for some more knowledge on how Canada's public alerting system works, and its CAP-CP XML data. Once you have a little bit of a better understanding of the system, even just a little bit, come back here!

Here's something, configurations! You might want to change some default settings, especially if they don't fit for your scenario. If you want to change your settings, press ```C``` during startup. To reset them to factory defaults, press ```R``` instead. I'll let you explore them for yourself! Although... if you can't find any CAP-GP geocodes for use in filtering, you can use [this Excel spreadsheet](https://www.publicsafety.gc.ca/cnt/rsrcs/pblctns/capcp-lctn-rfrncs/capcp-lctn-rfrncs-annex-a-201708.xlsx), which contains the most recent list of geocodes.

One last thing. If you want to grab the text produced for use in automation, you can use ```static-text.txt``` if you need the newest text. If you want the file to be empty when it is inactive, use ```active-text.txt```. For the opposite, you can use ```inactive-text.txt``` instead.

## How can I change the audio?
Audio can be added and changed easily! Simply add in files and swap as you please.

```in.wav``` This sound is used as the lead-in, and is played before all other sounds. It will simply be ignored if it does not exist.

```attn.wav``` This sound is used as the attention tone for alerts marked as severe and above. The built-in copy will be extracted if it does not exist.

```attn-minor.wav``` This sound is used as the attention tone for alerts marked as minor and below. It will fallback to **attn.wav** if it does not exist.

```audio.wav``` This sound is reserved for the program's internal use. Modifying the file should not have any effect, and will be overwritten.

```out.wav``` This sound is used as the lead-out, and is played after all other sounds. It will simply be ignored if it does not exist.

## Is there anything else I need to know?
Nope! That's about it. There's nothing else to know here. Thanks ApatheticDELL for this application idea, it worked out really well, and you were also awesome for helping me figure out these things. SharpENDEC (C#) was originally ported from QuantumENDEC (Python), and that was uh, really hard, and annoying to figure out. I did not like translating Python, but once it got going well, everything fit into place, and overall, felt good enough, then later on, I made it better.
32 changes: 20 additions & 12 deletions SharpENDEC/App.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SharpENDEC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Soft_Weather_Radio.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="SharpENDEC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="Soft_Weather_Radio.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1"/>
</startup>
<userSettings>
<SharpENDEC.Properties.Settings>
Expand Down Expand Up @@ -39,10 +39,10 @@
<value>True</value>
</setting>
<setting name="severityMinor" serializeAs="String">
<value>False</value>
<value>True</value>
</setting>
<setting name="severityUnknown" serializeAs="String">
<value>False</value>
<value>True</value>
</setting>
<setting name="urgencyImmediate" serializeAs="String">
<value>True</value>
Expand All @@ -62,13 +62,13 @@
</value>
</setting>
<setting name="CurrentLanguage" serializeAs="String">
<value>en</value>
<value>english</value>
</setting>
<setting name="SoundDevice" serializeAs="String">
<value>-1</value>
</setting>
<setting name="SpeechVoice" serializeAs="String">
<value>Tom</value>
<value>Ava</value>
</setting>
<setting name="WirelessAlertMode" serializeAs="String">
<value>False</value>
Expand All @@ -84,6 +84,14 @@
</ArrayOfString>
</value>
</setting>
<setting name="EnforceMaximumTime" serializeAs="String">
<value>120</value>
</setting>
<setting name="EnforceEventBlacklist" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
</SharpENDEC.Properties.Settings>
<Soft_Weather_Radio.Properties.Settings>
<setting name="statusTest" serializeAs="String">
Expand Down Expand Up @@ -133,17 +141,17 @@
</setting>
<setting name="AllowedLocations_Geocodes" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</value>
</setting>
<setting name="AllowedLocations_CLC" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</value>
</setting>
<setting name="UseFrench" serializeAs="String">
<value>False</value>
</setting>
</Soft_Weather_Radio.Properties.Settings>
</userSettings>
</configuration>
</configuration>
67 changes: 67 additions & 0 deletions SharpENDEC/ConsoleForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 184 additions & 0 deletions SharpENDEC/ConsoleForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace SharpENDEC
{
public partial class ConsoleForm : Form
{
public ConsoleForm()
{
InitializeComponent();
}

private void ConsoleForm_Load(object sender, EventArgs e)
{
Console.SetOut(new TextBoxOutWriter(textBox1));
Console.SetError(new TextBoxErrorWriter(textBox1));
}

public class TextBoxOutWriter : TextWriter
{
private readonly TextBox _textBox;
private readonly StringBuilder _buffer;

public TextBoxOutWriter(TextBox textBox)
{
_textBox = textBox;
_buffer = new StringBuilder();
_textBox.Multiline = true;
_textBox.ScrollBars = ScrollBars.Vertical;
}

public override void Write(char value)
{
_buffer.Append(value);
if (_buffer.Length >= 2)
{
Flush();
}
}

public override void Write(string value)
{
_buffer.Append(value);
if (_buffer.Length >= 2)
{
Flush();
}
}

public override Encoding Encoding => Encoding.UTF8;

public override void Flush()
{
if (_buffer.Length > 0)
{
_textBox.Invoke((MethodInvoker)delegate {
_textBox.AppendText(_buffer.ToString());
_textBox.ForeColor = Color.Lime;
});
_buffer.Clear();
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
Flush();
}
base.Dispose(disposing);
}
}

public class TextBoxInReader : TextReader
{
private TextBox _inputTextBox;
private TextBox _outputTextBox;
private string _inputBuffer;

public TextBoxInReader(TextBox inputTextBox, TextBox outputTextBox)
{
_inputTextBox = inputTextBox;
_outputTextBox = outputTextBox;

// Capture Enter key press in the input TextBox
_inputTextBox.KeyPress += new KeyPressEventHandler(OnEnterKeyPress);
}

private void OnEnterKeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true; // Prevent the beep sound

// Capture the input
_inputBuffer = _inputTextBox.Text;

// Clear input box and append to output box for feedback
_inputTextBox.Clear();
_outputTextBox.AppendText(_inputBuffer + Environment.NewLine);
}
}

public override string ReadLine()
{
// Wait until the Enter key is pressed (simulate input waiting)
while (string.IsNullOrEmpty(_inputBuffer))
{
Application.DoEvents(); // Allows processing of other UI events
}

string result = _inputBuffer;
_inputBuffer = null; // Clear the buffer after use

return result;
}

public Encoding Encoding => Encoding.UTF8;
}

public class TextBoxErrorWriter : TextWriter
{
private readonly TextBox _textBox;
private readonly StringBuilder _buffer;

public TextBoxErrorWriter(TextBox textBox)
{
_textBox = textBox;
_buffer = new StringBuilder();
_textBox.Multiline = true;
_textBox.ScrollBars = ScrollBars.Vertical;
}

public override void Write(char value)
{
_buffer.Append(value);
if (_buffer.Length >= 0)
{
Flush();
}
}

public override void Write(string value)
{
_buffer.Append(value);
if (_buffer.Length >= 0)
{
Flush();
}
}

public override Encoding Encoding => Encoding.UTF8;

public override void Flush()
{
if (_buffer.Length > 0)
{
_textBox.Invoke((MethodInvoker)delegate {
_textBox.AppendText(_buffer.ToString());
_textBox.ForeColor = Color.Red;
});
_buffer.Clear();
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
Flush();
}
base.Dispose(disposing);
}
}

private void ConsoleForm_KeyDown(object sender, KeyEventArgs e)
{

}
}
}
Loading

0 comments on commit 55f4ea2

Please sign in to comment.