Garmin Fleet Management Controller
2.19.0
|
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <zlib.h>
#include "util.h"
Go to the source code of this file.
Functions | |
CString | unzip (char *original) |
This function will uncompress a file into a new file. More... | |
BOOL | unzip (char *original, LPCTSTR destination) |
This function will uncompress a file into a specified file. More... | |
void | UTIL_calc_2d_direction (float32 aNorthVelocity, float32 aEastVelocity, char *aCardinalDirection, int aCardinalDirectionSize) |
Determine the nearest cardinal aCardinalDirection. More... | |
double | UTIL_calc_2d_speed (float32 aNorthVelocity, float32 aEastVelocity) |
Determine the two-dimensional velocity. More... | |
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. More... | |
double | UTIL_convert_degrees_to_radians (double aDegrees) |
Converts a latitude/longitude from degrees to radians. More... | |
sint32 | UTIL_convert_degrees_to_semicircles (double aDegrees) |
Converts a latitude/longitude from degrees to semicircles. More... | |
void | UTIL_convert_gps_time_to_seconds (const gps_time_type *aGpsTime, time_type *aSeconds) |
Converts from gps_time to Garmin time. More... | |
void | UTIL_convert_local_to_UTC (const time_type *aLocalTime, time_type *aUtcTime) |
Converts a time_type from local to UTC time. More... | |
double | UTIL_convert_radians_to_degrees (double aRadians) |
Converts a latitude/longitude from radians to degrees. More... | |
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. More... | |
void | UTIL_convert_seconds_to_gps_time (const time_type *aSeconds, gps_time_type *aGpsTime) |
Converts Garmin time to a structure containing GPS time. More... | |
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). More... | |
double | UTIL_convert_semicircles_to_degrees (sint32 aSemicircles) |
Converts a latitude/longitude from semicircles to degrees. More... | |
void | UTIL_convert_time_type_to_seconds (const date_time_data_type *aDateTime, time_type *aSeconds) |
Converts a time_type to seconds since midnight. More... | |
void | UTIL_convert_UTC_to_local (const time_type *aUtcTime, time_type *aLocalTime) |
Converts a time_type from UTC to local time. More... | |
bool | UTIL_data_is_printable (const char *aData, int aLength) |
Determine whether an array of characters consists only of printable ASCII. More... | |
bool | UTIL_data_is_uint32 (const char *aData) |
Determine whether an array of characters consists only of numeric, and that the value when converted from a string is in the valid range for a uint32. More... | |
void | UTIL_format_date_string (const date_time_data_type *aDateTime, char *aResultString, int aResultStringSize) |
Format a date as a string. More... | |
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. More... | |
time_type | UTIL_get_current_garmin_time () |
Get the current server time in Garmin format. More... | |
time_type | UTIL_get_garmin_time (tm aTimeTm) |
Get the current server time in Garmin format. More... | |
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. More... | |
uint16 | UTIL_hex_to_uint8 (const char *aHexString, uint8 *aBinaryData, uint16 aMaxBytes) |
Convert a hexadecimal ASCII string to an array of uint8. More... | |
void | UTIL_uint8_to_hex (const uint8 *aData, char *aOutput, uint8 aNumBytes) |
Convert from binary to a hexadecimal string. More... | |
void | write (CFile *catalog, char *text) |
This function is a helper for writing text to a file. More... | |
void | write (CFile *catalog, LPCTSTR wText) |
This function is a helper for writing Unicode text to a file. More... | |
void | write (CFile *catalog, LPCTSTR wText, int maxLength) |
This function is a helper for writing Unicode text to a file. More... | |
Variables | |
static uint8 const | sMonthDays [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
Number of days in each month in a non-leap year. More... | |
static uint32 const | sYearDays [12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 } |
Cumulative number of days in prior months in a non-leap year. More... | |
CString unzip | ( | char * | original | ) |
This function will uncompress a file into a new file.
If the original file was not gz compressed then the result file will be an exact copy of the original
Definition at line 741 of file util.cpp.
Referenced by CIftaDlg::OnEventIftaFileTransferReceived(), and CCustomFormsDlg::OnFormSubmitReceived().
BOOL unzip | ( | char * | original, |
LPCTSTR | destination | ||
) |
void UTIL_calc_2d_direction | ( | float32 | aNorthVelocity, |
float32 | aEastVelocity, | ||
char * | aCardinalDirection, | ||
int | aCardinalDirectionSize | ||
) |
Determine the nearest cardinal aCardinalDirection.
aNorthVelocity | The north velocity (negative is south) |
aEastVelocity | The aEastVelocity velocity (negative is west) |
aCardinalDirection | A buffer of at least 3 bytes to contain the cardinal direction, which is one of "N", "E", "S", "W", "NE", "NW", "SE", "SW", or "" |
Definition at line 692 of file util.cpp.
References PI.
Referenced by FmiApplicationLayer::calculate2DVelocity(), and UTIL_calc_2d_speed().
Determine the two-dimensional velocity.
aNorthVelocity | The north velocity (negative is south) |
aEastVelocity | The east velocity (negative is west) |
Definition at line 674 of file util.cpp.
References UTIL_calc_2d_direction().
Referenced by FmiApplicationLayer::calculate2DVelocity(), and UTIL_format_date_string().
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.
aDateTime | Structure containing year, month, and day |
aSeconds | Number of seconds since Dec 31, 1989 |
Definition at line 114 of file util.cpp.
References BASE_YEAR, date_time_data_type::date, date_time_data_type::_date::day, DAYS_IN_1_YEAR, DAYS_IN_4_YEARS, FALSE, FEBRUARY, date_time_data_type::_date::month, returnif_v, SECONDS_PER_DAY, sYearDays, TRUE, UTIL_convert_degrees_to_radians(), and date_time_data_type::_date::year.
Referenced by convertDateTime(), convertToTimeType(), parseDateTime(), and UTIL_convert_seconds_to_date_type().
double UTIL_convert_degrees_to_radians | ( | double | aDegrees | ) |
Converts a latitude/longitude from degrees to radians.
aDegrees | The latitude/longitude in degrees |
Definition at line 187 of file util.cpp.
References PI, and UTIL_convert_degrees_to_semicircles().
Referenced by UTIL_convert_date_time_to_seconds().
sint32 UTIL_convert_degrees_to_semicircles | ( | double | aDegrees | ) |
Converts a latitude/longitude from degrees to semicircles.
2^31 semicircles equal 180 degrees. The conversion uses the equivalent 2^30 semicircles per 90 degrees to avoid overflow.
aDegrees | The latitude/longitude in degrees |
Definition at line 204 of file util.cpp.
References UTIL_convert_seconds_to_gps_time().
Referenced by decodeDegreeFields(), CStopNewDlg::OnBnClickedOk(), FmiApplicationLayer::sendA602Stop(), FmiApplicationLayer::sendEnablePvtCommand(), FmiApplicationLayer::sendWaypoint(), and UTIL_convert_degrees_to_radians().
void UTIL_convert_gps_time_to_seconds | ( | const gps_time_type * | aGpsTime, |
time_type * | aSeconds | ||
) |
Converts from gps_time to Garmin time.
aGpsTime | Structure containing week number and time of week |
aSeconds | The Garmin time (seconds since Dec. 31, 1989 UTC) |
Definition at line 233 of file util.cpp.
References SECONDS_PER_DAY, gps_time_type::time_of_week, and gps_time_type::week_number_days.
Referenced by FmiApplicationLayer::rx(), and UTIL_convert_seconds_to_gps_time().
Converts a time_type from local to UTC time.
[in] | aUtcTime | The UTC time as a time_type. |
[out] | aLocalTime | The local time as a time_type. |
Definition at line 549 of file util.cpp.
References SECONDS_PER_MINUTE, and UTIL_format_time_string().
Referenced by convertDateTime(), convertToTimeType(), parseDateTime(), and UTIL_convert_UTC_to_local().
double UTIL_convert_radians_to_degrees | ( | double | aRadians | ) |
Converts a latitude/longitude from radians to degrees.
aRadians | The latitude/longitude in radians |
Definition at line 247 of file util.cpp.
References PI, and UTIL_convert_semicircles_to_degrees().
Referenced by FmiLogParser::getPacketDetail(), and FmiApplicationLayer::rx().
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.
aSeconds | Number of seconds since Dec 31, 1989 |
aDateTime | Structure containing year, month, and day |
Definition at line 39 of file util.cpp.
References BASE_YEAR, date_time_data_type::date, date_time_data_type::_date::day, DAYS_IN_1_YEAR, DAYS_IN_4_YEARS, DECEMBER, FALSE, FEBRUARY, MARCH, date_time_data_type::_date::month, SECONDS_PER_DAY, sMonthDays, sYearDays, TRUE, UTIL_convert_date_time_to_seconds(), and date_time_data_type::_date::year.
Referenced by convertFromTimeType(), convertTimeTypeToString(), FmiLogParser::formatTime(), and FmiApplicationLayer::rx().
void UTIL_convert_seconds_to_gps_time | ( | const time_type * | aSeconds, |
gps_time_type * | aGpsTime | ||
) |
Converts Garmin time to a structure containing GPS time.
aSeconds | The Garmin time (seconds since Dec. 31, 1989 UTC) |
aGpsTime | Structure containing week number and time of week |
Definition at line 218 of file util.cpp.
References SECONDS_PER_DAY, gps_time_type::time_of_week, UTIL_convert_gps_time_to_seconds(), and gps_time_type::week_number_days.
Referenced by UTIL_convert_degrees_to_semicircles().
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).
aSeconds | The Garmin time to convert |
aDateTime | The output structure |
Definition at line 274 of file util.cpp.
References date_time_data_type::_time::hour, date_time_data_type::_time::minute, date_time_data_type::_time::second, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, date_time_data_type::time, and UTIL_convert_time_type_to_seconds().
Referenced by convertFromTimeType(), convertTimeTypeToString(), FmiLogParser::formatTime(), CDashcamNtfctnFromClient::init(), CTxtMsgFromClient::OnInitDialog(), FmiApplicationLayer::rx(), and UTIL_convert_semicircles_to_degrees().
double UTIL_convert_semicircles_to_degrees | ( | sint32 | aSemicircles | ) |
Converts a latitude/longitude from semicircles to degrees.
aSemicircles | The latitude/longitude in semicircles |
Definition at line 260 of file util.cpp.
References UTIL_convert_seconds_to_time_type().
Referenced by encodeDegreeFields(), FmiLogParser::formatFmiPacket(), FmiLogParser::formatLatitude(), FmiLogParser::formatLongitude(), FmiLogParser::getPacketDetail(), CDashcamNtfctnFromClient::init(), CTxtMsgFromClient::OnInitDialog(), FmiApplicationLayer::rx(), and UTIL_convert_radians_to_degrees().
void UTIL_convert_time_type_to_seconds | ( | const date_time_data_type * | aDateTime, |
time_type * | aSeconds | ||
) |
Converts a time_type to seconds since midnight.
aDateTime | The structure containing hours, minutes, seconds |
aSeconds | The number of seconds since midnight. |
Definition at line 295 of file util.cpp.
References date_time_data_type::_time::hour, date_time_data_type::_time::minute, date_time_data_type::_time::second, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, date_time_data_type::time, and UTIL_hex_to_uint8().
Referenced by convertDateTime(), convertToTimeType(), parseDateTime(), and UTIL_convert_seconds_to_time_type().
Converts a time_type from UTC to local time.
[in] | aUtcTime | The UTC time as a time_type. |
[out] | aLocalTime | The local time as a time_type. |
Definition at line 526 of file util.cpp.
References SECONDS_PER_MINUTE, and UTIL_convert_local_to_UTC().
Referenced by convertFromTimeType(), convertTimeTypeToString(), FmiLogParser::formatTime(), CDashcamNtfctnFromClient::init(), CTxtMsgFromClient::OnInitDialog(), FmiApplicationLayer::rx(), and UTIL_data_is_uint32().
bool UTIL_data_is_printable | ( | const char * | aData, |
int | aLength | ||
) |
Determine whether an array of characters consists only of printable ASCII.
Uses isprint().
[in] | aData | The character array to test. |
[in] | aLength | The number of characters to test. |
Definition at line 471 of file util.cpp.
References UTIL_data_is_uint32().
Referenced by CGpiQueryDlg::OnGpiInfoReceived(), MessageId::toCString(), and UTIL_hex_to_uint16().
bool UTIL_data_is_uint32 | ( | const char * | aData | ) |
Determine whether an array of characters consists only of numeric, and that the value when converted from a string is in the valid range for a uint32.
[in] | aData | The character array to test. |
Definition at line 495 of file util.cpp.
References max_uint_val, and UTIL_convert_UTC_to_local().
Referenced by CDriverIdAndStatusDlg::OnEnChangeEditSet(), CStopNewDlg::OnFormChanged(), and UTIL_data_is_printable().
void UTIL_format_date_string | ( | const date_time_data_type * | aDateTime, |
char * | aResultString, | ||
int | aResultStringSize | ||
) |
Format a date as a string.
Formats the date portion of aDateTime as a string, in MM/DD/YYYY format
aDateTime | The date to format. |
aResultString | Pointer to a char[11] or longer to contain the formatted date. |
Definition at line 657 of file util.cpp.
References date_time_data_type::date, date_time_data_type::_date::day, date_time_data_type::_date::month, UTIL_calc_2d_speed(), and date_time_data_type::_date::year.
Referenced by FmiLogParser::formatTime(), FmiApplicationLayer::rx(), and UTIL_get_garmin_time().
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.
[in] | aDateTime | The structure containing the time. |
[out] | aResultString | A null-terminated ASCII string of the form "HH:MM:SS AA" (hours, minutes, seconds, AM/PM, respectively). |
Definition at line 575 of file util.cpp.
References FALSE, date_time_data_type::_time::hour, date_time_data_type::_time::minute, date_time_data_type::_time::second, date_time_data_type::time, and TRUE.
Referenced by FmiLogParser::formatTime(), CDashcamNtfctnFromClient::init(), CTxtMsgFromClient::OnInitDialog(), FmiApplicationLayer::rx(), and UTIL_convert_local_to_UTC().
time_type UTIL_get_current_garmin_time | ( | void | ) |
Get the current server time in Garmin format.
Definition at line 603 of file util.cpp.
References UTIL_get_garmin_time().
Referenced by FmiApplicationLayer::beginA611LongTextMessage(), CFeatureDlg::OnBnClickedOk(), CStopNewDlg::OnBnClickedOk(), CDashcamDlg::OnBnClickedSetLock(), FmiApplicationLayer::sendA602Stop(), FmiApplicationLayer::sendA602TextMessage(), FmiApplicationLayer::sendA603Stop(), FmiApplicationLayer::sendA604TextMessage(), FmiApplicationLayer::sendA607DriverIdUpdate(), FmiApplicationLayer::sendA607DriverStatusUpdate(), FmiApplicationLayer::sendDriverIdUpdate(), FmiApplicationLayer::sendDriverStatusUpdate(), and CMapViewerDlg::sendRouteToDevice().
time_type UTIL_get_garmin_time | ( | tm | aTimeTm | ) |
Get the current server time in Garmin format.
Definition at line 619 of file util.cpp.
References DAYS_IN_1_YEAR, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, sYearDays, and UTIL_format_date_string().
Referenced by UTIL_get_current_garmin_time().
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.
For example, given a hex string "01020304" and aMaxWords 2, the output will be the equivalent of { 258, 772 } decimal.
[in] | aHexString | The ASCII null-terminated string containing the hex to convert. |
[out] | aBinaryData | Pointer to an array of uint16 to contain the output. |
[in] | aMaxWords | The maximum number of words to convert. |
Definition at line 411 of file util.cpp.
References UTIL_data_is_printable().
Referenced by CFmiPcAppDlg::OnBnClickedSend(), and UTIL_uint8_to_hex().
Convert a hexadecimal ASCII string to an array of uint8.
[in] | aHexString | The hexadecimal string to convert. May be null-terminated. aHexString should not contain any prefix; only the digits 0-9 and a-f may be present. |
[out] | aBinaryData | An array of uint8 to receive the output. This array's size must be at least max_bytes. |
[in] | aMaxBytes | The maximum number of bytes to convert. If aHexString is not null-terminated its length must be at least 2 * max_bytes. |
Definition at line 323 of file util.cpp.
References UTIL_uint8_to_hex().
Referenced by FmiLogParser::getPacketDetail(), FmiLogParser::getPacketTitle(), MessageId::MessageId(), CFileTransferDlg::OnBnClickedOk(), CFmiPcAppDlg::OnBnClickedSend(), FmiLogParser::resendPacket(), FmiApplicationLayer::rx(), and UTIL_convert_time_type_to_seconds().
Convert from binary to a hexadecimal string.
Converts an array of uint8 values to a displayable string, one octet (uint8) at a time. No prefix is included in the output. For example, given a null-terminated ASCII string "ABC" and aNumBytes = 4, the output would be the string "41424300".
[in] | aData | The binary data. |
[out] | aOutput | The null-terminated output string. This must be a buffer of at least (2 * aNumBytes + 1) characters. |
[in] | aNumBytes | The number of bytes to convert. |
Definition at line 376 of file util.cpp.
References UTIL_hex_to_uint16().
Referenced by CGpiQueryDlg::OnGpiInfoReceived(), MessageId::toCString(), and UTIL_hex_to_uint8().
void write | ( | CFile * | catalog, |
char * | text | ||
) |
void write | ( | CFile * | catalog, |
LPCTSTR | wText | ||
) |
void write | ( | CFile * | catalog, |
LPCTSTR | wText, | ||
int | maxLength | ||
) |
|
static |
Number of days in each month in a non-leap year.
Definition at line 25 of file util.cpp.
Referenced by UTIL_convert_seconds_to_date_type().
|
static |
Cumulative number of days in prior months in a non-leap year.
Definition at line 30 of file util.cpp.
Referenced by UTIL_convert_date_time_to_seconds(), UTIL_convert_seconds_to_date_type(), and UTIL_get_garmin_time().