Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue Jul 31 04:59:16 2012 +0000
Revision:
3:24c5f0f50bf1
Parent:
2:e67f7c158087
Child:
6:6f002d202f59
Test bench version. Communications not completed. Debugging output present. But will read the local config file and save events that can be used for testing.

Who changed what in which revision?

UserRevisionLine numberNew 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 3:24c5f0f50bf1 14 const uint32_t bsize,
uci1 2:e67f7c158087 15 const uint32_t timeout) {
uci1 3:24c5f0f50bf1 16 printf("SnCommWin::SendData\r\n");
uci1 2:e67f7c158087 17 ECommWinResult res = kUndefFail;
uci1 2:e67f7c158087 18 if (conf.IsSendingAllFiles()) {
uci1 3:24c5f0f50bf1 19 printf("sending all files\r\n");
uci1 3:24c5f0f50bf1 20 const uint32_t to = (conf.IsObeyingTimeout()) ? timeout : kSecsPerYear;
uci1 3:24c5f0f50bf1 21 res = SnSDUtils::SendAllFiles(this, conf.IsDeletingFiles(), to, genBuf, bsize);
uci1 2:e67f7c158087 22 } else {
uci1 2:e67f7c158087 23 if (conf.GetCommSendData()==0) {
uci1 3:24c5f0f50bf1 24 printf("no data to send\r\n");
uci1 2:e67f7c158087 25 res = kOkNoMsg;
uci1 2:e67f7c158087 26 } else {
uci1 2:e67f7c158087 27 const uint32_t nev = (conf.GetCommSendData()>0) ?
uci1 3:24c5f0f50bf1 28 conf.GetCommSendData() // send N events
uci1 3:24c5f0f50bf1 29 : 0u; // send all events in last file
uci1 2:e67f7c158087 30 res = SendData(SnSDUtils::GetCurFile(), SnSDUtils::GetCurFileName(),
uci1 2:e67f7c158087 31 conf, evt, genBuf, nev);
uci1 3:24c5f0f50bf1 32 printf("after send data cur file, res=%d\r\n",(int)res);
uci1 3:24c5f0f50bf1 33 if (res>kAllFails) {
uci1 3:24c5f0f50bf1 34 printf("waiting for handshake\r\n");
uci1 3:24c5f0f50bf1 35 res = WaitHandshake(timeout, genBuf, bsize);
uci1 3:24c5f0f50bf1 36 }
uci1 2:e67f7c158087 37 }
uci1 2:e67f7c158087 38 }
uci1 2:e67f7c158087 39 return res;
uci1 2:e67f7c158087 40 }
uci1 2:e67f7c158087 41
uci1 2:e67f7c158087 42 SnCommWin::ECommWinResult SnCommWin::SendData(FILE* inf, const char* infn,
uci1 2:e67f7c158087 43 const SnConfigFrame& curConf,
uci1 2:e67f7c158087 44 SnEventFrame& evt,
uci1 2:e67f7c158087 45 char* const genBuf,
uci1 2:e67f7c158087 46 const uint32_t nevts,
uci1 2:e67f7c158087 47 const uint32_t firstEvt) {
uci1 2:e67f7c158087 48 // nevts==0 ==> send all events
uci1 2:e67f7c158087 49 // evtBuf should be 0 only if nevts==0
uci1 2:e67f7c158087 50
uci1 3:24c5f0f50bf1 51 printf("SnCommWin::SendData cur file\r\n");
uci1 2:e67f7c158087 52 ECommWinResult res = kUndefFail;
uci1 2:e67f7c158087 53 if (inf!=0) {
uci1 3:24c5f0f50bf1 54 res = SendFilename(infn, genBuf);
uci1 3:24c5f0f50bf1 55 if (res>kAllFails) {
uci1 3:24c5f0f50bf1 56 if (nevts==0) {
uci1 3:24c5f0f50bf1 57 res = SendData(inf);
uci1 3:24c5f0f50bf1 58 if (curConf.IsDeletingFiles() && res>=kOkMsgSent) {
uci1 3:24c5f0f50bf1 59 SnSDUtilsWhisperer::DeleteFile(inf, infn);
uci1 3:24c5f0f50bf1 60 }
uci1 3:24c5f0f50bf1 61 } else {
uci1 3:24c5f0f50bf1 62 if (genBuf!=0) {
uci1 3:24c5f0f50bf1 63 res = SendConfAndEvents(inf, curConf, evt, genBuf, nevts, firstEvt);
uci1 3:24c5f0f50bf1 64 }
uci1 2:e67f7c158087 65 }
uci1 2:e67f7c158087 66 }
uci1 2:e67f7c158087 67 }
uci1 2:e67f7c158087 68 return res;
uci1 2:e67f7c158087 69 }
uci1 2:e67f7c158087 70
uci1 3:24c5f0f50bf1 71 /*
uci1 2:e67f7c158087 72 SnCommWin::ECommWinResult SnCommWin::SendData(const char* infn,
uci1 2:e67f7c158087 73 const SnConfigFrame& curConf,
uci1 2:e67f7c158087 74 SnEventFrame& evt,
uci1 2:e67f7c158087 75 char* const genBuf,
uci1 2:e67f7c158087 76 const uint32_t nevts,
uci1 2:e67f7c158087 77 const uint32_t firstEvt) {
uci1 2:e67f7c158087 78 // nevts==0 ==> send all events
uci1 2:e67f7c158087 79 // evtBuf should be 0 only if nevts==0
uci1 2:e67f7c158087 80 //
uci1 2:e67f7c158087 81 // this version can send existing files that were previous closed
uci1 2:e67f7c158087 82
uci1 2:e67f7c158087 83 ECommWinResult res = kUndefFail;
uci1 2:e67f7c158087 84 FILE* inf = fopen(infn, "rb");
uci1 2:e67f7c158087 85 if (inf!=0) {
uci1 2:e67f7c158087 86 SendData(inf, infn, curConf, evt, genBuf, nevts, firstEvt);
uci1 2:e67f7c158087 87 if (inf!=0) {
uci1 2:e67f7c158087 88 fclose(inf);
uci1 2:e67f7c158087 89 }
uci1 2:e67f7c158087 90 }
uci1 2:e67f7c158087 91 return res;
uci1 2:e67f7c158087 92 }
uci1 3:24c5f0f50bf1 93 */