Skip to content

Commit

Permalink
AP_Scripting: Add bindings for command_long
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed Jan 30, 2025
1 parent d529601 commit a4d0ba8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2981,6 +2981,12 @@ function gcs:last_seen() end
---@return integer -- MAV_RESULT
function gcs:run_command_int(command, params) end

-- call a MAVLink MAV_CMD_xxx command via command_long interface
---@param command integer -- MAV_CMD_xxx
---@param params table -- parameters of p1, p2, p3, p4, p5, p6 and p7. Any not specified taken as zero
---@return integer -- MAV_RESULT
function gcs:run_command_long(command, params) end

-- The relay library provides access to controlling relay outputs.
relay = {}

Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ singleton GCS method get_high_latency_status depends HAL_HIGH_LATENCY2_ENABLED =
singleton GCS method enable_high_latency_connections void boolean
singleton GCS method enable_high_latency_connections depends HAL_HIGH_LATENCY2_ENABLED == 1
singleton GCS manual run_command_int lua_GCS_command_int 2 1
singleton GCS manual run_command_long lua_GCS_command_long 2 1

include AP_ONVIF/AP_ONVIF.h depends ENABLE_ONVIF == 1
singleton AP_ONVIF depends ENABLE_ONVIF == 1
Expand Down
42 changes: 42 additions & 0 deletions libraries/AP_Scripting/lua_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,48 @@ int lua_GCS_command_int(lua_State *L)

return 1;
}

/*
implement gcs:command_long() access to MAV_CMD_xxx commands
*/
int lua_GCS_command_long(lua_State *L)
{
GCS *_gcs = check_GCS(L);
binding_argcheck(L, 3);

const uint16_t command = get_uint16_t(L, 2);
if (!lua_istable(L, 3)) {
// must have parameter table
return 0;
}

mavlink_command_long_t pkt {};

pkt.command = command;

float *params = &pkt.param1;

// extract the 7 parameters as floats
for (uint8_t i=0; i<7; i++) {
char pname[3] { 'p' , char('1' + i), 0 };
lua_pushstring(L, pname);
lua_gettable(L, 3);
if (lua_isnumber(L, -1)) {
params[i] = lua_tonumber(L, -1);
}
lua_pop(L, 1);
}

// call the interface with scheduler lock
WITH_SEMAPHORE(AP::scheduler().get_semaphore());

auto result = _gcs->lua_command_long_packet(pkt);

// Return the resulting MAV_RESULT
lua_pushinteger(L, result);

return 1;
}
#endif

#if HAL_ENABLE_DRONECAN_DRIVERS
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Scripting/lua_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ int lua_mavlink_block_command(lua_State *L);
int lua_print(lua_State *L);
int lua_range_finder_handle_script_msg(lua_State *L);
int lua_GCS_command_int(lua_State *L);
int lua_GCS_command_long(lua_State *L);
int lua_DroneCAN_get_FlexDebug(lua_State *L);

0 comments on commit a4d0ba8

Please sign in to comment.