using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace IridiumTest { class IModem { private static byte[] txBytes = new byte[1024]; private const string a3laCSQ = "AT+CSQ\r"; public static int sendCSQ() { //Debug.Print(DateTime.Now + " Sending CSQ"); Array.Clear(txBytes, 0, txBytes.Length); Array.Copy(UTF8Encoding.UTF8.GetBytes(a3laCSQ), txBytes, a3laCSQ.Length); IridiumTest.Form1.iridiumPort.Write(txBytes, 0, a3laCSQ.Length); return (1); } private const string a3laD0 = "AT&D0\r"; public static void sendD0() { //Debug.Print(DateTime.Now + " Sending D0"); Array.Clear(txBytes, 0, txBytes.Length); Array.Copy(UTF8Encoding.UTF8.GetBytes(a3laD0), txBytes, a3laD0.Length); IridiumTest.Form1.iridiumPort.Write(txBytes, 0, a3laD0.Length); } private const string a3laK0 = "AT&K0\r"; public static void sendK0() { //Debug.Print(DateTime.Now + " Sending K0"); Array.Clear(txBytes, 0, txBytes.Length); Array.Copy(UTF8Encoding.UTF8.GetBytes(a3laK0), txBytes, a3laK0.Length); IridiumTest.Form1.iridiumPort.Write(txBytes, 0, a3laK0.Length); } private static byte[] sbdwtHeader = new byte[9] { (byte)65, (byte)84, (byte)43, (byte)83, (byte)66, (byte)68, (byte)87, (byte)84, (byte)13 }; // AT+SBDWT public static int loadSBDWT(string gpsString) { sbTemp.Clear(); sbTemp.Append(DateTime.Now.ToString("yyyy-MM-dd")); sbTemp.Append("T"); sbTemp.Append(DateTime.Now.ToString("HH:mm:ss")); sbTemp.Append("Z,"); sbTemp.Append("SQ = "); sbTemp.Append(SignalQuality.ToString()); sbTemp.Append(","); sbTemp.Append(gpsString); //Debug.Print(DateTime.Now + "SBDWT message = " + sbTemp.ToString()); IModem.sendSBDWT(UTF8Encoding.UTF8.GetBytes(sbTemp.ToString())); return (1); } private static readonly StringBuilder sbTemp = new StringBuilder(1024); public static void sendSBDWT(byte[] inBytes) { //Debug.Print(DateTime.Now + " Sending SBDWT"); IridiumTest.Form1.iridiumPort.Write(sbdwtHeader, 0, sbdwtHeader.Length); Thread.Sleep(2000); sbTemp.Clear(); sbTemp.Append(UTF8Encoding.UTF8.GetChars(inBytes)); //Debug.Print(DateTime.Now + " Sending:" + sbTemp.ToString()); IridiumTest.Form1.iridiumPort.Write(inBytes, 0, inBytes.Length); } private static readonly StringBuilder sbSBDD2 = new StringBuilder("AT+SBDD2\r"); public static int sendSBDD2() { //Debug.Print(DateTime.Now + " Sending SBDD2"); IridiumTest.Form1.iridiumPort.Write(UTF8Encoding.UTF8.GetBytes(sbSBDD2.ToString()), 0, sbSBDD2.Length); return (1); } private static readonly StringBuilder sbSBDI = new StringBuilder("AT+SBDI\r"); public static int sendSBDI() { //Debug.Print(DateTime.Now + " Sending SBDI"); Array.Clear(txBytes, 0, txBytes.Length); Array.Copy(UTF8Encoding.UTF8.GetBytes(sbSBDI.ToString()), txBytes, sbSBDI.Length); IridiumTest.Form1.iridiumPort.Write(txBytes, 0, sbSBDI.Length); return (1); } private static readonly StringBuilder sbSBDIX = new StringBuilder("AT+SBDIX\r"); public static void sendSBDIX() { //Debug.Print(DateTime.Now + " Sending SBDIX"); Array.Clear(txBytes, 0, txBytes.Length); Array.Copy(UTF8Encoding.UTF8.GetBytes(sbSBDI.ToString()), txBytes, sbSBDI.Length); IridiumTest.Form1.iridiumPort.Write(txBytes, 0, sbSBDI.Length); } static int SignalQuality; public static void parseSQ(byte[] inBytes) { if ((inBytes[0] == 43) && (inBytes[1] == 67) && (inBytes[2] == 83) && (inBytes[3] == 81)) SignalQuality = (int)inBytes[5] - 48; } } }