Révision 530
Ajouté par Pape Demba AMAR il y a presque 4 ans
SP4b3.c | ||
---|---|---|
/* This file is generated by Renesas Project Generator (Ver.4.18). */
|
||
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
||
/***********************************************************************/
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
#include <math.h>
|
||
|
||
void main(void)
|
||
typedef struct // declaration du type position compos? de la latitude et la longitude
|
||
{
|
||
|
||
float latitude;
|
||
float longitude;
|
||
} position;
|
||
|
||
typedef struct // declaration du type zone compos? de la position et la vitesse maximale
|
||
{
|
||
position rpos;
|
||
float vitmax;
|
||
} zone;
|
||
#define Rayon 6378.1370
|
||
//Trames de tests ? modifier si n?cessaire.
|
||
char * trames[]= {"$GPGSV,3,2,10,15,03,077,,18,04,041,42,19,85,271,,20,08,214,*7C",
|
||
"$GPGSV,3,3,10,22,39,053,50,28,15,320,*7E",
|
||
"$GPRMC,141914.00,A,4545.6424,N,00306.6036,E,0.4,99.4,010206,,*0C",
|
||
"$GPGLL,4545.6424,N,00306.6036,E,141914.00,A*0E",
|
||
"$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",
|
||
"$GPGGA,141925.00,4545.2410,N,00306.6046,E,1,05,3.4,501.4,M,,M,,*7D"
|
||
"$GPGSA,A,3,,03,,22,14,,01,,18,,,,3.9,3.4,1.9*39",
|
||
"$GPVTG,99.4,T,,M,0.4,N,0.7,K*57",
|
||
"$GPZDA,141914.00,01,02,2006,00,00*69",
|
||
0};
|
||
zone zones[] = // declaration d'un tableau de zones
|
||
{
|
||
{{44.78887762, -3.012}, 50},
|
||
{{44.7891220, -3.013}, 70},
|
||
{{46.7501,3.1101},50}
|
||
};
|
||
position test_position;
|
||
position pos1;
|
||
position pos2;
|
||
int trame_cmp(char * trame, char * type) // declaration de la fonction de comparaison de deux chaines
|
||
{
|
||
/* if (!strncmp(trame+1,type,strlen(type)))
|
||
return 1;
|
||
return 0;
|
||
*/
|
||
|
||
int i;
|
||
for (i=0; i<strlen(type); i++) // parcours de la longueur du type
|
||
{
|
||
if (trame[i+1] != type[i]) // inegalit? entre les caracteres
|
||
return 0; // renvoie 0
|
||
}
|
||
return 1; // renvoie 1
|
||
|
||
|
||
}
|
||
|
||
int decode_int(char c) // declaration de la fonction qui renvoie le nombre associ? au caractere
|
||
{
|
||
c=c-'0';
|
||
return c;
|
||
}
|
||
|
||
int decode_nombre(char * ch, int n) // fonction qui recupere les n premiers chiffres d'une chaine
|
||
{
|
||
int i;
|
||
int somme=0;
|
||
for (i=0;i<n;i++)
|
||
{
|
||
somme=(somme*10) + decode_int(ch[i]);
|
||
}
|
||
return somme;
|
||
|
||
}
|
||
float conversion_longitude(char * lon) // fonction qui convertie une longitude en nombre flottant
|
||
{
|
||
float result_convers,val_deci;
|
||
int val_ent_dec,val_ent_minut;
|
||
result_convers=decode_nombre(lon,3);// recuperation de la partie entiere
|
||
val_ent_minut=decode_nombre(&lon[3],2);
|
||
val_ent_dec=decode_nombre(&lon[6],4);
|
||
val_deci=(val_ent_minut+(0.0001*val_ent_dec))/60; // recuperation de la valeur decimale en degr?
|
||
result_convers=result_convers+val_deci;
|
||
return result_convers;
|
||
}
|
||
|
||
float conversion_latitude(char * lat) // fonction qui convertie une longitude en nombre flottant
|
||
{
|
||
// 3723.2475 equivalent a 37 degr? 23.2475 / 60 degr?
|
||
float result_convers,val_deci;
|
||
int val_ent_dec,val_ent_minut;
|
||
char minute[7];
|
||
char min[4];
|
||
int i;
|
||
for (i=0;i<7; i++) minute[i]=lat[2+i];
|
||
for (i=0;i<4; i++) min[i]=lat[5+i];
|
||
result_convers=decode_nombre(lat,2);// recuperation de la partie entiere 37
|
||
val_ent_minut=decode_nombre(minute,2); // 23
|
||
val_ent_dec=decode_nombre(min,4); // 2475
|
||
val_deci=(val_ent_minut+(val_ent_dec*0.0001))*0.0166667; // recuperation de la valeur decimale en degr?
|
||
result_convers+=val_deci;
|
||
return result_convers;
|
||
}
|
||
|
||
int decode_trame(char* trame,position * pos) // fonction qui rends les trames "GPGGA" et qui renvoie 1 et affichage de la latitude et la longitude en floattant
|
||
{
|
||
int i;
|
||
char ch[10];
|
||
if (trame_cmp(trame,"GPGGA"))
|
||
{
|
||
for (i=0;i<10;i++) ch[i]=trame[29+i];
|
||
pos->latitude=conversion_latitude(trame+17);
|
||
pos->longitude=conversion_longitude(ch);
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
float conver_radian(float x) // fonction qui convertit un nombre flottant en flottaant
|
||
{
|
||
return (x*M_PI)/180;
|
||
}
|
||
|
||
float calcul_distance(position pos1,position pos2) // fonction qui calcule la distance entre deux positions
|
||
{
|
||
float result= (40000/360) * sqrt(((pos2.latitude - pos1.latitude)*(pos2.latitude - pos1.latitude))+((pos2.longitude - pos1.longitude)*(pos2.longitude - pos1.longitude))) ;
|
||
return result;
|
||
|
||
}
|
||
|
||
float calcul_vitesse(position pos1,position pos2) // fonction qui calcule la distance entre deux positions
|
||
{
|
||
float vitesse;
|
||
vitesse=3600*(calcul_distance(pos1,pos2)*Rayon);
|
||
return vitesse;
|
||
}
|
||
|
||
int distance_a_la_plus_proche_zone(position p,zone r[],int nb_zones,float *d) // fonction qui calcule la distance la plus proche
|
||
{
|
||
int index=0;
|
||
int i;
|
||
*d=fabs(calcul_distance(p,r[0].rpos)); // initialisation du minimum
|
||
float t;
|
||
if (nb_zones>0)
|
||
{
|
||
for (i=1;i<nb_zones;i++)
|
||
{
|
||
t=fabs(calcul_distance(p,r[i].rpos));
|
||
if (t<*d)
|
||
{
|
||
*d=t;
|
||
index=i;
|
||
}
|
||
}
|
||
return index;
|
||
}
|
||
return -1;
|
||
}
|
||
void test_distance_plus_proche(void) //
|
||
{
|
||
position p;
|
||
p.latitude =45.75;
|
||
p.longitude=3.110060;
|
||
int num_zone;
|
||
float d ;
|
||
num_zone=distance_a_la_plus_proche_zone(p,zones,sizeof(zones),&d);
|
||
if (num_zone!=2 & fabs(d-44.85)>0.5)
|
||
{
|
||
printf(("erreur test distance la plus proche "));
|
||
exit(-1);
|
||
}
|
||
}
|
||
float fonction_generique(char* ch) // fonction qui convertit la latitudes ou la longitude en flottant
|
||
{
|
||
float result_convers;
|
||
if(ch[4]=='.')
|
||
{
|
||
result_convers=conversion_latitude(ch);
|
||
}
|
||
else if(ch[5]=='.')
|
||
{
|
||
result_convers=conversion_longitude(ch);
|
||
}
|
||
|
||
return result_convers;
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
/*
|
||
static int cpt=0;
|
||
cpt++;
|
||
if (trame_cmp(trame,"GPGGA"))
|
||
{printf ("> %s\n",trame);}
|
||
*/
|
||
position p;
|
||
position p_init;
|
||
p_init.latitude=45.750000;
|
||
p_init.longitude= 3.110060;
|
||
float distance;
|
||
float vitesse;
|
||
float seuil=1000;
|
||
int index;
|
||
if (decode_trame(trame,&p))
|
||
{
|
||
printf ("> %s\n",trame);
|
||
printf("la latitude est %f \n la longitude est %f \n ",p.latitude,p.longitude);
|
||
vitesse=calcul_vitesse(p_init,p);
|
||
index=distance_a_la_plus_proche_zone(p,zones,sizeof(zones),&distance);
|
||
if ((distance<seuil) && (vitesse>zones[index].vitmax))
|
||
{
|
||
printf(" alarme on \n");
|
||
printf(" zone numero %d \n ",index);
|
||
|
||
printf("la vitesse est %f\n ",vitesse);
|
||
printf("la distance est %f \n ",distance);
|
||
}
|
||
else
|
||
printf("Alarme off \n ");
|
||
p_init = p;
|
||
}
|
||
|
||
}
|
||
void test_decode_trame(void)
|
||
{
|
||
if (decode_trame("$GPGGA,141914.00,4545.0000,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D",&test_position)!=1)
|
||
{
|
||
printf("Erreur Test decode trame \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
void test_decode_int(void)
|
||
{
|
||
if (decode_int('0')!=0)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('1')!=1)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('2')!=2)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('3')!=3)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('4')!=4)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_int('5')!=5)
|
||
{
|
||
printf("Erreur test unitaire decode int\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_decode_nombre(void)
|
||
{
|
||
if (decode_nombre("7541",1)!=7)
|
||
{
|
||
printf("Erreur test unitaire decode nombre\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("7541",2)!=75)
|
||
{
|
||
printf("Erreur test unitaire decode nombre\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("7541",3)!=754)
|
||
{
|
||
printf("Erreur test unitaire decode nombre\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
void test_fonction_generique(void)
|
||
{
|
||
if (fonction_generique("3223.2475") - 37.387459 > 0.0001 )
|
||
{
|
||
printf("Erreur test latitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
if (fonction_generique("00306.6036")-3.110060 > 0.0001)
|
||
{
|
||
printf("Erreur test longitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_latitude(void)
|
||
{
|
||
if (conversion_latitude("3223.2475,N") - 37.387459 > 0.0001 )
|
||
{
|
||
printf("Erreur test latitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
void test_longitude(void)
|
||
{
|
||
if (conversion_longitude("00306.6036,E")-3.110060 > 0.0001)
|
||
{
|
||
printf("Erreur test longitude !!! \n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void)
|
||
{
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC suite chaine","GPGGA")!=0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC... ", "GPRMC" )!=1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$APRMC...", "GPGGA")!=0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
int trame_valide;
|
||
tests_unitaires();
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
test_latitude();
|
||
test_longitude();
|
||
test_fonction_generique();
|
||
test_decode_trame();
|
||
test_distance_plus_proche();
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
int i=0;
|
||
while (trames[i])
|
||
traitement(trames[i++]);
|
||
|
||
if (!trame_init())
|
||
exit(-1);
|
||
// Affichage des trames du fichier gps.log
|
||
char *trame;
|
||
printf ("Trames de tests du fichier gps.log\n");
|
||
while ((trame = trame_suivante()))
|
||
traitement(trame);
|
||
|
||
|
||
return 0;
|
||
}
|
||
|
||
#include "sfr32c87.h"
|
||
void init_keyboard(void);
|
||
void tpo_50ms(void) ;
|
||
unsigned char touche = 0;void main(void){
|
||
char t;
|
||
pu31=1;
|
||
pd10=0x00;
|
||
while (1){
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
p10=0;
|
||
}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
t=p10 ;
|
||
p10=~0x0F;
|
||
}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
p10=14;
|
||
t=p10;}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
|
||
p10=0x0D;
|
||
t=p10;
|
||
}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
p10=0x07;
|
||
t=p10;
|
||
}
|
||
}
|
||
}
|
||
void lcd_4b (char c)
|
||
{
|
||
|
||
pd1=0xff;
|
||
|
||
c=0b10000000;
|
||
|
||
if(c&0b10000000)
|
||
|
||
p1_7=1;
|
||
|
||
else
|
||
p1_7=0;
|
||
|
||
if(c&0b10000000)
|
||
|
||
p1_6=1;
|
||
|
||
else
|
||
p1_6=0;
|
||
|
||
if(c&0b10000000)
|
||
|
||
p1_5=1;
|
||
|
||
else
|
||
p1_5=0;
|
||
if(c&0b10000000)
|
||
|
||
p1_4=1;
|
||
|
||
else
|
||
p1_4=0;
|
||
|
||
|
||
|
||
if(c&0b10000000)
|
||
|
||
p1_2=1;
|
||
|
||
else
|
||
p1_2=0;
|
||
|
||
}
|
||
void main (void){
|
||
lcd_4b (0xF0);
|
||
lcd_4b (0xFA);
|
||
}
|
||
|
||
void lcd_8b (char c)
|
||
{
|
||
lcd_4b(c<<4);
|
||
}
|
||
lcd_com(c)
|
||
{
|
||
p1_0=0;
|
||
lcd_8b(c);
|
||
}
|
||
lcd_car(char c)
|
||
{
|
||
p1_0 = 0;
|
||
lcd_8b(c);
|
||
}
|
Formats disponibles : Unified diff
Implantation de l'ensemble des fonctions enveloppées en séances 1 et 2, sur la cible M32