Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCommWin.h@40:1324da35afd4, 2013-10-05 (annotated)
- Committer:
- uci1
- Date:
- Sat Oct 05 04:45:22 2013 +0000
- Revision:
- 40:1324da35afd4
- Parent:
- 37:ff95e7070f26
- Child:
- 41:d6f5e2f09e07
first commit of major overhaul to 2013-2014 mbed code. NOT YET FULLY TESTED. too many changes to list (fix local file receive, fix rates, external comm packes, big SD cards, get to comm win w/o SD, v8 config frame, v4 files, SBD buffering changes...)
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 | 40:1324da35afd4 | 31 | kOkWthMsgNoConf,// successfully received message and it says to stick with the same config |
uci1 | 40:1324da35afd4 | 32 | kOkWthMsgDidDel // successfully received message and deleted a file because of it |
uci1 | 1:e392595b4b76 | 33 | }; |
uci1 | 37:ff95e7070f26 | 34 | |
uci1 | 25:57b2627fe756 | 35 | static const char* kLocalDir; // the local mbed directory |
uci1 | 27:efc4d654b139 | 36 | static const char* kDelAllConfCodeStr; // a magic string to confirm deletion of all files on the SD card |
uci1 | 27:efc4d654b139 | 37 | static const uint8_t kDelAllConfCodeLen; // the length of the magic string |
uci1 | 21:ce51bb0ba4a5 | 38 | |
uci1 | 21:ce51bb0ba4a5 | 39 | private: |
uci1 | 21:ce51bb0ba4a5 | 40 | SnCommWin::ECommWinResult GetFilename(const uint32_t timeout, |
uci1 | 21:ce51bb0ba4a5 | 41 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 42 | const uint32_t namelen); |
uci1 | 21:ce51bb0ba4a5 | 43 | SnCommWin::ECommWinResult GetLocalFile(std::string fname, |
uci1 | 21:ce51bb0ba4a5 | 44 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 45 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 46 | const uint32_t timeout); |
uci1 | 21:ce51bb0ba4a5 | 47 | int16_t LoopLocalDirBinFiles(const bool doRemove, |
uci1 | 21:ce51bb0ba4a5 | 48 | const std::string& fname); |
uci1 | 21:ce51bb0ba4a5 | 49 | SnCommWin::ECommWinResult GetHeader(const uint32_t timeOut, |
uci1 | 21:ce51bb0ba4a5 | 50 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 51 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 52 | uint8_t& mcode, |
uci1 | 21:ce51bb0ba4a5 | 53 | uint32_t& mlen); |
uci1 | 21:ce51bb0ba4a5 | 54 | |
uci1 | 1:e392595b4b76 | 55 | |
uci1 | 3:24c5f0f50bf1 | 56 | protected: |
uci1 | 37:ff95e7070f26 | 57 | SnCommPeripheral* fComm; // the communication peripheral. deleted in dtor!! |
uci1 | 37:ff95e7070f26 | 58 | |
uci1 | 40:1324da35afd4 | 59 | virtual int32_t SendFileBlock(FILE* inf, |
uci1 | 40:1324da35afd4 | 60 | const uint8_t blockHeaderCode, |
uci1 | 40:1324da35afd4 | 61 | const uint32_t blockSize, |
uci1 | 40:1324da35afd4 | 62 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 63 | int32_t& bytesToSend, |
uci1 | 40:1324da35afd4 | 64 | const uint32_t timeout); |
uci1 | 12:d472f9811262 | 65 | |
uci1 | 40:1324da35afd4 | 66 | virtual int32_t SendFileContents(FILE* inf, |
uci1 | 40:1324da35afd4 | 67 | const SnConfigFrame& curConf, |
uci1 | 40:1324da35afd4 | 68 | SnEventFrame& evt, |
uci1 | 40:1324da35afd4 | 69 | SnPowerFrame& pow, |
uci1 | 40:1324da35afd4 | 70 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 71 | uint32_t nevts, |
uci1 | 40:1324da35afd4 | 72 | int32_t& bytesToBeSent, |
uci1 | 40:1324da35afd4 | 73 | const uint32_t timeout_clock); |
uci1 | 8:95a325df1f6b | 74 | |
uci1 | 37:ff95e7070f26 | 75 | public: |
uci1 | 37:ff95e7070f26 | 76 | SnCommWin(SnCommPeripheral* p); |
uci1 | 37:ff95e7070f26 | 77 | virtual ~SnCommWin(); |
uci1 | 12:d472f9811262 | 78 | |
uci1 | 37:ff95e7070f26 | 79 | // probably no need to overload |
uci1 | 40:1324da35afd4 | 80 | virtual bool TrySetSysTimeUnix(const uint32_t timeout, |
uci1 | 40:1324da35afd4 | 81 | uint32_t& prvTime, |
uci1 | 40:1324da35afd4 | 82 | uint32_t& setTime); |
uci1 | 37:ff95e7070f26 | 83 | virtual bool Connect(const uint32_t timeout); |
uci1 | 37:ff95e7070f26 | 84 | virtual bool CloseConn(const uint32_t timeout); |
uci1 | 40:1324da35afd4 | 85 | virtual bool PowerDown(const uint32_t timeout); |
uci1 | 1:e392595b4b76 | 86 | |
uci1 | 37:ff95e7070f26 | 87 | // optional overloads |
uci1 | 37:ff95e7070f26 | 88 | virtual void Set(const SnConfigFrame& conf) {} |
uci1 | 16:744ce85aede2 | 89 | |
uci1 | 37:ff95e7070f26 | 90 | // mandatory overloads |
uci1 | 37:ff95e7070f26 | 91 | virtual SnConfigFrame::EDatPackBit GetCommType() const=0; |
uci1 | 8:95a325df1f6b | 92 | |
uci1 | 1:e392595b4b76 | 93 | virtual ECommWinResult OpenWindow(const uint32_t timeout, |
uci1 | 1:e392595b4b76 | 94 | const bool sendStatus, |
uci1 | 1:e392595b4b76 | 95 | const SnConfigFrame& conf, |
uci1 | 1:e392595b4b76 | 96 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 97 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 98 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 99 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 100 | const float evtrate, |
uci1 | 2:e67f7c158087 | 101 | char* const genBuf)=0; |
uci1 | 1:e392595b4b76 | 102 | |
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 | 40:1324da35afd4 | 114 | |
uci1 | 40:1324da35afd4 | 115 | virtual ECommWinResult HandleHandshake(FILE* inf, const char* infn, |
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 | const uint32_t bsize, |
uci1 | 40:1324da35afd4 | 121 | const uint32_t handshakeTimeout, |
uci1 | 40:1324da35afd4 | 122 | const uint8_t hndshk, |
uci1 | 40:1324da35afd4 | 123 | const uint32_t hndlen, |
uci1 | 40:1324da35afd4 | 124 | const uint32_t* nevts=0); |
uci1 | 40:1324da35afd4 | 125 | int32_t SendHndshkReq(char* const genBuf, |
uci1 | 40:1324da35afd4 | 126 | const uint32_t timeout_clock); |
uci1 | 3:24c5f0f50bf1 | 127 | |
uci1 | 8:95a325df1f6b | 128 | ECommWinResult GetConfig(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 129 | const uint32_t timeOut, |
uci1 | 8:95a325df1f6b | 130 | char* const confBuf, |
uci1 | 8:95a325df1f6b | 131 | const uint32_t bsize); |
uci1 | 1:e392595b4b76 | 132 | |
uci1 | 8:95a325df1f6b | 133 | ECommWinResult SendStatus(const SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 134 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 135 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 136 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 137 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 138 | const float evtrate, |
uci1 | 8:95a325df1f6b | 139 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 140 | const uint32_t timeout_clock); |
uci1 | 1:e392595b4b76 | 141 | |
uci1 | 23:ccf39298f205 | 142 | SnCommWin::ECommWinResult SendString(const char* str, |
uci1 | 23:ccf39298f205 | 143 | const uint32_t timeout); |
uci1 | 23:ccf39298f205 | 144 | |
uci1 | 40:1324da35afd4 | 145 | int32_t SendFilename(const char* fn, |
uci1 | 40:1324da35afd4 | 146 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 147 | int32_t& bytesToBeSent, |
uci1 | 40:1324da35afd4 | 148 | const uint32_t timeout_clock); |
uci1 | 6:6f002d202f59 | 149 | |
uci1 | 40:1324da35afd4 | 150 | ECommWinResult SendDataFromFile(FILE* inf, const char* infn, |
uci1 | 8:95a325df1f6b | 151 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 152 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 153 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 154 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 155 | const uint32_t bsize, |
uci1 | 8:95a325df1f6b | 156 | const uint32_t nevts, |
uci1 | 8:95a325df1f6b | 157 | const uint32_t timeout_clock, |
uci1 | 40:1324da35afd4 | 158 | uint8_t* hndcode=0, |
uci1 | 40:1324da35afd4 | 159 | uint32_t* hndlen=0); |
uci1 | 6:6f002d202f59 | 160 | |
uci1 | 8:95a325df1f6b | 161 | ECommWinResult SendData(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 162 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 163 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 164 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 165 | const uint32_t bsize, |
uci1 | 40:1324da35afd4 | 166 | const uint32_t timeout); |
uci1 | 18:55f1581f2ee4 | 167 | |
uci1 | 1:e392595b4b76 | 168 | }; |
uci1 | 1:e392595b4b76 | 169 | |
uci1 | 1:e392595b4b76 | 170 | #endif // SN_SnCommWin |