implement gcs:command_int() access to MAV_CMD_xxx commands */
| 1178 | implement gcs:command_int() access to MAV_CMD_xxx commands |
| 1179 | */ |
| 1180 | int lua_GCS_command_int(lua_State *L) |
| 1181 | { |
| 1182 | GCS *_gcs = check_GCS(L); |
| 1183 | binding_argcheck(L, 3); |
| 1184 | |
| 1185 | const uint16_t command = get_uint16_t(L, 2); |
| 1186 | if (!lua_istable(L, 3)) { |
| 1187 | // must have parameter table |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | mavlink_command_int_t pkt {}; |
| 1192 | |
| 1193 | pkt.command = command; |
| 1194 | |
| 1195 | float *params = &pkt.param1; |
| 1196 | int32_t *xy = &pkt.x; |
| 1197 | |
| 1198 | // extract the first 4 parameters as floats |
| 1199 | for (uint8_t i=0; i<4; i++) { |
| 1200 | char pname[3] { 'p' , char('1' + i), 0 }; |
| 1201 | lua_pushstring(L, pname); |
| 1202 | lua_gettable(L, 3); |
| 1203 | if (lua_isnumber(L, -1)) { |
| 1204 | params[i] = lua_tonumber(L, -1); |
| 1205 | } |
| 1206 | lua_pop(L, 1); |
| 1207 | } |
| 1208 | |
| 1209 | // extract the xy values |
| 1210 | for (uint8_t i=0; i<2; i++) { |
| 1211 | const char *names[] = { "x", "y" }; |
| 1212 | lua_pushstring(L, names[i]); |
| 1213 | lua_gettable(L, 3); |
| 1214 | if (lua_isinteger(L, -1)) { |
| 1215 | xy[i] = lua_tointeger(L, -1); |
| 1216 | } |
| 1217 | lua_pop(L, 1); |
| 1218 | } |
| 1219 | |
| 1220 | // and z |
| 1221 | lua_pushstring(L, "z"); |
| 1222 | lua_gettable(L, 3); |
| 1223 | if (lua_isnumber(L, -1)) { |
| 1224 | pkt.z = lua_tonumber(L, -1); |
| 1225 | } |
| 1226 | lua_pop(L, 1); |
| 1227 | |
| 1228 | // optional frame |
| 1229 | lua_pushstring(L, "frame"); |
| 1230 | lua_gettable(L, 3); |
| 1231 | if (lua_isinteger(L, -1)) { |
| 1232 | pkt.frame = lua_tointeger(L, -1); |
| 1233 | } |
| 1234 | lua_pop(L, 1); |
| 1235 | |
| 1236 | // call the interface with scheduler lock |
| 1237 | WITH_SEMAPHORE(AP::scheduler().get_semaphore()); |
nothing calls this directly
no test coverage detected