Skip to content

Commit

Permalink
implemented command line args for source file + BCH
Browse files Browse the repository at this point in the history
  • Loading branch information
sictransit committed Jun 13, 2022
1 parent 584bb41 commit 644e7e9
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 50 deletions.
41 changes: 0 additions & 41 deletions BCH.cs

This file was deleted.

46 changes: 46 additions & 0 deletions BinaryCodedHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace net.sictransit.wefax
{
//1- Satellite name(8 characters) NOAA-11
//2- Spectral band(3 characters) DIR
//3- Date(YYMMDD) (6 characters) 910125
//4- Time(HHMM) (4 characters) 1315
//5- Sector name(4 Characters) W020
//6- Open(25 characters) non-standard info

class BinaryCodedHeader
{
private readonly string satelliteName;
private readonly string spectralBand;
private readonly string sectorName;
private readonly string open;
private readonly string date;
private readonly string time;

public BinaryCodedHeader(string satelliteName, string spectralBand, string date, string time, string sectorName, string open)
{
this.satelliteName = TrimClipAndPad(satelliteName ?? string.Empty, 8);
this.spectralBand = TrimClipAndPad(spectralBand ?? string.Empty, 3);
this.date = TrimClipAndPad(date ?? string.Empty, 6);
this.time = TrimClipAndPad(time ?? string.Empty, 4);
this.sectorName = TrimClipAndPad(sectorName ?? string.Empty, 4);
this.open = TrimClipAndPad(open ?? string.Empty, 25);
}

public bool IsEmpty => string.IsNullOrWhiteSpace(Text);

private string TrimClipAndPad(string s, int length)
{
var trimmed = s.Trim();

return trimmed.Substring(0, Math.Min(trimmed.Length, length)).PadRight(length);
}

public string Text => string.Concat(satelliteName, spectralBand, date, time, sectorName, open);

public IEnumerable<int> Binary => Text.Select(c => Convert.ToString(c, 2).PadLeft(8, '0')).SelectMany(x => x).Select(c => c == '1' ? 1 : 0);
}
}
2 changes: 1 addition & 1 deletion Fax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public float[] GetStop()
return GetSquareWave(450, 5);
}

public float[] GetBCH(BCH bch, bool debug = false)
public float[] GetBCH(BinaryCodedHeader bch, bool debug = false)
{
Log.Information($"encoding BCH: [{bch.Text}]");

Expand Down
28 changes: 28 additions & 0 deletions Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using CommandLine;

namespace net.sictransit.wefax
{
public class Options
{
[Option(Required = false, Default = "img/EIA_Resolution_Chart_1956.png", HelpText = "source image file to fax")]
public string SourceImage { get; set; }

[Option(Required = false, HelpText = "[BCH] satellite name (8 chars, e.g. \"NOAA-11\")")]
public string SatelliteName { get; set; }

[Option(Required = false, HelpText = "[BCH] spectral band (3 chars, e.g. \"DIR\")")]
public string SpectralBane { get; set; }

[Option(Required = false, HelpText = "[BCH] date (6 chars, \"yyMMdd\")")]
public string Date { get; set; }

[Option(Required = false, HelpText = "[BCH] time (4 chars, \"hhmm\")")]
public string Time { get; set; }

[Option(Required = false, HelpText = "[BCH] sector name (4 chars, e.g. \"W020\")")]
public string SectorName { get; set; }

[Option(Required = false, HelpText = "[BCH] non-standard info (25 chars)")]
public string Open { get; set; }
}
}
22 changes: 14 additions & 8 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NAudio.Wave;
using CommandLine;
using NAudio.Wave;
using Serilog;
using System;
using System.Drawing;
Expand All @@ -16,10 +17,19 @@ static void Main(string[] args)
.WriteTo.Console()
.CreateLogger();

Send(@"img/EIA_Resolution_Chart_1956.png", new BCH("GC8WD6Q", "MST", DateTime.UtcNow, "JO89", "d: 1000 m, b: 90.00 deg"));
Parser.Default.ParseArguments<Options>(args)
.WithParsed(o =>
{
if (!File.Exists(o.SourceImage))
{
throw new FileNotFoundException(o.SourceImage);
}

Send(o.SourceImage, new BinaryCodedHeader(o.SatelliteName, o.SectorName, o.Date, o.Time, o.SectorName, o.Open));
});
}

private static void Send(string filename, BCH bch = null)
private static void Send(string filename, BinaryCodedHeader bch)
{
var fax = new Fax(16000);

Expand Down Expand Up @@ -51,15 +61,11 @@ private static void Send(string filename, BCH bch = null)

writer.WriteSamples(phasing, 0, phasing.Length);

if (bch != null)
if (!bch.IsEmpty)
{
var header = fax.GetBCH(bch);

writer.WriteSamples(header, 0, header.Length);

//var debug = fax.GetBCH(bch, true);

//writer.WriteSamples(debug, 0, debug.Length);
}

for (int y = 0; y < scaled.Height; y++)
Expand Down
1 change: 1 addition & 0 deletions WeFax.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="NAudio" Version="1.10.0" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
Expand Down

0 comments on commit 644e7e9

Please sign in to comment.