Exemple #1
0
        private void RafraichirListeSms(ReponseCommandeAT reponseAT_CMGL_ALL)
        {
            _listeSms.Clear();
            int  startidx = reponseAT_CMGL_ALL.ReponseCommande.IndexOf("+CMGL:");
            bool stop     = (startidx < 0);

            while (!stop)
            {
                int    endidx = reponseAT_CMGL_ALL.ReponseCommande.IndexOf("\r\n+CMGL:", startidx + 6);
                string unSms;
                if (endidx >= 0)
                {
                    unSms = reponseAT_CMGL_ALL.ReponseCommande.Substring(startidx, endidx - startidx - 2);
                }
                else
                {
                    unSms = reponseAT_CMGL_ALL.ReponseCommande.Substring(startidx);
                    stop  = true;
                }
                SmsVM unSmsViewModel = new SmsVM(unSms);
                _listeSms.Add(unSmsViewModel);
                unSmsViewModel.SurRepondreSms += UnSmsViewModel_SurRepondreSms;
                startidx = endidx + 2;
            }
            OnPropertyChanged("ListeSms");
        }
Exemple #2
0
        public async Task <int> EnregistrerSms(string destNo, byte toda, string smsText)
        {
            if (destNo.StartsWith("+"))
            {
                destNo = destNo.Substring(1);
                toda   = 145;
            }
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT(@"AT+CMGW=""" + destNo + @"""" + GetChaineToda(toda), 5, smsText);

            if (rep == null)
            {
                return(NADHAT_ERREUR_ENVOI_DONNEES);
            }
            if (rep.CodeRetourNumerique == 0)
            {
                int posCMGW = rep.ReponseCommande.LastIndexOf("\r\n+CMGW: ");
                if (posCMGW >= 0)
                {
                    return(Convert.ToInt32(rep.ReponseCommande.Substring(posCMGW + 9)));
                }
                else
                {
                    return(NADHAT_ERREUR_REPONSE_INCORRECTE);
                }
            }
            else
            {
                return(-rep.CodeRetourNumerique);
            }
        }
Exemple #3
0
        public async Task <DateTimeOffset> GetHorloge()
        {
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT("AT+CCLK?");

            if ((rep != null) && (rep.CodeRetourNumerique == 0))
            {
                return(ConvertGsmTimestampToDateTimeOffset(rep.ReponseCommande.Substring(8, rep.ReponseCommande.Length - 9)));
            }
            return(DateTimeOffset.MinValue);
        }
Exemple #4
0
        public async Task <EtatConnexionDonnees> GetStatutConnexionDonnees(byte noConnexion)
        {
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT("AT+SAPBR=2," + noConnexion.ToString());

            if ((rep != null) && (rep.CodeRetourNumerique == 0))
            {
                return(EtatConnexionDonnees.CreateFrom(rep.ReponseCommande));
            }
            return(null);
        }
Exemple #5
0
 private async void Modele_SurReceptionReponseCommandeAT(object sender, ReponseCommandeAT reponseRecue)
 {
     if (reponseRecue.ReponseCommande.StartsWith("+CPIN: "))
     {
         EtatSim = GetEtatPin(reponseRecue.ReponseCommande);
         await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             OnPropertyChanged("EtatSim");
             OnPropertyChanged("SimDebloquee");
         });
     }
 }
Exemple #6
0
        public async Task <ConfigurationNtp> GetConfigurationNtp()
        {
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT("AT+CNTP?");

            if ((rep != null) && (rep.CodeRetourNumerique == 0))
            {
                return(ConfigurationNtp.CreateFrom(rep.ReponseCommande));
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public async Task <IDictionary <string, string> > GetParametresConnexionDonnees(byte noConnexion)
        {
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT("AT+SAPBR=4," + noConnexion.ToString());

            if ((rep != null) && (rep.CodeRetourNumerique == 0))
            {
                return(ConvertirParametresConnexionDonnees(rep.ReponseCommande));
            }
            else
            {
                return(null);
            }
        }
Exemple #8
0
        private async Task <string> EnvoyerCommandeATAvecReponseChaine(string commandeAT, int timeoutSeconds = 1)
        {
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT(commandeAT, timeoutSeconds);

            if ((rep != null) && (rep.CodeRetour == "OK"))
            {
                return(_derniereReponseCommandeAT.ReponseCommande);
            }
            else
            {
                return(null);
            }
        }
Exemple #9
0
 private async void Modele_SurAjoutSmsDansMemoire(object sender, uint noSms)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
     {
         ReponseCommandeAT smsRecu = await Modele.GetSms(noSms, true);
         if (smsRecu != null)
         {
             SmsVM unSmsViewModel = new SmsVM(smsRecu.ReponseCommande, noSms);
             _listeSms.Add(unSmsViewModel);
             unSmsViewModel.SurRepondreSms += UnSmsViewModel_SurRepondreSms;
             OnPropertyChanged("ListeSms");
         }
     });
 }
Exemple #10
0
        private bool TraiterLesReponses()
        {
            Match rechercheTrameAT;

            lock (_bufferLOCK)
            {
                rechercheTrameAT = _RegexTrameAT.Match(_buffer);
                SupprimerChaineRechecheeDans(rechercheTrameAT);
            }
            if (rechercheTrameAT.Success)
            {
                _derniereReponseCommandeAT = ReponseCommandeAT.CreateFromMatch(rechercheTrameAT);
                if (_derniereReponseCommandeAT != null)
                {
                    _attenteReponse.Set();
                    SurReceptionReponseCommandeAT?.Invoke(this, _derniereReponseCommandeAT);
                    if (_derniereReponseCommandeAT.CodeRetourNumerique == 0)
                    {
                        if (_derniereReponseCommandeAT.CommandeAT.StartsWith("AT+CMGD=1,4"))
                        {
                            SurSuppressionTousSmsDansMemoire?.Invoke(this);
                        }
                        if (_derniereReponseCommandeAT.CommandeAT.StartsWith(@"AT+CMGL=""ALL"""))
                        {
                            SurLectureTousSmsDepuisMemoire?.Invoke(this, _derniereReponseCommandeAT);
                        }
                        if (_derniereReponseCommandeAT.CommandeAT.StartsWith("AT+CMGW="))
                        {
                            int posCMGW = _derniereReponseCommandeAT.ReponseCommande.IndexOf("\r\n+CMGW: ");
                            if (posCMGW >= 0)
                            {
                                SurAjoutSmsDansMemoire(this, Convert.ToUInt32(_derniereReponseCommandeAT.ReponseCommande.Substring(posCMGW + 9)));
                            }
                        }
                    }
                }
            }
            return(rechercheTrameAT.Success);
        }
Exemple #11
0
        private bool TraiterLesNotifications()
        {
            Match rechercheNotifSMS;

            lock (_bufferLOCK)
            {
                rechercheNotifSMS = _RegexNotif.Match(_buffer);
                SupprimerChaineRechecheeDans(rechercheNotifSMS);
            }
            ReponseCommandeAT notif = ReponseCommandeAT.CreateFromMatchNotif(rechercheNotifSMS);

            if (notif != null)
            {
                SurReceptionNotificationAvecDonnees?.Invoke(this, notif);
                if (notif.ReponseCommande.StartsWith("+CMTI: "))
                {
                    NotificationMessageSms notifSMS = NotificationMessageSms.CreateFromMatch(rechercheNotifSMS);
                    if (notifSMS != null)
                    {
                        SurReceptionNotificationMessageSMS?.Invoke(this, notifSMS);
                        SurAjoutSmsDansMemoire?.Invoke(this, notifSMS.IndexMemoire);
                    }
                }
                //else if (notif.ReponseCommande == "NORMAL POWER DOWN")
                //  SurNormalPowerDown?.Invoke(this);
                //else if (notif.ReponseCommande == "SMS Ready")
                //  SurSMSReady?.Invoke(this);
                //else if (notif.ReponseCommande == "Call Ready")
                //  SurCallReady?.Invoke(this);
                else if (notif.ReponseCommande.StartsWith("+CNTP: "))
                {
                    SurReceptionNotificationSynchroNtp?.Invoke(this, Convert.ToByte(notif.ReponseCommande.Substring(7)));
                }
            }
            return(rechercheNotifSMS.Success);
        }
Exemple #12
0
        private async Task <ReponseCommandeAT> EnvoyerCommandeATAvecReponseAT(string commandeAT, int timeoutSeconds = 1, string texte = "")
        {
            _envoiCommandeATPossible.WaitOne();
            _attenteReponse.Reset();
            ReponseCommandeAT res = null;

            if (await EnvoyerCommandeAT(commandeAT))
            {
                if ((texte != "") && (!await EnvoyerTexte(texte)))
                {
                    _attenteReponse.Set();
                }
                else
                {
                    if (!_attenteReponse.WaitOne(new TimeSpan(0, 0, timeoutSeconds)))
                    {
                        _attenteReponse.Set();
                    }
                    res = _derniereReponseCommandeAT;
                }
            }
            _envoiCommandeATPossible.Release();
            return(res);
        }
Exemple #13
0
 private async void Modele_SurLectureTousSmsDepuisMemoire(object sender, ReponseCommandeAT reponseCommandeAT_CMGL_ALL)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RafraichirListeSms(reponseCommandeAT_CMGL_ALL); });
 }
Exemple #14
0
        private async Task <bool> EnvoyerCommandeATAvecReponseBool(string commandeAT, int timeoutSeconds = 1)
        {
            ReponseCommandeAT rep = await EnvoyerCommandeATAvecReponseAT(commandeAT, timeoutSeconds);

            return((rep != null) && (rep.CodeRetour == "OK"));
        }