Show
Ignore:
Timestamp:
08/05/08 21:23:15 (5 months ago)
Author:
liamstask
Message:

- shuffle network documentation
- remove can.c from build list in Heavy Makefile

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • firmware/trunk/core/makingthings/network.c

    r763 r781  
    939939 
    940940/** 
    941   Set whether the demo webserver is enabled. 
    942   The demo webserver provides access to some of the Make Controller's stats via a 
    943   standard web browser.  It is intended mainly as a reference for creating web based applications. 
    944    
    945   This value is stored persistently, so it will remain constant across system reboots. 
    946   @param state An integer specifying whether to enable the webserver - 1 (enable) or 0 (disable). 
    947 */ 
    948 //void Network_SetWebServerEnabled( int state ) 
    949 //{ 
    950 //  if( state ) 
    951 //  { 
    952 //    Network_StartWebServer( ); 
    953 // 
    954 //    if( !Network_GetWebServerEnabled( ) ) 
    955 //      Eeprom_Write( EEPROM_WEBSERVER_ENABLED, (uchar*)&state, 4 ); 
    956 //  } 
    957 //  else 
    958 //  { 
    959 //    Network_StopWebServer( ); 
    960 // 
    961 //    if( Network_GetWebServerEnabled( ) ) 
    962 //      Eeprom_Write( EEPROM_WEBSERVER_ENABLED, (uchar*)&state, 4 ); 
    963 //  } 
    964 //} 
    965  
    966 /** 
    967   Read whether the demo webserver is enabled. 
    968   This value is stored presistently, so it will be the same across system reboots. 
    969   @return An integer specifying whether the webserver is enabled - 1 (enabled) or 0 (disabled). 
    970 */ 
    971 //int Network_GetWebServerEnabled( ) 
    972 //{ 
    973 //  int state; 
    974 //  Eeprom_Read( EEPROM_WEBSERVER_ENABLED, (uchar*)&state, 4 ); 
    975 //  return (state == 1) ? 1 : 0; 
    976 //} 
     941  Resolve the IP address for a given host name. 
     942  Up to 4 DNS entries are cached, so if you make successive calls to this function,  
     943  you won't incur a whole lookup roundtrip - you'll just get the cached value. 
     944  The cached values are maintained internally, so if one of them becomes invalid, a 
     945  new lookup will be fired off the next time it's asked for. 
     946  @param name A string specifying the name of the host to look up. 
     947  @return An integer representation of the IP address of the host.  This can be  
     948  passed to the \ref Sockets functions to read and write.  Returns -1 on error. 
     949 
     950  \b Example 
     951  \code 
     952  // try to open a socket connection to makingthings.com 
     953  int addr = Network_DnsGetHostByName("makingthings.com"); 
     954  struct netconn* socket = Socket(addr, 80); // open up a new connection to that address 
     955  \endcode 
     956*/ 
     957int Network_DnsGetHostByName( const char *name ) 
     958{ 
     959  struct ip_addr addr; 
     960  int retval = -1; 
     961  if(!Network_DnsSemaphore) 
     962  { 
     963    Network_DnsSemaphore = SemaphoreCreate(); 
     964    if(!Network_DnsSemaphore) // the semaphore was not created successfully 
     965      return retval; 
     966    if(!SemaphoreTake(Network_DnsSemaphore, 0)) // do the initial take 
     967      return retval; 
     968  } 
     969  err_t result = dns_gethostbyname( name, &addr, Network_DnsCallback, 0); 
     970  if(result == ERR_OK) // the result was cached, just return it 
     971    retval = addr.addr; 
     972  else if(result == ERR_INPROGRESS) // a lookup is in progress - wait for the callback to signal that we've gotten a response 
     973  { 
     974    if(SemaphoreTake(Network_DnsSemaphore, 30000)) // timeout is 30 seconds by default 
     975      retval = Network->DnsResolvedAddress; 
     976  } 
     977  return ntohl(retval); 
     978} 
     979 
     980// static 
     981/* 
     982  The callback for a DNS look up.  The original request is waiting (via semaphore) on 
     983  this to pop the looked up address in the right spot. 
     984*/ 
     985void Network_DnsCallback(const char *name, struct ip_addr *addr, void *arg) 
     986{ 
     987  LWIP_UNUSED_ARG(arg); 
     988  LWIP_UNUSED_ARG(name); 
     989  if(addr) 
     990    Network->DnsResolvedAddress = addr->addr; 
     991  else 
     992    Network->DnsResolvedAddress = -1; // we didn't get an address, stuff an error value in there 
     993  SemaphoreGive(Network_DnsSemaphore); 
     994} 
    977995 
    978996/** @} 
     
    11511169} 
    11521170 
    1153 //void Network_StartWebServer( ) 
    1154 //{ 
    1155 //  WebServer_SetActive( 1 ); 
    1156 //} 
    1157 // 
    1158 //void Network_StopWebServer( ) 
    1159 //{ 
    1160 //  WebServer_SetActive( 0 ); 
    1161 //} 
    1162  
    11631171void Network_DhcpStart( struct netif* netif ) 
    11641172{ 
     
    11911199  return; 
    11921200} 
    1193  
    1194 /** 
    1195   Resolve the IP address for a given host name. 
    1196   Up to 4 DNS entries are cached, so if you make successive calls to this function,  
    1197   you won't incur a whole lookup roundtrip - you'll just get the cached value. 
    1198   The cached values are maintained internally, so if one of them becomes invalid, a 
    1199   new lookup will be fired off the next time it's asked for. 
    1200   @param name A string specifying the name of the host to look up. 
    1201   @return An integer representation of the IP address of the host.  This can be  
    1202   passed to the \ref Sockets functions to read and write.  Returns -1 on error. 
    1203  
    1204   \b Example 
    1205   \code 
    1206   // try to open a socket connection to makingthings.com 
    1207   int addr = Network_DnsGetHostByName("makingthings.com"); 
    1208   struct netconn* socket = Socket(addr, 80); // open up a new connection to that address 
    1209   \endcode 
    1210 */ 
    1211 int Network_DnsGetHostByName( const char *name ) 
    1212 { 
    1213   struct ip_addr addr; 
    1214   int retval = -1; 
    1215   if(!Network_DnsSemaphore) 
    1216   { 
    1217     Network_DnsSemaphore = SemaphoreCreate(); 
    1218     if(!Network_DnsSemaphore) // the semaphore was not created successfully 
    1219       return retval; 
    1220     if(!SemaphoreTake(Network_DnsSemaphore, 0)) // do the initial take 
    1221       return retval; 
    1222   } 
    1223   err_t result = dns_gethostbyname( name, &addr, Network_DnsCallback, 0); 
    1224   if(result == ERR_OK) // the result was cached, just return it 
    1225     retval = addr.addr; 
    1226   else if(result == ERR_INPROGRESS) // a lookup is in progress - wait for the callback to signal that we've gotten a response 
    1227   { 
    1228     if(SemaphoreTake(Network_DnsSemaphore, 30000)) // timeout is 30 seconds by default 
    1229       retval = Network->DnsResolvedAddress; 
    1230   } 
    1231   return ntohl(retval); 
    1232 } 
    1233  
    1234 // static 
    1235 /* 
    1236   The callback for a DNS look up.  The original request is waiting (via semaphore) on 
    1237   this to pop the looked up address in the right spot. 
    1238 */ 
    1239 void Network_DnsCallback(const char *name, struct ip_addr *addr, void *arg) 
    1240 { 
    1241   LWIP_UNUSED_ARG(arg); 
    1242   LWIP_UNUSED_ARG(name); 
    1243   if(addr) 
    1244     Network->DnsResolvedAddress = addr->addr; 
    1245   else 
    1246     Network->DnsResolvedAddress = -1; // we didn't get an address, stuff an error value in there 
    1247   SemaphoreGive(Network_DnsSemaphore); 
    1248 } 
    1249  
    12501201 
    12511202int Network_AddressConvert( char* address, int* a0, int* a1, int* a2, int* a3 )