Skip to content

Commit

Permalink
adding some debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ampledata committed Dec 24, 2024
1 parent da1a492 commit d7b7b52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions dronecot/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

from typing import Optional

import asyncio_mqtt as aiomqtt
from bitstruct import *
import lzma
import asyncio_mqtt as aiomqtt

import pytak
import dronecot
Expand Down Expand Up @@ -56,6 +55,8 @@ async def parse_message(self, message):
if ord(payload[-1:]) == 0:
payload = payload[:-1]

self._logger.debug("Message payload: %s", payload)

position = 0
while position != -1:
position = payload.find("}{")
Expand Down Expand Up @@ -145,6 +146,7 @@ async def run(self, _=-1) -> None:
async with client.messages() as messages:
await client.subscribe(topic)
async for message in messages:
self._logger.debug("Received message: %s", message)
await self.parse_message(message)


Expand All @@ -165,7 +167,7 @@ async def handle_data(self, data: dict) -> None:
data : `list[dict, ]`
List of craft data as key/value arrays.
"""
# self._logger.info(data)
self._logger.debug("Handling data: %s", data)
if "status" in data:
event = dronecot.xml_to_cot(data, self.config, "sensor_status_to_cot")
await self.put_queue(event)
Expand All @@ -186,7 +188,6 @@ async def run(self, _=-1) -> None:
while 1:
data = await self.net_queue.get()
if not data:
# await asyncio.sleep(0.01)
continue

await self.handle_data(data)
7 changes: 4 additions & 3 deletions dronecot/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def sensor_status_to_cot( # NOQA pylint: disable=too-many-locals,too-many-branc
data: dict,
config: Union[SectionProxy, dict, None] = None,
) -> Optional[ET.Element]:
"""Serialize sensor status data s Cursor on Target."""
"""Serialize sensor status data as Cursor on Target."""
config = config or {}
lat = data.get("lat")
lon = data.get("lon")
Expand Down Expand Up @@ -304,7 +304,8 @@ def sensor_status_to_cot( # NOQA pylint: disable=too-many-locals,too-many-branc
cotx.set("cot_host_id", cot_host_id)

remarks_fields.append(
f"SNSTAC C-UAS Sensor {sensor_id} - {status.get('model')} {status.get('status')} - Contact: info@snstac.com 415-598-8226"
f"SNSTAC C-UAS Sensor {sensor_id} - {status.get('model')} "
f"{status.get('status')} - Contact: info@snstac.com 415-598-8226"
)
cotx.set("sensor_id", sensor_id)
callsign = sensor_id
Expand Down Expand Up @@ -351,7 +352,7 @@ def sensor_status_to_cot( # NOQA pylint: disable=too-many-locals,too-many-branc
def xml_to_cot(
data: dict, config: Union[SectionProxy, dict, None] = None, func=None
) -> Optional[bytes]:
"""Return CoT XML object as an XML string."""
"""Return a CoT XML object as an XML string, using the given func."""
cot: Optional[ET.Element] = getattr(dronecot.functions, func)(data, config)
return (
b"\n".join([pytak.DEFAULT_XML_DECLARATION, ET.tostring(cot)]) if cot else None
Expand Down

0 comments on commit d7b7b52

Please sign in to comment.