Révision 789
Ajouté par rademagalh il y a presque 4 ans
main.c | ||
---|---|---|
{{44.7891220, -3.013}, 70},
|
||
};
|
||
|
||
int trame_cmp(char * trame, char * type)
|
||
{
|
||
int trame_cmp(char * trame, char * type){
|
||
int indice=1;
|
||
char mot[10]="";
|
||
//Extraction du mot entre le symbole $ et la virgule
|
||
... | ... | |
return 0;
|
||
}
|
||
}
|
||
|
||
int decode_int(char c)
|
||
{
|
||
int decode_int(char c){
|
||
int code;
|
||
char i;
|
||
if(c >= '0' && c <= '9')
|
||
... | ... | |
return -1;
|
||
}
|
||
}
|
||
|
||
int decode_nombrdistance_a_la_plus_proche_zone(pos1, zones, 2)e(char * ch, int n)
|
||
{
|
||
int decode_nombre(char * ch, int n){
|
||
int longueurMot=0;
|
||
char caratereCourrant=0;
|
||
//Obtention de la longueur du Mot extrait entre le symbole $ et la virgule
|
||
... | ... | |
else{
|
||
int j=0,sum=0;
|
||
char nb[n];
|
||
for(j=0; j<n; j++)
|
||
for(j=0; j<=n; j++)
|
||
{
|
||
if(ch[j] < 48 || ch[j] > 57)
|
||
{
|
||
... | ... | |
}
|
||
}
|
||
|
||
float CharVersDegre(char * ch)
|
||
{
|
||
float CharVersDegreV1(char * ch){
|
||
char * nombre=ch;
|
||
float dec;
|
||
int compte=0,n,degre;
|
||
... | ... | |
n=compte-1;
|
||
continue;
|
||
}
|
||
float d = *ch - '0';
|
||
int d = *ch - '0';
|
||
if (d >= 0 && d <= 9)
|
||
{
|
||
if (virguleVu) fact /= 10.0;
|
||
res = res * 10.0 + d;
|
||
if (virguleVu!=0)
|
||
{
|
||
fact /= 10.0;
|
||
}
|
||
res = res * 10.0 + (float)d;
|
||
}
|
||
if (*ch == ',')
|
||
{
|
||
... | ... | |
dec=(res * fact);
|
||
if (n==4)
|
||
{
|
||
degre=decode_nombre(nombre,2);
|
||
degre=decode_nombre(nombre,1);
|
||
dec=(dec-degre*100)/60;
|
||
}
|
||
else if (n==5)
|
||
{
|
||
degre=decode_nombre(nombre,3);
|
||
degre=decode_nombre(nombre,2);
|
||
dec=(dec-degre*100)/60;
|
||
}
|
||
dec = degre + dec;
|
||
return dec;
|
||
}
|
||
int CharVersDegreV2(char * ch){
|
||
int resultat=0;
|
||
int longueurCh=0;
|
||
char caratereCourrant=0;
|
||
do
|
||
{
|
||
caratereCourrant=ch[longueurCh];
|
||
longueurCh++;
|
||
}
|
||
while (caratereCourrant != '\0');
|
||
longueurCh--;
|
||
|
||
Position decode_trame(char * ch)
|
||
{
|
||
if (longueurCh == 9)
|
||
{
|
||
int nombre=decode_nombre(ch,8);
|
||
int nombre_avant_vir=decode_nombre(ch,4);
|
||
int deg=decode_nombre(ch,1);
|
||
int minute_avant_vir=nombre_avant_vir-deg*100;
|
||
int minute_apres_vir=(nombre-nombre_avant_vir*10000);
|
||
|
||
resultat=(deg+(minute_avant_vir+minute_apres_vir*0.0001)/60)*256;
|
||
|
||
}
|
||
else
|
||
{
|
||
int nombre=decode_nombre(ch,9);
|
||
int nombre_avant_vir=decode_nombre(ch,5);
|
||
int deg=decode_nombre(ch,2);
|
||
int minute_avant_vir=nombre_avant_vir-deg*100;
|
||
int minute_apres_vir=(nombre-nombre_avant_vir*10000);
|
||
|
||
resultat=(deg+(minute_avant_vir+minute_apres_vir*0.0001)/60)*256;
|
||
}
|
||
return resultat;
|
||
}
|
||
|
||
Position decode_trameV1(char * ch){
|
||
Position pos;
|
||
int i,indice=0;
|
||
char longitude[10]="";
|
||
... | ... | |
|
||
if (compteur_de_virgule==4)
|
||
{
|
||
for (int i = 0; i < 9; i++)
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
longitude[i]=ch[indice+1];
|
||
indice++;
|
||
... | ... | |
}
|
||
indice++;
|
||
} while (ch[indice]!='\0');
|
||
pos.latitude = CharVersDegre(latitude);
|
||
pos.longitude = CharVersDegre(longitude);
|
||
pos.latitude = CharVersDegreV1(latitude);
|
||
pos.longitude = CharVersDegreV1(longitude);
|
||
}
|
||
return pos;
|
||
}
|
||
Position decode_trameV2(char * ch){
|
||
Position pos1;
|
||
int i,indice=0;
|
||
char longitude[20]="";
|
||
char latitude[20]="";
|
||
int compteur_de_virgule = 0;
|
||
if (trame_cmp(ch,"GPGGA")==0)
|
||
{
|
||
return pos1;
|
||
}
|
||
else
|
||
{
|
||
|
||
float calcul_distance(Position p1,Position p2)
|
||
{
|
||
do
|
||
{
|
||
if (ch[indice]==',')
|
||
{
|
||
compteur_de_virgule++;
|
||
}
|
||
|
||
if (compteur_de_virgule==2)
|
||
{
|
||
for (int i = 0; i < 9; i++)
|
||
{
|
||
latitude[i]=ch[indice+1];
|
||
indice++;
|
||
}
|
||
}
|
||
|
||
if (compteur_de_virgule==4)
|
||
{
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
longitude[i]=ch[indice+1];
|
||
indice++;
|
||
}
|
||
break;
|
||
}
|
||
indice++;
|
||
} while (ch[indice]!='\0');
|
||
pos1.latitude = (float)CharVersRadiansV2(latitude)/256;
|
||
pos1.longitude = (float)CharVersRadiansV2(longitude)/256;
|
||
}
|
||
return pos1;
|
||
}
|
||
|
||
float calcul_distance(Position p1,Position p2){
|
||
float R_terre=6378.137;
|
||
float distance = R_terre*(p1.latitude-p2.latitude)*(3.14/180);
|
||
return distance;
|
||
}
|
||
|
||
float calcul_vitesse(float distance)
|
||
{
|
||
float calcul_vitesse(float distance){
|
||
return distance*3600;
|
||
}
|
||
|
||
float distance_a_la_plus_proche_zone(Position pos_voiture, Zone r[], int nb_zones)
|
||
{
|
||
float distance_a_la_plus_proche_zone(Position pos_voiture, Zone r[], int nb_zones){
|
||
Position t[nb_zones];
|
||
for (int i = 0; i < nb_zones; i++)
|
||
{
|
||
... | ... | |
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
void traitement(char * trame){
|
||
static int cpt=0;
|
||
cpt++;
|
||
printf ("> %s\n",trame);
|
||
}
|
||
distance_a_la_plus_proche_zone(pos1, zones, 2)
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
printf("Test de la fonction trame_cmp \n");
|
||
... | ... | |
{
|
||
printf("Pas d'erreur fonction potentiellement valide !\n");
|
||
}
|
||
}
|
||
|
||
}
|
||
//Fonction de tests unitaires pour decode_int
|
||
void test_decode_int(void){
|
||
printf("Test de la fonction decode_int \n");
|
||
... | ... | |
printf("Pas d'erreur fonction potentiellement valide ! \n");
|
||
}
|
||
}
|
||
|
||
//Fonction de tests unitaires pour decode_nombre
|
||
void test_decode_nombre(void){
|
||
printf("Test de la fonction decode_nombre \n");
|
||
... | ... | |
printf("Pas d'erreur fonction potentiellement valide ! \n");
|
||
}
|
||
}
|
||
|
||
void test_decode_trame(){
|
||
printf("Test de la fonction test_decode_trame \n");
|
||
if (5!=5){
|
Formats disponibles : Unified diff
Ajout de fonction CharVersDegre prototypé int au lieu de float