2929#include "bbatt.h"
3030#include "ttops.h"
3131#include "util.h"
32+ #include "ttblue.h"
3233
3334const char * PLEASE_SETCAP_ME =
3435 "**********************************************************\n"
@@ -228,12 +229,12 @@ read_gqf_status(TTDEV *ttd, int debug)
228229 time_t last_update = 0 ;
229230 uint8_t * fbuf ;
230231 int length ;
231- if ((length = tt_read_file (ttd , ttd -> files -> gps_status , debug , & fbuf )) < 0 ) {
232- fprintf (stderr , "WARNING: Could not read GPS status file 0x%08x from watch.\n" , ttd -> files -> gps_status );
232+ if ((length = tt_read_file (ttd , TTBLUE_FILE_GPS_STATUS , debug , & fbuf )) < 0 ) {
233+ fprintf (stderr , "WARNING: Could not read GPS status file 0x%08x from watch.\n" , TTBLUE_FILE_GPS_STATUS );
233234 last_update = -1 ;
234235 } else {
235236#ifdef DUMP_0x00020001
236- save_buf_to_file (make_tt_filename (ttd -> files -> gps_status , "bin" ), "wxb" , fbuf , length , 2 , true);
237+ save_buf_to_file (make_tt_filename (TTBLUE_FILE_GPS_STATUS , "bin" ), "wxb" , fbuf , length , 2 , true);
237238#endif
238239 if (length > 6 && (fbuf [0x02 ] | fbuf [0x03 ] | fbuf [0x04 ] | fbuf [0x05 ]) != 0 ) {
239240 struct tm tmp = { .tm_mday = fbuf [0x05 ], .tm_mon = fbuf [0x04 ]- 1 , .tm_year = (((int )fbuf [0x02 ])<<8 ) + fbuf [0x03 ] - 1900 };
@@ -529,23 +530,25 @@ int main(int argc, const char **argv)
529530 int length ;
530531
531532 fprintf (stderr , "Setting PHONE menu to '%s'.\n" , hostname );
532- tt_delete_file (ttd , ttd -> files -> hostname );
533- tt_write_file (ttd , ttd -> files -> hostname , false, (uint8_t * )hostname , strlen (hostname ), write_delay );
533+ tt_delete_file (ttd , TTBLUE_FILE_HOSTNAME1 );
534+ tt_write_file (ttd , TTBLUE_FILE_HOSTNAME1 , false, (uint8_t * )hostname , strlen (hostname ), write_delay );
535+ tt_delete_file (ttd , TTBLUE_FILE_HOSTNAME2 ); // Write name to two files as V1 and V2 devices seem to use different files
536+ tt_write_file (ttd , TTBLUE_FILE_HOSTNAME2 , false, (uint8_t * )hostname , strlen (hostname ), write_delay );
534537
535538#ifdef DUMP_0x000f20000
536- fprintf (stderr , "Reading preference file 0x%08x from watch...\n" , ttd -> files -> preference );
537- if ((length = tt_read_file (ttd , ttd -> files -> preference , debug , & fbuf )) < 0 ) {
538- fprintf (stderr , "WARNING: Could not read preferences file 0x%08x from watch.\n" , ttd -> files -> preference );
539+ fprintf (stderr , "Reading preference file 0x%08x from watch...\n" , TTBLUE_FILE_PREFERENCES_XML );
540+ if ((length = tt_read_file (ttd , TTBLUE_FILE_PREFERENCES_XML , debug , & fbuf )) < 0 ) {
541+ fprintf (stderr , "WARNING: Could not read preferences file 0x%08x from watch.\n" , TTBLUE_FILE_PREFERENCES_XML );
539542 } else {
540- save_buf_to_file (make_tt_filename (ttd -> files -> preference , "xml" ), "wxb" , fbuf , length , 2 , true);
543+ save_buf_to_file (make_tt_filename (TTBLUE_FILE_PREFERENCES_XML , "xml" ), "wxb" , fbuf , length , 2 , true);
541544 free (fbuf );
542545 }
543546#endif
544547
545548 if (set_time ) {
546- fprintf (stderr , "Checking watch settings manifest file 0x%08x...\n" , ttd -> files -> manifest );
547- if ((length = tt_read_file (ttd , ttd -> files -> manifest , debug , & fbuf )) < 0 ) {
548- fprintf (stderr , "WARNING: Could not read settings manifest file 0x%08x from watch!\n" , ttd -> files -> manifest );
549+ fprintf (stderr , "Checking watch settings manifest file 0x%08x...\n" , TTBLUE_FILE_MANIFEST1 );
550+ if ((length = tt_read_file (ttd , TTBLUE_FILE_MANIFEST1 , debug , & fbuf )) < 0 ) {
551+ fprintf (stderr , "WARNING: Could not read settings manifest file 0x%08x from watch!\n" , TTBLUE_FILE_MANIFEST1 );
549552 } else {
550553 // based on: https://github.com/ryanbinns/ttwatch/tree/master/manifest
551554 // the position of the UTC-offset in the manifest is 169 in all known firmware versions, so lazily hard-coded here for now
@@ -565,8 +568,8 @@ int main(int argc, const char **argv)
565568 if (btohl (* watch_timezone ) != lt -> tm_gmtoff ) {
566569 fprintf (stderr , " Changing timezone from UTC%+d to UTC%+ld.\n" , btohl (* watch_timezone ), lt -> tm_gmtoff );
567570 * watch_timezone = htobl (lt -> tm_gmtoff );
568- tt_delete_file (ttd , ttd -> files -> manifest );
569- tt_write_file (ttd , ttd -> files -> manifest , false, fbuf , length , write_delay );
571+ tt_delete_file (ttd , TTBLUE_FILE_MANIFEST1 );
572+ tt_write_file (ttd , TTBLUE_FILE_MANIFEST1 , false, fbuf , length , write_delay );
570573 needs_reboot = true;
571574 }
572575 }
@@ -576,15 +579,15 @@ int main(int argc, const char **argv)
576579
577580 if (get_activities ) {
578581 uint16_t * list ;
579- int n_files = tt_list_sub_files (ttd , ttd -> files -> activity_start , & list );
582+ int n_files = tt_list_sub_files (ttd , TTBLUE_FILE_TTBIN_DATA , & list );
580583
581584 if (n_files < 0 ) {
582585 fprintf (stderr , "Could not list activity files on watch!\n" );
583586 goto fail ;
584587 }
585588 fprintf (stderr , "Found %d activity files on watch.\n" , n_files );
586589 for (int ii = 0 ; ii < n_files ; ii ++ ) {
587- uint32_t fileno = ttd -> files -> activity_start + list [ii ];
590+ uint32_t fileno = TTBLUE_FILE_TTBIN_DATA + list [ii ];
588591
589592 fprintf (stderr , " Reading activity file 0x%08X ...\n" , fileno );
590593 term_title ("ttblue: Transferring activity %d/%d" , ii + 1 , n_files );
@@ -668,8 +671,8 @@ int main(int argc, const char **argv)
668671 goto fail ;
669672 } else {
670673 fclose (f );
671- tt_delete_file (ttd , ttd -> files -> quickgps );
672- result = tt_write_file (ttd , ttd -> files -> quickgps , debug , fbuf , length , write_delay );
674+ tt_delete_file (ttd , TTBLUE_FILE_GPSQUICKFIX_DATA );
675+ result = tt_write_file (ttd , TTBLUE_FILE_GPSQUICKFIX_DATA , debug , fbuf , length , write_delay );
673676 free (fbuf );
674677 if (result < 0 ) {
675678 fputs ("Failed to send QuickFixGPS update to watch.\n" , stderr );
@@ -678,7 +681,7 @@ int main(int argc, const char **argv)
678681 // official TomTom Android app seems to only issue this
679682 // "magic" update command when the GPS is brand new or
680683 // after a factory reset, or with 3x --update-gps
681- att_wrreq (ttd -> fd , ttd -> h -> cmd_status , BARRAY (0x05 , 0x01 , 0x00 , 0x01 ), 4 );
684+ att_wrreq (ttd -> fd , ttd -> h -> cmd_status , BARRAY (MSG_UPDATE_EPHEMERIS , 0x01 , 0x00 , 0x01 ), 4 );
682685
683686 time_t last_gqf_update = read_gqf_status (ttd , debug - 1 );
684687 if (last_gqf_update != -1 && last_gqf_update != 0 )
0 commit comments