Projekt na płytce k64f

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of Ethernet_UDP_server by NXP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003  
00004 
00005 
00006 const int PORT = 80;                             //port
00007 
00008 static const char* SERVER_IP = "192.168.1.101"; //IP serwera
00009 static const char* MASK = "255.255.255.0";      //maska
00010 static const char* GATEWAY = "192.168.1.1";     //gateway
00011 
00012 
00013 
00014 Serial pc(USBTX, USBRX);        //PC interface
00015 
00016 DigitalOut RedLed(LED1);
00017 //DigitalOut GreenLed(LED2);
00018 DigitalOut BlueLed(LED3);
00019 InterruptIn Switch1(SW2); // przycisk lewo 
00020 InterruptIn Switch2(SW3); // przycisk od prawy
00021 
00022 
00023 
00024 
00025 void init_usb(void);    //init usb
00026 void init_eth(void);    //init Ethernet
00027 
00028 void init_usb(void)
00029 {
00030     //pc.baud(9600);    //baud
00031     
00032 }  
00033 
00034 
00035 
00036 void blink()
00037 {
00038     RedLed=!RedLed;
00039     
00040 }
00041 void blink1()
00042 {
00043     BlueLed=!BlueLed;
00044 
00045 }
00046 int main(void)
00047 {
00048     char c;
00049    // int licznik;
00050   //  licznik=0;
00051   //  int a;
00052   //  int b;
00053     //int d[2]={a,b};
00054     
00055     //init_usb();     //init usb
00056 
00057     EthernetInterface eth;
00058     eth.init(SERVER_IP, MASK, GATEWAY);
00059     eth.connect();
00060     
00061     pc.printf("\nIP Address is %s\n\r", eth.getIPAddress());
00062     
00063     TCPSocketServer server;
00064     server.bind(PORT);
00065     server.listen(); // nasluch przychodzacych polaczen
00066     
00067     
00068     Switch1.fall(&blink);
00069     Switch2.fall(&blink1);
00070     
00071 
00072     
00073     
00074     while (true)    //wykonuj caly czas
00075     {             
00076         
00077         
00078         TCPSocketConnection client; 
00079 
00080         server.accept(client); // akceptacja nowego polaczenia
00081 
00082         client.set_blocking(false, 1500); // timeout (1.5)s
00083         
00084        c=RedLed;
00085        
00086        switch(c)
00087        {
00088         case 0:
00089         if (BlueLed==0){
00090         char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona ON</font></p> oraz <p><font color=""blue"">Dioda Niebieska ON</font></p><form action=""demo_form.asp""></form></body> </html>"; 
00091             client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko
00092             }
00093             else
00094             {
00095             char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona ON</font></p> oraz <p><font color=""blue"">Dioda Niebieska OFF</font></p><form action=""demo_form.asp""></form></body> </html>";
00096             client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko  
00097             }
00098        break;
00099        
00100        case 1:
00101         if (BlueLed==1){
00102         char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona OFF</font></p> oraz <p><font color=""blue"">Dioda Niebieska OFF</font></p><form action=""demo_form.asp""></form></body> </html>";
00103             client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko
00104 
00105             }
00106             else
00107             {
00108             char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona OFF</font></p> oraz <p><font color=""blue"">Dioda Niebieska ON</font></p><form action=""demo_form.asp""></form></body> </html>"; 
00109             client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko  
00110 
00111             }
00112        }
00113      
00114         
00115         
00116     /*    
00117         if (RedLed==0)
00118         {
00119             char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Czerwona włączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; 
00120             client.send_all(http_cmd, sizeof(http_cmd)-1); 
00121             }
00122             else
00123             { 
00124         char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Czerwona wyłączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; 
00125         client.send_all(http_cmd, sizeof(http_cmd)-1); 
00126         }
00127 }
00128         if (RedBlue==0)
00129         {
00130             char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Niebieska włączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; 
00131             client.send_all(http_cmd, sizeof(http_cmd)-1); 
00132         else
00133         {
00134         char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Niebieska włączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; 
00135         client.send_all(http_cmd, sizeof(http_cmd)-1); 
00136         }
00137         }
00138               
00139      */     
00140 
00141             
00142         client.close(); 
00143         
00144         pc.printf("\n\nClient closed\n\n\r");
00145  
00146        
00147         
00148     }
00149  }