1122121

Dependencies:   7SegSRDriver_3 C12832_lcd EthernetInterface_youcef2 TimeZone mbed-rtos mbed

Committer:
sefyou
Date:
Tue Jun 06 13:53:19 2017 +0000
Revision:
0:3d909922074a
op

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sefyou 0:3d909922074a 1 #include "mbed.h"
sefyou 0:3d909922074a 2 #include "EthernetInterface.h"
sefyou 0:3d909922074a 3 #include "C12832_lcd.h"
sefyou 0:3d909922074a 4 #include "Time.h"
sefyou 0:3d909922074a 5
sefyou 0:3d909922074a 6 C12832_LCD lcd; //Graphics LCD
sefyou 0:3d909922074a 7 /*****************MAISON*****************/
sefyou 0:3d909922074a 8 /*const char* ip= "192.168.1.49";
sefyou 0:3d909922074a 9 const char* masque= "255.255.255.0";
sefyou 0:3d909922074a 10 const char* gateway= "192.168.1.254";*/
sefyou 0:3d909922074a 11
sefyou 0:3d909922074a 12 /*****************COUR*******************/
sefyou 0:3d909922074a 13 const char* ip= "172.16.202.4";
sefyou 0:3d909922074a 14 const char* masque= "255.255.0.0";
sefyou 0:3d909922074a 15 const char* gateway= "172.16.0.5";
sefyou 0:3d909922074a 16
sefyou 0:3d909922074a 17 const int MCAST_PORT = 8888;
sefyou 0:3d909922074a 18
sefyou 0:3d909922074a 19 Timer heure;
sefyou 0:3d909922074a 20
sefyou 0:3d909922074a 21 int main() {
sefyou 0:3d909922074a 22 /************HEURE********************/
sefyou 0:3d909922074a 23 EthernetInterface eth;
sefyou 0:3d909922074a 24 eth.init(ip,masque,gateway); //Use DHCP
sefyou 0:3d909922074a 25 eth.connect();
sefyou 0:3d909922074a 26
sefyou 0:3d909922074a 27 UDPSocket sock;
sefyou 0:3d909922074a 28 sock.init();
sefyou 0:3d909922074a 29
sefyou 0:3d909922074a 30 Endpoint nist;
sefyou 0:3d909922074a 31 nist.set_address("utcnist.colorado.edu", 37);
sefyou 0:3d909922074a 32
sefyou 0:3d909922074a 33 char out_buffer[] = ""; // Does not matter
sefyou 0:3d909922074a 34 sock.sendTo(nist, out_buffer, sizeof(out_buffer));
sefyou 0:3d909922074a 35
sefyou 0:3d909922074a 36
sefyou 0:3d909922074a 37 char in_buffer[4];
sefyou 0:3d909922074a 38 int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));
sefyou 0:3d909922074a 39 unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
sefyou 0:3d909922074a 40 /************PREMIER SERVEUR ********************/
sefyou 0:3d909922074a 41 UDPSocket server;
sefyou 0:3d909922074a 42 server.bind(MCAST_PORT);
sefyou 0:3d909922074a 43 Endpoint client;
sefyou 0:3d909922074a 44 char data[256];
sefyou 0:3d909922074a 45
sefyou 0:3d909922074a 46 int heure01;
sefyou 0:3d909922074a 47 int heure02;
sefyou 0:3d909922074a 48
sefyou 0:3d909922074a 49 int minute01;
sefyou 0:3d909922074a 50 int minute02;
sefyou 0:3d909922074a 51 while (true)
sefyou 0:3d909922074a 52 {
sefyou 0:3d909922074a 53 heure.start();
sefyou 0:3d909922074a 54 data[0] = 0;
sefyou 0:3d909922074a 55 server.receiveFrom(client, data, sizeof(data));
sefyou 0:3d909922074a 56
sefyou 0:3d909922074a 57 if(data[0]=='B' && data[1]=='U' && data[2] =='Z' && data[3] == 'Z')
sefyou 0:3d909922074a 58 {
sefyou 0:3d909922074a 59 lcd.cls();
sefyou 0:3d909922074a 60 lcd.printf("premier serveur !");
sefyou 0:3d909922074a 61 }
sefyou 0:3d909922074a 62
sefyou 0:3d909922074a 63 if(data[0]=='B' && data[1]=='A' && data[2] =='C' && data[3] == 'K')
sefyou 0:3d909922074a 64 {
sefyou 0:3d909922074a 65 //lcd.cls();
sefyou 0:3d909922074a 66 //lcd.printf("premier serveur22");
sefyou 0:3d909922074a 67 if (heure.read_ms() >= 1000 )
sefyou 0:3d909922074a 68 {
sefyou 0:3d909922074a 69 set_time(timeRes);
sefyou 0:3d909922074a 70 time_t unixTime= time(NULL);
sefyou 0:3d909922074a 71 TimeStamp timeStamp(unixTime);
sefyou 0:3d909922074a 72 lcd.cls();
sefyou 0:3d909922074a 73 lcd.locate(1, 0);
sefyou 0:3d909922074a 74 // lcd.printf("heure :%d ------ minute :%d ",timeStamp.getHour()+2,timeStamp.getMinute());
sefyou 0:3d909922074a 75
sefyou 0:3d909922074a 76 heure01= ((timeStamp.getHour()+2) /10);
sefyou 0:3d909922074a 77 heure02= ((timeStamp.getHour()+2) %10);
sefyou 0:3d909922074a 78
sefyou 0:3d909922074a 79 minute01= ((timeStamp.getMinute()) /10);
sefyou 0:3d909922074a 80 minute02= ((timeStamp.getMinute()) %10);
sefyou 0:3d909922074a 81
sefyou 0:3d909922074a 82
sefyou 0:3d909922074a 83 lcd.printf("heure1 :%d ------ heure2 :%d", heure01, heure02);
sefyou 0:3d909922074a 84 lcd.printf("\n");
sefyou 0:3d909922074a 85 lcd.printf("minute1 :%d ------ minute2 :%d", minute01, minute02);
sefyou 0:3d909922074a 86 lcd.printf("\n");
sefyou 0:3d909922074a 87 lcd.printf("%d",heure.read_ms());
sefyou 0:3d909922074a 88 timeRes+=1;
sefyou 0:3d909922074a 89 heure.reset();
sefyou 0:3d909922074a 90
sefyou 0:3d909922074a 91 }
sefyou 0:3d909922074a 92 }
sefyou 0:3d909922074a 93 }
sefyou 0:3d909922074a 94
sefyou 0:3d909922074a 95
sefyou 0:3d909922074a 96 }