[gnoduino] Revert "fix UdpNtpClient for newer gcc"



commit c00ac5e9437a2007202e66a45d251eeda26d4f7a
Author: Lucian Langa <lucilanga gnome org>
Date:   Thu May 30 15:32:26 2013 +0200

    Revert "fix UdpNtpClient for newer gcc"
    
    This reverts commit 83cd53c2377b67c45c05654fb46433c8a68f81b7.

 .../examples/UdpNtpClient/UdpNtpClient.ino         |   24 ++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino 
b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
index a226d1f..c67c3fe 100644
--- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
+++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
@@ -45,6 +45,30 @@ byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing pack
 // A UDP instance to let us send and receive packets over UDP
 EthernetUDP Udp;
 
+// send an NTP request to the time server at the given address
+unsigned long sendNTPpacket(IPAddress& address)
+{
+  // set all bytes in the buffer to 0
+  memset(packetBuffer, 0, NTP_PACKET_SIZE);
+  // Initialize values needed to form NTP request
+  // (see URL above for details on the packets)
+  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
+  packetBuffer[1] = 0;     // Stratum, or type of clock
+  packetBuffer[2] = 6;     // Polling Interval
+  packetBuffer[3] = 0xEC;  // Peer Clock Precision
+  // 8 bytes of zero for Root Delay & Root Dispersion
+  packetBuffer[12]  = 49;
+  packetBuffer[13]  = 0x4E;
+  packetBuffer[14]  = 49;
+  packetBuffer[15]  = 52;
+
+  // all NTP fields have been given values, now
+  // you can send a packet requesting a timestamp:
+  Udp.beginPacket(address, 123); //NTP requests are to port 123
+  Udp.write(packetBuffer,NTP_PACKET_SIZE);
+  Udp.endPacket();
+}
+
 void setup() 
 {
  // Open serial communications and wait for port to open:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]