diff --git a/examples/rtcm.py b/examples/rtcm.py index b5f6931..01ae638 100755 --- a/examples/rtcm.py +++ b/examples/rtcm.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import asyncio +import base64 from mavsdk import System from mavsdk.rtk import RtcmData @@ -13,4 +14,6 @@ async def send_data(data): if __name__ == '__main__': rtcm_data = bytearray(b'\xd3\x00mCP\x00\x8c2\x16\x82\x00\x00,@\x88\x00\x00\x00\x00\x00 \x00\x00\x00~\x9c\xa4\x9a\x90\xa2\x8c\x00\x00\x01\xa7\xa2\x1e=gv\x8f\x1fq{\\x13_\xc9\xdf\x17\x02L$\xb6\xdd\x17\x9a.\xe8\xba\x94\x02U6^\xa2^\x08\xac\xf5\xf4\x1d\xcc\n\x9d\xe7\xeb\x04R\x15\x92\x93\xf9o\xf2\xc1\xb5-j\xba\xf12`@\r\x83\xc0\xe8B\x0f\x05\xec\x8c\xfc\xc4\x88l\xac\x7f\xf1\x1aR\xc2\xbc\x87') # noqa: E501 - asyncio.run(send_data(RtcmData(str(rtcm_data)))) + # In MAVSDK 3.0.0 the data is expected to be base64 encoded string + base64_rtcm_data = base64.b64encode(rtcm_data).decode('utf-8') + asyncio.run(send_data(RtcmData(base64_rtcm_data))) diff --git a/examples/rtk.py b/examples/rtk.py deleted file mode 100755 index 87cfeae..0000000 --- a/examples/rtk.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python3 - -import asyncio -from mavsdk import System, rtk - -# Some sample data that won't work because it needs to have the correct time -# information. However, that's the sort of bytes that can be expected. - -# In a real case this data would be read from an ntrip service or read from -# a local GNSS base station. - -rtcm_correction_data = bytes( - [0xd3, 0x0, 0x6, 0x4c, 0xe0, 0x0, 0x88, 0x10, 0x97, 0xc2, 0x44, 0x8b]) - - -async def run(): - # Init the drone - drone = System() - await drone.connect() - - # Start the tasks - asyncio.ensure_future(print_gps_info(drone)) - asyncio.ensure_future(send_rtcm(drone)) - - while True: - await asyncio.sleep(1) - - -async def print_gps_info(drone): - async for gps_info in drone.telemetry.gps_info(): - print(f"GPS info: {gps_info}") - - -async def send_rtcm(drone): - while True: - try: - # We convert the data to a string here as the API wants it even - # though it should be raw bytes. - # This creates odd an odd Python string that gets decoded on the - # C++ server side. - # With MAVSDK v2, the API will change to a vector of bytes instead - # of this clunky string. - - await drone.rtk.send_rtcm_data( - rtk.RtcmData(str(rtcm_correction_data))) - - except Exception as e: - print(f"Exception: {e}") - - await asyncio.sleep(1) - - -if __name__ == "__main__": - # Start the main function - asyncio.run(run())