Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 135 → Rev 136

/sportwatcher/trunk/libgarmin/byte_util.c
66,7 → 66,7
char *
get_string ( garmin_packet * p, int * offset )
{
char * start = p->packet.data + *offset;
char * start = (char *)(p->packet.data + *offset);
char * cursor = start;
int allow = garmin_packet_size(p) - *offset;
char * ret = NULL;
117,7 → 117,7
put_vstring ( uint8 ** buf, const char * x )
{
if ( x != NULL ) {
strcpy(*buf,x);
strcpy((char *)*buf,x);
*buf += strlen(x)+1;
}
}
131,7 → 131,7
char **
get_strings ( garmin_packet * p, int * offset )
{
char * start = p->packet.data + *offset;
char * start = (char *)(p->packet.data + *offset);
char * cursor = start;
int allow = garmin_packet_size(p) - *offset;
char ** ret = NULL;
/sportwatcher/trunk/libgarmin/Makefile.in
62,16 → 62,18
libgarmin_a_AR = $(AR) $(ARFLAGS)
libgarmin_a_LIBADD =
am_libgarmin_a_OBJECTS = byte_util.$(OBJEXT) command.$(OBJEXT) \
datatype.$(OBJEXT) pack.$(OBJEXT) packet_id.$(OBJEXT) \
protocol.$(OBJEXT) run.$(OBJEXT) scan.$(OBJEXT) \
symbol_name.$(OBJEXT) unpack.$(OBJEXT) usb_comm.$(OBJEXT)
datatype.$(OBJEXT) error.$(OBJEXT) pack.$(OBJEXT) \
packet_id.$(OBJEXT) prghook.$(OBJEXT) protocol.$(OBJEXT) \
run.$(OBJEXT) scan.$(OBJEXT) symbol_name.$(OBJEXT) \
unpack.$(OBJEXT) usb_comm.$(OBJEXT)
#>- libgarmin_a_OBJECTS = $(am_libgarmin_a_OBJECTS)
#>+ 7
libgarmin_a_final_OBJECTS = byte_util.o command.o datatype.o pack.o packet_id.o protocol.o run.o scan.o symbol_name.o unpack.o usb_comm.o
#>+ 8
libgarmin_a_final_OBJECTS = byte_util.o command.o datatype.o error.o pack.o packet_id.o prghook.o protocol.o run.o scan.o symbol_name.o unpack.o usb_comm.o
libgarmin_a_nofinal_OBJECTS = byte_util.$(OBJEXT) command.$(OBJEXT) \
datatype.$(OBJEXT) pack.$(OBJEXT) packet_id.$(OBJEXT) \
protocol.$(OBJEXT) run.$(OBJEXT) scan.$(OBJEXT) \
symbol_name.$(OBJEXT) unpack.$(OBJEXT) usb_comm.$(OBJEXT)
datatype.$(OBJEXT) error.$(OBJEXT) pack.$(OBJEXT) \
packet_id.$(OBJEXT) prghook.$(OBJEXT) protocol.$(OBJEXT) \
run.$(OBJEXT) scan.$(OBJEXT) symbol_name.$(OBJEXT) \
unpack.$(OBJEXT) usb_comm.$(OBJEXT)
@KDE_USE_FINAL_FALSE@libgarmin_a_OBJECTS = $(libgarmin_a_nofinal_OBJECTS)
@KDE_USE_FINAL_TRUE@libgarmin_a_OBJECTS = $(libgarmin_a_final_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
339,8 → 341,8
#>- METASOURCES = AUTO
lib_LIBRARIES = libgarmin.a
libgarmin_a_LDFLAGS = -module -no-undefined
libgarmin_a_SOURCES = byte_util.c command.c datatype.c garmin.h pack.c \
packet_id.c protocol.c run.c scan.c symbol_name.c unpack.c usb_comm.c
libgarmin_a_SOURCES = byte_util.c command.c datatype.c error.c garmin.h pack.c \
packet_id.c prghook.c protocol.c run.c scan.c symbol_name.c unpack.c usb_comm.c
 
#>- all: all-am
#>+ 1
433,8 → 435,10
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/byte_util.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/datatype.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/error.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pack.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/packet_id.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prghook.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protocol.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scan.Po@am__quote@
652,7 → 656,6
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
 
 
#>+ 2
KDE_DIST=Makefile.in BUGS print.c Makefile.am
 
/sportwatcher/trunk/libgarmin/protocol.c
201,6 → 201,7
garmin_packet p;
link_protocol link = garmin->protocol.link;
garmin_pid ppid;
char hv0[256];
 
if ( garmin_read(garmin,&p) > 0 ) {
ppid = garmin_gpid(link,garmin_packet_id(&p));
208,11 → 209,13
d = garmin_unpack_packet(&p,type);
} else {
/* Expected pid but got something else. */
fprintf(stderr, "garmin_read_singleton: expected %d, got %d\n",pid,ppid);
sprintf(hv0, "garmin_read_singleton: expected %d, got %d!",pid,ppid);
garmin_queue_error(hv0, err_warning);
}
} else {
/* Failed to read the packet off the link. */
fprintf(stderr, "garmin_read_singleton: failed to read Pid_Records packet\n");
sprintf(hv0, "garmin_read_singleton: failed to read Pid_Records packet!");
garmin_queue_error(hv0, err_warning);
}
 
return d;
234,6 → 237,7
int expected = 0;
int got = 0;
garmin_pid ppid;
char hv0[256];
 
if ( garmin_read(garmin,&p) > 0 ) {
ppid = garmin_gpid(link,garmin_packet_id(&p));
241,8 → 245,9
expected = get_uint16(p.packet.data);
 
if ( garmin->verbose != 0 ) {
fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
sprintf(hv0, "[garmin] Pid_Records indicates %d packets to follow!",
expected);
garmin_queue_error(hv0, err_info);
}
 
/* Allocate a list for the records. */
260,10 → 265,12
if ( ppid == Pid_Xfer_Cmplt ) {
if ( got != expected ) {
/* Incorrect number of packets received. */
fprintf(stderr, "garmin_read_records: expected %d packets, got %d\n",
sprintf(hv0, "garmin_read_records: expected %d packets, got %d!",
expected,got);
garmin_queue_error(hv0, err_error);
} else if ( garmin->verbose != 0 ) {
fprintf(stderr, "[garmin] all %d expected packets received\n",got);
sprintf(hv0, "[garmin] all %d expected packets received!",got);
garmin_queue_error(hv0, err_info);
}
done = 1;
} else if ( ppid == pid ) {
276,11 → 283,13
}
} else {
/* Expected Pid_Records but got something else. */
fprintf(stderr, "garmin_read_records: expected Pid_Records, got %d\n",ppid);
sprintf(hv0, "garmin_read_records: expected Pid_Records, got %d!",ppid);
garmin_queue_error(hv0, err_error);
}
} else {
/* Failed to read the Pid_Records packet off the link. */
fprintf(stderr, "garmin_read_records: failed to read Pid_Records packet\n");
sprintf(hv0, "garmin_read_records: failed to read Pid_Records packet!");
garmin_queue_error(hv0, err_error);
}
 
return d;
304,6 → 313,7
int got = 0;
int state = 0;
garmin_pid ppid;
char hv0[256];
 
if ( garmin_read(garmin,&p) > 0 ) {
ppid = garmin_gpid(link,garmin_packet_id(&p));
311,8 → 321,9
expected = get_uint16(p.packet.data);
 
if ( garmin->verbose != 0 ) {
fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
sprintf(hv0, "[garmin] Pid_Records indicates %d packets to follow!",
expected);
garmin_queue_error(hv0, err_info);
}
 
/* Allocate a list for the records. */
326,10 → 337,12
/* transfer complete! */
if ( got != expected ) {
/* wrong number of packets received! */
fprintf(stderr, "garmin_read_records2: expected %d packets, got %d\n",
sprintf(hv0, "garmin_read_records2: expected %d packets, got %d!",
expected,got);
garmin_queue_error(hv0, err_error);
} else if ( garmin->verbose != 0 ) {
fprintf(stderr, "[garmin] all %d expected packets received\n",got);
sprintf(hv0, "[garmin] all %d expected packets received!",got);
garmin_queue_error(hv0, err_info);
}
break;
}
372,15 → 385,18
}
if ( state < 0 ) {
/* Unexpected packet received. */
fprintf(stderr, "garmin_read_records2: unexpected packet %d received\n",ppid);
sprintf(hv0, "garmin_read_records2: unexpected packet %d received!",ppid);
garmin_queue_error(hv0, err_error);
}
} else {
/* Expected Pid_Records but got something else. */
fprintf(stderr, "garmin_read_records2: expected Pid_Records, got %d\n",ppid);
sprintf(hv0, "garmin_read_records2: expected Pid_Records, got %d!",ppid);
garmin_queue_error(hv0, err_error);
}
} else {
/* Failed to read the Pid_Records packet off the link. */
fprintf(stderr, "garmin_read_records2: failed to read Pid_Records packet\n");
sprintf(hv0, "garmin_read_records2: failed to read Pid_Records packet!");
garmin_queue_error(hv0, err_error);
}
 
return d;
406,6 → 422,7
int got = 0;
garmin_pid ppid;
int state = 0;
char hv0[256];
 
if ( garmin_read(garmin,&p) > 0 ) {
ppid = garmin_gpid(link,garmin_packet_id(&p));
413,8 → 430,9
expected = get_uint16(p.packet.data);
 
if ( garmin->verbose != 0 ) {
fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
sprintf(hv0, "[garmin] Pid_Records indicates %d packets to follow!",
expected);
garmin_queue_error(hv0, err_info);
}
 
/* Allocate a list for the records. */
428,10 → 446,12
/* transfer complete! */
if ( got != expected ) {
/* wrong number of packets received! */
fprintf(stderr, "garmin_read_records3: expected %d packets, got %d\n",
sprintf(hv0, "garmin_read_records3: expected %d packets, got %d!",
expected,got);
garmin_queue_error(hv0, err_error);
} else if ( garmin->verbose != 0 ) {
fprintf(stderr, "[garmin] all %d expected packets received\n",got);
sprintf(hv0, "[garmin] all %d expected packets received!",got);
garmin_queue_error(hv0, err_info);
}
break;
}
483,15 → 503,18
}
if ( state < 0 ) {
/* Unexpected packet received. */
fprintf(stderr, "garmin_read_records3: unexpected packet %d received\n",ppid);
sprintf(hv0, "garmin_read_records3: unexpected packet %d received!",ppid);
garmin_queue_error(hv0, err_error);
}
} else {
/* Expected Pid_Records but got something else. */
fprintf(stderr, "garmin_read_records3: expected Pid_Records, got %d\n",ppid);
sprintf(hv0, "garmin_read_records3: expected Pid_Records, got %d!",ppid);
garmin_queue_error(hv0, err_error);
}
} else {
/* Failed to read the Pid_Records packet off the link. */
printf(stderr, "garmin_read_records3: failed to read Pid_Records packet\n");
sprintf(hv0, "garmin_read_records3: failed to read Pid_Records packet!");
garmin_queue_error(hv0, err_error);
}
 
return d;
519,7 → 542,6
uint16 * datatypes;
 
/* Send the product request */
garmin_packetize(&p,L000_Pid_Product_Rqst,0,NULL);
garmin_write(garmin,&p);
 
584,6 → 606,8
break;
}
}
 
garmin_callback("product_request");
}
 
 
1087,11 → 1111,11
#define CASE_PROTOCOL(x) \
case appl_A##x: \
if ( garmin->verbose != 0 ) { \
printf("[garmin] -> garmin_read_a" #x "\n"); \
fprintf(stderr, "[garmin] -> garmin_read_a" #x "\n"); \
} \
data = garmin_read_a##x(garmin); \
if ( garmin->verbose != 0 ) { \
printf("[garmin] <- garmin_read_a" #x "\n"); \
fprintf(stderr, "[garmin] <- garmin_read_a" #x "\n"); \
} \
break
 
1117,6 → 1141,7
break;
}
 
garmin_callback();
return data;
}
 
/sportwatcher/trunk/libgarmin/usb_comm.c
105,6 → 105,7
static unsigned int rates[] = {0, 4800, 9600, 19200, 38400, 57600};
garmin_packet p;
struct sigaction saio;
char hv0[1024];
 
if (method && garmin->usb.fd == -1)
{
111,7 → 112,7
/* check for USB serial drivers -- very Linux-specific */
if (access("/sys/module/garmin_gps", R_OK) != 0)
{
fprintf(stderr, "garmin_gps not active.\n");
garmin_queue_error("garmin_gps not active!", err_error);
return 0;
}
 
167,11 → 168,12
 
if ( garmin->verbose != 0 )
{
fprintf(stderr, "[garmin] found VID %04x, PID %04x on %s/%s\n",
sprintf(hv0, "[garmin] found VID %04x, PID %04x on %s/%s!",
di->descriptor.idVendor,
di->descriptor.idProduct,
bi->dirname,
di->filename);
garmin_queue_error(hv0, err_info);
}
 
garmin->usb.handle = usb_open(di);
179,19 → 181,22
 
if ( garmin->usb.handle == NULL )
{
fprintf(stderr, "usb_open failed: %s\n",usb_strerror());
sprintf(hv0, "usb_open failed: %s!",usb_strerror());
garmin_queue_error(hv0, err_error);
return 0;
}
 
if ( usb_set_configuration(garmin->usb.handle,1) < 0 )
if (usb_set_configuration(garmin->usb.handle, 1) < 0 )
{
fprintf(stderr, "usb_set_configuration failed: %s\n",usb_strerror());
sprintf(hv0, "usb_set_configuration failed: %s!",usb_strerror());
garmin_queue_error(hv0, err_error);
return 0;
}
 
if ( usb_claim_interface(garmin->usb.handle,0) < 0 )
{
fprintf(stderr, "usb_claim_interface failed: %s\n",usb_strerror());
sprintf(hv0, "usb_claim_interface failed: %s!",usb_strerror());
garmin_queue_error(hv0, err_error);
return 0;
}
 
233,6 → 238,8
if ( garmin->usb.handle != NULL )
break;
}
 
garmin_queue_error("Couldn't detect any Garmin device!", err_info);
}
 
return (garmin->usb.handle != NULL);
354,6 → 361,7
struct timeval tv;
int sel_ret = 0;
int ok = 0;
char hv0[1024];
 
if (garmin->usb.fd == -1 && garmin->usb.handle == NULL)
garmin_open(garmin);
386,11 → 394,13
/* read error...
* or EAGAIN, but O_NONBLOCK is never set
*/
fprintf(stderr, "Read error=%ld, errno=%d\n", theBytesReturned, errno);
sprintf(hv0, "Read error=%ld, errno=%d!", theBytesReturned, errno);
garmin_queue_error(hv0, err_error);
continue;
}
 
fprintf(stderr, "got %ld bytes\n", theBytesReturned);
sprintf(hv0, "got %ld bytes.", theBytesReturned);
garmin_queue_error(hv0, err_info);
bLen += theBytesReturned;
 
if (theBytesReturned < ASYNC_DATA_SIZE)
403,7 → 413,7
{
/* really bad read error... */
bLen = 0;
fprintf(stderr, "Packet too long!\n");
garmin_queue_error("Packet too long!", err_fatal);
break;
}
 
432,7 → 442,8
garmin_packet_id(p) == Pid_Data_Available)
{
/* FIXME!!! */
fprintf(stderr, "Received a Pid_Data_Available from the unit!\n");
sprintf(hv0, "Received a Pid_Data_Available from the unit!");
garmin_queue_error(hv0, err_warning);
}
}
else
480,10 → 491,18
 
if (r != s)
{
char hv0[1024];
 
if (method)
fprintf(stderr, "Write to device failed!\n");
{
sprintf(hv0, "Write to device failed!");
garmin_queue_error(hv0, err_error);
}
else
fprintf(stderr, "usb_bulk_write failed: %s\n", usb_strerror());
{
sprintf(stderr, "usb_bulk_write failed: %s!", usb_strerror());
garmin_queue_error(hv0, err_error);
}
 
return 0;
}
524,6 → 543,7
garmin->id = 0;
}
 
garmin_callback("start_session");
return garmin->id;
}
 
/sportwatcher/trunk/libgarmin/prghook.c
0,0 → 1,41
/***************************************************************************
* Copyright (C) 2007, 2008 by Andreas Theofilu *
* andreas@theosys.at *
* *
* 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 version 3 of the License. *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
 
#include "garmin.h"
 
static void (*callback)(char *str) = NULL;
 
void garmin_set_hook(void (*func)(char *str))
{
if (!func)
return;
 
callback = func;
}
 
void garmin_clear_hook()
{
callback = NULL;
}
 
void garmin_callback(char *str)
{
if (callback)
callback(str);
}
/sportwatcher/trunk/libgarmin/datatype.c
106,11 → 106,11
 
n->data = data;
n->next = NULL;
 
if ( l->head == NULL ) l->head = n;
if ( l->tail != NULL ) l->tail->next = n;
l->tail = n;
 
l->elements++;
}
 
277,6 → 277,7
garmin_list * list;
garmin_list_node * node;
uint32 bytes = 0;
char hv0[256];
 
/*
The number of bytes needed in order to serialize a Garmin data structure
414,7 → 415,8
DATASIZE0(1013);
DATASIZE0(1015);
default:
printf("garmin_data_size: data type %d not supported\n",d->type);
sprintf(hv0, "garmin_data_size: data type %d not supported!",d->type);
garmin_queue_error(hv0, err_warning);
break;
}
}
/sportwatcher/trunk/libgarmin/pack.c
1096,7 → 1096,9
rpath[j] = 0;
if ( stat(rpath,&sb) != -1 ) { /* this part already exists */
if ( !S_ISDIR(sb.st_mode) ) { /* but is not a directory! */
fprintf(stderr,"mkpath: %s exists but is not a directory",rpath);
char hv0[1024];
sprintf(&hv0[0], "mkpath: %s exists but is not a directory",rpath);
garmin_queue_error(hv0, err_error);
ok = 0;
break;
} else {
1114,7 → 1116,9
chown(rpath,owner,group);
}
} else {
fprintf(stderr,"mkpath: mkdir(%s,%o): %s",path,mode,strerror(errno));
char hv0[1024];
sprintf(hv0, "mkpath: mkdir(%s,%o): %s",path,mode,strerror(errno));
garmin_queue_error(hv0, err_error);
ok = 0;
break;
}
1129,7 → 1133,9
chown(rpath,owner,group);
}
} else {
fprintf(stderr,"mkpath: mkdir(%s,%o): %s",path,mode,strerror(errno));
char hv0[1024];
sprintf(hv0, "mkpath: mkdir(%s,%o): %s",path,mode,strerror(errno));
garmin_queue_error(hv0, err_error);
ok = 0;
}
 
1182,7 → 1188,7
 
pos = buf;
memset(pos,0,GARMIN_HEADER);
strncpy(pos,GARMIN_MAGIC,11);
strncpy((char *)pos,GARMIN_MAGIC,11);
put_uint32(pos+12,GARMIN_VERSION);
marker = pos+16;
pos += GARMIN_HEADER;
1197,8 → 1203,10
 
if ( (wrote = write(fd,buf,packed)) != packed ) {
/* write error! */
printf("write of %d bytes returned %d: %s\n",
char hv0[256];
sprintf(hv0, "write of %d bytes returned %d: %s",
packed,wrote,strerror(errno));
garmin_queue_error(hv0, err_error);
}
close(fd);
 
1208,15 → 1216,21
 
} else {
/* malloc error */
printf("malloc(%d): %s\n",bytes + GARMIN_HEADER, strerror(errno));
char hv0[256];
sprintf(hv0, "malloc(%d): %s",bytes + GARMIN_HEADER, strerror(errno));
garmin_queue_error(hv0, err_error);
}
} else {
/* problem creating file. */
printf("creat: %s: %s\n",path,strerror(errno));
char hv0[1024];
sprintf(hv0, "creat: %s: %s",path,strerror(errno));
garmin_queue_error(hv0, err_error);
}
} else {
/* don't write empty data */
printf("%s: garmin_data_size was 0\n",path);
char hv0[1024];
printf("%s: garmin_data_size was 0",path);
garmin_queue_error(hv0, err_error);
}
 
return bytes;
1239,6 → 1253,7
uint8 * finish;
uint8 * marker;
uint32 bytes = 0;
char hv0[256];
 
if ( garmin_data_size(data) == 0 ) return 0;
 
1319,7 → 1334,8
CASE_DATA(1013);
CASE_DATA(1015);
default:
printf("garmin_pack: data type %d not supported\n",data->type);
sprintf(hv0, "garmin_pack: data type %d not supported",data->type);
garmin_queue_error(hv0, err_warning);
break;
}
#undef CASE_DATA
/sportwatcher/trunk/libgarmin/command.c
217,9 → 217,10
garmin_make_command_packet(garmin,cmd,&packet) ) {
ret = garmin_write(garmin,&packet);
} else {
char hv0[256];
/* Error: command not supported */
 
printf("Error: command %d not supported\n",cmd);
sprintf(&hv0[0], "Error: command %d not supported!",cmd);
garmin_queue_error(hv0, err_error);
}
 
return ret;
/sportwatcher/trunk/libgarmin/unpack.c
1069,8 → 1069,10
garmin_list_append(list,garmin_unpack(pos,type));
} else {
/* list element has wrong list ID */
printf("garmin_unpack_dlist: list element had ID %d, expected ID %d\n",
char hv0[256];
sprintf(hv0, "garmin_unpack_dlist: list element had ID %d, expected ID %d!",
id,list->id);
garmin_queue_error(hv0, err_error);
}
}
}
1088,6 → 1090,7
uint32 size;
uint32 type;
uint32 chunk;
char hv0[256];
 
/* First, read the header and check that it's satisfactory. */
1097,8 → 1100,9
if ( version > GARMIN_VERSION ) {
/* warning: version is more recent than supported. */
printf("garmin_unpack_chunk: version %.2f supported, %.2f found\n",
sprintf(hv0, "garmin_unpack_chunk: version %.2f supported, %.2f found!",
GARMIN_VERSION/100.0, version/100.0);
garmin_queue_error(hv0, err_warning);
}
/* This is the size of the packed data (not including the header) */
1118,15 → 1122,16
 
/* Double check - did we unpack the number of bytes we were supposed to? */
 
if ( unpacked != chunk ) {
if ( unpacked != chunk ) {
/* unpacked the wrong number of bytes! */
printf("garmin_unpack_chunk: unpacked %d bytes (expecting %d)\n",
sprintf(hv0, "garmin_unpack_chunk: unpacked %d bytes (expecting %d)!",
unpacked,chunk);
garmin_queue_error(hv0, err_error);
}
} else {
/* unknown file format */
printf("garmin_unpack_chunk: not a .gmn file\n");
sprintf(hv0, "garmin_unpack_chunk: not a .gmn file!");
garmin_queue_error(hv0, err_fatal);
}
 
return data;
1149,6 → 1154,7
uint8 * start;
struct stat sb;
int fd;
char hv0[1024];
 
if ( (fd = open(filename,O_RDONLY)) != -1 ) {
if ( fstat(fd,&sb) != -1 ) {
1162,7 → 1168,8
garmin_list_append(list,garmin_unpack_chunk(&pos));
if ( pos == start ) {
/* did not unpack anything! */
printf("garmin_load: %s: nothing unpacked!\n",filename);
sprintf(hv0, "garmin_load: %s: nothing unpacked!",filename);
garmin_queue_error(hv0, err_error);
break;
}
}
1178,25 → 1185,29
garmin_free_data(data_l);
} else {
data = data_l;
}
}
 
} else {
/* read failed */
printf("%s: read: %s\n",filename,strerror(errno));
sprintf(hv0, "%s: read: %s!",filename,strerror(errno));
garmin_queue_error(hv0, err_error);
}
free(buf);
} else {
/* malloc failed */
printf("%s: malloc: %s\n",filename,strerror(errno));
sprintf(hv0, "%s: malloc: %s!",filename,strerror(errno));
garmin_queue_error(hv0, err_fatal);
}
} else {
/* fstat failed */
printf("%s: fstat: %s\n",filename,strerror(errno));
sprintf(hv0, "%s: fstat: %s!",filename,strerror(errno));
garmin_queue_error(hv0, err_error);
}
close(fd);
} else {
/* open failed */
printf("%s: open: %s\n",filename,strerror(errno));
sprintf(hv0, "%s: open: %s!",filename,strerror(errno));
garmin_queue_error(hv0, err_error);
}
 
return data;
1225,6 → 1236,7
garmin_datatype type )
{
garmin_data * d = garmin_alloc_data(type);
char hv0[256];
 
/* Early exit if we were asked to allocate an unknown data type. */
 
1297,7 → 1309,8
CASE_DATA(1013);
CASE_DATA(1015);
default:
printf("garmin_unpack: data type %d not supported\n",type);
sprintf(hv0, "garmin_unpack: data type %d not supported!",type);
garmin_queue_error(hv0, err_warning);
break;
}
 
/sportwatcher/trunk/libgarmin/garmin.h
1942,7 → 1942,14
GET_COURSE_LIMITS
} garmin_get_type;
 
typedef enum {
err_info,
err_warning,
err_error,
err_fatal
} err_type;
 
 
/* ========================================================================= */
/* Function prototypes */
/* ========================================================================= */
2121,5 → 2128,22
 
void garmin_save_runs ( garmin_unit * garmin );
 
/* ------------------------------------------------------------------------- */
/* prghook.c */
/* ------------------------------------------------------------------------- */
 
void garmin_set_hook(void (*func)(char *str));
void garmin_clear_hook();
void garmin_callback();
 
/* ------------------------------------------------------------------------- */
/* error.c */
/* ------------------------------------------------------------------------- */
 
void garmin_queue_error(char *str, err_type type);
void garmin_clear_errors();
char *garmin_get_first_error(int *key);
char *garmin_get_next_error(int *key);
int garmin_count_error();
 
#endif /* __GARMIN_GARMIN_H__ */
/sportwatcher/trunk/libgarmin/Makefile.am
1,5 → 1,5
METASOURCES = AUTO
lib_LIBRARIES = libgarmin.a
libgarmin_a_LDFLAGS = -module -no-undefined
libgarmin_a_SOURCES = byte_util.c command.c datatype.c garmin.h pack.c \
packet_id.c protocol.c run.c scan.c symbol_name.c unpack.c usb_comm.c
libgarmin_a_SOURCES = byte_util.c command.c datatype.c error.c garmin.h pack.c \
packet_id.c prghook.c protocol.c run.c scan.c symbol_name.c unpack.c usb_comm.c
/sportwatcher/trunk/libgarmin/error.c
0,0 → 1,183
/***************************************************************************
* Copyright (C) 2007, 2008 by Andreas Theofilu *
* andreas@theosys.at *
* *
* 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 version 3 of the License. *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
 
#include "garmin.h"
#include <stdio.h>
#include <string.h>
 
struct GARMIN_ERROR
{
int idx;
err_type type;
char *gerr;
struct GARMIN_ERROR *next;
} GARMIN_ERROR;
 
static struct GARMIN_ERROR *gerr = NULL;
 
void garmin_queue_error(char *str, err_type type)
{
int idx = 0;
char *p, *s;
 
if (!str)
return;
 
switch (type)
{
case err_info:
p = strdup("Information");
break;
 
case err_warning:
p = strdup("Warning");
break;
 
case err_error:
p = strdup("Error");
break;
 
case err_fatal:
p = strdup("Fatal error");
break;
 
default:
p = strdup("Unknown");
}
 
if ((s = (char *)malloc(strlen(p) + strlen(str) + 10)) == NULL)
{
if (p)
free(p);
 
fprintf(stderr, "Not enough memory!\n");
return;
}
 
sprintf(s, "%s:\n%s", p, str);
free(p);
 
if (!gerr)
{
if ((gerr = (struct GARMIN_ERROR *)malloc(sizeof(struct GARMIN_ERROR))) == NULL)
{
fprintf(stderr, "Not enough memory!\n");
return;
}
 
gerr->idx = idx;
gerr->type = type;
gerr->gerr = s;
gerr->next = NULL;
}
else
{
struct GARMIN_ERROR *akt, *n;
 
if ((n = (struct GARMIN_ERROR *)malloc(sizeof(struct GARMIN_ERROR))) == NULL)
{
fprintf(stderr, "Not enough memory!\n");
return;
}
 
/* Find last error message */
akt = gerr;
 
while (akt->next)
{
akt = akt->next;
idx++;
}
 
idx++;
n->idx = idx;
n->type = type;
n->gerr = s;
n->next = NULL;
akt->next = n;
}
}
 
void garmin_clear_errors()
{
struct GARMIN_ERROR *akt, *old;
 
akt = gerr;
 
while (akt)
{
old = akt;
akt = akt->next;
 
if (old->gerr)
free(old->gerr);
 
free(old);
}
 
gerr = NULL;
}
 
char *garmin_get_first_error(int *key)
{
if (key)
*key = gerr->idx;
 
return gerr->gerr;
}
 
char *garmin_get_next_error(int *key)
{
struct GARMIN_ERROR *akt;
 
if (!key)
return NULL;
 
if (*key == -1)
return garmin_get_first_error(key);
 
akt = gerr;
 
while (akt)
{
if (*key == akt->idx && akt->next)
{
*key = akt->next->idx;
return akt->next->gerr;
}
 
akt = akt->next;
}
 
return NULL;
}
 
int garmin_count_error()
{
struct GARMIN_ERROR *akt = gerr;
int idx = 0;
 
while (akt)
{
idx++;
akt = akt->next;
}
 
return idx;
}