[Résolu]empecher retour chario

bonjour, mon programme enregistre la liaison GPS dans une carte SD mais à chaque réception du message,
il y a un retour et je sais pas comment l'annuler.

    #include <SPI.h>
    //#include <Adafruit_GPS.h>
    #include <My_GPS.h>
    #include <SoftwareSerial.h>
    #include <SD.h>
    #include <avr/sleep.h>
    #include <Wire.h>
    #include <Adafruit_Sensor.h>
    #include <SoftwareSerial.h>
    #include <Adafruit_LSM303_U.h>
    #include <Adafruit_9DOF.h>

    Adafruit_9DOF                 dof   = Adafruit_9DOF();
    Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
    Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);

    SoftwareSerial mySerial(8, 7);
    //Adafruit_GPS GPS(&mySerial);
    My_GPS GPS(&mySerial);

    boolean usingInterrupt = false;
    void useInterrupt();


    File logfile;

    void setup() {

      //Serial.begin(115200);
     // Serial.println(F("totodd"));
      pinMode(13, OUTPUT);
      pinMode(10, OUTPUT);
      accel.begin();
      mag.begin();

      SD.begin(10);
     
    char filename[15];
      strcpy(filename, "GPSLOG.TXT");
     
      logfile = SD.open(filename, FILE_WRITE);

      GPS.begin(9600);

      GPS.sendCommand("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28");
     
      GPS.sendCommand("$PMTK220,1000*1F");
     
      GPS.sendCommand("$PGCMD,33,0*6D");

      useInterrupt();
    }

    SIGNAL(TIMER0_COMPA_vect) {
      char c = GPS.read();
    }

    void useInterrupt() {
        TIMSK0 |= _BV(OCIE0A);
        usingInterrupt = true;
     
    }

    void loop() {
     
      sensors_event_t accel_event;
      sensors_event_t mag_event;
      sensors_vec_t   orientation;

      accel.getEvent(&accel_event);
      mag.getEvent(&mag_event);

      if (dof.fusionGetOrientation(&accel_event, &mag_event, &orientation))
      {
        logfile.print(">");
        logfile.println(orientation.roll);
        logfile.flush();
      }
      if (! usingInterrupt) {
        char c = GPS.read();
      }
     
      if (GPS.newNMEAreceived()) {
        char *stringptr = GPS.lastNMEA();
       
        if (!GPS.parse(stringptr))   
          return;
        uint8_t stringsize = strlen(stringptr);
        if (stringsize != logfile.write((uint8_t *)stringptr, stringsize))    //write the string to the SD file
           
        if (strstr(stringptr, "RMC") || strstr(stringptr, "GGA"))   logfile.flush();
       
      }
      delay(333);
    }

Le retour chario se fait ici

 if (stringsize != logfile.write((uint8_t *)stringptr, stringsize))    //write the string to the SD file
           
        if (strstr(stringptr, "RMC") || strstr(stringptr, "GGA")) ;

les librairies
Lighter_Adafruit_GPS.h

//declaration des variables et menbres de la classe
#ifndef Lighter_Adafruit_GPS_H
#define Lighter_Adafruit_GPS_H
 #include "Arduino.h"
 #include <SoftwareSerial.h>

// how long to wait when we're looking for a response
#define MAXWAITSENTENCE 5
#define PMTK_SET_NMEA_UPDATE_1HZ  "$PMTK220,1000*1F"
#define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
#define PMTK_SET_NMEA_UPDATE_1HZ  "$PMTK220,1000*1F"
#include "SoftwareSerial.h"
// AVR ok
// ARDUINO >= 100

class Lighter_Adafruit_GPS {
 public:
  void begin(uint16_t baud); 


  Lighter_Adafruit_GPS(SoftwareSerial *ser); // Constructor when using SoftwareSerial

 // Lighter_Adafruit_GPS(HardwareSerial *ser); // Constructor when using HardwareSerial

  char *lastNMEA(void);
  boolean newNMEAreceived();
  void common_init(void);

  void sendCommand(const char *);
  
  //void pause(boolean b);

  boolean parseNMEA(char *response);
  uint8_t parseHex(char c);

  char read(void);
  boolean parse(char *);
  void interruptReads(boolean r);



  uint8_t hour, minute, seconds, year, month, day;
  uint16_t milliseconds;
  // Floating point latitude and longitude value in degrees.
  float latitude, longitude;
  int32_t latitude_fixed, longitude_fixed;
  float latitudeDegrees, longitudeDegrees;
  float geoidheight, altitude;
  float speed, angle, magvariation, HDOP;
  char lat, lon, mag;
  boolean fix;
  uint8_t fixquality, satellites;

  //boolean waitForSentence(const char *wait, uint8_t max = MAXWAITSENTENCE);
 
 private:

  uint8_t parseResponse(char *response);
  SoftwareSerial *gpsSwSerial;
};


#endif

Lighter_Adafruit_GPS.cpp

#include <SoftwareSerial.h>
#include <Lighter_Adafruit_GPS.h>

// how long are max NMEA lines to parse?
#define MAXLINELENGTH 120

// we double buffer: read one line in and leave one for the main program
volatile char line1[MAXLINELENGTH];
volatile char line2[MAXLINELENGTH];
// our index into filling the current line
volatile uint8_t lineidx=0;
// pointers to the double buffers
volatile char *currentline;
volatile char *lastline;
volatile boolean recvdflag;



boolean Lighter_Adafruit_GPS::parse(char *nmea) {
 
  if (nmea[strlen(nmea)-4] == '*') {
    uint16_t sum = parseHex(nmea[strlen(nmea)-3]) * 16;
    sum += parseHex(nmea[strlen(nmea)-2]);
    
    // check checksum 
    for (uint8_t i=1; i < (strlen(nmea)-4); i++) {
      sum ^= nmea[i];
    }

  }
  int32_t degree;
  long minutes;
  char degreebuff[10];
  // look for a few common sentences
  if (strstr(nmea, "$GPGGA")) {
    // found GGA
    char *p = nmea;
    // get time
    p = strchr(p, ',')+1;
    float timef = atof(p);
    uint32_t time = timef;
    hour = time / 10000;
    minute = (time % 10000) / 100;
    seconds = (time % 100);

    milliseconds = fmod(timef, 1.0) * 1000;

    // parse out latitude
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      strncpy(degreebuff, p, 2);
      p += 2;
      degreebuff[2] = '\0';
      degree = atol(degreebuff) * 10000000;
      strncpy(degreebuff, p, 2); // minutes
      p += 3; // skip decimal point
      strncpy(degreebuff + 2, p, 4);
      degreebuff[6] = '\0';
      minutes = 50 * atol(degreebuff) / 3;
      latitude_fixed = degree + minutes;
      latitude = degree / 100000 + minutes * 0.000006F;
      latitudeDegrees = (latitude-100*int(latitude/100))/60.0;
      latitudeDegrees += int(latitude/100);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      if (p[0] == 'S') latitudeDegrees *= -1.0;
      if (p[0] == 'N') lat = 'N';
      else if (p[0] == 'S') lat = 'S';
      else if (p[0] == ',') lat = 0;
      else return false;
    }
    
    // parse out longitude
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      strncpy(degreebuff, p, 3);
      p += 3;
      degreebuff[3] = '\0';
      degree = atol(degreebuff) * 10000000;
      strncpy(degreebuff, p, 2); // minutes
      p += 3; // skip decimal point
      strncpy(degreebuff + 2, p, 4);
      degreebuff[6] = '\0';
      minutes = 50 * atol(degreebuff) / 3;
      longitude_fixed = degree + minutes;
      longitude = degree / 100000 + minutes * 0.000006F;
      longitudeDegrees = (longitude-100*int(longitude/100))/60.0;
      longitudeDegrees += int(longitude/100);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      if (p[0] == 'W') longitudeDegrees *= -1.0;
      if (p[0] == 'W') lon = 'W';
      else if (p[0] == 'E') lon = 'E';
      else if (p[0] == ',') lon = 0;
      else return false;
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      fixquality = atoi(p);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      satellites = atoi(p);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      HDOP = atof(p);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      altitude = atof(p);
    }
    
    p = strchr(p, ',')+1;
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      geoidheight = atof(p);
    }
    return true;
  }
  if (strstr(nmea, "$GPRMC")) {
   // found RMC
    char *p = nmea;

    // get time
    p = strchr(p, ',')+1;
    float timef = atof(p);
    uint32_t time = timef;
    hour = time / 10000;
    minute = (time % 10000) / 100;
    seconds = (time % 100);

    milliseconds = fmod(timef, 1.0) * 1000;

    p = strchr(p, ',')+1;
    // Serial.println(p);
    if (p[0] == 'A') 
      fix = true;
    else if (p[0] == 'V')
      fix = false;
    else
      return false;

    // parse out latitude
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      strncpy(degreebuff, p, 2);
      p += 2;
      degreebuff[2] = '\0';
      long degree = atol(degreebuff) * 10000000;
      strncpy(degreebuff, p, 2); // minutes
      p += 3; // skip decimal point
      strncpy(degreebuff + 2, p, 4);
      degreebuff[6] = '\0';
      long minutes = 50 * atol(degreebuff) / 3;
      latitude_fixed = degree + minutes;
      latitude = degree / 100000 + minutes * 0.000006F;
      latitudeDegrees = (latitude-100*int(latitude/100))/60.0;
      latitudeDegrees += int(latitude/100);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      if (p[0] == 'S') latitudeDegrees *= -1.0;
      if (p[0] == 'N') lat = 'N';
      else if (p[0] == 'S') lat = 'S';
      else if (p[0] == ',') lat = 0;
      else return false;
    }
    
    // parse out longitude
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      strncpy(degreebuff, p, 3);
      p += 3;
      degreebuff[3] = '\0';
      degree = atol(degreebuff) * 10000000;
      strncpy(degreebuff, p, 2); // minutes
      p += 3; // skip decimal point
      strncpy(degreebuff + 2, p, 4);
      degreebuff[6] = '\0';
      minutes = 50 * atol(degreebuff) / 3;
      longitude_fixed = degree + minutes;
      longitude = degree / 100000 + minutes * 0.000006F;
      longitudeDegrees = (longitude-100*int(longitude/100))/60.0;
      longitudeDegrees += int(longitude/100);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      if (p[0] == 'W') longitudeDegrees *= -1.0;
      if (p[0] == 'W') lon = 'W';
      else if (p[0] == 'E') lon = 'E';
      else if (p[0] == ',') lon = 0;
      else return false;
    }
    // speed
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      speed = atof(p);
    }
    
    // angle
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      angle = atof(p);
    }
    
    p = strchr(p, ',')+1;
    if (',' != *p)
    {
      uint32_t fulldate = atof(p);
      day = fulldate / 10000;
      month = (fulldate % 10000) / 100;
      year = (fulldate % 100);
    }
    // we dont parse the remaining, yet!
    return true;
  }

  return false;
}
//fonction lecture de la classe GPS
char Lighter_Adafruit_GPS::read(void) {
  char c = 0;
  

    if(!gpsSwSerial->available()) return c;
    c = gpsSwSerial->read();


  if (c == '\n') {
    currentline[lineidx] = 0;

    if (currentline == line1) {
      currentline = line2;
      lastline = line1;
    } else {
      currentline = line1;
      lastline = line2;
    }

    lineidx = 0;
    recvdflag = true;
  }

  currentline[lineidx++] = c;
  if (lineidx >= MAXLINELENGTH)
    lineidx = MAXLINELENGTH-1;

  return c;
}

//constructeur du GPS 
Lighter_Adafruit_GPS::Lighter_Adafruit_GPS(SoftwareSerial *ser)
{
  common_init();     // Set everything to common state, then...
  gpsSwSerial = ser; // ...override gpsSwSerial with value passed.
}

// Initialization code used by all constructor types
void Lighter_Adafruit_GPS::common_init(void) {

  gpsSwSerial = NULL; // Set both to NULL, then override correct

 // gpsHwSerial = NULL; // port pointer in corresponding constructor
  recvdflag   = false;
 // paused      = false;
  lineidx     = 0;
  currentline = line1;
  lastline    = line2;

  hour = minute = seconds = year = month = day =
    fixquality = satellites = 0; // uint8_t
  lat = lon = mag = 0; // char
  fix = false; // boolean
  milliseconds = 0; // uint16_t
  latitude = longitude = geoidheight = altitude =
    speed = angle = magvariation = HDOP = 0.0; // float
}
//fonction initialisation GPS
void Lighter_Adafruit_GPS::begin(uint16_t baud)
{
    gpsSwSerial->begin(baud);
  delay(10);
}
//fonction d'envoie des demandes du GPS 
void Lighter_Adafruit_GPS::sendCommand(const char *str) {
    gpsSwSerial->print(str);
}
//fonction de nouvelle reception GPS
boolean Lighter_Adafruit_GPS::newNMEAreceived(void) {
  return recvdflag;
}


//fonction ancienne reception GPS
char *Lighter_Adafruit_GPS::lastNMEA(void) {
  recvdflag = false;
  return (char *)lastline;
}
//fonction de convertisseur
// lecture en hexa et renvoie en decimal
uint8_t Lighter_Adafruit_GPS::parseHex(char c) {
    if (c < '0')
      return 0;
    if (c <= '9')
      return c - '0';
    if (c < 'A')
       return 0;
    if (c <= 'F')
       return (c - 'A')+10;
    // if (c > 'F')
    return 0;
}

bonjour
les sentences NMEA se terminent obligatoirement par CR/LF
si tu ne veux pas enregistrer CR/LF il suffit de faire -2 sur la variable stringsize

ah je ne savais pas merci :slight_smile:
je fais -2 à quel ligne ?

if (stringsize != logfile.write((uint8_t *)stringptr, stringsize-2))

Le retour chario n'est plus disponible à la fin de la trame mais il n'a pas disparu au début la trame GPS

Dans ce cas oubli le -2, essaye :

int i=0;

while(stringptr[i]!=NULL) {
if(stringptr[i]!=10 && stringptr[i]!=13)  logfile.write(stringptr[i]);
i++;
}

Yes! ça fonctionne merci beaucoup , je peux passer sur un autre projet :slight_smile:

B@tto:
Dans ce cas oubli le -2, essaye :

int i=0;

while(stringptr[i]!=NULL) {
if(stringptr[i]!=10 && stringptr[i]!=13)  logfile.write(stringptr[i]);
i++;
}

bonjour
et encore plus basiquement , les sentences NMEA etant en ascii lisible, un test sur >31 doit aussi bien faire l'affaire

if(stringptr[i] >31) logfile.write(stringptr[i]);