Skip to content

Commit

Permalink
chat: extra debug output for send-mavlink-message
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Dec 18, 2023
1 parent 3abc570 commit e219d05
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions MAVProxy/modules/mavproxy_chat/chat_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,34 +471,43 @@ def get_mavlink_message(self, arguments):
# send a mavlink message to the vehicle
def send_mavlink_message(self, arguments):
if arguments is None:
print("chat: send_mavlink_message: arguments is None")
return "send_mavlink_message: arguments is None"
else:
print("chat: send_mavlink_message arguments: " + str(arguments))

# retrieve requested message's name
mav_msg_name = arguments.get("message", None)
if mav_msg_name is None:
print("chat: send_mavlink_message: message not specified")
return "send_mavlink_message: message not specified"

# check if function to send the mavlink message exists
if not hasattr(self.mpstate.master().mav, mav_msg_name + "_send"):
# mavlink send message are always lower case
mav_send_fnname = mav_msg_name.lower() + "_send"

# check if function to send the mavlink message exists
if not hasattr(self.mpstate.master().mav, mav_send_fnname):
print("chat: send_mavlink_message: " + mav_send_fnname + " does not exist")
return "send_mavlink_message: specified message is not supported"
print("chat: send_mavlink_message: " + mav_send_fnname + " exists")

# populate message's fields
mav_msg_fields = {}
for field in arguments:
if field != "message":
mav_msg_fields[field] = arguments.get(field, None)

print("chat: send_mavlink_message: " + str(mav_msg_fields))

# send message
try:
getattr(self.mpstate.master().mav, mav_msg_name + "_send")(**mav_msg_fields)
except:
return "send_mavlink_message: failed to send message"
#try:
print("chat: send_mavlink_message: attempting to call " + mav_send_fnname)
getattr(self.mpstate.master().mav, mav_send_fnname)(**mav_msg_fields)
#except:
# return "send_mavlink_message: failed to send message"

# convert message to json
try:
return json.dumps(mav_msg.to_dict())
except:
return "send_mavlink_message: failed to convert message to json"
return "send_mavlink_message: message sent"

# get all available parameters names and their values
def get_all_parameters(self, arguments):
Expand Down

0 comments on commit e219d05

Please sign in to comment.