Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 6:f0248eb6714d, committed 2014-04-03
- Comitter:
- dylanembed123
- Date:
- Thu Apr 03 16:27:23 2014 +0000
- Parent:
- 5:eef5ea6a9916
- Commit message:
- Fix compile errors;
Changed in this revision
--- a/adapt/camera.h Thu Apr 03 15:56:05 2014 +0000 +++ b/adapt/camera.h Thu Apr 03 16:27:23 2014 +0000 @@ -1,3 +1,6 @@ +#ifndef _CAMERA_H_ +#define _CAMERA_H_ + /** * \brief Camera interface **/ @@ -88,4 +91,5 @@ uint8_t readResponse(uint8_t numbytes, uint8_t timeout); // Send the command void sendCommand(uint8_t cmd, uint8_t args[] = 0, uint8_t argn = 0); -}; \ No newline at end of file +}; +#endif \ No newline at end of file
--- a/adapt/gps.cpp Thu Apr 03 15:56:05 2014 +0000 +++ b/adapt/gps.cpp Thu Apr 03 16:27:23 2014 +0000 @@ -8,5 +8,5 @@ gps=new Serial(GPSPINTX,GPSPINRX); gps->baud(GPSBAUD);//gps->baud(115200);//57600); } - return *pc; + return *gps; } \ No newline at end of file
--- a/handle/dataLocation.cpp Thu Apr 03 15:56:05 2014 +0000 +++ b/handle/dataLocation.cpp Thu Apr 03 16:27:23 2014 +0000 @@ -1,39 +1,25 @@ - - -DataLocation* LocHolder::locs=NULL; -DataLocation* LocHolder::targ=NULL; -DataLocation* LocHolder::base=NULL; - -unsigned int LocHolder::headLocs=0; -unsigned int LocHolder::headTarg=0; -unsigned int LocHolder::headBase=0; - -unsigned int LocHolder::sizeLocs=0; -unsigned int LocHolder::sizeTarg=0; -unsigned int LocHolder::sizeBase=0; +#include "dataLocation.h" DataLocation* LocHolder::get(LHType type){ if(type==LHType_locs){ - if(locs==NULL)locs=new DataLocation[MAXNUMLOCS]; return locs; }else if(type==LHType_targ){ - if(targ==NULL)targ=new DataLocation[MAXNUMLOCS]; return targ; }else if(type==LHType_base){ - if(base==NULL)base=new DataLocation[MAXNUMLOCS]; return base; } -} - -unsigned int LocHolder::getRealIndex(int index,int offset=0){ - return (index+offset)%MAXNUMLOCS; + return base; } -DataLocation& LocHolder::getC(LHType type,int offset=0){ - return get(type)[getRealIndex(headLocs,offset)]; +unsigned int LocHolder::getRealIndex(LHType type,int index,int offset,bool useSize){ + return (index+offset)%(useSize?getI(type,LHIType_size):MAXNUMLOCS); } -unsigned int& getI(LHType type,LHIType indexType=LHIType_head){ +DataLocation& LocHolder::getC(LHType type,int offset){ + return get(type)[getRealIndex(type,offset)]; +} + +unsigned int& LocHolder::getI(LHType type,LHIType indexType){ if(indexType==LHIType_head){ // Grab proper header if(type==LHType_locs){return headLocs;}else if(type==LHType_targ){return headTarg;}else if(type==LHType_base){return headBase;} @@ -41,10 +27,17 @@ // Grab proper size if(type==LHType_locs){return sizeLocs;}else if(type==LHType_targ){return sizeTarg;}else if(type==LHType_base){return sizeBase;} } + return headLocs; } -void inc(LHType type,int amount=1){ +void LocHolder::inc(LHType type,int amount,bool abs){ unsigned int& index=getI(type); - index=(index+amount)%getI(type,LHIType_size); + index=getRealIndex(type,(abs?0:index),amount);//((abs?0:index)+amount)%getI(type,LHIType_size); getI(type)=index; +} + +void LocHolder::add(LHType type,DataLocation newLoc){ + getI(type)=getI(type,LHIType_size); + getI(type,LHIType_size)++; + getC(type)=newLoc; } \ No newline at end of file
--- a/handle/dataLocation.h Thu Apr 03 15:56:05 2014 +0000 +++ b/handle/dataLocation.h Thu Apr 03 16:27:23 2014 +0000 @@ -9,12 +9,14 @@ private: // Current value of lat lon and alt double lat,lon,alt; + double timestamp; public: - DataLocation(double latA,double lonA,double altA):lat(latA),lon(lonA),alt(altA){} + DataLocation(){} + DataLocation(double latA,double lonA,double altA,double t=0):lat(latA),lon(lonA),alt(altA),timestamp(t){} double& getLat(){return lat;} double& getLon(){return lon;} double& getAlt(){return alt;} -} +}; /// \brief Location holder type enum LHType{ @@ -33,18 +35,19 @@ class LocHolder{ private: // Actual Locations (absolute) - static DataLocation locs[MAXNUMLOCS]; + DataLocation locs[MAXNUMLOCS]; // Target Locations (relative to base station -> base station is at 0,0,0) - static DataLocation targ[MAXNUMLOCS]; + DataLocation targ[MAXNUMLOCS]; // Base Station Locations (absolute) - static DataLocation base[MAXNUMLOCS]; + DataLocation base[MAXNUMLOCS]; // Index of the head of the circular buffers - static unsigned int headLocs,headTarg,headBase; + unsigned int headLocs,headTarg,headBase; // Number of locations - static unsigned int sizeLocs,sizeTarg,sizeBase; + unsigned int sizeLocs,sizeTarg,sizeBase; + LocHolder():headLocs(0),headTarg(0),headBase(0),sizeLocs(0),sizeTarg(0),sizeBase(0){} public: /// \brief Get locations type - static DataLocation* get(LHType type); + DataLocation* get(LHType type); /// \brief Get Current value DataLocation& getC(LHType type,int offset=0); @@ -52,15 +55,11 @@ /// \brief Get Index unsigned int& getI(LHType type,LHIType indexType=LHIType_head); - /// \brief Increment index - void inc(LHType type,int amount=1); + /// \brief Fix an index that might be out of bounds; + unsigned int getRealIndex(LHType type,int index,int offset=0,bool useSize=true); - /// \brief Add data - void addLocs(DataLocation newLoc); - void addTarg(DataLocation newLoc); - void addBase(DataLocation newLoc); + /// \brief Increment index + void inc(LHType type,int amount=1,bool abs=false); - void incLocs(int amount=1); - void incLocs(int amount=1); - void incLocs(int amount=1); + void add(LHType type,DataLocation newLoc); }; \ No newline at end of file
--- a/handle/handleCamera.cpp Thu Apr 03 15:56:05 2014 +0000 +++ b/handle/handleCamera.cpp Thu Apr 03 16:27:23 2014 +0000 @@ -17,7 +17,7 @@ int i; for(i=0;i<size;){ // read 32 bytes at a time; - uint8_t bytesToRead = min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups! + uint8_t bytesToRead = std::min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups! uint8_t bytesRead=0; uint8_t* buffer = cam.readPicture(bytesToRead,&bytesRead); for(int a=0;a<bytesRead;a++){USB::getSerial().putc(buffer[a]);}
--- a/handle/handleCamera.h Thu Apr 03 15:56:05 2014 +0000 +++ b/handle/handleCamera.h Thu Apr 03 16:27:23 2014 +0000 @@ -3,6 +3,7 @@ #include "adapt/usb.h" #include "adapt/camera.h" +#include <algorithm> class ImageHandle{ private: Camera cam;
--- a/handle/handleGPS.cpp Thu Apr 03 15:56:05 2014 +0000 +++ b/handle/handleGPS.cpp Thu Apr 03 16:27:23 2014 +0000 @@ -1,10 +1,11 @@ +#include "handleGPS.h" void GPSHandle::setup(){ } void GPSHandle::update(){ while(true){ - if(gps.readable()>0){ - char c = gps.getc(); + if(gps.getSerial().readable()>0){ + char c = gps.getSerial().getc(); USB::getSerial().printf("%c",c); } } @@ -12,4 +13,7 @@ bool GPSHandle::check(){ return true; +} + +void GPSHandle::run(){ } \ No newline at end of file
--- a/handle/handleGPS.h Thu Apr 03 15:56:05 2014 +0000 +++ b/handle/handleGPS.h Thu Apr 03 16:27:23 2014 +0000 @@ -2,10 +2,10 @@ #define _HANDLEGPS_H_ #include "adapt/usb.h" -#include "adapt/camera.h" +#include "adapt/gps.h" class GPSHandle{ private: - GPS gps + GPS gps; bool initialized; /// \brief Setup @@ -16,7 +16,7 @@ bool check(); public: /// \brief Constructor - ImageHandle():initialized(false){} + GPSHandle():initialized(false){} /// \brief Run an instance of this void run(); };
--- a/main.cpp Thu Apr 03 15:56:05 2014 +0000 +++ b/main.cpp Thu Apr 03 16:27:23 2014 +0000 @@ -3,6 +3,8 @@ #include <sstream> #include "adapt/usb.h" #include "adapt/camera.h" +#include "handle/handleCamera.h" +#include "handle/handleGPS.h" /* Serial pc(USBTX,USBRX); Serial xbee(p9,p10);//tx, rx @@ -157,7 +159,7 @@ int main(){ ImageHandle imageHand; - GPSHand gpsHand; + GPSHandle gpsHand; /// Main Loop while(1){