using System; using System.Collections.Generic; using System.Linq; using System.Text; using SafeMobileLib; using System.Threading; namespace SDRgateway { class TestClass { public TestClass() { msgCell cell1 = new msgCell(); cell1.msg = MSG_TYPE.SMS; cell1.IMEI = "101"; cell1.sms = "MSG @ " + DateTime.Now; Program.smsINQueue.PostItem(cell1); for (int i = 1; i < 30; i++) { Thread.Sleep(1000); LIPSDR lipsdr = new LIPSDR(); LIP lip = new LIP(); lip.latitude = "45.12" + (i * 12).ToString(); lip.longitude = "25.98" + (i * 17).ToString(); lip.horizontalVelocity = ((i % 3) + ((i / 2) % 3)).ToString(); SM.Print("Adding LIP message to gps queue."); msgCell cell = new msgCell(); lipsdr.sourceaddress = "390807";//"10" + i.ToString(); //IMEI subscriber if (lipsdr.sourceaddress != "") cell.IMEI = lipsdr.sourceaddress; else SM.Print("subscriber == null"); //LAT latitude if (lip.latitude != "") cell.lat = lip.latitude; else SM.Print("latitude == null"); //LNG if (lip.longitude != "") cell.lng = lip.longitude; else SM.Print("longitude == null"); if (lip.timePositionHour == null || lip.timePositionHour == "") { lip.timePositionHour = DateTime.UtcNow.Hour.ToString(); } if (lip.timePositionMinute == null || lip.timePositionMinute == "") { lip.timePositionMinute = DateTime.UtcNow.Minute.ToString(); } if (lip.timePositionSecond == null || lip.timePositionSecond == "") { lip.timePositionSecond = DateTime.UtcNow.Second.ToString(); } //time DateTime time = new DateTime((int)DateTime.UtcNow.Year, (int)DateTime.UtcNow.Month, (int)DateTime.UtcNow.Day, (int)Convert.ToInt32(lip.timePositionHour), (int)Convert.ToInt32(lip.timePositionMinute), (int)Convert.ToInt32(lip.timePositionSecond)); SM.Print("time:" + time.ToString()); if (time != null) cell.time = time; else SM.Print("time == null"); //speed speed if (lip.horizontalVelocity.Contains("Horizontal speed is unknown")) { lip.horizontalVelocity = "0"; } if (lip.horizontalVelocity.Contains("km/h")) { lip.horizontalVelocity = lip.horizontalVelocity.Replace("km/h", ""); } //this is for knots //ulong spd = (ulong)(ulong.Parse( lip.horizontalVelocity) * 1.85325); ulong spd = ulong.Parse(lip.horizontalVelocity); if (spd != null) cell.spd = spd.ToString(); else SM.Print("spd == null"); //poll response cell.poll = 0; Program.gpsQueue.PostItem(cell); } } public static void TestMSG(string asciiData) { Console.WriteLine("asciiData:" + asciiData); //message decoder and display section LIPSDR lipsdr = new LIPSDR(); lipsdr.sdsDecoder(asciiData); ; Console.WriteLine("Raw Data: " + lipsdr.binarydata); Console.WriteLine("Source Address : " + lipsdr.sourceaddress); Console.WriteLine("Destination Address : " + lipsdr.destinationaddress); Console.WriteLine("Protocol Identifier: " + lipsdr.PIvalue); Console.WriteLine("Message Reference: " + lipsdr.messageReference); Console.WriteLine("User_data: " + lipsdr.User_data); Console.WriteLine("SDTS_TL_DATA_flags: " + lipsdr.SDTS_TL_DATA_flags); Console.WriteLine("CM_reply: " + lipsdr.CM_reply); Console.WriteLine("Reply: " + lipsdr.reply); if (lipsdr.PIvalue == "130") { //IF SMS this must be added msgCell cell = new msgCell(); cell.msg = MSG_TYPE.SMS; cell.IMEI = lipsdr.sourceaddress; cell.sms = lipsdr.User_data; Program.smsINQueue.PostItem(cell); //send ACK back // sending a report back int sourISSI = int.Parse(lipsdr.destinationaddress); int DestISSI = int.Parse(lipsdr.sourceaddress); byte[] REPORT_ACK = {0x00, 0x0f, 0x00, (byte)(((UInt32)sourISSI&0xff0000)>>16), // source ISSI (byte)(((UInt32)sourISSI&0x00ff00)>>8), (byte)(((UInt32)sourISSI&0x0000ff)), (byte)(((UInt32)DestISSI&0x00ff0000)>>16), // destination ISSI (byte)(((UInt32)DestISSI&0x0000ff00)>>8), (byte)(((UInt32)DestISSI&0x000000ff)), (byte)(byte.Parse(lipsdr.PIvalue)),// 0xc0, // protocol 0x60, // flags 0x00, // message reference 0x00, // area slection 0x00, 0x10, // TL length (bits) 0x01, // PDU type = Report 0x00 // Delivery status = ACK }; REPORT_ACK[11] = byte.Parse(lipsdr.messageReference); ; // msg_id } if (lipsdr.PIvalue == "10") { LIP lip = new LIP(); lip.decoder(lipsdr.User_data); int len = (int.Parse(lipsdr.TLlength_include_SDTS_TL_PDU_field) / 4) - 1; Console.WriteLine("User Data len: " + len); Console.WriteLine("pDUType: " + lip.pDUType); Console.WriteLine("Time Type : " + lip.timeType); Console.WriteLine("Time Elapsed :" + lip.timeElapsed); Console.WriteLine("timePositionDay: " + lip.timePositionDay); Console.WriteLine("timePositionHour: " + lip.timePositionHour); Console.WriteLine("timePositionMinute: " + lip.timePositionMinute); Console.WriteLine("timePositionSecond: " + lip.timePositionSecond); Console.WriteLine("locationShape: " + lip.locationShape); Console.WriteLine("longitude: " + lip.longitude); Console.WriteLine("latitude: " + lip.latitude); Console.WriteLine("horizontalVelocity: " + lip.horizontalVelocity); MSG_TYPE type = lipsdr.GetMSGtype(lipsdr.User_data, len); msgCell cell = new msgCell(); //IMEI subscriber if (lipsdr.sourceaddress != "") cell.IMEI = lipsdr.sourceaddress; else SM.Print("subscriber == null"); switch (type) { case MSG_TYPE.ARS_ON: { SM.Print("Adding ARS_ON message to eventQueue."); cell.msg = MSG_TYPE.ARS; cell.ars = 1; Program.eventQueue.PostItem(cell); break; } case MSG_TYPE.ARS_OFF: { SM.Print("Adding ARS_OFF message to eventQueue."); cell.msg = MSG_TYPE.ARS; cell.ars = 0; Program.eventQueue.PostItem(cell); break; } case MSG_TYPE.Emergency: { SM.Print("Adding Emergency message to eventQueue."); cell.msg = MSG_TYPE.Emergency; Program.eventQueue.PostItem(cell); break; } case MSG_TYPE.GPS: { SM.Print("Adding LIP message to gps queue."); //LAT latitude if (lip.latitude != "") cell.lat = lip.latitude; else SM.Print("latitude == null"); //LNG if (lip.longitude != "") cell.lng = lip.longitude; else SM.Print("longitude == null"); if (lip.timePositionHour == null || lip.timePositionHour == "") { lip.timePositionHour = DateTime.UtcNow.Hour.ToString(); } if (lip.timePositionMinute == null || lip.timePositionMinute == "") { lip.timePositionMinute = DateTime.UtcNow.Minute.ToString(); } if (lip.timePositionSecond == null || lip.timePositionSecond == "") { lip.timePositionSecond = DateTime.UtcNow.Second.ToString(); } //time DateTime time = new DateTime((int)DateTime.UtcNow.Year, (int)DateTime.UtcNow.Month, (int)DateTime.UtcNow.Day, (int)Convert.ToInt32(lip.timePositionHour), (int)Convert.ToInt32(lip.timePositionMinute), (int)Convert.ToInt32(lip.timePositionSecond)); if (time != null) cell.time = time; else SM.Print("time == null"); Utils.WriteLine("Horizontal Velocity: " + lip.horizontalVelocity); //speed speed ulong spd = 0; if (!ulong.TryParse(lip.horizontalVelocity, out spd)) lip.horizontalVelocity = "0"; if (lip.horizontalVelocity.Contains("Horizontal speed is unknown")) { lip.horizontalVelocity = "0"; } if (lip.horizontalVelocity.Contains("km/h")) { lip.horizontalVelocity = lip.horizontalVelocity.Replace("km/h", ""); } //this is for knots //ulong spd = (ulong)(ulong.Parse( lip.horizontalVelocity) * 1.85325); spd = ulong.Parse(lip.horizontalVelocity); if (spd != null) cell.spd = spd.ToString(); else SM.Print("spd == null"); //poll response cell.poll = 0; Program.gpsQueue.PostItem(cell); break; } } } } } }