Subversion Repositories public

Rev

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

Rev 101 Rev 136
Line 199... Line 199...
199
{
199
{
200
  garmin_data *     d = NULL;
200
  garmin_data *     d = NULL;
201
  garmin_packet     p;
201
  garmin_packet     p;
202
  link_protocol     link = garmin->protocol.link;
202
  link_protocol     link = garmin->protocol.link;
203
  garmin_pid        ppid;
203
  garmin_pid        ppid;
-
 
204
  char              hv0[256];
204
 
205
 
205
  if ( garmin_read(garmin,&p) > 0 ) {
206
  if ( garmin_read(garmin,&p) > 0 ) {
206
    ppid = garmin_gpid(link,garmin_packet_id(&p));
207
    ppid = garmin_gpid(link,garmin_packet_id(&p));
207
    if ( ppid == pid ) {
208
    if ( ppid == pid ) {
208
      d = garmin_unpack_packet(&p,type);
209
      d = garmin_unpack_packet(&p,type);
209
    } else {
210
    } else {
210
      /* Expected pid but got something else. */
211
      /* Expected pid but got something else. */
211
      fprintf(stderr, "garmin_read_singleton: expected %d, got %d\n",pid,ppid);
212
      sprintf(hv0, "garmin_read_singleton: expected %d, got %d!",pid,ppid);
-
 
213
      garmin_queue_error(hv0, err_warning);
212
    }
214
    }
213
  } else {
215
  } else {
214
    /* Failed to read the packet off the link. */
216
    /* Failed to read the packet off the link. */
215
    fprintf(stderr, "garmin_read_singleton: failed to read Pid_Records packet\n");
217
    sprintf(hv0, "garmin_read_singleton: failed to read Pid_Records packet!");
-
 
218
    garmin_queue_error(hv0, err_warning);
216
  }
219
  }
217
 
220
 
218
  return d;
221
  return d;
219
}
222
}
220
 
223
 
Line 232... Line 235...
232
  link_protocol     link      = garmin->protocol.link;
235
  link_protocol     link      = garmin->protocol.link;
233
  int               done      = 0;
236
  int               done      = 0;
234
  int               expected  = 0;
237
  int               expected  = 0;
235
  int               got       = 0;
238
  int               got       = 0;
236
  garmin_pid        ppid;
239
  garmin_pid        ppid;
-
 
240
  char              hv0[256];
237
 
241
 
238
  if ( garmin_read(garmin,&p) > 0 ) {
242
  if ( garmin_read(garmin,&p) > 0 ) {
239
    ppid = garmin_gpid(link,garmin_packet_id(&p));
243
    ppid = garmin_gpid(link,garmin_packet_id(&p));
240
    if ( ppid == Pid_Records ) {
244
    if ( ppid == Pid_Records ) {
241
      expected = get_uint16(p.packet.data);
245
      expected = get_uint16(p.packet.data);
242
 
246
 
243
      if ( garmin->verbose != 0 ) {
247
      if ( garmin->verbose != 0 ) {
244
	fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
248
	sprintf(hv0, "[garmin] Pid_Records indicates %d packets to follow!",
245
	       expected);
249
	       expected);
-
 
250
        garmin_queue_error(hv0, err_info);
246
      }
251
      }
247
 
252
 
248
      /* Allocate a list for the records. */
253
      /* Allocate a list for the records. */
249
 
254
 
250
      d = garmin_alloc_data(data_Dlist);
255
      d = garmin_alloc_data(data_Dlist);
Line 258... Line 263...
258
      while ( !done && garmin_read(garmin,&p) > 0 ) {
263
      while ( !done && garmin_read(garmin,&p) > 0 ) {
259
	ppid = garmin_gpid(link,garmin_packet_id(&p));
264
	ppid = garmin_gpid(link,garmin_packet_id(&p));
260
	if ( ppid == Pid_Xfer_Cmplt ) {
265
	if ( ppid == Pid_Xfer_Cmplt ) {
261
	  if ( got != expected ) {
266
	  if ( got != expected ) {
262
	    /* Incorrect number of packets received. */
267
	    /* Incorrect number of packets received. */
263
	    fprintf(stderr, "garmin_read_records: expected %d packets, got %d\n",
268
	    sprintf(hv0, "garmin_read_records: expected %d packets, got %d!",
264
		   expected,got);
269
		   expected,got);
-
 
270
	    garmin_queue_error(hv0, err_error);
265
	  } else if ( garmin->verbose != 0 ) {
271
	  } else if ( garmin->verbose != 0 ) {
266
	    fprintf(stderr, "[garmin] all %d expected packets received\n",got);
272
	    sprintf(hv0, "[garmin] all %d expected packets received!",got);
-
 
273
	    garmin_queue_error(hv0, err_info);
267
	  }
274
	  }
268
	  done = 1;
275
	  done = 1;
269
	} else if ( ppid == pid ) {
276
	} else if ( ppid == pid ) {
270
	  garmin_list_append(l,garmin_unpack_packet(&p,type));
277
	  garmin_list_append(l,garmin_unpack_packet(&p,type));
271
	  got++;
278
	  got++;
Line 274... Line 281...
274
	  done = 1;
281
	  done = 1;
275
	}
282
	}
276
      }
283
      }
277
    } else {
284
    } else {
278
      /* Expected Pid_Records but got something else. */
285
      /* Expected Pid_Records but got something else. */
279
      fprintf(stderr, "garmin_read_records: expected Pid_Records, got %d\n",ppid);
286
      sprintf(hv0, "garmin_read_records: expected Pid_Records, got %d!",ppid);
-
 
287
      garmin_queue_error(hv0, err_error);
280
    }
288
    }
281
  } else {
289
  } else {
282
    /* Failed to read the Pid_Records packet off the link. */
290
    /* Failed to read the Pid_Records packet off the link. */
283
    fprintf(stderr, "garmin_read_records: failed to read Pid_Records packet\n");
291
    sprintf(hv0, "garmin_read_records: failed to read Pid_Records packet!");
-
 
292
    garmin_queue_error(hv0, err_error);
284
  }
293
  }
285
 
294
 
286
  return d;
295
  return d;
287
}
296
}
288
 
297
 
Line 302... Line 311...
302
  link_protocol     link      = garmin->protocol.link;
311
  link_protocol     link      = garmin->protocol.link;
303
  int               expected  = 0;
312
  int               expected  = 0;
304
  int               got       = 0;
313
  int               got       = 0;
305
  int               state     = 0;
314
  int               state     = 0;
306
  garmin_pid        ppid;
315
  garmin_pid        ppid;
-
 
316
  char              hv0[256];
307
 
317
 
308
  if ( garmin_read(garmin,&p) > 0 ) {
318
  if ( garmin_read(garmin,&p) > 0 ) {
309
    ppid = garmin_gpid(link,garmin_packet_id(&p));
319
    ppid = garmin_gpid(link,garmin_packet_id(&p));
310
    if ( ppid == Pid_Records ) {
320
    if ( ppid == Pid_Records ) {
311
      expected = get_uint16(p.packet.data);
321
      expected = get_uint16(p.packet.data);
312
 
322
 
313
      if ( garmin->verbose != 0 ) {
323
      if ( garmin->verbose != 0 ) {
314
	fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
324
	sprintf(hv0, "[garmin] Pid_Records indicates %d packets to follow!",
315
	       expected);
325
	       expected);
-
 
326
	garmin_queue_error(hv0, err_info);
316
      }
327
      }
317
 
328
 
318
      /* Allocate a list for the records. */
329
      /* Allocate a list for the records. */
319
 
330
 
320
      d = garmin_alloc_data(data_Dlist);
331
      d = garmin_alloc_data(data_Dlist);
Line 324... Line 335...
324
	ppid = garmin_gpid(link,garmin_packet_id(&p));
335
	ppid = garmin_gpid(link,garmin_packet_id(&p));
325
	if ( ppid == Pid_Xfer_Cmplt ) {
336
	if ( ppid == Pid_Xfer_Cmplt ) {
326
	  /* transfer complete! */
337
	  /* transfer complete! */
327
	  if ( got != expected ) {
338
	  if ( got != expected ) {
328
	    /* wrong number of packets received! */
339
	    /* wrong number of packets received! */
329
	    fprintf(stderr, "garmin_read_records2: expected %d packets, got %d\n",
340
	    sprintf(hv0, "garmin_read_records2: expected %d packets, got %d!",
330
		   expected,got);
341
		   expected,got);
-
 
342
	    garmin_queue_error(hv0, err_error);
331
	  } else if ( garmin->verbose != 0 ) {
343
	  } else if ( garmin->verbose != 0 ) {
332
	    fprintf(stderr, "[garmin] all %d expected packets received\n",got);
344
	    sprintf(hv0, "[garmin] all %d expected packets received!",got);
-
 
345
	    garmin_queue_error(hv0, err_info);
333
	  }
346
	  }
334
	  break;
347
	  break;
335
	}
348
	}
336
	switch ( state ) {
349
	switch ( state ) {
337
	case 0:  /* want pid1 */
350
	case 0:  /* want pid1 */
Line 370... Line 383...
370
	  break;
383
	  break;
371
	}
384
	}
372
      }
385
      }
373
      if ( state < 0 ) {
386
      if ( state < 0 ) {
374
	/* Unexpected packet received. */
387
	/* Unexpected packet received. */
375
	fprintf(stderr, "garmin_read_records2: unexpected packet %d received\n",ppid);
388
	sprintf(hv0, "garmin_read_records2: unexpected packet %d received!",ppid);
-
 
389
        garmin_queue_error(hv0, err_error);
376
      }
390
      }
377
    } else {
391
    } else {
378
      /* Expected Pid_Records but got something else. */
392
      /* Expected Pid_Records but got something else. */
379
      fprintf(stderr, "garmin_read_records2: expected Pid_Records, got %d\n",ppid);
393
      sprintf(hv0, "garmin_read_records2: expected Pid_Records, got %d!",ppid);
-
 
394
      garmin_queue_error(hv0, err_error);
380
    }
395
    }
381
  } else {
396
  } else {
382
    /* Failed to read the Pid_Records packet off the link. */
397
    /* Failed to read the Pid_Records packet off the link. */
383
    fprintf(stderr, "garmin_read_records2: failed to read Pid_Records packet\n");
398
    sprintf(hv0, "garmin_read_records2: failed to read Pid_Records packet!");
-
 
399
    garmin_queue_error(hv0, err_error);
384
  }
400
  }
385
 
401
 
386
  return d;
402
  return d;
387
}
403
}
388
 
404
 
Line 404... Line 420...
404
  link_protocol     link      = garmin->protocol.link;
420
  link_protocol     link      = garmin->protocol.link;
405
  int               expected  = 0;
421
  int               expected  = 0;
406
  int               got       = 0;
422
  int               got       = 0;
407
  garmin_pid        ppid;
423
  garmin_pid        ppid;
408
  int               state     = 0;
424
  int               state     = 0;
-
 
425
  char              hv0[256];
409
 
426
 
410
  if ( garmin_read(garmin,&p) > 0 ) {
427
  if ( garmin_read(garmin,&p) > 0 ) {
411
    ppid = garmin_gpid(link,garmin_packet_id(&p));
428
    ppid = garmin_gpid(link,garmin_packet_id(&p));
412
    if ( ppid == Pid_Records ) {
429
    if ( ppid == Pid_Records ) {
413
      expected = get_uint16(p.packet.data);
430
      expected = get_uint16(p.packet.data);
414
 
431
 
415
      if ( garmin->verbose != 0 ) {
432
      if ( garmin->verbose != 0 ) {
416
	fprintf(stderr, "[garmin] Pid_Records indicates %d packets to follow\n",
433
	sprintf(hv0, "[garmin] Pid_Records indicates %d packets to follow!",
417
	       expected);
434
	       expected);
-
 
435
	garmin_queue_error(hv0, err_info);
418
      }
436
      }
419
 
437
 
420
      /* Allocate a list for the records. */
438
      /* Allocate a list for the records. */
421
 
439
 
422
      d = garmin_alloc_data(data_Dlist);
440
      d = garmin_alloc_data(data_Dlist);
Line 426... Line 444...
426
	ppid = garmin_gpid(link,garmin_packet_id(&p));
444
	ppid = garmin_gpid(link,garmin_packet_id(&p));
427
	if ( ppid == Pid_Xfer_Cmplt ) {
445
	if ( ppid == Pid_Xfer_Cmplt ) {
428
	  /* transfer complete! */
446
	  /* transfer complete! */
429
	  if ( got != expected ) {
447
	  if ( got != expected ) {
430
	    /* wrong number of packets received! */
448
	    /* wrong number of packets received! */
431
	    fprintf(stderr, "garmin_read_records3: expected %d packets, got %d\n",
449
	    sprintf(hv0, "garmin_read_records3: expected %d packets, got %d!",
432
		   expected,got);
450
		   expected,got);
-
 
451
	    garmin_queue_error(hv0, err_error);
433
	  } else if ( garmin->verbose != 0 ) {
452
	  } else if ( garmin->verbose != 0 ) {
434
	    fprintf(stderr, "[garmin] all %d expected packets received\n",got);
453
	    sprintf(hv0, "[garmin] all %d expected packets received!",got);
-
 
454
	    garmin_queue_error(hv0, err_info);
435
	  }
455
	  }
436
	  break;
456
	  break;
437
	}
457
	}
438
	switch ( state ) {
458
	switch ( state ) {
439
	case 0:  /* want pid1 */
459
	case 0:  /* want pid1 */
Line 481... Line 501...
481
	  break;
501
	  break;
482
	}
502
	}
483
      }
503
      }
484
      if ( state < 0 ) {
504
      if ( state < 0 ) {
485
	/* Unexpected packet received. */
505
	/* Unexpected packet received. */
486
	fprintf(stderr, "garmin_read_records3: unexpected packet %d received\n",ppid);
506
	sprintf(hv0, "garmin_read_records3: unexpected packet %d received!",ppid);
-
 
507
        garmin_queue_error(hv0, err_error);
487
      }
508
      }
488
    } else {
509
    } else {
489
      /* Expected Pid_Records but got something else. */
510
      /* Expected Pid_Records but got something else. */
490
      fprintf(stderr, "garmin_read_records3: expected Pid_Records, got %d\n",ppid);
511
      sprintf(hv0, "garmin_read_records3: expected Pid_Records, got %d!",ppid);
-
 
512
      garmin_queue_error(hv0, err_error);
491
    }
513
    }
492
  } else {
514
  } else {
493
    /* Failed to read the Pid_Records packet off the link. */
515
    /* Failed to read the Pid_Records packet off the link. */
494
    printf(stderr, "garmin_read_records3: failed to read Pid_Records packet\n");
516
    sprintf(hv0, "garmin_read_records3: failed to read Pid_Records packet!");
-
 
517
    garmin_queue_error(hv0, err_error);
495
  }
518
  }
496
 
519
 
497
  return d;
520
  return d;
498
}
521
}
499
 
522
 
Line 517... Line 540...
517
  uint8                  tag;
540
  uint8                  tag;
518
  uint16                 data;
541
  uint16                 data;
519
  uint16 *               datatypes;
542
  uint16 *               datatypes;
520
 
543
 
521
  /* Send the product request */
544
  /* Send the product request */
522
  
-
 
523
  garmin_packetize(&p,L000_Pid_Product_Rqst,0,NULL);
545
  garmin_packetize(&p,L000_Pid_Product_Rqst,0,NULL);
524
  garmin_write(garmin,&p);
546
  garmin_write(garmin,&p);
525
 
547
 
526
  /* Read the response. */
548
  /* Read the response. */
527
  
549
  
Line 582... Line 604...
582
    default:
604
    default:
583
      /* Ignore any other packets sent from the device. */
605
      /* Ignore any other packets sent from the device. */
584
      break;
606
      break;
585
    }
607
    }
586
  }
608
  }
-
 
609
 
-
 
610
  garmin_callback("product_request");
587
}
611
}
588
 
612
 
589
 
613
 
590
/* ------------------------------------------------------------------------- */
614
/* ------------------------------------------------------------------------- */
591
/* 6.4  A100 - Waypoint Transfer Protocol                                    */
615
/* 6.4  A100 - Waypoint Transfer Protocol                                    */
Line 1085... Line 1109...
1085
  garmin_data * data = NULL;
1109
  garmin_data * data = NULL;
1086
 
1110
 
1087
#define CASE_PROTOCOL(x)                                                      \
1111
#define CASE_PROTOCOL(x)                                                      \
1088
  case appl_A##x:                                                             \
1112
  case appl_A##x:                                                             \
1089
    if ( garmin->verbose != 0 ) {                                             \
1113
    if ( garmin->verbose != 0 ) {                                             \
1090
      printf("[garmin] -> garmin_read_a" #x "\n");                            \
1114
      fprintf(stderr, "[garmin] -> garmin_read_a" #x "\n");                            \
1091
    }                                                                         \
1115
    }                                                                         \
1092
    data = garmin_read_a##x(garmin);                                          \
1116
    data = garmin_read_a##x(garmin);                                          \
1093
    if ( garmin->verbose != 0 ) {                                             \
1117
    if ( garmin->verbose != 0 ) {                                             \
1094
      printf("[garmin] <- garmin_read_a" #x "\n");                            \
1118
      fprintf(stderr, "[garmin] <- garmin_read_a" #x "\n");                            \
1095
    }                                                                         \
1119
    }                                                                         \
1096
    break
1120
    break
1097
 
1121
 
1098
  switch ( protocol ) {
1122
  switch ( protocol ) {
1099
  CASE_PROTOCOL(100);   /* waypoints */
1123
  CASE_PROTOCOL(100);   /* waypoints */
Line 1115... Line 1139...
1115
  default:
1139
  default:
1116
    /* invalid top-level read protocol */
1140
    /* invalid top-level read protocol */
1117
    break;
1141
    break;
1118
  }
1142
  }
1119
 
1143
 
-
 
1144
  garmin_callback();
1120
  return data;
1145
  return data;
1121
}
1146
}
1122
 
1147
 
1123
 
1148
 
1124
/* ------------------------------------------------------------------------- */
1149
/* ------------------------------------------------------------------------- */