Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnCommAfarTCP.cpp
- Revision:
- 4:a91682e19d6b
- Parent:
- 3:24c5f0f50bf1
- Child:
- 5:9cea89700c66
--- a/SnCommAfarTCP.cpp Tue Jul 31 04:59:16 2012 +0000 +++ b/SnCommAfarTCP.cpp Thu Aug 02 05:42:47 2012 +0000 @@ -1,8 +1,9 @@ /* #include "SnCommAfarTCP.h" -SnCommAfarTCP::SnCommAfarTCP(char* const b64buf, const uint32_t bblen) : - fB64buf(b64buf), fbblen(bblen), fRmtServ(remote), +SnCommAfarTCP::SnCommAfarTCP(const bool useb64, + char* const b64buf, const uint32_t bblen) : + fUseB64(useb64), fB64buf(b64buf), fbblen(bblen), fRmtServ(remote), fEth(new EthernetInterface), fSock(new TCPSocketConnection) { fEth->init("128.195.204.148", // my IP @@ -19,14 +20,29 @@ delete fSock; } +int SnCommAfarTCP::Receive(char* const buf, const uin32_t mlen, + const uint32_t bsize, + const uint32_t timeout_clock) { + +} + int SnCommAfarTCP::SendAll(const char* const data, const uint32_t length, const uint32_t timeout_clock) { - const char* dd = data; int res=0; uint32_t b=0; while ( (length>b) && (time(0)<timeout_clock) ) { - res = fSock-> + res = fSock->send_all(data+b, length-b); + switch (res) { + case -1: + // TODO: how to check the error? + continue; + case 0: + return res; + default: + b += res; + }; } + return res; // timeout } @@ -62,4 +78,26 @@ return ret; } + +SnCommWin::ECommWinResult SnCommAfarTCP::WaitHandshake(const uint32_t timeout, + char* const buf, + const uint32_t bsize) { + printf("WaitHandshake, to=%u\r\n",timeout); + + uint32_t mlen=0; // this message length + const bool rd = Receive(buf, mlen, bsize, timeout, fB64buf, fbblen); + if (rd) { + uint32_t msgLen=0; + uint8_t msgCode=0; + const char* b = buf; + SnHeaderFrame::ReadFrom(b, msgCode, msgLen); + if (msgCode==SnHeaderFrame::kHandshakeCode) { + return SnCommWin::kOkWithMsg; + } else { + // TODO: somehow handle unexpected message? + return SnCommWin::kUnexpectedRec; + } + } + return SnCommWin::kOkNoMsg; +} */ \ No newline at end of file