//fonction qui affiche le contenu d'un message PDU public void afficherContenuMessagePDU(SMS unSMS) { Console.Out.WriteLine("--------- Contenu message PDU ------------"); Console.Out.WriteLine("Expediteur : " + unSMS.PhoneNumber); Console.Out.WriteLine("Message : " + unSMS.Message); Console.Out.WriteLine("Date : " + unSMS.ServiceCenterTimeStamp); Console.Out.WriteLine("Accuse reception : " + unSMS.StatusReportIndication); Console.Out.WriteLine("Type de message : " + unSMS.Type); }
//calcul la periode de validite public int calculValidityPeriod(TimeSpan unePeriode) { SMS sms = new SMS(); return sms.calculValidityPeriod(unePeriode); }
/// <summary> /// retourne les SMS recus /// </summary> /// <returns>Les SMS reçus</returns> public SMS[] readPDUMessage() { //passage en mode PDU Send("AT+CMGF=0"); readAllSMS("4", 1); //messages en text brut string message = Recv(); //Console.Out.WriteLine("Message brut : " + message); //on recupere les reponses a decoder string[] tabRep = decouperChaineLecturePDU(message); SMS[] tabSMSRecus = new SMS[tabRep.Length]; //on decode chaque reponse for (int i = 0; i < tabRep.Length; i++) { tabSMSRecus[i] = decodeSMSPDU(tabRep[i]); } return tabSMSRecus; }
/** * Encode un message texte * Receipt : demande accuse reception ou non * typeEncodage : 7,8 ou 16 bits ? * validityPeriod : periode de validite du message, par defaut 0 (aucune periode) * */ public string encodeMsgPDU(string message, string no, Boolean receipt, string typeEncodage, int validityPeriod = -1) { SMS sms = new SMS(); String result = null; //Setting direction of sms sms.Direction = SMSDirection.Submited; //Set the recipient number sms.PhoneNumber = no; sms.Message = message; //accuse de recepetion sms.StatusReportIndication = receipt; //periode de validite if (validityPeriod != -1) { sms.ValidityPeriod = decoderValidityPeriod(validityPeriod); } //Encodage switch (typeEncodage) { case "7bits": result = sms.Compose(SMS.SMSEncoding._7bit); break; case "8bits": result = sms.Compose(SMS.SMSEncoding._8bit); break; case "16bits": result = sms.Compose(SMS.SMSEncoding.UCS2); break; } return result; }
public SMS decodeSMSPDU(string message) { //on recupere le sms SMS sms = new SMS(); SMS.Fetch(sms, ref message); //afficherContenuMessagePDU(sms); return sms; }
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; } }
//calcul la periode de validite public int calculValidityPeriod(TimeSpan unePeriode) { SMS sms = new SMS(); return(sms.calculValidityPeriod(unePeriode)); }