Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCommWin.h@56:0bba0ef15697, 2014-10-30 (annotated)
- Committer:
- uci1
- Date:
- Thu Oct 30 06:42:17 2014 +0000
- Revision:
- 56:0bba0ef15697
- Parent:
- 41:d6f5e2f09e07
- Child:
- 84:80b15993944e
update ext libs, add tempr, allow SST/ATWD, improve handshaking, run/seq list, req seq range, allow SBD only in low pwr, all pins start off, can collect data to ram w/o SD card, add parameters to status update
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 | 41:d6f5e2f09e07 | 11 | class SnSignalStrengthFrame; |
uci1 | 37:ff95e7070f26 | 12 | class SnCommPeripheral; |
uci1 | 56:0bba0ef15697 | 13 | class SnTempFrame; |
uci1 | 1:e392595b4b76 | 14 | |
uci1 | 37:ff95e7070f26 | 15 | // DAQ station communication utilities |
uci1 | 1:e392595b4b76 | 16 | |
uci1 | 1:e392595b4b76 | 17 | class SnCommWin { |
uci1 | 1:e392595b4b76 | 18 | public: |
uci1 | 1:e392595b4b76 | 19 | enum ECommWinResult { |
uci1 | 1:e392595b4b76 | 20 | kUndefFail, // undefined fail type |
uci1 | 1:e392595b4b76 | 21 | kCanNotConnect, // unable to connect to port |
uci1 | 1:e392595b4b76 | 22 | kFailTimeout, // timed out but message required |
uci1 | 2:e67f7c158087 | 23 | kFailNoneSent, // none of the message sent |
uci1 | 1:e392595b4b76 | 24 | kFailPartSent, // only part of the message sent |
uci1 | 3:24c5f0f50bf1 | 25 | kUnexpectedRec, // unexpected / unhandled message received |
uci1 | 1:e392595b4b76 | 26 | kAllFails, // to be used for "if (ret > kAllFails) ==> success" |
uci1 | 1:e392595b4b76 | 27 | // only successes should go below |
uci1 | 1:e392595b4b76 | 28 | kConnected, // connection established, no messaging attempted |
uci1 | 27:efc4d654b139 | 29 | kOkStopComm, // received signal to stop communicating |
uci1 | 1:e392595b4b76 | 30 | kOkMsgSent, // message sent without waiting for "received" handshake |
uci1 | 1:e392595b4b76 | 31 | kOkNoMsg, // timed out with no message, but that is ok |
uci1 | 12:d472f9811262 | 32 | kOkWithMsg, // successfully received message |
uci1 | 40:1324da35afd4 | 33 | kOkWthMsgNoConf,// successfully received message and it says to stick with the same config |
uci1 | 40:1324da35afd4 | 34 | kOkWthMsgDidDel // successfully received message and deleted a file because of it |
uci1 | 1:e392595b4b76 | 35 | }; |
uci1 | 37:ff95e7070f26 | 36 | |
uci1 | 25:57b2627fe756 | 37 | static const char* kLocalDir; // the local mbed directory |
uci1 | 27:efc4d654b139 | 38 | static const char* kDelAllConfCodeStr; // a magic string to confirm deletion of all files on the SD card |
uci1 | 27:efc4d654b139 | 39 | static const uint8_t kDelAllConfCodeLen; // the length of the magic string |
uci1 | 21:ce51bb0ba4a5 | 40 | |
uci1 | 21:ce51bb0ba4a5 | 41 | private: |
uci1 | 56:0bba0ef15697 | 42 | bool fSendingInHandshake; // true if we are sending files as a result of a handshake. |
uci1 | 56:0bba0ef15697 | 43 | // will ignore further handshake requests to send new files |
uci1 | 56:0bba0ef15697 | 44 | // in order to avoid a stack overflow |
uci1 | 56:0bba0ef15697 | 45 | |
uci1 | 56:0bba0ef15697 | 46 | |
uci1 | 21:ce51bb0ba4a5 | 47 | SnCommWin::ECommWinResult GetFilename(const uint32_t timeout, |
uci1 | 21:ce51bb0ba4a5 | 48 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 49 | const uint32_t namelen); |
uci1 | 21:ce51bb0ba4a5 | 50 | SnCommWin::ECommWinResult GetLocalFile(std::string fname, |
uci1 | 21:ce51bb0ba4a5 | 51 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 52 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 53 | const uint32_t timeout); |
uci1 | 21:ce51bb0ba4a5 | 54 | int16_t LoopLocalDirBinFiles(const bool doRemove, |
uci1 | 21:ce51bb0ba4a5 | 55 | const std::string& fname); |
uci1 | 21:ce51bb0ba4a5 | 56 | SnCommWin::ECommWinResult GetHeader(const uint32_t timeOut, |
uci1 | 21:ce51bb0ba4a5 | 57 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 58 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 59 | uint8_t& mcode, |
uci1 | 21:ce51bb0ba4a5 | 60 | uint32_t& mlen); |
uci1 | 21:ce51bb0ba4a5 | 61 | |
uci1 | 1:e392595b4b76 | 62 | |
uci1 | 3:24c5f0f50bf1 | 63 | protected: |
uci1 | 37:ff95e7070f26 | 64 | SnCommPeripheral* fComm; // the communication peripheral. deleted in dtor!! |
uci1 | 37:ff95e7070f26 | 65 | |
uci1 | 40:1324da35afd4 | 66 | virtual int32_t SendFileBlock(FILE* inf, |
uci1 | 40:1324da35afd4 | 67 | const uint8_t blockHeaderCode, |
uci1 | 40:1324da35afd4 | 68 | const uint32_t blockSize, |
uci1 | 40:1324da35afd4 | 69 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 70 | int32_t& bytesToSend, |
uci1 | 40:1324da35afd4 | 71 | const uint32_t timeout); |
uci1 | 12:d472f9811262 | 72 | |
uci1 | 40:1324da35afd4 | 73 | virtual int32_t SendFileContents(FILE* inf, |
uci1 | 40:1324da35afd4 | 74 | const SnConfigFrame& curConf, |
uci1 | 40:1324da35afd4 | 75 | SnEventFrame& evt, |
uci1 | 40:1324da35afd4 | 76 | SnPowerFrame& pow, |
uci1 | 40:1324da35afd4 | 77 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 78 | uint32_t nevts, |
uci1 | 40:1324da35afd4 | 79 | int32_t& bytesToBeSent, |
uci1 | 40:1324da35afd4 | 80 | const uint32_t timeout_clock); |
uci1 | 8:95a325df1f6b | 81 | |
uci1 | 37:ff95e7070f26 | 82 | public: |
uci1 | 37:ff95e7070f26 | 83 | SnCommWin(SnCommPeripheral* p); |
uci1 | 37:ff95e7070f26 | 84 | virtual ~SnCommWin(); |
uci1 | 12:d472f9811262 | 85 | |
uci1 | 37:ff95e7070f26 | 86 | // probably no need to overload |
uci1 | 40:1324da35afd4 | 87 | virtual bool TrySetSysTimeUnix(const uint32_t timeout, |
uci1 | 40:1324da35afd4 | 88 | uint32_t& prvTime, |
uci1 | 40:1324da35afd4 | 89 | uint32_t& setTime); |
uci1 | 37:ff95e7070f26 | 90 | virtual bool Connect(const uint32_t timeout); |
uci1 | 37:ff95e7070f26 | 91 | virtual bool CloseConn(const uint32_t timeout); |
uci1 | 40:1324da35afd4 | 92 | virtual bool PowerDown(const uint32_t timeout); |
uci1 | 1:e392595b4b76 | 93 | |
uci1 | 37:ff95e7070f26 | 94 | // optional overloads |
uci1 | 37:ff95e7070f26 | 95 | virtual void Set(const SnConfigFrame& conf) {} |
uci1 | 16:744ce85aede2 | 96 | |
uci1 | 37:ff95e7070f26 | 97 | // mandatory overloads |
uci1 | 37:ff95e7070f26 | 98 | virtual SnConfigFrame::EDatPackBit GetCommType() const=0; |
uci1 | 8:95a325df1f6b | 99 | |
uci1 | 1:e392595b4b76 | 100 | virtual ECommWinResult OpenWindow(const uint32_t timeout, |
uci1 | 1:e392595b4b76 | 101 | const bool sendStatus, |
uci1 | 1:e392595b4b76 | 102 | const SnConfigFrame& conf, |
uci1 | 1:e392595b4b76 | 103 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 104 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 105 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 106 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 107 | const float evtrate, |
uci1 | 56:0bba0ef15697 | 108 | const uint32_t powerOnTime, |
uci1 | 56:0bba0ef15697 | 109 | const SnTempFrame& temper, |
uci1 | 2:e67f7c158087 | 110 | char* const genBuf)=0; |
uci1 | 1:e392595b4b76 | 111 | |
uci1 | 27:efc4d654b139 | 112 | virtual bool GetDeleteAllConfirmCode(const SnConfigFrame& conf, |
uci1 | 27:efc4d654b139 | 113 | const uint32_t length, |
uci1 | 27:efc4d654b139 | 114 | const uint32_t timeout, |
uci1 | 27:efc4d654b139 | 115 | char* const buf, |
uci1 | 27:efc4d654b139 | 116 | const uint32_t bsize); |
uci1 | 21:ce51bb0ba4a5 | 117 | virtual ECommWinResult WaitHandshake(const SnConfigFrame& conf, |
uci1 | 21:ce51bb0ba4a5 | 118 | const uint32_t timeout, |
uci1 | 3:24c5f0f50bf1 | 119 | char* const buf, |
uci1 | 6:6f002d202f59 | 120 | const uint32_t bsize, |
uci1 | 27:efc4d654b139 | 121 | uint8_t& hndShkCode, |
uci1 | 27:efc4d654b139 | 122 | uint32_t* hndShkLen=0); |
uci1 | 40:1324da35afd4 | 123 | |
uci1 | 40:1324da35afd4 | 124 | virtual ECommWinResult HandleHandshake(FILE* inf, const char* infn, |
uci1 | 40:1324da35afd4 | 125 | const SnConfigFrame& curConf, |
uci1 | 40:1324da35afd4 | 126 | SnEventFrame& evt, |
uci1 | 40:1324da35afd4 | 127 | SnPowerFrame& pow, |
uci1 | 40:1324da35afd4 | 128 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 129 | const uint32_t bsize, |
uci1 | 40:1324da35afd4 | 130 | const uint32_t handshakeTimeout, |
uci1 | 40:1324da35afd4 | 131 | const uint8_t hndshk, |
uci1 | 40:1324da35afd4 | 132 | const uint32_t hndlen, |
uci1 | 40:1324da35afd4 | 133 | const uint32_t* nevts=0); |
uci1 | 40:1324da35afd4 | 134 | int32_t SendHndshkReq(char* const genBuf, |
uci1 | 40:1324da35afd4 | 135 | const uint32_t timeout_clock); |
uci1 | 3:24c5f0f50bf1 | 136 | |
uci1 | 41:d6f5e2f09e07 | 137 | ECommWinResult SendSignalStrength(char* const genBuf, |
uci1 | 41:d6f5e2f09e07 | 138 | SnSignalStrengthFrame& sigstr, |
uci1 | 41:d6f5e2f09e07 | 139 | const uint32_t timeout_clock); |
uci1 | 41:d6f5e2f09e07 | 140 | |
uci1 | 8:95a325df1f6b | 141 | ECommWinResult GetConfig(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 142 | const uint32_t timeOut, |
uci1 | 8:95a325df1f6b | 143 | char* const confBuf, |
uci1 | 8:95a325df1f6b | 144 | const uint32_t bsize); |
uci1 | 1:e392595b4b76 | 145 | |
uci1 | 8:95a325df1f6b | 146 | ECommWinResult SendStatus(const SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 147 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 148 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 149 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 150 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 151 | const float evtrate, |
uci1 | 56:0bba0ef15697 | 152 | const uint32_t powerOnTime, |
uci1 | 56:0bba0ef15697 | 153 | const SnTempFrame& temper, |
uci1 | 8:95a325df1f6b | 154 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 155 | const uint32_t timeout_clock); |
uci1 | 1:e392595b4b76 | 156 | |
uci1 | 23:ccf39298f205 | 157 | SnCommWin::ECommWinResult SendString(const char* str, |
uci1 | 23:ccf39298f205 | 158 | const uint32_t timeout); |
uci1 | 23:ccf39298f205 | 159 | |
uci1 | 40:1324da35afd4 | 160 | int32_t SendFilename(const char* fn, |
uci1 | 40:1324da35afd4 | 161 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 162 | int32_t& bytesToBeSent, |
uci1 | 40:1324da35afd4 | 163 | const uint32_t timeout_clock); |
uci1 | 6:6f002d202f59 | 164 | |
uci1 | 40:1324da35afd4 | 165 | ECommWinResult SendDataFromFile(FILE* inf, const char* infn, |
uci1 | 8:95a325df1f6b | 166 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 167 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 168 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 169 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 170 | const uint32_t bsize, |
uci1 | 8:95a325df1f6b | 171 | const uint32_t nevts, |
uci1 | 8:95a325df1f6b | 172 | const uint32_t timeout_clock, |
uci1 | 40:1324da35afd4 | 173 | uint8_t* hndcode=0, |
uci1 | 40:1324da35afd4 | 174 | uint32_t* hndlen=0); |
uci1 | 6:6f002d202f59 | 175 | |
uci1 | 8:95a325df1f6b | 176 | ECommWinResult SendData(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 177 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 178 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 179 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 180 | const uint32_t bsize, |
uci1 | 40:1324da35afd4 | 181 | const uint32_t timeout); |
uci1 | 18:55f1581f2ee4 | 182 | |
uci1 | 56:0bba0ef15697 | 183 | // assume little endian |
uci1 | 56:0bba0ef15697 | 184 | static |
uci1 | 56:0bba0ef15697 | 185 | uint16_t GetMinSeqFrom(const uint32_t hndshk) { |
uci1 | 56:0bba0ef15697 | 186 | // left-most 2 bytes |
uci1 | 56:0bba0ef15697 | 187 | return (hndshk>>16u); |
uci1 | 56:0bba0ef15697 | 188 | } |
uci1 | 56:0bba0ef15697 | 189 | static |
uci1 | 56:0bba0ef15697 | 190 | uint16_t GetMaxSeqFrom(const uint32_t hndshk) { |
uci1 | 56:0bba0ef15697 | 191 | // right-most 2 bytes |
uci1 | 56:0bba0ef15697 | 192 | return (hndshk&0xFFFF); |
uci1 | 56:0bba0ef15697 | 193 | } |
uci1 | 56:0bba0ef15697 | 194 | |
uci1 | 1:e392595b4b76 | 195 | }; |
uci1 | 1:e392595b4b76 | 196 | |
uci1 | 1:e392595b4b76 | 197 | #endif // SN_SnCommWin |