-
Dependents: GPSXbee_1_1 GPSXbee_1_0
Revision 1:d4cbfcb2be46, committed 2014-12-16
- Comitter:
- Deurklink
- Date:
- Tue Dec 16 13:00:07 2014 +0000
- Parent:
- 0:8b33ba38cc3a
- Commit message:
- Version 1.1
Changed in this revision
Beacon.cpp | Show annotated file Show diff for this revision Revisions of this file |
Beacon.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Beacon.cpp Fri Jul 04 09:51:12 2014 +0000 +++ b/Beacon.cpp Tue Dec 16 13:00:07 2014 +0000 @@ -2,12 +2,14 @@ Beacon::Beacon(PinName gpsTx, PinName gpsRx, PinName xbTx, PinName xbRx, int freq, int len) : gps(gpsTx, gpsRx), + sd(p5, p6, p7, p8, "sd"), L1(LED1), L2(LED2), L3(LED3), L4(LED4), XBee(xbTx, xbRx), - PPS(p5), + PPS(p30), + CD(p25), T1(p11), T2(p12), T3(p15), @@ -27,6 +29,7 @@ RxTO = false; PulseFrequency = 25; //Hz Pulselength = 1000; //usec + SDEnabled = false; } // Beacon initialisation @@ -34,30 +37,22 @@ // Power down ethernet module PHY_PowerDown(); - // Initialize dipswitches initDipSwitch(); - // Read beacon number and timing offset readDipSwitch(); + SDEnabled = initSD(); // Set baud rate XBee.baud(9600); - - XBee.printf("\r\n.. Beacon (ID:%d) Initializing ..\n",BeaconNumber); // Initialize GPS unit gps.Init(); - //Attach interrupt to rising edge of GPS PPS pin PPS.rise(this, &Beacon::ppsSync); // Initialize PWM - resetPWM(PulseFrequency, Pulselength); - - XBee.printf("\r\n.. Beacon (ID:%d) Initialization finished ..\n",BeaconNumber); - - L1 = 1; + resetPWM(PulseFrequency, Pulselength); return true; } @@ -107,6 +102,34 @@ //--------------------------------------------------------------------------- + +//------------------------------------SD------------------------------------ +bool Beacon::initSD(){ + CD.mode(PullUp); + + if (CD == 1) { + L3 = 1; + FILE *fp = fopen("/sd/log.txt", "a"); + if(fp == NULL) { + fclose(fp); + return false; + } + else{ + fprintf(fp,"\r\nSTART LOG"); + fclose(fp); + L4 = 1; + return true; + } + } + else{ + return false; + } +} + +//--------------------------------------------------------------------------- + + + //------------------------------------PWM------------------------------------ void Beacon::startPWM(){ // enable PWM mode and counting @@ -167,6 +190,7 @@ void Beacon::printStatus(){ // Print the status of a Beacon XBee.printf("\r\n\nBeacon (ID:%d); TimingOffset: %d",BeaconNumber, TimingOffset); + XBee.printf("\r\nLogging enabled: %d (0=off,1=on)",SDEnabled); XBee.printf("\r\nLast GPS update: %d:%d:%2.2f",gps.hours, gps.minutes, gps.seconds); XBee.printf("\r\nFlash frequency: %d Hz; Pulse length: %d usec", PulseFrequency, Pulselength); XBee.printf("\r\nPulse generation: %d (0=off,1=on)",PWMon); @@ -323,6 +347,14 @@ XBee.printf("\r\nBeacon (ID:%d) did not understand message",BeaconNumber); XBee.printf("\r\nReceived: %s",RxBuffer); } + + if (SDEnabled){ + FILE *fp = fopen("/sd/log.txt", "a"); + fprintf(fp,"\r\n%d:%d:%2.2f Received: %s",gps.hours, gps.minutes, gps.seconds, RxBuffer); + fclose(fp); + } + + // Flush buffer for (int i=0;i<255;i++){ RxBuffer[i] = '0';
--- a/Beacon.h Fri Jul 04 09:51:12 2014 +0000 +++ b/Beacon.h Tue Dec 16 13:00:07 2014 +0000 @@ -3,6 +3,7 @@ #include "GPS.h" #include "EthernetPowerControl.h" #include "MODSERIAL.h" +#include "SDFileSystem.h" #define XBEETIMEOUT 5 @@ -11,6 +12,7 @@ public: Beacon(PinName gpsTx, PinName gpsRx, PinName xbTx, PinName xbRx, int freq, int len); GPS gps; + SDFileSystem sd; bool init(); void parseXbee(); void parseGpsData(); @@ -36,6 +38,11 @@ void ppsSync(); void readDipSwitch(); void initDipSwitch(); + + bool initSD(); + bool SDEnabled; + // SD card detect pin + DigitalIn CD; // Pins are all bound to a mbed pin in the constructor // Digital pins for setting the Timing offset