SPDUSMS[] ReadPDUOutboxSMS(string pdu, out int[] index, out int[] message_status, out string[] address_text) { //RPDUSMS pdusms = new RPDUSMS(); /* +CMGL: 0,3,,22 * 07919772929090F011000B819830232933F10008FF080074006500730074 * OK */ //07 919772929090F0 11 00 0B 81 9830232933F1 00 08 FF 08 0074006500730074 string pat1 = @"\+CMGL:\s(?<index>[0-9]+),(?<message_status>[0-9]+),(?<address_text>[0-9A-Za-z\-]*),(?<TPDU_length>[0-9]+)(\r\n)(?<SMSC_number_and_TPDU>[0-9A-F]+)[\r\n]"; Regex reg1 = new Regex(pat1, RegexOptions.IgnoreCase); MatchCollection m = reg1.Matches(pdu); SPDUSMS[] pdusms = new SPDUSMS[m.Count]; index = new int[m.Count]; message_status = new int[m.Count]; address_text = new string[m.Count]; for (int i = 0; i < m.Count; i++) { //ret[i] = m[i].Groups["addr"].Value; index[i] = int.Parse(m[i].Groups["index"].Value); message_status[i] = int.Parse(m[i].Groups["message_status"].Value); address_text[i] = m[i].Groups["address_text"].Value; string stpdu = m[i].Groups["SMSC_number_and_TPDU"].Value; int cursor = 0; pdusms[i].SMSC_num_len = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor = 2; if (pdusms[i].SMSC_num_len != 0x00) { pdusms[i].SMSC_type_of_num = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; int chread = ((int)pdusms[i].SMSC_num_len * 2) - 2;//2-длина SMSC_num_len pdusms[i].SMSC_num = BCDUnFixNum(stpdu.Substring(cursor, chread)); cursor += chread; } else { pdusms[i].SMSC_type_of_num = 0x00; pdusms[i].SMSC_num = string.Empty; } pdusms[i].TPDU = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; pdusms[i].MR = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; pdusms[i].DA_ref_len = Convert.ToByte(stpdu.Substring(cursor, 2), 16);//TODO не нашел, что делать, но говорят, что мб 0x00 cursor += 2; pdusms[i].DA_type_of_num = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; int DA_num_len = (int)pdusms[i].DA_ref_len; if (DA_num_len % 2 > 0) { DA_num_len++; } pdusms[i].DA_num = BCDUnFixNum(stpdu.Substring(cursor, DA_num_len)); cursor += DA_num_len; pdusms[i].PID = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; pdusms[i].DCS = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; pdusms[i].VP = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; pdusms[i].UDL = Convert.ToByte(stpdu.Substring(cursor, 2), 16); cursor += 2; switch (pdusms[i].DCS) { case (byte)DEncProtocol.SbitDefault: { pdusms[i].UD = PDU7bToString(stpdu.Substring(cursor)); } break; case (byte)DEncProtocol.UTF7: { pdusms[i].UD = USC2toString(stpdu.Substring(cursor)); } break; default: { pdusms[i].UD = PDU7bToString(stpdu.Substring(cursor)); } break; } } return(pdusms); }
/// <summary> /// Компиляця строки к отправке SMS /// </summary> /// <param name="smsc_num"></param> /// <param name="tsmsc_num"></param> /// <param name="da_num"></param> /// <param name="tda_num"></param> /// <param name="ep"></param> /// <param name="TimeLife"></param> /// <param name="text"></param> /// <param name="pdu_len">Длина PDU, исключая блок SCA</param> /// <returns></returns> string GetPDUSendStr(string smsc_num, TypeOfNumber tsmsc_num, string da_num, TypeOfNumber tda_num, DEncProtocol ep, string text, out int pdu_len) { int len_sca = 1; SPDUSMS spdusms = new SPDUSMS(); string res = string.Empty; if (smsc_num.Length == 0) { spdusms.SMSC_num_len = 0x00; spdusms.SMSC_type_of_num = 0x00; spdusms.SMSC_num = string.Empty; res += "00"; } else { spdusms.SMSC_type_of_num = (byte)tsmsc_num; spdusms.SMSC_num = BCDFixNum(smsc_num); len_sca += 1 + (spdusms.SMSC_num.Length / 2); spdusms.SMSC_num_len = (byte)(len_sca - 1); res += string.Format("{0:X2}", spdusms.SMSC_num_len) + string.Format("{0:X2}", spdusms.SMSC_type_of_num) + spdusms.SMSC_num; } spdusms.TPDU = 0x31;//Отчет о доставке, вр.жизни далее 1 байт res += string.Format("{0:X2}", spdusms.TPDU); spdusms.MR = 0x00; res += string.Format("{0:X2}", spdusms.MR); spdusms.DA_ref_len = (byte)da_num.Length; res += string.Format("{0:X2}", spdusms.DA_ref_len); spdusms.DA_type_of_num = (byte)tda_num; res += string.Format("{0:X2}", spdusms.DA_type_of_num); spdusms.DA_num = BCDFixNum(da_num); res += spdusms.DA_num; spdusms.PID = 0x00; res += string.Format("{0:X2}", spdusms.PID); spdusms.DCS = (byte)ep; res += string.Format("{0:X2}", spdusms.DCS); spdusms.VP = 0xAA; res += string.Format("{0:X2}", spdusms.VP); string[] rt = new string[2]; switch (ep) { case DEncProtocol.SbitDefault: { rt = StringToPDU7b(text); spdusms.UDL = Convert.ToByte(rt[0], 16); spdusms.UD = rt[1]; } break; case DEncProtocol.UTF7: { rt = StringToUCS2(text); spdusms.UDL = Convert.ToByte(rt[0], 16); spdusms.UD = rt[1]; } break; default: break; } res += rt[0] + rt[1]; pdu_len = (res.Length / 2) - len_sca; return(res); }