Hi all.
I need to read a .txt document with my c++ program. My .txt is data that I take from a GPS and it has different kind of data
i.e. <timeStamp> <status> <latitude> <longitude> <altitude> <numSatellites> <HDOP> <X> <Y> <Z> <X2D> <Y2D> <Xdiff3D-2D> <Ydiff3D-2D> <NMEA_GGAstring><CR>
and the information is like this:
1213891110.84 0 41.3831338 2.1161887 66.2 7 1.2 -294.85 -554.07 -56.49 -336.30 -559.84 41.46 5.77 $GPGGA,155830.00,4122.98803,N,00206.97132,E,1,07,1.2,66.21,M,51.31,M,0.0,,*50
1213891111.96 0 41.3831343 2.1161892 66.2 7 1.2 -294.78 -554.07 -56.49 -336.23 -559.83 41.45 5.77 $GPGGA,155831.00,4122.98806,N,00206.97135,E,1,07,1.2,66.17,M,51.31,M,0.0,,*56
So the problem is to create the code to open and read this.
My code is....
#include "gpsfromFile.h"
/**
Default constructor. Reads configuration file, opens data and log files and opens and onfigures the serial port the config file says
*/
CgpsfromFile::CgpsfromFile(int partnerID, int robotID, char *labelString) : Cgps(partnerID,robotID,labelString)
{
cout << "Here is where I need to implement constructor. Open file define in labelstring" << endl;
}
/**
Default destructor. Closes serial port
*/
CgpsfromFile::~CgpsfromFile()
{
cout << "Here is where I implement destructor. Close file define in labelstring" << endl;
}
*/
void CgpsfromFile::process()
{
cout << "Here is where I need to implement the process to read line by line the filename with fscanf or fread and change the data in the define variables in the protected of gps.h" << endl;
}
-------------------------------------------------------------------------------------------
This is what I got in gpsfromFile.h
#ifndef gpsfromFile_h
#define gpsfromFile_h
#include <sys/time.h>
#include <termios.h>
#include <fcntl.h>
#include "../gps/gps.h"
using namespace std;
/**
CgpsfromFile implements a class for a gps as read from a file based on the generic class for gps, Cgps
*/
class CgpsfromFile : public Cgps
{
protected:
struct stime
{
unsigned int hour;
unsigned int minute;
unsigned int second;
unsigned int cen_second;
};
public:
CgpsfromFile(int partnerID, int robotID, char *labelString); /**<default constructor, opens file to read from */
virtual ~CgpsfromFile(); /**<default destructor, closes file, data and log files*/
void process();
// void printData(); /**<Prints data to gpsDataFile*/
};
#endif
-----------------------------------------------------------------------------------------------------
and this is gps.h
#ifndef gps_h
#define gps_h
//include
#include <math.h>
#include <yarp/os/Network.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/os/Bottle.h>
#include "../logDataProcess/logDataProcess.h"
//const double deg2rad= 3.141592653589793/180.0;
using namespace yarp::os;
/**
Cgps implements a generic class for gps devices, based on the class ClogDataFiles which manages with Data and Log files
*/
class Cgps : public ClogDataProcess
{
protected:
double latitude, longitude, altitude; /**<Earth coordinates (degrees, degrees, meters) */
int numSatellites; /**<Number of satellites */
float HDOP; /**<Horizontal Dilution of Precision */
double xx2d, yy2d, xx, yy, zz; /**<Coordinates wrt map origin (meters) */
char NMEAGGA[88]; /**<NMEA chain buffer type GGA. Max lenght is 82 + 1 for \\n*/
char stringData[250];/**<auxiliar string to write data to be printed in the data file*/
BufferedPort<Bottle> output; /**<YARP port to send the device data*/
public:
Cgps(int ptid, int rid, char *labelString); /**<constructor*/
virtual ~Cgps(); /**<destructor*/
virtual void process()=0; /**<loads gps data to the variables. Returns an error code. 0 is OK! */
void printData(); /**<Prints data to gpsDataFile*/
void sendData(); /**<writes device data to the yarp output port*/
};
#endif