@@ -129,7 +129,7 @@ typedef struct garmin_parser_t {
129
129
unsigned int setpoint_low_cbar , setpoint_high_cbar ;
130
130
unsigned int setpoint_low_switch_depth_mm , setpoint_high_switch_depth_mm ;
131
131
unsigned int setpoint_low_switch_mode , setpoint_high_switch_mode ;
132
- dc_gasmix_t * current_gasmix ;
132
+ dc_usage_t current_gasmix_usage ;
133
133
} dive ;
134
134
135
135
// I count nine (!) different GPS fields Hmm.
@@ -239,11 +239,11 @@ static void garmin_event(struct garmin_parser_t *garmin,
239
239
sample .gasmix = data ;
240
240
garmin -> callback (DC_SAMPLE_GASMIX , & sample , garmin -> userdata );
241
241
242
- dc_gasmix_t * gasmix = & garmin -> cache .GASMIX [data ];
243
- if (! garmin -> dive . current_gasmix || gasmix -> usage != garmin -> dive .current_gasmix -> usage ) {
242
+ dc_usage_t gasmix_usage = garmin -> cache .GASMIX [data ]. usage ;
243
+ if (gasmix_usage != garmin -> dive .current_gasmix_usage ) {
244
244
dc_sample_value_t sample2 = {0 };
245
245
sample2 .event .type = SAMPLE_EVENT_STRING ;
246
- if (gasmix -> usage == DC_USAGE_DILUENT ) {
246
+ if (gasmix_usage == DC_USAGE_DILUENT ) {
247
247
sample2 .event .name = "Switched to closed circuit" ;
248
248
} else {
249
249
sample2 .event .name = "Switched to open circuit bailout" ;
@@ -252,7 +252,7 @@ static void garmin_event(struct garmin_parser_t *garmin,
252
252
253
253
garmin -> callback (DC_SAMPLE_EVENT , & sample2 , garmin -> userdata );
254
254
255
- garmin -> dive .current_gasmix = gasmix ;
255
+ garmin -> dive .current_gasmix_usage = gasmix_usage ;
256
256
}
257
257
258
258
return ;
@@ -486,19 +486,22 @@ DECLARE_FIELD(ANY, timestamp, UINT32)
486
486
{
487
487
garmin -> record_data .timestamp = data ;
488
488
if (garmin -> callback ) {
489
- dc_sample_value_t sample = {0 };
490
-
491
489
// Turn the timestamp relative to the beginning of the dive
492
- if (data < garmin -> dive .time )
490
+ if (data < garmin -> dive .time ) {
491
+ DEBUG (garmin -> base .context , "Timestamp before dive start: %d (dive start: %d)" , data , garmin -> dive .time );
492
+
493
493
return ;
494
- data -= garmin -> dive .time ;
494
+ }
495
+ data -= garmin -> dive .time - 1 ;
495
496
496
497
// Did we already do this?
497
- if (data < garmin -> record_data .time )
498
+ if (data == garmin -> record_data .time )
498
499
return ;
499
500
501
+ garmin -> record_data .time = data ;
502
+
500
503
// Now we're ready to actually update the sample times
501
- garmin -> record_data . time = data + 1 ;
504
+ dc_sample_value_t sample = { 0 } ;
502
505
sample .time = data * 1000 ;
503
506
garmin -> callback (DC_SAMPLE_TIME , & sample , garmin -> userdata );
504
507
}
@@ -656,14 +659,18 @@ DECLARE_FIELD(ACTIVITY, event_group, UINT8) { }
656
659
// SPORT
657
660
DECLARE_FIELD (SPORT , sub_sport , ENUM ) {
658
661
garmin -> dive .sub_sport = (ENUM ) data ;
662
+ garmin -> dive .current_gasmix_usage = DC_USAGE_OPEN_CIRCUIT ;
659
663
dc_divemode_t val ;
660
664
switch (data ) {
661
665
case 55 : val = DC_DIVEMODE_GAUGE ;
662
666
break ;
663
667
case 56 :
664
668
case 57 : val = DC_DIVEMODE_FREEDIVE ;
665
669
break ;
666
- case 63 : val = DC_DIVEMODE_CCR ;
670
+ case 63 :
671
+ val = DC_DIVEMODE_CCR ;
672
+ garmin -> dive .current_gasmix_usage = DC_USAGE_DILUENT ;
673
+
667
674
break ;
668
675
default : val = DC_DIVEMODE_OC ;
669
676
}
@@ -797,7 +804,7 @@ DECLARE_FIELD(SENSOR_PROFILE, enabled, ENUM)
797
804
{
798
805
current_sensor (garmin )-> sensor_enabled = data ;
799
806
}
800
- DECLARE_FIELD (SENSOR_PROFILE , sensor_type , UINT8 )
807
+ DECLARE_FIELD (SENSOR_PROFILE , sensor_type , ENUM )
801
808
{
802
809
// 28 is tank pod
803
810
// start filling in next sensor after this record
@@ -1090,7 +1097,7 @@ DECLARE_MESG(SENSOR_PROFILE) = {
1090
1097
SET_FIELD (SENSOR_PROFILE , 0 , ant_channel_id , UINT32Z ), // derived from the number engraved on the side
1091
1098
SET_FIELD (SENSOR_PROFILE , 2 , name , STRING ),
1092
1099
SET_FIELD (SENSOR_PROFILE , 3 , enabled , ENUM ),
1093
- SET_FIELD (SENSOR_PROFILE , 52 , sensor_type , UINT8 ), // 28 is tank pod
1100
+ SET_FIELD (SENSOR_PROFILE , 52 , sensor_type , ENUM ), // 28 is tank pod
1094
1101
SET_FIELD (SENSOR_PROFILE , 74 , pressure_units , ENUM ), // 0 is PSI, 1 is KPA (unused), 2 is Bar
1095
1102
SET_FIELD (SENSOR_PROFILE , 75 , rated_pressure , UINT16 ),
1096
1103
SET_FIELD (SENSOR_PROFILE , 76 , reserve_pressure , UINT16 ),
@@ -1337,7 +1344,10 @@ static int traverse_regular(struct garmin_parser_t *garmin,
1337
1344
}
1338
1345
1339
1346
if (field_desc ) {
1340
- field_desc -> parse (garmin , base_type , data );
1347
+ if (field_nr == 253 && !msg_desc -> maxfield )
1348
+ DEBUG (garmin -> base .context , "Ignoring timestamp field for undefined message." );
1349
+ else
1350
+ field_desc -> parse (garmin , base_type , data );
1341
1351
} else {
1342
1352
unknown_field (garmin , data , msg_name , field_nr , base_type , len );
1343
1353
}
@@ -1521,7 +1531,12 @@ traverse_data(struct garmin_parser_t *garmin)
1521
1531
// Compressed records are like normal records
1522
1532
// with that added relative timestamp
1523
1533
DEBUG (garmin -> base .context , "Compressed record for type %d" , type );
1524
- parse_ANY_timestamp (garmin , time );
1534
+
1535
+ if (!(garmin -> type_desc + type )-> msg_desc -> maxfield )
1536
+ DEBUG (garmin -> base .context , "Ignoring timestamp field for undefined message." );
1537
+ else
1538
+ parse_ANY_timestamp (garmin , time );
1539
+
1525
1540
len = traverse_regular (garmin , data , datasize , type , & time );
1526
1541
} else if (record & 0x40 ) { // Definition record?
1527
1542
len = traverse_definition (garmin , data , datasize , record );
@@ -1615,6 +1630,20 @@ static void add_sensor_string(garmin_parser_t *garmin, const char *desc, const s
1615
1630
static dc_status_t
1616
1631
garmin_parser_set_data (garmin_parser_t * garmin , const unsigned char * data , unsigned int size )
1617
1632
{
1633
+ // This list is empirical and somewhat speculative
1634
+ // will have to be confirmed with Garmin
1635
+ static const struct {
1636
+ int id ;
1637
+ const char * name ;
1638
+ } models [] = {
1639
+ { 2859 , "Descent Mk1" },
1640
+ { 2991 , "Descent Mk1 APAC" },
1641
+ { 3258 , "Descent Mk2(i)" },
1642
+ { 3542 , "Descent Mk2s" },
1643
+ { 3702 , "Descent Mk2 APAC" },
1644
+ { 4223 , "Descent Mk3" },
1645
+ };
1646
+
1618
1647
/* Walk the data once without a callback to set up the core fields */
1619
1648
garmin -> callback = NULL ;
1620
1649
garmin -> userdata = NULL ;
@@ -1630,6 +1659,17 @@ garmin_parser_set_data (garmin_parser_t *garmin, const unsigned char *data, unsi
1630
1659
if (garmin -> dive .firmware )
1631
1660
dc_field_add_string_fmt (& garmin -> cache , "Firmware" , "%u.%02u" ,
1632
1661
garmin -> dive .firmware / 100 , garmin -> dive .firmware % 100 );
1662
+ if (garmin -> dive .product ) {
1663
+ int i = 0 ;
1664
+ for (i = 0 ; i < C_ARRAY_SIZE (models ); i ++ )
1665
+ if (models [i ].id == garmin -> dive .product )
1666
+ break ;
1667
+
1668
+ if (i < C_ARRAY_SIZE (models ))
1669
+ dc_field_add_string_fmt (& garmin -> cache , "Model" , "%s" , models [i ].name );
1670
+ else
1671
+ dc_field_add_string_fmt (& garmin -> cache , "Model" , "Unknown model ID: %u" , garmin -> dive .product );
1672
+ }
1633
1673
1634
1674
// These seem to be the "real" GPS dive coordinates
1635
1675
add_gps_string (garmin , "GPS1" , & garmin -> gps .SESSION .entry );
0 commit comments