From 7f9ca762bec397c2eb27fcc85b47ed6e58932735 Mon Sep 17 00:00:00 2001 From: James Pace Date: Wed, 16 Sep 2026 19:51:01 -0400 Subject: [PATCH] Add identiy and version number. Some generic cleanup. --- am_i_up/Api.py | 24 +++++++++++++++++------ am_i_up/Facts.py | 32 +++++++++++++++++++++++++------ am_i_up/client.py | 21 +++++++++++++++++++- assets/login.html | 2 +- launch/data_simulators.launch.xml | 14 ++++++++++++++ params/am_i_up.yaml | 3 ++- params/j7s_threed_image2rtsp.yaml | 14 ++++++++++++++ params/mediamtx.yaml | 4 +++- 8 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 params/j7s_threed_image2rtsp.yaml diff --git a/am_i_up/Api.py b/am_i_up/Api.py index f749bf8..cefa08b 100644 --- a/am_i_up/Api.py +++ b/am_i_up/Api.py @@ -33,8 +33,9 @@ class Api: web.get('/api/ping', self.ping), web.get('/api/uptime', self.uptime), web.get('/api/build_info', self.build_info), + web.get('/api/version_number', self.version_number), web.get('/api/env', self.env), - web.get('/api/status', self.status), + web.get('/api/identity', self.identity), web.get("/api/position", self.position), web.get("/api/diagnostics", self.diagnostics), web.post("/api/login", self.login), @@ -134,6 +135,17 @@ class Api: resp = {"uptime": self._facts.get_uptime()} return web.json_response(resp) + async def version_number(self, request): + version = self._facts.get_version() + if not version: + resp = {"status": False, "message": "version not found."} + return web.json_response(resp) + resp = { + "status": True, + "version": version + } + return web.json_response(resp) + async def build_info(self, request): project_state = self._facts.get_buildinfo() if not project_state: @@ -149,11 +161,11 @@ class Api: env = self._facts.get_env() return web.json_response(env) - async def status(self, request): - status = self._facts.get_status() - if not status: - status = "Nothing received!" - resp = {"message": status} + async def identity(self, request): + identity = self._facts.get_identity() + if not identity: + identity = "Nothing received!" + resp = {"message": identity} return web.json_response(resp) async def position(self, request): diff --git a/am_i_up/Facts.py b/am_i_up/Facts.py index 9bb1806..5acce3e 100644 --- a/am_i_up/Facts.py +++ b/am_i_up/Facts.py @@ -30,7 +30,7 @@ class Facts: rclpy.init() self._node = rclpy.create_node('am_i_up') - self._status_sub = self._node.create_subscription(String, "status", self._status_callback, 1) + self._ident_sub = self._node.create_subscription(String, "identity", self._identity_callback, 1) self._navsat_sub = self._node.create_subscription(NavSatFix, "navsatfix", self._navsat_callback, 1) self._diagnostics_sub = self._node.create_subscription(DiagnosticArray, "/diagnostics_agg", self._diag_callback, 1) @@ -42,7 +42,7 @@ class Facts: self._video_streams = self._node.declare_parameter("video_streams", [""]).value self._video_display_port = self._node.declare_parameter("video_display_port", "8889").value - self._status_string = None + self._identity_string = None self._lat_long = None self._diag_msg = None @@ -56,8 +56,8 @@ class Facts: def get_lat_long(self): return self._lat_long - def get_status(self): - return self._status_string + def get_identity(self): + return self._identity_string def get_listen_port(self): return self._listen_port @@ -119,6 +119,26 @@ class Facts: print("Can't find build info.\n{}".format(e)) return project_state_content + def get_version(self): + # Find the share directory for 'build_info_getter'. + build_info_getter_directory = None + try: + build_info_getter_directory = get_package_share_directory('build_info_getter') + except Exception as e: + print("Can't find build info.\n{}".format(e)) + return None + # Find and read the version file in int. + version_number_file = build_info_getter_directory + "/version_number" + version_number = None + try: + with open(version_number_file, 'r') as file_obj: + version_number = file_obj.readline().rstrip() + except Exception as e: + # We either didn't load the file or couldn't read it. + print("Can't find build info.\n{}".format(e)) + + return version_number + def get_password(self): return self._password @@ -128,8 +148,8 @@ class Facts: def get_video_display_port(self): return self._video_display_port - def _status_callback(self, msg): - self._status_string = msg.data + def _identity_callback(self, msg): + self._identity_string = msg.data def _diag_callback(self, msg): self._diag_msg = msg diff --git a/am_i_up/client.py b/am_i_up/client.py index abb43ac..aad811f 100644 --- a/am_i_up/client.py +++ b/am_i_up/client.py @@ -22,7 +22,6 @@ def main(args=None): parser.add_argument("--host", default="http://localhost:8000") args = parser.parse_args() - client = Client(args.host) if args.action == 'ping': @@ -35,6 +34,10 @@ def main(args=None): asyncio.run(client.call_env()) if args.action == 'diagnostics': asyncio.run(client.call_diagnostics()) + if args.action == 'identity': + asyncio.run(client.call_identity()) + if args.action == 'version': + asyncio.run(client.call_version()) class Client(): def __init__(self, host): @@ -83,6 +86,22 @@ class Client(): async with session.get(f'{self._host}/api/env') as resp: print(await resp.text()) + async def call_identity(self): + print("Calling identity.") + + async with aiohttp.ClientSession() as session: + await self.login(session) + async with session.get(f'{self._host}/api/identity') as resp: + print(await resp.text()) + + async def call_version(self): + print("Calling version.") + + async with aiohttp.ClientSession() as session: + await self.login(session) + async with session.get(f'{self._host}/api/version_number') as resp: + print(await resp.text()) + async def call_diagnostics(self): print("Calling diagnostics.") diff --git a/assets/login.html b/assets/login.html index bf272be..3f14c30 100644 --- a/assets/login.html +++ b/assets/login.html @@ -27,7 +27,7 @@