using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using SN_Server; using SN_Server.ServerMSGS; using System.Net; using System.Net.Sockets; using System.Net.NetworkInformation; namespace Simulator_CS_GTW { public partial class Form1 : Form { private System.Threading.Timer tServerConnection; private System.Threading.Timer tPingPong; private System.Threading.Timer tCheckCSList; private System.Threading.Timer tCheckUnitList; private System.Threading.Timer tCheckSMSlist; private System.Threading.Timer tCheckPolllist; private System.Threading.Timer tReportPollACK; private System.Threading.Timer tReportTM; private System.Threading.Timer tReportARS; private System.Threading.Timer tReportPosition; private ServerConnector _sc; private bool isConnected = false; private string localIP = "127.0.0.1"; //private String serial = "000B68542G52"; //private String[] serials = { "000B28063B53", "000B68542G52", "051W3213H340", "005G8544W550", "101B4410A000", "994B1085G890", "95001DSAKA01" }; //private String[] serials = { "000B28063B53", "000B68542G52", "051W3213H340", "005G8544W550", "101B4410A000", "994B1085G890", "95001DSAKA01" }; private UnitList unitList = new UnitList(); public Form1() { InitializeComponent(); foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { //Console.WriteLine(ni.Name); if(!ni.Name.Contains("VM")) foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { localIP = ip.Address.ToString(); Console.WriteLine(ip.Address.ToString()); } } } } } private void Form1_Load(object sender, EventArgs e) { //Random rnd = new Random(); //serial = serials[rnd.Next(1, 7)]; // serial = GeneratePassword(); } private void ReportPositionCallBack(Object state) { if (cbPosRep.Checked) { for (int j = 0; j < unitList.Count; j++) { double lat = 43.65354 + j * 0.001; double lng = -86.39612 + j * 0.001; double speed = j % 90; String gpsTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; String msg = GenMsg(0xB011, textBoxSerial.Text, unitList.getUnitAtPosition(j).DBid + "/" + lat + "/" + lng + "/" + speed + "/" + gpsTime); if (_sc != null) { byte[] dataMsg = System.Text.Encoding.ASCII.GetBytes(msg); _sc.Send(dataMsg, dataMsg.Length); } } } tReportPosition.Change(new TimeSpan(0, 0, Int32.Parse(tbIntARSRep.Text)), new TimeSpan(System.Threading.Timeout.Infinite)); } private void ReportARSCallBack(Object state) { if (cbARSRep.Checked) { for (int j=0; j