diff --git a/Meshtastic/Connections/DeviceConnection.cs b/Meshtastic/Connections/DeviceConnection.cs index df2e373..66841bd 100644 --- a/Meshtastic/Connections/DeviceConnection.cs +++ b/Meshtastic/Connections/DeviceConnection.cs @@ -17,6 +17,12 @@ public DeviceConnection(ILogger logger) Logger = logger; } + public DeviceConnection(ILogger logger, DeviceStateContainer container) + { + Logger = logger; + DeviceStateContainer = container; + } + public virtual Task Monitor() { throw new NotImplementedException(); diff --git a/Meshtastic/Connections/SerialConnection.cs b/Meshtastic/Connections/SerialConnection.cs index 4ea10b5..985396f 100644 --- a/Meshtastic/Connections/SerialConnection.cs +++ b/Meshtastic/Connections/SerialConnection.cs @@ -20,6 +20,22 @@ public SerialConnection(ILogger logger, string port, int baudRate = Resources.DE }; } + public SerialConnection(ILogger logger, + string port, + DeviceStateContainer container, + bool dtrEnable = true, + Handshake handshake = Handshake.XOnXOff, + int baudRate = Resources.DEFAULT_BAUD_RATE) : base(logger) + { + serialPort = new SerialPort(port, baudRate) + { + DtrEnable = dtrEnable, + Handshake = handshake, + WriteBufferSize = 8, + }; + DeviceStateContainer = container; + } + public static string[] ListPorts() => SerialPort.GetPortNames(); public override async Task Monitor() diff --git a/Meshtastic/Connections/TcpConnection.cs b/Meshtastic/Connections/TcpConnection.cs index f1c7599..585a953 100644 --- a/Meshtastic/Connections/TcpConnection.cs +++ b/Meshtastic/Connections/TcpConnection.cs @@ -21,6 +21,17 @@ public TcpConnection(ILogger logger, string host, int port = Resources.DEFAULT_T }; } + + public TcpConnection(ILogger logger, string host, DeviceStateContainer container, int port = Resources.DEFAULT_TCP_PORT) : base(logger) + { + client = new TcpClient(host, port) + { + ReceiveBufferSize = DEFAULT_BUFFER_SIZE, + NoDelay = true + }; + DeviceStateContainer = container; + } + public override async Task WriteToRadio(ToRadio packet, Func> isComplete) { DeviceStateContainer.AddToRadio(packet);