From 641649d964de66af367ca9c8f973a9bf4094e530 Mon Sep 17 00:00:00 2001 From: Jono Targett Date: Sun, 15 Mar 2026 19:41:32 +1030 Subject: [PATCH] Added the second CFG command --- handler.py | 4 +--- ubxhandler.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/handler.py b/handler.py index 6a0b777..c57ea84 100644 --- a/handler.py +++ b/handler.py @@ -6,9 +6,6 @@ import inspect from paho.mqtt.properties import Properties from dataclasses import asdict -BAUD = 115200 -INTERVAL = 5 - class MQTTHandler: @@ -97,6 +94,7 @@ class MQTTHandler: await self.execute_command(command_name, payload, message.properties) async def run(self): + INTERVAL = 5 while True: try: async with self.mqtt_client as client: diff --git a/ubxhandler.py b/ubxhandler.py index b9756f7..7a928a7 100644 --- a/ubxhandler.py +++ b/ubxhandler.py @@ -72,6 +72,9 @@ class UBXHandler(MQTTHandler): topic = f"{self.topic_base}/{message.identity}/{name}" await self.mqtt_client.publish(topic, value, qos=1, retain=True) + else: + #print("Unexpected response:", message) + pass @command({"type": "number"}, description="An example command") async def example_cmd(self, args): @@ -120,3 +123,42 @@ class UBXHandler(MQTTHandler): ) num_bytes = await self.serial_port.write_async(message.serialize()) return num_bytes + + @command( + { + "type": "object", + "properties": { + "measRate": { + "type": "integer", + "minimum": 50, + "maximum": 60000, + "description": "Measurement period in milliseconds", + }, + "navRate": { + "type": "integer", + "minimum": 1, + "maximum": 127, + "description": "Number of measurement cycles per navigation solution", + }, + "timeRef": { + "type": "integer", + "enum": [0, 1], + "description": "Time reference (0=UTC, 1=GPS)", + }, + }, + "required": ["measRate", "navRate", "timeRef"], + "additionalProperties": False, + }, + description="Reconfigure the rate properties for the UBX device.", + ) + async def configure_rate(self, args): + message = pyubx2.UBXMessage( + "CFG", + "CFG-RATE", + pyubx2.ubxtypes_core.SET, + measRate=args["measRate"], + navRate=args["navRate"], + timeRef=args["timeRef"], + ) + num_bytes = await self.serial_port.write_async(message.serialize()) + return num_bytes