119 lines
4.4 KiB
C#
119 lines
4.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Collections;
|
|||
|
using System.Net.Sockets;
|
|||
|
|
|||
|
namespace CPlus_GW
|
|||
|
{
|
|||
|
public class CPlusGW
|
|||
|
{
|
|||
|
|
|||
|
public string gatewayID;
|
|||
|
public bool status = false;
|
|||
|
|
|||
|
public static InterthreadMessageQueue<MotoTRBOcmdMsg> locationQueue = new InterthreadMessageQueue<MotoTRBOcmdMsg>();
|
|||
|
public static InterthreadMessageQueue<htCell_t> DBQueueLocation = new InterthreadMessageQueue<htCell_t>();
|
|||
|
public static InterthreadMessageQueue<OC4Jrfid> DBQueueRFID = new InterthreadMessageQueue<OC4Jrfid>();
|
|||
|
public static InterthreadMessageQueue<SMSmsg> sendSMSQueue = new InterthreadMessageQueue<SMSmsg>();
|
|||
|
public static ArrayList waitConfSMSList = new ArrayList();
|
|||
|
public static InterthreadMessageQueue<SMSmsg> confSMSQueue = new InterthreadMessageQueue<SMSmsg>();
|
|||
|
|
|||
|
//queue for GUI display
|
|||
|
public static InterthreadMessageQueue<string> TextQueue = new InterthreadMessageQueue<string>();
|
|||
|
|
|||
|
public static UdpClient smsUDPclient = null;
|
|||
|
|
|||
|
LocationThread LocationConnection = null; // the threads for the 5 services we handle(ARS/watcher thread is started in StartARSService)
|
|||
|
//DBconnThread DBConnection = null;
|
|||
|
ReceiveSMSThread ReceiveSMSthr = null;
|
|||
|
SendSMSThread SendSMSthr = null;
|
|||
|
|
|||
|
|
|||
|
Thread LocationThreadobj = null;
|
|||
|
Thread ReceiveSMSThreadobj = null;
|
|||
|
Thread SendSMSThreadobj = null;
|
|||
|
|
|||
|
WatcherServerThread server;
|
|||
|
|
|||
|
public CPlusGW()
|
|||
|
{
|
|||
|
|
|||
|
if (Program.cfg.errorMSG != "")
|
|||
|
{
|
|||
|
Console.WriteLine("Error reading config file.\n\rPlease press any key to exit!!!");
|
|||
|
TextQueue.PostItem("Error reading config file.Please check \"GWconfig.ini\"");
|
|||
|
//Console.ReadKey();
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
public void Start()
|
|||
|
{
|
|||
|
//MotoTRBOGW p = new MotoTRBOGW();
|
|||
|
try
|
|||
|
{
|
|||
|
if(smsUDPclient ==null)
|
|||
|
smsUDPclient = new UdpClient(Program.cfg.smsPort_r);
|
|||
|
StartARSService();
|
|||
|
StartLocationService();
|
|||
|
StartSMSService();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
SafeMobileLib.Utils.WriteLine("CPlusGW Start Exception: " + ex.ToString(), ConsoleColor.Red);
|
|||
|
}
|
|||
|
status = true;
|
|||
|
//p.StartOC4JService();
|
|||
|
}
|
|||
|
|
|||
|
public void Stop()
|
|||
|
{
|
|||
|
//smsUDPclient.Close();
|
|||
|
server.Stop();
|
|||
|
status = false;
|
|||
|
}
|
|||
|
|
|||
|
void StartARSService()
|
|||
|
{
|
|||
|
SafeMobileLib.Utils.WriteLine("Starting Location Service", ConsoleColor.DarkMagenta);
|
|||
|
server = new WatcherServerThread(Program.cfg.ctrlIP, Program.cfg.arsPort, gatewayID, Program.cfg.report);
|
|||
|
server.Start();
|
|||
|
//server.SubscribeALL(cfg.dialogid);
|
|||
|
server.SubscribeALL(1234);
|
|||
|
}
|
|||
|
|
|||
|
public void StartLocationService()
|
|||
|
{
|
|||
|
SafeMobileLib.Utils.WriteLine("Starting Location Service", ConsoleColor.DarkMagenta);
|
|||
|
// create thread to listen UDP
|
|||
|
LocationConnection = new LocationThread();
|
|||
|
LocationConnection.port = Program.cfg.locPort_r;
|
|||
|
//LocationConnection.parent = this;
|
|||
|
LocationThreadobj = new Thread(new ThreadStart(LocationConnection.HandleConnection));
|
|||
|
LocationThreadobj.IsBackground = true;
|
|||
|
LocationThreadobj.Start();
|
|||
|
}
|
|||
|
|
|||
|
public void StartSMSService()
|
|||
|
{
|
|||
|
|
|||
|
SafeMobileLib.Utils.WriteLine("Starting SMS Service", ConsoleColor.DarkMagenta);
|
|||
|
// create thread to listen UDP
|
|||
|
ReceiveSMSthr = new ReceiveSMSThread((ushort)Program.cfg.smsPort_r, gatewayID);
|
|||
|
//ARSConnection.parent = this;
|
|||
|
ReceiveSMSThreadobj = new Thread(new ThreadStart(ReceiveSMSthr.HandleConnection));
|
|||
|
ReceiveSMSThreadobj.IsBackground = true;
|
|||
|
ReceiveSMSThreadobj.Start();
|
|||
|
|
|||
|
// create thread to listen UDP
|
|||
|
SendSMSthr = new SendSMSThread(Program.cfg.smsPort);
|
|||
|
//ARSConnection.parent = this;
|
|||
|
SendSMSThreadobj = new Thread(new ThreadStart(SendSMSthr.HandleConnection));
|
|||
|
SendSMSThreadobj.IsBackground = true;
|
|||
|
SendSMSThreadobj.Start();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|