Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCommWin.h@21:ce51bb0ba4a5, 2012-10-10 (annotated)
- Committer:
- uci1
- Date:
- Wed Oct 10 05:54:12 2012 +0000
- Revision:
- 21:ce51bb0ba4a5
- Parent:
- 18:55f1581f2ee4
- Child:
- 23:ccf39298f205
Uses USB comm. Fix rates calc. Power up/down ETH with Afar. Fix sending evt with status. Add num files and bytes of data to status. Can save a local file (i.e. reprogram MBED) via comms. Set config after each comm win (need if cards pow cycle).
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:e392595b4b76 | 26 | kOkMsgSent, // message sent without waiting for "received" handshake |
uci1 | 1:e392595b4b76 | 27 | kOkNoMsg, // timed out with no message, but that is ok |
uci1 | 12:d472f9811262 | 28 | kOkWithMsg, // successfully received message |
uci1 | 12:d472f9811262 | 29 | kOkWthMsgNoConf // successfully received message and it says to stick with the same config |
uci1 | 1:e392595b4b76 | 30 | }; |
uci1 | 21:ce51bb0ba4a5 | 31 | |
uci1 | 21:ce51bb0ba4a5 | 32 | private: |
uci1 | 21:ce51bb0ba4a5 | 33 | SnCommWin::ECommWinResult GetFilename(const uint32_t timeout, |
uci1 | 21:ce51bb0ba4a5 | 34 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 35 | const uint32_t namelen); |
uci1 | 21:ce51bb0ba4a5 | 36 | SnCommWin::ECommWinResult GetLocalFile(std::string fname, |
uci1 | 21:ce51bb0ba4a5 | 37 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 38 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 39 | const uint32_t timeout); |
uci1 | 21:ce51bb0ba4a5 | 40 | int16_t LoopLocalDirBinFiles(const bool doRemove, |
uci1 | 21:ce51bb0ba4a5 | 41 | const std::string& fname); |
uci1 | 21:ce51bb0ba4a5 | 42 | SnCommWin::ECommWinResult GetHeader(const uint32_t timeOut, |
uci1 | 21:ce51bb0ba4a5 | 43 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 44 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 45 | uint8_t& mcode, |
uci1 | 21:ce51bb0ba4a5 | 46 | uint32_t& mlen); |
uci1 | 21:ce51bb0ba4a5 | 47 | |
uci1 | 1:e392595b4b76 | 48 | |
uci1 | 3:24c5f0f50bf1 | 49 | protected: |
uci1 | 12:d472f9811262 | 50 | virtual int SendFileBlock(FILE* inf, |
uci1 | 12:d472f9811262 | 51 | const uint8_t blockHeaderCode, |
uci1 | 12:d472f9811262 | 52 | const uint32_t blockSize, |
uci1 | 12:d472f9811262 | 53 | char* const genBuf, |
uci1 | 12:d472f9811262 | 54 | const uint32_t timeout); |
uci1 | 12:d472f9811262 | 55 | |
uci1 | 8:95a325df1f6b | 56 | virtual ECommWinResult SendFileContents(FILE* inf, |
uci1 | 8:95a325df1f6b | 57 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 58 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 59 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 60 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 61 | uint32_t nevts, |
uci1 | 12:d472f9811262 | 62 | const uint32_t timeout_clock); |
uci1 | 8:95a325df1f6b | 63 | |
uci1 | 21:ce51bb0ba4a5 | 64 | // send and receive must not kick the watchdog, or a bad timeout |
uci1 | 21:ce51bb0ba4a5 | 65 | // could block a station forever! |
uci1 | 8:95a325df1f6b | 66 | virtual int32_t ReceiveAll(char* const buf, const uint32_t mlen, |
uci1 | 8:95a325df1f6b | 67 | const uint32_t timeout_clock)=0; |
uci1 | 8:95a325df1f6b | 68 | virtual int32_t SendAll(char* const data, const uint32_t length, |
uci1 | 8:95a325df1f6b | 69 | const uint32_t timeout_clock)=0; |
uci1 | 12:d472f9811262 | 70 | |
uci1 | 12:d472f9811262 | 71 | bool IsTimedOut(const uint32_t timeout_clock) const; |
uci1 | 8:95a325df1f6b | 72 | |
uci1 | 12:d472f9811262 | 73 | |
uci1 | 1:e392595b4b76 | 74 | public: |
uci1 | 1:e392595b4b76 | 75 | virtual ~SnCommWin() {} |
uci1 | 1:e392595b4b76 | 76 | |
uci1 | 16:744ce85aede2 | 77 | virtual SnConfigFrame::EDatPackBit GetCommType() const=0; |
uci1 | 16:744ce85aede2 | 78 | |
uci1 | 16:744ce85aede2 | 79 | virtual bool TrySetSysTimeUnix(const uint32_t timeout) { return 0; } |
uci1 | 16:744ce85aede2 | 80 | |
uci1 | 8:95a325df1f6b | 81 | virtual void Set(const SnConfigFrame& conf)=0; |
uci1 | 8:95a325df1f6b | 82 | |
uci1 | 1:e392595b4b76 | 83 | virtual ECommWinResult OpenWindow(const uint32_t timeout, |
uci1 | 1:e392595b4b76 | 84 | const bool sendStatus, |
uci1 | 1:e392595b4b76 | 85 | const SnConfigFrame& conf, |
uci1 | 1:e392595b4b76 | 86 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 87 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 88 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 89 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 90 | const float evtrate, |
uci1 | 2:e67f7c158087 | 91 | char* const genBuf)=0; |
uci1 | 1:e392595b4b76 | 92 | |
uci1 | 1:e392595b4b76 | 93 | virtual bool Connect(const uint32_t timeout)=0; |
uci1 | 15:f2569d8e4176 | 94 | virtual bool CloseConn(const uint32_t timeout)=0; |
uci1 | 16:744ce85aede2 | 95 | virtual uint32_t GetConnectTimeout() const; |
uci1 | 16:744ce85aede2 | 96 | virtual uint32_t GetListenTimeout() const; |
uci1 | 21:ce51bb0ba4a5 | 97 | virtual ECommWinResult WaitHandshake(const SnConfigFrame& conf, |
uci1 | 21:ce51bb0ba4a5 | 98 | const uint32_t timeout, |
uci1 | 3:24c5f0f50bf1 | 99 | char* const buf, |
uci1 | 6:6f002d202f59 | 100 | const uint32_t bsize, |
uci1 | 8:95a325df1f6b | 101 | uint8_t& hndShkCode); |
uci1 | 3:24c5f0f50bf1 | 102 | |
uci1 | 8:95a325df1f6b | 103 | ECommWinResult GetConfig(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 104 | const uint32_t timeOut, |
uci1 | 8:95a325df1f6b | 105 | char* const confBuf, |
uci1 | 8:95a325df1f6b | 106 | const uint32_t bsize); |
uci1 | 1:e392595b4b76 | 107 | |
uci1 | 8:95a325df1f6b | 108 | ECommWinResult SendStatus(const SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 109 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 110 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 111 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 112 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 113 | const float evtrate, |
uci1 | 8:95a325df1f6b | 114 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 115 | const uint32_t timeout_clock); |
uci1 | 1:e392595b4b76 | 116 | |
uci1 | 8:95a325df1f6b | 117 | ECommWinResult SendFilename(const char* fn, |
uci1 | 8:95a325df1f6b | 118 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 119 | const uint32_t timeout_clock); |
uci1 | 6:6f002d202f59 | 120 | |
uci1 | 8:95a325df1f6b | 121 | ECommWinResult SendData(FILE* inf, const char* infn, |
uci1 | 8:95a325df1f6b | 122 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 123 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 124 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 125 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 126 | const uint32_t bsize, |
uci1 | 8:95a325df1f6b | 127 | const uint32_t nevts, |
uci1 | 8:95a325df1f6b | 128 | const uint32_t timeout_clock, |
uci1 | 12:d472f9811262 | 129 | const uint32_t handshakeTimeout); |
uci1 | 6:6f002d202f59 | 130 | |
uci1 | 8:95a325df1f6b | 131 | ECommWinResult SendData(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 132 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 133 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 134 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 135 | const uint32_t bsize, |
uci1 | 12:d472f9811262 | 136 | const uint32_t timeout, |
uci1 | 12:d472f9811262 | 137 | const uint32_t handshakeTimeout); |
uci1 | 8:95a325df1f6b | 138 | |
uci1 | 18:55f1581f2ee4 | 139 | // for debugging |
uci1 | 18:55f1581f2ee4 | 140 | void dispStrBytes(const char* const s, const uint32_t len) const { |
uci1 | 18:55f1581f2ee4 | 141 | const char* c = s; |
uci1 | 18:55f1581f2ee4 | 142 | for (uint32_t i=0; i<len; ++i, ++c) { |
uci1 | 18:55f1581f2ee4 | 143 | if (*c>0x1F && *c<0x7F) { |
uci1 | 18:55f1581f2ee4 | 144 | printf("%c", *c); |
uci1 | 18:55f1581f2ee4 | 145 | } else { |
uci1 | 18:55f1581f2ee4 | 146 | printf(".x%02x.", *c); |
uci1 | 18:55f1581f2ee4 | 147 | } |
uci1 | 18:55f1581f2ee4 | 148 | } |
uci1 | 18:55f1581f2ee4 | 149 | } |
uci1 | 18:55f1581f2ee4 | 150 | |
uci1 | 1:e392595b4b76 | 151 | }; |
uci1 | 1:e392595b4b76 | 152 | |
uci1 | 1:e392595b4b76 | 153 | #endif // SN_SnCommWin |