20,741
edits
Line 189: | Line 189: | ||
It is foreseeable that we may need to modify and extend JSBSim, i.e. to add new components - unfortunately, the "Extending JSBSim" chapter in the JSBSim reference manual is still just a placeholder without any content, so here are some stubs to help lower the barrier to entry when extending JSBSim. | It is foreseeable that we may need to modify and extend JSBSim, i.e. to add new components - unfortunately, the "Extending JSBSim" chapter in the JSBSim reference manual is still just a placeholder without any content, so here are some stubs to help lower the barrier to entry when extending JSBSim. | ||
=== Adding new Telnet commands === | |||
Analogous to FlightGear's [[Telnet usage|telnet/props]] system, JSBSim is a similar mechanism for remotely debugging/inspecting a running JSBSim instance, this can be enabled by adding this to the FDM: | |||
<syntaxhighlight lang="xml"> | |||
<input port="4000"/> | |||
</syntaxhighlight> | |||
You can then connect to the running FDM instance by using this | |||
<syntaxhighlight lang="text"> | |||
telnet localhost 4000 | |||
</syntaxhighlight> | |||
The protocol is fairly simple and straightforward to extend, see '''/src/models/FGInput.cpp''', to add a new command you just need to edit the '''bool FGInput::Run(bool Holding)''' method and add a new command, e.g. to a new '''test''' command that returns ''Hello World'': | |||
<syntaxhighlight lang="diff"> | |||
diff --git a/src/models/FGInput.cpp b/src/models/FGInput.cpp | |||
index e189a49..3c71907 100644 | |||
--- a/src/models/FGInput.cpp | |||
+++ b/src/models/FGInput.cpp | |||
@@ -237,8 +237,11 @@ bool FGInput::Run(bool Holding) | |||
" help\n" | |||
" quit\n" | |||
" info\n\n"); | |||
- | |||
- } else { | |||
+ } | |||
+ else if(command == "test") { | |||
+ socket->Reply("Hello World from JSBSim!\n"); | |||
+ } | |||
+ else { | |||
socket->Reply(string("Unknown command: ") + token + string("\n")); | |||
} | |||
</syntaxhighlight> | |||
=== Adding new Functions === | === Adding new Functions === |