Index: trunk/lib/FlairSensorActuator/src/NmeaGps.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/Gps.cpp	(revision 42)
+++ trunk/lib/FlairSensorActuator/src/NmeaGps.cpp	(revision 51)
@@ -4,5 +4,5 @@
 // %flair:license}
 //  created:    2013/08/23
-//  filename:   Gps.cpp
+//  filename:   NmeaGps.cpp
 //
 //  author:     Guillaume Sanahuja
@@ -11,13 +11,12 @@
 //  version:    $Id: $
 //
-//  purpose:    objet integrant le recepteur gps mb800
+//  purpose:    Base class for GPS using NMEA sentances
 //
 //
 /*********************************************************************/
 
-#include "Gps.h"
+#include "NmeaGps.h"
 #include "geodesie.h"
 #include <Euler.h>
-#include <cvmatrix.h>
 #include <DataPlot1D.h>
 #include <Tab.h>
@@ -31,4 +30,5 @@
 #include <Vector3D.h>
 #include <Label.h>
+#include <GpsData.h>
 #include <string.h>
 
@@ -41,5 +41,5 @@
 namespace sensor {
 
-Gps::Gps(const FrameworkManager *parent, string name, NMEAFlags_t NMEAFlags)
+NmeaGps::NmeaGps(const FrameworkManager *parent, string name, NMEAFlags_t NMEAFlags)
     : IODevice(parent, name) {
   this->NMEAFlags = NMEAFlags;
@@ -50,31 +50,8 @@
 
   if ((NMEAFlags & GGA) == 0) {
-    Err("Enable at least GGA sentence\n");
-  }
-
-  int index = 0;
-  if ((NMEAFlags & GGA) != 0) {
-    index += 3;
-  }
-  if ((NMEAFlags & VTG) != 0) {
-    index += 2;
-  }
-  if ((NMEAFlags & GST) != 0) {
-    index += 3;
-  }
-
-  cvmatrix_descriptor *desc = new cvmatrix_descriptor(index, 1);
-  index = 0;
-  if ((NMEAFlags & GGA) != 0) {
-    desc->SetElementName(0, 0, "e");
-    desc->SetElementName(1, 0, "n");
-    desc->SetElementName(2, 0, "u");
-    index += 3;
-  }
-  if ((NMEAFlags & VTG) != 0) {
-    desc->SetElementName(index, 0, "ve");
-    desc->SetElementName(index + 1, 0, "vn");
-    index += 2;
-  }
+    Err("Enable at least the GGA sentence\n");
+  }
+
+ /*
   if ((NMEAFlags & GST) != 0) {
     desc->SetElementName(index, 0, "dev_lat");
@@ -83,6 +60,5 @@
     index += 3;
   }
-  output = new cvmatrix((IODevice *)this, desc, floatType);
-  AddDataToLog(output);
+  */
 
   // station sol
@@ -97,35 +73,42 @@
   position = new GeoCoordinate((IODevice *)this, "position", 0, 0, 0);
 
-  fix = FixQuality_t::Invalid;
-  nb_sat = 0;
   take_ref = false;
-  nb_sat_label->SetText("nb_sat: %i", nb_sat);
-  fix_label->SetText("fix: %i", fix);
-}
-
-Gps::~Gps() {
+
+  gpsData = new GpsData(this);
+  AddDataToLog(gpsData);
+
+  nb_sat_label->SetText("nb_sat: %i", gpsData->GetNumberOfSatellites());
+  fix_label->SetText("fix: %i", gpsData->GetFixQuality());
+}
+
+NmeaGps::~NmeaGps() {
   nmea_parser_destroy(&parser);
   delete main_tab;
 }
 
-void Gps::UseDefaultPlot(void) {
-  int index = 0;
+const GpsData *NmeaGps::GetDatas(void) const {
+   return gpsData;
+}
+
+void NmeaGps::GetDatas(core::GpsData **outGpsData) const {
+  *outGpsData = gpsData;
+}
+
+void NmeaGps::UseDefaultPlot(void) {
   plot_tab = new Tab(tab, "Mesures");
 
   if ((NMEAFlags & GGA) != 0) {
     e_plot = new DataPlot1D(plot_tab->NewRow(), "e", -10, 10);
-    e_plot->AddCurve(output->Element(index));
+    e_plot->AddCurve(gpsData->Element(GpsData::East));
     n_plot = new DataPlot1D(plot_tab->LastRowLastCol(), "n", -10, 10);
-    n_plot->AddCurve(output->Element(index + 1));
+    n_plot->AddCurve(gpsData->Element(GpsData::North));
     u_plot = new DataPlot1D(plot_tab->LastRowLastCol(), "u", -10, 10);
-    u_plot->AddCurve(output->Element(index + 2));
-    index += 3;
+    u_plot->AddCurve(gpsData->Element(GpsData::Up));
   }
   if ((NMEAFlags & VTG) != 0) {
     ve_plot = new DataPlot1D(plot_tab->NewRow(), "ve", -10, 10);
-    ve_plot->AddCurve(output->Element(index));
+    ve_plot->AddCurve(gpsData->Element(GpsData::EastVelocity));
     vn_plot = new DataPlot1D(plot_tab->LastRowLastCol(), "vn", -10, 10);
-    vn_plot->AddCurve(output->Element(index + 1));
-    index += 2;
+    vn_plot->AddCurve(gpsData->Element(GpsData::NorthVelocity));
   }
 
@@ -135,5 +118,5 @@
 }
 
-DataPlot1D *Gps::EPlot(void) const {
+DataPlot1D *NmeaGps::EPlot(void) const {
   if ((NMEAFlags & GGA) != 0) {
     return e_plot;
@@ -144,5 +127,5 @@
 }
 
-DataPlot1D *Gps::NPlot(void) const {
+DataPlot1D *NmeaGps::NPlot(void) const {
   if ((NMEAFlags & GGA) != 0) {
     return n_plot;
@@ -153,5 +136,5 @@
 }
 
-DataPlot1D *Gps::UPlot(void) const {
+DataPlot1D *NmeaGps::UPlot(void) const {
   if ((NMEAFlags & GGA) != 0) {
     return u_plot;
@@ -162,5 +145,5 @@
 }
 
-DataPlot1D *Gps::VEPlot(void) const {
+DataPlot1D *NmeaGps::VEPlot(void) const {
   if ((NMEAFlags & VTG) != 0) {
     return ve_plot;
@@ -171,5 +154,5 @@
 }
 
-DataPlot1D *Gps::VNPlot(void) const {
+DataPlot1D *NmeaGps::VNPlot(void) const {
   if ((NMEAFlags & VTG) != 0) {
     return vn_plot;
@@ -180,35 +163,19 @@
 }
 
-Layout *Gps::GetLayout(void) const { return sensor_tab; }
-
-Tab *Gps::GetPlotTab(void) const { return plot_tab; }
-
-TabWidget *Gps::GetTab(void) const { return tab; }
-
-uint16_t Gps::NbSat(void) const {
-  output->GetMutex();
-  uint16_t result = nb_sat;
-  output->ReleaseMutex();
-  return result;
-}
-
-Gps::FixQuality_t Gps::FixQuality(void) const {
-  output->GetMutex();
-  FixQuality_t result = fix;
-  output->ReleaseMutex();
-  return result;
-}
-
-void Gps::SetRef(void) { take_ref = true; }
-
-void Gps::GetENUPosition(Vector3D *point) {
-  output->GetMutex();
-  point->x = output->ValueNoMutex(0, 0);
-  point->y = output->ValueNoMutex(1, 0);
-  point->z = output->ValueNoMutex(2, 0);
-  output->ReleaseMutex();
-}
-
-void Gps::parseFrame(const char *frame, int frame_size) {
+Layout *NmeaGps::GetLayout(void) const { return sensor_tab; }
+
+Tab *NmeaGps::GetPlotTab(void) const { return plot_tab; }
+
+TabWidget *NmeaGps::GetTab(void) const { return tab; }
+
+void NmeaGps::SetRef(void) { take_ref = true; }
+
+void NmeaGps::GetEnu(Vector3D *point) {
+  gpsData->GetMutex();
+  gpsData->GetEnu(point->x,point->y,point->z);
+  gpsData->ReleaseMutex();
+}
+
+void NmeaGps::parseFrame(const char *frame, int frame_size) {
 
   int result;
@@ -222,20 +189,21 @@
 
   if (result == 1) {
+    nmea_info2pos(&info, &pos);
     // Printf("%s\n",frame);
-    // Printf("nb:%i fix:%i lat:%f long:%f alt:%f vel:%f
-    // angle:%f\n",pack.satinuse,pack.sig,info.lat,info.lon,info.elv,info.speed*1000./3600.,info.direction);
-    // Printf("lat:%f long:%f\n",pos.lat,pos.lon);
-    output->GetMutex(); // on utilise le mutex de l'output pour fix et nb_sat
-    if ((int)fix != pack.sig) {
-      fix = (FixQuality_t)pack.sig;
-      fix_label->SetText("fix: %i", fix);
-    }
-    if (nb_sat != pack.satinuse) {
-      nb_sat = pack.satinuse;
-      nb_sat_label->SetText("nb_sat: %i", nb_sat);
-    }
-    output->ReleaseMutex();
-
-    nmea_info2pos(&info, &pos);
+   //  Printf("nb:%i fix:%i lat:%f long:%f alt:%f vel:%f angle:%f\n",pack.satinuse,pack.sig,info.lat,info.lon,info.elv,info.speed*1000./3600.,info.direction);
+//Printf("lat:%f long:%f\n",pos.lat,pos.lon);
+
+    gpsData->GetMutex(); // on utilise le mutex de gpsData pour fix et nb_sat
+    if (gpsData->GetFixQuality() != (GpsData::FixQuality_t)pack.sig) {
+      gpsData->SetFixQuality((GpsData::FixQuality_t)pack.sig);
+      fix_label->SetText("fix: %i", pack.sig);
+    }
+    if (gpsData->GetNumberOfSatellites() != pack.satinuse) {
+      gpsData->SetNumberOfSatellites(pack.satinuse) ;
+      nb_sat_label->SetText("nb_sat: %i", pack.satinuse);
+    }
+    gpsData->ReleaseMutex();
+
+    gpsData->SetLla(Euler::ToDegree(pos.lat), Euler::ToDegree(pos.lon),info.elv);
     position->SetCoordinates(Euler::ToDegree(pos.lat), Euler::ToDegree(pos.lon),
                              info.elv);
@@ -257,20 +225,10 @@
       // Printf("lon:%f lat:%f elv:%f\n",pos.lon,pos.lat,info.elv);
 
-      // on prend une fois pour toute le mutex et on fait des accès directs
-      output->GetMutex();
-      output->SetValueNoMutex(0, 0, e);
-      output->SetValueNoMutex(1, 0, n);
-      output->SetValueNoMutex(2, 0, u);
-
-      int index = 3;
+      gpsData->SetEnu(e,n,u);
+
       if ((NMEAFlags & VTG) != 0) {
-        output->SetValueNoMutex(index, 0,
-                                info.speed * 1000. / 3600. *
-                                    sin(Euler::ToRadian(info.direction)));
-        output->SetValueNoMutex(index + 1, 0,
-                                info.speed * 1000. / 3600. *
-                                    cos(Euler::ToRadian(info.direction)));
-        index += 2;
-      }
+        gpsData->SetVelocity(info.speed * 1000. / 3600. * sin(Euler::ToRadian(info.direction)),
+                                  info.speed * 1000. / 3600. * cos(Euler::ToRadian(info.direction)));
+      }/*
       if ((NMEAFlags & GST) != 0) {
         // Thread::Printf("dev_lon:%f dev_lat:%f
@@ -280,9 +238,9 @@
         output->SetValueNoMutex(index + 2, 0, info.dev_elv);
         index += 3;
-      }
-      output->ReleaseMutex();
-
-      output->SetDataTime(GetTime());
-      ProcessUpdate(output);
+      }*/
+
+
+      gpsData->SetDataTime(GetTime());
+      ProcessUpdate(gpsData);
     }
   }
