public override async Task <IList <SmsWithIndex> > ListSmssAsync(SmsStatus smsStatus) { (AtError error, AtResponse response) = await channel.SendMultilineCommand($"AT+CMGL=\"{SmsStatusHelpers.ToString(smsStatus)}\"", null); List <SmsWithIndex> smss = new List <SmsWithIndex>(); if (error == AtError.NO_ERROR) { for (int i = 0; i < response.Intermediates.Count; i += 2) { string metaData = response.Intermediates[i]; var match = Regex.Match(metaData, @"\+CMGL:\s(?<index>\d+),""(?<status>[A-Z\s]+)"",""(?<sender>\+?\d+)"",("""")?,""(?<received>(?<year>\d\d)/(?<month>\d\d)/(?<day>\d\d),(?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)(?<zone>[-+]\d\d))"""); if (match.Success) { int index = int.Parse(match.Groups["index"].Value); SmsStatus status = SmsStatusHelpers.ToSmsStatus(match.Groups["status"].Value); PhoneNumber sender = new PhoneNumber(match.Groups["sender"].Value); int year = int.Parse(match.Groups["year"].Value); int month = int.Parse(match.Groups["month"].Value); int day = int.Parse(match.Groups["day"].Value); int hour = int.Parse(match.Groups["hour"].Value); int minute = int.Parse(match.Groups["minute"].Value); int second = int.Parse(match.Groups["second"].Value); int zone = int.Parse(match.Groups["zone"].Value); DateTimeOffset received = new DateTimeOffset(2000 + year, month, day, hour, minute, second, TimeSpan.FromMinutes(15 * zone)); string message = response.Intermediates[i + 1]; smss.Add(new SmsWithIndex(index, status, sender, received, message)); } } } return(smss); }
public override async Task <Sms> ReadSmsAsync(int index) { (AtError error, AtResponse response) = await channel.SendMultilineCommand($"AT+CMGR={index}", null); if (error == AtError.NO_ERROR && response.Intermediates.Count > 0) { string line = response.Intermediates.First(); var match = Regex.Match(line, @"\+CMGR:\s""(?<status>[A-Z\s]+)"",""(?<sender>\+?\d+)"",("""")?,""(?<received>(?<year>\d\d)/(?<month>\d\d)/(?<day>\d\d),(?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)(?<zone>[-+]\d\d))"""); if (match.Success) { SmsStatus status = SmsStatusHelpers.ToSmsStatus(match.Groups["status"].Value); PhoneNumber sender = new PhoneNumber(match.Groups["sender"].Value); int year = int.Parse(match.Groups["year"].Value); int month = int.Parse(match.Groups["month"].Value); int day = int.Parse(match.Groups["day"].Value); int hour = int.Parse(match.Groups["hour"].Value); int minute = int.Parse(match.Groups["minute"].Value); int second = int.Parse(match.Groups["second"].Value); int zone = int.Parse(match.Groups["zone"].Value); DateTimeOffset received = new DateTimeOffset(2000 + year, month, day, hour, minute, second, TimeSpan.FromMinutes(15 * zone)); string message = response.Intermediates.Last(); return(new Sms(status, sender, received, message)); } } return(null); }