78 lines
2.3 KiB
C#
78 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using SafeMobileLib;
|
|
|
|
|
|
namespace MotoRepeater
|
|
{
|
|
class TallysmanSendThread
|
|
{
|
|
//public static IPEndPoint iep;
|
|
//public static Socket server;
|
|
private ushort Port = 0;
|
|
//private string radioIP;
|
|
private UdpMulticast udpMulticastBusConnection = null;
|
|
UdpClient udpClient;
|
|
private String mIP;
|
|
private Int32 mPort;
|
|
|
|
public TallysmanSendThread(ushort port, String multicastID, String multicastPort)
|
|
{
|
|
Port = port;
|
|
mIP = multicastID;
|
|
mPort = Int32.Parse(multicastPort);
|
|
}
|
|
|
|
public void handleConnection()
|
|
{
|
|
try
|
|
{
|
|
udpMulticastBusConnection = new UdpMulticast(mIP, mPort);
|
|
udpMulticastBusConnection.OnNewDataRecv += new UdpMulticast.newData4Send(udp_OnNewDataReceived);
|
|
udpMulticastBusConnection.StartListen();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.WriteLine("TallysmanSendThread exception while joining the multicast group: " + ex.ToString(), ConsoleColor.Red);
|
|
}
|
|
|
|
try
|
|
{
|
|
udpClient = new UdpClient();
|
|
udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|
udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, Port));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.WriteLine("TallysmanSendThread handleConnection exception while creating udpClient: " + ex.ToString(), ConsoleColor.Red);
|
|
}
|
|
|
|
while (true) { Thread.Sleep(100); }
|
|
}
|
|
|
|
void udp_OnNewDataReceived(byte[] data, int dataLen)
|
|
{
|
|
try
|
|
{
|
|
Utils.WriteLine("TallysmanSendThread udp_OnNewDataReceived");
|
|
string str = System.Text.Encoding.ASCII.GetString(data, 0, dataLen);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SM.Debug(ex.ToString());
|
|
}
|
|
}
|
|
|
|
public void sendTallysmanCommand(String ID, String _gpio, String _type, int transactionID)
|
|
{
|
|
}
|
|
|
|
|
|
}
|
|
}
|