Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCommWin.cpp@2:e67f7c158087, 2012-07-24 (annotated)
- Committer:
- uci1
- Date:
- Tue Jul 24 02:07:23 2012 +0000
- Revision:
- 2:e67f7c158087
- Parent:
- 1:e392595b4b76
- Child:
- 3:24c5f0f50bf1
added header to i/o. still lots of debugging prints.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uci1 | 2:e67f7c158087 | 1 | #include "SnCommWin.h" |
uci1 | 2:e67f7c158087 | 2 | |
uci1 | 2:e67f7c158087 | 3 | #include "SnConfigFrame.h" |
uci1 | 2:e67f7c158087 | 4 | #include "SnSDUtils.h" |
uci1 | 2:e67f7c158087 | 5 | |
uci1 | 2:e67f7c158087 | 6 | /* |
uci1 | 2:e67f7c158087 | 7 | bool SnCommWin::fgCommEst = false; |
uci1 | 2:e67f7c158087 | 8 | bool SnCommWin::fgWinOpen = false; |
uci1 | 2:e67f7c158087 | 9 | */ |
uci1 | 2:e67f7c158087 | 10 | |
uci1 | 2:e67f7c158087 | 11 | SnCommWin::ECommWinResult SnCommWin::SendData(SnConfigFrame& conf, |
uci1 | 2:e67f7c158087 | 12 | SnEventFrame& evt, |
uci1 | 2:e67f7c158087 | 13 | char* const genBuf, |
uci1 | 2:e67f7c158087 | 14 | const uint32_t timeout) { |
uci1 | 2:e67f7c158087 | 15 | ECommWinResult res = kUndefFail; |
uci1 | 2:e67f7c158087 | 16 | if (conf.IsSendingAllFiles()) { |
uci1 | 2:e67f7c158087 | 17 | res = SnSDUtils::SendAllFiles(this, conf.IsDeletingFiles()); |
uci1 | 2:e67f7c158087 | 18 | } else { |
uci1 | 2:e67f7c158087 | 19 | if (conf.GetCommSendData()==0) { |
uci1 | 2:e67f7c158087 | 20 | res = kOkNoMsg; |
uci1 | 2:e67f7c158087 | 21 | } else { |
uci1 | 2:e67f7c158087 | 22 | const uint32_t nev = (conf.GetCommSendData()>0) ? |
uci1 | 2:e67f7c158087 | 23 | conf.GetCommSendData() |
uci1 | 2:e67f7c158087 | 24 | : 0u; // send all events in file |
uci1 | 2:e67f7c158087 | 25 | res = SendData(SnSDUtils::GetCurFile(), SnSDUtils::GetCurFileName(), |
uci1 | 2:e67f7c158087 | 26 | conf, evt, genBuf, nev); |
uci1 | 2:e67f7c158087 | 27 | } |
uci1 | 2:e67f7c158087 | 28 | } |
uci1 | 2:e67f7c158087 | 29 | return res; |
uci1 | 2:e67f7c158087 | 30 | } |
uci1 | 2:e67f7c158087 | 31 | |
uci1 | 2:e67f7c158087 | 32 | SnCommWin::ECommWinResult SnCommWin::SendData(FILE* inf, const char* infn, |
uci1 | 2:e67f7c158087 | 33 | const SnConfigFrame& curConf, |
uci1 | 2:e67f7c158087 | 34 | SnEventFrame& evt, |
uci1 | 2:e67f7c158087 | 35 | char* const genBuf, |
uci1 | 2:e67f7c158087 | 36 | const uint32_t nevts, |
uci1 | 2:e67f7c158087 | 37 | const uint32_t firstEvt) { |
uci1 | 2:e67f7c158087 | 38 | // nevts==0 ==> send all events |
uci1 | 2:e67f7c158087 | 39 | // evtBuf should be 0 only if nevts==0 |
uci1 | 2:e67f7c158087 | 40 | // |
uci1 | 2:e67f7c158087 | 41 | // this version should be used to send the current file (avoid fopen/fclose) |
uci1 | 2:e67f7c158087 | 42 | |
uci1 | 2:e67f7c158087 | 43 | ECommWinResult res = kUndefFail; |
uci1 | 2:e67f7c158087 | 44 | if (inf!=0) { |
uci1 | 2:e67f7c158087 | 45 | if (nevts==0) { |
uci1 | 2:e67f7c158087 | 46 | res = SendData(inf); |
uci1 | 2:e67f7c158087 | 47 | if (curConf.IsDeletingFiles() && res>=kOkMsgSent) { |
uci1 | 2:e67f7c158087 | 48 | SnSDUtilsWhisperer::DeleteFile(inf, infn); |
uci1 | 2:e67f7c158087 | 49 | } |
uci1 | 2:e67f7c158087 | 50 | } else { |
uci1 | 2:e67f7c158087 | 51 | if (genBuf!=0) { |
uci1 | 2:e67f7c158087 | 52 | res = SendConfAndEvents(inf, curConf, evt, genBuf, nevts, firstEvt); |
uci1 | 2:e67f7c158087 | 53 | } |
uci1 | 2:e67f7c158087 | 54 | } |
uci1 | 2:e67f7c158087 | 55 | } |
uci1 | 2:e67f7c158087 | 56 | return res; |
uci1 | 2:e67f7c158087 | 57 | } |
uci1 | 2:e67f7c158087 | 58 | |
uci1 | 2:e67f7c158087 | 59 | |
uci1 | 2:e67f7c158087 | 60 | SnCommWin::ECommWinResult SnCommWin::SendData(const char* infn, |
uci1 | 2:e67f7c158087 | 61 | const SnConfigFrame& curConf, |
uci1 | 2:e67f7c158087 | 62 | SnEventFrame& evt, |
uci1 | 2:e67f7c158087 | 63 | char* const genBuf, |
uci1 | 2:e67f7c158087 | 64 | const uint32_t nevts, |
uci1 | 2:e67f7c158087 | 65 | const uint32_t firstEvt) { |
uci1 | 2:e67f7c158087 | 66 | // nevts==0 ==> send all events |
uci1 | 2:e67f7c158087 | 67 | // evtBuf should be 0 only if nevts==0 |
uci1 | 2:e67f7c158087 | 68 | // |
uci1 | 2:e67f7c158087 | 69 | // this version can send existing files that were previous closed |
uci1 | 2:e67f7c158087 | 70 | |
uci1 | 2:e67f7c158087 | 71 | ECommWinResult res = kUndefFail; |
uci1 | 2:e67f7c158087 | 72 | FILE* inf = fopen(infn, "rb"); |
uci1 | 2:e67f7c158087 | 73 | if (inf!=0) { |
uci1 | 2:e67f7c158087 | 74 | SendData(inf, infn, curConf, evt, genBuf, nevts, firstEvt); |
uci1 | 2:e67f7c158087 | 75 | if (inf!=0) { |
uci1 | 2:e67f7c158087 | 76 | fclose(inf); |
uci1 | 2:e67f7c158087 | 77 | } |
uci1 | 2:e67f7c158087 | 78 | } |
uci1 | 2:e67f7c158087 | 79 | return res; |
uci1 | 2:e67f7c158087 | 80 | } |