Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnCommWin.cpp
- Revision:
- 25:57b2627fe756
- Parent:
- 24:7d725fc8201e
- Child:
- 26:b3180073c8ec
--- a/SnCommWin.cpp Tue Oct 23 20:58:29 2012 +0000 +++ b/SnCommWin.cpp Tue Oct 30 05:23:57 2012 +0000 @@ -15,6 +15,8 @@ //#define DEBUG +const char* SnCommWin::kLocalDir = "/local"; + uint32_t SnCommWin::GetConnectTimeout() const { return kConnectTimeout; } uint32_t SnCommWin::GetListenTimeout() const { return kListenTimeout; } @@ -25,7 +27,7 @@ } else { const uint32_t ct = time(0); if ( (ct==0) || - (abs(static_cast<double>(timeout_clock-ct))>kSecsPerDay) ) { + (fabs(static_cast<double>(timeout_clock-ct))>kSecsPerDay) ) { // clock problems! // timeout now. hope the clock problems // get fixed in the next comm window @@ -92,7 +94,8 @@ const uint32_t bsize, const uint32_t nevts, const uint32_t timeout_clock, - const uint32_t handshakeTimeout) { + const uint32_t handshakeTimeout, + uint8_t* hndres) { // nevts==0 ==> send all events // handshakeTimeout is never a clock time -- always a delta(t) @@ -128,10 +131,14 @@ uint8_t hndshk=0; res = WaitHandshake(curConf, handshakeTimeout, genBuf, bsize, hndshk); #ifdef DEBUG + if (hndres!=0) { + *hndres = hndshk; + } printf("res=%d, nevts=%u, isdel=%d, inf=%p, curfile=%p, hndshk=%02x\r\n", res, nevts, curConf.IsDeletingFiles(), inf, SnSDUtils::GetCurFile(), hndshk); #endif +/* if ( (res==SnCommWin::kOkWithMsg) // got handshake && (nevts==0) // sent whole file && curConf.IsDeletingFiles() // want to delete @@ -144,6 +151,7 @@ SnSDUtilsWhisperer::DeleteFile(inf, infn); didDel=true; } +*/ } } } @@ -155,6 +163,11 @@ if ( (inf!=SnSDUtils::GetCurFile()) && (didDel==false) ) { SnSDUtils::CloseOutputFile(inf); } + if ( IsTimedOut(timeout_clock) ) { + if ( kFailTimeout < res ) { + res = kFailTimeout; + } + } return res; } @@ -204,6 +217,16 @@ return SnCommWin::kUnexpectedRec; } +void SnCommWin::CapitalizeInPlace(std::string::iterator s, + const std::string::const_iterator send) { + static const char upd = 'a' - 'A'; // a>A + for (; s!=send; ++s) { + if ( ((*s)>='a') && ((*s)<='z') ) { + (*s) -= upd; + } + } +} + SnCommWin::ECommWinResult SnCommWin::GetLocalFile(std::string fname, char* const buf, const uint32_t bsize, @@ -220,7 +243,7 @@ #endif // got the header.. make the file.. // make the file name ALLCAPS, since LocalFileSystem will do it anyway - std::transform(fname.begin(), fname.end(), fname.begin(), toupper); + CapitalizeInPlace(fname.begin(), fname.end()); // now ensure the file name is 8.3 only -- for LocalFileSystem const size_t ldlen = strlen(kLocalDir); // 12 = 8.3 filename format, 1 for / and 1 for \0