Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Fri Aug 03 23:50:57 2012 +0000
Revision:
6:6f002d202f59
Parent:
5:9cea89700c66
Child:
8:95a325df1f6b
Remove line that powered amps outside of SetPower. Still lots of debugging output. Communication systems totally unimplemented.

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 5:9cea89700c66 8 #include "SnBitUtils.h"
uci1 5:9cea89700c66 9 #include "SnPowerFrame.h"
uci1 0:664899e0b988 10
uci1 0:664899e0b988 11 class SnEventFrame;
uci1 0:664899e0b988 12 class SnConfigFrame;
uci1 0:664899e0b988 13
uci1 0:664899e0b988 14 // a namespace-like class to handle the i/o with the SD card
uci1 0:664899e0b988 15
uci1 0:664899e0b988 16 class SnSDUtils {
uci1 0:664899e0b988 17 public:
uci1 1:e392595b4b76 18 static const char* const kSDsubDir;
uci1 1:e392595b4b76 19 static const uint8_t kFNBufSize=128;
uci1 1:e392595b4b76 20 static const uint8_t kIOvers; // file I/O version
uci1 5:9cea89700c66 21 static const uint32_t kMaxSizeOfFileHdr;
uci1 0:664899e0b988 22
uci1 0:664899e0b988 23 private:
uci1 0:664899e0b988 24
uci1 0:664899e0b988 25 static
uci1 3:24c5f0f50bf1 26 FILE* OpenSDFile(const char* name, const char* mode);
uci1 1:e392595b4b76 27
uci1 1:e392595b4b76 28 static
uci1 0:664899e0b988 29 uint16_t GetSeqNum(const uint64_t macadr,
uci1 0:664899e0b988 30 const uint32_t run);
uci1 0:664899e0b988 31
uci1 0:664899e0b988 32 static
uci1 0:664899e0b988 33 const char* GetOutFileName(const uint64_t macadr,
uci1 0:664899e0b988 34 const uint32_t run,
uci1 0:664899e0b988 35 const uint16_t seq);
uci1 0:664899e0b988 36
uci1 0:664899e0b988 37 static
uci1 0:664899e0b988 38 void DeleteFile(FILE*& f, const char* fname);
uci1 0:664899e0b988 39
uci1 0:664899e0b988 40 static char fgCurFileName[kFNBufSize];
uci1 1:e392595b4b76 41 static FILE* fgCurFile;
uci1 0:664899e0b988 42
uci1 0:664899e0b988 43 public:
uci1 0:664899e0b988 44 SnSDUtils() {}
uci1 0:664899e0b988 45 virtual ~SnSDUtils() {}
uci1 0:664899e0b988 46
uci1 0:664899e0b988 47 static
uci1 0:664899e0b988 48 int CloseOutputFile(FILE* f)
uci1 0:664899e0b988 49 { return (f!=0) ? fclose(f) : 0; }
uci1 0:664899e0b988 50
uci1 0:664899e0b988 51 static
uci1 0:664899e0b988 52 FILE* OpenNewOutputFile(const uint64_t macadr,
uci1 4:a91682e19d6b 53 const uint32_t run,
uci1 4:a91682e19d6b 54 const uint16_t v1, const uint16_t v2);
uci1 0:664899e0b988 55
uci1 0:664899e0b988 56 static
uci1 3:24c5f0f50bf1 57 FILE* OpenExistingFile(const char* name, const bool setcurrent);
uci1 0:664899e0b988 58
uci1 0:664899e0b988 59 static
uci1 0:664899e0b988 60 SnCommWin::ECommWinResult SendAllFiles(SnCommWin* comm,
uci1 3:24c5f0f50bf1 61 const bool doDelete,
uci1 3:24c5f0f50bf1 62 const uint32_t timeout,
uci1 3:24c5f0f50bf1 63 char* const buf,
uci1 6:6f002d202f59 64 const uint32_t bsize,
uci1 6:6f002d202f59 65 const SnConfigFrame& curConf,
uci1 6:6f002d202f59 66 SnEventFrame& evt);
uci1 0:664899e0b988 67
uci1 0:664899e0b988 68 static
uci1 0:664899e0b988 69 const char* GetCurFileName() { return fgCurFileName; }
uci1 0:664899e0b988 70
uci1 0:664899e0b988 71 static
uci1 1:e392595b4b76 72 FILE* GetCurFile() { return fgCurFile; }
uci1 1:e392595b4b76 73
uci1 1:e392595b4b76 74 static
uci1 0:664899e0b988 75 bool WriteEventTo(FILE* efile, char* const evtBuf,
uci1 0:664899e0b988 76 const SnEventFrame& evt,
uci1 0:664899e0b988 77 const SnConfigFrame& conf);
uci1 0:664899e0b988 78
uci1 0:664899e0b988 79 static
uci1 0:664899e0b988 80 bool WriteConfig(FILE* efile,
uci1 0:664899e0b988 81 const SnConfigFrame& conf);
uci1 5:9cea89700c66 82 /*
uci1 0:664899e0b988 83 static
uci1 2:e67f7c158087 84 bool WriteFileHeader(FILE* f, const uint64_t macadr,
uci1 4:a91682e19d6b 85 const uint32_t run, const uint16_t seq,
uci1 4:a91682e19d6b 86 const uint16_t v1, const uint16_t v2);
uci1 2:e67f7c158087 87
uci1 2:e67f7c158087 88 static
uci1 2:e67f7c158087 89 bool ReadFileHeader(FILE* f, uint64_t& macadr,
uci1 4:a91682e19d6b 90 uint32_t& run, uint16_t& seq,
uci1 4:a91682e19d6b 91 uint16_t& v1, uint16_t& v2);
uci1 5:9cea89700c66 92 */
uci1 5:9cea89700c66 93 template<class T>
uci1 5:9cea89700c66 94 static
uci1 5:9cea89700c66 95 SnCommWin::ECommWinResult WriteFileHeader(T& f, const uint64_t macadr,
uci1 5:9cea89700c66 96 const uint32_t run, const uint16_t seq,
uci1 5:9cea89700c66 97 const uint16_t v1, const uint16_t v2) {
uci1 5:9cea89700c66 98 // MUST INCREMENT kIOvers if these writes are altered
uci1 5:9cea89700c66 99 f = SnBitUtils::WriteTo(f, kIOvers);
uci1 5:9cea89700c66 100 f = SnBitUtils::WriteTo(f, macadr);
uci1 5:9cea89700c66 101 f = SnBitUtils::WriteTo(f, run);
uci1 5:9cea89700c66 102 f = SnBitUtils::WriteTo(f, seq);
uci1 5:9cea89700c66 103 SnPowerFrame::WriteTo(f, v1, v2);
uci1 5:9cea89700c66 104 return SnCommWin::kOkMsgSent;
uci1 5:9cea89700c66 105 }
uci1 5:9cea89700c66 106
uci1 5:9cea89700c66 107 template<class T>
uci1 5:9cea89700c66 108 static
uci1 5:9cea89700c66 109 SnCommWin::ECommWinResult ReadFileHeader(T& f, uint64_t& macadr,
uci1 5:9cea89700c66 110 uint32_t& run, uint16_t& seq,
uci1 5:9cea89700c66 111 uint16_t& v1, uint16_t& v2) {
uci1 5:9cea89700c66 112 uint8_t Rv=0;
uci1 5:9cea89700c66 113 f = SnBitUtils::ReadFrom(f, Rv);
uci1 5:9cea89700c66 114 f = SnBitUtils::ReadFrom(f, macadr);
uci1 5:9cea89700c66 115 f = SnBitUtils::ReadFrom(f, run);
uci1 5:9cea89700c66 116 f = SnBitUtils::ReadFrom(f, seq);
uci1 5:9cea89700c66 117 if (Rv>1) {
uci1 5:9cea89700c66 118 SnPowerFrame::ReadFrom(f, v1, v2);
uci1 5:9cea89700c66 119 }
uci1 5:9cea89700c66 120 return SnCommWin::kOkWithMsg;
uci1 5:9cea89700c66 121 }
uci1 5:9cea89700c66 122
uci1 5:9cea89700c66 123 static
uci1 5:9cea89700c66 124 uint32_t SizeOfFileHeader() { return kMaxSizeOfFileHdr; }
uci1 0:664899e0b988 125
uci1 0:664899e0b988 126 friend class SnSDUtilsWhisperer; // to restrict access to specific functions
uci1 0:664899e0b988 127 };
uci1 0:664899e0b988 128
uci1 0:664899e0b988 129 class SnSDUtilsWhisperer {
uci1 0:664899e0b988 130 static
uci1 0:664899e0b988 131 void DeleteFile(FILE*& f, const char* fname) {
uci1 0:664899e0b988 132 return SnSDUtils::DeleteFile(f, fname);
uci1 0:664899e0b988 133 }
uci1 0:664899e0b988 134
uci1 0:664899e0b988 135 friend class SnCommWin; // the one who's allowed to use me
uci1 0:664899e0b988 136 };
uci1 0:664899e0b988 137
uci1 0:664899e0b988 138 #endif // SN_SnSDUtils