Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:software:homelab:library:module:ethernet [2012/05/16 12:49] – created raivo.sellen:software:homelab:library:module:ethernet [2020/07/20 12:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Ethernet ====== ====== Ethernet ======
-<note important>Translation</note> 
-//Seotud mooduliga: [HW] [[et:hardware:homelab:controller]]// 
  
-See teegi osa sisaldab Kodulabori etherneti kasutamise funktsioone.+//Necessary knowledge: [HW] [[en:hardware:homelab:controller]]//
  
-===== Konstandid =====+The following part of library contains HomeLab Ethernet functions.
  
-    * **//static uint8_t mymac[6] {0x54,0x55,0x58,0x10,0x00,0x24}//** - kontrolleri MAC aadress (võib valida suvalise aadress, kuid oluline on, et ühes võrgus aadressid ei korduks). +===== Constants =====
-    * **//static uint8_t myip[4] {192,168,1,100}//** - IP aadress vastavalt kohtvõrgule, viimane number tuleb ise valida, juhul kui see on võrgus juba hõivatud. +
-    * **//static uint8_t buf[BUFFER_SIZE+1]//** - andmepuhvri suurus (tavaliselt 600+1 baiti).+
  
 +    * **//static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24}//** - controller MAC address (you can choose a random address, but it is important to be unique in the network).
 +    * **//static uint8_t myip[4] = {192,168,1,100}//** - IP address corresponding to LAN, you must choose different last digit, if it is already present in the network.
 +    * **//static uint8_t buf[BUFFER_SIZE+1]//** - size of data buffer (usually 600+1 B).
  
-===== Funktsioonid =====+ 
 +===== Functions =====
  
   * **//void ethernet_standby(void)//** \\   * **//void ethernet_standby(void)//** \\
-    Viib etherneti kontrolleri magavasse (madala energiatarbegaolekusse.+    Brings Ethernet controller into sleep mode (low energy consumption).
  
   * **//void ethernet_init(uint8_t *mac, uint8_t *ip)//** \\   * **//void ethernet_init(uint8_t *mac, uint8_t *ip)//** \\
-    Etherneti kontrolleri algseadistus koos MAC ja IP aadressidegaParameetrid+    Ethernet controller initial setup with MAC and IP addresses. 
-    * //*mac// - MAC aadressi massiiv+    Parameters
-    * //*ip// - IP aadressi massiiv.+    * //*mac// - MAC address array
 +    * //*ip// - IP address array.
  
   * **//uint16_t ethernet_get_packet (uint16_t maxlen, uint8_t* packet)//** \\   * **//uint16_t ethernet_get_packet (uint16_t maxlen, uint8_t* packet)//** \\
-    Kuulab võrku, kuni saab endale mõeldud ja andmeid sisaldava andmepaketiParameetrid+    Polls network until it receives packet addressed to it and containing data. 
-    * //maxlen// - maksimaalne lubatud andmepuhvri suurus+    Parameters
-    * //*buffer// - massiiv, kuhu salvestab vastuvõetud andmed edasiseks töötluseks+    * //maxlen// - maximum allowed data buffer size
-    * Kui pakett on saabunud, tagastab saabunud paketi pikkuse baitidesvastasel juhul tagastab 0.+    * //*buffer// - array where to save received data for further operations
 +    * If the packet has arrivedreturns the length of the received packet in bytes and in opposite case returns 0.
  
   * **//uint16_t ethernet_analyse_packet(uint8_t *buf,uint16_t plen)//** \\   * **//uint16_t ethernet_analyse_packet(uint8_t *buf,uint16_t plen)//** \\
-    Analüüsib, kas vastuvõetud andmepakett sisaldab URL-i kohta andmeidVajadusel vastab pingileParameetrid+    Analyzes if received packet contains info about URL. Will respond to ping if needed. 
-    * //*buf// - andmete massiiv, mida analüüsida+    Parameters
-    * //plen// - saabunud paketi pikkus baitides.+    * //*buf// - data array to analyze
 +    * //plen// - length of received packet in bytes.
     * Tagastab URL-i esimese tähemärgi aadressi. Kui URL on tühi, siis tagastab 0.     * Tagastab URL-i esimese tähemärgi aadressi. Kui URL on tühi, siis tagastab 0.
 +    * Returns the address of the first char in URL. If URL is empty, it will return 0.
  
   * **//uint16_t ethernet_load_data (uint8_t *buf,uint16_t pos, const prog_char *progmem_s)   * **//uint16_t ethernet_load_data (uint8_t *buf,uint16_t pos, const prog_char *progmem_s)
 //** \\ //** \\
-    Laeb veebilehe kuvamiseks html-koodi kontrolleri programmimälust TCP saatmise puhvrisseParameetrid+    Loads HTML-code for displaying webpage from controller program memory into TCP send buffer. 
-    * //*buf// - andmemassiiv, mida saata TCP kaudu+    Parameters
-    * //pos// - andmete lõpu aadress puhvris, mida tuleb jälgida, kui andmeid üksteise järele laadida sinnaEsimene aadress on 0. +    * //*buf// - data arrya to send using TCP. 
-    * //*progmem_s//stringi nimi, mis on salvestatud programmi mällu ja kust andmed laetakse saatmise massiivi+    * //pos// - data end address in buffer which must be maintained if data is loaded in queueThe first address is 0. 
-    * Tagastab andmejada lõpu aadressi, mida saab sisestada parameetrina järgmise html-koodi laadimiseks.+    * //*progmem_s//string name that is saved into program memory and from where data is loaded into send array
 +    * Retruns end address of data array which can be input as a parameter for loading next HTML-code.
  
   * **//void ethernet_print_webpage (uint8_t *buf,uint16_t dlen)//** \\   * **//void ethernet_print_webpage (uint8_t *buf,uint16_t dlen)//** \\
-    Kuvab veebilehte vastavalt valmislaetud html-koodileParameetrid+    Dislays webpage according to preloaded HTML-code. 
-    * //*buf// - andmemassiiv, kuhu html on valmis laetud+    Parameters
-    * //dplen// - andmete lõpu aadress puhvris, milleni kuvab koodi.+    * //*buf// - Data array where HTLM is preloaded
 +    * //dplen// - End address of data in buffer to be displayed as HTML-code.
  
  
-~~PB~~+<pagebreak>
  
-===== Näide =====+===== Example =====
  
 <code c> <code c>
Line 57: Line 63:
 #include <homelab/pin.h> #include <homelab/pin.h>
  
-// Veebilehe koostamiseks eraldi funktsioon+// Function for compiling webpage
 uint16_t ethernet_load_webpage(uint8_t on_off); uint16_t ethernet_load_webpage(uint8_t on_off);
  
-// MAC ja IP peavad olema unikaalsed oma kohtvõrgus+// MAC and IP must be unique in network
-// kahte ühesugust aadressi ei saa olla seadmetel+// same addresses in two devices are not allowed
-// See MAC on suvaliselt võetud (üldjuhul pole vaja muuta)+// Random MAC address (usually no need to change it)
 static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24}; static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
  
-// IP vastavalt kohtvõrgule (viimane number valida ise)+// IP according to LAN (you need to choose the last number)
 static uint8_t myip[4] = {192,168,1,100}; static uint8_t myip[4] = {192,168,1,100};
  
-//andmejada pikkus+//length of data array
 static uint16_t gPlen;  static uint16_t gPlen; 
  
-//Andmete puhvri suurus+//Data buffer size
 #define BUFFER_SIZE 600 #define BUFFER_SIZE 600
 static uint8_t buf[BUFFER_SIZE+1]; static uint8_t buf[BUFFER_SIZE+1];
  
-//LED PB7 muutuja määramine+//LED PB7 variable
 pin debug_led = PIN(B, 7); pin debug_led = PIN(B, 7);
  
Line 85: Line 91:
  char *str;    char *str;  
  
- // LED PB7 on väljund+ // LED PB7 is output
  pin_setup_output(debug_led);  pin_setup_output(debug_led);
   
- // Etherneti initseerimine vastavalt etteantud aadressidele+ // Etherneti initialization with given addresses
  ethernet_init(mymac, myip);   ethernet_init(mymac, myip);
                  
         while(1)         while(1)
  {  {
- // Võtab vastu pakette, kuni saab endale määratud andmetega paketi+ // Receive packets until it receives addressed to him with data
     pktlen=ethernet_get_packet(BUFFER_SIZE, buf);     pktlen=ethernet_get_packet(BUFFER_SIZE, buf);
  
-        // Teeb paketi eeltöötluse ja vastab "ping" paketileTagastab paketi URL-i.+        // Performs packet preconditioning and answer to "ping" packet 
 +        // Returns packet URL.
         gPlen=ethernet_analyse_packet(buf,pktlen);         gPlen=ethernet_analyse_packet(buf,pktlen);
  
- // Kui on URL-is on infotsiis hakkab seda analüüsima+ // If URL contains infostart analyzing it
         if (gPlen!=0)         if (gPlen!=0)
  {                 {               
-            // Laeb URL-i aadressiosa viita "str"Olgu veel öeldud, et  +            // Load URL address part into "str".  
-     //URL-is on neli esimest kohta IP aadressi numbrid      +            // The first 4 digits are IP address numbers.
             str = (char *)&(buf[gPlen+4]);             str = (char *)&(buf[gPlen+4]);
   
- // Otsib URL-ist stringi "/1"              + // Find string "/1" from URL              
  if (strncmp("/1",str,2)==0)  if (strncmp("/1",str,2)==0)
  {  {
-                         // Laeb veebilehe+                         // Load webpage
  gPlen = ethernet_load_webpage(0);  gPlen = ethernet_load_webpage(0);
  
- // LED põlema+ // LED on
  pin_clear(debug_led);   pin_clear(debug_led);
                            
                   }                   }
- // Järgmisena otsib URL-ist stringi "/0"+ // At next, find string "/0" from URL
  else if (strncmp("/0",str,2)==0)  else if (strncmp("/0",str,2)==0)
  {  {
-                         // Laeb veebilehe+                         // Load webpage
  gPlen = ethernet_load_webpage(1);  gPlen = ethernet_load_webpage(1);
  
- // LED kustutada+ // LED on
  pin_set(debug_led);  pin_set(debug_led);
                          
                   }                   }
- // Muul juhul lae veebileht vastavalt LED olekule+ // In other cases load webpage according to LED condition
                  else                   else 
  {              {            
Line 132: Line 139:
                  }                                                      }                                    
   
- // Kuva varem valmis laetud veebileht                 + // Display preloaded webpage                 
-                        ethernet_print_webpage (buf,gPlen);      +                        ethernet_print_webpage (buf,gPlen);                 
-            +
  }  }
     }     }
Line 141: Line 147:
  
  
-// Veebileht laetakse kuvamiseks kirjutades andmed TCP saatmise puhvrisse+// Webpage will be loaded by writing data into TCP send buffer
 uint16_t ethernet_load_webpage(uint8_t on_off) uint16_t ethernet_load_webpage(uint8_t on_off)
 { {
     uint16_t plen=0;      uint16_t plen=0; 
  
- // Laeb html koodi saatmiseks puhvrisse + // Load HTML-code into buffer to send it 
- // Need suured stringid on salvestatud PSTR makro abil programmimälusse+ // Those large strings are saved into program memory using PSTR macro
- // et mitte raisata liigselt töömälu.+ // to save SRAM
  
- // Laeb veebilehe päise + // Load webpage header 
-       plen=ethernet_load_data(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));+ 
 + plen=ethernet_load_data(buf,0,PSTR 
 + ("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
          
-    plen=ethernet_load_data(buf,plen,PSTR("<center><p>Homelab PB7 LED: "));+ plen=ethernet_load_data(buf,plen,PSTR("<center><p>Homelab PB7 LED: "));
   
-    // Kui LED ei põlesiis kuva nii.+    // if LED is offdisplay it
     if (on_off)     if (on_off)
     {     {
-         plen=ethernet_load_data(buf,plen,PSTR("<font color=\"#00FF00\"> OFF</font>"));+      plen=ethernet_load_data(buf,plen,PSTR("<font color=\"#00FF00\"> OFF</font>"));
     }     }
-    // Kui LED põleb.+    // if LED is on
     else     else
     {     {
-         plen=ethernet_load_data(buf,plen,PSTR("<font color=\"#FF0000\"> ON</font>"));+      plen=ethernet_load_data(buf,plen,PSTR("<font color=\"#FF0000\"> ON</font>"));
     }     }
     // Lae "Refresh" nupp     // Lae "Refresh" nupp
-    plen=ethernet_load_data(buf,plen,PSTR(" <small><a href=\".\">[refresh status]</a></small></p>\n<p><a href=\"."));+    plen=ethernet_load_data(buf,plen,PSTR 
 +    (" <small><a href=\".\">[refresh status]</a></small></p>\n<p><a href=\"."));
          
-    // Lae LED oleku muutmise nupp vastavalt selle olekule.+    // Load the button for LED condition change.
     if (on_off)     if (on_off)
     {     {
Line 180: Line 189:
     }      } 
          
-    // Väljasta andmete lõpu aadress puhvris+    // Return the end address of data in buffer
     return(plen);     return(plen);
 } }
  
 </code> </code>
- 
en/software/homelab/library/module/ethernet.1337161792.txt.gz · Last modified: (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0