bonjour ceci est mon premier post sur ce site
bonjour à vous tous,
je travail en ce moment sur la platine arduino : http://www.lextronic.fr/produit.php?id=4133
ainsi que le module gps suivant : http://www.lextronic.fr/produit.php?id=5910
Le but de ma manipulation est de faire un programme en C pour récupérer toutes les informations gps, chose qui n'était pas très difficile à faire. Vu que je suis sous Linux il suffisait d'ouvrir le DF "/dev/ttyUSB0" puis lire les informations qui y circulent.
Mon problème est plus au niveau de l'écriture, quand j'envoie une commande à la carte arduino via l'usb, cette commande n'est prise en compte par arduino que durant la 2eme exécution du programme C.
Ex:
j'envoie à arduino la commande suivant : "$PSTMNMEACONFIG,0,4800,1,1\r", alors cette commande n'est prise en compte par la carte que durant la 2eme exécution du programme. Avez-vous idée d'ou peut venir le problème??
PS :
La commande permet de sélectionner une seule information parmi toutes les infos envoyées par le GPS.
vous trouverais si joint mon bout de code.
merci du coup de main.
.h
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <time.h>
#define BAUDRATE B4800
#define SELECTGGA "$PSTMNMEACONFIG,0,4800,1,1\r"
#define MODEMDEVICE "/dev/ttyUSB0"
#define _POSIX_SOURCE 1
#define FALSE 0
#define TRUE 1
int InitSerialGpsCom(struct termios oldconf, struct termios newconf);
void StartSerialCom(int fd);
void RestorPar(int fd,struct termios oldconf);
.c
#include "ModuleGps.h"
int InitSerialGpsCom(struct termios oldconf, struct termios newconf)
{
int fd,c, res;
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd <0)
{
perror(MODEMDEVICE);
exit(-1);
}
tcgetattr(fd,&oldconf); /* sauvegarde de la configuration courante */
bzero(&newconf, sizeof(newconf)); /* on initialise la structure zéro */
newconf.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newconf.c_iflag = IGNPAR | IGNCR;
newconf.c_oflag = 0;//OPOST | ONLCR;
newconf.c_lflag = ICANON;
newconf.c_cc[VINTR] = 0; /* Ctrl-c */
newconf.c_cc[VQUIT] = 0; /* Ctrl-\ */
newconf.c_cc[VERASE] = 0; /* del */
newconf.c_cc[VKILL] = 0; /* @ */
newconf.c_cc[VEOF] = 4; /* Ctrl-d */
newconf.c_cc[VTIME] = 0; /* compteur inter-caract`re non utilis Ì */
newconf.c_cc[VMIN] = 1; /* read bloquant jusquâ??` lâ??arriv Ìe dâ??1 caract`re */
newconf.c_cc[VSWTC] = 0; /* â??\0â?? */
newconf.c_cc[VSTART] = 0; /* Ctrl-q */
newconf.c_cc[VSTOP] = 0; /* Ctrl-s */
newconf.c_cc[VSUSP] = 0; /* Ctrl-z */
newconf.c_cc[VEOL] = 0; /* â??\0â?? */
newconf.c_cc[VREPRINT] = 0; /* Ctrl-r */
newconf.c_cc[VDISCARD] = 0; /* Ctrl-u */
newconf.c_cc[VWERASE] = 0; /* Ctrl-w */
newconf.c_cc[VLNEXT] = 0; /* Ctrl-v */
newconf.c_cc[VEOL2] = 0; /* â??\0â?? */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newconf);
return fd;
}
void SelectOnlyGGA(struct termios oldconf, struct termios newconf)
{
int fd = InitSerialGpsCom(oldconf, newconf);
int bufleng = write(fd,SELECTGGA,strlen(SELECTGGA));
close(fd);
}
void RestorPar(int fd,struct termios oldconf)
{
tcsetattr(fd,TCSANOW,&oldconf);
}
void StartSerialCom(int fd)
{
FILE* f;
char buf[255];
int bufleng,j,i=0;
/*Selection de la commande GGA au niveau du gps*/
bufleng = write(fd,SELECTGGA,strlen(SELECTGGA));
while (i<100)
{
bufleng = read(fd,buf,255);
buf[bufleng]=0; /* on termine la ligne, pour pouvoir lâ??afficher */
//SaveFrames(f,buf);
//SplitGGA(buf);
printf("%d) %s\n", i,buf);
i++;
}
}
int main()
{
int FD;
struct termios oldtio,newtio;
FD = InitSerialGpsCom(oldtio,newtio);
StartSerialCom(FD);
RestorPar(FD,oldtio);
}