Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue Oct 30 05:23:57 2012 +0000
Revision:
25:57b2627fe756
Parent:
21:ce51bb0ba4a5
Child:
28:484943132bb0
AFAR comms. Upped baud to 921600. Store data in run-seq subdirs, max of 100 files per dir, to prevent station grinding to a halt due when 800 files are in one directory. Cache file size count. Stagger tickers. Fixed some gcc warnings.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 1:e392595b4b76 1 #ifndef SN_SnStatusFrame
uci1 1:e392595b4b76 2 #define SN_SnStatusFrame
uci1 1:e392595b4b76 3
uci1 1:e392595b4b76 4 #include <stdint.h>
uci1 1:e392595b4b76 5
uci1 1:e392595b4b76 6 #include "SnBitUtils.h"
uci1 1:e392595b4b76 7 #include "SnCommWin.h"
uci1 1:e392595b4b76 8 #include "SnConfigFrame.h"
uci1 1:e392595b4b76 9 #include "SnEventFrame.h"
uci1 21:ce51bb0ba4a5 10 #include "SnSDUtils.h"
uci1 1:e392595b4b76 11
uci1 25:57b2627fe756 12 //#define ST_DEBUG
uci1 25:57b2627fe756 13
uci1 1:e392595b4b76 14 struct SnStatusFrame {
uci1 1:e392595b4b76 15 //
uci1 1:e392595b4b76 16 // A simple struct (everything public) to function like namespace.
uci1 1:e392595b4b76 17 // The contents of the status frame are sent from here, in order to
uci1 1:e392595b4b76 18 // help make sure the status frame is the same for each comm method.
uci1 1:e392595b4b76 19 //
uci1 1:e392595b4b76 20 // No member variables are used in order to preserve memory on the mbed.
uci1 1:e392595b4b76 21 // (i.e. no actual status frame middle-man object exists)
uci1 1:e392595b4b76 22 //
uci1 1:e392595b4b76 23
uci1 1:e392595b4b76 24 static const uint8_t kIOVers; // MUST BE INCREASED if bytes written/read change!!
uci1 1:e392595b4b76 25
uci1 10:3c93db1cfb12 26 static const uint32_t kMaxSizeOfV1 =
uci1 1:e392595b4b76 27 1u + sizeof(uint64_t)
uci1 1:e392595b4b76 28 + (sizeof(uint32_t)*3u) + (sizeof(uint16_t))
uci1 1:e392595b4b76 29 + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 30 + SnEventFrame::kMaxSizeOf;
uci1 10:3c93db1cfb12 31 static const uint32_t kMaxSizeOfV2 =
uci1 10:3c93db1cfb12 32 sizeof(uint64_t) + (3u*sizeof(uint32_t)) + (2u*sizeof(uint16_t))
uci1 10:3c93db1cfb12 33 + (3u*sizeof(uint8_t)) + (2u*sizeof(float))
uci1 10:3c93db1cfb12 34 + SnConfigFrame::kConfLblLen;
uci1 21:ce51bb0ba4a5 35 static const uint32_t kMaxSizeOfV3 =
uci1 21:ce51bb0ba4a5 36 kMaxSizeOfV2 + sizeof(uint32_t) + sizeof(float);
uci1 10:3c93db1cfb12 37 static const uint32_t kMaxSizeOf = kMaxSizeOfV1;
uci1 10:3c93db1cfb12 38
uci1 25:57b2627fe756 39 public:
uci1 25:57b2627fe756 40 static bool fgRecalcFiles;
uci1 25:57b2627fe756 41 private:
uci1 25:57b2627fe756 42 static uint32_t fgNfiles;
uci1 25:57b2627fe756 43 static float fgTotKbytes;
uci1 25:57b2627fe756 44 public:
uci1 10:3c93db1cfb12 45 static
uci1 10:3c93db1cfb12 46 uint32_t GetMaxSizeOf(const uint8_t rv) {
uci1 10:3c93db1cfb12 47 if (rv==1) {
uci1 10:3c93db1cfb12 48 return kMaxSizeOfV1;
uci1 21:ce51bb0ba4a5 49 } else if (rv==2) {
uci1 21:ce51bb0ba4a5 50 return kMaxSizeOfV2;
uci1 10:3c93db1cfb12 51 } else {
uci1 21:ce51bb0ba4a5 52 return kMaxSizeOfV3;
uci1 10:3c93db1cfb12 53 }
uci1 10:3c93db1cfb12 54 }
uci1 1:e392595b4b76 55
uci1 1:e392595b4b76 56 template<class T>
uci1 1:e392595b4b76 57 static
uci1 3:24c5f0f50bf1 58 SnCommWin::ECommWinResult WriteTo(T& x,
uci1 1:e392595b4b76 59 const SnConfigFrame& conf,
uci1 1:e392595b4b76 60 const SnEventFrame& evt,
uci1 10:3c93db1cfb12 61 char* const evtBuf,
uci1 10:3c93db1cfb12 62 const uint16_t seq,
uci1 10:3c93db1cfb12 63 const float thmrate,
uci1 21:ce51bb0ba4a5 64 const float evtrate,
uci1 21:ce51bb0ba4a5 65 const uint8_t loseLSB,
uci1 21:ce51bb0ba4a5 66 const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 67 const uint16_t wvBase) {
uci1 1:e392595b4b76 68 // expect 'x' to be a MODSERIAL& or a char const*
uci1 1:e392595b4b76 69
uci1 1:e392595b4b76 70 const uint32_t llen = strlen(conf.GetLabel());
uci1 1:e392595b4b76 71
uci1 1:e392595b4b76 72 // if anything about these writes changes, update kIOVers and SizeOf
uci1 1:e392595b4b76 73 x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
uci1 1:e392595b4b76 74 x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
uci1 1:e392595b4b76 75 x = SnBitUtils::WriteTo(x, llen);
uci1 1:e392595b4b76 76 x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
uci1 1:e392595b4b76 77 x = SnBitUtils::WriteTo(x, conf.GetRun());
uci1 10:3c93db1cfb12 78 x = SnBitUtils::WriteTo(x, seq);
uci1 1:e392595b4b76 79 x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
uci1 1:e392595b4b76 80 x = SnBitUtils::WriteTo(x, loseLSB);
uci1 1:e392595b4b76 81 x = SnBitUtils::WriteTo(x, loseMSB);
uci1 1:e392595b4b76 82 x = SnBitUtils::WriteTo(x, wvBase);
uci1 10:3c93db1cfb12 83 x = SnBitUtils::WriteTo(x, thmrate);
uci1 10:3c93db1cfb12 84 x = SnBitUtils::WriteTo(x, evtrate);
uci1 21:ce51bb0ba4a5 85 // file info
uci1 25:57b2627fe756 86 if (fgRecalcFiles) {
uci1 25:57b2627fe756 87 #ifdef ST_DEBUG
uci1 25:57b2627fe756 88 printf("Calling GetDirProps for %s\r\n",SnSDUtils::kSDdir);
uci1 25:57b2627fe756 89 #endif
uci1 25:57b2627fe756 90 SnSDUtils::GetDirProps(SnSDUtils::kSDdir, fgNfiles, fgTotKbytes);
uci1 25:57b2627fe756 91 fgTotKbytes /= 1e3; // KB
uci1 25:57b2627fe756 92 #ifdef ST_DEBUG
uci1 25:57b2627fe756 93 printf("nfiles=%u, tb=%g kb\r\n",fgNfiles,fgTotKbytes);
uci1 25:57b2627fe756 94 #endif
uci1 25:57b2627fe756 95 fgRecalcFiles = false;
uci1 21:ce51bb0ba4a5 96 }
uci1 25:57b2627fe756 97 x = SnBitUtils::WriteTo(x, fgNfiles);
uci1 25:57b2627fe756 98 x = SnBitUtils::WriteTo(x, fgTotKbytes);
uci1 21:ce51bb0ba4a5 99
uci1 1:e392595b4b76 100 return SnCommWin::kOkMsgSent;
uci1 1:e392595b4b76 101 }
uci1 10:3c93db1cfb12 102
uci1 1:e392595b4b76 103 static
uci1 8:95a325df1f6b 104 uint32_t SizeOf(const uint8_t rv, const uint32_t confLblLen,
uci1 1:e392595b4b76 105 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 1:e392595b4b76 106 // number of bytes read/written during i/o
uci1 10:3c93db1cfb12 107 const uint32_t maxsize = GetMaxSizeOf(rv);
uci1 10:3c93db1cfb12 108 const uint32_t msz = maxsize - SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 109 + confLblLen;
uci1 10:3c93db1cfb12 110 if (rv==1) {
uci1 10:3c93db1cfb12 111 if ((loseLSB==0) && (loseMSB==0)) {
uci1 10:3c93db1cfb12 112 return msz;
uci1 10:3c93db1cfb12 113 } else {
uci1 10:3c93db1cfb12 114 return msz - maxsize
uci1 10:3c93db1cfb12 115 + SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 10:3c93db1cfb12 116 loseLSB, loseMSB);
uci1 10:3c93db1cfb12 117 }
uci1 10:3c93db1cfb12 118 } else {
uci1 1:e392595b4b76 119 return msz;
uci1 1:e392595b4b76 120 }
uci1 1:e392595b4b76 121 }
uci1 1:e392595b4b76 122
uci1 1:e392595b4b76 123 static
uci1 8:95a325df1f6b 124 uint32_t SizeOf(const uint8_t rv, const SnConfigFrame& conf) {
uci1 8:95a325df1f6b 125 return SizeOf(rv, conf.GetLabelStrLen(),
uci1 1:e392595b4b76 126 conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
uci1 1:e392595b4b76 127 }
uci1 1:e392595b4b76 128
uci1 1:e392595b4b76 129 };
uci1 1:e392595b4b76 130
uci1 1:e392595b4b76 131 #endif // SN_SnStatusFrame