Subversion Repositories public

Rev

Rev 93 | Rev 136 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 93 Rev 101
Line 206... Line 206...
206
    ppid = garmin_gpid(link,garmin_packet_id(&p));
206
    ppid = garmin_gpid(link,garmin_packet_id(&p));
207
    if ( ppid == pid ) {
207
    if ( ppid == pid ) {
208
      d = garmin_unpack_packet(&p,type);
208
      d = garmin_unpack_packet(&p,type);
209
    } else {
209
    } else {
210
      /* Expected pid but got something else. */
210
      /* Expected pid but got something else. */
211
      printf("garmin_read_singleton: expected %d, got %d\n",pid,ppid);
211
      fprintf(stderr, "garmin_read_singleton: expected %d, got %d\n",pid,ppid);
212
    }
212
    }
213
  } else {
213
  } else {
214
    /* Failed to read the packet off the link. */
214
    /* Failed to read the packet off the link. */
215
    printf("garmin_read_singleton: failed to read Pid_Records packet\n");
215
    fprintf(stderr, "garmin_read_singleton: failed to read Pid_Records packet\n");
216
  }
216
  }
217
 
217
 
218
  return d;
218
  return d;
219
}
219
}
220
 
220
 
Line 239... Line 239...
239
    ppid = garmin_gpid(link,garmin_packet_id(&p));
239
    ppid = garmin_gpid(link,garmin_packet_id(&p));
240
    if ( ppid == Pid_Records ) {
240
    if ( ppid == Pid_Records ) {
241
      expected = get_uint16(p.packet.data);
241
      expected = get_uint16(p.packet.data);
242
 
242
 
243
      if ( garmin->verbose != 0 ) {
243
      if ( garmin->verbose != 0 ) {
244
	printf("[garmin] Pid_Records indicates %d packets to follow\n",
244
	fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
245
	       expected);
245
	       expected);
246
      }
246
      }
247
 
247
 
248
      /* Allocate a list for the records. */
248
      /* Allocate a list for the records. */
249
 
249
 
Line 258... Line 258...
258
      while ( !done && garmin_read(garmin,&p) > 0 ) {
258
      while ( !done && garmin_read(garmin,&p) > 0 ) {
259
	ppid = garmin_gpid(link,garmin_packet_id(&p));
259
	ppid = garmin_gpid(link,garmin_packet_id(&p));
260
	if ( ppid == Pid_Xfer_Cmplt ) {
260
	if ( ppid == Pid_Xfer_Cmplt ) {
261
	  if ( got != expected ) {
261
	  if ( got != expected ) {
262
	    /* Incorrect number of packets received. */
262
	    /* Incorrect number of packets received. */
263
	    printf("garmin_read_records: expected %d packets, got %d\n",
263
	    fprintf(stderr, "garmin_read_records: expected %d packets, got %d\n",
264
		   expected,got);
264
		   expected,got);
265
	  } else if ( garmin->verbose != 0 ) {
265
	  } else if ( garmin->verbose != 0 ) {
266
	    printf("[garmin] all %d expected packets received\n",got);
266
	    fprintf(stderr, "[garmin] all %d expected packets received\n",got);
267
	  }
267
	  }
268
	  done = 1;
268
	  done = 1;
269
	} else if ( ppid == pid ) {
269
	} else if ( ppid == pid ) {
270
	  garmin_list_append(l,garmin_unpack_packet(&p,type));
270
	  garmin_list_append(l,garmin_unpack_packet(&p,type));
271
	  got++;
271
	  got++;
Line 274... Line 274...
274
	  done = 1;
274
	  done = 1;
275
	}
275
	}
276
      }
276
      }
277
    } else {
277
    } else {
278
      /* Expected Pid_Records but got something else. */
278
      /* Expected Pid_Records but got something else. */
279
      printf("garmin_read_records: expected Pid_Records, got %d\n",ppid);
279
      fprintf(stderr, "garmin_read_records: expected Pid_Records, got %d\n",ppid);
280
    }
280
    }
281
  } else {
281
  } else {
282
    /* Failed to read the Pid_Records packet off the link. */
282
    /* Failed to read the Pid_Records packet off the link. */
283
    printf("garmin_read_records: failed to read Pid_Records packet\n");
283
    fprintf(stderr, "garmin_read_records: failed to read Pid_Records packet\n");
284
  }
284
  }
285
 
285
 
286
  return d;
286
  return d;
287
}
287
}
288
 
288
 
Line 309... Line 309...
309
    ppid = garmin_gpid(link,garmin_packet_id(&p));
309
    ppid = garmin_gpid(link,garmin_packet_id(&p));
310
    if ( ppid == Pid_Records ) {
310
    if ( ppid == Pid_Records ) {
311
      expected = get_uint16(p.packet.data);
311
      expected = get_uint16(p.packet.data);
312
 
312
 
313
      if ( garmin->verbose != 0 ) {
313
      if ( garmin->verbose != 0 ) {
314
	printf("[garmin] Pid_Records indicates %d packets to follow\n",
314
	fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
315
	       expected);
315
	       expected);
316
      }
316
      }
317
      
317
 
318
      /* Allocate a list for the records. */
318
      /* Allocate a list for the records. */
319
 
319
 
320
      d = garmin_alloc_data(data_Dlist);
320
      d = garmin_alloc_data(data_Dlist);
321
      l = (garmin_list *)d->data;
321
      l = (garmin_list *)d->data;
322
 
322
 
Line 324... Line 324...
324
	ppid = garmin_gpid(link,garmin_packet_id(&p));
324
	ppid = garmin_gpid(link,garmin_packet_id(&p));
325
	if ( ppid == Pid_Xfer_Cmplt ) {
325
	if ( ppid == Pid_Xfer_Cmplt ) {
326
	  /* transfer complete! */
326
	  /* transfer complete! */
327
	  if ( got != expected ) {
327
	  if ( got != expected ) {
328
	    /* wrong number of packets received! */
328
	    /* wrong number of packets received! */
329
	    printf("garmin_read_records2: expected %d packets, got %d\n",
329
	    fprintf(stderr, "garmin_read_records2: expected %d packets, got %d\n",
330
		   expected,got);
330
		   expected,got);
331
	  } else if ( garmin->verbose != 0 ) {
331
	  } else if ( garmin->verbose != 0 ) {
332
	    printf("[garmin] all %d expected packets received\n",got);
332
	    fprintf(stderr, "[garmin] all %d expected packets received\n",got);
333
	  }
333
	  }
334
	  break;
334
	  break;
335
	}
335
	}
336
	switch ( state ) {
336
	switch ( state ) {
337
	case 0:  /* want pid1 */
337
	case 0:  /* want pid1 */
Line 370... Line 370...
370
	  break;
370
	  break;
371
	}
371
	}
372
      }
372
      }
373
      if ( state < 0 ) {
373
      if ( state < 0 ) {
374
	/* Unexpected packet received. */
374
	/* Unexpected packet received. */
375
	printf("garmin_read_records2: unexpected packet %d received\n",ppid);
375
	fprintf(stderr, "garmin_read_records2: unexpected packet %d received\n",ppid);
376
      }
376
      }
377
    } else {
377
    } else {
378
      /* Expected Pid_Records but got something else. */
378
      /* Expected Pid_Records but got something else. */
379
      printf("garmin_read_records2: expected Pid_Records, got %d\n",ppid);
379
      fprintf(stderr, "garmin_read_records2: expected Pid_Records, got %d\n",ppid);
380
    }
380
    }
381
  } else {
381
  } else {
382
    /* Failed to read the Pid_Records packet off the link. */
382
    /* Failed to read the Pid_Records packet off the link. */
383
    printf("garmin_read_records2: failed to read Pid_Records packet\n");
383
    fprintf(stderr, "garmin_read_records2: failed to read Pid_Records packet\n");
384
  }
384
  }
385
 
385
 
386
  return d;
386
  return d;
387
}
387
}
388
 
388
 
Line 411... Line 411...
411
    ppid = garmin_gpid(link,garmin_packet_id(&p));
411
    ppid = garmin_gpid(link,garmin_packet_id(&p));
412
    if ( ppid == Pid_Records ) {
412
    if ( ppid == Pid_Records ) {
413
      expected = get_uint16(p.packet.data);
413
      expected = get_uint16(p.packet.data);
414
 
414
 
415
      if ( garmin->verbose != 0 ) {
415
      if ( garmin->verbose != 0 ) {
416
	printf("[garmin] Pid_Records indicates %d packets to follow\n",
416
	fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
417
	       expected);
417
	       expected);
418
      }
418
      }
419
 
419
 
420
      /* Allocate a list for the records. */
420
      /* Allocate a list for the records. */
421
 
421
 
Line 426... Line 426...
426
	ppid = garmin_gpid(link,garmin_packet_id(&p));
426
	ppid = garmin_gpid(link,garmin_packet_id(&p));
427
	if ( ppid == Pid_Xfer_Cmplt ) {
427
	if ( ppid == Pid_Xfer_Cmplt ) {
428
	  /* transfer complete! */
428
	  /* transfer complete! */
429
	  if ( got != expected ) {
429
	  if ( got != expected ) {
430
	    /* wrong number of packets received! */
430
	    /* wrong number of packets received! */
431
	    printf("garmin_read_records3: expected %d packets, got %d\n",
431
	    fprintf(stderr, "garmin_read_records3: expected %d packets, got %d\n",
432
		   expected,got);
432
		   expected,got);
433
	  } else if ( garmin->verbose != 0 ) {
433
	  } else if ( garmin->verbose != 0 ) {
434
	    printf("[garmin] all %d expected packets received\n",got);
434
	    fprintf(stderr, "[garmin] all %d expected packets received\n",got);
435
	  }
435
	  }
436
	  break;
436
	  break;
437
	}
437
	}
438
	switch ( state ) {
438
	switch ( state ) {
439
	case 0:  /* want pid1 */
439
	case 0:  /* want pid1 */
Line 481... Line 481...
481
	  break;
481
	  break;
482
	}
482
	}
483
      }
483
      }
484
      if ( state < 0 ) {
484
      if ( state < 0 ) {
485
	/* Unexpected packet received. */
485
	/* Unexpected packet received. */
486
	printf("garmin_read_records3: unexpected packet %d received\n",ppid);
486
	fprintf(stderr, "garmin_read_records3: unexpected packet %d received\n",ppid);
487
      }
487
      }
488
    } else {
488
    } else {
489
      /* Expected Pid_Records but got something else. */
489
      /* Expected Pid_Records but got something else. */
490
      printf("garmin_read_records3: expected Pid_Records, got %d\n",ppid);
490
      fprintf(stderr, "garmin_read_records3: expected Pid_Records, got %d\n",ppid);
491
    }
491
    }
492
  } else {
492
  } else {
493
    /* Failed to read the Pid_Records packet off the link. */
493
    /* Failed to read the Pid_Records packet off the link. */
494
    printf("garmin_read_records3: failed to read Pid_Records packet\n");
494
    printf(stderr, "garmin_read_records3: failed to read Pid_Records packet\n");
495
  }
495
  }
496
 
496
 
497
  return d;
497
  return d;
498
}
498
}
499
 
499
 
Line 1156... Line 1156...
1156
}
1156
}
1157
 
1157
 
1158
 
1158
 
1159
/* Initialize a connection with a Garmin unit. */
1159
/* Initialize a connection with a Garmin unit. */
1160
 
1160
 
1161
int
-
 
1162
garmin_init ( garmin_unit * garmin, int verbose )
1161
int garmin_init(garmin_unit *garmin, int verbose)
1163
{
1162
{
1164
  memset(garmin,0,sizeof(garmin_unit));
1163
	memset(garmin, 0, sizeof(garmin_unit));
1165
  garmin->verbose = verbose;
1164
	garmin->verbose = verbose;
-
 
1165
	garmin->usb.fd = -1;
1166
 
1166
 
1167
  if ( garmin_open(garmin) != 0 ) {
1167
	if ( garmin_open(garmin) != 0 )
-
 
1168
	{
1168
    garmin_start_session(garmin);
1169
	   garmin_start_session(garmin);
1169
    garmin_read_a000_a001(garmin);
1170
	   garmin_read_a000_a001(garmin);
1170
    return 1;
1171
	   return 1;
-
 
1172
	}
1171
  } else {
1173
	else
-
 
1174
	{
1172
    return 0;
1175
	   return 0;
1173
  }
1176
	}
1174
}
1177
}
1175
 
1178