├── assets ├── wechat_qrcode.png └── paypal_button.svg ├── demo ├── Sandwych.SmartConfig.AndroidDemoApp │ ├── Resources │ │ ├── values │ │ │ ├── dimens.xml │ │ │ ├── ic_launcher_background.xml │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── menu │ │ │ └── menu_main.xml │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ ├── device_list_row.xml │ │ │ └── content_main.xml │ │ └── AboutResources.txt │ ├── DeviceListViewHolder.cs │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Assets │ │ └── AboutAssets.txt │ ├── DeviceListViewAdapter.cs │ ├── MainActivity.cs │ └── Sandwych.SmartConfig.AndroidDemoApp.csproj └── Sandwych.SmartConfig.CliDemoApp │ ├── Sandwych.SmartConfig.CliDemoApp.csproj │ └── Program.cs ├── src └── Sandwych.SmartConfig │ ├── Sandwych.SmartConfig.csproj │ ├── Esptouch │ ├── EspOptionNames.cs │ ├── EspWellKnownConstants.cs │ ├── Protocol │ │ ├── EspDevicePacketInterpreter.cs │ │ ├── EspProcedureEncoder.cs │ │ └── EspDatumFrameEncoder.cs │ └── EspSmartConfigProvider.cs │ ├── SmartConfigTimerEventHandler.cs │ ├── Constants.cs │ ├── ISmartConfigContextFactory.cs │ ├── Protocol │ ├── IProcedureEncoder.cs │ ├── IDevicePacketInterpreter.cs │ ├── FrameDataConverter.cs │ └── Segment.cs │ ├── ISmartConfigDevice.cs │ ├── Airkiss │ ├── AirkissOptionNames.cs │ ├── AirkissWellknownConstants.cs │ ├── Protocol │ │ ├── AirkissPrefixCodeFrameEncoder.cs │ │ ├── AirkissSeqEntryFrameEncoder.cs │ │ ├── AirkissDevicePacketInterpreter.cs │ │ ├── AirkissMagicCodeFrameEncoder.cs │ │ └── AirkissProcedureEncoder.cs │ └── AirkissSmartConfigProvider.cs │ ├── DeviceDiscoveredEventArgs.cs │ ├── ISmartConfigProvider.cs │ ├── Networking │ ├── IDatagramBroadcaster.cs │ ├── IDatagramReceiver.cs │ ├── IDatagramClient.cs │ ├── DatagramReceiveResult.cs │ ├── DefaultDatagramClient.cs │ ├── DatagramReceiver.cs │ └── DatagramBroadcaster.cs │ ├── Util │ ├── BytesHelper.cs │ ├── LinqExtensions.cs │ ├── TaskExtensions.cs │ ├── AsyncExtensions.cs │ └── Crc.cs │ ├── ISmartConfigJob.cs │ ├── SmartConfigExtensions.cs │ ├── StandardOptionNames.cs │ ├── SmartConfigArguments.cs │ ├── SmartConfigDevice.cs │ ├── SmartConfigTimerEventArgs.cs │ ├── AbstractSmartConfigProvider.cs │ ├── SmartConfigContext.cs │ ├── Directory.Build.props │ ├── SmartConfigStarter.cs │ └── SmartConfigJob.cs ├── NuGet.config ├── test └── Sandwych.SmartConfig.Test │ ├── Util │ ├── LinqExtensions.cs │ ├── BytesHelperTests.cs │ └── Crc8Tests.cs │ ├── Sandwych.SmartConfig.Test.csproj │ ├── Airkiss │ └── Protocol │ │ ├── AirkissPrefixCodeFrameEncoderTests.cs │ │ ├── AirkissMagicCodeFrameEncoderTests.cs │ │ ├── AirkissDevicePacketInterpreterTests.cs │ │ ├── AirkissSeqEntryFrameEncoderTests.cs │ │ └── AirkissProcedureEncoderTests.cs │ └── Esptouch │ └── Protocol │ ├── EspDatumFrameEncoderTests.cs │ └── EspProcedureEncoderTests.cs ├── LICENSE.md ├── Common.props ├── appveyor.yml ├── Sandwych.SmartConfig.sln ├── Sandwych.SmartConfig.Demo.sln ├── README.zh_cn.md ├── README.md ├── .gitignore └── .editorconfig /assets/wechat_qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/assets/wechat_qrcode.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 4 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #2C3E50 4 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Sandwych.SmartConfig.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | WiFi SmartConfig Demo App 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Esptouch/EspOptionNames.cs: -------------------------------------------------------------------------------- 1 | namespace Sandwych.SmartConfig.Esptouch 2 | { 3 | public static class EspOptionNames 4 | { 5 | public const string DatumPeriodTimeout = "esp.datum_period"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/sandwych-smartconfig/HEAD/demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/SmartConfigTimerEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Sandwych.SmartConfig 6 | { 7 | public delegate void SmartConfigTimerEventHandler(object sender, SmartConfigTimerEventArgs e); 8 | } 9 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #2c3e50 4 | #1B3147 5 | #3498db 6 | 7 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Sandwych.SmartConfig 6 | { 7 | internal class Constants 8 | { 9 | public static readonly byte[] EmptyBuffer = new byte[] { }; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/ISmartConfigContextFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Sandwych.SmartConfig 6 | { 7 | public interface ISmartConfigContextFactory 8 | { 9 | SmartConfigContext CreateContext(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Protocol/IProcedureEncoder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Sandwych.SmartConfig.Protocol 4 | { 5 | public interface IProcedureEncoder 6 | { 7 | IEnumerable Encode(SmartConfigContext context, SmartConfigArguments args); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/ISmartConfigDevice.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Net.NetworkInformation; 3 | 4 | namespace Sandwych.SmartConfig 5 | { 6 | public interface ISmartConfigDevice 7 | { 8 | PhysicalAddress MacAddress { get; } 9 | IPAddress IPAddress { get; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Airkiss/AirkissOptionNames.cs: -------------------------------------------------------------------------------- 1 | namespace Sandwych.SmartConfig.Airkiss 2 | { 3 | public static class AirkissOptionNames 4 | { 5 | public const string RandomNumber = "airkiss.random"; 6 | public const string PrefixCodeTimeout = "airkiss.prefix_timeout"; 7 | public const string MagicCodeTimeout = "airkiss.magic_timeout"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/DeviceDiscoveredEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Sandwych.SmartConfig 4 | { 5 | public class DeviceDiscoveredEventArgs : EventArgs 6 | { 7 | public DeviceDiscoveredEventArgs(ISmartConfigDevice device) 8 | { 9 | this.Device = device; 10 | } 11 | 12 | public ISmartConfigDevice Device { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/ISmartConfigProvider.cs: -------------------------------------------------------------------------------- 1 | using Sandwych.SmartConfig.Protocol; 2 | 3 | namespace Sandwych.SmartConfig 4 | { 5 | public interface ISmartConfigProvider : ISmartConfigContextFactory 6 | { 7 | string Name { get; } 8 | 9 | IProcedureEncoder CreateProcedureEncoder(); 10 | 11 | IDevicePacketInterpreter CreateDevicePacketInterpreter(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Airkiss/AirkissWellknownConstants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Sandwych.SmartConfig.Airkiss 6 | { 7 | public class AirkissWellknownConstants 8 | { 9 | public static IReadOnlyList GuideCodes { get; } = new ushort[] { 1, 2, 3, 4 }; 10 | public const int DevicePacketLength = 7; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Networking/IDatagramBroadcaster.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace Sandwych.SmartConfig.Networking 6 | { 7 | public interface IDatagramBroadcaster : IDisposable 8 | { 9 | Task BroadcastAsync( 10 | SmartConfigContext context, SmartConfigArguments args, CancellationToken cancelToken); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Networking/IDatagramReceiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Sandwych.SmartConfig.Networking 7 | { 8 | public interface IDatagramReceiver : IDisposable 9 | { 10 | Task ListenAsync( 11 | SmartConfigContext context, IPAddress localAddress, CancellationToken cancelToken); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Util/BytesHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Sandwych.SmartConfig.Util 2 | { 3 | public static class BytesHelper 4 | { 5 | public static ushort CombineUshort(byte high4bit, byte low4bit) => 6 | (ushort)(((high4bit << 4) & 0xF0) | (low4bit & 0x0F)); 7 | 8 | public static (byte high, byte low) Bisect(this byte b) => 9 | ((byte)(b >> 4), (byte)(b & 0x0F)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Protocol/IDevicePacketInterpreter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.NetworkInformation; 4 | using System.Text; 5 | 6 | namespace Sandwych.SmartConfig.Protocol 7 | { 8 | public interface IDevicePacketInterpreter 9 | { 10 | bool Validate(SmartConfigContext context, byte[] packet); 11 | 12 | PhysicalAddress ParseMacAddress(byte[] packet); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.CliDemoApp/Sandwych.SmartConfig.CliDemoApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | sccli 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/ISmartConfigJob.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace Sandwych.SmartConfig 6 | { 7 | public interface ISmartConfigJob : IDisposable 8 | { 9 | TimeSpan Timeout { get; } 10 | 11 | Task ExecuteAsync(SmartConfigContext context, 12 | SmartConfigArguments args, 13 | CancellationToken cancelToken); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Networking/IDatagramClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Sandwych.SmartConfig.Networking 8 | { 9 | public interface IDatagramClient : IDisposable 10 | { 11 | void Bind(IPEndPoint localEndPoint); 12 | Task SendAsync(byte[] datagram, int bytes, IPEndPoint target); 13 | 14 | Task ReceiveAsync(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Esptouch/EspWellKnownConstants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Sandwych.SmartConfig.Esptouch 5 | { 6 | public static class EspWellKnownConstants 7 | { 8 | 9 | public static IReadOnlyList GuideCodes { get; } = new ushort[] { 515, 514, 513, 512 }; 10 | 11 | public const String EspTouchVersion = "v0.3.7.2"; 12 | 13 | public const byte EspDevicePacketMagic = 0x18; 14 | public const int EspDevicePacketLength = 11; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/SmartConfigExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace Sandwych.SmartConfig 8 | { 9 | public static class SmartConfigExtensions 10 | { 11 | public static async Task ExecuteAsync( 12 | this ISmartConfigJob self, SmartConfigContext context, SmartConfigArguments args) 13 | { 14 | await self.ExecuteAsync(context, args, CancellationToken.None); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/StandardOptionNames.cs: -------------------------------------------------------------------------------- 1 | namespace Sandwych.SmartConfig 2 | { 3 | public static class StandardOptionNames 4 | { 5 | public const string BroadcastingTargetPort = "std.btp"; 6 | public const string ListeningPort = "std.lp"; 7 | public const string EncryptionKey = "std.enc_key"; 8 | 9 | public const string FrameInterval = "std.frame_interval"; 10 | public const string SegmentInterval = "std.segment_interval"; 11 | public const string GuideCodeTimeout = "std.guide_period"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Util/LinqExtensions.cs: -------------------------------------------------------------------------------- 1 | //https://stackoverflow.com/questions/438188/split-a-collection-into-n-parts-with-linq 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Sandwych.SmartConfig.Util 6 | { 7 | public static class LinqExtensions 8 | { 9 | public static IEnumerable> Partition( 10 | this IEnumerable source, int partitionSize) 11 | { 12 | int i = 0; 13 | return source.GroupBy(x => i++ / partitionSize); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Networking/DatagramReceiveResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | 6 | namespace Sandwych.SmartConfig.Networking 7 | { 8 | public struct DatagramReceiveResult 9 | { 10 | public byte[] Buffer { get; } 11 | public IPEndPoint RemoteEndPoint { get; } 12 | 13 | public DatagramReceiveResult(byte[] buffer, IPEndPoint remote) 14 | { 15 | this.Buffer = buffer; 16 | this.RemoteEndPoint = remote; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/SmartConfigArguments.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.NetworkInformation; 5 | using System.Text; 6 | 7 | namespace Sandwych.SmartConfig 8 | { 9 | public class SmartConfigArguments 10 | { 11 | public string Password { get; set; } = string.Empty; 12 | public string Ssid { get; set; } 13 | public PhysicalAddress Bssid { get; set; } 14 | public IPAddress LocalAddress { get; set; } 15 | public bool? IsHiddenSsid { get; set; } = null; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/SmartConfigDevice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.NetworkInformation; 5 | using System.Text; 6 | 7 | namespace Sandwych.SmartConfig 8 | { 9 | public class SmartConfigDevice : ISmartConfigDevice 10 | { 11 | public PhysicalAddress MacAddress { get; } 12 | public IPAddress IPAddress { get; } 13 | 14 | public SmartConfigDevice(PhysicalAddress mac, IPAddress ip) 15 | { 16 | this.MacAddress = mac; 17 | this.IPAddress = ip; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/DeviceListViewHolder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using Android.App; 7 | using Android.Content; 8 | using Android.OS; 9 | using Android.Runtime; 10 | using Android.Views; 11 | using Android.Widget; 12 | 13 | namespace Sandwych.SmartConfig.AndroidDemoApp 14 | { 15 | public class DeviceListViewHolder 16 | { 17 | public ImageView Image { get; set; } 18 | public TextView IPAddressView { get; set; } 19 | public TextView MacAddressView { get; set; } 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/SmartConfigTimerEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Sandwych.SmartConfig 6 | { 7 | public class SmartConfigTimerEventArgs : EventArgs 8 | { 9 | public TimeSpan Timeout { get; } 10 | public TimeSpan ExecutedTime { get; } 11 | public TimeSpan LeftTime => Timeout - ExecutedTime; 12 | 13 | public SmartConfigTimerEventArgs (TimeSpan timeout, TimeSpan elapsed) 14 | { 15 | this.Timeout = timeout; 16 | this.ExecutedTime = elapsed; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/Sandwych.SmartConfig.Test/Util/LinqExtensions.cs: -------------------------------------------------------------------------------- 1 | //https://stackoverflow.com/questions/438188/split-a-collection-into-n-parts-with-linq 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Sandwych.SmartConfig.Test.Util 8 | { 9 | public static class LinqExtensions 10 | { 11 | public static IEnumerable> Partition( 12 | this IEnumerable source, int partitionSize) 13 | { 14 | int i = 0; 15 | return source.GroupBy(x => i++ / partitionSize); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Sandwych.SmartConfig/Protocol/FrameDataConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Sandwych.Esptouch.Protocol 5 | { 6 | public static class FrameDataConverter 7 | { 8 | 9 | public static IReadOnlyList ValueToFilledByteArray(int value) 10 | { 11 | if (value > 0x1FF || value < 0) 12 | { 13 | throw new ArgumentOutOfRangeException(nameof(value)); 14 | } 15 | 16 | var result = new List(value); 17 | for (int i = 0; i < value; i++) 18 | { 19 | result[i] = (byte)'1'; 20 | } 21 | return result; 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); -------------------------------------------------------------------------------- /test/Sandwych.SmartConfig.Test/Util/BytesHelperTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Sandwych.SmartConfig.Util; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Sandwych.SmartConfig.Test.Util 8 | { 9 | public class BytesHelperTests 10 | { 11 | [Test] 12 | public void CombineUshortShouldWorks() 13 | { 14 | Assert.AreEqual((ushort)0x43, BytesHelper.CombineUshort(0x4, 0x3)); 15 | } 16 | 17 | [Test] 18 | public void BisectUshortShouldWorks() 19 | { 20 | Assert.AreEqual(0x9, BytesHelper.Bisect(0x98).high); 21 | Assert.AreEqual(0x8, BytesHelper.Bisect(0x98).low); 22 | Assert.AreEqual(0x3, BytesHelper.Bisect(0x43).low); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Sandwych.SmartConfig.Test/Sandwych.SmartConfig.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /demo/Sandwych.SmartConfig.AndroidDemoApp/Resources/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |