David Smart / iCal
Committer:
WiredHome
Date:
Sun Jun 08 01:35:37 2014 +0000
Revision:
4:a1c25d936346
Parent:
3:fc5cdc930896
Child:
5:69577415c16e
Cleaned up debugging interface.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:49245357cd1b 1 #ifndef ICAL_H
WiredHome 0:49245357cd1b 2 #define ICAL_H
WiredHome 0:49245357cd1b 3 #include "mbed.h"
WiredHome 0:49245357cd1b 4
WiredHome 4:a1c25d936346 5 //#include "NTPClient.h"
WiredHome 0:49245357cd1b 6
WiredHome 0:49245357cd1b 7 // This defines the total number of events that can be handled - kind of limiting
WiredHome 0:49245357cd1b 8 // but maybe ok for now.
WiredHome 0:49245357cd1b 9 #define EVENT_COUNT 10
WiredHome 0:49245357cd1b 10
WiredHome 0:49245357cd1b 11
WiredHome 0:49245357cd1b 12 // Maximum storage space for each item as free-form text
WiredHome 4:a1c25d936346 13 #ifdef WIN32
WiredHome 4:a1c25d936346 14 #define SUMMARY_CHARS 100
WiredHome 4:a1c25d936346 15 #define LOCATION_CHARS 100
WiredHome 4:a1c25d936346 16 #define CATEGORY_CHARS 20
WiredHome 4:a1c25d936346 17 #else
WiredHome 0:49245357cd1b 18 #define SUMMARY_CHARS 40
WiredHome 3:fc5cdc930896 19 #define LOCATION_CHARS 20
WiredHome 3:fc5cdc930896 20 #define CATEGORY_CHARS 20
WiredHome 4:a1c25d936346 21 #endif
WiredHome 0:49245357cd1b 22
WiredHome 0:49245357cd1b 23 typedef enum {
WiredHome 0:49245357cd1b 24 rptfNone,
WiredHome 0:49245357cd1b 25 rptfDaily,
WiredHome 0:49245357cd1b 26 rptfWeekly,
WiredHome 0:49245357cd1b 27 rptfMonthly,
WiredHome 0:49245357cd1b 28 rptfYearly
WiredHome 0:49245357cd1b 29 } RepeatFreq_t;
WiredHome 0:49245357cd1b 30
WiredHome 0:49245357cd1b 31 #if 0
WiredHome 0:49245357cd1b 32 typedef enum {
WiredHome 0:49245357cd1b 33 Sunday = 0x01,
WiredHome 0:49245357cd1b 34 Monday = 0x02,
WiredHome 0:49245357cd1b 35 Tuesday = 0x04,
WiredHome 0:49245357cd1b 36 Wednesday = 0x08,
WiredHome 0:49245357cd1b 37 Thursday = 0x10,
WiredHome 0:49245357cd1b 38 Friday = 0x20,
WiredHome 0:49245357cd1b 39 Saturday = 0x40
WiredHome 0:49245357cd1b 40 } RepeatDays_t;
WiredHome 0:49245357cd1b 41 #endif
WiredHome 0:49245357cd1b 42
WiredHome 0:49245357cd1b 43 typedef struct {
WiredHome 0:49245357cd1b 44 time_t Start;
WiredHome 0:49245357cd1b 45 time_t End;
WiredHome 0:49245357cd1b 46 time_t Until;
WiredHome 0:49245357cd1b 47 uint16_t Count;
WiredHome 0:49245357cd1b 48 uint16_t Interval;
WiredHome 0:49245357cd1b 49 RepeatFreq_t RepeatFreq;
WiredHome 4:a1c25d936346 50 uint8_t RepeatDays; // bit mapped (bit 0 = sunday, bit 1=monday, ...)
WiredHome 4:a1c25d936346 51 uint16_t RepeatMonths; // bit mapped (bit 0 = jan, 1=feb, ...)
WiredHome 4:a1c25d936346 52 uint32_t RepeatMonthDay; // bit mapped (bit 1 = 1st, 2=2nd, ...)
WiredHome 4:a1c25d936346 53 uint32_t RepeatMonthDayRev; // reverse -1 = last day = bit 1, -2=bit 2, ...
WiredHome 0:49245357cd1b 54 char Summary[SUMMARY_CHARS];
WiredHome 0:49245357cd1b 55 char Location[LOCATION_CHARS];
WiredHome 0:49245357cd1b 56 char Category[CATEGORY_CHARS]; // "Green", ...
WiredHome 0:49245357cd1b 57 int Priority; // 1 == High, 5 == Normal, 9 == Low
WiredHome 0:49245357cd1b 58 } Event_T;
WiredHome 0:49245357cd1b 59
WiredHome 0:49245357cd1b 60
WiredHome 0:49245357cd1b 61 extern Event_T EventList[EVENT_COUNT];
WiredHome 0:49245357cd1b 62
WiredHome 4:a1c25d936346 63
WiredHome 4:a1c25d936346 64 /// Parse an iCal stream, and extract everything useful.
WiredHome 4:a1c25d936346 65 ///
WiredHome 4:a1c25d936346 66 /// This accepts a pointer to a [large] buffer, which is the contents
WiredHome 4:a1c25d936346 67 /// of an iCal stream. It walked through all of the available
WiredHome 4:a1c25d936346 68 /// information to extract the Event list.
WiredHome 4:a1c25d936346 69 ///
WiredHome 4:a1c25d936346 70 /// @param[in] pStart is a pointer to the start of the stream.
WiredHome 4:a1c25d936346 71 /// @param[in] gridStartTime is a time value representing the start of the time-window of interest.
WiredHome 4:a1c25d936346 72 /// @param[in] gridEndTime is a time value representing the end of the time-window of interest.
WiredHome 4:a1c25d936346 73 /// @param[in] tzoSec is the time-zone offset in seconds.
WiredHome 4:a1c25d936346 74 /// @param[in] showEvents when true causes it to print the events as parsed.
WiredHome 4:a1c25d936346 75 /// @returns number of events in range.
WiredHome 4:a1c25d936346 76 ///
WiredHome 4:a1c25d936346 77 int ParseICalStream(char * pStart, time_t gridStartTime, time_t gridEndTime, int32_t tzoSec, bool showEvents = false);
WiredHome 4:a1c25d936346 78
WiredHome 4:a1c25d936346 79
WiredHome 4:a1c25d936346 80 /// Get the number of events that have been cached.
WiredHome 4:a1c25d936346 81 ///
WiredHome 4:a1c25d936346 82 /// @returns the number of events.
WiredHome 4:a1c25d936346 83 ///
WiredHome 4:a1c25d936346 84 int GetNumEvents(void);
WiredHome 4:a1c25d936346 85
WiredHome 4:a1c25d936346 86 /// Compute the intersection of two time ranges, and evaluate the recurringing events.
WiredHome 4:a1c25d936346 87 ///
WiredHome 4:a1c25d936346 88 /// This compares a pair of time ranges, each by a start and end time. If they overlap
WiredHome 4:a1c25d936346 89 /// it then computes the intersection of those two ranges. Additionally, for a
WiredHome 4:a1c25d936346 90 /// specified Event, it will evaluate the recurring events that may also fall into
WiredHome 4:a1c25d936346 91 /// the target time range.
WiredHome 4:a1c25d936346 92 ///
WiredHome 4:a1c25d936346 93 /// @note This is usually the only API you need, as this will first call
WiredHome 4:a1c25d936346 94 /// the TimeIntersects function, and if that fails, then it will evaluate
WiredHome 4:a1c25d936346 95 /// repeat information.
WiredHome 4:a1c25d936346 96 ///
WiredHome 4:a1c25d936346 97 /// @param[in,out] start1 is the starting time of range 1.
WiredHome 4:a1c25d936346 98 /// @param[in,out] end1 is the ending time of range 1.
WiredHome 4:a1c25d936346 99 /// @param[in] start2 is the starting time of range 2.
WiredHome 4:a1c25d936346 100 /// @param[in] end2 is the ending time of range 2.
WiredHome 4:a1c25d936346 101 /// @param[in] Event is a pointer to the event of interest that may have recurring series.
WiredHome 4:a1c25d936346 102 /// @returns true if the ranges overlap, and then start1 and end1 are set to the
WiredHome 4:a1c25d936346 103 /// intersection.
WiredHome 4:a1c25d936346 104 ///
WiredHome 4:a1c25d936346 105 bool RepeatIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2, Event_T * Event = NULL);
WiredHome 4:a1c25d936346 106
WiredHome 4:a1c25d936346 107
WiredHome 4:a1c25d936346 108 /// Compute the intersection of two time ranges, and returns that intersection.
WiredHome 4:a1c25d936346 109 ///
WiredHome 4:a1c25d936346 110 /// This compares a pair of time ranges, each by a start and end time. If they overlap
WiredHome 4:a1c25d936346 111 /// it then computes the intersection of those two ranges.
WiredHome 4:a1c25d936346 112 ///
WiredHome 4:a1c25d936346 113 /// @param[in,out] start1 is the starting time of range 1.
WiredHome 4:a1c25d936346 114 /// @param[in,out] end1 is the ending time of range 1.
WiredHome 4:a1c25d936346 115 /// @param[in] start2 is the starting time of range 2.
WiredHome 4:a1c25d936346 116 /// @param[in] end2 is the ending time of range 2.
WiredHome 4:a1c25d936346 117 /// @returns true if the ranges overlap, and then start1 and end1 are set to the
WiredHome 4:a1c25d936346 118 /// intersection.
WiredHome 4:a1c25d936346 119 ///
WiredHome 4:a1c25d936346 120 bool TimeIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2);
WiredHome 4:a1c25d936346 121
WiredHome 4:a1c25d936346 122
WiredHome 4:a1c25d936346 123 // Private Functions - no real value external to the iCal public interface
WiredHome 4:a1c25d936346 124 // other than for test code.
WiredHome 4:a1c25d936346 125
WiredHome 4:a1c25d936346 126 /// Computes the next interval for iCal events that have recurrence.
WiredHome 4:a1c25d936346 127 ///
WiredHome 4:a1c25d936346 128 /// @param[in] baseT is the base time value which is a factor only in leap-year.
WiredHome 4:a1c25d936346 129 /// @param[in] repeatFreq is a value representing the frequency of recurrence -
WiredHome 4:a1c25d936346 130 /// 0=none, 1=daily, 2=weekly, 3=monthly, 4=yearly
WiredHome 4:a1c25d936346 131 /// @param[in] interval is the multiplier of that repeat frequency to the next
WiredHome 4:a1c25d936346 132 /// event.
WiredHome 4:a1c25d936346 133 /// @returns a time_t value which is the incremental interval, and would be added
WiredHome 4:a1c25d936346 134 /// to a reference time.
WiredHome 4:a1c25d936346 135 ///
WiredHome 4:a1c25d936346 136 time_t NextInterval(time_t baseT, int repeatFreq, int interval);
WiredHome 4:a1c25d936346 137
WiredHome 4:a1c25d936346 138
WiredHome 0:49245357cd1b 139 /// Format a ctime value as a string, without the trailing <cr>
WiredHome 0:49245357cd1b 140 ///
WiredHome 0:49245357cd1b 141 /// This uses the normal ctime function, which appends a <cr>, but
WiredHome 0:49245357cd1b 142 /// it then removes that trailing line ending character. Additionally,
WiredHome 0:49245357cd1b 143 /// this keeps a few local static buffers to return the time string in
WiredHome 0:49245357cd1b 144 /// which permits a printf (for example) to call this api a few times
WiredHome 0:49245357cd1b 145 /// and get the proper representation of each.
WiredHome 0:49245357cd1b 146 ///
WiredHome 1:db274b9e40cc 147 /// @param[in] t is a time value;
WiredHome 0:49245357cd1b 148 /// @returns a pointer to a static buffer containing the converted time.
WiredHome 0:49245357cd1b 149 ///
WiredHome 0:49245357cd1b 150 char * FormatCTime(time_t t);
WiredHome 0:49245357cd1b 151
WiredHome 0:49245357cd1b 152 /// Sort the Events that have been extracted from the iCal results.
WiredHome 0:49245357cd1b 153 ///
WiredHome 0:49245357cd1b 154 void SortEvents();
WiredHome 0:49245357cd1b 155
WiredHome 0:49245357cd1b 156 /// Show the details for a specific Event, on the specified serial stream.
WiredHome 0:49245357cd1b 157 ///
WiredHome 4:a1c25d936346 158 /// Most useful during development, and perhaps no value after that.
WiredHome 0:49245357cd1b 159 ///
WiredHome 1:db274b9e40cc 160 /// @param[in] Event is the event of interest.
WiredHome 0:49245357cd1b 161 ///
WiredHome 0:49245357cd1b 162 void ShowEventInfo(Event_T & Event);
WiredHome 0:49245357cd1b 163
WiredHome 0:49245357cd1b 164 /// Access the 2-letter abbreviation for the day of the week.
WiredHome 0:49245357cd1b 165 ///
WiredHome 1:db274b9e40cc 166 /// @param[in] i is the day of the week, where 0 = sunday
WiredHome 0:49245357cd1b 167 /// @returns a pointer to the 2-letter abbreviation.
WiredHome 0:49245357cd1b 168 ///
WiredHome 0:49245357cd1b 169 const char * RepeatDayAbbrev(int i);
WiredHome 0:49245357cd1b 170
WiredHome 0:49245357cd1b 171 /// Parse a Datestamp string into a time value.
WiredHome 0:49245357cd1b 172 ///
WiredHome 0:49245357cd1b 173 /// Parses a string which can look like this: 20140505T200000
WiredHome 0:49245357cd1b 174 /// into a time_t value.
WiredHome 0:49245357cd1b 175 ///
WiredHome 1:db274b9e40cc 176 /// @param[in] string is the string to parse.
WiredHome 1:db274b9e40cc 177 /// @param[in] tzoSec is the time-zone offset in seconds.
WiredHome 0:49245357cd1b 178 /// @returns time_t value.
WiredHome 0:49245357cd1b 179 ///
WiredHome 1:db274b9e40cc 180 time_t ParseDateStamp(char * string, int32_t tzoSec);
WiredHome 0:49245357cd1b 181
WiredHome 4:a1c25d936346 182 /// Parse a Time Zone ID value from the front-end of a Datestamp
WiredHome 0:49245357cd1b 183 ///
WiredHome 4:a1c25d936346 184 /// Parses a string which can look like one of these:
WiredHome 4:a1c25d936346 185 /// @li TZID="(GMT -06:00)":20140519T063000
WiredHome 4:a1c25d936346 186 /// @li TZID:(UTC-06:00) Central Time (US & Canada)
WiredHome 4:a1c25d936346 187 /// @li TZID:(GMT -06:00)
WiredHome 0:49245357cd1b 188 ///
WiredHome 4:a1c25d936346 189 /// @param[in] string to be parsed.
WiredHome 4:a1c25d936346 190 /// @returns time zone offset in seconds.
WiredHome 0:49245357cd1b 191 ///
WiredHome 4:a1c25d936346 192 int32_t ParseTZID(char * string);
WiredHome 0:49245357cd1b 193
WiredHome 4:a1c25d936346 194
WiredHome 0:49245357cd1b 195
WiredHome 0:49245357cd1b 196
WiredHome 4:a1c25d936346 197 #endif // ICAL_H