mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
detect hwecho based on whether the hardware seems to be echoing during
pt_read_version, rather than based on the device name
This commit is contained in:
@@ -83,7 +83,7 @@ record_cb(unsigned char *buf, void *user_data)
|
||||
static void
|
||||
usage(const char *progname)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-d <device>] [-e] [-f] [-o <output file>]\n",
|
||||
fprintf(stderr, "usage: %s [-d <device>] [-f] [-o <output file>]\n",
|
||||
progname);
|
||||
exit(1);
|
||||
}
|
||||
@@ -108,9 +108,6 @@ main(int argc, char *argv[])
|
||||
devices[0] = optarg;
|
||||
dev_cnt = 1;
|
||||
break;
|
||||
case 'e':
|
||||
hwecho = 1;
|
||||
break;
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
@@ -151,11 +148,6 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
fprintf(stderr, "Reading from %s.\n", devices[0]);
|
||||
if (pt_hwecho(devices[0]))
|
||||
hwecho = 1;
|
||||
|
||||
if (hwecho)
|
||||
fprintf(stderr, "Expecting hardware echo.\n");
|
||||
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "Opening device %s.\n", devices[0]);
|
||||
@@ -171,7 +163,7 @@ main(int argc, char *argv[])
|
||||
memset(&vstate, 0, sizeof(vstate));
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "\nCalling pt_read_version.\n");
|
||||
while ((r = pt_read_version(&vstate, fd, hwecho)) != PT_DONE) {
|
||||
while ((r = pt_read_version(&vstate, fd, &hwecho)) != PT_DONE) {
|
||||
assert(r == PT_NEED_READ);
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(fd, &readfds);
|
||||
|
||||
@@ -141,10 +141,11 @@ DownloadRideDialog::time_cb(struct tm *time)
|
||||
QMessageBox::critical(this, tr("Read error"),
|
||||
tr("Can't find ride time"));
|
||||
reject();
|
||||
} else
|
||||
sprintf(outname, "%04d_%02d_%02d_%02d_%02d_%02d.raw",
|
||||
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
|
||||
time->tm_hour, time->tm_min, time->tm_sec);
|
||||
return;
|
||||
}
|
||||
sprintf(outname, "%04d_%02d_%02d_%02d_%02d_%02d.raw",
|
||||
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
|
||||
time->tm_hour, time->tm_min, time->tm_sec);
|
||||
assert(strlen(outname) == sizeof(outname) - 1);
|
||||
label->setText(label->text() + tr("done.\nWriting to ")
|
||||
+ outname + ".");
|
||||
@@ -159,6 +160,7 @@ DownloadRideDialog::time_cb(struct tm *time)
|
||||
tr("&Overwrite"), tr("&Cancel"),
|
||||
QString(), 1, 1) == 1) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((out = fopen(path.c_str(), "w")) == NULL) {
|
||||
@@ -166,6 +168,7 @@ DownloadRideDialog::time_cb(struct tm *time)
|
||||
tr("Can't open ") + path.c_str()
|
||||
+ tr(" for writing: ") + strerror(errno));
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
label->setText(label->text() + tr("\nRide data read: "));
|
||||
endingOffset = label->text().size();
|
||||
@@ -201,7 +204,7 @@ DownloadRideDialog::readVersion()
|
||||
{
|
||||
if (notifier)
|
||||
notifier->setEnabled(false);
|
||||
int r = pt_read_version(&vstate, fd, hwecho);
|
||||
int r = pt_read_version(&vstate, fd, &hwecho);
|
||||
if (r == PT_DONE) {
|
||||
if (notifier) {
|
||||
delete notifier;
|
||||
@@ -299,7 +302,7 @@ DownloadRideDialog::downloadClicked()
|
||||
if (device)
|
||||
free(device);
|
||||
device = strdup(listWidget->currentItem()->text().toAscii().data());
|
||||
hwecho = pt_hwecho(device);
|
||||
hwecho = 0;
|
||||
fd = open(device, O_RDWR | O_NOCTTY);
|
||||
if (fd < 0) {
|
||||
QMessageBox::critical(this, tr("Read error"),
|
||||
|
||||
46
src/lib/pt.c
46
src/lib/pt.c
@@ -75,15 +75,6 @@ pt_find_device(char *result[], int capacity)
|
||||
return count;
|
||||
}
|
||||
|
||||
#define KSDEVSTR "/dev/cu.KeySerial"
|
||||
#define LINUXSERIALSTR "/dev/ttyS"
|
||||
int
|
||||
pt_hwecho(const char *device)
|
||||
{
|
||||
return (strncmp(device, KSDEVSTR, strlen(KSDEVSTR)) == 0
|
||||
|| strncmp(device, LINUXSERIALSTR, strlen(LINUXSERIALSTR)) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
pt_make_async(int fd)
|
||||
{
|
||||
@@ -126,7 +117,7 @@ fprintb(FILE *file, unsigned char *buf, int cnt)
|
||||
}
|
||||
|
||||
int
|
||||
pt_read_version(struct pt_read_version_state *state, int fd, int hwecho)
|
||||
pt_read_version(struct pt_read_version_state *state, int fd, int *hwecho)
|
||||
{
|
||||
char c = 0x56;
|
||||
int n;
|
||||
@@ -142,28 +133,7 @@ pt_read_version(struct pt_read_version_state *state, int fd, int hwecho)
|
||||
state->i = 0;
|
||||
}
|
||||
|
||||
if (state->state == 1) {
|
||||
if (hwecho) {
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "Calling read on device.\n");
|
||||
n = read(fd, &c, 1);
|
||||
if (n <= 0) {
|
||||
if ((n < 0) && (errno == EAGAIN)) {
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "Need read.\n");
|
||||
return PT_NEED_READ;
|
||||
}
|
||||
perror("read");
|
||||
exit(1);
|
||||
}
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "Read %d bytes: %02x.\n", n, 0xff & c);
|
||||
assert(n == 1);
|
||||
}
|
||||
state->state = 2;
|
||||
}
|
||||
|
||||
assert(state->state == 2);
|
||||
assert(state->state == 1);
|
||||
while (state->i < 29) {
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "Need %d bytes. Calling read on device.\n",
|
||||
@@ -183,7 +153,17 @@ pt_read_version(struct pt_read_version_state *state, int fd, int hwecho)
|
||||
fprintb(stderr, state->buf + state->i, n);
|
||||
fprintf(stderr, ".\n");
|
||||
}
|
||||
state->i += n;
|
||||
if ((state->i == 0) && (state->buf[0] == 0x56)) {
|
||||
if (pt_debug_level >= PT_DEBUG_MAX)
|
||||
fprintf(stderr, "Hardware echo detected.\n");
|
||||
*hwecho = 1;
|
||||
for (int j = 0; j < n - 1; ++j)
|
||||
state->buf[j] = state->buf[j+1];
|
||||
state->i = n - 1;
|
||||
}
|
||||
else {
|
||||
state->i += n;
|
||||
}
|
||||
}
|
||||
|
||||
return PT_DONE;
|
||||
|
||||
@@ -45,7 +45,7 @@ struct pt_read_version_state {
|
||||
unsigned char buf[30];
|
||||
};
|
||||
extern int pt_read_version(struct pt_read_version_state *state,
|
||||
int fd, int hwecho);
|
||||
int fd, int *hwecho);
|
||||
|
||||
struct pt_read_data_state {
|
||||
int state;
|
||||
|
||||
Reference in New Issue
Block a user