/// <summary> /// Lese Statusreport-SMS Modemspeicher, melde und lösche den Statusreport anschließend. /// ACHTUNG: Überprüfung des Reports /// </summary> /// <param name="input"></param> private static void ParseStatusReport(string input) { if (input == null) { return; } try { //+CMGL: < index > , < stat > , < fo > , < mr > , [ < ra > ], [ < tora > ], < scts > , < dt > , < st > //[... ] //OK //<st> 0-31 erfolgreich versandt; 32-63 versucht weiter zu senden: 64-127 Sendeversuch abgebrochen //z.B.: +CMGL: 1,"REC READ",6,34,,,"20/11/06,16:08:45+04","20/11/06,16:08:50+04",0 //Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",(\d+),(\d+),,,""(.+)"",""(.+)"",(\d+)\r\n"); Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",(\d+),(\d+),,,""(.+)"",""(.+)"",(\d+)"); Match m = r.Match(input); while (m.Success) { Sms smsReport = new Sms(); smsReport.SetIndex(m.Groups[1].Value); //<index> smsReport.Status = m.Groups[2].Value; //<stat> smsReport.FirstOctet = byte.Parse(m.Groups[3].Value); //<fo> smsReport.MessageReference = byte.Parse(m.Groups[4].Value); //<mr> //sms.SmsProviderTimeStamp = GsmConverter.ReadDateTime(m.Groups[5].Value); //<scts: ServiceCenterTimeStamp> smsReport.SmsProviderTimeStamp = GsmConverter.ReadDateTime(m.Groups[6].Value); //<dt: DischargeTime> smsReport.SendStatus = byte.Parse(m.Groups[7].Value); //<st> //Für Wiedererkennung Werte aus 'Orignal-SMS' einfügen Sms smsTracking = SmsTrackingQueue.Find(x => x.MessageReference == smsReport.MessageReference); if (smsTracking != null) { smsReport.Message = smsTracking.Message; smsReport.Phone = smsTracking.Phone; SmsTrackingQueue.Remove(smsTracking); MelBox2.GlobalProperty.SmsPendingReports = SmsTrackingQueue.Count; } if (smsReport.Status == "REC UNREAD" || smsReport.Status == "REC READ") { RaiseSmsStatusreportEvent(smsReport); #if DEBUG DebugShowSms(smsReport, "Sendebestätigung von Modem"); #endif SmsToDelete.Add(smsReport.Index); } m = m.NextMatch(); } SmsDeletePending(); } catch (Exception ex) { throw new Exception(string.Format("ParseStatusReport() {0}\r\n{1}\r\n{2}", ex.GetType(), ex.Message, ex.InnerException)); } }
/// <summary> /// Lese SMS-Textnachricht aus Modemspeicher, melde und lösche die Nachricht anschließend. /// </summary> /// <param name="input"></param> private static void ParseSmsMessages(string input) { if (input == null) { return; } try { #region comment /* +CMGL: <index> , <stat> , <oa> / <da> , [ <alpha> ], [ <scts> ][, <tooa> / <toda> , <length> ] * <data> * [... ] * OK * +CMGL: 9,"REC READ","+4917681371522",,"20/11/08,13:47:10+04" * Ein Test 08.11.2020 13:46 PS sms38.de * //*/ #endregion Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""(.+|\n)+?(?=OK)"); //SAMBA75 //Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n"); //SAMBA75 //Regex r = new Regex(@"(\d+),(.+\s.+),(.+),(.+),(.+),(.+),(.+)\n{2}"); //SAMSUNG GALAXY A3 Match m = r.Match(input.Replace('\n', ' ')); while (m.Success) { Sms sms = new Sms(); sms.SetIndex(m.Groups[1].Value); sms.Status = m.Groups[2].Value; sms.Phone = GsmConverter.StrToPhone(m.Groups[3].Value); sms.Name = m.Groups[4].Value; sms.SetTimeStamp(m.Groups[5].Value); sms.Message = m.Groups[6].Value; if (sms.Status == "REC UNREAD" || sms.Status == "REC READ") { RaiseSmsRecievedEvent(sms); #if DEBUG DebugShowSms(sms, "SMS von Modem"); #endif SmsToDelete.Add(sms.Index); } m = m.NextMatch(); } SmsDeletePending(); } catch (Exception ex) { throw ex; } }
/// <summary> /// Lese Statusreport-SMS, lösche bei erfolgreichem Senden SMS aus Sendungsverfolgung /// </summary> /// <param name="input"></param> private void ParseStatusReport(string input) { if (input == null) return; try { //+CMGL: < index > , < stat > , < fo > , < mr > , [ < ra > ], [ < tora > ], < scts > , < dt > , < st > //[... ] //OK //<st> 0-31 erfolgreich versandt; 32-63 versucht weiter zu senden: 64-127 Sendeversuch abgebrochen //z.B.: +CMGL: 1,"REC READ",6,34,,,"20/11/06,16:08:45+04","20/11/06,16:08:50+04",0 //Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",(\d+),(\d+),,,""(.+)"",""(.+)"",(\d+)\r\n"); Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",(\d+),(\d+),,,""(.+)"",""(.+)"",(\d+)"); Match m = r.Match(input); if(m.Length > 0) { DebugTracking(); } while (m.Success) { byte.TryParse(m.Groups[1].Value, out byte index); string status = m.Groups[2].Value; byte trackingId = byte.Parse(m.Groups[4].Value); Console.WriteLine("Status-report für SMS-Index {0} erhalten.", trackingId); byte trackingStatus = byte.Parse(m.Groups[7].Value); if (status != "REC UNREAD" && status != "REC READ") continue; //nur empfangene Nachrichten Sms confirmedSms = SmsQueue.FindAll(x => x.TrackingId == trackingId).FirstOrDefault(); if (confirmedSms != null) { confirmedSms.SendStatus = trackingStatus; OnRaiseSmsStatusreportEvent(confirmedSms); if (confirmedSms.SendStatus < 32) //SMS erfolgreich versendet { SmsQueue.Remove(confirmedSms); } } SmsToDelete.Add(index); //Diesen Statusreport löschen m = m.NextMatch(); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Lese SMS-Textnachricht, melde und lösche die Nachricht anschließend. /// </summary> /// <param name="input"></param> private void ParseRecMessages(string input) { if (input == null) return; try { #region comment /* Output if text mode ( AT+CMGF =1) and command successful: For SMS-DELIVER +CMGR: <stat> , <oa> , [ <alpha> ], <scts> [, <tooa> , <fo> , <pid> , <dcs> , <sca> , <tosca> , <length> ] <data> [... ] OK For SMS-SUBMIT +CMGR: <stat> , <da> , [ <alpha> ][, <toda> , <fo> , <pid> , <dcs> , [ <vp> ], <sca> , <tosca> , <length> ] <data> [... ] OK For SMS-STATUS-REPORT +CMGR: <stat> , <fo> , <mr> , [ <ra> ], [ <tora> ], <scts> , <dt> , <st> <data> [... ] OK <stat> : Status {string} <oa> Originating Address (Quellle) {string} <da> Destination Address (Ziel) {string} <fo> First Octet Status-Byte (keine Erklärung gefunden) {byte} <mr> Message Reference (= Bezugs-Id in Statusreport) {byte} <svcts> ServiceCenterTimeStamp {string} <toda> / <tora> / <tooa> Byte Typ der Ziel-/Empfängeradresse 145 = "+49...", sonst 129 {byte} +CMGL: 9,"REC READ","+4917681371522",,"20/11/08,13:47:10+04" Ein Test 08.11.2020 13:46 PS sms38.de //*/ #endregion Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n"); //SAMBA75 //Regex r2 = new Regex(@"(\d+),(.+\s.+),(.+),(.+),(.+),(.+),(.+)\n{2}"); //SAMSUNG GALAXY A3 Match m = r.Match(input); while (m.Success) { Sms sms = new Sms(); sms.SetIndex(m.Groups[1].Value); sms.Status = m.Groups[2].Value; sms.Phone = StrToPhone(m.Groups[3].Value); sms.Content = m.Groups[6].Value; if (sms.Status == "REC UNREAD" || sms.Status == "REC READ") { OnRaiseSmsRecievedEvent(sms); SmsToDelete.Add(sms.Index); } m = m.NextMatch(); } } catch (Exception ex) { throw ex; } }