Révision 537
Ajouté par Pape Demba AMAR il y a presque 4 ans
SP4b3.c | ||
---|---|---|
/***********************************************************************/
|
||
|
||
#include "sfr32c87.h"
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
#include <math.h>
|
||
|
||
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}
|
||
};
|
||
|
||
void init_keyboard(void);
|
||
void tpo_50ms(void) ;
|
||
unsigned char touche = 0;void main(void){
|
||
... | ... | |
pu31=1;
|
||
pd10=0x00;
|
||
while (1){
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
if (( t & 0xF0)!= 0xf0 ){
|
||
p10=0;
|
||
}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
if (( t & 0xF0)!= 0xf0 ){
|
||
t=p10 ;
|
||
p10=~0x0F;
|
||
}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
if (( t & 0xF0)!= 0xf0 ){
|
||
p10=14;
|
||
t=p10;}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
if (( t & 0xF0)!= 0xf0 ){
|
||
|
||
p10=0x0D;
|
||
t=p10;
|
||
}
|
||
if (( t & 0xf0)! = 0xf0 )){
|
||
if (( t & 0xF0)!= 0xf0 ){
|
||
p10=0x07;
|
||
t=p10;
|
||
}
|
||
... | ... | |
void lcd_4b (char c)
|
||
{
|
||
|
||
pd1=0xff;
|
||
pd1=0xFF;
|
||
|
||
c=0b10000000;
|
||
|
||
... | ... | |
p1_2=0;
|
||
|
||
}
|
||
|
||
|
||
void main (void){
|
||
lcd_4b (0xF0);
|
||
lcd_4b (0xFA);
|
||
... | ... | |
{
|
||
p1_0 = 0;
|
||
lcd_8b(c);
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|
||
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);
|
||
}
|
||
}
|
Formats disponibles : Unified diff
calcule de temps (en cycle et en ms) passé par le programme pour :
• décoder une trame
• calculer une nouvelle position et une nouvelle distance
• trouver la plus proche zone, lorsque la table contient 1, 2, puis 10 zones
les programmes sen vours de modification