Skip to content
forked from cr/hx870

Commit

Permalink
Add skeleton of nav data flash/erase CLI proposed in cr#1
Browse files Browse the repository at this point in the history
  • Loading branch information
johannessen committed Oct 27, 2019
1 parent 191a7db commit 4453407
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
49 changes: 48 additions & 1 deletion hxtool/cli/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self):
result = max(self.dump(hx), result)

if self.args.flash or self.args.erase:
raise NotImplementedError
result = max(self.flash_erase(hx), result)

return result

Expand All @@ -62,6 +62,53 @@ def dump(self, hx):
return 0


def flash_erase(self, hx):
nav_data = { "waypoints": [], "routes": [] }

if self.args.flash:
if self.args.gpx:
logger.info("Reading GPX nav data from `{}`".format(self.args.gpx))
raise NotImplementedError

logger.info(log_nav_data("Read {w} waypoint{ws} and {r} route{rs} from file", nav_data))
if self.args.erase:
logger.info("Will replace nav data on device")
else:
logger.info("Will append to nav data on device")

logger.info("Reading nav data from handset")
raise NotImplementedError

logger.info(log_nav_data("In total {w} waypoint{ws} and {r} route{rs}", nav_data))
if nav_data_oversized(nav_data, hx):
return 10

logger.info("Writing nav data to handset")
raise NotImplementedError

return 0


def log_nav_data(text: str, nav_data: dict) -> str:
waypoint_count = len(nav_data["waypoints"])
route_count = len(nav_data["routes"])
return text.format(
w = waypoint_count, ws = "s" if waypoint_count != 1 else "",
r = route_count, rs = "s" if route_count != 1 else "" )


def nav_data_oversized(nav_data: dict, hx: object) -> bool:
limits = hx.config.limits()
oversized = False
if len(nav_data["waypoints"]) > limits["waypoints"]:
logger.critical("Too many waypoints to fit on device (maximum: {})".format(limits["waypoints"]))
oversized = True
if len(nav_data["routes"]) > limits["routes"]:
logger.critical("Too many routes to fit on device (maximum: {})".format(limits["routes"]))
oversized = True
return oversized


def write_gpx(nav_data: dict, file_name: str) -> int:
if len(nav_data["waypoints"]) == 0:
logger.warning("No waypoints in device. Not writing empty GPX file")
Expand Down
6 changes: 6 additions & 0 deletions hxtool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class GenericHXConfig(object):
def __init__(self, protocol: GenericHXProtocol):
self.p = protocol

def limits(self):
return {
"waypoints": 200,
"routes": 20,
}

def config_read(self, progress=False):
config_data = b''
bytes_to_go = 0x8000
Expand Down

0 comments on commit 4453407

Please sign in to comment.