Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnSDUtils.h@4:a91682e19d6b, 2012-08-02 (annotated)
- Committer:
- uci1
- Date:
- Thu Aug 02 05:42:47 2012 +0000
- Revision:
- 4:a91682e19d6b
- Parent:
- 3:24c5f0f50bf1
- Child:
- 5:9cea89700c66
Add power reading, once per file. Prevent seq number from wrapping around. Still many debugging messages. Communications not finished.
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 | 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 | 3:24c5f0f50bf1 | 23 | FILE* OpenSDFile(const char* name, const char* mode); |
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 | 4:a91682e19d6b | 50 | const uint32_t run, |
uci1 | 4:a91682e19d6b | 51 | const uint16_t v1, const uint16_t v2); |
uci1 | 0:664899e0b988 | 52 | |
uci1 | 0:664899e0b988 | 53 | static |
uci1 | 3:24c5f0f50bf1 | 54 | FILE* OpenExistingFile(const char* name, const bool setcurrent); |
uci1 | 0:664899e0b988 | 55 | |
uci1 | 0:664899e0b988 | 56 | static |
uci1 | 0:664899e0b988 | 57 | SnCommWin::ECommWinResult SendAllFiles(SnCommWin* comm, |
uci1 | 3:24c5f0f50bf1 | 58 | const bool doDelete, |
uci1 | 3:24c5f0f50bf1 | 59 | const uint32_t timeout, |
uci1 | 3:24c5f0f50bf1 | 60 | char* const buf, |
uci1 | 3:24c5f0f50bf1 | 61 | const uint32_t bsize); |
uci1 | 0:664899e0b988 | 62 | |
uci1 | 0:664899e0b988 | 63 | static |
uci1 | 0:664899e0b988 | 64 | const char* GetCurFileName() { return fgCurFileName; } |
uci1 | 0:664899e0b988 | 65 | |
uci1 | 0:664899e0b988 | 66 | static |
uci1 | 1:e392595b4b76 | 67 | FILE* GetCurFile() { return fgCurFile; } |
uci1 | 1:e392595b4b76 | 68 | |
uci1 | 1:e392595b4b76 | 69 | static |
uci1 | 0:664899e0b988 | 70 | bool WriteEventTo(FILE* efile, char* const evtBuf, |
uci1 | 0:664899e0b988 | 71 | const SnEventFrame& evt, |
uci1 | 0:664899e0b988 | 72 | const SnConfigFrame& conf); |
uci1 | 0:664899e0b988 | 73 | |
uci1 | 0:664899e0b988 | 74 | static |
uci1 | 0:664899e0b988 | 75 | bool WriteConfig(FILE* efile, |
uci1 | 0:664899e0b988 | 76 | const SnConfigFrame& conf); |
uci1 | 0:664899e0b988 | 77 | |
uci1 | 0:664899e0b988 | 78 | static |
uci1 | 2:e67f7c158087 | 79 | bool WriteFileHeader(FILE* f, const uint64_t macadr, |
uci1 | 4:a91682e19d6b | 80 | const uint32_t run, const uint16_t seq, |
uci1 | 4:a91682e19d6b | 81 | const uint16_t v1, const uint16_t v2); |
uci1 | 2:e67f7c158087 | 82 | |
uci1 | 2:e67f7c158087 | 83 | static |
uci1 | 2:e67f7c158087 | 84 | bool ReadFileHeader(FILE* f, uint64_t& macadr, |
uci1 | 4:a91682e19d6b | 85 | uint32_t& run, uint16_t& seq, |
uci1 | 4:a91682e19d6b | 86 | uint16_t& v1, uint16_t& v2); |
uci1 | 0:664899e0b988 | 87 | |
uci1 | 0:664899e0b988 | 88 | friend class SnSDUtilsWhisperer; // to restrict access to specific functions |
uci1 | 0:664899e0b988 | 89 | }; |
uci1 | 0:664899e0b988 | 90 | |
uci1 | 0:664899e0b988 | 91 | class SnSDUtilsWhisperer { |
uci1 | 0:664899e0b988 | 92 | static |
uci1 | 0:664899e0b988 | 93 | void DeleteFile(FILE*& f, const char* fname) { |
uci1 | 0:664899e0b988 | 94 | return SnSDUtils::DeleteFile(f, fname); |
uci1 | 0:664899e0b988 | 95 | } |
uci1 | 0:664899e0b988 | 96 | |
uci1 | 0:664899e0b988 | 97 | friend class SnCommWin; // the one who's allowed to use me |
uci1 | 0:664899e0b988 | 98 | }; |
uci1 | 0:664899e0b988 | 99 | |
uci1 | 0:664899e0b988 | 100 | #endif // SN_SnSDUtils |