Skip to content

Commit

Permalink
Added some power display info
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjw3 committed Oct 17, 2021
1 parent 8fe9e2e commit 1787e88
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Native-Modem/SynchronousModem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Start(FrameReceived onFrameReceived)
modemState = ModemState.Running;

_ = Modulate();
_ = Demodulate(onFrameReceived, 0.20f);
_ = Demodulate(onFrameReceived, 0.30f);

asioOut.AudioAvailable += OnAsioOutAudioAvailable;
asioOut.Play();
Expand Down Expand Up @@ -212,6 +212,7 @@ async Task Modulate()
}

const int DECODE_WAIT_SAMPLES = 200;
const int POWER_DISPLAY_INTERVAL = 2400;

enum DemodulateState
{
Expand All @@ -237,6 +238,10 @@ async Task Demodulate(FrameReceived onFrameReceived, float syncPowerThreshold)

DemodulateState state = DemodulateState.Sync;

int powerDisplayCounter = 0;
float powerMax = 0f;
float localMax = 0f;

while (true)
{
if (!await TaskUtilities.WaitUntilUnless(() => !RxFIFO.IsEmpty, () => modemState != ModemState.Running))
Expand All @@ -263,6 +268,15 @@ async Task Demodulate(FrameReceived onFrameReceived, float syncPowerThreshold)
{
syncPower *= protocol.HeaderMagnitude / magnitude;
}
powerMax = MathF.Max(powerMax, syncPower);
powerDisplayCounter++;
if (powerDisplayCounter >= POWER_DISPLAY_INTERVAL)
{
localMax = MathF.Max(localMax, powerMax);
Console.Write($"Current sync power: {powerMax / minSyncPower * 100f:000.000}%, Local max: {localMax / minSyncPower * 100f:000.000}%\r");
powerDisplayCounter = 0;
powerMax = 0f;
}
if (writer != null)
{
writer.WriteSample(syncPower / minSyncPower);
Expand All @@ -279,6 +293,8 @@ async Task Demodulate(FrameReceived onFrameReceived, float syncPowerThreshold)
decodeFrame.Add(sample);
if (decodeFrame.Count > protocol.Header.Length)
{
localMax = 0f;
Console.WriteLine($"Frame detected! sync power: {syncPowerLocalMax / minSyncPower * 100f}% ");
syncPowerLocalMax = 0f;
state = DemodulateState.Decode;
}
Expand Down

0 comments on commit 1787e88

Please sign in to comment.