Show
Ignore:
Timestamp:
12/07/07 04:40:54 (13 months ago)
Author:
follower
Message:

Now we've copied xSmurf's PROGMEM and other changes to his branch we'll back them out from here for now as they require SPrint from cral which we don't yet supply by default (this caused problems for people trying out the code in its current state.).

Files:
1 modified

Legend:

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

    r69 r72  
    55  See: 
    66 
    7    <http://code.rancidbacon.com/LearningAboutArduinoWIZ810MJ>    
     7     <http://code.rancidbacon.com/LearningAboutArduinoWIZ810MJ>      
    88 
    99  Current features: 
    1010   
    11     * Initial W5100 driver port: 
    12     
    13       + new-style network configuration 
     11      * Initial W5100 driver port: 
     12      
     13          + new-style network configuration 
     14           
     15          + socket creation/listening/closing 
     16           
     17          + Sending/Receiving okay 
     18           
     19          + example "echo" server (no longer) 
     20           
     21          + example "web server" with LED flash. 
     22 
     23      * Terrible hacked-together code 
     24 
     25  Author: 
     26 
     27     follower@rancidbacon.com 
    1428       
    15       + socket creation/listening/closing 
    16        
    17       + Sending/Receiving okay 
    18        
    19       + example "echo" server (no longer) 
    20        
    21       + example "web server" with LED flash. 
    22  
    23     * Terrible hacked-together code 
    24  
    25   Author: 
    26  
    27    follower@rancidbacon.com 
    28      
    2929  License: 
    30    
    31    LGPL 
    32     
     30     
     31     LGPL 
     32      
    3333  Version: 
    3434   
    35    20071106-0005+ 
    36     
     35     20071106-0005+ 
     36      
    3737*/ 
    3838 
    3939#include <WIZ810MJ.h> 
    40 #include <SPrint/staticPrint.h> 
     40 
    4141 
    4242 
     
    5757  /* 
    5858 
    59    Configure pins and registers required for SPI communication. 
     59     Configure pins and registers required for SPI communication. 
    6060   
    6161  */ 
     
    7070   
    7171  /* 
    72    Configure SPI Control Register (SPCR) (All values initially 0) 
    73     Bit  Description 
    74     7  SPI Interrupt Enable    -- disable  (SPIE --> 0) 
    75     6  SPI Enable        -- enable   (SPE  --> 1) 
    76     5  Data Order        -- MSB 1st  (DORD --> 0) (Slave specific) 
    77     4  Master/Slave Select     -- master   (MSTR --> 1) 
    78     3  Clock Polarity      --      (CPOL --> 0) (Slave specific) ("Mode") 
    79     2  Clock Phase         --      (CPHA --> 0) (Slave specific) 
    80     1  SPI Clock Rate Select 1 -- }      (SPR1 --> 0)  
    81     0  SPI Clock Rate Select 0 -- } fOSC/4 (SPR0 --> 0) ("Fastest" but see SPI2X in SPSR) 
     72     Configure SPI Control Register (SPCR) (All values initially 0) 
     73      Bit  Description 
     74        7  SPI Interrupt Enable    -- disable  (SPIE --> 0) 
     75        6  SPI Enable              -- enable   (SPE  --> 1) 
     76        5  Data Order              -- MSB 1st  (DORD --> 0) (Slave specific) 
     77        4  Master/Slave Select     -- master   (MSTR --> 1) 
     78        3  Clock Polarity          --          (CPOL --> 0) (Slave specific) ("Mode") 
     79        2  Clock Phase             --          (CPHA --> 0) (Slave specific) 
     80        1  SPI Clock Rate Select 1 -- }        (SPR1 --> 0)  
     81        0  SPI Clock Rate Select 0 -- } fOSC/4 (SPR0 --> 0) ("Fastest" but see SPI2X in SPSR) 
    8282  */ 
    8383  SPCR = (1<<SPE)| (1<<MSTR); 
     
    9696  /* 
    9797   
    98    Initialise the WIZ810MJ module and driver. 
    99     
     98     Initialise the WIZ810MJ module and driver. 
     99      
    100100   */ 
    101101 
    102102  /* 
    103    Initialise the W5100 chip 
    104     
    105    (Originally I thought it was possible for the chip 
    106     to function without a hardware reset but it 
    107     seems not to be the case.) 
    108    */  
     103     Initialise the W5100 chip 
     104      
     105     (Originally I thought it was possible for the chip 
     106      to function without a hardware reset but it 
     107      seems not to be the case.) 
     108   */    
    109109  pinMode(PIN_RESET, OUTPUT); 
    110110   
     
    132132 
    133133void setup () { 
    134   Serial.begin(19200); 
    135   SPrintln("Setup enter..."); 
    136  
    137   configureSPI();   
     134  Serial.begin(9600); 
     135  Serial.println("Setup enter..."); 
     136 
     137  configureSPI();     
    138138   
    139139  initModule(); 
    140140 
    141   SPrintln("Test W5100 configuration...");     
    142    
    143   byte config_gateway[] = {192,168,0.1}; 
    144   byte config_subnet_mask[] = {255,255,0,0}; 
     141  Serial.println("Test W5100 configuration...");         
     142   
     143  byte config_gateway[] = {192,168,2,101}; 
     144  byte config_subnet_mask[] = {255,255,255,0}; 
    145145  byte config_mac_address[] = {0x02,0xDE,0xAD,0xBE,0xEF,0x00}; 
    146   byte config_ip_address[] = {192,168,0,69}; 
     146  byte config_ip_address[] = {192,168,2,105}; 
    147147    
    148148  setGAR(config_gateway); 
     
    151151  setSIPR(config_ip_address); 
    152152    
    153   SPrintln("End test W5100 configuration...");     
    154    
    155      
    156   SPrintln("Test W5100 driver code..."); 
     153  Serial.println("End test W5100 configuration...");         
     154     
     155         
     156  Serial.println("Test W5100 driver code..."); 
    157157   
    158158  getGAR(ip); 
    159159   
    160   SPrint("Gateway IP read (first digit): "); 
     160  Serial.print("Gateway IP read (first digit): "); 
    161161  Serial.println(ip[0], DEC); 
    162162 
    163   SPrintln("End test W5100 driver code..."); 
     163  Serial.println("End test W5100 driver code...");         
    164164 
    165165  pinMode(PIN_LED, OUTPUT); 
    166166  digitalWrite(PIN_LED, HIGH); 
    167167   
    168   SPrintln("Setup exit..."); 
     168  Serial.println("Setup exit..."); 
    169169   
    170170} 
     
    174174  strcpy((char *) buffer, "w00t!> "); 
    175175 
    176   SPrint("send result: ");  
     176  Serial.print("send result: ");  
    177177  //Serial.println(send(testSocket, buffer, 6), DEC); 
    178178  Serial.println(send(testSocket, buffer, strlen((char *)buffer)), DEC); 
     
    182182 
    183183  //strcpy((char *) buffer, "Content-Type: text/plain\n\nfoo!\n"); 
     184  strcpy((char *) buffer, "HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r<html><body bgcolor='#000000'>foo!</body></html>\n\r"); 
    184185  if (ledState) { 
    185   strcpy((char *) buffer, "HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r<html><body bgcolor='#000000'>foo!</body></html>\n\r"); 
    186186   buffer[66] = 'F';  
    187187  } else { 
    188   strcpy((char *) buffer, "HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r<html><body bgcolor='#000000'>bar!</body></html>\n\r"); 
    189    buffer[68] = 'F';    
     188   buffer[68] = 'F';      
    190189  } 
    191    
    192   SPrint("send result: ");  
     190 
     191  Serial.print("send result: ");  
    193192  Serial.println(send(testSocket, buffer, strlen((char *)buffer)), DEC); 
    194193} 
     
    196195 
    197196void loop() { 
    198   SPrintln("Test W5100 socket..."); 
    199    
    200   SPrint("Create socket result: ");  
     197  Serial.println("Test W5100 socket..."); 
     198   
     199  Serial.print("Create socket result: ");  
    201200  Serial.println(socket(testSocket, Sn_MR_TCP, 80, 0), DEC); 
    202201 
    203   SPrint("Socket status: ");    
     202  Serial.print("Socket status: ");    
    204203  Serial.println(IINCHIP_READ(Sn_SR(testSocket)), HEX); 
    205204   
    206205  if (IINCHIP_READ(Sn_SR(testSocket)) == SOCK_CLOSED) { 
    207     SPrintln("Socket still closed, waiting..."); 
     206    Serial.println("Socket still closed, waiting..."); 
    208207    while (IINCHIP_READ(Sn_SR(testSocket)) == SOCK_CLOSED) { 
    209208      //pass 
     
    211210  } 
    212211   
    213   SPrint("Listen on socket result: "); 
     212  Serial.print("Listen on socket result: ");  
    214213  Serial.println(listen(testSocket), DEC); 
    215    
    216   SPrintln("Waiting for connection...");  
     214 
     215  Serial.println("Waiting for connection...");  
    217216 
    218217  while (getSn_SR(testSocket) == SOCK_LISTEN) { 
     
    224223  getSn_DIPR(testSocket, ip); 
    225224   
    226   SPrint("Destination IP read (last digit): "); 
     225  Serial.print("Destination IP read (last digit): "); 
    227226  Serial.println(ip[3], DEC); 
    228227 
     
    258257  while (getSn_SR(testSocket) == SOCK_ESTABLISHED) { 
    259258   while (getSn_RX_RSR(testSocket) > 0) { 
    260    recv(testSocket, bytesReceived, 1); 
    261    theByte = bytesReceived[0]; 
    262    //Serial.print(bytesReceived[0], BYTE); 
    263    Serial.print(theByte, BYTE); 
    264    if ((state == STATE_G) && (theByte == 'G')) { 
    265     state = STATE_E; 
    266    } else if ((state == STATE_E) && (theByte == 'E')) { 
    267      state = STATE_T; 
    268    } else if ((state == STATE_T) && (theByte == 'T')) { 
    269      state = STATE_SPACE; 
    270    } else if ((state == STATE_SPACE) && (theByte == ' ')) { 
    271      state = STATE_SLASH; 
    272    } else if ((state == STATE_SLASH) && (theByte == '/')) { 
    273     state = STATE_READ; 
    274    } else if ((state == STATE_READ) && (theByte == '0')) { 
    275      digitalWrite(PIN_LED, LOW); 
    276      ledState = 0; 
    277      //state = STATE_END; 
    278      delay(100);     
    279    } else if ((state == STATE_READ) && (theByte == '1')) { 
    280      digitalWrite(PIN_LED, HIGH); 
    281      ledState = 1; 
    282      //state = STATE_END; 
    283      delay(100);     
    284    } else if (state == STATE_READ) { 
    285      // It's not a valid byte. 
    286      state = STATE_END;    
    287    } else { 
    288      state = STATE_ERR; 
    289    } 
    290      
    291    if ((state == STATE_ERR) || (state == STATE_END)) { 
    292      SPrintln(""); 
    293      break; 
    294    } 
    295       
    296    /* 
    297   dataLength = getSn_RX_RSR(testSocket); 
    298    
    299   if (dataLength >= MAX_RX_BUFFER_SIZE) { // TODO: blah, blah... 
    300     dataLength = MAX_RX_BUFFER_SIZE-1; 
    301   } 
    302   // SPrint("dataLength: "); Serial.println(dataLength, HEX); 
    303   //SPrint("recv result: ");  
    304   //Serial.println(recv(testSocket, bytesReceived, dataLength), DEC); // NOTE: Throws away unread portion? No? 
    305   recv(testSocket, bytesReceived, dataLength); // TODO: Return length? 
    306   bytesReceived[dataLength]=0x00; 
    307   Serial.print((char *)bytesReceived); 
    308    
    309   //SPrint("send result: ");  
    310   //Serial.println(send(testSocket, bytesReceived, dataLength), DEC); 
    311    
    312   //sendPrompt(bytesReceived); 
    313   */ 
    314    
     259     recv(testSocket, bytesReceived, 1); 
     260     theByte = bytesReceived[0]; 
     261     //Serial.print(bytesReceived[0], BYTE); 
     262     Serial.print(theByte, BYTE); 
     263     if ((state == STATE_G) && (theByte == 'G')) { 
     264       state = STATE_E; 
     265     } else if ((state == STATE_E) && (theByte == 'E')) { 
     266       state = STATE_T;        
     267     } else if ((state == STATE_T) && (theByte == 'T')) { 
     268       state = STATE_SPACE;        
     269     } else if ((state == STATE_SPACE) && (theByte == ' ')) { 
     270       state = STATE_SLASH;        
     271     } else if ((state == STATE_SLASH) && (theByte == '/')) { 
     272       state = STATE_READ;        
     273     } else if ((state == STATE_READ) && (theByte == '0')) { 
     274       digitalWrite(PIN_LED, LOW); 
     275       ledState = 0; 
     276       //state = STATE_END; 
     277       delay(100);     
     278     } else if ((state == STATE_READ) && (theByte == '1')) { 
     279       digitalWrite(PIN_LED, HIGH); 
     280       ledState = 1; 
     281       //state = STATE_END; 
     282       delay(100);     
     283     } else if (state == STATE_READ) { 
     284       // It's not a valid byte. 
     285       state = STATE_END;        
     286     } else { 
     287       state = STATE_ERR; 
     288     } 
     289       
     290     if ((state == STATE_ERR) || (state == STATE_END)) { 
     291       Serial.println(""); 
     292       break; 
     293     } 
     294        
     295     /* 
     296    dataLength = getSn_RX_RSR(testSocket); 
     297     
     298    if (dataLength >= MAX_RX_BUFFER_SIZE) { // TODO: blah, blah... 
     299      dataLength = MAX_RX_BUFFER_SIZE-1; 
     300    } 
     301    // Serial.print("dataLength: "); Serial.println(dataLength, HEX); 
     302    //Serial.print("recv result: ");  
     303    //Serial.println(recv(testSocket, bytesReceived, dataLength), DEC); // NOTE: Throws away unread portion? No? 
     304    recv(testSocket, bytesReceived, dataLength); // TODO: Return length? 
     305    bytesReceived[dataLength]=0x00; 
     306    Serial.print((char *)bytesReceived); 
     307     
     308    //Serial.print("send result: ");  
     309    //Serial.println(send(testSocket, bytesReceived, dataLength), DEC); 
     310     
     311    //sendPrompt(bytesReceived); 
     312    */ 
     313     
    315314   } 
    316315   sendBanner(bytesToSend, ledState); 
     
    318317   break; 
    319318 } 
    320    
     319 
     320  disconnect(testSocket); 
    321321  close(testSocket); 
    322   disconnect(testSocket); 
    323            
    324   SPrintln("End test W5100 socket...");     
    325  
    326    
    327    
    328 } 
    329  
     322                     
     323  Serial.println("End test W5100 socket...");         
     324 
     325   
     326   
     327} 
     328