Garmin Fleet Management Controller  2.19.0
util.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * util.cpp - Utility Procedures
5 *
6 * Copyright 2008-2012 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <time.h>
16 #include <math.h>
17 #include <zlib.h>
18 //#include <windows.h>
19 
20 #include "util.h"
21 
22 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 static uint8 const sMonthDays[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
26 
27 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 static uint32 const sYearDays[ 12 ] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
31 
32 //----------------------------------------------------------------------
37 //----------------------------------------------------------------------
39  (
40  const time_type * aSeconds,
41  date_time_data_type * aDateTime
42  )
43 {
44  /*----------------------------------------------------------
45  Local Variables
46  ----------------------------------------------------------*/
47  boolean isLeapYear;
48  time_type days;
49  sint32 fourYearCount;
50 
51  days = *aSeconds / SECONDS_PER_DAY;
52  fourYearCount = (sint32)( days / DAYS_IN_4_YEARS );
53  days -= fourYearCount * DAYS_IN_4_YEARS;
54  aDateTime->date.year = (uint16)( fourYearCount * 4 ) + BASE_YEAR;
55 
56  while( days > DAYS_IN_1_YEAR )
57  {
58  days -= DAYS_IN_1_YEAR;
59 
60  if( ( aDateTime->date.year % 4 ) == 0 )
61  {
62  days--;
63  }
64 
65  ( aDateTime->date.year )++;
66  }
67 
68  if( days < 1 )
69  {
70  aDateTime->date.year--;
71  aDateTime->date.month = DECEMBER;
72  aDateTime->date.day = sMonthDays[ DECEMBER - 1 ];
73  }
74  else
75  {
76  isLeapYear = FALSE;
77 
78  /*--------------------------------------------------
79  Adjust for the extra day that happens during leap
80  years (February 29). This adjustment needs to
81  happen any time after the beginning of March.
82  --------------------------------------------------*/
83  if( ( days > sYearDays[ MARCH - 1 ] ) &&
84  ( ( aDateTime->date.year % 4 ) == 0 ) )
85  {
86  days--;
87  isLeapYear = TRUE;
88  }
89 
90  for( aDateTime->date.month = DECEMBER;
91  days <= sYearDays[ aDateTime->date.month -1 ];
92  aDateTime->date.month-- );
93 
94  aDateTime->date.day = (uint8)( days - sYearDays[ aDateTime->date.month - 1 ] );
95 
96  if( ( isLeapYear == TRUE ) &&
97  ( aDateTime->date.month == FEBRUARY ) &&
98  ( aDateTime->date.day == sMonthDays[ FEBRUARY - 1 ] ) )
99  {
100  aDateTime->date.day++;
101  }
102  }
103 }
104 
105 //----------------------------------------------------------------------
112 //----------------------------------------------------------------------
114  (
115  const date_time_data_type * aDateTime,
116  time_type * aSeconds
117  )
118 {
119  /*----------------------------------------------------------
120  Local Variables
121  ----------------------------------------------------------*/
122  time_type days;
123  sint32 fourYearCount;
124  int i;
125 
126  returnif_v( ( aDateTime->date.year < 1989 ), FALSE );
127  returnif_v( ( aDateTime->date.year == 1989 ) &&
128  ( aDateTime->date.month < 12 ), FALSE );
129  returnif_v( ( aDateTime->date.year == 1989 ) &&
130  ( aDateTime->date.month == 12 ) &&
131  ( aDateTime->date.day < 31 ), FALSE );
132 
133  returnif_v( ( aDateTime->date.year > 2126 ), FALSE );
134  returnif_v( ( aDateTime->date.year == 2126 ) &&
135  ( aDateTime->date.month > 2 ), FALSE );
136  returnif_v( ( aDateTime->date.year == 2126 ) &&
137  ( aDateTime->date.month == 2 ) &&
138  ( aDateTime->date.day > 5 ), FALSE );
139 
140  returnif_v( ( aDateTime->date.month == 0 ) ||
141  ( aDateTime->date.month > 12 ), FALSE );
142 
143  fourYearCount = ( aDateTime->date.year - BASE_YEAR ) / 4;
144  days = (sint32)fourYearCount * DAYS_IN_4_YEARS;
145 
146  for( i = ( ( fourYearCount * 4 ) + BASE_YEAR ); i < (int)aDateTime->date.year; i++ )
147  {
148  days += DAYS_IN_1_YEAR;
149  if( (i % 4) == 0 )
150  {
151  days++;
152  }
153  }
154 
155  days += sYearDays[ aDateTime->date.month - 1 ];
156  if( ( aDateTime->date.month > FEBRUARY ) &&
157  ( ( aDateTime->date.year % 4 ) == 0 ) )
158  {
159  days++;
160  }
161 
162  days += aDateTime->date.day;
163 
164  /*------------------------------------------------------
165  This accounts for the fact that internal time really
166  starts one day before the base year. The above
167  conversion does not work for December 31, 1989.
168  ------------------------------------------------------*/
169  if( ( aDateTime->date.year == 1989 ) &&
170  ( aDateTime->date.month == 12 ) &&
171  ( aDateTime->date.day == 31 ) )
172  {
173  days = 0;
174  }
175 
176  *aSeconds = days * SECONDS_PER_DAY;
177  return TRUE;
178 }
179 
180 
181 //----------------------------------------------------------------------
185 //----------------------------------------------------------------------
187  (
188  double aDegrees
189  )
190 {
191 return aDegrees * (double)( PI / 180 );
192 } /* UTIL_convert_degrees_to_radians() */
193 
194 
195 //----------------------------------------------------------------------
202 //----------------------------------------------------------------------
204  (
205  double aDegrees
206  )
207 {
208 return (sint32)( aDegrees * (double)( ( 1 << 30 ) / 90 ) );
209 } /* UTIL_convert_degrees_to_semicircles() */
210 
211 //----------------------------------------------------------------------
216 //----------------------------------------------------------------------
218  (
219  const time_type * aSeconds,
220  gps_time_type * aGpsTime
221  )
222 {
223  aGpsTime->week_number_days = (sint32)( *aSeconds / SECONDS_PER_DAY );
224  aGpsTime->time_of_week = *aSeconds - ( aGpsTime->week_number_days * SECONDS_PER_DAY );
225 }
226 
227 //----------------------------------------------------------------------
231 //----------------------------------------------------------------------
233  (
234  const gps_time_type * aGpsTime,
235  time_type * aSeconds
236  )
237 {
238  *aSeconds = ( aGpsTime->week_number_days * SECONDS_PER_DAY ) + aGpsTime->time_of_week;
239 }
240 
241 //----------------------------------------------------------------------
245 //----------------------------------------------------------------------
247  (
248  double aRadians
249  )
250 {
251 return aRadians * (double)( 180 / PI );
252 } /* UTIL_convert_radians_to_degrees() */
253 
254 //----------------------------------------------------------------------
258 //----------------------------------------------------------------------
260  (
261  sint32 aSemicircles
262  )
263 {
264 return (double)aSemicircles * 90 / ( 1 << 30 );
265 } /* UTIL_convert_semicircles_to_degrees() */
266 
267 //----------------------------------------------------------------------
272 //----------------------------------------------------------------------
274  (
275  const time_type * aSeconds,
276  date_time_data_type * aDateTime
277  )
278 {
279  time_type secondsSinceMidnight;
280 
281  secondsSinceMidnight = *aSeconds % SECONDS_PER_DAY;
282 
283  aDateTime->time.hour = (sint16)( secondsSinceMidnight / SECONDS_PER_HOUR );
284  secondsSinceMidnight -= aDateTime->time.hour * SECONDS_PER_HOUR;
285  aDateTime->time.minute = (uint8)( secondsSinceMidnight / SECONDS_PER_MINUTE );
286  aDateTime->time.second = (uint8)( secondsSinceMidnight - aDateTime->time.minute * SECONDS_PER_MINUTE );
287 }
288 
289 //----------------------------------------------------------------------
293 //----------------------------------------------------------------------
295  (
296  const date_time_data_type * aDateTime,
297  time_type * aSeconds
298  )
299 {
300  *aSeconds = ( aDateTime->time.hour * SECONDS_PER_HOUR )
301  + ( aDateTime->time.minute * SECONDS_PER_MINUTE )
302  + aDateTime->time.second;
303 }
304 
305 
306 //----------------------------------------------------------------------
321 //----------------------------------------------------------------------
323  (
324  const char * aHexString,
325  uint8 * aBinaryData,
326  uint16 aMaxBytes
327  )
328 {
329  static const char hex[] = "0123456789abcdef";
330  const char * currentChar;
331  const char * hexPos;
332  bool highNibble = true;
333  uint16 binaryIndex = 0;
334  uint8 workByte = 0;
335 
336  currentChar = aHexString;
337 
338  while( binaryIndex < aMaxBytes && *currentChar != '\0' )
339  {
340  hexPos = strchr( hex, tolower( *currentChar ) );
341  if( hexPos != NULL )
342  {
343  if( highNibble )
344  {
345  workByte = (uint8)( ( hexPos - hex ) << 4 );
346  }
347  else
348  {
349  workByte += (uint8)( hexPos - hex );
350  aBinaryData[binaryIndex++] = workByte;
351  }
352  highNibble = !highNibble;
353  }
354  else return 0;
355  currentChar++;
356  }
357  if( !highNibble )
358  binaryIndex = 0;
359 
360  return binaryIndex;
361 }
362 
363 //----------------------------------------------------------------------
374 //----------------------------------------------------------------------
376  (
377  const uint8 * aData,
378  char * aOutput,
379  uint8 aNumBytes
380  )
381 {
382  static const char hex[] = "0123456789abcdef";
383 
384  for( int i = 0; i < aNumBytes; i++ )
385  {
386  aOutput[2 * i] = hex[ aData[i] / 16 ];
387  aOutput[2 * i + 1] = hex[ aData[i] % 16 ];
388  }
389  aOutput[2 * aNumBytes] = '\0';
390 }
391 
392 //----------------------------------------------------------------------
409 //----------------------------------------------------------------------
411  (
412  const char * aHexString,
413  uint16 * aBinaryData,
414  uint8 aMaxWords
415  )
416 {
417  static const char hex[] = "0123456789abcdef";
418  const char * currentChar;
419  const char * hexPos;
420  int state = 0;
421  uint8 binaryIndex = 0;
422  uint16 work = 0;
423 
424  currentChar = aHexString;
425 
426  while( binaryIndex < aMaxWords && *currentChar != '\0' )
427  {
428  hexPos = strchr( hex, tolower( *currentChar ) );
429  if( hexPos != NULL )
430  {
431  switch( state )
432  {
433  case 0: //highest byte
434  work = (uint16)( hexPos - hex ) << 12;
435  break;
436  case 1: //middle high
437  work += (uint16)( hexPos - hex ) << 8;
438  break;
439  case 2: //middle low
440  work += (uint16)( hexPos - hex ) << 4;
441  break;
442  case 3: //lowest
443  work += (uint16)( hexPos - hex );
444  aBinaryData[binaryIndex++] = work;
445  }
446  state++;
447  if( state > 3 ) state = 0;
448  }
449  else return 0;
450  currentChar++;
451  }
452 
453  if( state != 0 )
454  {
455  binaryIndex = 0;
456  }
457 
458  return binaryIndex;
459 }
460 
461 
462 //----------------------------------------------------------------------
469 //----------------------------------------------------------------------
471  (
472  const char * aData,
473  int aLength
474  )
475 {
476  for( int i = 0; i < aLength; i++ )
477  {
478  if( aData[i] < 0 || !isprint( aData[i] ) )
479  {
480  return false;
481  }
482  }
483  return true;
484 }
485 
486 //----------------------------------------------------------------------
493 //----------------------------------------------------------------------
495  (
496  const char * aData
497  )
498 {
499  if( strlen( aData ) == 0 )
500  {
501  return false;
502  }
503 
504  if( _atoi64( aData ) > max_uint_val( uint32 ) ||
505  _atoi64( aData ) < 0 )
506  {
507  return false;
508  }
509 
510  for( unsigned int i = 0; i < strlen( aData ); i++ )
511  {
512  if( aData[i] < '0' || aData[i] > '9' )
513  {
514  return false;
515  }
516  }
517  return true;
518 }
519 
520 //----------------------------------------------------------------------
524 //----------------------------------------------------------------------
526  (
527  const time_type * aUtcTime,
528  time_type * aLocalTime
529  )
530 {
531  TIME_ZONE_INFORMATION tzinfo;
532 
533  switch ( GetTimeZoneInformation( &tzinfo ) )
534  {
535  case TIME_ZONE_ID_DAYLIGHT:
536  *aLocalTime = *aUtcTime - ( ( tzinfo.Bias + tzinfo.DaylightBias ) * SECONDS_PER_MINUTE );
537  break;
538  default:
539  *aLocalTime = *aUtcTime - ( ( tzinfo.Bias + tzinfo.StandardBias ) * SECONDS_PER_MINUTE );
540  }
541 }
542 
543 //----------------------------------------------------------------------
547 //----------------------------------------------------------------------
549  (
550  const time_type * aLocalTime,
551  time_type * aUtcTime
552  )
553 {
554  TIME_ZONE_INFORMATION tzinfo;
555 
556  switch ( GetTimeZoneInformation( &tzinfo ) )
557  {
558  case TIME_ZONE_ID_DAYLIGHT:
559  *aUtcTime = *aLocalTime + ( ( tzinfo.Bias + tzinfo.DaylightBias ) * SECONDS_PER_MINUTE );
560  break;
561  default:
562  *aUtcTime = *aLocalTime + ( ( tzinfo.Bias + tzinfo.StandardBias ) * SECONDS_PER_MINUTE );
563  }
564 }
565 
566 //----------------------------------------------------------------------
573 //----------------------------------------------------------------------
575  (
576  const date_time_data_type * aDateTime,
577  char * aResultString,
578  int aResultStringSize
579  )
580 {
581  boolean morning = TRUE;
582  sint16 hour = aDateTime->time.hour;
583 
584  // 0 <= hour <= 23
585  if( hour >= 12 )
586  {
587  hour -= 12;
588  morning = FALSE;
589  }
590  // 0 <= hour <= 11
591  if( hour == 0 ) hour = 12;
592 
593  if( morning )
594  sprintf_s( aResultString, aResultStringSize, "%02d:%02d:%02d AM", hour, aDateTime->time.minute, aDateTime->time.second );
595  else
596  sprintf_s( aResultString, aResultStringSize, "%02d:%02d:%02d PM", hour, aDateTime->time.minute, aDateTime->time.second );
597 }
598 
599 //----------------------------------------------------------------------
602 //----------------------------------------------------------------------
604 {
605  time_t aCurrentTime;
606  tm aCurrentTm;
607 
608  time( &aCurrentTime );
609  //convert to nice struct that separates into years since 1900, days, hours, minutes...
610  gmtime_s( &aCurrentTm, &aCurrentTime );
611 
612  return UTIL_get_garmin_time( aCurrentTm );
613 }
614 
615 //----------------------------------------------------------------------
618 //----------------------------------------------------------------------
620 {
621  //Garmin time counts seconds from Dec 31, 1989
622  //First, find seconds from Jan 1 1990 to aCurrentTm, excluding leap days
623  time_type seconds = ( ( aTimeTm.tm_year - 90 ) * SECONDS_PER_DAY * DAYS_IN_1_YEAR )
624  + ( aTimeTm.tm_yday * SECONDS_PER_DAY )
625  + ( aTimeTm.tm_hour * SECONDS_PER_HOUR )
626  + ( aTimeTm.tm_min * SECONDS_PER_MINUTE )
627  + ( aTimeTm.tm_sec );
628 
629  // Then add seconds from Dec 31 1989 to Jan 1 1990
630  seconds += SECONDS_PER_DAY;
631 
632  //adjust for leap days
633  // 88 last leap year prior to base year
634  // (subtract 88 since time_t base year is 1900)
635  int leapDays = ( aTimeTm.tm_year - 88 ) / 4;
636 
637  // if in a leap year and on or before Feb 28
638  // -> leap day has not happened this year
639  if( ( aTimeTm.tm_year % 4 == 0 ) &&
640  ( (uint32) aTimeTm.tm_yday <= sYearDays[2] ) )
641  {
642  leapDays--;
643  }
644  seconds += leapDays * SECONDS_PER_DAY;
645  return seconds;
646 }
647 
648 //----------------------------------------------------------------------
655 //----------------------------------------------------------------------
657  (
658  const date_time_data_type * aDateTime,
659  char * aResultString,
660  int aResultStringSize
661  )
662 {
663  sprintf_s( aResultString, aResultStringSize, "%02d/%02d/%04d", aDateTime->date.month, aDateTime->date.day, aDateTime->date.year );
664 }
665 
666 //----------------------------------------------------------------------
672 //----------------------------------------------------------------------
673 double UTIL_calc_2d_speed
674  (
675  float32 aNorthVelocity,
676  float32 aEastVelocity
677  )
678 {
679  return sqrt( pow( (double)aNorthVelocity, 2.0 ) +
680  pow( (double)aEastVelocity, 2.0 ) );
681 }
682 
683 //----------------------------------------------------------------------
690 //----------------------------------------------------------------------
692  (
693  float32 aNorthVelocity,
694  float32 aEastVelocity,
695  char * aCardinalDirection,
696  int aCardinalDirectionSize
697  )
698 {
699  if( ( aNorthVelocity == 0 ) && ( aEastVelocity == 0 ) )
700  {
701  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "" );
702  return;
703  }
704 
705  double angle = atan2( (double)aNorthVelocity, (double)aEastVelocity );
706 
707  //between -pi/8 and pi/8 = E
708  if( angle > ( PI * -1/8 ) && angle < ( PI * 1/8 ) )
709  strcpy_s( aCardinalDirection, aCardinalDirectionSize,"E" );
710  //between pi/8 and 3pi/8 = NE
711  else if( angle >= ( PI * 1/8 ) && angle < ( PI * 3/8 ) )
712  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "NE" );
713  //between 3pi/8 and 5pi/8 = N
714  else if( angle >= ( PI * 3/8 ) && angle < ( PI * 5/8 ) )
715  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "N" );
716  //between 5pi/8 and 7pi/8 = NW
717  else if( angle >= ( PI * 5/8 ) && angle < ( PI * 7/8 ) )
718  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "NW" );
719  //greater than 7pi/8 OR less than -7pi/8 = W
720  else if( angle >= ( PI * 7/8 ) || angle < ( PI * -7/8 ) )
721  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "W" );
722  //between -7*pi/8 and -5pi/8 = SW
723  else if( angle >= ( PI * -7/8 ) && angle < ( PI * -5/8 ) )
724  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "SW" );
725  //between -5pi/8 and -3pi/8 = S
726  else if( angle >= ( PI * -5/8 ) && angle < ( PI * -3/8 ) )
727  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "S" );
728  //between -3pi/8 and -pi/8 = SE
729  else if( angle >= ( PI * -3/8 ) && angle < ( PI * -1/8 ) )
730  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "SE" );
731  else
732  strcpy_s( aCardinalDirection, aCardinalDirectionSize, "??" );
733 }
734 
735 
736 //----------------------------------------------------------------------
740 //----------------------------------------------------------------------
741 CString unzip( char * original )
742  {
743  gzFile zipFile = gzopen( original, "rb" );
744  if ( NULL != zipFile)
745  {
746  CString newFilename( original );
747  newFilename += _T( ".inflated" );
748  CFile newFile;
749  if ( newFile.Open( newFilename, CFile::modeCreate | CFile::modeWrite ) )
750  {
751  BYTE buf[1024];
752  int len = 0;
753  while ( ( len = gzread( zipFile, buf, 1024 ) ) > 0 )
754  {
755  newFile.Write( ( const void * ) buf, ( UINT ) len );
756  }
757  gzclose( zipFile );
758  newFile.Close();
759  return newFilename;
760  }
761  gzclose( zipFile );
762  }
763  return CString( original );
764  }
765 
766 //----------------------------------------------------------------------
770 //----------------------------------------------------------------------
771 BOOL unzip( char * original, LPCTSTR destination )
772  {
773  // if file can be unzipped, do that
774  gzFile zipFile = gzopen( original, "rb" );
775  if ( NULL != zipFile)
776  {
777  CFile newFile;
778  if ( newFile.Open( destination, CFile::modeCreate | CFile::modeWrite ) )
779  {
780  BYTE buf[1024];
781  int len = 0;
782  while ( ( len = gzread( zipFile, buf, 1024 ) ) > 0 )
783  {
784  newFile.Write( ( const void * ) buf, ( UINT ) len );
785  }
786  gzclose( zipFile );
787  newFile.Close();
788  }
789  gzclose( zipFile );
790  return TRUE;
791  }
792  // otherwise just copy the file to the destination
793  return CopyFile( CString( original ), destination, FALSE );
794  }
795 
796 //----------------------------------------------------------------------
798 //----------------------------------------------------------------------
799 void write(CFile * catalog, char * text)
800  {
801  catalog->Write( ( const void * )text, ( UINT ) strlen( text ) );
802  }
803 
804 //----------------------------------------------------------------------
806 //----------------------------------------------------------------------
807 void write(CFile * catalog, LPCTSTR wText)
808  {
809  // convert Unicode to character array
810  int textLen = WideCharToMultiByte( CP_UTF8, 0, wText, -1, NULL, 0, NULL, NULL );
811  char * text = new char[textLen];
812  WideCharToMultiByte( CP_UTF8, 0, wText, -1, text, textLen, NULL, NULL );
813  catalog->Write( ( const void * ) text, textLen-1 );
814  delete text;
815  }
816 
817 //----------------------------------------------------------------------
819 //----------------------------------------------------------------------
820 void write(CFile * catalog, LPCTSTR wText, int maxLength )
821  {
822  // convert Unicode to character array
823  int textLen = WideCharToMultiByte( CP_UTF8, 0, wText, -1, NULL, 0, NULL, NULL );
824  char * text = new char[textLen];
825  WideCharToMultiByte( CP_UTF8, 0, wText, -1, text, textLen, NULL, NULL );
826  if ( textLen > maxLength )
827  {
828  catalog->Write( ( const void * ) text, maxLength-1 );
829  }
830  else {
831  catalog->Write( ( const void * ) text, textLen-1 );
832  }
833  catalog->Write( "\0", 1 );
834  delete text;
835  }
double UTIL_calc_2d_speed(float32 aNorthVelocity, float32 aEastVelocity)
Determine the two-dimensional velocity.
Definition: util.cpp:674
sint32 UTIL_convert_degrees_to_semicircles(double aDegrees)
Converts a latitude/longitude from degrees to semicircles.
Definition: util.cpp:204
struct date_time_data_type::_date date
uint8 second
second (0-59)
Definition: garmin_types.h:162
void UTIL_convert_gps_time_to_seconds(const gps_time_type *aGpsTime, time_type *aSeconds)
Converts from gps_time to Garmin time.
Definition: util.cpp:233
#define returnif_v(_check, _value)
Return a value if a condition is true.
Definition: util_macros.h:119
uint8 minute
minute (0-59)
Definition: garmin_types.h:161
#define DECEMBER
One-based month number for December.
Definition: util.h:50
void UTIL_format_date_string(const date_time_data_type *aDateTime, char *aResultString, int aResultStringSize)
Format a date as a string.
Definition: util.cpp:657
void UTIL_convert_seconds_to_gps_time(const time_type *aSeconds, gps_time_type *aGpsTime)
Converts Garmin time to a structure containing GPS time.
Definition: util.cpp:218
bool UTIL_data_is_uint32(const char *aData)
Determine whether an array of characters consists only of numeric, and that the value when converted ...
Definition: util.cpp:495
void UTIL_format_time_string(const date_time_data_type *aDateTime, char *aResultString, int aResultStringSize)
Converts a time structure (date_time_data_type) to a time string representation.
Definition: util.cpp:575
uint8 UTIL_hex_to_uint16(const char *aHexString, uint16 *aBinaryData, uint8 aMaxWords)
Converts a null-terminated string in hexadecimal format to an array of uint16 numbers, assuming natural byte ordering in the hex. No prefix should be present in the hex string.
Definition: util.cpp:411
#define FALSE
Definition: garmin_types.h:46
double UTIL_convert_radians_to_degrees(double aRadians)
Converts a latitude/longitude from radians to degrees.
Definition: util.cpp:247
struct date_time_data_type::_time time
time_type UTIL_get_garmin_time(tm aTimeTm)
Get the current server time in Garmin format.
Definition: util.cpp:619
#define SECONDS_PER_DAY
Number of seconds in one day.
Definition: util.h:37
void UTIL_convert_time_type_to_seconds(const date_time_data_type *aDateTime, time_type *aSeconds)
Converts a time_type to seconds since midnight.
Definition: util.cpp:295
#define TRUE
Definition: garmin_types.h:45
void UTIL_convert_seconds_to_time_type(const time_type *aSeconds, date_time_data_type *aDateTime)
Converts from a Garmin time to a structure containing separate members for hour, minute, and second (time_type).
Definition: util.cpp:274
double UTIL_convert_degrees_to_radians(double aDegrees)
Converts a latitude/longitude from degrees to radians.
Definition: util.cpp:187
signed short int sint16
16-bit signed integer
Definition: garmin_types.h:57
Date & time data type with separate fields for month, day, year, hour, minute, and second...
Definition: garmin_types.h:150
double UTIL_convert_semicircles_to_degrees(sint32 aSemicircles)
Converts a latitude/longitude from semicircles to degrees.
Definition: util.cpp:260
#define MARCH
One-based month number for March.
Definition: util.h:48
uint16 UTIL_hex_to_uint8(const char *aHexString, uint8 *aBinaryData, uint16 aMaxBytes)
Convert a hexadecimal ASCII string to an array of uint8.
Definition: util.cpp:323
float float32
32-bit IEEE-format floating point data. (1 sign bit, 8 exponent bits, and 23 mantissa bits) ...
Definition: garmin_types.h:70
sint32 week_number_days
Days since December 31st, 1989 to beginning of week (i.e., this is a Sunday)
Definition: garmin_types.h:145
CString unzip(char *original)
This function will uncompress a file into a new file.
Definition: util.cpp:741
void UTIL_convert_seconds_to_date_type(const time_type *aSeconds, date_time_data_type *aDateTime)
Converts a Garmin date to a structure containing year, month, and day.
Definition: util.cpp:39
void write(CFile *catalog, char *text)
This function is a helper for writing text to a file.
Definition: util.cpp:799
void UTIL_uint8_to_hex(const uint8 *aData, char *aOutput, uint8 aNumBytes)
Convert from binary to a hexadecimal string.
Definition: util.cpp:376
signed long int sint32
32-bit signed integer
Definition: garmin_types.h:59
boolean UTIL_convert_date_time_to_seconds(const date_time_data_type *aDateTime, time_type *aSeconds)
Converts a date from from a structure to a Garmin date.
Definition: util.cpp:114
bool UTIL_data_is_printable(const char *aData, int aLength)
Determine whether an array of characters consists only of printable ASCII.
Definition: util.cpp:471
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
#define FEBRUARY
One-based month number for February.
Definition: util.h:46
#define SECONDS_PER_HOUR
Number of seconds in one hour.
Definition: util.h:40
uint16 year
Real year (1990 means 1990!)
Definition: garmin_types.h:156
#define SECONDS_PER_MINUTE
Number of seconds in one minute.
Definition: util.h:43
static uint8 const sMonthDays[12]
Number of days in each month in a non-leap year.
Definition: util.cpp:25
uint8 month
month (1-12)
Definition: garmin_types.h:154
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
static uint32 const sYearDays[12]
Cumulative number of days in prior months in a non-leap year.
Definition: util.cpp:30
time_type UTIL_get_current_garmin_time()
Get the current server time in Garmin format.
Definition: util.cpp:603
#define DAYS_IN_1_YEAR
Number of days in a non-leap year.
Definition: util.h:28
void UTIL_calc_2d_direction(float32 aNorthVelocity, float32 aEastVelocity, char *aCardinalDirection, int aCardinalDirectionSize)
Determine the nearest cardinal aCardinalDirection.
Definition: util.cpp:692
sint32 time_of_week
Seconds since 12:00 AM Sunday.
Definition: garmin_types.h:146
void UTIL_convert_UTC_to_local(const time_type *aUtcTime, time_type *aLocalTime)
Converts a time_type from UTC to local time.
Definition: util.cpp:526
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
#define BASE_YEAR
The base year for Garmin dates.
Definition: util.h:22
#define max_uint_val(_t)
The maximum unsigned integer that can be stored in a type.
Definition: util_macros.h:77
uint32 time_type
Absolute time (number of seconds since 12/31/1989 12:00 am UTC)
Definition: garmin_types.h:97
#define PI
The ratio of a circle&#39;s circumference to its diameter.
Definition: util.h:16
#define DAYS_IN_4_YEARS
Number of days in four years.
Definition: util.h:25
sint16 hour
hour (0-65535), range required for correct ETE conversion
Definition: garmin_types.h:160
void UTIL_convert_local_to_UTC(const time_type *aLocalTime, time_type *aUtcTime)
Converts a time_type from local to UTC time.
Definition: util.cpp:549
Encapsulates the fields of a GPS time for conversion.
Definition: garmin_types.h:143