diff --git a/src/cmd/cmd.pro b/src/cmd/cmd.pro deleted file mode 100644 index 55619eac4..000000000 --- a/src/cmd/cmd.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE=subdirs -SUBDIRS=cpint ptdl ptpk ptunpk diff --git a/src/cmd/cpint/cpint.cpp b/src/cmd/cpint/cpint.cpp deleted file mode 100644 index 4fe25f01b..000000000 --- a/src/cmd/cpint/cpint.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * $Id: cpint-cmd.c,v 1.1 2006/08/11 19:53:07 srhea Exp $ - * - * Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cpint.h" - -struct cpi_file_info *head; - -static void -canceled(int unused) -{ - unused = 0; - if (head) { - fprintf(stderr, "calceled.\n"); - unlink(head->outname); - } - exit(1); -} - -int -main(int argc, char *argv[]) -{ - int i; - double *bests; - int bestlen; - char *dir = "."; - if (argc > 1) - dir = argv[1]; - signal(SIGINT, canceled); - head = cpi_files_to_update(dir); - while (head) { - fprintf(stderr, "Processing ride file %s...", head->file); - fflush(stderr); - update_cpi_file(head, NULL, NULL); - fprintf(stderr, "done.\n"); - head = head->next; - } - combine_cpi_files(dir, &bests, &bestlen); - for (i = 0; i < bestlen; ++i) { - if (bests[i] != 0) - printf("%6.3f %3.0f\n", i / 60.0, round(bests[i])); - } - return 0; -} - diff --git a/src/cmd/cpint/cpint.pro b/src/cmd/cpint/cpint.pro deleted file mode 100644 index aba0104e2..000000000 --- a/src/cmd/cpint/cpint.pro +++ /dev/null @@ -1,18 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Fri Sep 14 16:54:53 2007 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += ../../gui -LIBS +=../../gui/cpint.o \ - ../../gui/RideFile.o \ - ../../gui/CsvRideFile.o \ - ../../gui/SrmRideFile.o \ - ../../gui/RawRideFile.o \ - ../../srm/libsrm.a \ - ../../lib/libgc.a - -# Input -SOURCES += cpint.cpp diff --git a/src/cmd/ptdl/ptdl.cpp b/src/cmd/ptdl/ptdl.cpp deleted file mode 100644 index ca1ff4a11..000000000 --- a/src/cmd/ptdl/ptdl.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * $Id: ptdl.c,v 1.10 2006/09/06 23:23:03 srhea Exp $ - * - * Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include "pt.h" - -#define MAX_DEVICES 20 - -int force; - -static void -time_cb(struct tm *time, void *user_data) -{ - char outname[24]; - FILE **out = (FILE**) user_data; - if (!*out) { - if (!time) { - fprintf(stderr, "Can't find ride time;" - " specify output file with -o.\n"); - exit(1); - } - 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); - fprintf(stderr, "done.\nWriting to %s.\n", outname); - if ((*out = fopen(outname, "r")) != NULL) { - if (force) - fclose(*out); - else { - fprintf(stderr, "Error: %s already exists! " - "Specify -f to overwrite it.\n", outname); - exit(1); - } - } - if ((*out = fopen(outname, "w")) == NULL) { - fprintf(stderr, "Couldn't open %s for writing: %s", - outname, strerror(errno)); - exit(1); - } - fprintf(stderr, "Reading ride data..."); - fflush(stderr); - } -} - -static void -record_cb(unsigned char *buf, void *user_data) -{ - static int count = 0; - int i; - FILE **out = (FILE**) user_data; - for (i = 0; i < 6; ++i) - fprintf(*out, "%02x%s", buf[i], (i == 5) ? "\n" : " "); - if ((++count % 256) == 0) { - fprintf(stderr, "."); - fflush(stderr); - } -} - -static void -usage(const char *progname) -{ - fprintf(stderr, "usage: %s [-d ] [-f] [-o ]\n", - progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - int i, ch, fd, r; - char *devices[MAX_DEVICES]; - int dev_cnt = 0; - char *outname = NULL; - FILE *out = NULL; - struct pt_read_version_state vstate; - struct pt_read_data_state dstate; - struct timeval timeout; - fd_set readfds; - int hwecho = 0; - - while ((ch = getopt(argc, argv, "d:efho:v")) != -1) { - switch (ch) { - case 'd': - devices[0] = optarg; - dev_cnt = 1; - break; - case 'f': - force = 1; - break; - case 'o': - outname = optarg; - if (strcmp(outname, "-") == 0) - out = stdout; - else if ((out = fopen(outname, "w")) == NULL) { - fprintf(stderr, "Couldn't open %s for writing: %s", - outname, strerror(errno)); - exit(1); - } - break; - case 'v': - pt_debug_level = PT_DEBUG_MAX; - break; - case 'h': - case '?': - default: - usage(argv[0]); - } - } - argc -= optind; - argv += optind; - - if (!dev_cnt) { - dev_cnt = pt_find_device(devices, MAX_DEVICES); - if (dev_cnt == 0) { - fprintf(stderr, "Can't find device; specify one with -d.\n"); - exit(1); - } - if (dev_cnt > 1) { - fprintf(stderr, "Multiple devices present; specify one with -d:\n"); - for (i = 0; i < dev_cnt; ++i) - fprintf(stderr, " %s\n", devices[i]); - exit(1); - } - } - - fprintf(stderr, "Reading from %s.\n", devices[0]); - - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Opening device %s.\n", devices[0]); - fd = open(devices[0], O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) { - perror("open"); - exit(1); - } - fprintf(stderr, "Reading version information..."); - fflush(stderr); - - pt_make_async(fd); - 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) { - assert(r == PT_NEED_READ); - FD_ZERO(&readfds); - FD_SET(fd, &readfds); - timeout.tv_sec = 5; - timeout.tv_usec = 0; - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Calling select.\n"); - select(fd + 1, &readfds, NULL, NULL, &timeout); - if (!FD_ISSET(fd, &readfds)) { - fprintf(stderr, "timeout.\n"); - exit(1); - } - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "\nCalling pt_read_version.\n"); - } - fprintf(stderr, "done.\n"); - close(fd); - - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Opening device %s.\n", devices[0]); - fd = open(devices[0], O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) { - perror("open"); - exit(1); - } - if (out) - fprintf(stderr, "Writing to %s.\nReading ride data...", outname); - else - fprintf(stderr, "Reading ride time..."); - fflush(stderr); - - pt_make_async(fd); - memset(&dstate, 0, sizeof(dstate)); - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "\nCalling pt_read_data.\n"); - while ((r = pt_read_data(&dstate, fd, hwecho, time_cb, - record_cb, &out)) != PT_DONE) { - assert(r == PT_NEED_READ); - FD_ZERO(&readfds); - FD_SET(fd, &readfds); - timeout.tv_sec = 5; - timeout.tv_usec = 0; - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Calling select.\n"); - select(fd + 1, &readfds, NULL, NULL, &timeout); - if (!FD_ISSET(fd, &readfds)) { - fprintf(stderr, "timeout.\n"); - exit(1); - } - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "\nCalling pt_read_data.\n"); - } - fprintf(stderr, "done.\n"); - - return 0; -} - diff --git a/src/cmd/ptdl/ptdl.pro b/src/cmd/ptdl/ptdl.pro deleted file mode 100644 index 84eec3ac4..000000000 --- a/src/cmd/ptdl/ptdl.pro +++ /dev/null @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Fri Sep 14 16:56:22 2007 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += ../../lib -LIBS += ../../lib/libgc.a - -# Input -SOURCES += ptdl.cpp diff --git a/src/cmd/ptpk/ptpk.cpp b/src/cmd/ptpk/ptpk.cpp deleted file mode 100644 index 5cc0c43fb..000000000 --- a/src/cmd/ptpk/ptpk.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * $Id: ptpk.c,v 1.1 2006/05/27 16:17:25 srhea Exp $ - * - * Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include "pt.h" - -void -pt_pack(FILE *in, FILE *out, int wheel_sz_mm, int rec_int) -{ - double mins, nm, mph, watts, miles; - int cad, hr, interval = 0; - double last_mins = 0.0, last_miles = 0.0; - int last_interval = 0; - int i; - struct tm start_tm, inc_tm; - time_t start_time = 0, inc_time; - int lineno = 1; - char line[256]; - unsigned char buf[6]; - regex_t date_reg; - int date_nmatch = 7; - regmatch_t *date_pmatch = - (regmatch_t*) calloc(date_nmatch, sizeof(regmatch_t)); - regex_t rider_reg; - int rider_nmatch = 12; - regmatch_t *rider_pmatch = - (regmatch_t*) calloc(rider_nmatch, sizeof(regmatch_t)); - - if (regcomp(&date_reg, "^([0-9][0-9]?)\\\\([0-9][0-9]?)\\\\" - "([0-9][0-9][0-9][0-9]) +([0-9][0-9]?):([0-9][0-9]?):" - "([0-9][0-9]?) *$", REG_EXTENDED)) - assert(0); - - if (regcomp(&rider_reg, "^([0-9]+\\.[0-9]+)" - "([0-9]+(\\.[0-9]+)?)" - "([0-9]+(\\.[0-9]+)?|NaN)([0-9]+|NaN)" - "([0-9]+(\\.[0-9]+)?)([0-9]+)" - "([0-9]+|NaN)([0-9]+)$", - REG_EXTENDED)) - assert(0); - - pt_pack_header(buf); - pt_write_data(out, buf); - - while (fgets(line, sizeof(line), in)) { - line[strlen(line) - 1] = '\0'; /* drop newline */ - if (strcmp(line, "") == 0) { - /* ignore it */ - } - else if (strcmp(line, "") == 0) { - /* ignore it */ - } - else if (strcmp(line, "") == 0) { - /* ignore it */ - } - else if (!regexec(&date_reg, line, date_nmatch, date_pmatch, 0)) { - for (i = 1; i < date_nmatch; ++i) - line[date_pmatch[i].rm_eo] = '\0'; - memset(&start_tm, 0, sizeof(start_tm)); - start_tm.tm_year = atoi(line + date_pmatch[3].rm_so) - 1900; - start_tm.tm_mon = atoi(line + date_pmatch[1].rm_so) - 1; - start_tm.tm_mday = atoi(line + date_pmatch[2].rm_so); - start_tm.tm_hour = atoi(line + date_pmatch[4].rm_so); - start_tm.tm_min = atoi(line + date_pmatch[5].rm_so); - start_tm.tm_sec = atoi(line + date_pmatch[6].rm_so); - start_tm.tm_isdst = -1; - start_time = mktime(&start_tm); - assert(start_time != -1); - pt_pack_time(buf, &start_tm); - pt_write_data(out, buf); - pt_pack_config(buf, interval, rec_int, wheel_sz_mm); - pt_write_data(out, buf); - } - else if (!regexec(&rider_reg, line, rider_nmatch, rider_pmatch, 0)) { - for (i = 1; i < rider_nmatch; ++i) - line[rider_pmatch[i].rm_eo] = '\0'; - mins = atof(line + rider_pmatch[1].rm_so); - nm = atof(line + rider_pmatch[2].rm_so); - if (strcmp(line + rider_pmatch[4].rm_so, "NaN") == 0) - mph = -1.0; - else - mph = atof(line + rider_pmatch[4].rm_so); - if (strcmp(line + rider_pmatch[6].rm_so, "NaN") == 0) - watts = -1.0; - else - watts = atof(line + rider_pmatch[6].rm_so); - miles = atof(line + rider_pmatch[7].rm_so); - cad = atoi(line + rider_pmatch[9].rm_so); - if (strcmp(line + rider_pmatch[10].rm_so, "NaN") == 0) - hr = 255; - else - hr = atoi(line + rider_pmatch[10].rm_so); - interval = atoi(line + rider_pmatch[11].rm_so); - if (mins - last_mins - 0.021 > 1.0 / 60.0) { - struct tm *tm_p; - inc_time = start_time - + (unsigned) round((mins - 0.021000001) * 60.0); - tm_p = localtime(&inc_time); - assert(tm_p); - inc_tm = *tm_p; - pt_pack_time(buf, &inc_tm); - pt_write_data(out, buf); - pt_pack_config(buf, interval, rec_int, wheel_sz_mm); - pt_write_data(out, buf); - } - else if (last_interval != interval) { - pt_pack_config(buf, interval, rec_int, wheel_sz_mm); - pt_write_data(out, buf); - } - pt_pack_data(buf, wheel_sz_mm, nm, mph, - miles - last_miles, cad, hr); - pt_write_data(out, buf); - last_mins = mins; - last_interval = interval; - last_miles = miles; - } - else { - fprintf(stderr, "ERROR: line %d unrecognized: \"%s\"\n", - lineno, line); - exit(1); - } - ++lineno; - } -} - -static void -usage(const char *progname) -{ - fprintf(stderr, "usage: %s [-o ] [-r ]" - "[-w ] []\n", - progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - int ch, i; - int wheel_sz_mm = 2096; - int rec_int = 1; - char *inname = NULL, *outname = NULL; - FILE *in, *out = NULL; - - while ((ch = getopt(argc, argv, "ho:r:w:")) != -1) { - switch (ch) { - case 'o': - outname = optarg; - if (strcmp(outname, "-") == 0) { - out = stdout; - outname = "STDOUT"; - } - break; - case 'r': - rec_int = atoi(optarg); - break; - case 'w': - wheel_sz_mm = atoi(optarg); - break; - case 'h': - case '?': - default: - usage(argv[0]); - } - } - argc -= optind; - argv += optind; - - if (argc == 0) { - in = stdin; - inname = "STDIN"; - if (outname == NULL) { - out = stdout; - outname = "STDOUT"; - } - } - else { - inname = argv[0]; - if ((in = fopen(inname, "r")) == NULL) { - fprintf(stderr, "Couldn't open %s for reading: %s\n", - inname, strerror(errno)); - exit(1); - } - if (outname == NULL) { - outname = (char*) malloc(strlen(inname) + 5); - strcpy(outname, inname); - for (i = strlen(outname); i >= 0; --i) - if (outname[i] == '.') break; - if (i >= 0) - strcpy(outname + i + 1, "raw"); - else - strcpy(outname + strlen(outname), ".raw"); - } - } - - if ((out == NULL) && ((out = fopen(outname, "w")) == NULL)) { - fprintf(stderr, "Couldn't open %s for writing: %s\n", - outname, strerror(errno)); - exit(1); - } - - pt_pack(in, out, wheel_sz_mm, rec_int); - - fclose(in); - fclose(out); - - return 0; -} - diff --git a/src/cmd/ptpk/ptpk.pro b/src/cmd/ptpk/ptpk.pro deleted file mode 100644 index ce8f36803..000000000 --- a/src/cmd/ptpk/ptpk.pro +++ /dev/null @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Fri Sep 14 16:57:18 2007 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += ../../lib -LIBS += ../../lib/libgc.a - -# Input -SOURCES += ptpk.cpp diff --git a/src/cmd/ptunpk/ptunpk.cpp b/src/cmd/ptunpk/ptunpk.cpp deleted file mode 100644 index 24738395f..000000000 --- a/src/cmd/ptunpk/ptunpk.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * $Id: ptunpk.c,v 1.4 2006/06/04 14:32:34 srhea Exp $ - * - * Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include "pt.h" - -#define KM_TO_MI 0.62137119 -#define BAD_KM_TO_MI 0.62 - -static FILE *out; - -int metric; /* Non zero if distance units should be output in metric. */ - -static void -config_cb(unsigned interval, unsigned rec_int, unsigned wheel_sz_mm, - void *context) -{ - context = NULL; - fprintf(out, "# wheel size=%d mm, interval=%d, rec int=%d\n", - wheel_sz_mm, interval, rec_int); -} - -static void -time_cb(struct tm *time, time_t since_epoch, void *context) -{ - context = NULL; - fprintf(out, "# %d/%d/%d %d:%02d:%02d %d\n", - time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec, (int) since_epoch); -} - -static void -data_cb(double secs, double nm, double mph, double watts, double miles, - unsigned cad, unsigned hr, unsigned interval, void *context) -{ - context = NULL; - fprintf(out, "%.3f %.1f", secs / 60.0, nm); - if (mph == -1.0) - fprintf(out, " NaN NaN"); - else - fprintf(out, " %0.3f %.0f", metric ? (mph / KM_TO_MI) : mph, watts); - fprintf(out, " %.5f %d", metric ? (miles / KM_TO_MI) : miles, cad); - if (hr == 0) - fprintf(out, " NaN"); - else - fprintf(out, " %d", hr); - fprintf(out, " %d\n", interval); -} - -/* Like data_cb, but output PowerTap CSV format. */ -static void -csv_data_cb(double secs, double nm, double mph, double watts, double miles, - unsigned cad, unsigned hr, unsigned interval, void *context) -{ - context = NULL; - fprintf(out, "%7.3f, %10.1f,", secs / 60.0, nm); - if (mph == -1.0) - fprintf(out, " 0.0, 0,"); - else - fprintf(out, "%6.1f, %5.0f,", metric ? (mph / KM_TO_MI) : mph, watts); - fprintf(out, "%8.3f, %7d,", metric ? (miles / KM_TO_MI) : miles, cad); - fprintf(out, "%6d, %3d\n", hr, interval); -} - -static int errors; -static void -error_cb(const char *msg, void *context) -{ - context = NULL; - fprintf(stderr, "%s\n", msg); - ++errors; -} - -static void -usage(const char *progname) -{ - fprintf(stderr, - "usage: %s [-c] [-p] [-m] [-o ] []\n", - progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - int ch, i, compat = 0, csv_output = 0; - char *inname = NULL, *outname = NULL; - FILE *in; - - while ((ch = getopt(argc, argv, "chmpo:")) != -1) { - switch (ch) { - case 'c': - compat = 1; - break; - case 'o': - outname = optarg; - if (strcmp(outname, "-") == 0) { - out = stdout; - outname = "STDOUT"; - } - break; - case 'p': - csv_output = 1; - break; - case 'm': - metric = 1; - break; - case 'h': - case '?': - default: - usage(argv[0]); - } - } - argc -= optind; - argv += optind; - - if (argc == 0) { - in = stdin; - inname = "STDIN"; - if (outname == NULL) { - out = stdout; - outname = "STDOUT"; - } - } - else { - inname = argv[0]; - if ((in = fopen(inname, "r")) == NULL) { - fprintf(stderr, "Couldn't open %s for reading: %s\n", - inname, strerror(errno)); - exit(1); - } - if (outname == NULL) { - outname = (char*) malloc(strlen(inname) + 5); - strcpy(outname, inname); - for (i = strlen(outname); i >= 0; --i) - if (outname[i] == '.') break; - if (i >= 0) { - strcpy(outname + i + 1, - csv_output ? "csv" : "dat"); - } - else { - strcpy(outname + strlen(outname), - csv_output ? ".csv" : ".dat"); - } - } - } - - if ((out == NULL) && ((out = fopen(outname, "w")) == NULL)) { - fprintf(stderr, "Couldn't open %s for writing: %s\n", - outname, strerror(errno)); - exit(1); - } - - if (csv_output) { - if (metric) { - fprintf(out, "Minutes, Torq (N-m), Km/h, Watts, Km," - " Cadence, Hrate, ID\n"); - } - else { - fprintf(out, "Minutes, Torq (N-m), Mi/h, Watts, Mi," - " Cadence, Hrate, ID\n"); - } - pt_read_raw(in, compat, NULL, NULL, NULL, csv_data_cb, error_cb); - } - else { - if (metric) - fprintf(out, "# Time Torq KPH Watts KMs Cad HR Int\n"); - else - fprintf(out, "# Time Torq MPH Watts Miles Cad HR Int\n"); - pt_read_raw(in, compat, NULL, config_cb, time_cb, data_cb, error_cb); - } - - return errors ? 1 : 0; -} - diff --git a/src/cmd/ptunpk/ptunpk.pro b/src/cmd/ptunpk/ptunpk.pro deleted file mode 100644 index 57d5ac3a4..000000000 --- a/src/cmd/ptunpk/ptunpk.pro +++ /dev/null @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Fri Sep 14 17:16:58 2007 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += ../../lib -LIBS += ../../lib/libgc.a - -# Input -SOURCES += ptunpk.cpp diff --git a/src/cmd/scripts/intervals.pl b/src/cmd/scripts/intervals.pl deleted file mode 100755 index 774db8557..000000000 --- a/src/cmd/scripts/intervals.pl +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/perl -w -# -# $Id: intervals.pl,v 1.2 2006/08/11 19:53:50 srhea Exp $ -# -# Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 2 of the License, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., 51 -# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -use strict; - -my $interval = -1; -my $time_start = 0; -my $time_end = 0; -my $mile_start = 0; -my $mile_end = 0; -my $watts_max = 0; -my $watts_sum = 0; -my $watts_cnt = 0; -my $hrate_max = 0; -my $hrate_sum = 0; -my $hrate_cnt = 0; -my $caden_max = 0; -my $caden_sum = 0; -my $caden_cnt = 0; -my $speed_max = 0; -my $speed_sum = 0; -my $speed_cnt = 0; -my $ignore_power_zeros = 0; - -if ($#ARGV >= 0 && $ARGV[0] eq "--ignore-power-zeros") { - $ignore_power_zeros = 1; - shift; -} - -sub sumarize { - my $dur = $time_end - $time_start; - my $len = $mile_end - $mile_start; - my $minutes = int($dur); - my $seconds = int(60 * ($dur - int($dur))); - my $watts_avg = ($watts_cnt == 0) ? 0 : int($watts_sum / $watts_cnt); - my $hrate_avg = ($hrate_cnt == 0) ? 0 : int($hrate_sum / $hrate_cnt); - my $caden_avg = ($caden_cnt == 0) ? 0 : int($caden_sum / $caden_cnt); - my $speed_avg = int($speed_sum / $speed_cnt); - printf "%2d\t%2d:%02d\t%5.1f\t%4d\t%4d\t%3d\t%3d\t%3d\t%3d\t%0.1f\t%0.1f\n", $interval, $minutes, $seconds, $len, $watts_avg, $watts_max, $hrate_avg, $hrate_max, $caden_avg, $caden_max, $speed_avg, $speed_max; - $watts_sum = 0; - $watts_cnt = 0; - $watts_max = 0; - $hrate_max = 0; - $hrate_sum = 0; - $hrate_cnt = 0; - $caden_max = 0; - $caden_sum = 0; - $caden_cnt = 0; - $speed_max = 0; - $speed_sum = 0; - $speed_cnt = 0; -} - -print "\t\t\tPower\t\tHeart Rate\tCadence\t\tSpeed\n"; -print "Int\t Dur\tDist\t Avg\t Max\tAvg\tMax\tAvg\tMax\tAvg\tMax\n"; - -while (<>) { - if (m/^#/) { - } - else { - my @cols = split; - if ($#cols != 7) { - print STDERR "Wrong number of columns: $_"; - exit 1; - } - my ($min, $torq, $speed, $watts, $miles, $caden, $hrate, $id) = @cols; - if ($id != $interval) { - if ($interval != -1) { - sumarize(); - } - $interval = $id; - $time_start = $min; - $mile_start = $miles; - } - $mile_end = $miles; - $time_end = $min; - if ($watts ne "NaN" && ($watts > 0 || !$ignore_power_zeros)) { - $watts_sum += $watts; - $watts_cnt += 1; - if ($watts > $watts_max) { $watts_max = $watts; } - } - if ($hrate ne "NaN" && $hrate > 0) { - $hrate_sum += $hrate; - $hrate_cnt += 1; - if ($hrate > $hrate_max) { $hrate_max = $hrate; } - } - if ($caden ne "NaN" && $caden > 0) { - $caden_sum += $caden; - $caden_cnt += 1; - if ($caden > $caden_max) { $caden_max = $caden; } - } - if ($speed ne "NaN") { - $speed_sum += $speed; - $speed_cnt += 1; - if ($speed > $speed_max) { $speed_max = $speed; } - } - } -} - -sumarize(); - diff --git a/src/cmd/scripts/smooth.pl b/src/cmd/scripts/smooth.pl deleted file mode 100755 index 4f4606641..000000000 --- a/src/cmd/scripts/smooth.pl +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/perl -w -# -# $Id: smooth.pl,v 1.1 2006/05/16 14:24:50 srhea Exp $ -# -# Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 2 of the License, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., 51 -# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -use strict; - -if ($#ARGV < 0) { - print "usage: smooth.pl \n"; - exit 1; -} - -my $len = $ARGV[0] / 60.0; -my $count = 0; -my $total = 0; -my $start_time = 0; - -while () { - if (m/^#/) { - } - else { - my @cols = split; - if (!($cols[1] eq "NaN")) { - ++$count; - $total += $cols[1]; - } - if ($cols[0] >= $start_time + $len) { - if ($count > 0) { - printf "$start_time %f\n", $total / $count; - } - $start_time = $cols[0]; - $total = 0; - $count = 0; - } - } -} - diff --git a/src/lib/lib.pro b/src/lib/lib.pro deleted file mode 100644 index cbfa4e924..000000000 --- a/src/lib/lib.pro +++ /dev/null @@ -1,14 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Fri Sep 14 16:49:39 2007 -###################################################################### - -TEMPLATE = lib -TARGET = gc -DEPENDPATH += . -INCLUDEPATH += . -CONFIG += static - -# Input -HEADERS += pt.h -SOURCES += pt.cpp - diff --git a/src/lib/pt.cpp b/src/lib/pt.cpp deleted file mode 100644 index bbcf318a9..000000000 --- a/src/lib/pt.cpp +++ /dev/null @@ -1,688 +0,0 @@ -/* - * $Id: pt.c,v 1.9 2006/09/06 23:23:03 srhea Exp $ - * - * Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pt.h" - -#define MAGIC_CONSTANT 147375.0 -#define PI 3.14159265 -#define TIME_UNIT_MIN 0.021 - -#define LBFIN_TO_NM 0.11298483 -#define KM_TO_MI 0.62137119 - -#define BAD_LBFIN_TO_NM_1 0.112984 -#define BAD_LBFIN_TO_NM_2 0.1129824 -#define BAD_KM_TO_MI 0.62 - -unsigned pt_debug_level; - -static unsigned char -check(unsigned value) -{ - assert(value < 256); - return (unsigned char) value; -} - -int -pt_find_device(char *result[], int capacity) -{ - regex_t reg; - DIR *dirp; - struct dirent *dp; - int count = 0; - if (regcomp(®, - "^(cu\\.(usbmodem[0-9A-F]+|usbserial-[0-9A-F]+|KeySerial[0-9])|ttyUSB[0-9]|ttyS[0-2])$", - REG_EXTENDED|REG_NOSUB)) { - assert(0); - } - dirp = opendir("/dev"); - while ((count < capacity) && ((dp = readdir(dirp)) != NULL)) { - if (regexec(®, dp->d_name, 0, NULL, 0) == 0) { - result[count] = (char*) malloc(6 + strlen(dp->d_name)); - sprintf(result[count], "/dev/%s", dp->d_name); - ++count; - } - } - return count; -} - -void -pt_make_async(int fd) -{ - struct termios tty; - int flags = fcntl(fd, F_GETFL, 0); - if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { - perror("fcntl"); - assert(0); - } - if (tcgetattr(fd, &tty) == -1) { - perror("tcgetattr"); - assert(0); - } - tty.c_cflag &= ~CRTSCTS; /* no hardware flow control */ - tty.c_cflag &= ~(PARENB | PARODD); /* no parity */ - tty.c_cflag &= ~CSTOPB; /* 1 stop bit */ - tty.c_cflag &= ~CSIZE; /* clear size bits */ - tty.c_cflag |= CS8; /* 8 bits */ - tty.c_cflag |= CLOCAL | CREAD; /* ignore modem control lines */ - if (cfsetspeed(&tty, B9600) == -1) { - perror("cfsetspeed"); - assert(0); - } - tty.c_iflag = IGNBRK; /* ignore BREAK condition on input */ - tty.c_lflag = 0; - tty.c_oflag = 0; - tty.c_cc[VMIN] = 1; /* all reads return at least one character */ - if (tcsetattr(fd, TCSANOW, &tty) == -1) { - perror("tcsetattr"); - assert(0); - } -} - -static void -fprintb(FILE *file, unsigned char *buf, int cnt) -{ - unsigned char *end = buf + cnt; - while (buf < end) - fprintf(file, "%02x", 0xff & *buf++); -} - -int -pt_read_version(struct pt_read_version_state *state, int fd, int *hwecho) -{ - char c = 0x56; - int n; - - if (state->state == 0) { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Writing 0x%x to device.\n", (unsigned) c); - if ((n = write(fd, &c, 1)) < 1) { - perror("write"); - exit(1); - } - state->state = 1; - state->i = 0; - } - - assert(state->state == 1); - while (1) { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Calling read on device.\n"); - n = read(fd, state->buf + state->i, sizeof(state->buf) - state->i); - 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: ", n); - fprintb(stderr, state->buf + state->i, n); - fprintf(stderr, ".\n"); - } - state->i += n; - if ((state->i >= 2) - && (state->buf[state->i - 2] == 0x0d) - && (state->buf[state->i - 1] == 0x0a)) { - break; - } - } - - /* - * We expect the version string to be something like - * "VER 02.21 PRO...", so if we see two V's, it's probably - * because there's a hardware echo going on. - */ - - int start = -1; - for (int i = 0; i < state->i - 3; ++i) { - if (strncmp((char*) state->buf + i, "VER", 3) == 0) { - start = i; - break; - } - } - - if (start < 0) { - // TODO: return something like PT_ERROR? - fprintf(stderr, "Unrecognized version string.\n"); - } - else { - int count = 0; - for (int i = 0; i < start; ++i) { - if (state->buf[i] == 0x56) - ++count; - } - if (count > 0) { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Hardware echo detected.\n"); - *hwecho = 1; - } - else { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "No hardware echo detected.\n"); - *hwecho = 0; - } - } - - return PT_DONE; -} - -int -pt_read_data(struct pt_read_data_state *state, - int fd, int hwecho, - void (*time_cb)(struct tm *, void *), - void (*record_cb)(unsigned char *, void *), - void *user_data) -{ - char c = 0x44; - int j, n; - unsigned csum; - struct tm time; - - if (state->state == 0) { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Writing 0x%x to device.\n", (unsigned) c); - if ((n = write(fd, &c, 1)) < 1) { - perror("write"); - exit(1); - } - state->block = 1; - state->i = 0; - state->state = 1; - } - - 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; - } - - if (state->state == 2) { - while (state->i < (int) sizeof(state->header)) { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Calling read on device.\n"); - n = read(fd, state->header + state->i, - sizeof(state->header) - state->i); - 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: ", n); - fprintb(stderr, state->buf + state->i, n); - fprintf(stderr, ".\n"); - } - state->i += n; - } - state->state = 3; - state->i = 0; - } - - while (1) { - if (state->state == 3) { - while (state->i < (int) sizeof(state->buf)) { - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Calling read on device.\n"); - n = read(fd, state->buf + state->i, - sizeof(state->buf) - state->i); - 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: ", n); - fprintb(stderr, state->buf + state->i, n); - fprintf(stderr, ".\n"); - } - state->i += n; - /* TODO: why is this next if statement here? */ - if ((state->i == 2) && (state->buf[0] == 0x0d) - && (state->buf[1] == 0x0a)) { - return PT_DONE; - } - } - if (state->block == 1) { - n = 0; - if (pt_is_config(state->buf + n)) - n += 6; - if (!pt_is_time(state->buf + n) - || (pt_unpack_time(state->buf + n, &time) == -1)) - time_cb(NULL, user_data); - else - time_cb(&time, user_data); - record_cb(state->header, user_data); - } - csum = 0; - for (j = 0; j < state->i - 1; ++j) - csum += state->buf[j]; - if ((csum % 256) != state->buf[state->i-1]) { - fprintf(stderr, "\nbad checksum on block %d: %d vs %d", - state->block, state->buf[state->i-1], csum); - } - for (j = 0; j < state->i - 1; j += 6) { - if (state->buf[j]) - record_cb(state->buf + j, user_data); - else - break; - } - c = 0x71; - if (pt_debug_level >= PT_DEBUG_MAX) - fprintf(stderr, "Writing 0x%x to device.\n", (unsigned) c); - n = write(fd, &c, 1); - if (n < 1) { - perror("write"); - exit(1); - } - ++(state->block); - state->i = 0; - state->state = 4; - } - - assert(state->state == 4); - 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: ", n); - fprintb(stderr, state->buf + state->i, n); - fprintf(stderr, ".\n"); - } - assert(n == 1); - } - state->state = 3; - } - - return PT_DONE; -} - -int -pt_is_time(unsigned char *buf) -{ - return buf[0] == 0x60; -} - -time_t -pt_unpack_time(unsigned char *buf, struct tm *time) -{ - memset(time, 0, sizeof(*time)); - time->tm_year = 2000 + buf[1] - 1900; - time->tm_mon = buf[2] - 1; - time->tm_mday = buf[3] & 0x1f; - time->tm_hour = buf[4] & 0x1f; - time->tm_min = buf[5] & 0x3f; - time->tm_sec = ((buf[3] >> 5) << 3) | (buf[4] >> 5); - time->tm_isdst = -1; - return mktime(time); -} - -int -pt_is_config(unsigned char *buf) -{ - return buf[0] == 0x40; -} - -int -pt_unpack_config(unsigned char *buf, unsigned *interval, - unsigned *last_interval, unsigned *rec_int, - unsigned *wheel_sz_mm) -{ - *wheel_sz_mm = (buf[1] << 8) | buf[2]; - /* Data from device wraps interval after 9... */ - if (buf[3] != *last_interval) { - *last_interval = buf[3]; - ++*interval; - } - *rec_int = buf[4] + 1; - return 0; -} - -int -pt_is_data(unsigned char *buf) -{ - return (buf[0] & 0x80) == 0x80; -} - -static double -my_round(double x) -{ - int i = (int) x; - double z = x - i; - /* For some unknown reason, the PowerTap software rounds 196.5 down... */ - if ((z > 0.5) || ((z == 0.5) && (i != 196))) - ++i; - return i; -} - -void -pt_unpack_data(unsigned char *buf, int compat, unsigned rec_int, - unsigned wheel_sz_mm, double *time_secs, double *torque_Nm, - double *mph, double *watts, double *dist_m, unsigned *cad, - unsigned *hr) -{ - double kph10; - unsigned speed; - unsigned torque_inlbs; - double rotations; - double radians; - double joules; - - *time_secs += rec_int * TIME_UNIT_MIN * 60.0; - torque_inlbs = ((buf[1] & 0xf0) << 4) | buf[2]; - if (torque_inlbs == 0xfff) - torque_inlbs = 0; - speed = ((buf[1] & 0x0f) << 8) | buf[3]; - if ((speed < 100) || (speed == 0xfff)) { - if ((speed != 0) && (speed < 1000)) { - fprintf(stderr, "possible error: speed=%.1f; ignoring it\n", - MAGIC_CONSTANT / speed / 10.0); - } - *mph = -1.0; - *watts = -1.0; - } - else { - if (compat) - *torque_Nm = torque_inlbs * BAD_LBFIN_TO_NM_2; - else - *torque_Nm = torque_inlbs * LBFIN_TO_NM; - kph10 = MAGIC_CONSTANT / speed; - if (compat) - *mph = my_round(kph10) / 10.0 * BAD_KM_TO_MI; - else - *mph = kph10 / 10.0 * KM_TO_MI; - rotations = rec_int * TIME_UNIT_MIN * 100000.0 * kph10 - / wheel_sz_mm / 60.0; - radians = rotations * 2.0 * PI; - joules = *torque_Nm * radians; - *watts = joules / (rec_int * TIME_UNIT_MIN * 60); - if (compat) - *watts = my_round(*watts); - else - *watts = round(*watts); - } - if (compat) - *torque_Nm = torque_inlbs * BAD_LBFIN_TO_NM_1; - *dist_m += (buf[0] & 0x7f) * wheel_sz_mm / 1000.0; - *cad = buf[4]; - if (*cad == 0xff) - *cad = 0; - *hr = buf[5]; - if (*hr == 0xff) - *hr = 0; -} - -void -pt_write_data(FILE *out, unsigned char *buf) -{ - int i; - for (i = 0; i < 5; ++i) - fprintf(out, "%02x ", buf[i]); - fprintf(out, "%02x\n", buf[i]); -} - -void -pt_pack_header(unsigned char *buf) -{ - unsigned char src[] = { 0x57, 0x56, 0x55, 0x64, 0x02, 0x15 }; - memcpy(buf, src, 6); -} - -void -pt_pack_time(unsigned char *buf, struct tm *time) -{ - buf[0] = 0x60; - buf[1] = check(time->tm_year + 1900 - 2000); - buf[2] = check(time->tm_mon + 1); - buf[3] = check(time->tm_mday) | check((time->tm_sec >> 3) << 5); - buf[4] = check(time->tm_hour) | check((time->tm_sec & 0x7) << 5); - buf[5] = check(time->tm_min); -} - -void -pt_pack_config(unsigned char *buf, unsigned interval, - unsigned rec_int, unsigned wheel_sz_mm) -{ - buf[0] = 0x40; - buf[1] = check(wheel_sz_mm >> 8); - buf[2] = wheel_sz_mm & 0xff; - buf[3] = check(interval % 9); - buf[4] = rec_int - 1; - buf[5] = 0x0; -} - -void -pt_pack_data(unsigned char *buf, unsigned wheel_sz_mm, double nm, - double mph, double miles, unsigned cad, unsigned hr) -{ - double rotations = miles / BAD_KM_TO_MI * 1000.00 * 1000.0 / wheel_sz_mm; - unsigned inlbs = (unsigned) round(nm / BAD_LBFIN_TO_NM_2); - double kph10 = mph * 10.0 / BAD_KM_TO_MI; - unsigned speed; - if (mph == -1.0) - speed = 0xfff; - else - speed = (unsigned) round(MAGIC_CONSTANT / kph10); - buf[0] = 0x80 | check((unsigned) round(rotations)); - buf[1] = ((inlbs & 0xf00) >> 4) | ((speed & 0xf00) >> 8); - buf[2] = inlbs & 0xff; - buf[3] = speed & 0xff; - buf[4] = check(cad); - buf[5] = check(hr); -} - - -void -pt_read_raw(FILE *in, int compat, void *context, - void (*config_cb)(unsigned interval, unsigned rec_int, - unsigned wheel_sz_mm, void *context), - void (*time_cb)(struct tm *time, time_t since_epoch, void *context), - void (*data_cb)(double secs, double nm, double mph, - double watts, double miles, unsigned cad, - unsigned hr, unsigned interval, void *context), - void (*error_cb)(const char *msg, void *context)) -{ - unsigned interval = 0; - unsigned last_interval = 0; - unsigned wheel_sz_mm = 0; - unsigned rec_int = 0; - int i, n, row = 0; - unsigned char buf[6]; - unsigned sbuf[6]; - double meters = 0.0; - double secs = 0.0, start_secs = 0.0; - double miles; - double mph; - double nm; - double watts; - unsigned cad; - unsigned hr; - struct tm time; - time_t since_epoch; - char ebuf[256]; - - while ((n = fscanf(in, "%x %x %x %x %x %x\n", - sbuf, sbuf+1, sbuf+2, sbuf+3, sbuf+4, sbuf+5)) == 6) { - ++row; - for (i = 0; i < 6; ++i) { - if (sbuf[i] > 0xff) { n = 1; break; } - buf[i] = sbuf[i]; - } - if (row == 1) { - /* Serial number? */ - } - else if (pt_is_config(buf)) { - if (pt_unpack_config(buf, &interval, &last_interval, - &rec_int, &wheel_sz_mm) < 0) { - sprintf(ebuf, "Couldn't unpack config record."); - if (error_cb) error_cb(ebuf, context); - return; - } - if (config_cb) config_cb(interval, rec_int, wheel_sz_mm, context); - } - else if (pt_is_time(buf)) { - since_epoch = pt_unpack_time(buf, &time); - bool ignore = false; - if (start_secs == 0.0) - start_secs = since_epoch; - else if (since_epoch - start_secs > secs) - secs = since_epoch - start_secs; - else { - sprintf(ebuf, "Warning: %0.3f minutes into the ride, " - "time jumps backwards by %0.3f minutes; ignoring it.", - secs / 60.0, (secs - since_epoch + start_secs) / 60.0); - if (error_cb) error_cb(ebuf, context); - ignore = true; - } - if (time_cb && !ignore) time_cb(&time, since_epoch, context); - } - else if (pt_is_data(buf)) { - if (wheel_sz_mm == 0) { - sprintf(ebuf, "Read data row before wheel size set."); - if (error_cb) error_cb(ebuf, context); - return; - } - pt_unpack_data(buf, compat, rec_int, wheel_sz_mm, &secs, - &nm, &mph, &watts, &meters, &cad, &hr); - if (compat) - miles = round(meters) / 1000.0 * BAD_KM_TO_MI; - else - miles = meters / 1000.0 * KM_TO_MI; - if (data_cb) - data_cb(secs, nm, mph, watts, miles, cad, - hr, interval, context); - } - else { - sprintf(ebuf, "Unknown record type 0x%x on row %d.", buf[0], row); - if (error_cb) error_cb(ebuf, context); - return; - } - } - if (n != -1) { - sprintf(ebuf, "Parse error on row %d.", row); - if (error_cb) error_cb(ebuf, context); - return; - } -} - -#define NMATCH 9 -void -pt_read_dat(FILE *in, void (*record_cb)(double, double, double, int, - double, int, int, int, void*), - void *user_data) -{ - regex_t reg_com, reg_dat; - regmatch_t pmatch[NMATCH]; - char line[256]; - double min, nm, mph, miles; - int watts, cad, hr, intv; - int i, len; - - if (regcomp(®_com, "^#", REG_EXTENDED | REG_NOSUB)) - assert(0); - if (regcomp(®_dat, "^([0-9]+\\.[0-9]+) +([0-9]+\\.[0-9]+) +" - "([0-9]+\\.[0-9]+|NaN) +([0-9]+|NaN) +([0-9]+\\.[0-9]+) +" - "([0-9]+) +([0-9]+|NaN) +([0-9]+)$", REG_EXTENDED)) - assert(0); - - while (fgets(line, sizeof(line), in)) { - len = strlen(line); - if (!line[len-1] == '\n') - assert(0); - line[len-1] = '\0'; - if (regexec(®_com, line, 0, NULL, 0) == 0) { - /* do nothing */ - } - else if (regexec(®_dat, line, NMATCH, pmatch, 0) == 0) { - for (i = 0; i < NMATCH; ++i) - line[pmatch[i].rm_eo] = '\0'; - if (sscanf(line + pmatch[1].rm_so, "%lf", &min) != 1) - assert(0); - if (sscanf(line + pmatch[2].rm_so, "%lf", &nm) != 1) - assert(0); - if (sscanf(line + pmatch[3].rm_so, "%lf", &mph) != 1) - mph = -1.0; - if (sscanf(line + pmatch[4].rm_so, "%d", &watts) != 1) - watts = -1; - if (sscanf(line + pmatch[5].rm_so, "%lf", &miles) != 1) - assert(0); - if (sscanf(line + pmatch[6].rm_so, "%d", &cad) != 1) - assert(0); - if (sscanf(line + pmatch[7].rm_so, "%d", &hr) != 1) - hr = -1; - if (sscanf(line + pmatch[8].rm_so, "%d", &intv) != 1) - assert(0); - record_cb(min, nm, mph, watts, miles, cad, hr, intv, user_data); - } - else { - fprintf(stderr, "Bad line: \"%s\"\n", line); - exit(1); - } - } -} - diff --git a/src/lib/pt.h b/src/lib/pt.h deleted file mode 100644 index dab949cb5..000000000 --- a/src/lib/pt.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * $Id: pt.h,v 1.9 2006/09/06 23:23:03 srhea Exp $ - * - * Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __pt_h -#define __pt_h 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include -#include - -#define PT_DEBUG_NONE 0 -#define PT_DEBUG_MAX 1 -extern unsigned pt_debug_level; - -extern int pt_find_device(char *result[], int capacity); -extern int pt_hwecho(const char *device); - -#define PT_DONE 0 -#define PT_NEED_READ 1 - -extern void pt_make_async(int fd); - -struct pt_read_version_state { - int state; - int i; - unsigned char buf[30]; -}; -extern int pt_read_version(struct pt_read_version_state *state, - int fd, int *hwecho); - -struct pt_read_data_state { - int state; - int i; - unsigned block; - unsigned char header[6]; - unsigned char buf[256 * 6 + 1]; -}; -extern int pt_read_data(struct pt_read_data_state *state, - int fd, int hwecho, - void (*time_cb)(struct tm *, void *), - void (*record_cb)(unsigned char *, void *), - void *user_data); - -extern int pt_is_time(unsigned char *buf); -extern time_t pt_unpack_time(unsigned char *buf, struct tm *time); - -extern int pt_is_config(unsigned char *buf); -extern int pt_unpack_config(unsigned char *buf, unsigned *interval, - unsigned *last_interval, unsigned *rec_int, - unsigned *wheel_sz_mm); - -extern int pt_is_data(unsigned char *buf); -extern void pt_unpack_data(unsigned char *buf, int compat, unsigned rec_int, - unsigned wheel_sz_mm, double *time_secs, - double *torque_Nm, double *mph, double *watts, - double *dist_m, unsigned *cad, unsigned *hr); - -void pt_write_data(FILE *out, unsigned char *buf); -void pt_pack_header(unsigned char *buf); -void pt_pack_time(unsigned char *buf, struct tm *time); -void pt_pack_config(unsigned char *buf, unsigned interval, - unsigned rec_int, unsigned wheel_sz_mm); -void pt_pack_data(unsigned char *buf, unsigned wheel_sz_mm, double nm, - double mph, double miles, unsigned cad, unsigned hr); - -extern void pt_read_raw(FILE *in, int compat, void *context, - void (*config_cb)(unsigned interval, unsigned rec_int, - unsigned wheel_sz_mm, void *context), - void (*time_cb)(struct tm *time, time_t since_epoch, void *context), - void (*data_cb)(double secs, double nm, double mph, - double watts, double miles, unsigned cad, - unsigned hr, unsigned interval, void *context), - void (*error_cb)(const char *msg, void *context)); - -extern void pt_read_dat(FILE *in, - void (*record_cb)(double, double, double, int, - double, int, int, int, void*), - void *user_data); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __pt_h */ - diff --git a/src/src.pro b/src/src.pro index c17e0cdac..e480a5ea1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,6 +1,3 @@ TEMPLATE = subdirs CONFIG += ordered -macx || unix { - SUBDIRS = lib cmd -} SUBDIRS = srm pt gui