Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Thu Nov 01 07:00:17 2012 +0000
Revision:
27:efc4d654b139
Parent:
25:57b2627fe756
Child:
36:87865913ae6f
Afar comms enabled. Bug fixes: comm win opens with high rate now and no power to afar with afar comm enabled will not stall MBED. Features: stop file transfer, delete a specified run or delete all files on the SD card (file trans handshakes).

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 1:e392595b4b76 11
uci1 1:e392595b4b76 12 // ABC for communication types
uci1 1:e392595b4b76 13
uci1 1:e392595b4b76 14 class SnCommWin {
uci1 1:e392595b4b76 15 public:
uci1 1:e392595b4b76 16 enum ECommWinResult {
uci1 1:e392595b4b76 17 kUndefFail, // undefined fail type
uci1 1:e392595b4b76 18 kCanNotConnect, // unable to connect to port
uci1 1:e392595b4b76 19 kFailTimeout, // timed out but message required
uci1 2:e67f7c158087 20 kFailNoneSent, // none of the message sent
uci1 1:e392595b4b76 21 kFailPartSent, // only part of the message sent
uci1 3:24c5f0f50bf1 22 kUnexpectedRec, // unexpected / unhandled message received
uci1 1:e392595b4b76 23 kAllFails, // to be used for "if (ret > kAllFails) ==> success"
uci1 1:e392595b4b76 24 // only successes should go below
uci1 1:e392595b4b76 25 kConnected, // connection established, no messaging attempted
uci1 27:efc4d654b139 26 kOkStopComm, // received signal to stop communicating
uci1 1:e392595b4b76 27 kOkMsgSent, // message sent without waiting for "received" handshake
uci1 1:e392595b4b76 28 kOkNoMsg, // timed out with no message, but that is ok
uci1 12:d472f9811262 29 kOkWithMsg, // successfully received message
uci1 12:d472f9811262 30 kOkWthMsgNoConf // successfully received message and it says to stick with the same config
uci1 1:e392595b4b76 31 };
uci1 23:ccf39298f205 32
uci1 23:ccf39298f205 33 static const size_t kMaxStrLen = 512; // max bytes for a string send. prevent something crazy
uci1 25:57b2627fe756 34 static const char* kLocalDir; // the local mbed directory
uci1 27:efc4d654b139 35 static const char* kDelAllConfCodeStr; // a magic string to confirm deletion of all files on the SD card
uci1 27:efc4d654b139 36 static const uint8_t kDelAllConfCodeLen; // the length of the magic string
uci1 21:ce51bb0ba4a5 37
uci1 21:ce51bb0ba4a5 38 private:
uci1 21:ce51bb0ba4a5 39 SnCommWin::ECommWinResult GetFilename(const uint32_t timeout,
uci1 21:ce51bb0ba4a5 40 char* const buf,
uci1 21:ce51bb0ba4a5 41 const uint32_t namelen);
uci1 21:ce51bb0ba4a5 42 SnCommWin::ECommWinResult GetLocalFile(std::string fname,
uci1 21:ce51bb0ba4a5 43 char* const buf,
uci1 21:ce51bb0ba4a5 44 const uint32_t bsize,
uci1 21:ce51bb0ba4a5 45 const uint32_t timeout);
uci1 21:ce51bb0ba4a5 46 int16_t LoopLocalDirBinFiles(const bool doRemove,
uci1 21:ce51bb0ba4a5 47 const std::string& fname);
uci1 21:ce51bb0ba4a5 48 SnCommWin::ECommWinResult GetHeader(const uint32_t timeOut,
uci1 21:ce51bb0ba4a5 49 char* const buf,
uci1 21:ce51bb0ba4a5 50 const uint32_t bsize,
uci1 21:ce51bb0ba4a5 51 uint8_t& mcode,
uci1 21:ce51bb0ba4a5 52 uint32_t& mlen);
uci1 21:ce51bb0ba4a5 53
uci1 1:e392595b4b76 54
uci1 3:24c5f0f50bf1 55 protected:
uci1 12:d472f9811262 56 virtual int SendFileBlock(FILE* inf,
uci1 12:d472f9811262 57 const uint8_t blockHeaderCode,
uci1 12:d472f9811262 58 const uint32_t blockSize,
uci1 12:d472f9811262 59 char* const genBuf,
uci1 12:d472f9811262 60 const uint32_t timeout);
uci1 12:d472f9811262 61
uci1 8:95a325df1f6b 62 virtual ECommWinResult SendFileContents(FILE* inf,
uci1 8:95a325df1f6b 63 const SnConfigFrame& curConf,
uci1 8:95a325df1f6b 64 SnEventFrame& evt,
uci1 8:95a325df1f6b 65 SnPowerFrame& pow,
uci1 8:95a325df1f6b 66 char* const genBuf,
uci1 8:95a325df1f6b 67 uint32_t nevts,
uci1 12:d472f9811262 68 const uint32_t timeout_clock);
uci1 8:95a325df1f6b 69
uci1 21:ce51bb0ba4a5 70 // send and receive must not kick the watchdog, or a bad timeout
uci1 21:ce51bb0ba4a5 71 // could block a station forever!
uci1 8:95a325df1f6b 72 virtual int32_t ReceiveAll(char* const buf, const uint32_t mlen,
uci1 8:95a325df1f6b 73 const uint32_t timeout_clock)=0;
uci1 8:95a325df1f6b 74 virtual int32_t SendAll(char* const data, const uint32_t length,
uci1 8:95a325df1f6b 75 const uint32_t timeout_clock)=0;
uci1 12:d472f9811262 76
uci1 12:d472f9811262 77 bool IsTimedOut(const uint32_t timeout_clock) const;
uci1 8:95a325df1f6b 78
uci1 12:d472f9811262 79
uci1 1:e392595b4b76 80 public:
uci1 1:e392595b4b76 81 virtual ~SnCommWin() {}
uci1 1:e392595b4b76 82
uci1 16:744ce85aede2 83 virtual SnConfigFrame::EDatPackBit GetCommType() const=0;
uci1 16:744ce85aede2 84
uci1 16:744ce85aede2 85 virtual bool TrySetSysTimeUnix(const uint32_t timeout) { return 0; }
uci1 16:744ce85aede2 86
uci1 8:95a325df1f6b 87 virtual void Set(const SnConfigFrame& conf)=0;
uci1 8:95a325df1f6b 88
uci1 1:e392595b4b76 89 virtual ECommWinResult OpenWindow(const uint32_t timeout,
uci1 1:e392595b4b76 90 const bool sendStatus,
uci1 1:e392595b4b76 91 const SnConfigFrame& conf,
uci1 1:e392595b4b76 92 const SnEventFrame& evt,
uci1 8:95a325df1f6b 93 const SnPowerFrame& pow,
uci1 10:3c93db1cfb12 94 const uint16_t seq,
uci1 10:3c93db1cfb12 95 const float thmrate,
uci1 10:3c93db1cfb12 96 const float evtrate,
uci1 2:e67f7c158087 97 char* const genBuf)=0;
uci1 1:e392595b4b76 98
uci1 1:e392595b4b76 99 virtual bool Connect(const uint32_t timeout)=0;
uci1 15:f2569d8e4176 100 virtual bool CloseConn(const uint32_t timeout)=0;
uci1 16:744ce85aede2 101 virtual uint32_t GetConnectTimeout() const;
uci1 16:744ce85aede2 102 virtual uint32_t GetListenTimeout() const;
uci1 27:efc4d654b139 103 virtual bool GetDeleteAllConfirmCode(const SnConfigFrame& conf,
uci1 27:efc4d654b139 104 const uint32_t length,
uci1 27:efc4d654b139 105 const uint32_t timeout,
uci1 27:efc4d654b139 106 char* const buf,
uci1 27:efc4d654b139 107 const uint32_t bsize);
uci1 21:ce51bb0ba4a5 108 virtual ECommWinResult WaitHandshake(const SnConfigFrame& conf,
uci1 21:ce51bb0ba4a5 109 const uint32_t timeout,
uci1 3:24c5f0f50bf1 110 char* const buf,
uci1 6:6f002d202f59 111 const uint32_t bsize,
uci1 27:efc4d654b139 112 uint8_t& hndShkCode,
uci1 27:efc4d654b139 113 uint32_t* hndShkLen=0);
uci1 3:24c5f0f50bf1 114
uci1 8:95a325df1f6b 115 ECommWinResult GetConfig(SnConfigFrame& conf,
uci1 8:95a325df1f6b 116 const uint32_t timeOut,
uci1 8:95a325df1f6b 117 char* const confBuf,
uci1 8:95a325df1f6b 118 const uint32_t bsize);
uci1 1:e392595b4b76 119
uci1 8:95a325df1f6b 120 ECommWinResult SendStatus(const SnConfigFrame& conf,
uci1 8:95a325df1f6b 121 const SnEventFrame& evt,
uci1 8:95a325df1f6b 122 const SnPowerFrame& pow,
uci1 10:3c93db1cfb12 123 const uint16_t seq,
uci1 10:3c93db1cfb12 124 const float thmrate,
uci1 10:3c93db1cfb12 125 const float evtrate,
uci1 8:95a325df1f6b 126 char* const genBuf,
uci1 8:95a325df1f6b 127 const uint32_t timeout_clock);
uci1 1:e392595b4b76 128
uci1 23:ccf39298f205 129 SnCommWin::ECommWinResult SendString(const char* str,
uci1 23:ccf39298f205 130 const uint32_t timeout);
uci1 23:ccf39298f205 131
uci1 8:95a325df1f6b 132 ECommWinResult SendFilename(const char* fn,
uci1 8:95a325df1f6b 133 char* const genBuf,
uci1 8:95a325df1f6b 134 const uint32_t timeout_clock);
uci1 6:6f002d202f59 135
uci1 8:95a325df1f6b 136 ECommWinResult SendData(FILE* inf, const char* infn,
uci1 8:95a325df1f6b 137 const SnConfigFrame& curConf,
uci1 8:95a325df1f6b 138 SnEventFrame& evt,
uci1 8:95a325df1f6b 139 SnPowerFrame& pow,
uci1 8:95a325df1f6b 140 char* const genBuf,
uci1 8:95a325df1f6b 141 const uint32_t bsize,
uci1 8:95a325df1f6b 142 const uint32_t nevts,
uci1 8:95a325df1f6b 143 const uint32_t timeout_clock,
uci1 25:57b2627fe756 144 const uint32_t handshakeTimeout,
uci1 25:57b2627fe756 145 uint8_t* hndres=0);
uci1 6:6f002d202f59 146
uci1 8:95a325df1f6b 147 ECommWinResult SendData(SnConfigFrame& conf,
uci1 8:95a325df1f6b 148 SnEventFrame& evt,
uci1 8:95a325df1f6b 149 SnPowerFrame& pow,
uci1 8:95a325df1f6b 150 char* const genBuf,
uci1 8:95a325df1f6b 151 const uint32_t bsize,
uci1 12:d472f9811262 152 const uint32_t timeout,
uci1 12:d472f9811262 153 const uint32_t handshakeTimeout);
uci1 8:95a325df1f6b 154
uci1 25:57b2627fe756 155 static
uci1 25:57b2627fe756 156 void CapitalizeInPlace(std::string::iterator s,
uci1 25:57b2627fe756 157 const std::string::const_iterator send);
uci1 25:57b2627fe756 158
uci1 18:55f1581f2ee4 159 // for debugging
uci1 18:55f1581f2ee4 160 void dispStrBytes(const char* const s, const uint32_t len) const {
uci1 18:55f1581f2ee4 161 const char* c = s;
uci1 18:55f1581f2ee4 162 for (uint32_t i=0; i<len; ++i, ++c) {
uci1 18:55f1581f2ee4 163 if (*c>0x1F && *c<0x7F) {
uci1 18:55f1581f2ee4 164 printf("%c", *c);
uci1 18:55f1581f2ee4 165 } else {
uci1 18:55f1581f2ee4 166 printf(".x%02x.", *c);
uci1 18:55f1581f2ee4 167 }
uci1 18:55f1581f2ee4 168 }
uci1 18:55f1581f2ee4 169 }
uci1 18:55f1581f2ee4 170
uci1 1:e392595b4b76 171 };
uci1 1:e392595b4b76 172
uci1 1:e392595b4b76 173 #endif // SN_SnCommWin