Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: main.cpp
- Revision:
- 28:484943132bb0
- Parent:
- 27:efc4d654b139
- Child:
- 30:f869ed4bcc08
--- a/main.cpp Thu Nov 01 07:00:17 2012 +0000 +++ b/main.cpp Sat Nov 24 06:38:43 2012 +0000 @@ -4,8 +4,9 @@ Watchdog::SnKickStarter gKickStarter(WDFAILSAFE); #define ENABLE_AFAR_COMM -//#define ENABLE_SBD_COMM +#define ENABLE_SBD_COMM //#define ENABLE_USB_COMM +#define ENABLE_AFAR_TWITTER //#define USE_RTOS_TIMER //#define USE_ETH_INTERFACE @@ -36,6 +37,9 @@ #include "SnCommAfarTCP.h" #else #include "SnCommAfarNetIf.h" +#ifdef ENABLE_AFAR_TWITTER +#include "SnCommAfarNetIfTwitter.h" +#endif #endif #include "SnCommUsb.h" #include "SnCommSBD.h" @@ -183,6 +187,9 @@ //static char gB64Buf[gB64Bsize]; static char gGenBuf[gBufSize]; // must be big enough for event or status or config! static SnCommWin* gComms[kNcomms] = { 0 }; // order => priority. afar uses RTOS, and must be made inside main +#if defined(ENABLE_AFAR_TWITTER) && defined(ENABLE_AFAR_COMM) +static SnCommAfarNetIfTwitter* gTwit = 0; +#endif void procForceTrigger() { if (gReadingOut==false && gCommWinOpen==false) { @@ -535,6 +542,9 @@ gComms[comi++] = new SnCommAfarTCP(gConf); #else gComms[comi++] = new SnCommAfarNetIf(gConf); +#ifdef ENABLE_AFAR_TWITTER + gTwit = new SnCommAfarNetIfTwitter(gConf); +#endif #endif #endif #ifdef ENABLE_SBD_COMM @@ -545,9 +555,9 @@ #endif #ifdef DEBUG - printf("make comm objects\r\n"); + printf("made comm objects\r\n"); #endif - + #ifdef USE_RTOS_TIMER gForceTicker = new rtos::RtosTimer(&procForceTrigger); gHeartbeatTicker = new rtos::RtosTimer(&procHeartbeat); @@ -1065,16 +1075,6 @@ wait_ms(200); MakeOutputFile(); - /* - // TODO: change comm parameters - printf("set comm params\r\n"); - for (uint8_t cc=0; cc<kNcomms; cc++) { - if (gComms[cc]!=0) { - gComms[cc]->Set(gConf); - } - } - */ - // reset tickers ResetAllTickers(); @@ -1133,12 +1133,12 @@ } //PIN_forceTrigger=0; // necessary for forced triggers, harmless for other triggers gReadingOut = true; // disallow new forced triggers - +/* #ifdef DEBUG printf("after wait for trig. PIN_a_sf_clk=%d\r\n", PIN_a_sf_clk.read()); #endif - +*/ // we can't be interrupted before data arrives at the MB FPGA //StopAllTickers(); /* @@ -1265,6 +1265,10 @@ // time to recount files for the status update SnStatusFrame::fgRecalcFiles = true; +#if defined(ENABLE_AFAR_TWITTER) && defined(ENABLE_AFAR_COMM) + bool doTwitter = false; +#endif + #ifdef DEBUG printf("start loop over comms\r\n"); #endif @@ -1337,6 +1341,14 @@ Watchdog::kick(); // don't reset! // connected. listen for config *ss = false; // don't send status next time + +#if defined(ENABLE_AFAR_TWITTER) && defined(ENABLE_AFAR_COMM) + if ((*cw)->GetCommType()==SnConfigFrame::kAfar) { + // if we connected by Afar + doTwitter = true; + } +#endif + #ifdef DEBUG printf("get conf gtt=%u\r\n",gConf.GetTimeoutTime(gLastCommWin, listo)); #endif @@ -1380,12 +1392,14 @@ Watchdog::kick(); // don't reset! } // end loop over comms - // close the connection(s) + + // check Iridium time & close the connection(s) cw = gComms; for (uint8_t i=0; i<kNcomms; i++, cw++) { if ((*cw)==0) { continue; } + // check Iridium time if ((*cw)->GetCommType()==SnConfigFrame::kIrid) { #ifdef DEBUG printf("try to set iridium time\r\n"); @@ -1399,11 +1413,56 @@ gConf.GetTimeoutTime(gLastCommWin,gConf.GetCommWinDuration())); } } + // close the connection (*cw)->CloseConn(gConf.GetTimeoutTime(gLastCommWin,gConf.GetCommWinDuration())); Watchdog::kick(); // don't reset! + // after normal Afar connection closed, try to tweet + if ((*cw)->GetCommType()==SnConfigFrame::kAfar) { + // tweet +#if defined(ENABLE_AFAR_TWITTER) && defined(ENABLE_AFAR_COMM) +#ifdef DEBUG + printf("for twitter: gTwit=%p, doTwitter=%d\r\n",gTwit,(int)doTwitter); +#endif + // send a twitter update + if ( (gTwit!=0) && doTwitter ) { + const uint32_t conto = + (gConf.GetCommWinDuration() < gTwit->GetConnectTimeout()) ? + gConf.GetCommWinDuration() : gTwit->GetConnectTimeout(); + const uint32_t listo = + (gConf.GetCommWinDuration() < gTwit->GetListenTimeout()) ? + gConf.GetCommWinDuration() : gTwit->GetListenTimeout(); +#ifdef DEBUG + printf("open twit window. conto=%u, listo=%u\r\n", + conto, listo); +#endif + const SnCommWin::ECommWinResult conres = gTwit->OpenWindow( + gConf.GetTimeoutTime(gLastCommWin, conto), false, gConf, + gEvent, gPower, + SnSDUtils::GetCurSeqNum(), thmrate, evtrate, + gGenBuf); + if (conres>=SnCommWin::kConnected) { + Watchdog::kick(); // don't reset! + gTwit->Tweet(gConf, thmrate, evtrate, gGenBuf, + gConf.GetTimeoutTime(time(0), listo)); + } + } + } +#endif + } + } // if duration >0 + + /* not working. must use DEFCONF.DAT to change IP's. + // change comm parameters (IP addresses) +#ifdef DEBUG + printf("set comm params\r\n"); +#endif + for (uint8_t cc=0; cc<kNcomms; cc++) { + if (gComms[cc]!=0) { + gComms[cc]->Set(gConf); } } - + */ + // (probably) power down comms and power up cards,amps SetPower(false);