mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-28 04:38:55 +08:00
AP_Scripting: introduce serial device simulation support
Allows a script to simulate a device attached via any serial protocol. The script can read and write data and have it handled according to the protocol as if exchanged over a serial port. The script can then do protocol translation, data filtering and validation, hardware-in-the-loop simulation, experimentation, etc., especially in combination with the scripting protocol which lets the script itself handle an attached device and so interpose any communication.
This commit is contained in:
1 parent
4df2a1bce7
commit
a077e4a3ed
10 files changed
+358
-9
No files matched your search
@@ -160,6 +160,43 @@ const AP_Param::GroupInfo AP_Scripting::var_info[] = {
|
||||
// @RebootRequired: True
|
||||
// @User: Advanced
|
||||
AP_GROUPINFO("THD_PRIORITY", 14, AP_Scripting, _thd_priority, uint8_t(ThreadPriority::NORMAL)),
|
||||
|
||||
#if AP_SCRIPTING_SERIALDEVICE_ENABLED
|
||||
// @Param: SDEV_EN
|
||||
// @DisplayName: Scripting serial device enable
|
||||
// @Description: Enable scripting serial devices
|
||||
// @Values: 0:Disabled, 1:Enabled
|
||||
// @RebootRequired: True
|
||||
// @User: Advanced
|
||||
AP_GROUPINFO_FLAGS("SDEV_EN", 15, AP_Scripting, _serialdevice.enable, 0, AP_PARAM_FLAG_ENABLE),
|
||||
|
||||
// @Param: SDEV1_PROTO
|
||||
// @DisplayName: Serial protocol of scripting serial device
|
||||
// @Description: Serial protocol of scripting serial device
|
||||
// @CopyFieldsFrom: SERIAL1_PROTOCOL
|
||||
// @RebootRequired: True
|
||||
// @User: Advanced
|
||||
AP_GROUPINFO("SDEV1_PROTO", 16, AP_Scripting, _serialdevice.ports[0].state.protocol, -1),
|
||||
|
||||
#if AP_SCRIPTING_SERIALDEVICE_NUM_PORTS > 1
|
||||
// @Param: SDEV2_PROTO
|
||||
// @DisplayName: Serial protocol of scripting serial device
|
||||
// @Description: Serial protocol of scripting serial device
|
||||
// @CopyFieldsFrom: SCR_SDEV1_PROTO
|
||||
AP_GROUPINFO("SDEV2_PROTO", 17, AP_Scripting, _serialdevice.ports[1].state.protocol, -1),
|
||||
#endif
|
||||
|
||||
#if AP_SCRIPTING_SERIALDEVICE_NUM_PORTS > 2
|
||||
// @Param: SDEV3_PROTO
|
||||
// @DisplayName: Serial protocol of scripting serial device
|
||||
// @Description: Serial protocol of scripting serial device
|
||||
// @CopyFieldsFrom: SCR_SDEV1_PROTO
|
||||
AP_GROUPINFO("SDEV3_PROTO", 18, AP_Scripting, _serialdevice.ports[2].state.protocol, -1),
|
||||
#endif
|
||||
#endif // AP_SCRIPTING_SERIALDEVICE_ENABLED
|
||||
|
||||
// WARNING: additional parameters must be listed before SDEV_EN (but have an
|
||||
// index after SDEV3_PROTO) so they are not disabled by it!
|
||||
|
||||
AP_GROUPEND
|
||||
};
|
||||
@@ -220,6 +257,16 @@ void AP_Scripting::init(void) {
|
||||
}
|
||||
}
|
||||
|
||||
#if AP_SCRIPTING_SERIALDEVICE_ENABLED
|
||||
void AP_Scripting::init_serialdevice_ports(void) {
|
||||
if (!_enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
_serialdevice.init();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAL_GCS_ENABLED
|
||||
MAV_RESULT AP_Scripting::handle_command_int_packet(const mavlink_command_int_t &packet) {
|
||||
switch ((SCRIPTING_CMD)packet.param1) {
|
||||
|
||||
Reference in new issue
Block a user