MBED implementation of JAudioStream
Diff: JAudioStream.cpp
- Revision:
- 7:9dfba830a0c8
- Parent:
- 6:7e366261cd93
- Child:
- 8:65d8e8882907
diff -r 7e366261cd93 -r 9dfba830a0c8 JAudioStream.cpp --- a/JAudioStream.cpp Wed Aug 19 09:04:41 2015 +0000 +++ b/JAudioStream.cpp Wed Aug 19 15:38:05 2015 +0000 @@ -1,4 +1,5 @@ #include "JAudioStream.h" +#define LOG_LEVEL_INFO #include "logger.h" JAudioStream::JAudioStream() { @@ -18,7 +19,7 @@ eth.init(); eth.connect(); socket.init(); - socket.set_blocking(true); + socket.set_blocking(false, 500); remotePort = port; remoteIp = ip; endPoint.set_address(ip, port); @@ -30,8 +31,10 @@ bool JAudioStream::read(char *buffer, int size) { TRACE("Received %s", buffer); - socket.receiveFrom(endPoint, buffer, size); - return true; + if (socket.receiveFrom(endPoint, buffer, size)) { + return true; + } + return false; } bool JAudioStream::isConnected() { @@ -96,20 +99,22 @@ void JAudioStream::receive() { char resp[MAX_PACKT]; - if (read(resp, MAX_PACKT)) { - if (memcmp(resp, cond, 4) == 0) { - connected = true; - } else if (memcmp(resp, dctd, 4) == 0) { - connected = false; - } else if (memcmp(resp, hrbt, 4) == 0) { - char message[MESSAGE_SIZE]; - buildMeassge(hrbt, -1, message); - send(message, MESSAGE_SIZE); - } else if (memcmp(resp, begn, 4) == 0) { - memmove(&nowPlaying[0], &resp[4], 20); - inTransmission = true; - } else if (memcmp(resp, comt, 4) == 0) { - inTransmission = false; - } - } + //if (!inTransmission) { + if (read(resp, MAX_PACKT)) { + if (memcmp(resp, cond, 4) == 0) { + connected = true; + } else if (memcmp(resp, dctd, 4) == 0) { + connected = false; + } else if (memcmp(resp, hrbt, 4) == 0) { + char message[MESSAGE_SIZE]; + buildMeassge(hrbt, -1, message); + send(message, MESSAGE_SIZE); + } else if (memcmp(resp, begn, 4) == 0) { + memmove(&nowPlaying[0], &resp[4], 20); + inTransmission = true; + } else if (memcmp(resp, comt, 4) == 0) { + inTransmission = false; + } + } + //} }