Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnCommWin.cpp
- Revision:
- 6:6f002d202f59
- Parent:
- 3:24c5f0f50bf1
- Child:
- 8:95a325df1f6b
--- a/SnCommWin.cpp Fri Aug 03 00:04:34 2012 +0000 +++ b/SnCommWin.cpp Fri Aug 03 23:50:57 2012 +0000 @@ -1,13 +1,9 @@ #include "SnCommWin.h" +#include "SnHeaderFrame.h" #include "SnConfigFrame.h" #include "SnSDUtils.h" -/* -bool SnCommWin::fgCommEst = false; -bool SnCommWin::fgWinOpen = false; -*/ - SnCommWin::ECommWinResult SnCommWin::SendData(SnConfigFrame& conf, SnEventFrame& evt, char* const genBuf, @@ -15,10 +11,11 @@ const uint32_t timeout) { printf("SnCommWin::SendData\r\n"); ECommWinResult res = kUndefFail; + const uint32_t to = (conf.IsObeyingTimeout()) ? timeout : kSecsPerYear; if (conf.IsSendingAllFiles()) { printf("sending all files\r\n"); - const uint32_t to = (conf.IsObeyingTimeout()) ? timeout : kSecsPerYear; - res = SnSDUtils::SendAllFiles(this, conf.IsDeletingFiles(), to, genBuf, bsize); + res = SnSDUtils::SendAllFiles(this, conf.IsDeletingFiles(), to, + genBuf, bsize, conf, evt); } else { if (conf.GetCommSendData()==0) { printf("no data to send\r\n"); @@ -28,12 +25,8 @@ conf.GetCommSendData() // send N events : 0u; // send all events in last file res = SendData(SnSDUtils::GetCurFile(), SnSDUtils::GetCurFileName(), - conf, evt, genBuf, nev); + conf, evt, genBuf, bsize, nev, to); printf("after send data cur file, res=%d\r\n",(int)res); - if (res>kAllFails) { - printf("waiting for handshake\r\n"); - res = WaitHandshake(timeout, genBuf, bsize); - } } } return res; @@ -43,51 +36,37 @@ const SnConfigFrame& curConf, SnEventFrame& evt, char* const genBuf, + const uint32_t bsize, const uint32_t nevts, + const uint32_t timeout_clock, const uint32_t firstEvt) { // nevts==0 ==> send all events - // evtBuf should be 0 only if nevts==0 printf("SnCommWin::SendData cur file\r\n"); ECommWinResult res = kUndefFail; if (inf!=0) { - res = SendFilename(infn, genBuf); + // send the file name + res = SendFilename(infn, genBuf, timeout_clock); if (res>kAllFails) { - if (nevts==0) { - res = SendData(inf); - if (curConf.IsDeletingFiles() && res>=kOkMsgSent) { - SnSDUtilsWhisperer::DeleteFile(inf, infn); - } - } else { - if (genBuf!=0) { - res = SendConfAndEvents(inf, curConf, evt, genBuf, nevts, firstEvt); + if (genBuf!=0) { + // send the contents + res = SendFileContents(inf, curConf, evt, genBuf, + nevts, timeout_clock, firstEvt); + if (res>SnCommWin::kAllFails) { + // wait for handshake + uint8_t hndshk=0; + res = WaitHandshake(timeout_clock, genBuf, bsize, hndshk); + if ( (res==SnCommWin::kOkWithMsg) // got handshake + && (nevts==0) // sent whole file + && curConf.IsDeletingFiles() // want to delete + //&& (strcmp(infn, SnSDUtils::GetCurFileName()!=0) // not current file (TODO?) + && (hndshk==SnHeaderFrame::kHnShOkComplCode)) { // whole file received + // delete it + SnSDUtilsWhisperer::DeleteFile(inf, infn); + } } } } } return res; } - -/* -SnCommWin::ECommWinResult SnCommWin::SendData(const char* infn, - const SnConfigFrame& curConf, - SnEventFrame& evt, - char* const genBuf, - const uint32_t nevts, - const uint32_t firstEvt) { - // nevts==0 ==> send all events - // evtBuf should be 0 only if nevts==0 - // - // this version can send existing files that were previous closed - - ECommWinResult res = kUndefFail; - FILE* inf = fopen(infn, "rb"); - if (inf!=0) { - SendData(inf, infn, curConf, evt, genBuf, nevts, firstEvt); - if (inf!=0) { - fclose(inf); - } - } - return res; -} -*/ \ No newline at end of file