Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

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?

UserRevisionLine numberNew contents of line
uci1 0:664899e0b988 1 #ifndef SN_SnSDUtils
uci1 0:664899e0b988 2 #define SN_SnSDUtils
uci1 0:664899e0b988 3
uci1 0:664899e0b988 4 #include <stdio.h>
uci1 0:664899e0b988 5 #include <stdint.h>
uci1 0:664899e0b988 6
uci1 0:664899e0b988 7 #include "SnCommWin.h"
uci1 0:664899e0b988 8
uci1 0:664899e0b988 9 class SnEventFrame;
uci1 0:664899e0b988 10 class SnConfigFrame;
uci1 0:664899e0b988 11
uci1 0:664899e0b988 12 // a namespace-like class to handle the i/o with the SD card
uci1 0:664899e0b988 13
uci1 0:664899e0b988 14 class SnSDUtils {
uci1 0:664899e0b988 15 public:
uci1 1:e392595b4b76 16 static const char* const kSDsubDir;
uci1 1:e392595b4b76 17 static const uint8_t kFNBufSize=128;
uci1 1:e392595b4b76 18 static const uint8_t kIOvers; // file I/O version
uci1 0:664899e0b988 19
uci1 0:664899e0b988 20 private:
uci1 0:664899e0b988 21
uci1 0:664899e0b988 22 static
uci1 1:e392595b4b76 23 FILE* OpenSDFile(const char* name);
uci1 1:e392595b4b76 24
uci1 1:e392595b4b76 25 static
uci1 0:664899e0b988 26 uint16_t GetSeqNum(const uint64_t macadr,
uci1 0:664899e0b988 27 const uint32_t run);
uci1 0:664899e0b988 28
uci1 0:664899e0b988 29 static
uci1 0:664899e0b988 30 const char* GetOutFileName(const uint64_t macadr,
uci1 0:664899e0b988 31 const uint32_t run,
uci1 0:664899e0b988 32 const uint16_t seq);
uci1 0:664899e0b988 33
uci1 0:664899e0b988 34 static
uci1 0:664899e0b988 35 void DeleteFile(FILE*& f, const char* fname);
uci1 0:664899e0b988 36
uci1 0:664899e0b988 37 static char fgCurFileName[kFNBufSize];
uci1 1:e392595b4b76 38 static FILE* fgCurFile;
uci1 0:664899e0b988 39
uci1 0:664899e0b988 40 public:
uci1 0:664899e0b988 41 SnSDUtils() {}
uci1 0:664899e0b988 42 virtual ~SnSDUtils() {}
uci1 0:664899e0b988 43
uci1 0:664899e0b988 44 static
uci1 0:664899e0b988 45 int CloseOutputFile(FILE* f)
uci1 0:664899e0b988 46 { return (f!=0) ? fclose(f) : 0; }
uci1 0:664899e0b988 47
uci1 0:664899e0b988 48 static
uci1 0:664899e0b988 49 FILE* OpenNewOutputFile(const uint64_t macadr,
uci1 0:664899e0b988 50 const uint32_t run);
uci1 0:664899e0b988 51
uci1 0:664899e0b988 52 static
uci1 0:664899e0b988 53 FILE* OpenExistingFile(const char* name);
uci1 0:664899e0b988 54
uci1 0:664899e0b988 55 static
uci1 0:664899e0b988 56 SnCommWin::ECommWinResult SendAllFiles(SnCommWin* comm,
uci1 0:664899e0b988 57 const bool doDelete);
uci1 0:664899e0b988 58
uci1 0:664899e0b988 59 static
uci1 0:664899e0b988 60 const char* GetCurFileName() { return fgCurFileName; }
uci1 0:664899e0b988 61
uci1 0:664899e0b988 62 static
uci1 1:e392595b4b76 63 FILE* GetCurFile() { return fgCurFile; }
uci1 1:e392595b4b76 64
uci1 1:e392595b4b76 65 static
uci1 0:664899e0b988 66 bool WriteEventTo(FILE* efile, char* const evtBuf,
uci1 0:664899e0b988 67 const SnEventFrame& evt,
uci1 0:664899e0b988 68 const SnConfigFrame& conf);
uci1 0:664899e0b988 69
uci1 0:664899e0b988 70 static
uci1 0:664899e0b988 71 bool WriteConfig(FILE* efile,
uci1 0:664899e0b988 72 const SnConfigFrame& conf);
uci1 0:664899e0b988 73
uci1 0:664899e0b988 74 static
uci1 2:e67f7c158087 75 bool WriteFileHeader(FILE* f, const uint64_t macadr,
uci1 2:e67f7c158087 76 const uint32_t run, const uint16_t seq);
uci1 2:e67f7c158087 77
uci1 2:e67f7c158087 78 static
uci1 2:e67f7c158087 79 bool ReadFileHeader(FILE* f, uint64_t& macadr,
uci1 2:e67f7c158087 80 uint32_t& run, uint16_t& seq);
uci1 0:664899e0b988 81
uci1 0:664899e0b988 82 friend class SnSDUtilsWhisperer; // to restrict access to specific functions
uci1 0:664899e0b988 83 };
uci1 0:664899e0b988 84
uci1 0:664899e0b988 85 class SnSDUtilsWhisperer {
uci1 0:664899e0b988 86 static
uci1 0:664899e0b988 87 void DeleteFile(FILE*& f, const char* fname) {
uci1 0:664899e0b988 88 return SnSDUtils::DeleteFile(f, fname);
uci1 0:664899e0b988 89 }
uci1 0:664899e0b988 90
uci1 0:664899e0b988 91 friend class SnCommWin; // the one who's allowed to use me
uci1 0:664899e0b988 92 };
uci1 0:664899e0b988 93
uci1 0:664899e0b988 94 #endif // SN_SnSDUtils