25 static uint8 const sMonthDays[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
30 static uint32 const sYearDays[ 12 ] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
60 if( ( aDateTime->
date.
year % 4 ) == 0 )
84 ( ( aDateTime->
date.
year % 4 ) == 0 ) )
96 if( ( isLeapYear ==
TRUE ) &&
146 for( i = ( ( fourYearCount * 4 ) +
BASE_YEAR ); i < (int)aDateTime->
date.
year; i++ )
157 ( ( aDateTime->
date.
year % 4 ) == 0 ) )
169 if( ( aDateTime->
date.
year == 1989 ) &&
171 ( aDateTime->
date.
day == 31 ) )
191 return aDegrees * (double)(
PI / 180 );
208 return (
sint32)( aDegrees * (double)( ( 1 << 30 ) / 90 ) );
251 return aRadians * (double)( 180 /
PI );
264 return (
double)aSemicircles * 90 / ( 1 << 30 );
324 const char * aHexString,
329 static const char hex[] =
"0123456789abcdef";
330 const char * currentChar;
332 bool highNibble =
true;
336 currentChar = aHexString;
338 while( binaryIndex < aMaxBytes && *currentChar !=
'\0' )
340 hexPos = strchr( hex, tolower( *currentChar ) );
345 workByte = (
uint8)( ( hexPos - hex ) << 4 );
349 workByte += (
uint8)( hexPos - hex );
350 aBinaryData[binaryIndex++] = workByte;
352 highNibble = !highNibble;
382 static const char hex[] =
"0123456789abcdef";
384 for(
int i = 0; i < aNumBytes; i++ )
386 aOutput[2 * i] = hex[ aData[i] / 16 ];
387 aOutput[2 * i + 1] = hex[ aData[i] % 16 ];
389 aOutput[2 * aNumBytes] =
'\0';
412 const char * aHexString,
417 static const char hex[] =
"0123456789abcdef";
418 const char * currentChar;
421 uint8 binaryIndex = 0;
424 currentChar = aHexString;
426 while( binaryIndex < aMaxWords && *currentChar !=
'\0' )
428 hexPos = strchr( hex, tolower( *currentChar ) );
434 work = (
uint16)( hexPos - hex ) << 12;
437 work += (
uint16)( hexPos - hex ) << 8;
440 work += (
uint16)( hexPos - hex ) << 4;
443 work += (
uint16)( hexPos - hex );
444 aBinaryData[binaryIndex++] = work;
447 if( state > 3 ) state = 0;
476 for(
int i = 0; i < aLength; i++ )
478 if( aData[i] < 0 || !isprint( aData[i] ) )
499 if( strlen( aData ) == 0 )
505 _atoi64( aData ) < 0 )
510 for(
unsigned int i = 0; i < strlen( aData ); i++ )
512 if( aData[i] <
'0' || aData[i] >
'9' )
531 TIME_ZONE_INFORMATION tzinfo;
533 switch ( GetTimeZoneInformation( &tzinfo ) )
535 case TIME_ZONE_ID_DAYLIGHT:
536 *aLocalTime = *aUtcTime - ( ( tzinfo.Bias + tzinfo.DaylightBias ) *
SECONDS_PER_MINUTE );
539 *aLocalTime = *aUtcTime - ( ( tzinfo.Bias + tzinfo.StandardBias ) *
SECONDS_PER_MINUTE );
554 TIME_ZONE_INFORMATION tzinfo;
556 switch ( GetTimeZoneInformation( &tzinfo ) )
558 case TIME_ZONE_ID_DAYLIGHT:
559 *aUtcTime = *aLocalTime + ( ( tzinfo.Bias + tzinfo.DaylightBias ) *
SECONDS_PER_MINUTE );
562 *aUtcTime = *aLocalTime + ( ( tzinfo.Bias + tzinfo.StandardBias ) *
SECONDS_PER_MINUTE );
577 char * aResultString,
578 int aResultStringSize
581 boolean morning =
TRUE;
591 if( hour == 0 ) hour = 12;
594 sprintf_s( aResultString, aResultStringSize,
"%02d:%02d:%02d AM", hour, aDateTime->
time.
minute, aDateTime->
time.
second );
596 sprintf_s( aResultString, aResultStringSize,
"%02d:%02d:%02d PM", hour, aDateTime->
time.
minute, aDateTime->
time.
second );
608 time( &aCurrentTime );
610 gmtime_s( &aCurrentTm, &aCurrentTime );
627 + ( aTimeTm.tm_sec );
635 int leapDays = ( aTimeTm.tm_year - 88 ) / 4;
639 if( ( aTimeTm.tm_year % 4 == 0 ) &&
659 char * aResultString,
660 int aResultStringSize
663 sprintf_s( aResultString, aResultStringSize,
"%02d/%02d/%04d", aDateTime->
date.
month, aDateTime->
date.
day, aDateTime->
date.
year );
679 return sqrt( pow( (
double)aNorthVelocity, 2.0 ) +
680 pow( (
double)aEastVelocity, 2.0 ) );
695 char * aCardinalDirection,
696 int aCardinalDirectionSize
699 if( ( aNorthVelocity == 0 ) && ( aEastVelocity == 0 ) )
701 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"" );
705 double angle = atan2( (
double)aNorthVelocity, (
double)aEastVelocity );
708 if( angle > (
PI * -1/8 ) && angle < (
PI * 1/8 ) )
709 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"E" );
711 else if( angle >= (
PI * 1/8 ) && angle < (
PI * 3/8 ) )
712 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"NE" );
714 else if( angle >= (
PI * 3/8 ) && angle < (
PI * 5/8 ) )
715 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"N" );
717 else if( angle >= (
PI * 5/8 ) && angle < (
PI * 7/8 ) )
718 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"NW" );
720 else if( angle >= (
PI * 7/8 ) || angle < (
PI * -7/8 ) )
721 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"W" );
723 else if( angle >= (
PI * -7/8 ) && angle < (
PI * -5/8 ) )
724 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"SW" );
726 else if( angle >= (
PI * -5/8 ) && angle < (
PI * -3/8 ) )
727 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"S" );
729 else if( angle >= (
PI * -3/8 ) && angle < (
PI * -1/8 ) )
730 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"SE" );
732 strcpy_s( aCardinalDirection, aCardinalDirectionSize,
"??" );
743 gzFile zipFile = gzopen( original,
"rb" );
744 if ( NULL != zipFile)
746 CString newFilename( original );
747 newFilename += _T(
".inflated" );
749 if ( newFile.Open( newFilename, CFile::modeCreate | CFile::modeWrite ) )
753 while ( ( len = gzread( zipFile, buf, 1024 ) ) > 0 )
755 newFile.Write( (
const void * ) buf, ( UINT ) len );
763 return CString( original );
771 BOOL
unzip(
char * original, LPCTSTR destination )
774 gzFile zipFile = gzopen( original,
"rb" );
775 if ( NULL != zipFile)
778 if ( newFile.Open( destination, CFile::modeCreate | CFile::modeWrite ) )
782 while ( ( len = gzread( zipFile, buf, 1024 ) ) > 0 )
784 newFile.Write( (
const void * ) buf, ( UINT ) len );
793 return CopyFile( CString( original ), destination,
FALSE );
799 void write(CFile * catalog,
char * text)
801 catalog->Write( (
const void * )text, ( UINT ) strlen( text ) );
807 void write(CFile * catalog, LPCTSTR wText)
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 );
820 void write(CFile * catalog, LPCTSTR wText,
int maxLength )
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 )
828 catalog->Write( (
const void * ) text, maxLength-1 );
831 catalog->Write( (
const void * ) text, textLen-1 );
833 catalog->Write(
"\0", 1 );
double UTIL_calc_2d_speed(float32 aNorthVelocity, float32 aEastVelocity)
Determine the two-dimensional velocity.
sint32 UTIL_convert_degrees_to_semicircles(double aDegrees)
Converts a latitude/longitude from degrees to semicircles.
struct date_time_data_type::_date date
uint8 second
second (0-59)
void UTIL_convert_gps_time_to_seconds(const gps_time_type *aGpsTime, time_type *aSeconds)
Converts from gps_time to Garmin time.
#define returnif_v(_check, _value)
Return a value if a condition is true.
uint8 minute
minute (0-59)
#define DECEMBER
One-based month number for December.
void UTIL_format_date_string(const date_time_data_type *aDateTime, char *aResultString, int aResultStringSize)
Format a date as a string.
void UTIL_convert_seconds_to_gps_time(const time_type *aSeconds, gps_time_type *aGpsTime)
Converts Garmin time to a structure containing GPS time.
bool UTIL_data_is_uint32(const char *aData)
Determine whether an array of characters consists only of numeric, and that the value when converted ...
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.
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.
double UTIL_convert_radians_to_degrees(double aRadians)
Converts a latitude/longitude from radians to degrees.
struct date_time_data_type::_time time
time_type UTIL_get_garmin_time(tm aTimeTm)
Get the current server time in Garmin format.
#define SECONDS_PER_DAY
Number of seconds in one day.
void UTIL_convert_time_type_to_seconds(const date_time_data_type *aDateTime, time_type *aSeconds)
Converts a time_type to seconds since midnight.
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).
double UTIL_convert_degrees_to_radians(double aDegrees)
Converts a latitude/longitude from degrees to radians.
signed short int sint16
16-bit signed integer
Date & time data type with separate fields for month, day, year, hour, minute, and second...
double UTIL_convert_semicircles_to_degrees(sint32 aSemicircles)
Converts a latitude/longitude from semicircles to degrees.
#define MARCH
One-based month number for March.
uint16 UTIL_hex_to_uint8(const char *aHexString, uint8 *aBinaryData, uint16 aMaxBytes)
Convert a hexadecimal ASCII string to an array of uint8.
float float32
32-bit IEEE-format floating point data. (1 sign bit, 8 exponent bits, and 23 mantissa bits) ...
sint32 week_number_days
Days since December 31st, 1989 to beginning of week (i.e., this is a Sunday)
CString unzip(char *original)
This function will uncompress a file into a new file.
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.
void write(CFile *catalog, char *text)
This function is a helper for writing text to a file.
void UTIL_uint8_to_hex(const uint8 *aData, char *aOutput, uint8 aNumBytes)
Convert from binary to a hexadecimal string.
signed long int sint32
32-bit signed integer
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.
bool UTIL_data_is_printable(const char *aData, int aLength)
Determine whether an array of characters consists only of printable ASCII.
unsigned short int uint16
16-bit unsigned integer
#define FEBRUARY
One-based month number for February.
#define SECONDS_PER_HOUR
Number of seconds in one hour.
uint16 year
Real year (1990 means 1990!)
#define SECONDS_PER_MINUTE
Number of seconds in one minute.
static uint8 const sMonthDays[12]
Number of days in each month in a non-leap year.
unsigned char uint8
8-bit unsigned integer
static uint32 const sYearDays[12]
Cumulative number of days in prior months in a non-leap year.
time_type UTIL_get_current_garmin_time()
Get the current server time in Garmin format.
#define DAYS_IN_1_YEAR
Number of days in a non-leap year.
void UTIL_calc_2d_direction(float32 aNorthVelocity, float32 aEastVelocity, char *aCardinalDirection, int aCardinalDirectionSize)
Determine the nearest cardinal aCardinalDirection.
sint32 time_of_week
Seconds since 12:00 AM Sunday.
void UTIL_convert_UTC_to_local(const time_type *aUtcTime, time_type *aLocalTime)
Converts a time_type from UTC to local time.
unsigned long int uint32
32-bit unsigned integer
#define BASE_YEAR
The base year for Garmin dates.
#define max_uint_val(_t)
The maximum unsigned integer that can be stored in a type.
uint32 time_type
Absolute time (number of seconds since 12/31/1989 12:00 am UTC)
#define PI
The ratio of a circle's circumference to its diameter.
#define DAYS_IN_4_YEARS
Number of days in four years.
sint16 hour
hour (0-65535), range required for correct ETE conversion
void UTIL_convert_local_to_UTC(const time_type *aLocalTime, time_type *aUtcTime)
Converts a time_type from local to UTC time.
Encapsulates the fields of a GPS time for conversion.