Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnSDUtils.cpp
- Revision:
- 64:6c7a316eafad
- Parent:
- 63:4820a4460f00
- Child:
- 65:2cb3e99ce466
--- a/SnSDUtils.cpp Fri Nov 28 05:41:42 2014 +0000 +++ b/SnSDUtils.cpp Fri Nov 28 07:42:57 2014 +0000 @@ -37,6 +37,7 @@ static const uint16_t __kMaxUShort = ~0; bool SnSDUtils::InitSDCard(const bool force) { + Watchdog::kick(); // don't reset if ((fgNeedToInit || force) && (fgDoInit!=0)) { fgInitOk = (*fgDoInit)() == 0; if (IsInitOk()) { @@ -50,6 +51,7 @@ uint32_t& slen, const bool useSeq) { // returns a STATIC string! (so make a copy of it before use) // sets slen to the length of this string (same as strlen) + Watchdog::kick(); // don't reset static const uint16_t tmplen = strlen(kSDsubDir)+50; static char* tmpsd = new char[tmplen]; slen = snprintf(tmpsd, tmplen, "%s/r%05ld", kSDsubDir, run); @@ -73,6 +75,7 @@ // // filename = SnEvtsM[6-byte hex mac adr]r[6-digit run num]s[5-digit seq num].dat // 35 chars 7 + 12 +1+ 5 +1+ 5 + 4 + Watchdog::kick(); // don't reset uint32_t sdlen(0); std::string subdirs( GetSubDirFor(run, seq, sdlen, true) ); const char* subdir = subdirs.c_str(); @@ -93,6 +96,7 @@ bool SnSDUtils::GetRunSeqFromFilename(const char* fn, uint32_t& run, uint16_t& seq) { + Watchdog::kick(); // don't reset bool ret = false; const int32_t ncomp = strrchr(fn, 'r') - fn; #ifdef DEBUG @@ -123,6 +127,7 @@ #ifdef DEBUG printf("OpenOrMakeAllDirs: [%s]\r\n",dirname); #endif + Watchdog::kick(); // don't reset // try making the subdir DIR* sd(0); std::string dn(dirname); @@ -162,6 +167,7 @@ #ifdef DEBUG printf("open dir %s\r\n",dirname); #endif + Watchdog::kick(); // don't reset if (InitSDCard()) { DIR* rd( opendir(dirname) ); @@ -189,6 +195,8 @@ const uint32_t run) { // count the files having expected filename format + Watchdog::kick(); // don't reset + uint16_t maxs(kBadSeqNum); if (InitSDCard()) { @@ -238,6 +246,9 @@ #ifdef DEBUG printf("Found max seq dir num %hu for run %u\r\n",maxs,run); #endif + + Watchdog::kick(); // don't reset + // open up the seq dir rdnms = GetSubDirFor(run, maxs, rdlen, true); rdnm = rdnms.c_str(); @@ -294,6 +305,7 @@ FILE* SnSDUtils::OpenExistingFile(const char* name, const bool setcurrent, const bool redoDir) { + Watchdog::kick(); // don't reset FILE* f = 0; if (InitSDCard()) { //if ((name!=NULL) && ((*name)!=0) ) { // simple check if filename not set @@ -318,6 +330,7 @@ #ifdef DEBUG printf("GetFullFilename (%s)\r\n",name); #endif + Watchdog::kick(); // don't reset bool ret = false; uint32_t run(0); uint16_t seq(0); @@ -358,6 +371,7 @@ #ifdef DEBUG printf("OpenSDFile: Trying to open %s.\r\n",name); #endif + Watchdog::kick(); // don't reset FILE* f = 0; if (InitSDCard()) { @@ -423,6 +437,7 @@ printf("getting seq num for run %u, minseq %hu\r\n", run, minseq); #endif + Watchdog::kick(); // don't reset fgCurFile = 0; fgCurSeq = GetSeqNum(macadr, run); #ifdef DEBUG @@ -464,6 +479,7 @@ } void SnSDUtils::PrintFilesInDirs(const char* dirname) { + Watchdog::kick(); // don't reset if (InitSDCard()) { DIR* d; @@ -489,6 +505,7 @@ } float SnSDUtils::GetFreeBytes() { + Watchdog::kick(); // don't reset float frs(0); if (InitSDCard()) { @@ -513,6 +530,7 @@ void SnSDUtils::GetDirProps(const char* dirname, uint32_t& nfiles, float& totbytes) { + Watchdog::kick(); // don't reset nfiles = 0; totbytes = 0; if (InitSDCard()) { @@ -550,6 +568,7 @@ bool SnSDUtils::WriteHeartbeatTo(FILE* file, const uint32_t time, const uint32_t num) { + Watchdog::kick(); // don't reset if (file!=0) { if (InitSDCard()) { @@ -567,6 +586,7 @@ bool SnSDUtils::WriteTrigWaitWinTime(FILE* file, SnClockSetFrame& clkset, const bool isStart) { + Watchdog::kick(); // don't reset if (file!=0) { if (InitSDCard()) { @@ -584,6 +604,7 @@ bool SnSDUtils::WriteEventTo(FILE* efile, char* const evtBuf, const SnEventFrame& evt, const SnConfigFrame& conf) { + Watchdog::kick(); // don't reset // write event to SD card bool ret = false; if (efile!=0) { @@ -603,6 +624,7 @@ bool SnSDUtils::WriteConfig(FILE* efile, const SnConfigFrame& conf) { + Watchdog::kick(); // don't reset if (efile!=0) { if (InitSDCard()) { @@ -619,6 +641,7 @@ #ifdef DEBUG printf("try to delete %s at %p\r\n",fname,f); #endif + Watchdog::kick(); // don't reset if (InitSDCard()) { if (f!=0) { @@ -639,6 +662,7 @@ #ifdef DEBUG printf("deleteing files of run %lu\r\n",run); #endif + Watchdog::kick(); // don't reset uint32_t rdlen(0); std::string rdnm( GetSubDirFor(run, 0, rdlen, false) ); DeleteAllFiles(rdnm.c_str()); @@ -648,6 +672,7 @@ #ifdef DEBUG printf("deleting ALL files in %s\r\n",dirname); #endif + Watchdog::kick(); // don't reset if (InitSDCard()) { DIR* d; @@ -686,6 +711,7 @@ #ifdef DEBUG printf("DeleteDirIfEmpty(%s)\r\n",dirname); #endif + Watchdog::kick(); // don't reset bool doDel = false; if (InitSDCard()) { @@ -727,7 +753,7 @@ #ifdef DEBUG printf("SendOneFile (%s)\r\n",dfn); #endif - + Watchdog::kick(); // don't reset SnCommWin::ECommWinResult res = SnCommWin::kOkMsgSent; // open the file @@ -771,6 +797,7 @@ } bool SnSDUtils::ClearRunSeqList() { + Watchdog::kick(); // don't reset if (InitSDCard()) { FILE* rslistf = fopen(kRunSeqListFilenm,"w"); const bool ok = rslistf!=0; @@ -785,6 +812,7 @@ bool SnSDUtils::AddToRunSeqList(const uint32_t run, const uint16_t seq) { + Watchdog::kick(); // don't reset if (InitSDCard()) { FILE* rslistf = fopen(kRunSeqListFilenm,"a"); bool ok = false; @@ -816,6 +844,7 @@ #ifdef DEBUG printf("SendFileWithRunSeq\r\n"); #endif + Watchdog::kick(); // don't reset // get the file name std::string dfn = @@ -862,6 +891,8 @@ SnCommWin::ECommWinResult rs = SnCommWin::kOkMsgSent; + Watchdog::kick(); // don't reset + if (InitSDCard()) { // open up the run/seq list file and send each corresponding file @@ -878,6 +909,8 @@ printf("feof=%d, ferror=%d\r\n", (int)(feof(rslistf)), (int)(ferror(rslistf))); #endif + Watchdog::kick(); // don't reset + const int nfilled = fscanf(rslistf, "%u %hu\n", &run ,&seq); #ifdef DEBUG @@ -942,9 +975,14 @@ printf("SendPartOfRun\r\n"); #endif + Watchdog::kick(); // don't reset + SnCommWin::ECommWinResult rs = SnCommWin::kOkMsgSent; for (uint16_t seq=minseq; seq<=maxseq; ++seq) { + + Watchdog::kick(); // don't reset + SnCommWin::ECommWinResult res = SendFileWithRunSeq(comm, timeout, buf, bsize, @@ -977,7 +1015,9 @@ SnPowerFrame& pow, const uint32_t runnum) { // send all files in a run - + + Watchdog::kick(); // don't reset + // get the run dir uint32_t rdlen(0); std::string rdnms ( GetSubDirFor(runnum, 0, rdlen, false) ); @@ -994,7 +1034,9 @@ SnPowerFrame& pow, const char* dirname) { // send all files in the specified directory - + + Watchdog::kick(); // don't reset + SnCommWin::ECommWinResult rs = SnCommWin::kUndefFail; if (InitSDCard()) {