852 lines
35 KiB
C#
852 lines
35 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Collections;
|
|||
|
using System.Net.Sockets;
|
|||
|
using System.Net;
|
|||
|
using System.ComponentModel;
|
|||
|
using Telerik.WinControls;
|
|||
|
using SafeMobileLib;
|
|||
|
using SafeMobileLib.Safenet;
|
|||
|
using SafeMobileLib.MessageDecoders;
|
|||
|
|
|||
|
namespace MotoRepeater
|
|||
|
{
|
|||
|
public class MotoRepeater_GW
|
|||
|
{
|
|||
|
public static LOGS hLog = null;
|
|||
|
public static TimeSpan timeDifference = new TimeSpan(0);
|
|||
|
|
|||
|
public static AppType appType = AppType.SAFEDISPATCH;
|
|||
|
|
|||
|
public static Config cfg = new Config();
|
|||
|
public static ConsoleArgs consoleArgs;
|
|||
|
public static List<RadioGateway> radioGWs = new List<RadioGateway>();
|
|||
|
public static Boolean isRunning = true;
|
|||
|
|
|||
|
// Thread Timers
|
|||
|
public static InternalStatistic arsStatistic = new InternalStatistic();
|
|||
|
public static InternalStatistic gpsStatistic = new InternalStatistic();
|
|||
|
public static InternalStatistic pollStatistic = new InternalStatistic();
|
|||
|
public static InternalStatistic smsStatistic = new InternalStatistic();
|
|||
|
public static InternalStatistic telemetryStatistic = new InternalStatistic();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//private MessageBus mBus;
|
|||
|
private DataBaseInterface dbInterface;
|
|||
|
public static DateTime startTime = DateTime.Now;
|
|||
|
public static DateTime lastEntry;
|
|||
|
public static bool addressLoaded = false;
|
|||
|
|
|||
|
private WatcherServerThread ddmsWatcher;
|
|||
|
private LocationThread LocationConnection;
|
|||
|
private SMSReceiveThread SMSReceiveConnection = null;
|
|||
|
private SMSSendThread SMSSendConnection = null;
|
|||
|
private TelemetryReceiveThread TelemetryReceiveConnection = null;
|
|||
|
private TelemetrySendThread TelemetrySendConnection = null;
|
|||
|
private TallysmanReceiveThread TallysmanReceiveConnection = null;
|
|||
|
|
|||
|
public static System.Net.Sockets.UdpClient smsUDPclient = null;
|
|||
|
|
|||
|
private Thread LocationThreadobj = null;
|
|||
|
private Thread ReceiveSMSThreadobj = null;
|
|||
|
private Thread SendSMSThreadobj = null;
|
|||
|
private Thread TelemetryReceiveThreadObj = null;
|
|||
|
private Thread TallysmanReceiveThreadObj = null;
|
|||
|
private Thread TelemetrySendThreadObj = null;
|
|||
|
private Thread SMSReceiveThreadObj = null;
|
|||
|
private Thread SMSSendThreadObj = null;
|
|||
|
private Thread GatewayStatusThread = null;
|
|||
|
|
|||
|
private DBvehiclesManager vehiclesManager;
|
|||
|
|
|||
|
|
|||
|
// Voice MultiCast
|
|||
|
private UdpMulticast voiceMulticastSlot1Send;
|
|||
|
private UdpMulticast voiceMulticastSlot2Send;
|
|||
|
|
|||
|
private int DialogID = 0x2222;
|
|||
|
// Wireline and LE
|
|||
|
private LinkEstablishment linkEstablishment;
|
|||
|
private Wireline wireline;
|
|||
|
|
|||
|
public REP_STATUS _registered = REP_STATUS.stoped;
|
|||
|
public REP_STATUS registered
|
|||
|
{
|
|||
|
get { return _registered; }
|
|||
|
set
|
|||
|
{
|
|||
|
_registered = value;
|
|||
|
RegStatusChanged("RegStatusProp");
|
|||
|
}
|
|||
|
}
|
|||
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
protected void RegStatusChanged(string name)
|
|||
|
{
|
|||
|
PropertyChangedEventHandler handler = PropertyChanged;
|
|||
|
if (handler != null)
|
|||
|
{
|
|||
|
PropertyChangedEventArgs e = new PropertyChangedEventArgs(name);
|
|||
|
|
|||
|
handler(this, e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public MotoRepeater_GW()
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
//DB.LoadUnitInfo(gatewayID);
|
|||
|
|
|||
|
//cfg = new Config();;
|
|||
|
/*
|
|||
|
try
|
|||
|
{
|
|||
|
udpMulticast = new UdpMulticast(cfg.msgBusIP, cfg.msgBusPort);
|
|||
|
//Console.WriteLine("Location thread successfully registered to multicast group");
|
|||
|
udpMulticast.OnNewDataRecv += new UdpMulticast.newData4Send(udpMulticast_OnNewDataRecv);
|
|||
|
udpMulticast.StartListen();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Utils.WriteLine("Location Thread Error while joining the multicast group: " + ex.ToString());
|
|||
|
}
|
|||
|
//*/
|
|||
|
|
|||
|
// Get the time from Internet and then save the difference in time between the local computer time
|
|||
|
// and the internet one from time.nist.gov
|
|||
|
Thread internetTimeThread = new Thread(new ThreadStart(delegate()
|
|||
|
{
|
|||
|
timeDifference = (DT.GetNetworkTime()).Subtract(DateTime.UtcNow);
|
|||
|
}));
|
|||
|
internetTimeThread.Start();
|
|||
|
|
|||
|
GatewayStatusThread = new Thread(new ThreadStart(delegate()
|
|||
|
{
|
|||
|
int count = 0;
|
|||
|
|
|||
|
while (isRunning)
|
|||
|
{
|
|||
|
if(++count % 120 == 0)
|
|||
|
{
|
|||
|
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|||
|
|
|||
|
Int64 upTime = DateTime.Now.DateTo70Format() - startTime.DateTo70Format();
|
|||
|
AddGatewayStatusMessage(MotoRepeater_GW.cfg.GWCODE, (registered == REP_STATUS.ddmsUP ? true : false),
|
|||
|
String.Format("Uptime:{0};Version:{1}", upTime, v.ToString()));
|
|||
|
}
|
|||
|
Thread.Sleep(500);
|
|||
|
}
|
|||
|
}
|
|||
|
));
|
|||
|
GatewayStatusThread.Start();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void StartGPSService()
|
|||
|
{
|
|||
|
// create thread to listen UDP
|
|||
|
LocationConnection = new LocationThread((ushort)cfg.GPS_PORT, this);
|
|||
|
|
|||
|
#region LOCATION Received Events
|
|||
|
// add event listener for when a location is received
|
|||
|
LocationConnection.OnLocationReceived += delegate(LocationEventArgs e)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(e.RadioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + e.RadioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
gpsStatistic.incoming++;
|
|||
|
OnEventToDisplayOnUI(String.Format("Position [{0:0.0000},{1:0.0000}] from {2}{3}{4}", Math.Round(e.Latitude, 4),
|
|||
|
Math.Round(e.Longitude, 4), e.RadioID ,
|
|||
|
e.Altitude > 0 ? System.Environment.NewLine+ "\t Altitude [" + e.Altitude + " meters]" : "",
|
|||
|
e.LevelOfConfidence > -1 ? "" + "\t Level of confidence ["
|
|||
|
+ e.LevelOfConfidence + "%]" : ""));
|
|||
|
|
|||
|
Utils.WriteLine("POSITION TIME AFTER EVENT IS : " + e.GPSTime.ToString());
|
|||
|
// send the poll through the messageBus
|
|||
|
dbInterface.LocationResponseReceived(e.RadioID, (new DateTime(1970, 1, 1).AddSeconds(e.GPSTime)), (int)e.Speed, e.Latitude, e.Longitude);
|
|||
|
};
|
|||
|
|
|||
|
// add event listener for when a poll response is received
|
|||
|
LocationConnection.OnPollReceived += delegate(LocationEventArgs e)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(e.RadioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + e.RadioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
pollStatistic.incoming++;
|
|||
|
OnEventToDisplayOnUI(String.Format("Poll Res [{0:0.0000},{1:0.0000}]{3} from {2}", Math.Round(e.Latitude, 4),
|
|||
|
Math.Round(e.Longitude, 4), e.RadioID,
|
|||
|
e.Altitude > 0 ? System.Environment.NewLine + "\t Altitude [" + e.Altitude + " meters]" : "",
|
|||
|
e.LevelOfConfidence > -1 ? "" + "\t Level of confidence ["
|
|||
|
+ e.LevelOfConfidence + "%]" : ""));
|
|||
|
|
|||
|
// send the poll through the messageBus
|
|||
|
dbInterface.PollResponseReceived(e.RadioID, (new DateTime(1970, 1, 1).AddSeconds(e.GPSTime)), (int)e.Speed, e.Latitude, e.Longitude, e.seqID);
|
|||
|
};
|
|||
|
|
|||
|
LocationConnection.OnLocationThreadKilled += OnLocationThreadKilled;
|
|||
|
#endregion
|
|||
|
|
|||
|
//LocationConnection.parent = this;
|
|||
|
LocationThreadobj = new Thread(new ThreadStart(LocationConnection.handleConnection));
|
|||
|
LocationThreadobj.IsBackground = true;
|
|||
|
LocationThreadobj.Start();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void OnLocationThreadKilled()
|
|||
|
{
|
|||
|
// restart location thread
|
|||
|
|
|||
|
if (LocationThreadobj.ThreadState != ThreadState.Running)
|
|||
|
{
|
|||
|
LocationThreadobj.Abort();
|
|||
|
// restart the GPS Service
|
|||
|
StartGPSService();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void StartDDMSService()
|
|||
|
{
|
|||
|
ddmsWatcher = new WatcherServerThread(cfg.DDMS_IP, cfg.DDMS_PORT);
|
|||
|
ddmsWatcher.OnDdmsConnectionStatusChanged += new WatcherServerThread.ConnectionStatusDEl(ddmsWatcher_OnDdmsConnectionStatusChanged);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#region ARS Received Events
|
|||
|
// add event listener for when an ARS is received
|
|||
|
ddmsWatcher.OnARSReceived += delegate(Int64 radioID, bool isON)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(radioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + radioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
string arsState = (isON) ? "ON" : "OFF";
|
|||
|
Utils.WriteLine("ARS " + arsState + " from " + radioID);
|
|||
|
OnEventToDisplayOnUI("ARS " + arsState + " from " + radioID);
|
|||
|
|
|||
|
ArsMSG ars = new ArsMSG();
|
|||
|
ars.imei = radioID.ToString();
|
|||
|
ars.msg = arsState;
|
|||
|
//SN_Queues.arsMsgQueue.PostItem(ars);
|
|||
|
dbInterface.ARSStateReceived(radioID, isON);
|
|||
|
//mBus.SendARS(radioID + "", arsState);
|
|||
|
|
|||
|
if (isON)
|
|||
|
{
|
|||
|
//Thread.Sleep(1500);
|
|||
|
//LocationThread.SendTriggeredLocationSTOP(radioID.ToString(), 0xEE, true);
|
|||
|
Thread.Sleep(1000);
|
|||
|
PerformeARSon(radioID.ToString());
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
ddmsWatcher.OnTriggeredLocationRequest += delegate(string radioID, int reportingInterval)
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI("Location request [" + reportingInterval + " sec] for " + radioID);
|
|||
|
};
|
|||
|
#endregion
|
|||
|
|
|||
|
//ddmsWatcher.OnMessageRecv += new WatcherServerThread.MessageRecv(ddmsWatcher_OnMessageRecv);
|
|||
|
ddmsWatcher.Start();
|
|||
|
}
|
|||
|
|
|||
|
void ddmsWatcher_OnDdmsConnectionStatusChanged(bool isUP)
|
|||
|
{
|
|||
|
ddmsClientChanged(isUP);
|
|||
|
}
|
|||
|
|
|||
|
private void ddmsClientChanged(bool state)
|
|||
|
{
|
|||
|
if (state)
|
|||
|
{
|
|||
|
registered = REP_STATUS.ddmsUP;
|
|||
|
|
|||
|
//ddmsWatcher.SubscribeList(ddmsWatcher.DialogID, new List<string>() { "101" });
|
|||
|
ddmsWatcher.SubscribeALL(DialogID++);
|
|||
|
//ddmsWatcher.SubscribeList(0x2222, new List<string> { "103"});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
registered = REP_STATUS.ddmsDOWN;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private UdpClient udpClient;
|
|||
|
void StartSMSService()
|
|||
|
{
|
|||
|
udpClient = null;
|
|||
|
udpClient = new UdpClient(cfg.SMS_PORT);
|
|||
|
//udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|||
|
//udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, cfg.TM_port));
|
|||
|
|
|||
|
//create thread for sending SMSs to the radios
|
|||
|
SMSSendConnection = new SMSSendThread((ushort)cfg.SMS_PORT, true, udpClient);
|
|||
|
SMSSendThreadObj = new Thread(new ThreadStart(SMSSendConnection.handleConnection));
|
|||
|
SMSSendThreadObj.IsBackground = true;
|
|||
|
SMSSendThreadObj.Start();
|
|||
|
|
|||
|
|
|||
|
SMSReceiveConnection = new SMSReceiveThread((ushort)cfg.SMS_PORT, udpClient);
|
|||
|
|
|||
|
#region SMS Received Events
|
|||
|
SMSReceiveConnection.OnSMSBytesReceived += delegate(Int64 radioID, byte[] received)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(radioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + radioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
smsStatistic.incoming++;
|
|||
|
dbInterface.SMSReceived(radioID, received);
|
|||
|
OnEventToDisplayOnUI("SMS from radio " + radioID);
|
|||
|
};
|
|||
|
SMSReceiveConnection.OnSMSReceived += delegate(Int64 radioID, string message)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(radioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + radioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
smsStatistic.incoming++;
|
|||
|
dbInterface.SMSReceived(radioID, message);
|
|||
|
OnEventToDisplayOnUI("SMS from radio " + radioID);
|
|||
|
};
|
|||
|
|
|||
|
SMSReceiveConnection.OnSMSAckReceived += delegate(byte[] received, string seq_no)
|
|||
|
{
|
|||
|
dbInterface.SMSAckReceived(received, seq_no);
|
|||
|
OnEventToDisplayOnUI("SMS ACK ");
|
|||
|
};
|
|||
|
#endregion
|
|||
|
|
|||
|
SMSReceiveThreadObj = new Thread(new ThreadStart(SMSReceiveConnection.handleConnection));
|
|||
|
SMSReceiveThreadObj.IsBackground = true;
|
|||
|
SMSReceiveThreadObj.Start();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void StartTelemetryService()
|
|||
|
{
|
|||
|
//create thread for receiving telemetry notifications from the radios
|
|||
|
TelemetryReceiveConnection = new TelemetryReceiveThread((ushort)cfg.TELEMETRY_PORT);
|
|||
|
#region TELEMETRY Received Events
|
|||
|
TelemetryReceiveConnection.OnTelemetryBytesReceived += delegate(Int64 radioID, byte[] received)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(radioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + radioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
telemetryStatistic.incoming++;
|
|||
|
dbInterface.TelemetryReceived(radioID, received);
|
|||
|
OnEventToDisplayOnUI("Telemetry from radio " + radioID);
|
|||
|
};
|
|||
|
#endregion
|
|||
|
|
|||
|
TelemetryReceiveThreadObj = new Thread(new ThreadStart(TelemetryReceiveConnection.handleConnection));
|
|||
|
TelemetryReceiveThreadObj.IsBackground = true;
|
|||
|
TelemetryReceiveThreadObj.Start();
|
|||
|
|
|||
|
//create thread for sending telemetry commands to the radios
|
|||
|
TelemetrySendConnection = new TelemetrySendThread((ushort)cfg.TELEMETRY_PORT);
|
|||
|
TelemetrySendThreadObj = new Thread(new ThreadStart(TelemetrySendConnection.handleConnection));
|
|||
|
TelemetrySendThreadObj.IsBackground = true;
|
|||
|
TelemetrySendThreadObj.Start();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void StartTallysmanService()
|
|||
|
{
|
|||
|
bool writeGatewayTallysmanStatus = false;
|
|||
|
|
|||
|
//create thread for receiving Tallysman notifications from the radios
|
|||
|
TallysmanReceiveConnection = new TallysmanReceiveThread((ushort)cfg.TALLYSMAN_PORT);
|
|||
|
|
|||
|
#region TALLYSMAN Received Events
|
|||
|
TallysmanReceiveConnection.OnLocationReceived += delegate(LocationEventArgs e)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(e.RadioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + e.RadioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
gpsStatistic.incoming++;
|
|||
|
OnEventToDisplayOnUI(String.Format("Position [{0:0.0000},{1:0.0000}] from {2}{3}{4}", Math.Round(e.Latitude, 4),
|
|||
|
Math.Round(e.Longitude, 4), e.RadioID,
|
|||
|
e.Altitude > 0 ? System.Environment.NewLine + "\t Altitude [" + e.Altitude + " meters]" : "",
|
|||
|
e.LevelOfConfidence > -1 ? "" + "\t Level of confidence ["
|
|||
|
+ e.LevelOfConfidence + "%]" : ""));
|
|||
|
|
|||
|
// insert gateway status for tallysman if connected
|
|||
|
if(!writeGatewayTallysmanStatus)
|
|||
|
{
|
|||
|
writeGatewayTallysmanStatus = true;
|
|||
|
AddGatewayStatusMessage(MotoRepeater_GW.cfg.GWCODE,
|
|||
|
(registered == REP_STATUS.ddmsUP ? true : false), "TALLYSMAN CONNECTED");
|
|||
|
}
|
|||
|
|
|||
|
dbInterface.LocationReceived(e);
|
|||
|
};
|
|||
|
|
|||
|
TallysmanReceiveConnection.OnTelemetryReceived += delegate(TelemetryReceivedEventArgs e)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(e.RadioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + e.RadioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
telemetryStatistic.incoming++;
|
|||
|
dbInterface.TelemetryReceived(e);
|
|||
|
OnEventToDisplayOnUI("Telemetry from radio " + e.RadioID);
|
|||
|
};
|
|||
|
|
|||
|
TallysmanReceiveConnection.OnTallysmanEventReceived += delegate(TallysmanEventArgs e)
|
|||
|
{
|
|||
|
// skip this event if the units is not assigned to this gateway
|
|||
|
if (!dbInterface.UnitIsAssignedToGw(e.RadioID + ""))
|
|||
|
{
|
|||
|
Utils.WriteLine("Unit " + e.RadioID + " not assigned to this gateway", ConsoleColor.Green);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
dbInterface.TallysmanEventReceived(e);
|
|||
|
};
|
|||
|
|
|||
|
#endregion
|
|||
|
TallysmanReceiveThreadObj = new Thread(new ThreadStart(TallysmanReceiveConnection.handleConnection));
|
|||
|
TallysmanReceiveThreadObj.IsBackground = true;
|
|||
|
TallysmanReceiveThreadObj.Start();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public int GetReportingInterval(string radioId)
|
|||
|
{
|
|||
|
return dbInterface.GetReportingIntervalForUnit(radioId);
|
|||
|
}
|
|||
|
|
|||
|
private void PerformeARSon(string SUID)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
//get reporting interval
|
|||
|
int report_time = dbInterface.GetReportingIntervalForUnit(SUID);
|
|||
|
|
|||
|
if (report_time != -1)
|
|||
|
{
|
|||
|
|
|||
|
if (report_time != 0)
|
|||
|
{
|
|||
|
Thread p = new Thread(delegate()
|
|||
|
{
|
|||
|
LocationThread.SendTriggeredLocationSTOP(SUID, LocationThread.REQ_ID, false);
|
|||
|
|
|||
|
int coun = 0;
|
|||
|
while (MotoRepeater_GW.isRunning && (coun++) < 6)
|
|||
|
{
|
|||
|
|
|||
|
Thread.Sleep(500);
|
|||
|
}
|
|||
|
|
|||
|
//Utils.ConsWrite(DebugMSG_Type.GPS, "Interval for SUID:" + SUID + " =" + report_time);
|
|||
|
//LocationThread.SendTriggeredLocationRequestCSBK(SUID, report_time);
|
|||
|
if (LocationThread.SendTriggeredLocationRequestWithLOC(SUID, report_time))
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI("Location request [" + report_time + " sec] for " + SUID);
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
p.Start();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Utils.WriteLine("SUID:" + SUID + " interval=0 , no GPS reporting needed.", ConsoleType.GPS);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Utils.WriteLine("SUID:" + SUID + " not found in DB / not assigned here", ConsoleType.GPS);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Utils.WriteLine("SUID:" + SUID + " ERROR in PerformeARSon", ConsoleType.ARS);
|
|||
|
Utils.WriteLine(ex.ToString(), ConsoleType.ALL);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void StartLinkEstablishment()
|
|||
|
{
|
|||
|
// start Voice MultiCast for SafeDispatch
|
|||
|
if (MotoRepeater_GW.appType == AppType.SAFEDISPATCH)
|
|||
|
{
|
|||
|
int dbIDSlot1 = 0;
|
|||
|
int dbIDSlot2 = 0;
|
|||
|
|
|||
|
// check what slots are registered in order to wireline register
|
|||
|
foreach (RadioGateway rg in MotoRepeater_GW.radioGWs)
|
|||
|
{
|
|||
|
if (rg.Imei == 1)
|
|||
|
dbIDSlot1 = rg.Id;
|
|||
|
else if (rg.Imei == 2)
|
|||
|
dbIDSlot2 = rg.Id;
|
|||
|
}
|
|||
|
|
|||
|
// do not create link Establishment if no gateway for any slot
|
|||
|
if (dbIDSlot1 == 0 && dbIDSlot2 == 0)
|
|||
|
return;
|
|||
|
|
|||
|
// save REPEATER IP and peer ID from the DB
|
|||
|
MotoRepeater_GW.cfg.MASTER_IP = MotoRepeater_GW.radioGWs[0].Ip;
|
|||
|
|
|||
|
|
|||
|
// update the master Repeater IP inside the config file
|
|||
|
Config.UpdateConfigParameter("NAI", "masterRepeaterIP", MotoRepeater_GW.cfg.MASTER_IP);
|
|||
|
|
|||
|
|
|||
|
//start voice bus for send
|
|||
|
if (dbIDSlot1 > 0)
|
|||
|
{
|
|||
|
string voiceMulticastIP4SendSlot1 = "224.10." + MotoRepeater_GW.cfg.GWID + "." + dbIDSlot1;
|
|||
|
voiceMulticastSlot1Send = new UdpMulticast(voiceMulticastIP4SendSlot1, 17234);
|
|||
|
|
|||
|
Utils.WriteLine("Slot 1 voice multicast " + voiceMulticastIP4SendSlot1, ConsoleColor.Yellow);
|
|||
|
|
|||
|
}
|
|||
|
if (dbIDSlot2 > 0)
|
|||
|
{
|
|||
|
string voiceMulticastIP4SendSlot2 = "224.10." + MotoRepeater_GW.cfg.GWID + "." + dbIDSlot2;
|
|||
|
voiceMulticastSlot2Send = new UdpMulticast(voiceMulticastIP4SendSlot2, 17234);
|
|||
|
|
|||
|
Utils.WriteLine("Slot 2 voice multicast " + voiceMulticastIP4SendSlot2, ConsoleColor.Yellow);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// create Link Establishment object
|
|||
|
linkEstablishment = new LinkEstablishment(MotoRepeater_GW.cfg.MASTER_IP, MotoRepeater_GW.cfg.MASTER_PORT,
|
|||
|
MotoRepeater_GW.cfg.PEER_ID, MotoRepeater_GW.cfg.PEER_PORT, LinkEstablishment.SystemReleaseNumber.R23A, MotoRepeater_GW.cfg.SYSTEM_TYPE);
|
|||
|
|
|||
|
linkEstablishment.SetMyselfPeerPort(MotoRepeater_GW.cfg.PEER_PORT);
|
|||
|
linkEstablishment.SetSystemType(MotoRepeater_GW.cfg.SYSTEM_TYPE);
|
|||
|
|
|||
|
|
|||
|
// register only desired slots
|
|||
|
linkEstablishment.SetRegisteredSlots(Wireline.SlotNumber.BothSlots);
|
|||
|
|
|||
|
// add event listener for when the link establishment is up
|
|||
|
linkEstablishment.OnRegistrationResponseReceived += delegate(Boolean isValid)
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI(String.Format("Link Establishment is {0}", isValid ? "up" : "down"));//"successful" : "unsuccessful"));
|
|||
|
|
|||
|
if(!isValid)
|
|||
|
OnEventToDisplayOnUI(String.Format("Please check Internet connection or Repeater IP & Port configuration"));
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
wireline = new Wireline(linkEstablishment);
|
|||
|
|
|||
|
// add event listener for when a station changes it's status
|
|||
|
wireline.OnRadioStatusChanged += delegate(Int64 radioID, MotoRepeater.Wireline.SlotNumber slot, Boolean isEnabled)
|
|||
|
{
|
|||
|
dbInterface.RadioEnableDisableStatusReceived(radioID, slot, isEnabled);
|
|||
|
|
|||
|
OnEventToDisplayOnUI(String.Format("Radio {1} is {0}", (isEnabled ? "Enable" : "Disable"), radioID));
|
|||
|
};
|
|||
|
|
|||
|
// add event listener for when an emergency is received
|
|||
|
wireline.OnEmergencyChanged += delegate(Int64 radioID, MotoRepeater.Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI(String.Format("Emergency from {0}", radioID));
|
|||
|
dbInterface.EmergencyReceived(radioID, slot);
|
|||
|
|
|||
|
// send poll request for this unit
|
|||
|
LocationThread.SendPollRequest(radioID+"");
|
|||
|
|
|||
|
};
|
|||
|
wireline.OnRegistrationReceived += delegate(Boolean isValid, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI(String.Format("Wireline registered on {0}", slot));
|
|||
|
};
|
|||
|
|
|||
|
wireline.OnCallStatusReceived += delegate(Int64 sourceID, Int64 targertID, int callType, int callStatus, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
|
|||
|
string callTypee = Definitions.GetCallStatus4UI(callStatus);
|
|||
|
if ((CallType)callType == CallType.ALLCALL)
|
|||
|
OnEventToDisplayOnUI(String.Format("{0} {1} from {2}", Definitions.GetCallType4UI(callType), Definitions.GetCallStatus4UI(callStatus), sourceID));
|
|||
|
else
|
|||
|
OnEventToDisplayOnUI(String.Format("{0} {1} from {2} to {3}", Definitions.GetCallType4UI(callType), Definitions.GetCallStatus4UI(callStatus), sourceID, targertID));
|
|||
|
|
|||
|
dbInterface.CallStatusBroadcastReceived(sourceID, targertID, (CallType)callType, (CallStatus)callStatus, slot);
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
wireline.OnAudioFrameReceived += delegate(byte[] audioFrame, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
// send the voice on appropiate voice multicast
|
|||
|
if (slot == Wireline.SlotNumber.Slot1)
|
|||
|
voiceMulticastSlot1Send.Send(audioFrame, audioFrame.Length);
|
|||
|
else
|
|||
|
voiceMulticastSlot2Send.Send(audioFrame, audioFrame.Length);
|
|||
|
};
|
|||
|
|
|||
|
// start registration via LE
|
|||
|
linkEstablishment.StartLinkEstablishment();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void StopLinkEstablishment()
|
|||
|
{
|
|||
|
if (linkEstablishment != null)
|
|||
|
linkEstablishment.StopLinkEstablishment();
|
|||
|
}
|
|||
|
|
|||
|
private void WirelineReg()
|
|||
|
{
|
|||
|
List<MotoRepeater.Wireline.RegEntry> listReg = new List<MotoRepeater.Wireline.RegEntry>();
|
|||
|
listReg.Add(new MotoRepeater.Wireline.RegEntry(MotoRepeater.Wireline.AddressType.AllIndividualCall, 1, 0xFFFFFF));
|
|||
|
//reg.regEntriesList.Add(new MotoRepeater.Wireline.RegEntry(MotoRepeater.Wireline.AddressType.AllTalkgroupCall, 1, 16772654));
|
|||
|
wireline.Register(Wireline.SlotNumber.Slot1, listReg);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void AddGatewayStatusMessage(Int64 gwCode, bool connected, string message)
|
|||
|
{
|
|||
|
|
|||
|
//add gateway status!!
|
|||
|
GWstatus gws = new GWstatus();
|
|||
|
gws.gw_id = gwCode + "";
|
|||
|
gws.status = connected ? 1 : 0;
|
|||
|
gws.message = message;
|
|||
|
SN_Queues.gwstatusQueue.PostItem(gws);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void Start()
|
|||
|
{
|
|||
|
Thread threadGatewayStart = new Thread(new ThreadStart(GatewayHandler));
|
|||
|
threadGatewayStart.Start();
|
|||
|
|
|||
|
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|||
|
AddGatewayStatusMessage(MotoRepeater_GW.cfg.GWCODE,
|
|||
|
(registered == REP_STATUS.ddmsUP ? true : false), "Started [" + v.ToString() + "]");
|
|||
|
|
|||
|
|
|||
|
// display the current Date to the console and register for midnight event
|
|||
|
// in order to display the new date each time
|
|||
|
OnEventToDisplayOnUI("Gateway started on " + DateTime.Today.ToLongDateString());
|
|||
|
MidnightNotifier.ItsMidnight += (s, e) =>
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI("Today is " + DateTime.Today.ToLongDateString());
|
|||
|
};
|
|||
|
MidnightNotifier.UserChangedDate += (s, e) =>
|
|||
|
{
|
|||
|
//MotoRepeater_GW.l
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Stop()
|
|||
|
{
|
|||
|
|
|||
|
AddGatewayStatusMessage(MotoRepeater_GW.cfg.GWCODE, false, "Stopping");
|
|||
|
|
|||
|
Thread.Sleep(400);
|
|||
|
|
|||
|
isRunning = false;
|
|||
|
StopLinkEstablishment();
|
|||
|
if (dbInterface != null)
|
|||
|
dbInterface.Stop();
|
|||
|
|
|||
|
if (LocationConnection != null)
|
|||
|
LocationConnection.StopLocationThread();
|
|||
|
|
|||
|
if (ddmsWatcher != null)
|
|||
|
ddmsWatcher.Stop();
|
|||
|
|
|||
|
if (udpClient != null)
|
|||
|
udpClient.Close();
|
|||
|
}
|
|||
|
|
|||
|
private void GatewayHandler()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (appType == AppType.SAFEDISPATCH)
|
|||
|
dbInterface = new DataBaseSD();
|
|||
|
else if (appType == AppType.SAFENET)
|
|||
|
{
|
|||
|
dbInterface = new DataBaseSN();
|
|||
|
((DataBaseSN)dbInterface).OnGPSInsertedBlocked += delegate ()
|
|||
|
{
|
|||
|
OnGPSInsertedBlocked?.Invoke();
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// add event listener for when a Poll request is received
|
|||
|
dbInterface.OnPollRequestReceived += delegate(object sender, PollRequestEventArgs e)
|
|||
|
{
|
|||
|
pollStatistic.outgoing++;
|
|||
|
OnEventToDisplayOnUI(String.Format("POLL request for {0}", e.RadioID));
|
|||
|
if(e.SeqID != 0)
|
|||
|
LocationThread.SendPollRequest(e.RadioID.ToString(), (byte)e.SeqID);
|
|||
|
else
|
|||
|
LocationThread.SendPollRequest(e.RadioID.ToString());
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
// add event listener for when a radio needs to be enabled/disabled
|
|||
|
dbInterface.OnRadioEnableDisableRequest += delegate(object sender, RadioEnableDisableRequestEventArgs e)
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI(String.Format("Radio {0} Request for {1}", (e.Enabled ? "Enable" : "Disble"), e.RadioID));
|
|||
|
if (e.Enabled)
|
|||
|
wireline.EnableRadioOnSlot(e.RadioID, e.Slot);
|
|||
|
else
|
|||
|
wireline.DisableRadioOnSlot(e.RadioID, e.Slot);
|
|||
|
};
|
|||
|
|
|||
|
// add event listener for when an emergency needs to be acknowledged
|
|||
|
dbInterface.OnEmergencyAckRequest += delegate(object sender, EmergencyAckEventArgs e)
|
|||
|
{
|
|||
|
OnEventToDisplayOnUI(String.Format("Emergency ACK for {0}", e.RadioID));
|
|||
|
wireline.EmergencyACKOnSlot(e.RadioID, e.Slot);
|
|||
|
};
|
|||
|
|
|||
|
// add event listener for when the gateway needs to report its channel
|
|||
|
dbInterface.OnChannelQuery += delegate(object sender, ChannelQueryEventArgs e)
|
|||
|
{
|
|||
|
dbInterface.SendChannelBroadcastMessage(e.RadioGwID);
|
|||
|
};
|
|||
|
|
|||
|
dbInterface.OnSMSRequestReceived += delegate(object sender, SMSRequestEventArgs e)
|
|||
|
{
|
|||
|
smsStatistic.outgoing++;
|
|||
|
OnEventToDisplayOnUI(String.Format("SMS to radio {0}", e.RadioID));
|
|||
|
SMSSendConnection.SendSMS(e.RadioID + "", e.message, e.isACKWanted, e.seqID);
|
|||
|
};
|
|||
|
|
|||
|
dbInterface.OnGroupSMSRequestReceived += delegate(object sender, SMSRequestEventArgs e)
|
|||
|
{
|
|||
|
smsStatistic.outgoing++;
|
|||
|
OnEventToDisplayOnUI(String.Format("SMS to group {0}", e.RadioID));
|
|||
|
SMSSendConnection.SendSMSGroup(e.GroupID + "", e.message, e.isACKWanted, e.seqID);
|
|||
|
};
|
|||
|
|
|||
|
dbInterface.OnTelemetryRequestReceived += delegate(object sender, TelemetryRequestEventArgs e)
|
|||
|
{
|
|||
|
telemetryStatistic.outgoing++;
|
|||
|
OnEventToDisplayOnUI(String.Format("Telemetry to radio {0}", e.RadioID));
|
|||
|
TelemetrySendConnection.sendTelemetryCommand(e.RadioID, e.GPIO, e.Type, (int)e.seqID);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
StartDDMSService();
|
|||
|
Thread.Sleep(100);
|
|||
|
StartGPSService();
|
|||
|
Thread.Sleep(100);
|
|||
|
StartSMSService();
|
|||
|
Thread.Sleep(100);
|
|||
|
StartTelemetryService();
|
|||
|
Thread.Sleep(100);
|
|||
|
StartTallysmanService();
|
|||
|
/*
|
|||
|
#region PRIVATECALL
|
|||
|
// intercept events for Private Call
|
|||
|
|
|||
|
dbInterface.OnInitPrivateCallRequest += delegate(Int64 radioID, string broadcastAddress, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
wireline.InitiatePrivateCallOnSlot(radioID, slot);
|
|||
|
};
|
|||
|
|
|||
|
dbInterface.OnEndPrivateCallRequest += delegate(Int64 radioID, string broadcastAddress, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
wireline.EndPrivateCallOnSlot(radioID, slot);
|
|||
|
};
|
|||
|
#endregion
|
|||
|
|
|||
|
#region GROUPCALL
|
|||
|
// intercept events for Group Call
|
|||
|
dbInterface.OnInitGroupCallRequest += delegate(Int64 groupID, string broadcastAddress, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
wireline.InitiateGroupCallOnSlot(groupID, slot);
|
|||
|
};
|
|||
|
|
|||
|
dbInterface.OnEndGroupCallRequest += delegate(Int64 groupID, string broadcastAddress, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
wireline.EndGroupCallOnSlot(groupID, slot);
|
|||
|
};
|
|||
|
#endregion
|
|||
|
|
|||
|
#region ALLCALL
|
|||
|
// intercept events for All Call
|
|||
|
dbInterface.OnInitAllCallRequest += delegate(string broadcastAddress, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
wireline.InitiateAllCallOnSlot(slot);
|
|||
|
};
|
|||
|
|
|||
|
dbInterface.OnEndAllCallRequest += delegate(string broadcastAddress, Wireline.SlotNumber slot)
|
|||
|
{
|
|||
|
wireline.EndAllCallOnSlot(slot);
|
|||
|
};
|
|||
|
#endregion
|
|||
|
*/
|
|||
|
//registered = REP_STATUS.started;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
registered = REP_STATUS.stoped;
|
|||
|
Utils.WriteLine("Exception in starting repeater thread." + ex.ToString(), ConsoleColor.Red);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public delegate void EventToDisplayOnUIDEl(string msg);
|
|||
|
public event EventToDisplayOnUIDEl OnEventToDisplayOnUI;
|
|||
|
|
|||
|
public delegate void GPSInsertedBlockedDel();
|
|||
|
public event GPSInsertedBlockedDel OnGPSInsertedBlocked;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public enum REP_STATUS
|
|||
|
{
|
|||
|
started = 0x00,
|
|||
|
stoped = 0x01,
|
|||
|
ddmsUP = 0x02,
|
|||
|
ddmsDOWN = 0x03
|
|||
|
};
|
|||
|
}
|