20 #if( FMI_SUPPORT_A610 ) 42 static void modifyStatusChangeRecord(
bool (*locator)(
void * key, vector<string> & record),
void * key,
void (*updater)(
void * val, vector<string> & record),
void * val,
const char * source );
44 static void decodeDegreeFields(
uint32 & field_flags,
int start,
int end, ofstream & rawFile, vector<string> & record,
uint16 & fieldIdx,
char * format );
45 static void decodeUint32Fields(
uint32 & field_flags,
int start,
int end, ofstream & rawFile, vector<string> & record,
uint16 & fieldIdx,
char * format );
46 static void decodeUint16Fields(
uint32 & field_flags,
int start,
int end, ofstream & rawFile, vector<string> & record,
uint16 & fieldIdx,
char * format );
67 for(
int i=start; i<=end; i++ )
69 if( field_flags & ( 0x01 << i) )
71 rawFile.read( (
char*) &len, 1 );
74 rawFile.read( buf, len );
106 for(
int i=start; i<=end; i++ )
108 if( field_flags & ( 0x01 << i) )
110 rawFile.read( (
char*) &aTimestamp,
sizeof( aTimestamp ) );
111 if( aTimestamp == 0 )
132 if( field_flags & ( 0x01 << start) )
134 rawFile.read( (
char*) &aTimestamp,
sizeof( aTimestamp ) );
135 if( aTimestamp == 0 )
161 for(
int i=start; i<=end; i++ )
163 if( field_flags & ( 0x01 << i) )
165 rawFile.read( (
char*) &rawValue,
sizeof( rawValue ) );
167 sprintf( tmp, format, degrees );
184 for(
int i=start; i<=end; i++ )
186 if( field_flags & ( 0x01 << i) )
188 rawFile.read( (
char*) &value,
sizeof( value ) );
189 sprintf( tmp, format, value );
206 for(
int i=start; i<=end; i++ )
208 if( field_flags & ( 0x01 << i) )
210 rawFile.read( (
char*) &value,
sizeof( value ) );
211 sprintf( tmp, format, value );
232 while( fstream.good() && !fstream.eof() )
234 fstream.read( &c, 1 );
236 if (!inquotes && curstring.length()==0 && c==
'"')
241 else if (inquotes && c==
'"')
244 if ( fstream.peek()==
'"' )
247 curstring.push_back(c);
248 fstream.read( &c, 1 );
256 else if (!inquotes && c==delimiter)
259 record.push_back( curstring );
262 else if (!inquotes && (c==
'\r' || c==
'\n') )
264 if( c ==
'\r' && fstream.peek() ==
'\n' ) {
265 fstream.read( &c, 1 );
267 record.push_back( curstring );
268 return (
uint16) record.size();
272 curstring.push_back(c);
276 record.push_back( curstring );
277 return (
uint16) record.size();
286 return ( record[1].compare(
"0x01" ) == 0 && record[2].compare( (
char* ) key ) == 0 );
294 record[22] = (
char* ) val;
300 static void modifyStatusChangeRecord(
bool (*locator)(
void * key, vector<string> & record),
void * key,
void (*updater)(
void * val, vector<string> & record),
void * val,
const char * source)
302 ifstream origFile( source, ios_base::in | ios_base::binary );
303 if( !origFile.good() )
308 char tmpFileName[_MAX_PATH];
311 strncpy( tmpFileName, source, _MAX_PATH - 5 );
312 tmpFileName[_MAX_PATH - 5] =
'\0';
313 strcat( tmpFileName,
".tmp" );
315 CFile modFile( CString( tmpFileName ), CFile::modeCreate | CFile::modeWrite );
319 memset( &hdr, 0,
sizeof( hdr ) );
322 vector<string> record;
325 while( 1 < ( cellCount =
readCSVRecord( origFile, record ) ) )
327 if(
'#' != record[0][0] )
329 if ( locator( key, record ) )
331 updater( val, record );
336 for(
uint32 i=0; i<record.size()-1; i++ )
338 strncpy( cell, record[i].c_str(),
cnt_of_array( cell ) - 1 );
350 if( DeleteFile( CString( source ) ) )
352 MoveFile( CString( tmpFileName ), CString( source ) );
362 ifstream rawFile( source, ios_base::binary | ios_base::in );
363 if( !rawFile.good() )
369 memset( &hdr, 0,
sizeof( hdr ) );
373 map<time_type,time_type> verifiedStatusUpdates;
379 rawFile.seekg(
sizeof( hdr ) +
sizeof(
uint32 ), ios_base::beg );
381 for(
int i=0; i<3; i++ )
383 rawFile.read( len, 1 );
384 rawFile.read( tmp, (
int) len[0] );
385 tmp[(int)len[0]] = 0;
387 rawFile.seekg( 0, ios_base::beg );
391 sprintf(dest, destFormat, tmp);
392 if( !csvFile.Open( CString( dest ), CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate ) )
410 csvWriter.
WriteValue(
"Co-Driver first name" );
411 csvWriter.
WriteValue(
"Co-Driver last name" );
416 csvWriter.
WriteValue(
"Current odom. reading" );
424 while ( rawFile.good() && !rawFile.eof() )
427 rawFile.read( (
char* ) &hdr,
sizeof( hdr ) );
433 case DRIVER_ANNOTATION:
436 for(
int i = 0; i<15; i++)
445 case DRIVER_STATUS_CHANGE:
447 csvWriter.
WriteValue(
"Driver status change" );
448 for(
int i = 0; i<15; i++)
456 csvWriter.
WriteValue(
"Longitude of change" );
458 csvWriter.
WriteValue(
"Additional status flag" );
461 case DRIVER_VERIFIED_LOG:
463 csvWriter.
WriteValue(
"Driver verified log" );
464 for(
int i = 0; i<15; i++)
471 case DRIVER_COULD_NOT_VERIFY_LOG:
473 csvWriter.
WriteValue(
"Driver could not verify log" );
474 for(
int i = 0; i<15; i++)
481 case DRIVER_ADDED_NEW_SHIPMENT_ENTRY:
483 csvWriter.
WriteValue(
"Driver added new shipment entry" );
484 for(
int i = 0; i<15; i++)
492 csvWriter.
WriteValue(
"Shipment document number" );
496 case DRIVER_MODIFIED_EXISTING_SHIPMENT_ENTRY:
498 csvWriter.
WriteValue(
"Driver modified existing shipment entry" );
499 for(
int i = 0; i<15; i++)
507 csvWriter.
WriteValue(
"Shipment document number" );
511 case DRIVER_DELETED_SHIPMENT_ENTRY:
513 csvWriter.
WriteValue(
"Driver deleted shipment entry" );
514 for(
int i = 0; i<15; i++)
522 csvWriter.
WriteValue(
"Shipment document number" );
526 case PND_FAILURE_DETECTION:
528 csvWriter.
WriteValue(
"PND failure detection" );
529 for(
int i = 0; i<15; i++)
534 csvWriter.
WriteValue(
"Event error timestamp" );
542 sprintf( tmp,
"0x%.4x", hdr.
version );
548 sprintf( tmp,
"0x%.2x", hdr.
reason );
557 for (
int ii=0; ii < 32; ii++) {
559 TRACE1(
"field flag %d present\n", ii);
565 case DRIVER_ANNOTATION:
571 case DRIVER_STATUS_CHANGE:
580 case DRIVER_VERIFIED_LOG:
583 verifiedStatusUpdates[originalTimestamp] = recordTimestamp;
586 case DRIVER_COULD_NOT_VERIFY_LOG:
591 case DRIVER_ADDED_NEW_SHIPMENT_ENTRY:
598 case DRIVER_MODIFIED_EXISTING_SHIPMENT_ENTRY:
605 case DRIVER_DELETED_SHIPMENT_ENTRY:
612 case PND_FAILURE_DETECTION:
630 char originalTimestampString[30], verifiedTimestampString[30];
631 for( map<time_type,time_type>::iterator it = verifiedStatusUpdates.begin(); it != verifiedStatusUpdates.end(); ++it )
646 ASSERT(record[fieldIdx].length() <= UCHAR_MAX);
648 for(
int i=start; i<=end; i++ )
650 if( field_flags & ( 0x01 << i) )
652 if( fieldIdx < record.size() )
654 len[0] = (char) record[fieldIdx].length();
655 rawFile.write( len, 1 );
656 rawFile.write( record[fieldIdx].c_str(), (std::streamsize) record[fieldIdx].length() );
661 rawFile.write( len, 1 );
675 for(
int i=start; i<=end; i++ )
677 if( ( fieldIdx < record.size() ) && ( 0 < record[fieldIdx].length() ) )
679 sscanf_s( record[fieldIdx].c_str(), format, °rees );
681 rawFile.write( (
char* ) &rawValue,
sizeof( rawValue ) );
694 for(
int i=start; i<=end; i++ )
696 if( ( fieldIdx < record.size() ) && ( 0 < record[fieldIdx].length() ) )
698 if( 0 == strcmp(
"%x", format ) )
700 sscanf_s( record[fieldIdx].substr(2).c_str(), format, &value );
704 sscanf_s( record[fieldIdx].c_str(), format, &value );
706 rawFile.write( (
char* ) &value,
sizeof( value ) );
720 for(
int i=start; i<=end; i++ )
722 if( ( fieldIdx < record.size() ) && ( 0 < record[fieldIdx].length() ) )
724 sscanf_s( record[fieldIdx].substr(2).c_str(), format, &value );
725 actualValue = (
uint16) value;
726 rawFile.write( (
char* ) &actualValue,
sizeof( actualValue ) );
739 for(
int i=start; i<=end; i++ )
741 if( fieldIdx < record.size() )
744 if( 0 < record[fieldIdx].length() )
748 rawFile.write( (
char* ) ×tamp,
sizeof( timestamp ) );
756 for(
int i=start; i<=end && (
uint32)i<record.size(); i++ )
758 if( 0 < record[i].length() )
760 field_flags |= ( 0x01 << i );
771 ifstream csvFile( source, ios_base::in | ios_base::binary );
772 if( !csvFile.good() )
777 ofstream rawFile( dest, ios_base::out | ios_base::binary );
780 memset( &hdr, 0,
sizeof( hdr ) );
782 uint32 convertedRecords = 0;
784 COleDateTime timestamp;
785 COleDateTime cutoff = COleDateTime::GetCurrentTime();
786 cutoff -= COleDateTimeSpan(14,0,0,0);
787 vector<string> record;
789 while( 1 < ( cellCount =
readCSVRecord( csvFile, record ) ) )
791 if(
'#' == record[0][0] )
797 sscanf_s( record[fieldIdx++].substr(2).c_str(),
"%x", &hdr.
version );
801 sscanf_s( record[fieldIdx++].substr(2).c_str(),
"%x", &reason );
807 case DRIVER_STATUS_CHANGE:
813 if( !timestamp.ParseDateTime( CString( record[fieldIdx].c_str() ) ) )
818 if( timestamp < cutoff )
826 uint16 hdrFieldIdx = fieldIdx;
832 case DRIVER_ANNOTATION:
840 case DRIVER_STATUS_CHANGE:
848 case DRIVER_VERIFIED_LOG:
853 case DRIVER_COULD_NOT_VERIFY_LOG:
858 case DRIVER_ADDED_NEW_SHIPMENT_ENTRY:
863 case DRIVER_MODIFIED_EXISTING_SHIPMENT_ENTRY:
868 case DRIVER_DELETED_SHIPMENT_ENTRY:
873 case PND_FAILURE_DETECTION:
880 rawFile.write( (
char* ) &hdr,
sizeof( hdr ) );
889 case DRIVER_ANNOTATION:
897 case DRIVER_STATUS_CHANGE:
906 case DRIVER_VERIFIED_LOG:
911 case DRIVER_COULD_NOT_VERIFY_LOG:
916 case DRIVER_ADDED_NEW_SHIPMENT_ENTRY:
923 case DRIVER_MODIFIED_EXISTING_SHIPMENT_ENTRY:
930 case DRIVER_DELETED_SHIPMENT_ENTRY:
937 case PND_FAILURE_DETECTION:
950 return convertedRecords;
958 ifstream csvFile( source, ios_base::in | ios_base::binary );
959 if( !csvFile.good() )
967 memset( &hdr, 0,
sizeof( hdr ) );
970 vector<string> record;
973 while( 1 < ( cellCount =
readCSVRecord( csvFile, record ) ) )
975 if(
'#' != record[0][0] )
977 sscanf_s( record[1].substr(2).c_str(),
"%x", &reason );
978 if ( reason == (
uint32) type ) {
993 ifstream csvFile( source, ios_base::in | ios_base::binary );
994 if( !csvFile.good() )
1002 memset( &hdr, 0,
sizeof( hdr ) );
1005 vector<string> record;
1008 while( 1 < ( cellCount =
readCSVRecord( csvFile, record ) ) )
1010 if(
'#' != record[0][0] )
1012 sscanf_s( record[1].substr(2).c_str(),
"%x", &reason );
1013 if ( reason == (
uint32) type ) {
1014 if( index == count++ )
1016 visitor(
this, record, data );
1023 return( index == count-1 );
1035 dt.ParseDateTime( CString( cellValue.c_str() ) );
1044 timestamp = date + time;
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)
static void encodeUint16Fields(uint32 field_flags, int start, int end, ifstream &rawFile, CsvWriter &csvWriter, char *format)
Convert 2 byte unsigned int into 6 byte hex string.
uint8 minute
minute (0-59)
static void encodeDegreeFields(uint32 field_flags, int start, int end, ifstream &rawFile, CsvWriter &csvWriter, char *format)
Convert 4 byte signed int into degrees.
static void modifyStatusChangeRecord(bool(*locator)(void *key, vector< string > &record), void *key, void(*updater)(void *val, vector< string > &record), void *val, const char *source)
Function for finding and updating a record.
static time_type parseDateTime(std::string cellValue)
Convert date-time string to UTC timestamp.
static void encodeStringFields(uint32 field_flags, int start, int end, ifstream &rawFile, CsvWriter &csvWriter)
Convert 1 byte length and character stream into CSV cell.
void WriteValue(char *value)
bool convertAnnotation(std::vector< std::string > &record, fmi_driver_annotation_data_type *annotation)
Convert an Annotation record to structure sent to FMI device.
#define cnt_of_array(_a)
The number of elements in _a.
uint16 countRecords(const char *source, evt_log_reason type)
Count records by type.
Utility for converting between raw AOBRD data to human- readable CSV file. Used to attempt to auto-co...
static uint16 readCSVRecord(ifstream &fstream, vector< string > &record, char delimiter)
Convert CSV record into vector of strings.
struct date_time_data_type::_time time
void UTIL_convert_time_type_to_seconds(const date_time_data_type *aDateTime, time_type *aSeconds)
Converts a time_type to seconds since midnight.
static void encodeTimestampFields(uint32 field_flags, int start, int end, ifstream &rawFile, CsvWriter &csvWriter)
Convert time_type into human-readable formatted timestamp.
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).
signed short int sint16
16-bit signed integer
Date & time data type with separate fields for month, day, year, hour, minute, and second...
static void decodeTimestampFields(uint32 &field_flags, int start, int end, ofstream &rawFile, vector< string > &record, uint16 &fieldIdx)
Convert human-readable formatted timestamp into seconds.
double UTIL_convert_semicircles_to_degrees(sint32 aSemicircles)
Converts a latitude/longitude from semicircles to degrees.
static void checkFieldHeaders(uint32 &field_flags, int start, int end, vector< string > &record, uint16 &fieldIdx)
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.
time_type server_timestamp
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.
Data type for the Annotation Download Response Packet ID (0X110D) from server to client.
void convertToCsv(const char *source, const char *destFormat)
Convert raw file to CSV.
unsigned short int uint16
16-bit unsigned integer
static void decodeUint16Fields(uint32 &field_flags, int start, int end, ofstream &rawFile, vector< string > &record, uint16 &fieldIdx, char *format)
Convert 6 byte hex string into 2 byte unsigned int.
uint16 year
Real year (1990 means 1990!)
static void decodeStringFields(uint32 &field_flags, int start, int end, ofstream &rawFile, vector< string > &record, uint16 &fieldIdx)
Convert CSV fields into 1 byte length and character stream.
char server_annotation[60]
unsigned char uint8
8-bit unsigned integer
void updateEventBeingVerified(void *val, vector< string > &record)
callback for updating a verified Driver Status Change event
static void convertTimeTypeToString(time_type aTimestamp, char *full, int fullSize)
static void decodeUint32Fields(uint32 &field_flags, int start, int end, ofstream &rawFile, vector< string > &record, uint16 &fieldIdx, char *format)
Convert 10 byte hex string into 4 byte unsigned int.
bool locateEventBeingVerified(void *key, vector< string > &record)
callback for finding a Driver Status Change event in CSV file
static time_type encodeTimestampField(uint32 field_flags, int start, ifstream &rawFile, CsvWriter &csvWriter)
bool findRecordAt(const char *source, evt_log_reason type, uint16 index, bool(*visitor)(AobrdEventLogConverter *converter, std::vector< std::string > &record, void *data), void *data)
Visit records by type and index.
time_type server_start_time
time_type server_end_time
AobrdEventLogConverter()
Constructor.
void UTIL_convert_UTC_to_local(const time_type *aUtcTime, time_type *aLocalTime)
Converts a time_type from UTC to local time.
static void encodeUint32Fields(uint32 field_flags, int start, int end, ifstream &rawFile, CsvWriter &csvWriter, char *format)
Convert 4 byte unsigned int into 10 byte hex string.
unsigned long int uint32
32-bit unsigned integer
uint32 convertToRaw(const char *source, const char *dest)
Convert CSV file to raw.
uint32 time_type
Absolute time (number of seconds since 12/31/1989 12:00 am UTC)
sint16 hour
hour (0-65535), range required for correct ETE conversion
static void decodeDegreeFields(uint32 &field_flags, int start, int end, ofstream &rawFile, vector< string > &record, uint16 &fieldIdx, char *format)
Convert degrees into 4 byte signed int.
void UTIL_convert_local_to_UTC(const time_type *aLocalTime, time_type *aUtcTime)
Converts a time_type from local to UTC time.