1818#include " QGCApplication.h"
1919#include " AppMessages.h"
2020#include " CmdLineOptParser.h"
21+ #include " MAVLinkProtocol.h"
2122
2223#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
2324 #include < QtWidgets/QMessageBox>
@@ -150,6 +151,8 @@ int main(int argc, char *argv[])
150151
151152 bool runUnitTests = false ;
152153 bool simpleBootTest = false ;
154+ QString systemIdStr = QString ();
155+ bool hasSystemId = false ;
153156
154157#ifdef QT_DEBUG
155158 // We parse a small set of command line options here prior to QGCApplication in order to handle the ones
@@ -163,6 +166,7 @@ int main(int argc, char *argv[])
163166 { " --unittest" , &runUnitTests, &unitTestOptions },
164167 { " --unittest-stress" , &stressUnitTests, &unitTestOptions },
165168 { " --no-windows-assert-ui" , &quietWindowsAsserts, nullptr },
169+ { " --system-id" , &hasSystemId, &systemIdStr },
166170 // Add additional command line option flags here
167171 };
168172
@@ -201,6 +205,18 @@ int main(int argc, char *argv[])
201205
202206 app.init ();
203207
208+ // Set system ID if specified via command line, for example --system-id:255
209+ if (hasSystemId) {
210+ bool ok;
211+ int systemId = systemIdStr.toInt (&ok);
212+ if (ok && systemId >= 0 && systemId <= 255 ) { // MAVLink system IDs are 8-bit
213+ qDebug () << " Setting MAVLink System ID to:" << systemId;
214+ MAVLinkProtocol::instance ()->setSystemId (systemId);
215+ } else {
216+ qDebug () << " Not setting MAVLink System ID. It must be between 0 and 255. Invalid system ID value:" << systemIdStr;
217+ }
218+ }
219+
204220 int exitCode = 0 ;
205221
206222#ifdef QGC_UNITTEST_BUILD
0 commit comments