Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCommWin.h@37:ff95e7070f26, 2013-05-29 (annotated)
- Committer:
- uci1
- Date:
- Wed May 29 00:20:31 2013 +0000
- Revision:
- 37:ff95e7070f26
- Parent:
- 36:87865913ae6f
- Child:
- 40:1324da35afd4
SBD only and DEBUG enabled. Safety nets enabled. Protocol and Comms as separate packages. Compiles, but untested.
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 | 37:ff95e7070f26 | 11 | class SnCommPeripheral; |
uci1 | 1:e392595b4b76 | 12 | |
uci1 | 37:ff95e7070f26 | 13 | // DAQ station communication utilities |
uci1 | 1:e392595b4b76 | 14 | |
uci1 | 1:e392595b4b76 | 15 | class SnCommWin { |
uci1 | 1:e392595b4b76 | 16 | public: |
uci1 | 1:e392595b4b76 | 17 | enum ECommWinResult { |
uci1 | 1:e392595b4b76 | 18 | kUndefFail, // undefined fail type |
uci1 | 1:e392595b4b76 | 19 | kCanNotConnect, // unable to connect to port |
uci1 | 1:e392595b4b76 | 20 | kFailTimeout, // timed out but message required |
uci1 | 2:e67f7c158087 | 21 | kFailNoneSent, // none of the message sent |
uci1 | 1:e392595b4b76 | 22 | kFailPartSent, // only part of the message sent |
uci1 | 3:24c5f0f50bf1 | 23 | kUnexpectedRec, // unexpected / unhandled message received |
uci1 | 1:e392595b4b76 | 24 | kAllFails, // to be used for "if (ret > kAllFails) ==> success" |
uci1 | 1:e392595b4b76 | 25 | // only successes should go below |
uci1 | 1:e392595b4b76 | 26 | kConnected, // connection established, no messaging attempted |
uci1 | 27:efc4d654b139 | 27 | kOkStopComm, // received signal to stop communicating |
uci1 | 1:e392595b4b76 | 28 | kOkMsgSent, // message sent without waiting for "received" handshake |
uci1 | 1:e392595b4b76 | 29 | kOkNoMsg, // timed out with no message, but that is ok |
uci1 | 12:d472f9811262 | 30 | kOkWithMsg, // successfully received message |
uci1 | 12:d472f9811262 | 31 | kOkWthMsgNoConf // successfully received message and it says to stick with the same config |
uci1 | 1:e392595b4b76 | 32 | }; |
uci1 | 37:ff95e7070f26 | 33 | |
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 | 37:ff95e7070f26 | 56 | SnCommPeripheral* fComm; // the communication peripheral. deleted in dtor!! |
uci1 | 37:ff95e7070f26 | 57 | |
uci1 | 12:d472f9811262 | 58 | virtual int SendFileBlock(FILE* inf, |
uci1 | 12:d472f9811262 | 59 | const uint8_t blockHeaderCode, |
uci1 | 12:d472f9811262 | 60 | const uint32_t blockSize, |
uci1 | 12:d472f9811262 | 61 | char* const genBuf, |
uci1 | 12:d472f9811262 | 62 | const uint32_t timeout); |
uci1 | 12:d472f9811262 | 63 | |
uci1 | 8:95a325df1f6b | 64 | virtual ECommWinResult SendFileContents(FILE* inf, |
uci1 | 8:95a325df1f6b | 65 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 66 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 67 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 68 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 69 | uint32_t nevts, |
uci1 | 12:d472f9811262 | 70 | const uint32_t timeout_clock); |
uci1 | 8:95a325df1f6b | 71 | |
uci1 | 37:ff95e7070f26 | 72 | public: |
uci1 | 37:ff95e7070f26 | 73 | SnCommWin(SnCommPeripheral* p); |
uci1 | 37:ff95e7070f26 | 74 | virtual ~SnCommWin(); |
uci1 | 12:d472f9811262 | 75 | |
uci1 | 37:ff95e7070f26 | 76 | // probably no need to overload |
uci1 | 37:ff95e7070f26 | 77 | virtual bool TrySetSysTimeUnix(const uint32_t timeout); |
uci1 | 37:ff95e7070f26 | 78 | virtual bool Connect(const uint32_t timeout); |
uci1 | 37:ff95e7070f26 | 79 | virtual bool CloseConn(const uint32_t timeout); |
uci1 | 1:e392595b4b76 | 80 | |
uci1 | 37:ff95e7070f26 | 81 | // optional overloads |
uci1 | 37:ff95e7070f26 | 82 | virtual uint32_t GetConnectTimeout() const; |
uci1 | 37:ff95e7070f26 | 83 | virtual uint32_t GetListenTimeout() const; |
uci1 | 37:ff95e7070f26 | 84 | virtual void Set(const SnConfigFrame& conf) {} |
uci1 | 16:744ce85aede2 | 85 | |
uci1 | 37:ff95e7070f26 | 86 | // mandatory overloads |
uci1 | 37:ff95e7070f26 | 87 | virtual SnConfigFrame::EDatPackBit GetCommType() const=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 | 27:efc4d654b139 | 99 | virtual bool GetDeleteAllConfirmCode(const SnConfigFrame& conf, |
uci1 | 27:efc4d654b139 | 100 | const uint32_t length, |
uci1 | 27:efc4d654b139 | 101 | const uint32_t timeout, |
uci1 | 27:efc4d654b139 | 102 | char* const buf, |
uci1 | 27:efc4d654b139 | 103 | const uint32_t bsize); |
uci1 | 21:ce51bb0ba4a5 | 104 | virtual ECommWinResult WaitHandshake(const SnConfigFrame& conf, |
uci1 | 21:ce51bb0ba4a5 | 105 | const uint32_t timeout, |
uci1 | 3:24c5f0f50bf1 | 106 | char* const buf, |
uci1 | 6:6f002d202f59 | 107 | const uint32_t bsize, |
uci1 | 27:efc4d654b139 | 108 | uint8_t& hndShkCode, |
uci1 | 27:efc4d654b139 | 109 | uint32_t* hndShkLen=0); |
uci1 | 3:24c5f0f50bf1 | 110 | |
uci1 | 8:95a325df1f6b | 111 | ECommWinResult GetConfig(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 112 | const uint32_t timeOut, |
uci1 | 8:95a325df1f6b | 113 | char* const confBuf, |
uci1 | 8:95a325df1f6b | 114 | const uint32_t bsize); |
uci1 | 1:e392595b4b76 | 115 | |
uci1 | 8:95a325df1f6b | 116 | ECommWinResult SendStatus(const SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 117 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 118 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 119 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 120 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 121 | const float evtrate, |
uci1 | 8:95a325df1f6b | 122 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 123 | const uint32_t timeout_clock); |
uci1 | 1:e392595b4b76 | 124 | |
uci1 | 23:ccf39298f205 | 125 | SnCommWin::ECommWinResult SendString(const char* str, |
uci1 | 23:ccf39298f205 | 126 | const uint32_t timeout); |
uci1 | 23:ccf39298f205 | 127 | |
uci1 | 8:95a325df1f6b | 128 | ECommWinResult SendFilename(const char* fn, |
uci1 | 8:95a325df1f6b | 129 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 130 | const uint32_t timeout_clock); |
uci1 | 6:6f002d202f59 | 131 | |
uci1 | 8:95a325df1f6b | 132 | ECommWinResult SendData(FILE* inf, const char* infn, |
uci1 | 8:95a325df1f6b | 133 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 134 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 135 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 136 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 137 | const uint32_t bsize, |
uci1 | 8:95a325df1f6b | 138 | const uint32_t nevts, |
uci1 | 8:95a325df1f6b | 139 | const uint32_t timeout_clock, |
uci1 | 25:57b2627fe756 | 140 | const uint32_t handshakeTimeout, |
uci1 | 25:57b2627fe756 | 141 | uint8_t* hndres=0); |
uci1 | 6:6f002d202f59 | 142 | |
uci1 | 8:95a325df1f6b | 143 | ECommWinResult SendData(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 144 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 145 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 146 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 147 | const uint32_t bsize, |
uci1 | 12:d472f9811262 | 148 | const uint32_t timeout, |
uci1 | 12:d472f9811262 | 149 | const uint32_t handshakeTimeout); |
uci1 | 18:55f1581f2ee4 | 150 | |
uci1 | 1:e392595b4b76 | 151 | }; |
uci1 | 1:e392595b4b76 | 152 | |
uci1 | 1:e392595b4b76 | 153 | #endif // SN_SnCommWin |