diff --git a/Chat/index.html b/Chat/index.html
index 8c5c5dbf..26f7feda 100644
--- a/Chat/index.html
+++ b/Chat/index.html
@@ -524,7 +524,7 @@
// fallthrough
case "get_vehicle_state":
// Get the vehicle state including armed status and (flight) mode
- // fallthrough
+ return get_vehicle_state();
case "get_location_plus_offset":
// Calculate the latitude and longitude given an existing latitude and longitude and distances (in meters) North and East
// fallthrough
@@ -641,6 +641,26 @@
return new Date().toLocaleString('en-US', options);
}
+
+ //get vehicle state
+ function get_vehicle_state(){
+ //get latest HEARTBEAT message
+ const heartbeat_msg = mavlink_store.get_latest_message(0);
+ //sanity check
+ if (!heartbeat_msg || !heartbeat_msg.hasOwnProperty("base_mode") || !heartbeat_msg.hasOwnProperty("custom_mode")) {
+ return "unknown because no HEARTBEAT message has been received from the vehicle";
+ }
+ //get the armed state flag by applying mask to base_model property
+ const armed_flag = (heartbeat_msg["base_mode"] & mavlink20.MAV_MODE_FLAG_SAFETY_ARMED) > 0;
+ //get mode number from custom_mode property
+ const mode_number = heartbeat_msg["custom_mode"];
+
+ return {
+ "armed": armed_flag,
+ "mode": mode_number
+ }
+ }
+
class EventHandler extends EventEmitter {
constructor(client) {
super()
@@ -713,6 +733,7 @@
try {
const toolOutputs = data.required_action.submit_tool_outputs.tool_calls.map((toolCall) => {
let output = handle_function_call(toolCall.function.name, toolCall.function.arguments)
+ output = JSON.stringify(output);
add_text_to_debug("fn:" + toolCall.function.name + " output:" + output)
return {
tool_call_id: toolCall.id,