Skip to content

Commit

Permalink
Merge pull request #8 from oldrev/dev
Browse files Browse the repository at this point in the history
Code Cleaning
  • Loading branch information
oldrev authored Dec 12, 2020
2 parents 683c772 + 1a4b9aa commit 7870f34
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Sandwych.SmartConfig.Airkiss.Protocol;
using Sandwych.SmartConfig.Airkiss.Protocol;
using Sandwych.SmartConfig.Protocol;
using System;
using System.Collections.Generic;
Expand All @@ -15,7 +15,7 @@ public class AirkissSmartConfigProvider : AbstractSmartConfigProvider
{
yield return (StandardOptionNames.BroadcastingTargetPort, 10001); // The port to broadcast doesn't matter
yield return (StandardOptionNames.ListeningPort, 10000);
yield return (StandardOptionNames.FrameInterval, TimeSpan.FromMilliseconds(0));
yield return (StandardOptionNames.FrameInterval, TimeSpan.Zero);
yield return (StandardOptionNames.SegmentInterval, TimeSpan.FromMilliseconds(5));
yield return (StandardOptionNames.GuideCodeTimeout, TimeSpan.FromSeconds(2));

Expand Down
4 changes: 2 additions & 2 deletions src/Sandwych.SmartConfig/Esptouch/EspSmartConfigProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Sandwych.SmartConfig.Esptouch.Protocol;
using Sandwych.SmartConfig.Esptouch.Protocol;
using Sandwych.SmartConfig.Protocol;
using System;
using System.Collections.Generic;
Expand All @@ -16,7 +16,7 @@ public override IDevicePacketInterpreter CreateDevicePacketInterpreter()
{
yield return (StandardOptionNames.BroadcastingTargetPort, 7001);
yield return (StandardOptionNames.ListeningPort, 18266);
yield return (StandardOptionNames.FrameInterval, TimeSpan.FromMilliseconds(8));
yield return (StandardOptionNames.FrameInterval, TimeSpan.Zero);
yield return (StandardOptionNames.SegmentInterval, TimeSpan.FromMilliseconds(8));
yield return (StandardOptionNames.GuideCodeTimeout, TimeSpan.FromSeconds(2));
yield return (EspOptionNames.DatumPeriodTimeout, TimeSpan.FromSeconds(4));
Expand Down
11 changes: 9 additions & 2 deletions src/Sandwych.SmartConfig/Networking/DatagramBroadcaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ private async Task BroadcastProcedureAsync(
await this.BroadcastSegmentUntilAsync(
context, segment, broadcastBuffer, userCancelToken);
}
await Task.Delay(segmentInterval, userCancelToken);
if (segmentInterval > TimeSpan.Zero)
{
await Task.Delay(segmentInterval, userCancelToken);
}
}

await Task.Delay(segmentInterval, userCancelToken);
if (segmentInterval > TimeSpan.Zero)
{
await Task.Delay(segmentInterval, userCancelToken);
}
}
}

Expand All @@ -98,6 +104,7 @@ private async Task BroadcastSegmentByTimesAsync(
var segmentInterval = context.GetOption<TimeSpan>(StandardOptionNames.FrameInterval);
for (int i = 0; i < segment.BroadcastingMaxTimes; i++)
{
token.ThrowIfCancellationRequested();
await this.BroadcastSingleSegmentAsync(segment, broadcastBuffer, segmentInterval, token);
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/Sandwych.SmartConfig/Networking/DefaultDatagramClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,5 @@ public void Dispose()
_udp.Dispose();
}

private static int GetFirstWifiInterfaceIndex()
{
var adapters = NetworkInterface.GetAllNetworkInterfaces();
var wifi = adapters.Where(
x => x.NetworkInterfaceType == NetworkInterfaceType.Wireless80211
&& x.OperationalStatus == OperationalStatus.Up
&& !x.IsReceiveOnly
).FirstOrDefault();
if(wifi == null)
{
throw new IOException("Cannot find available WiFi interface");
}
return wifi.GetIPProperties().GetIPv4Properties().Index;
}

}
}

0 comments on commit 7870f34

Please sign in to comment.