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); }
private async Task <EtatConnexionDonnees> GetStatutConnexionDonneesStable(byte noConnexion) { EtatConnexionDonnees res = await GetStatutConnexionDonnees(noConnexion); int nbFois = 17; while ((nbFois > 0) && (res != null) && ((res.StatutConnexion == StatutConnexionDonnees.scConnexionEnCours) || (res.StatutConnexion == StatutConnexionDonnees.scDeconnexionEnCours))) { await Task.Delay(5000); nbFois--; res = await GetStatutConnexionDonnees(noConnexion); } return(res); }
public static EtatConnexionDonnees CreateFrom(string reponseCommandeAT_SAPBR) { EtatConnexionDonnees res = null; int idxSAPBR = reponseCommandeAT_SAPBR.IndexOf("+SAPBR: "); if (idxSAPBR >= 0) { string[] tabchamps = reponseCommandeAT_SAPBR.Substring(idxSAPBR + 8).Split(','); res = new EtatConnexionDonnees() { AdresseIP = tabchamps[2].Trim('"') }; try { res.NoConnexion = Convert.ToByte(tabchamps[0]); res.StatutConnexion = (StatutConnexionDonnees)Convert.ToByte(tabchamps[1]); } catch (Exception) { res = null; } } return(res); }
public async Task <int> SynchroniserHorlogeNtp(byte noConnexion, string apn, string ntpServerUrl, TimeSpan timezoneOffset) { string noConStr = noConnexion.ToString(); if (await EnvoyerCommandeATAvecReponseBool("AT+SAPBR=3," + noConStr + @",""Contype"",""GPRS""")) { if (await EnvoyerCommandeATAvecReponseBool("AT+SAPBR=3," + noConStr + @",""APN"",""" + apn + @"""")) { EtatConnexionDonnees ecData = await GetStatutConnexionDonneesStable(noConnexion); if (ecData == null) { return(-7); } else if (ecData.StatutConnexion == StatutConnexionDonnees.scConnexionEnCours) { return(-8); } else if (ecData.StatutConnexion == StatutConnexionDonnees.scDeconnexionEnCours) { return(-9); } else if (ecData.StatutConnexion == StatutConnexionDonnees.scDeconnecte) { if (!await EnvoyerCommandeATAvecReponseBool("AT+SAPBR=1," + noConStr, 85)) { return(-4); } } if (await EnvoyerCommandeATAvecReponseBool("AT+CNTPCID=" + noConStr)) { if (await EnvoyerCommandeATAvecReponseBool(@"AT+CNTP=""" + ntpServerUrl + @"""," + (timezoneOffset.TotalHours * 4).ToString())) { if (await EnvoyerCommandeATAvecReponseBool("AT+CNTP")) { return(0); } else { return(-1); } } else { return(-2); } } else { return(-3); } } else { return(-5); } } else { return(-6); } }