Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue May 03 02:01:35 2016 +0000
Revision:
116:8099b754fbb4
Parent:
98:ce72ef143b9b
Child:
122:c1b5023eac69
One program for all stns via UID/MAC lookup table or generation. Status sends number trg/evt and livetime, not rates. Add 512 sample evt and RFFT-LUTs. Add L1Scaledown trg bit. Allow skip SST reset at start. Fix dt at end of seq. End of comm signal.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 1:e392595b4b76 1 #ifndef SN_SnCommWin
uci1 1:e392595b4b76 2 #define SN_SnCommWin
uci1 1:e392595b4b76 3
uci1 1:e392595b4b76 4 #include "mbed.h"
uci1 1:e392595b4b76 5 #include <stdint.h>
uci1 21:ce51bb0ba4a5 6 #include <string>
uci1 1:e392595b4b76 7
uci1 8:95a325df1f6b 8 #include "SnConfigFrame.h"
uci1 1:e392595b4b76 9 class SnEventFrame;
uci1 8:95a325df1f6b 10 class SnPowerFrame;
uci1 41:d6f5e2f09e07 11 class SnSignalStrengthFrame;
uci1 37:ff95e7070f26 12 class SnCommPeripheral;
uci1 56:0bba0ef15697 13 class SnTempFrame;
uci1 84:80b15993944e 14 class SnClockSetFrame;
uci1 84:80b15993944e 15 class SnHeartbeatFrame;
uci1 1:e392595b4b76 16
uci1 37:ff95e7070f26 17 // DAQ station communication utilities
uci1 1:e392595b4b76 18
uci1 1:e392595b4b76 19 class SnCommWin {
uci1 1:e392595b4b76 20 public:
uci1 1:e392595b4b76 21 enum ECommWinResult {
uci1 1:e392595b4b76 22 kUndefFail, // undefined fail type
uci1 1:e392595b4b76 23 kCanNotConnect, // unable to connect to port
uci1 1:e392595b4b76 24 kFailTimeout, // timed out but message required
uci1 2:e67f7c158087 25 kFailNoneSent, // none of the message sent
uci1 1:e392595b4b76 26 kFailPartSent, // only part of the message sent
uci1 3:24c5f0f50bf1 27 kUnexpectedRec, // unexpected / unhandled message received
uci1 1:e392595b4b76 28 kAllFails, // to be used for "if (ret > kAllFails) ==> success"
uci1 1:e392595b4b76 29 // only successes should go below
uci1 1:e392595b4b76 30 kConnected, // connection established, no messaging attempted
uci1 27:efc4d654b139 31 kOkStopComm, // received signal to stop communicating
uci1 1:e392595b4b76 32 kOkMsgSent, // message sent without waiting for "received" handshake
uci1 1:e392595b4b76 33 kOkNoMsg, // timed out with no message, but that is ok
uci1 12:d472f9811262 34 kOkWithMsg, // successfully received message
uci1 40:1324da35afd4 35 kOkWthMsgNoConf,// successfully received message and it says to stick with the same config
uci1 40:1324da35afd4 36 kOkWthMsgDidDel // successfully received message and deleted a file because of it
uci1 1:e392595b4b76 37 };
uci1 37:ff95e7070f26 38
uci1 25:57b2627fe756 39 static const char* kLocalDir; // the local mbed directory
uci1 27:efc4d654b139 40 static const char* kDelAllConfCodeStr; // a magic string to confirm deletion of all files on the SD card
uci1 27:efc4d654b139 41 static const uint8_t kDelAllConfCodeLen; // the length of the magic string
uci1 21:ce51bb0ba4a5 42
uci1 21:ce51bb0ba4a5 43 private:
uci1 56:0bba0ef15697 44 bool fSendingInHandshake; // true if we are sending files as a result of a handshake.
uci1 56:0bba0ef15697 45 // will ignore further handshake requests to send new files
uci1 56:0bba0ef15697 46 // in order to avoid a stack overflow
uci1 56:0bba0ef15697 47
uci1 56:0bba0ef15697 48
uci1 21:ce51bb0ba4a5 49 SnCommWin::ECommWinResult GetFilename(const uint32_t timeout,
uci1 21:ce51bb0ba4a5 50 char* const buf,
uci1 21:ce51bb0ba4a5 51 const uint32_t namelen);
uci1 21:ce51bb0ba4a5 52 SnCommWin::ECommWinResult GetLocalFile(std::string fname,
uci1 21:ce51bb0ba4a5 53 char* const buf,
uci1 21:ce51bb0ba4a5 54 const uint32_t bsize,
uci1 21:ce51bb0ba4a5 55 const uint32_t timeout);
uci1 21:ce51bb0ba4a5 56 int16_t LoopLocalDirBinFiles(const bool doRemove,
uci1 21:ce51bb0ba4a5 57 const std::string& fname);
uci1 21:ce51bb0ba4a5 58 SnCommWin::ECommWinResult GetHeader(const uint32_t timeOut,
uci1 21:ce51bb0ba4a5 59 char* const buf,
uci1 21:ce51bb0ba4a5 60 const uint32_t bsize,
uci1 21:ce51bb0ba4a5 61 uint8_t& mcode,
uci1 21:ce51bb0ba4a5 62 uint32_t& mlen);
uci1 21:ce51bb0ba4a5 63
uci1 84:80b15993944e 64 bool WriteStatusDataPackHeaderTo(char*& b,
uci1 84:80b15993944e 65 const uint32_t payloadLen);
uci1 84:80b15993944e 66
uci1 84:80b15993944e 67 bool CallHeaderWriteTo(char*& b,
uci1 84:80b15993944e 68 const uint8_t msgCode,
uci1 84:80b15993944e 69 const uint32_t msgLen);
uci1 84:80b15993944e 70
uci1 84:80b15993944e 71 int32_t CallSendAll(const char* const data, const uint32_t length,
uci1 84:80b15993944e 72 const uint32_t timeout_clock);
uci1 84:80b15993944e 73
uci1 84:80b15993944e 74
uci1 84:80b15993944e 75 template<class T>
uci1 84:80b15993944e 76 char* WriteStatusDataPackHeadersFor(const T& x,
uci1 84:80b15993944e 77 const uint8_t hdrCode,
uci1 84:80b15993944e 78 char*& b,
uci1 84:80b15993944e 79 const uint32_t timeout_clock) {
uci1 84:80b15993944e 80 // flag that this is a data packet
uci1 84:80b15993944e 81 const uint32_t xMsgLen = x.SizeOf();
uci1 84:80b15993944e 82 WriteStatusDataPackHeaderTo(b, xMsgLen);
uci1 84:80b15993944e 83 CallHeaderWriteTo(b, hdrCode, xMsgLen);
uci1 84:80b15993944e 84 return b;
uci1 84:80b15993944e 85 }
uci1 84:80b15993944e 86
uci1 84:80b15993944e 87 template<class T>
uci1 84:80b15993944e 88 char* SendStatusDataPack(const T& x,
uci1 84:80b15993944e 89 const uint8_t hdrCode,
uci1 84:80b15993944e 90 int32_t& toBeSent,
uci1 84:80b15993944e 91 int32_t& byteSent,
uci1 84:80b15993944e 92 char* const genBuf,
uci1 84:80b15993944e 93 const uint32_t timeout_clock) {
uci1 84:80b15993944e 94 char* b = genBuf;
uci1 84:80b15993944e 95 b = WriteStatusDataPackHeadersFor(x, hdrCode,
uci1 84:80b15993944e 96 b, timeout_clock);
uci1 84:80b15993944e 97 x.WriteTo(b);
uci1 84:80b15993944e 98 const int32_t sendNow = (b - genBuf);
uci1 84:80b15993944e 99 toBeSent += sendNow;
uci1 84:80b15993944e 100 byteSent += CallSendAll(genBuf, sendNow, timeout_clock);
uci1 84:80b15993944e 101 return b;
uci1 84:80b15993944e 102 }
uci1 84:80b15993944e 103
uci1 1:e392595b4b76 104
uci1 3:24c5f0f50bf1 105 protected:
uci1 37:ff95e7070f26 106 SnCommPeripheral* fComm; // the communication peripheral. deleted in dtor!!
uci1 37:ff95e7070f26 107
uci1 40:1324da35afd4 108 virtual int32_t SendFileBlock(FILE* inf,
uci1 40:1324da35afd4 109 const uint8_t blockHeaderCode,
uci1 40:1324da35afd4 110 const uint32_t blockSize,
uci1 40:1324da35afd4 111 char* const genBuf,
uci1 40:1324da35afd4 112 int32_t& bytesToSend,
uci1 40:1324da35afd4 113 const uint32_t timeout);
uci1 12:d472f9811262 114
uci1 40:1324da35afd4 115 virtual int32_t SendFileContents(FILE* inf,
uci1 40:1324da35afd4 116 const SnConfigFrame& curConf,
uci1 40:1324da35afd4 117 SnEventFrame& evt,
uci1 40:1324da35afd4 118 SnPowerFrame& pow,
uci1 40:1324da35afd4 119 char* const genBuf,
uci1 40:1324da35afd4 120 uint32_t nevts,
uci1 40:1324da35afd4 121 int32_t& bytesToBeSent,
uci1 40:1324da35afd4 122 const uint32_t timeout_clock);
uci1 8:95a325df1f6b 123
uci1 37:ff95e7070f26 124 public:
uci1 37:ff95e7070f26 125 SnCommWin(SnCommPeripheral* p);
uci1 37:ff95e7070f26 126 virtual ~SnCommWin();
uci1 12:d472f9811262 127
uci1 37:ff95e7070f26 128 // probably no need to overload
uci1 40:1324da35afd4 129 virtual bool TrySetSysTimeUnix(const uint32_t timeout,
uci1 40:1324da35afd4 130 uint32_t& prvTime,
uci1 40:1324da35afd4 131 uint32_t& setTime);
uci1 37:ff95e7070f26 132 virtual bool Connect(const uint32_t timeout);
uci1 116:8099b754fbb4 133 virtual bool CloseConn(const uint32_t timeout,
uci1 116:8099b754fbb4 134 char* const genBuf=0,
uci1 116:8099b754fbb4 135 const bool sendCloseSignal=false);
uci1 40:1324da35afd4 136 virtual bool PowerDown(const uint32_t timeout);
uci1 1:e392595b4b76 137
uci1 37:ff95e7070f26 138 // optional overloads
uci1 37:ff95e7070f26 139 virtual void Set(const SnConfigFrame& conf) {}
uci1 16:744ce85aede2 140
uci1 37:ff95e7070f26 141 // mandatory overloads
uci1 37:ff95e7070f26 142 virtual SnConfigFrame::EDatPackBit GetCommType() const=0;
uci1 8:95a325df1f6b 143
uci1 84:80b15993944e 144 virtual ECommWinResult OpenWindow(const bool sendStatus,
uci1 84:80b15993944e 145 const SnConfigFrame& conf,
uci1 84:80b15993944e 146 const SnPowerFrame& pow, // com win power
uci1 84:80b15993944e 147 const SnEventFrame& stEvent,
uci1 84:80b15993944e 148 const uint16_t seq,
uci1 116:8099b754fbb4 149 // const float thmrate,
uci1 116:8099b754fbb4 150 // const float evtrate,
uci1 116:8099b754fbb4 151 const uint32_t numThmTrigs,
uci1 116:8099b754fbb4 152 const uint32_t numSavedEvts,
uci1 116:8099b754fbb4 153 const float seqlive,
uci1 84:80b15993944e 154 const uint32_t powerOnTime,
uci1 84:80b15993944e 155 const SnTempFrame& temper, // com win temp
uci1 84:80b15993944e 156 char* const genBuf,
uci1 84:80b15993944e 157 const uint32_t timeout_clock)=0;
uci1 116:8099b754fbb4 158
uci1 27:efc4d654b139 159 virtual bool GetDeleteAllConfirmCode(const SnConfigFrame& conf,
uci1 27:efc4d654b139 160 const uint32_t length,
uci1 27:efc4d654b139 161 const uint32_t timeout,
uci1 27:efc4d654b139 162 char* const buf,
uci1 27:efc4d654b139 163 const uint32_t bsize);
uci1 21:ce51bb0ba4a5 164 virtual ECommWinResult WaitHandshake(const SnConfigFrame& conf,
uci1 21:ce51bb0ba4a5 165 const uint32_t timeout,
uci1 3:24c5f0f50bf1 166 char* const buf,
uci1 6:6f002d202f59 167 const uint32_t bsize,
uci1 27:efc4d654b139 168 uint8_t& hndShkCode,
uci1 27:efc4d654b139 169 uint32_t* hndShkLen=0);
uci1 40:1324da35afd4 170
uci1 40:1324da35afd4 171 virtual ECommWinResult HandleHandshake(FILE* inf, const char* infn,
uci1 40:1324da35afd4 172 const SnConfigFrame& curConf,
uci1 40:1324da35afd4 173 SnEventFrame& evt,
uci1 40:1324da35afd4 174 SnPowerFrame& pow,
uci1 40:1324da35afd4 175 char* const genBuf,
uci1 40:1324da35afd4 176 const uint32_t bsize,
uci1 40:1324da35afd4 177 const uint32_t handshakeTimeout,
uci1 40:1324da35afd4 178 const uint8_t hndshk,
uci1 40:1324da35afd4 179 const uint32_t hndlen,
uci1 40:1324da35afd4 180 const uint32_t* nevts=0);
uci1 40:1324da35afd4 181 int32_t SendHndshkReq(char* const genBuf,
uci1 40:1324da35afd4 182 const uint32_t timeout_clock);
uci1 3:24c5f0f50bf1 183
uci1 41:d6f5e2f09e07 184 ECommWinResult SendSignalStrength(char* const genBuf,
uci1 41:d6f5e2f09e07 185 SnSignalStrengthFrame& sigstr,
uci1 41:d6f5e2f09e07 186 const uint32_t timeout_clock);
uci1 41:d6f5e2f09e07 187
uci1 8:95a325df1f6b 188 ECommWinResult GetConfig(SnConfigFrame& conf,
uci1 8:95a325df1f6b 189 const uint32_t timeOut,
uci1 8:95a325df1f6b 190 char* const confBuf,
uci1 8:95a325df1f6b 191 const uint32_t bsize);
uci1 1:e392595b4b76 192
uci1 8:95a325df1f6b 193 ECommWinResult SendStatus(const SnConfigFrame& conf,
uci1 84:80b15993944e 194 const SnPowerFrame& pow, // com win power
uci1 84:80b15993944e 195 const SnEventFrame& stEvent,
uci1 84:80b15993944e 196 const uint16_t seq,
uci1 116:8099b754fbb4 197 // const float thmrate,
uci1 116:8099b754fbb4 198 // const float evtrate,
uci1 116:8099b754fbb4 199 const uint32_t numThmTrigs,
uci1 116:8099b754fbb4 200 const uint32_t numSavedEvts,
uci1 116:8099b754fbb4 201 const float seqlive,
uci1 84:80b15993944e 202 const uint32_t powerOnTime,
uci1 84:80b15993944e 203 const SnTempFrame& temper, // com win temp
uci1 84:80b15993944e 204 char* const genBuf,
uci1 84:80b15993944e 205 const uint32_t timeout_clock);
uci1 84:80b15993944e 206
uci1 84:80b15993944e 207 virtual ECommWinResult SendStatusData(const SnConfigFrame& conf,
uci1 98:ce72ef143b9b 208 const SnConfigFrame& stConf,
uci1 84:80b15993944e 209 const SnClockSetFrame& stTrgStartClk,
uci1 84:80b15993944e 210 const SnClockSetFrame& stTrgStopClk,
uci1 84:80b15993944e 211 const SnPowerFrame& stPower,
uci1 84:80b15993944e 212 const SnEventFrame& stEvent,
uci1 84:80b15993944e 213 const SnTempFrame& stTemperature,
uci1 84:80b15993944e 214 const SnHeartbeatFrame& stHeartbeat,
uci1 84:80b15993944e 215 const bool stNewPower,
uci1 84:80b15993944e 216 const bool stNewEvent,
uci1 84:80b15993944e 217 const bool stNewHeartbeat,
uci1 84:80b15993944e 218 const bool stNewTemperature,
uci1 84:80b15993944e 219 char* const genBuf,
uci1 84:80b15993944e 220 const uint32_t timeout_clock);
uci1 84:80b15993944e 221
uci1 23:ccf39298f205 222 SnCommWin::ECommWinResult SendString(const char* str,
uci1 23:ccf39298f205 223 const uint32_t timeout);
uci1 23:ccf39298f205 224
uci1 40:1324da35afd4 225 int32_t SendFilename(const char* fn,
uci1 40:1324da35afd4 226 char* const genBuf,
uci1 40:1324da35afd4 227 int32_t& bytesToBeSent,
uci1 40:1324da35afd4 228 const uint32_t timeout_clock);
uci1 6:6f002d202f59 229
uci1 40:1324da35afd4 230 ECommWinResult SendDataFromFile(FILE* inf, const char* infn,
uci1 8:95a325df1f6b 231 const SnConfigFrame& curConf,
uci1 8:95a325df1f6b 232 SnEventFrame& evt,
uci1 8:95a325df1f6b 233 SnPowerFrame& pow,
uci1 8:95a325df1f6b 234 char* const genBuf,
uci1 8:95a325df1f6b 235 const uint32_t bsize,
uci1 8:95a325df1f6b 236 const uint32_t nevts,
uci1 8:95a325df1f6b 237 const uint32_t timeout_clock,
uci1 40:1324da35afd4 238 uint8_t* hndcode=0,
uci1 40:1324da35afd4 239 uint32_t* hndlen=0);
uci1 6:6f002d202f59 240
uci1 8:95a325df1f6b 241 ECommWinResult SendData(SnConfigFrame& conf,
uci1 8:95a325df1f6b 242 SnEventFrame& evt,
uci1 8:95a325df1f6b 243 SnPowerFrame& pow,
uci1 8:95a325df1f6b 244 char* const genBuf,
uci1 8:95a325df1f6b 245 const uint32_t bsize,
uci1 40:1324da35afd4 246 const uint32_t timeout);
uci1 18:55f1581f2ee4 247
uci1 56:0bba0ef15697 248 // assume little endian
uci1 56:0bba0ef15697 249 static
uci1 56:0bba0ef15697 250 uint16_t GetMinSeqFrom(const uint32_t hndshk) {
uci1 56:0bba0ef15697 251 // left-most 2 bytes
uci1 56:0bba0ef15697 252 return (hndshk>>16u);
uci1 56:0bba0ef15697 253 }
uci1 56:0bba0ef15697 254 static
uci1 56:0bba0ef15697 255 uint16_t GetMaxSeqFrom(const uint32_t hndshk) {
uci1 56:0bba0ef15697 256 // right-most 2 bytes
uci1 56:0bba0ef15697 257 return (hndshk&0xFFFF);
uci1 56:0bba0ef15697 258 }
uci1 56:0bba0ef15697 259
uci1 1:e392595b4b76 260 };
uci1 1:e392595b4b76 261
uci1 1:e392595b4b76 262 #endif // SN_SnCommWin