Changeset 114

Show
Ignore:
Timestamp:
12/11/07 04:18:09 (13 months ago)
Author:
follower
Message:

Add 'available()' method to connection to match 'Serial.available()'. Change 'read()' method to match behaviour of 'Serial.read()'. Document some of this. Print bytes received from the demo to the console.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/follower/wiz810mj/src/demo/WizDemo4/WizDemo4.pde

    r113 r114  
    227227    int listen(); 
    228228    int isConnected(); 
     229    int available(); 
    229230    int read(); 
    230231    void NetworkConnection::close(); 
     
    250251} 
    251252 
     253int NetworkConnection::available() { 
     254  /* 
     255   
     256    Functionality matches 'Serial.available()'. 
     257 
     258    Note: If the socket is not connected then this will return 0, 
     259          but it is intended that 'isConnected()' would be checked first. 
     260 
     261    Returns: 
     262      "The number of bytes available to read ... or 0 if none are available. 
     263      If any data has come in, [...].available() will be greater than 0." 
     264 
     265   */ 
     266   // TODO: Do we want to check for 'isConnected' as well, or not? 
     267   //       We have to, I guess, for valid behaviour with 'getSn_*'. 
     268   if (!isConnected()) { 
     269     return 0; 
     270   } 
     271    
     272   return getSn_RX_RSR(_socket); 
     273} 
     274 
     275#define NO_READ_DATA_AVAILABLE -1 
     276 
    252277int NetworkConnection::read() { 
    253278  /* 
     279   
     280     Functionality matches 'Serial.read()'. 
     281 
     282     Returns: 
     283       "an int, the first byte of incoming serial data available 
     284        (or -1 if no data is available)." 
     285 
    254286 
    255287     Note: I thought 'recv' blocked until data was available, 
     
    262294   */ 
    263295  uint8_t theByte; 
     296 
     297  if (!available()) { 
     298    return NO_READ_DATA_AVAILABLE; 
     299  } 
     300   
    264301  recv(_socket, &theByte, 1); 
    265302  return theByte;     
     
    403440   
    404441  Serial.println("Connected..."); 
     442 
     443  while (conn.isConnected()) { 
     444     if (conn.available()) { 
     445       Serial.print(conn.read(), BYTE); 
     446     }  
     447  } 
     448   
     449  Serial.println(""); 
    405450 
    406451  conn.close();