Skip to content

Commit 2f5cd40

Browse files
committed
Move definitions into new file ttblue.h
Remove structs with files as they are mostly identical between V1 and V2 devices. Use similar format as the ttwatch project do, to simplify a potential future merge of the projects. Some interesting information: * There seem to be 11 bluetooth commands in total used by the android app * There are at least 3 types of notifications: phone call, text message and voice mail/misc.(?)
1 parent 31e9e8d commit 2f5cd40

File tree

4 files changed

+69
-45
lines changed

4 files changed

+69
-45
lines changed

ttblue.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "bbatt.h"
3030
#include "ttops.h"
3131
#include "util.h"
32+
#include "ttblue.h"
3233

3334
const 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)

ttblue.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef __TTBLUE_H__
2+
#define __TTBLUE_H__
3+
/*****************************************************************************/
4+
5+
/******************************************************************************
6+
* Messages *
7+
******************************************************************************/
8+
#define MSG_OPEN_FILE_WRITE (0x02)
9+
#define MSG_WRITE (0x00)
10+
#define MSG_READ (0x01)
11+
#define MSG_CANCEL_TRANSFER (0x02)
12+
#define MSG_LIST_FILES (0x03)
13+
#define MSG_DELETE (0x04)
14+
#define MSG_UPDATE_EPHEMERIS (0x05) // Used on the quickgps file
15+
#define MSG_UPDATE_GOLF_MAPS (0x06) // No idea how this one works
16+
#define MSG_RESET_DEVICE (0x07)
17+
#define MSG_SET_TIME (0x08)
18+
#define MSG_UIPROD (0x09) // Used on the rest_proto_file and for phone notifications
19+
#define MSG_WRITE_RECOVERABLE (0x0a) // Used on V2 devices instead of MSG_WRITE
20+
#define MSG_READ_RECOVERABLE (0x0b) // Used on V2 devices instead of MSG_READ
21+
22+
/******************************************************************************
23+
* File IDs *
24+
******************************************************************************/
25+
#define TTBLUE_FILE_NOTIFICATION (0x00b50000) // for text messages, phone calls
26+
#define TTBLUE_FILE_GPS_STATUS (0x00020001)
27+
#define TTBLUE_FILE_HOSTNAME1 (0x00020002) // Hostname on V1 devices
28+
#define TTBLUE_FILE_HOSTNAME2 (0x00020003) // Hostname on V2 devices (offical
29+
// tomtom app only sets this one)
30+
#define TTBLUE_FILE_GOLF_MANIFEST (0x00b00000)
31+
#define TTBLUE_FILE_STEP_BUCKET (0x00b10000)
32+
#define TTBLUE_FILE_GOLF_SCORECARDS (0x00940000) // Also called GOLF_ROUNDS?
33+
#define TTBLUE_FILE_REST_PROTO_FILE (0x00890000) // Only file uiprod command is used
34+
// on except notification files
35+
#define TTBLUE_FILE_FIRMWARE_CHUNK (0x00fd0000) // Used when doing OTA updates?
36+
#define TTBLUE_FILE_BRIDGEHEAD (0x00000000) // ??
37+
#define TTBLUE_FILE_MANIFEST1 (0x00850000)
38+
#define TTBLUE_FILE_PREFERENCES_XML (0x00f20000)
39+
#define TTBLUE_FILE_TTBIN_DATA (0x00910000)
40+
#define TTBLUE_FILE_GPSQUICKFIX_DATA (0x00010100)
41+
42+
#endif // __TTBLUE_H__

ttops.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,13 @@
1414
#include "util.h"
1515
#include "ttops.h"
1616
#include "version.h"
17+
#include "ttblue.h"
1718

1819
/****************************************************************************/
1920

2021
struct tt_handles v1_handles = { .ppcp=0x0b, .passcode=0x32, .magic=0x35, .cmd_status=0x25, .length=0x28, .transfer=0x2b, .check=0x2e };
2122
struct tt_handles v2_handles = { .ppcp=0, .passcode=0x82, .magic=0x85, .cmd_status=0x72, .length=0x75, .transfer=0x78, .check=0x7b };
2223

23-
struct tt_files v1_files = {
24-
.hostname = 0x00020002,
25-
.preference = 0x00f20000,
26-
.manifest = 0x00850000,
27-
.activity_start = 0x00910000,
28-
.gps_status = 0x00020001,
29-
.quickgps = 0x00010100
30-
};
31-
32-
struct tt_files v2_files = {
33-
.hostname = 0x00020003,
34-
.preference = 0x00f20000,
35-
.manifest = 0x00850000,
36-
.activity_start = 0x00910000,
37-
.gps_status = 0x00020001,
38-
.quickgps = 0x00010100
39-
};
40-
4124
struct ble_dev_info v1_info[] = {
4225
{ 0x001e, "maker" },
4326
{ 0x0016, "serial" },
@@ -98,7 +81,6 @@ tt_device_init(int protocol_version, int fd) {
9881
d->oldest_tested_firmware = VERSION_TUPLE(1,8,34);
9982
d->newest_tested_firmware = VERSION_TUPLE(1,8,46);
10083
d->tested_models = tested_models_v1;
101-
d->files = &v1_files;
10284
break;
10385
case 2:
10486
d->h = &v2_handles;
@@ -108,7 +90,6 @@ tt_device_init(int protocol_version, int fd) {
10890
// @drkingpo confirmed v1.2.0 works now (see issue #5)
10991
// @Grimler91 tested 1.7.62 and 1.7.64.
11092
d->tested_models = tested_models_v2;
111-
d->files = &v2_files;
11293
break;
11394
default:
11495
return NULL;
@@ -266,7 +247,7 @@ tt_read_file(TTDEV *d, uint32_t fileno, int debug, uint8_t **buf)
266247
if (fileno>>24)
267248
return -EINVAL;
268249

269-
uint8_t cmd[] = {1, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
250+
uint8_t cmd[] = {MSG_READ, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
270251
att_wrreq(d->fd, d->h->cmd_status, cmd, sizeof cmd);
271252
if (EXPECT_uint32(d, d->h->cmd_status, 1) < 0)
272253
goto prealloc_fail;
@@ -347,7 +328,7 @@ tt_write_file(TTDEV *d, uint32_t fileno, int debug, const uint8_t *buf, uint32_t
347328
if (fileno>>24)
348329
return -EINVAL;
349330

350-
uint8_t cmd[] = {0, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
331+
uint8_t cmd[] = {MSG_WRITE, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
351332
att_wrreq(d->fd, d->h->cmd_status, cmd, sizeof cmd);
352333
if (EXPECT_uint32(d, d->h->cmd_status, 1) < 0)
353334
return -1;
@@ -446,7 +427,7 @@ tt_delete_file(TTDEV *d, uint32_t fileno)
446427
if (fileno>>24)
447428
return -EINVAL;
448429

449-
uint8_t cmd[] = {4, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
430+
uint8_t cmd[] = {MSG_DELETE, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
450431
att_wrreq(d->fd, d->h->cmd_status, cmd, sizeof cmd);
451432
if (EXPECT_uint32(d, d->h->cmd_status, 1) < 0)
452433
return -1;
@@ -471,7 +452,7 @@ tt_list_sub_files(TTDEV *d, uint32_t fileno, uint16_t **outlist)
471452
if (fileno>>24)
472453
return -EINVAL;
473454

474-
uint8_t cmd[] = {3, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
455+
uint8_t cmd[] = {MSG_LIST_FILES, (fileno>>16)&0xff, fileno&0xff, (fileno>>8)&0xff};
475456
att_wrreq(d->fd, d->h->cmd_status, cmd, sizeof cmd);
476457
if (EXPECT_uint32(d, d->h->cmd_status, 1) < 0)
477458
return -1;

ttops.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
struct tt_handles { uint16_t ppcp, passcode, magic, cmd_status, length, transfer, check; };
88

9-
struct tt_files { uint32_t hostname, preference, manifest, activity_start, gps_status, quickgps; };
10-
119
struct ble_dev_info {
1210
uint16_t handle;
1311
const char *name;

0 commit comments

Comments
 (0)