public static void Fetch(SMSStatusReport statusReport, ref string source) { SMSBase.Fetch(statusReport, ref source); statusReport._messageReference = PopByte(ref source); statusReport._phoneNumber = PopPhoneNumber(ref source); statusReport._serviceCenterTimeStamp = PopDate(ref source); statusReport._reportTimeStamp = PopDate(ref source); statusReport._reportStatus = (ReportStatus)PopByte(ref source); }
public static void Fetch(SMSBase sms, ref string source) { sms._serviceCenterNumber = PopServiceCenterAddress(ref source); sms._pduType = PopByte(ref source); System.Collections.BitArray bits = new System.Collections.BitArray(new byte[] { sms._pduType }); sms.ReplyPathExists = bits[7]; sms.UserDataStartsWithHeader = bits[6]; sms.StatusReportIndication = bits[5]; sms.ValidityPeriodFormat = (ValidityPeriodFormat)(sms._pduType & 0x18); sms.Direction = (SMSDirection)(sms._pduType & 1); }
public static void Fetch(SMS sms, ref string source) { SMSBase.Fetch(sms, ref source); if (sms._direction == SMSDirection.Submited) { sms._messageReference = PopByte(ref source); } sms._phoneNumber = PopPhoneNumber(ref source); sms._protocolIdentifier = PopByte(ref source); sms._dataCodingScheme = PopByte(ref source); if (sms._direction == SMSDirection.Submited) { if (sms._validityPeriod != 0x00) { sms._validityPeriod = PopByte(ref source); } } if (sms._direction == SMSDirection.Received) { sms._serviceCenterTimeStamp = PopDate(ref source); } sms._userData = source; if (source == string.Empty) { return; } int userDataLength = PopByte(ref source); if (userDataLength == 0) { return; } if (sms._userDataStartsWithHeader) { byte userDataHeaderLength = PopByte(ref source); sms._userDataHeader = PopBytes(ref source, userDataHeaderLength); userDataLength -= userDataHeaderLength + 1; } if (userDataLength == 0) { return; } switch ((SMSEncoding)sms._dataCodingScheme & SMSEncoding.ReservedMask) { case SMSEncoding._7bit: sms._message = Decode7bit(source, userDataLength); break; case SMSEncoding._8bit: sms._message = Decode8bit(source, userDataLength); break; case SMSEncoding.UCS2: sms._message = DecodeUCS2(source, userDataLength); break; } }
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); } } } }
public static void Fetch(SMSBase sms, ref string source) { sms._serviceCenterNumber = PopServiceCenterAddress(ref source); sms._pduType = PopByte(ref source); System.Collections.BitArray bits = new System.Collections.BitArray(new byte[] { sms._pduType }); sms.ReplyPathExists = bits[7]; sms.UserDataStartsWithHeader = bits[6]; sms.StatusReportIndication = bits[5]; sms.ValidityPeriodFormat = (ValidityPeriodFormat) (sms._pduType & 0x18); sms.Direction = (SMSDirection) (sms._pduType & 1); }