QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

handle/dataLocation.h

Committer:
dylanembed123
Date:
2014-04-10
Revision:
14:6be57da62283
Parent:
9:da906eeac51e
Child:
15:e3e03a9df89e

File content as of revision 14:6be57da62283:

/**
  *  \brief Data location data holder
  **/

#define MAXNUMLOCS 64

typedef struct DataLocS{
    double lat,lon,alt;
    double timestamp;
}DataLoc;

// Storage of data location
class DataLocation{
private:
    // Current value of lat lon and alt
    double lat,lon,alt;
    double timestamp;
public:
    DataLocation(){}
    DataLocation(double latA,double lonA,double altA,double timestampA=0):lat(latA),lon(lonA),alt(altA),timestamp(timestampA){}
    double& getLat(){return lat;}
    double& getLon(){return lon;}
    double& getAlt(){return alt;}
};

/// \brief Location holder type
enum LHType{
    LHType_locs=0,
    LHType_targ,
    LHType_base
};

/// \brief Location holder index type
enum LHIType{
    LHIType_head=0,
    LHIType_size
};

// Singleton location holder
class LocHolder{
private:
    // Actual Locations (absolute)
    DataLocation locs[MAXNUMLOCS];
    // Target Locations (relative to base station -> base station is at 0,0,0)
    DataLocation targ[MAXNUMLOCS];
    // Base Station Locations (absolute)
    DataLocation base[MAXNUMLOCS];
    // Index of the head of the circular buffers
    unsigned int headLocs,headTarg,headBase;
    // Number of locations
    unsigned int sizeLocs,sizeTarg,sizeBase;
public:
    /// \brief Default constructor
    LocHolder():headLocs(0),headTarg(0),headBase(0),sizeLocs(0),sizeTarg(0),sizeBase(0){}
    
    /// \brief Get locations type
    DataLocation* get(LHType type);
    
    /// \brief Get Current value
    DataLocation& getC(LHType type,int offset=0);
    
    /// \brief Get Index
    unsigned int& getI(LHType type,LHIType indexType=LHIType_head);
    
    /// \brief Fix an index that might be out of bounds;
    unsigned int getRealIndex(LHType type,int index,int offset=0,bool useSize=true);
    
    /// \brief Increment index
    void inc(LHType type,int amount=1,bool abs=false);
    
    /// \brief Append a location to the end.
    void add(LHType type,DataLocation newLoc);
};

static LocHolder mainLocHolder;
static LocHolder& Locs(){return mainLocHolder;}