Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnSDUtils.h@0:664899e0b988, 2012-06-30 (annotated)
- Committer:
- uci1
- Date:
- Sat Jun 30 02:03:51 2012 +0000
- Revision:
- 0:664899e0b988
- Child:
- 1:e392595b4b76
first version. SD card writing and data readout works. communications not tested.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:664899e0b988 | 16 | static const char* kSDsubDir; |
uci1 | 0:664899e0b988 | 17 | static const uint8_t kFNBufSize=128; |
uci1 | 0:664899e0b988 | 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 | 0:664899e0b988 | 23 | uint16_t GetSeqNum(const uint64_t macadr, |
uci1 | 0:664899e0b988 | 24 | const uint32_t run); |
uci1 | 0:664899e0b988 | 25 | |
uci1 | 0:664899e0b988 | 26 | static |
uci1 | 0:664899e0b988 | 27 | const char* GetOutFileName(const uint64_t macadr, |
uci1 | 0:664899e0b988 | 28 | const uint32_t run, |
uci1 | 0:664899e0b988 | 29 | const uint16_t seq); |
uci1 | 0:664899e0b988 | 30 | |
uci1 | 0:664899e0b988 | 31 | static |
uci1 | 0:664899e0b988 | 32 | void DeleteFile(FILE*& f, const char* fname); |
uci1 | 0:664899e0b988 | 33 | |
uci1 | 0:664899e0b988 | 34 | static char fgCurFileName[kFNBufSize]; |
uci1 | 0:664899e0b988 | 35 | |
uci1 | 0:664899e0b988 | 36 | public: |
uci1 | 0:664899e0b988 | 37 | SnSDUtils() {} |
uci1 | 0:664899e0b988 | 38 | virtual ~SnSDUtils() {} |
uci1 | 0:664899e0b988 | 39 | |
uci1 | 0:664899e0b988 | 40 | static |
uci1 | 0:664899e0b988 | 41 | int CloseOutputFile(FILE* f) |
uci1 | 0:664899e0b988 | 42 | { return (f!=0) ? fclose(f) : 0; } |
uci1 | 0:664899e0b988 | 43 | |
uci1 | 0:664899e0b988 | 44 | static |
uci1 | 0:664899e0b988 | 45 | FILE* OpenNewOutputFile(const uint64_t macadr, |
uci1 | 0:664899e0b988 | 46 | const uint32_t run); |
uci1 | 0:664899e0b988 | 47 | |
uci1 | 0:664899e0b988 | 48 | static |
uci1 | 0:664899e0b988 | 49 | FILE* OpenExistingFile(const char* name); |
uci1 | 0:664899e0b988 | 50 | |
uci1 | 0:664899e0b988 | 51 | static |
uci1 | 0:664899e0b988 | 52 | SnCommWin::ECommWinResult SendAllFiles(SnCommWin* comm, |
uci1 | 0:664899e0b988 | 53 | const bool doDelete); |
uci1 | 0:664899e0b988 | 54 | |
uci1 | 0:664899e0b988 | 55 | static |
uci1 | 0:664899e0b988 | 56 | const char* GetCurFileName() { return fgCurFileName; } |
uci1 | 0:664899e0b988 | 57 | |
uci1 | 0:664899e0b988 | 58 | static |
uci1 | 0:664899e0b988 | 59 | bool WriteEventTo(FILE* efile, char* const evtBuf, |
uci1 | 0:664899e0b988 | 60 | const SnEventFrame& evt, |
uci1 | 0:664899e0b988 | 61 | const SnConfigFrame& conf); |
uci1 | 0:664899e0b988 | 62 | |
uci1 | 0:664899e0b988 | 63 | static |
uci1 | 0:664899e0b988 | 64 | bool WriteConfig(FILE* efile, |
uci1 | 0:664899e0b988 | 65 | const SnConfigFrame& conf); |
uci1 | 0:664899e0b988 | 66 | |
uci1 | 0:664899e0b988 | 67 | static |
uci1 | 0:664899e0b988 | 68 | bool WriteFileHeader(FILE* f, const uint64_t macadr); |
uci1 | 0:664899e0b988 | 69 | |
uci1 | 0:664899e0b988 | 70 | friend class SnSDUtilsWhisperer; // to restrict access to specific functions |
uci1 | 0:664899e0b988 | 71 | }; |
uci1 | 0:664899e0b988 | 72 | |
uci1 | 0:664899e0b988 | 73 | class SnSDUtilsWhisperer { |
uci1 | 0:664899e0b988 | 74 | static |
uci1 | 0:664899e0b988 | 75 | void DeleteFile(FILE*& f, const char* fname) { |
uci1 | 0:664899e0b988 | 76 | return SnSDUtils::DeleteFile(f, fname); |
uci1 | 0:664899e0b988 | 77 | } |
uci1 | 0:664899e0b988 | 78 | |
uci1 | 0:664899e0b988 | 79 | friend class SnCommWin; // the one who's allowed to use me |
uci1 | 0:664899e0b988 | 80 | }; |
uci1 | 0:664899e0b988 | 81 | |
uci1 | 0:664899e0b988 | 82 | #endif // SN_SnSDUtils |