public SMS decodeSMSPDU(string message) { //on recupere le sms SMS sms = new SMS(); SMS.Fetch(sms, ref message); //afficherContenuMessagePDU(sms); return(sms); }
private static void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string indata = sp.ReadExisting(); int f; //Console.Write(indata); if (indata.IndexOf("OK") > 0) { lastAT = DateTime.Now; } if (indata.IndexOf("CMGL:") > 0) { string[] delimiter = new string[] { "CMGL:" }; String[] substrings = indata.Split(delimiter, StringSplitOptions.None); foreach (string substr in substrings) { if ((substr.IndexOf(",,") != -1)) { //Console.WriteLine(substr); try { f = Convert.ToInt32(substr.IndexOf(",")); } catch { continue; } string nummes = substr.Substring(1, f - 1); int n = substr.IndexOf('\n'); string str = ""; if (n != -1) { str = substr.Substring(n + 1, substr.Length - n - 2); } else { str = substr; } n = str.IndexOf('\r'); if (n != -1) { str = str.Substring(0, n); } SMSType smsType = SMSBase.GetSMSType(str); switch (smsType) { case SMSType.SMS: SMS sms = new SMS(); SMS.Fetch(sms, ref str); Console.WriteLine(sms.Message); Console.WriteLine(sms.PhoneNumber); //string databaseName = @"C:\Users\Rootkit\Desktop\WindowsService-master\ServiceSMS\bin\Debug\readsms.db"; SQLiteConnection db = new SQLiteConnection(string.Format("Data Source={0}; Version=3;", databaseName)); SQLiteCommand Command = db.CreateCommand(); Command.CommandText = "insert into smshistory (date,tel,message,UID) values (@Date,@tel,@message,@UID)"; string customFmt = "yyyy-MM-dd HH:mm:ss"; //2016-07-01 00:00:00 Command.Parameters.AddWithValue("@Date", sms.ServiceCenterTimeStamp.ToString(customFmt)); Command.Parameters.AddWithValue("@tel", sms.PhoneNumber); Command.Parameters.AddWithValue("@message", sms.Message); Command.Parameters.AddWithValue("@UID", Convert.ToString(Guid.NewGuid())); if (sms.Message != null) { db.Open(); Command.ExecuteNonQuery(); db.Close(); } port.Write("AT+CMGD=" + nummes + "\r\n"); //Console.WriteLine(sms._phoneNumber); break; } //string nummessage = substring.Substring(1, 3); //Console.WriteLine(nummessage); } } } }