Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions uecp-sharp/UECPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

namespace UECP
{
public interface Endpoint
public interface UDPEndpoint
{
void SendData(byte[] data);
}

public class UDPSimplexEndpoint : Endpoint
public class UDPSimplexEndpoint : UDPEndpoint
{
private UdpClient _udpClient;

Expand All @@ -47,4 +47,23 @@ public void SendData(byte[] data)
_udpClient.Send(data, data.Length);
}
}
public interface TCPEndpoint
{
void SendData(byte[] data);
}
public class TCPSimplexEndpoint : TCPEndpoint
{
private TcpClient _tcpClient;
private NetworkStream TCPStream;
public TCPSimplexEndpoint(string encoderAddress, int encoderPort)
{
_tcpClient = new TcpClient(IPAddress.Parse(encoderAddress).ToString(), encoderPort);
//_tcpClient.Connect(IPAddress.Parse(encoderAddress), encoderPort);
}
public void SendData(byte[] data)
{
TCPStream = _tcpClient.GetStream();
TCPStream.Write(data, 0, data.Length);
}
}
}
40 changes: 36 additions & 4 deletions uecp-sharp/UECPEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,36 @@ namespace UECP
{
public class UECPEncoder
{
Endpoint _endpoint;
UDPEndpoint _endpoint;
TCPEndpoint _TCPendpoint;
private string consCheck = "";

public UECPEncoder(Endpoint ep)
public UECPEncoder(TCPEndpoint ep)
{
_TCPendpoint = ep;
constructorCheck("TCP");
}
public UECPEncoder(UDPEndpoint ep)
{
_endpoint = ep;
constructorCheck("UDP");
}

//Checking which Class Constructor is used
public void constructorCheck(string inputCheck)
{
string tell = "";
if (inputCheck == "TCP")
{
consCheck = "TCP";
}
if (inputCheck == "UDP")
{
consCheck = "UDP";
}
//return tell;
}
//Checking which Class Constructor is used
public void SetPI(UInt16 pi)
{
BuildAndSendMessage(MEC.RDS_PI, BitConverter.GetBytes(pi));
Expand Down Expand Up @@ -117,8 +140,17 @@ private void BuildAndSendMessage(MessageElement messageElement)
{
UECPFrame uecpFrame = new UECPFrame();
uecpFrame.MessageElements.Add(messageElement);

_endpoint.SendData(uecpFrame.GetBytes());
//We have to check which constructor is used (TCP or UDP)
if (consCheck == "UDP")
{
_endpoint.SendData(uecpFrame.GetBytes());
}
else if (consCheck == "TCP")
{
_TCPendpoint.SendData(uecpFrame.GetBytes());
}
//We have to check which constructor is used (TCP or UDP)

}

private void FillBytes(List<byte> data, byte fillWith, int desiredLength)
Expand Down