NetServices

This documentation is for the Segundo Equipo version of the NetServices library.

Import libraryNetServices

This library is based on Donatien's source V1.04 (5 August 2010).

The following improvements and bug fixes are made:

#pragma diag_remark directives are added to the following files to turn compiler warnings into remarks (which are not normally displayed)

  • EthernetNetIf.cpp
  • lwipNetUdpSocket.cpp
  • igmp.c
  • mem.c
  • RPCHandler.cpp
  • MySQLClient.cpp
  • NTPClient.cpp

base64.h

  • fixed bug that prevented Base64::encode from working with a string with embedded null characters
  • required for authentication in SMTPClient

EmailMessage.cpp / .h

  • renamed from emailMessage.cpp / .h
  • updated from non-compiling sample
  • bug fixes and additional methods
  • changed recipients list from queue to vector for non-destructive send
  • to be used with SMTPClient (see further down)

    Import library

    Public Member Functions

      EmailMessage ()
      Instantiates the email message.
      ~EmailMessage ()
      Destructor for the email message.
    void  setFrom (const char *from)
      Set FROM address.
    void  addTo (const char *to)
      Add TO address to list of recipient addresses.
    void  clearTo ()
      Clear TO addresses.
    int  printf (const char *format,...)
      Append text to content of message using printf.
    void  clearContent ()
      Clear content previously appended by printf.

    Friends

    class  SMTPClient

eth_drv.cpp / .h

  • only creates Ethernet object if required (init may be called without previous call to eth_free)
  • add method to allow access to Ethernet object pointer (may be null if not initialised)

Ethernet* eth_interface();

EthernetNetIf.cpp / .h

  • implemented getHwAddr() method to return array containing hardware address
  • turn off debug (uncomment line 34 in .cpp if required), IP address can be printed instead using getIp() method and hardware address using getHwAddr()

IpAddr ethIp = eth.getIp();
printf("Connected ok, IP : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
const char* hwAddr = eth.getHwAddr();
printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n",
   hwAddr[0], hwAddr[1], hwAddr[2],
   hwAddr[3], hwAddr[4], hwAddr[5]);
  • optional hostname in DHCP constructor

// set hostname ready for DHCP
EthernetNetIf eth("mbedSE");

Import library

Public Member Functions

  EthernetNetIf (const char *hostname=NULL)
  Instantiates the Interface and register it against the stack, DHCP will be used.
  EthernetNetIf ( IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns)
  Instantiates the Interface and register it against the stack, DHCP will not be used.
EthernetErr   setup (int timeout_ms=15000)
  Brings the interface up.
const char *  getHwAddr () const
  Returns an array containing the hardware address.
const char *  getHostname () const
  Returns a pointer to the hostname set in the constructor.
IpAddr   getIp () const
  Returns the IP of the interface once it's connected.
  • allow setup to be called multiple times by deleting and recreating network objects if previously setup
    • dhcp structure creation is moved to EthernetNetIf (to avoid memory leak) and passed to netif using dhcp_set_struct()
    • designed to be used so that setup can be called until successful as in the code sample below
    • note that behaviour when calling setup after a previous successful call is undefined

#define HOSTNAME "mbedSE"
EthernetNetIf eth(HOSTNAME);
EthernetErr ethErr;
do {
    printf("Setting up...\n");
    ethErr = eth.setup();
    if (ethErr) printf("Timeout\n", ethErr);
} while (ethErr != ETH_OK);

mem.c

  • added MEM_POSITION to ram_heap

memp.c

  • added MEM_POSITION to memp
  • added MEM_POSITION to memp_bases
  • added MEM_POSITION to memp_memory

lwipopts.h

  • turned off SIO_FIFO_DEBUG and TCPDUMP_DEBUG
  • defined LWIP_NETIF_HOSTNAME in DHCP options section

Warning

MEM_POSITION becomes effective (due to mem.c and memp.c changes) and is defined as AHBSRAM1 (not AHBSRAM0)

lwipopts2.h

  • deleted (not used)

netCfg.h

  • disabled all options apart from NET_ETH and NET_LWIP_STACK

NTPClient.cpp

  • modified code (line 150) so that time is adjusted to limit offset range only if necessary (otherwise unconditional adjustment to end of July 2010 is undesirable since NTP could subsequently fail)

if ((int)time(NULL) < 1280000000) set_time( 1280000000 ); //End of July 2010... just there to limit offset range

RPCHandler.cpp

  • modified cleanReq method to decode URLs (not just space and +) using url_decode already available in url.h

#include "url.h"
...
void RPCHandler::cleanReq(char* data)
{
    char* decoded = url_decode(data);
    strcpy(data, decoded);
    free(decoded);
/*    
  char* p;
  static const char* lGarbage[2] = {"%20", "+"};
  for(int i = 0; i < 2; i++)
  {
    while( p = strstr(data, lGarbage[i]) )
    {
      memset((void*) p, ' ', strlen(lGarbage[i]));
    }
  }
*/  
}

SMTPClient.cpp / .h

timers.c

  • reset next_timeout pointer on initialise (allows EthernetNetIf::setup to be called more than once)

void sys_timeouts_init(void)
{
  next_timeout = NULL;
...