Skip to content

Commit

Permalink
Merge pull request #58 from meshtastic/wip
Browse files Browse the repository at this point in the history
Add constructor overloads for starting from a previous device state
  • Loading branch information
thebentern authored Nov 21, 2023
2 parents 73f66de + 459f0e6 commit 3a32b1d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Meshtastic/Connections/DeviceConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions Meshtastic/Connections/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions Meshtastic/Connections/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceStateContainer> WriteToRadio(ToRadio packet, Func<FromRadio, DeviceStateContainer, Task<bool>> isComplete)
{
DeviceStateContainer.AddToRadio(packet);
Expand Down

0 comments on commit 3a32b1d

Please sign in to comment.