DCF77
1.0.0
DCF77 is a library for the Arduino Platform to read and decode the atomic time broadcasted by the DCF77 radiostation.
|
00001 #ifndef DCF77_h 00002 #define DCF77_h 00003 00004 #if ARDUINO >= 100 00005 #include <Arduino.h> 00006 #else 00007 #include <WProgram.h> 00008 #endif 00009 #include <Time.h> 00010 00011 #define MIN_TIME 1334102400 // Date: 11-4-2012 00012 #define MAX_TIME 4102444800 // Date: 1-1-2100 00013 00014 #define DCFRejectionTime 700 // Pulse-to-Pulse rejection time. 00015 #define DCFRejectPulseWidth 50 // Minimal pulse width 00016 #define DCFSplitTime 180 // Specifications distinguishes pulse width 100 ms and 200 ms. In practice we see 130 ms and 230 00017 #define DCFSyncTime 1500 // Specifications defines 2000 ms pulse for end of sequence 00018 00019 class DCF77 { 00020 private: 00021 00022 //Private variables 00023 bool initialized; 00024 static int dCF77Pin; 00025 static int dCFinterrupt; 00026 static byte pulseStart; 00027 00028 // DCF77 and internal timestamps 00029 static time_t previousUpdatedTime; 00030 static time_t latestupdatedTime; 00031 static time_t processingTimestamp; 00032 static time_t previousProcessingTimestamp; 00033 static unsigned char CEST; 00034 // DCF time format structure 00035 struct DCF77Buffer { 00036 //unsigned long long prefix :21; 00037 unsigned long long prefix :17; 00038 unsigned long long CEST :1; // CEST 00039 unsigned long long CET :1; // CET 00040 unsigned long long unused :2; // unused bits 00041 unsigned long long Min :7; // minutes 00042 unsigned long long P1 :1; // parity minutes 00043 unsigned long long Hour :6; // hours 00044 unsigned long long P2 :1; // parity hours 00045 unsigned long long Day :6; // day 00046 unsigned long long Weekday :3; // day of week 00047 unsigned long long Month :5; // month 00048 unsigned long long Year :8; // year (5 -> 2005) 00049 unsigned long long P3 :1; // parity 00050 }; 00051 00052 00053 // DCF Parity format structure 00054 struct ParityFlags{ 00055 unsigned char parityFlag :1; 00056 unsigned char parityMin :1; 00057 unsigned char parityHour :1; 00058 unsigned char parityDate :1; 00059 } static flags; 00060 00061 // Parameters shared between interupt loop and main loop 00062 static volatile bool FilledBufferAvailable; 00063 static volatile unsigned long long filledBuffer; 00064 static volatile time_t filledTimestamp; 00065 00066 // DCF Buffers and indicators 00067 static int bufferPosition; 00068 static unsigned long long runningBuffer; 00069 static unsigned long long processingBuffer; 00070 00071 // Pulse flanks 00072 static int leadingEdge; 00073 static int trailingEdge; 00074 static int PreviousLeadingEdge; 00075 static bool Up; 00076 00077 //Private functions 00078 void static initialize(void); 00079 void static bufferinit(void); 00080 void static finalizeBuffer(void); 00081 static bool receivedTimeUpdate(void); 00082 void static storePreviousTime(void); 00083 void static calculateBufferParities(void); 00084 bool static processBuffer(void); 00085 void static appendSignal(unsigned char signal); 00086 00087 public: 00088 // Public Functions 00089 DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank=true); 00090 00091 static time_t getTime(void); 00092 static time_t getUTCTime(void); 00093 static void Start(void); 00094 static void Stop(void); 00095 static void int0handler(); 00096 }; 00097 00098 #endif 00099