Files
dotnet-screenlogic/EasyTouchUnit.cs
Parnic d6dfcb14a9 Added support for remote connection by name via Pentair servers
This brings along proper password encryption and validation for the login process (which is still not needed for local connections).

You can run the remote connection tests by passing a system name and password as 2 arguments (so the system name needs to be quoted, e.g.: `test "Pentair: xx-xx-xx" 1234`)

Also updated to latest .NET Core and C# versions while I was at it.
2019-02-20 15:19:42 -06:00

65 lines
2.0 KiB
C#

using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ScreenLogicConnect
{
public class EasyTouchUnit
{
public String gatewayName { get; private set; }
public byte gatewaySubType { get; private set; }
public byte gatewayType { get; private set; }
public IPAddress ipAddress { get; private set; }
public bool isValid { get; private set; }
public short port { get; private set; }
public EasyTouchUnit(UdpReceiveResult result)
{
try
{
ipAddress = result.RemoteEndPoint.Address;
using (var ms = new MemoryStream(result.Buffer))
{
using (var br = new BinaryReader(ms))
{
var unitType = br.ReadInt32();
if (unitType == 2)
{
br.ReadBytes(4);
port = br.ReadInt16();
gatewayType = br.ReadByte();
gatewaySubType = br.ReadByte();
gatewayName = Encoding.ASCII.GetString(result.Buffer.Skip((int)ms.Position).TakeWhile(x => x != 0).ToArray());
isValid = true;
}
}
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
}
public EasyTouchUnit(Messages.GetGatewayData data)
{
try
{
gatewayName = data.GatewayName;
ipAddress = IPAddress.Parse(data.IPAddr);
port = data.Port;
isValid = data.GatewayFound && data.PortOpen;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
}
}
}