Newer
Older
TestStandRepository / Software / Arduino / libraries / Arduino-Libraries / DCF77 / DCF77.h
  1. #ifndef DCF77_h
  2. #define DCF77_h
  3.  
  4. #if ARDUINO >= 100
  5. #include <Arduino.h>
  6. #else
  7. #include <WProgram.h>
  8. #endif
  9. #include <Time.h>
  10.  
  11. #define MIN_TIME 1334102400 // Date: 11-4-2012
  12. #define MAX_TIME 4102444800 // Date: 1-1-2100
  13.  
  14. #define DCFRejectionTime 700 // Pulse-to-Pulse rejection time.
  15. #define DCFRejectPulseWidth 50 // Minimal pulse width
  16. #define DCFSplitTime 180 // Specifications distinguishes pulse width 100 ms and 200 ms. In practice we see 130 ms and 230
  17. #define DCFSyncTime 1500 // Specifications defines 2000 ms pulse for end of sequence
  18.  
  19. class DCF77 {
  20. private:
  21.  
  22. //Private variables
  23. bool initialized;
  24. static int dCF77Pin;
  25. static int dCFinterrupt;
  26. static byte pulseStart;
  27.  
  28. // DCF77 and internal timestamps
  29. static time_t previousUpdatedTime;
  30. static time_t latestupdatedTime;
  31. static time_t processingTimestamp;
  32. static time_t previousProcessingTimestamp;
  33. static unsigned char CEST;
  34. // DCF time format structure
  35. struct DCF77Buffer {
  36. //unsigned long long prefix :21;
  37. unsigned long long prefix :17;
  38. unsigned long long CEST :1; // CEST
  39. unsigned long long CET :1; // CET
  40. unsigned long long unused :2; // unused bits
  41. unsigned long long Min :7; // minutes
  42. unsigned long long P1 :1; // parity minutes
  43. unsigned long long Hour :6; // hours
  44. unsigned long long P2 :1; // parity hours
  45. unsigned long long Day :6; // day
  46. unsigned long long Weekday :3; // day of week
  47. unsigned long long Month :5; // month
  48. unsigned long long Year :8; // year (5 -> 2005)
  49. unsigned long long P3 :1; // parity
  50. };
  51. // DCF Parity format structure
  52. struct ParityFlags{
  53. unsigned char parityFlag :1;
  54. unsigned char parityMin :1;
  55. unsigned char parityHour :1;
  56. unsigned char parityDate :1;
  57. } static flags;
  58.  
  59. // Parameters shared between interupt loop and main loop
  60. static volatile bool FilledBufferAvailable;
  61. static volatile unsigned long long filledBuffer;
  62. static volatile time_t filledTimestamp;
  63.  
  64. // DCF Buffers and indicators
  65. static int bufferPosition;
  66. static unsigned long long runningBuffer;
  67. static unsigned long long processingBuffer;
  68.  
  69. // Pulse flanks
  70. static int leadingEdge;
  71. static int trailingEdge;
  72. static int PreviousLeadingEdge;
  73. static bool Up;
  74. //Private functions
  75. void static initialize(void);
  76. void static bufferinit(void);
  77. void static finalizeBuffer(void);
  78. static bool receivedTimeUpdate(void);
  79. void static storePreviousTime(void);
  80. void static calculateBufferParities(void);
  81. bool static processBuffer(void);
  82. void static appendSignal(unsigned char signal);
  83.  
  84. public:
  85. // Public Functions
  86. DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank=true);
  87. static time_t getTime(void);
  88. static time_t getUTCTime(void);
  89. static void Start(void);
  90. static void Stop(void);
  91. static void int0handler();
  92. };
  93.  
  94. #endif
  95.