Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCommWin.h@41:d6f5e2f09e07, 2013-10-08 (annotated)
- Committer:
- uci1
- Date:
- Tue Oct 08 23:44:00 2013 +0000
- Revision:
- 41:d6f5e2f09e07
- Parent:
- 40:1324da35afd4
- Child:
- 56:0bba0ef15697
sbd only, debug on. send iridium signal strength. check first event even if cards off. make serial type explicit as Serial has no vtable. SBD comms: send buffered returns bytes sent out, use checksum of msg from modem, fix EmptyRxBuf, add checkSIgStr
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 | 1:e392595b4b76 | 13 | |
uci1 | 37:ff95e7070f26 | 14 | // DAQ station communication utilities |
uci1 | 1:e392595b4b76 | 15 | |
uci1 | 1:e392595b4b76 | 16 | class SnCommWin { |
uci1 | 1:e392595b4b76 | 17 | public: |
uci1 | 1:e392595b4b76 | 18 | enum ECommWinResult { |
uci1 | 1:e392595b4b76 | 19 | kUndefFail, // undefined fail type |
uci1 | 1:e392595b4b76 | 20 | kCanNotConnect, // unable to connect to port |
uci1 | 1:e392595b4b76 | 21 | kFailTimeout, // timed out but message required |
uci1 | 2:e67f7c158087 | 22 | kFailNoneSent, // none of the message sent |
uci1 | 1:e392595b4b76 | 23 | kFailPartSent, // only part of the message sent |
uci1 | 3:24c5f0f50bf1 | 24 | kUnexpectedRec, // unexpected / unhandled message received |
uci1 | 1:e392595b4b76 | 25 | kAllFails, // to be used for "if (ret > kAllFails) ==> success" |
uci1 | 1:e392595b4b76 | 26 | // only successes should go below |
uci1 | 1:e392595b4b76 | 27 | kConnected, // connection established, no messaging attempted |
uci1 | 27:efc4d654b139 | 28 | kOkStopComm, // received signal to stop communicating |
uci1 | 1:e392595b4b76 | 29 | kOkMsgSent, // message sent without waiting for "received" handshake |
uci1 | 1:e392595b4b76 | 30 | kOkNoMsg, // timed out with no message, but that is ok |
uci1 | 12:d472f9811262 | 31 | kOkWithMsg, // successfully received message |
uci1 | 40:1324da35afd4 | 32 | kOkWthMsgNoConf,// successfully received message and it says to stick with the same config |
uci1 | 40:1324da35afd4 | 33 | kOkWthMsgDidDel // successfully received message and deleted a file because of it |
uci1 | 1:e392595b4b76 | 34 | }; |
uci1 | 37:ff95e7070f26 | 35 | |
uci1 | 25:57b2627fe756 | 36 | static const char* kLocalDir; // the local mbed directory |
uci1 | 27:efc4d654b139 | 37 | static const char* kDelAllConfCodeStr; // a magic string to confirm deletion of all files on the SD card |
uci1 | 27:efc4d654b139 | 38 | static const uint8_t kDelAllConfCodeLen; // the length of the magic string |
uci1 | 21:ce51bb0ba4a5 | 39 | |
uci1 | 21:ce51bb0ba4a5 | 40 | private: |
uci1 | 21:ce51bb0ba4a5 | 41 | SnCommWin::ECommWinResult GetFilename(const uint32_t timeout, |
uci1 | 21:ce51bb0ba4a5 | 42 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 43 | const uint32_t namelen); |
uci1 | 21:ce51bb0ba4a5 | 44 | SnCommWin::ECommWinResult GetLocalFile(std::string fname, |
uci1 | 21:ce51bb0ba4a5 | 45 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 46 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 47 | const uint32_t timeout); |
uci1 | 21:ce51bb0ba4a5 | 48 | int16_t LoopLocalDirBinFiles(const bool doRemove, |
uci1 | 21:ce51bb0ba4a5 | 49 | const std::string& fname); |
uci1 | 21:ce51bb0ba4a5 | 50 | SnCommWin::ECommWinResult GetHeader(const uint32_t timeOut, |
uci1 | 21:ce51bb0ba4a5 | 51 | char* const buf, |
uci1 | 21:ce51bb0ba4a5 | 52 | const uint32_t bsize, |
uci1 | 21:ce51bb0ba4a5 | 53 | uint8_t& mcode, |
uci1 | 21:ce51bb0ba4a5 | 54 | uint32_t& mlen); |
uci1 | 21:ce51bb0ba4a5 | 55 | |
uci1 | 1:e392595b4b76 | 56 | |
uci1 | 3:24c5f0f50bf1 | 57 | protected: |
uci1 | 37:ff95e7070f26 | 58 | SnCommPeripheral* fComm; // the communication peripheral. deleted in dtor!! |
uci1 | 37:ff95e7070f26 | 59 | |
uci1 | 40:1324da35afd4 | 60 | virtual int32_t SendFileBlock(FILE* inf, |
uci1 | 40:1324da35afd4 | 61 | const uint8_t blockHeaderCode, |
uci1 | 40:1324da35afd4 | 62 | const uint32_t blockSize, |
uci1 | 40:1324da35afd4 | 63 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 64 | int32_t& bytesToSend, |
uci1 | 40:1324da35afd4 | 65 | const uint32_t timeout); |
uci1 | 12:d472f9811262 | 66 | |
uci1 | 40:1324da35afd4 | 67 | virtual int32_t SendFileContents(FILE* inf, |
uci1 | 40:1324da35afd4 | 68 | const SnConfigFrame& curConf, |
uci1 | 40:1324da35afd4 | 69 | SnEventFrame& evt, |
uci1 | 40:1324da35afd4 | 70 | SnPowerFrame& pow, |
uci1 | 40:1324da35afd4 | 71 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 72 | uint32_t nevts, |
uci1 | 40:1324da35afd4 | 73 | int32_t& bytesToBeSent, |
uci1 | 40:1324da35afd4 | 74 | const uint32_t timeout_clock); |
uci1 | 8:95a325df1f6b | 75 | |
uci1 | 37:ff95e7070f26 | 76 | public: |
uci1 | 37:ff95e7070f26 | 77 | SnCommWin(SnCommPeripheral* p); |
uci1 | 37:ff95e7070f26 | 78 | virtual ~SnCommWin(); |
uci1 | 12:d472f9811262 | 79 | |
uci1 | 37:ff95e7070f26 | 80 | // probably no need to overload |
uci1 | 40:1324da35afd4 | 81 | virtual bool TrySetSysTimeUnix(const uint32_t timeout, |
uci1 | 40:1324da35afd4 | 82 | uint32_t& prvTime, |
uci1 | 40:1324da35afd4 | 83 | uint32_t& setTime); |
uci1 | 37:ff95e7070f26 | 84 | virtual bool Connect(const uint32_t timeout); |
uci1 | 37:ff95e7070f26 | 85 | virtual bool CloseConn(const uint32_t timeout); |
uci1 | 40:1324da35afd4 | 86 | virtual bool PowerDown(const uint32_t timeout); |
uci1 | 1:e392595b4b76 | 87 | |
uci1 | 37:ff95e7070f26 | 88 | // optional overloads |
uci1 | 37:ff95e7070f26 | 89 | virtual void Set(const SnConfigFrame& conf) {} |
uci1 | 16:744ce85aede2 | 90 | |
uci1 | 37:ff95e7070f26 | 91 | // mandatory overloads |
uci1 | 37:ff95e7070f26 | 92 | virtual SnConfigFrame::EDatPackBit GetCommType() const=0; |
uci1 | 8:95a325df1f6b | 93 | |
uci1 | 1:e392595b4b76 | 94 | virtual ECommWinResult OpenWindow(const uint32_t timeout, |
uci1 | 1:e392595b4b76 | 95 | const bool sendStatus, |
uci1 | 1:e392595b4b76 | 96 | const SnConfigFrame& conf, |
uci1 | 1:e392595b4b76 | 97 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 98 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 99 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 100 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 101 | const float evtrate, |
uci1 | 2:e67f7c158087 | 102 | char* const genBuf)=0; |
uci1 | 1:e392595b4b76 | 103 | |
uci1 | 27:efc4d654b139 | 104 | virtual bool GetDeleteAllConfirmCode(const SnConfigFrame& conf, |
uci1 | 27:efc4d654b139 | 105 | const uint32_t length, |
uci1 | 27:efc4d654b139 | 106 | const uint32_t timeout, |
uci1 | 27:efc4d654b139 | 107 | char* const buf, |
uci1 | 27:efc4d654b139 | 108 | const uint32_t bsize); |
uci1 | 21:ce51bb0ba4a5 | 109 | virtual ECommWinResult WaitHandshake(const SnConfigFrame& conf, |
uci1 | 21:ce51bb0ba4a5 | 110 | const uint32_t timeout, |
uci1 | 3:24c5f0f50bf1 | 111 | char* const buf, |
uci1 | 6:6f002d202f59 | 112 | const uint32_t bsize, |
uci1 | 27:efc4d654b139 | 113 | uint8_t& hndShkCode, |
uci1 | 27:efc4d654b139 | 114 | uint32_t* hndShkLen=0); |
uci1 | 40:1324da35afd4 | 115 | |
uci1 | 40:1324da35afd4 | 116 | virtual ECommWinResult HandleHandshake(FILE* inf, const char* infn, |
uci1 | 40:1324da35afd4 | 117 | const SnConfigFrame& curConf, |
uci1 | 40:1324da35afd4 | 118 | SnEventFrame& evt, |
uci1 | 40:1324da35afd4 | 119 | SnPowerFrame& pow, |
uci1 | 40:1324da35afd4 | 120 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 121 | const uint32_t bsize, |
uci1 | 40:1324da35afd4 | 122 | const uint32_t handshakeTimeout, |
uci1 | 40:1324da35afd4 | 123 | const uint8_t hndshk, |
uci1 | 40:1324da35afd4 | 124 | const uint32_t hndlen, |
uci1 | 40:1324da35afd4 | 125 | const uint32_t* nevts=0); |
uci1 | 40:1324da35afd4 | 126 | int32_t SendHndshkReq(char* const genBuf, |
uci1 | 40:1324da35afd4 | 127 | const uint32_t timeout_clock); |
uci1 | 3:24c5f0f50bf1 | 128 | |
uci1 | 41:d6f5e2f09e07 | 129 | ECommWinResult SendSignalStrength(char* const genBuf, |
uci1 | 41:d6f5e2f09e07 | 130 | SnSignalStrengthFrame& sigstr, |
uci1 | 41:d6f5e2f09e07 | 131 | const uint32_t timeout_clock); |
uci1 | 41:d6f5e2f09e07 | 132 | |
uci1 | 8:95a325df1f6b | 133 | ECommWinResult GetConfig(SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 134 | const uint32_t timeOut, |
uci1 | 8:95a325df1f6b | 135 | char* const confBuf, |
uci1 | 8:95a325df1f6b | 136 | const uint32_t bsize); |
uci1 | 1:e392595b4b76 | 137 | |
uci1 | 8:95a325df1f6b | 138 | ECommWinResult SendStatus(const SnConfigFrame& conf, |
uci1 | 8:95a325df1f6b | 139 | const SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 140 | const SnPowerFrame& pow, |
uci1 | 10:3c93db1cfb12 | 141 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 142 | const float thmrate, |
uci1 | 10:3c93db1cfb12 | 143 | const float evtrate, |
uci1 | 8:95a325df1f6b | 144 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 145 | const uint32_t timeout_clock); |
uci1 | 1:e392595b4b76 | 146 | |
uci1 | 23:ccf39298f205 | 147 | SnCommWin::ECommWinResult SendString(const char* str, |
uci1 | 23:ccf39298f205 | 148 | const uint32_t timeout); |
uci1 | 23:ccf39298f205 | 149 | |
uci1 | 40:1324da35afd4 | 150 | int32_t SendFilename(const char* fn, |
uci1 | 40:1324da35afd4 | 151 | char* const genBuf, |
uci1 | 40:1324da35afd4 | 152 | int32_t& bytesToBeSent, |
uci1 | 40:1324da35afd4 | 153 | const uint32_t timeout_clock); |
uci1 | 6:6f002d202f59 | 154 | |
uci1 | 40:1324da35afd4 | 155 | ECommWinResult SendDataFromFile(FILE* inf, const char* infn, |
uci1 | 8:95a325df1f6b | 156 | const SnConfigFrame& curConf, |
uci1 | 8:95a325df1f6b | 157 | SnEventFrame& evt, |
uci1 | 8:95a325df1f6b | 158 | SnPowerFrame& pow, |
uci1 | 8:95a325df1f6b | 159 | char* const genBuf, |
uci1 | 8:95a325df1f6b | 160 | const uint32_t bsize, |
uci1 | 8:95a325df1f6b | 161 | const uint32_t nevts, |
uci1 | 8:95a325df1f6b | 162 | const uint32_t timeout_clock, |
uci1 | 40:1324da35afd4 | 163 | uint8_t* hndcode=0, |
uci1 | 40:1324da35afd4 | 164 | uint32_t* hndlen=0); |
uci1 | 6:6f002d202f59 | 165 | |
uci1 | 8:95a325df1f6b | 166 | ECommWinResult SendData(SnConfigFrame& conf, |
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 | 40:1324da35afd4 | 171 | const uint32_t timeout); |
uci1 | 18:55f1581f2ee4 | 172 | |
uci1 | 1:e392595b4b76 | 173 | }; |
uci1 | 1:e392595b4b76 | 174 | |
uci1 | 1:e392595b4b76 | 175 | #endif // SN_SnCommWin |