Skip to content

Commit

Permalink
teach lowranceusr about track segments (#1306)
Browse files Browse the repository at this point in the history
* teach lowranceusr about track segments.

lowranceusr versions 2 & 3 have a continuous flag used to
indicate dicontinuities in a trail.
The lowranceusr version 2 & 3 reader now flags trail discontinuities
as new track segements.
The lowranceusr version 2 & 3 writer now flags new track segments as
discontinuities.

Also fix two subtle bugs:
1) when reading a version 2 or 3 trail with the break option we would
fail to break the trail if the discontinuity was at the start of a
section other than the first section.
2) when writing a version 2 or 3 trail with the merge option if the
number of points exceeded MAX_TRAIL_POINTS we would write a header
that indicated MAX_TRAIL_POINTS but actually write MAX_TRAIL_POINTS + 1.

* add lowranceusr test for track segments.
  • Loading branch information
tsteven4 authored Jul 27, 2024
1 parent c86aff1 commit b1d2df5
Show file tree
Hide file tree
Showing 5 changed files with 7,577 additions and 18 deletions.
44 changes: 27 additions & 17 deletions lowranceusr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -989,16 +989,20 @@ LowranceusrFormat::lowranceusr_parse_trail(int* trail_num)
wpt_tmp->latitude = lat_mm_to_deg(gbfgetint32(file_in));
wpt_tmp->longitude = lon_mm_to_deg(gbfgetint32(file_in));

// It's not clear if this should be the continuous global or
// a local continuous_flag.
char continuous_flag = gbfgetc(file_in);
if (!continuous_flag && opt_seg_break && j) {
/* option to break trails into segments was specified */
auto* trk_tmp = new route_head;
trk_tmp->rte_num = ++(*trail_num);
trk_tmp->rte_name = trk_head->rte_name;
track_add_head(trk_tmp);
trk_head = trk_tmp;
if (!continuous_flag) {
if (opt_seg_break) {
/* option to break trails into segments was specified */
if (!trk_head->rte_waypt_empty()) {
auto* trk_tmp = new route_head;
trk_tmp->rte_num = ++(*trail_num);
trk_tmp->rte_name = trk_head->rte_name;
track_add_head(trk_tmp);
trk_head = trk_tmp;
}
} else {
wpt_tmp->wpt_flags.new_trkseg = 1;
}
}

/* Track Point */
Expand Down Expand Up @@ -1589,7 +1593,7 @@ LowranceusrFormat::lowranceusr_trail_hdr(const route_head* trk)
gbfputint16(num_trail_points, file_out);
gbfputint16(max_trail_size, file_out);
gbfputint16(num_section_points, file_out);
trail_point_count=1;
trail_point_count=0;
}

void
Expand Down Expand Up @@ -1689,7 +1693,8 @@ LowranceusrFormat::lowranceusr4_route_trl(const route_head* /*unused*/) const
void
LowranceusrFormat::lowranceusr_trail_disp(const Waypoint* wpt)
{
if (trail_point_count <= MAX_TRAIL_POINTS) {
if (trail_point_count < MAX_TRAIL_POINTS) {
trail_point_count++;
int lat = lat_deg_to_mm(wpt->latitude);
int lon = lon_deg_to_mm(wpt->longitude);

Expand All @@ -1699,11 +1704,15 @@ LowranceusrFormat::lowranceusr_trail_disp(const Waypoint* wpt)

gbfputint32(lat, file_out);
gbfputint32(lon, file_out);
gbfwrite(&continuous, 1, 1, file_out);
if (!continuous) {
continuous = 1;
}
trail_point_count++;
/* If this isn't the first point in the outgoing trail, and
* i) the source wpt was the start of a new track segment or
* ii) the source wpt is the first waypoint of a track that is being merged
* then set the continuous flag to 0 to indicate a discontinuity.
* Otherwise set the continous flag to 1.
*/
char continuous_flag = !((trail_point_count > 1) && (wpt->wpt_flags.new_trkseg || merge_new_track));
merge_new_track = false;
gbfwrite(&continuous_flag, 1, 1, file_out);
}
}

Expand Down Expand Up @@ -1757,7 +1766,7 @@ LowranceusrFormat::lowranceusr_merge_trail_tlr(const route_head* /*unused*/)
void
LowranceusrFormat::lowranceusr_merge_trail_hdr_2(const route_head* /*unused*/)
{
continuous = 0;
merge_new_track = true;
}

void
Expand Down Expand Up @@ -2038,6 +2047,7 @@ LowranceusrFormat::write()
gbfputint16(NumTrails, file_out);
if (NumTrails) {
trail_count=0;
merge_new_track = false;
auto lowranceusr_trail_disp_lambda = [this](const Waypoint* waypointp)->void {
lowranceusr_trail_disp(waypointp);
};
Expand Down
2 changes: 1 addition & 1 deletion lowranceusr.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class LowranceusrFormat : public Format
unsigned short waypt_out_count{};
int trail_count{}, lowrance_route_count{};
int trail_point_count{};
char continuous = 1;
bool merge_new_track{false};
short num_section_points{};
char* merge{};
int reading_version{};
Expand Down
Loading

0 comments on commit b1d2df5

Please sign in to comment.