diff --git a/branches/follower/wiz810mj/src/demo/WizDemo4/WizDemo4.pde b/branches/follower/wiz810mj/src/demo/WizDemo4/WizDemo4.pde index 1796a11..842f7e5 100644 --- a/branches/follower/wiz810mj/src/demo/WizDemo4/WizDemo4.pde +++ b/branches/follower/wiz810mj/src/demo/WizDemo4/WizDemo4.pde @@ -226,6 +226,7 @@ class NetworkConnection { // Essentially a Socket wrapper int listen(); int isConnected(); + int available(); int read(); void NetworkConnection::close(); @@ -249,8 +250,39 @@ int NetworkConnection::listen() { // TODO: Make private or protected? return !!::listen(_socket); // TODO: Use C++ namespaces for the driver functions? } +int NetworkConnection::available() { + /* + + Functionality matches 'Serial.available()'. + + Note: If the socket is not connected then this will return 0, + but it is intended that 'isConnected()' would be checked first. + + Returns: + "The number of bytes available to read ... or 0 if none are available. + If any data has come in, [...].available() will be greater than 0." + + */ + // TODO: Do we want to check for 'isConnected' as well, or not? + // We have to, I guess, for valid behaviour with 'getSn_*'. + if (!isConnected()) { + return 0; + } + + return getSn_RX_RSR(_socket); +} + +#define NO_READ_DATA_AVAILABLE -1 + int NetworkConnection::read() { /* + + Functionality matches 'Serial.read()'. + + Returns: + "an int, the first byte of incoming serial data available + (or -1 if no data is available)." + Note: I thought 'recv' blocked until data was available, but it currently seems not to block after all. @@ -261,6 +293,11 @@ int NetworkConnection::read() { */ uint8_t theByte; + + if (!available()) { + return NO_READ_DATA_AVAILABLE; + } + recv(_socket, &theByte, 1); return theByte; } @@ -403,6 +440,14 @@ void setup () { Serial.println("Connected..."); + while (conn.isConnected()) { + if (conn.available()) { + Serial.print(conn.read(), BYTE); + } + } + + Serial.println(""); + conn.close(); Serial.println("End test and dummy loop");