diff --git a/autobuild.sh b/autobuild.sh index e27559f2b11b3e1f96c2b6b40f05afe271df8c52..bf9b6ac74b8d03f0c98d68ae3946179ead1297db 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -28,7 +28,7 @@ do elif [ $OPT = "grab_debian_dependencies" ] &> /dev/null then echo you chose to install debian dependencies - sudo apt-get install cmake libqt4-dev flite1-dev libphonon-dev libopenscenegraph-dev + sudo apt-get install cmake libqt4-dev flite1-dev libphonon-dev libopenscenegraph-dev libsdl1.2-dev exit 0 elif [ $OPT = "remake" ] &> /dev/null diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index 0c43dbd6e07039c4f96c598fc85b42f50f3c8600..69ee72af4d437d2e56a7eee212d545e22eb9ac3b 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -182,6 +182,14 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) unsigned int decodeState = mavlink_parse_char(link->getId(), (uint8_t)(b.at(position)), &message, &status); if (decodeState == 1) { +#ifdef MAVLINK_MESSAGE_LENGTHS + const uint8_t message_lengths[] = MAVLINK_MESSAGE_LENGTHS; + if (message.msgid >= sizeof(message_lengths) || + message.len != message_lengths[message.msgid]) { + qDebug() << "MAVLink message " << message.msgid << " length incorrect (was " << message.len << " expected " << message_lengths[message.msgid] << ")"; + continue; + } +#endif // Log data if (m_loggingEnabled && m_logfile) { const int len = MAVLINK_MAX_PACKET_LEN+sizeof(quint64); diff --git a/src/comm/MAVLinkSimulationLink.cc b/src/comm/MAVLinkSimulationLink.cc index 1683ca2172ad2cec9c9f3e1e19545844555bb35f..50e87e9ff790391052a43fe341b2341d39ca25df 100644 --- a/src/comm/MAVLinkSimulationLink.cc +++ b/src/comm/MAVLinkSimulationLink.cc @@ -934,7 +934,7 @@ bool MAVLinkSimulationLink::connect() emit connected(true); start(LowPriority); - MAVLinkSimulationMAV* mav1 = new MAVLinkSimulationMAV(this, 1, 47.376, 8.548); + MAVLinkSimulationMAV* mav1 = new MAVLinkSimulationMAV(this, 1, 37.480391, -122.282883); Q_UNUSED(mav1); // MAVLinkSimulationMAV* mav2 = new MAVLinkSimulationMAV(this, 2, 47.375, 8.548, 1); // Q_UNUSED(mav2); diff --git a/src/comm/MAVLinkSimulationMAV.cc b/src/comm/MAVLinkSimulationMAV.cc index 2f2b2c70498dea5e42821a330e3c5b59507213a9..356104601ddf338dbe1c95ad0837dc8a654aaffc 100644 --- a/src/comm/MAVLinkSimulationMAV.cc +++ b/src/comm/MAVLinkSimulationMAV.cc @@ -23,13 +23,20 @@ MAVLinkSimulationMAV::MAVLinkSimulationMAV(MAVLinkSimulationLink *parent, int sy yaw(0.0), globalNavigation(true), firstWP(false), - previousSPX(8.548056), - previousSPY(47.376389), - previousSPZ(550), - previousSPYaw(0.0), - nextSPX(8.548056), - nextSPY(47.376389), - nextSPZ(550), +// previousSPX(8.548056), +// previousSPY(47.376389), +// previousSPZ(550), +// previousSPYaw(0.0), +// nextSPX(8.548056), +// nextSPY(47.376389), +// nextSPZ(550), + previousSPX(37.480391), + previousSPY(122.282883), + previousSPZ(550), + previousSPYaw(0.0), + nextSPX(37.480391), + nextSPY(122.282883), + nextSPZ(550), nextSPYaw(0.0), sys_mode(MAV_MODE_READY), sys_state(MAV_STATE_STANDBY), diff --git a/src/comm/MAVLinkXMLParser.cc b/src/comm/MAVLinkXMLParser.cc index 5aeb84338118faec5d3ec7a15bd32d093689d9c1..2ef5ab873b14beba809038a7ae17b66d8202b5a1 100644 --- a/src/comm/MAVLinkXMLParser.cc +++ b/src/comm/MAVLinkXMLParser.cc @@ -90,6 +90,16 @@ bool MAVLinkXMLParser::generate() int mavlinkVersion = 0; + // we need to gather the message lengths across multiple includes, + // which we can do via detecting recursion + static unsigned message_lengths[256]; + static int highest_message_id; + static int recursion_level; + + if (recursion_level == 0) { + highest_message_id = 0; + memset(message_lengths, 0, sizeof(message_lengths)); + } // Start main header @@ -138,7 +148,9 @@ bool MAVLinkXMLParser::generate() MAVLinkXMLParser includeParser(incFilePath, topLevelOutputDirName, this); connect(&includeParser, SIGNAL(parseState(QString)), this, SIGNAL(parseState(QString))); // Generate and write + recursion_level++; includeParser.generate(); + recursion_level--; mainHeader += "\n#include \"../" + pureIncludeFileName + "/" + pureIncludeFileName + ".h\"\n"; @@ -340,7 +352,7 @@ bool MAVLinkXMLParser::generate() QString decodeLines; QString sendArguments; QString commentLines; - + unsigned message_length = 0; // Get the message fields @@ -437,6 +449,40 @@ bool MAVLinkXMLParser::generate() } + // message length calculation + unsigned element_multiplier = 1; + unsigned element_length = 0; + const struct { + const char *prefix; + unsigned length; + } length_map[] = { + { "array", 1 }, + { "char", 1 }, + { "uint8", 1 }, + { "int8", 1 }, + { "uint16", 2 }, + { "int16", 2 }, + { "uint32", 4 }, + { "int32", 4 }, + { "uint64", 8 }, + { "int64", 8 }, + { "float", 4 }, + { "double", 8 }, + }; + if (fieldType.contains("[")) { + element_multiplier = fieldType.split("[").at(1).split("]").first().toInt(); + } + for (unsigned i=0; iERROR: Unable to calculate length for %2 near line %1\nAbort.").arg(QString::number(e.lineNumber()), fieldType)); + } + message_length += element_length; + // // QString unpackingCode; @@ -489,6 +535,11 @@ bool MAVLinkXMLParser::generate() f = f.nextSibling(); } + if (messageId > highest_message_id) { + highest_message_id = messageId; + } + message_lengths[messageId] = message_length; + cStruct = cStruct.arg(cStructName, cStructLines); lcmStructDefs.append("\n").append(cStruct).append("\n"); pack = pack.arg(messageName, packParameters, messageName.toUpper(), packLines); @@ -540,6 +591,15 @@ bool MAVLinkXMLParser::generate() mainHeader += includeLine.arg(messagesDirName + "/" + cFiles.at(i).first); } + mainHeader += "\n\n// MESSAGE LENGTHS\n\n"; + mainHeader += "#undef MAVLINK_MESSAGE_LENGTHS\n"; + mainHeader += "#define MAVLINK_MESSAGE_LENGTHS { "; + for (int i=0; isay(errString+tr(", please check the communication console for details.")); + GAudioOutput::instance()->say(errString+tr(", please check console for details.")); emit textMessageReceived(uasId, message.compid, 255, errString); std::cout << "Unable to decode message from system " << std::dec << static_cast(message.sysid) << " with message id:" << static_cast(message.msgid) << std::endl; //qDebug() << std::cerr << "Unable to decode message from system " << std::dec << static_cast(message.acid) << " with message id:" << static_cast(message.msgid) << std::endl; @@ -1119,7 +1119,8 @@ void UAS::startPressureCalibration() quint64 UAS::getUnixTime(quint64 time) { if (time == 0) { - return MG::TIME::getGroundTimeNow(); +// qDebug() << "XNEW time:" <writeParametersToStorage(); } void QGCParamWidget::readParameters() { + if (!mav) return; mav->readParametersFromStorage(); } diff --git a/src/ui/WaypointView.cc b/src/ui/WaypointView.cc index 7727fed4eb9936d0009be4d41e6a8f4e1ae3385c..9377458ad4b24137c3ba24f7c1d466c3e1317143 100644 --- a/src/ui/WaypointView.cc +++ b/src/ui/WaypointView.cc @@ -203,17 +203,17 @@ void WaypointView::updateActionView(int action) m_ui->orbitSpinBox->show(); m_ui->holdTimeSpinBox->show(); break; - case MAV_CMD_NAV_ORIENTATION_TARGET: - m_ui->orbitSpinBox->hide(); - m_ui->takeOffAngleSpinBox->hide(); - m_ui->turnsSpinBox->hide(); - m_ui->holdTimeSpinBox->show(); - m_ui->customActionWidget->hide(); - - m_ui->autoContinue->show(); - m_ui->acceptanceSpinBox->hide(); - m_ui->yawSpinBox->hide(); - break; +// case MAV_CMD_NAV_ORIENTATION_TARGET: +// m_ui->orbitSpinBox->hide(); +// m_ui->takeOffAngleSpinBox->hide(); +// m_ui->turnsSpinBox->hide(); +// m_ui->holdTimeSpinBox->show(); +// m_ui->customActionWidget->hide(); + +// m_ui->autoContinue->show(); +// m_ui->acceptanceSpinBox->hide(); +// m_ui->yawSpinBox->hide(); +// break; default: break; } diff --git a/thirdParty/qserialport/include/QtSerialPort/qportsettings.h b/thirdParty/qserialport/include/QtSerialPort/qportsettings.h index 810304f599612c9e875705ea1b8a5d98e6c5442d..771f7baba5ce400f58260d9c7b9c2836377c2321 100644 --- a/thirdParty/qserialport/include/QtSerialPort/qportsettings.h +++ b/thirdParty/qserialport/include/QtSerialPort/qportsettings.h @@ -42,224 +42,224 @@ #endif namespace TNX { - -enum ChangeApplyTypes { AllAppTy, PortAttrOnlyAppTy, CommTimeoutsOnlyAppTy }; - -/** - * Communication timeout values for Win32/CE and Posix platforms. - * @see www.unixwiz.net/techtips/termios-vmin-vtime.html - */ -struct CommTimeouts { + + enum ChangeApplyTypes { AllAppTy, PortAttrOnlyAppTy, CommTimeoutsOnlyAppTy }; + + /** + * Communication timeout values for Win32/CE and Posix platforms. + * @see www.unixwiz.net/techtips/termios-vmin-vtime.html + */ + struct CommTimeouts { #ifdef TNX_WINDOWS_SERIAL_PORT - typedef DWORD commt_t; - static const DWORD NoTimeout = MAXDWORD; + typedef DWORD commt_t; + static const DWORD NoTimeout = MAXDWORD; #else - typedef quint8 commt_t; - static const qint8 NoTimeout = -1; + typedef quint8 commt_t; + static const qint8 NoTimeout = -1; #endif - - // Win32 only section - commt_t Win32ReadIntervalTimeout; ///< Maximum time between read chars. Win32 only. - commt_t Win32ReadTotalTimeoutMultiplier; ///< Multiplier of characters. Win32 only. - commt_t Win32ReadTotalTimeoutConstant; ///< Constant in milliseconds. Win32 only. - commt_t Win32WriteTotalTimeoutMultiplier; ///< Multiplier of characters. Win32 only. - commt_t Win32WriteTotalTimeoutConstant; ///< Constant in milliseconds. Win32 only. - - // Posix only section - commt_t PosixVTIME; ///< Read timeout. Posix only. - commt_t PosixVMIN; ///< Minimum number of bytes before returning from - ///< read operation. Posix only. - CommTimeouts() - : Win32ReadIntervalTimeout(NoTimeout), Win32ReadTotalTimeoutMultiplier(0), Win32ReadTotalTimeoutConstant(0), - Win32WriteTotalTimeoutMultiplier(25), Win32WriteTotalTimeoutConstant(250), - PosixVTIME(0), PosixVMIN(1) - { - } -}; - -/** - * Wrapper class for serial port settings. - */ -class TONIX_EXPORT QPortSettings -{ -public: - enum BaudRate { - BAUDR_UNKNOWN = 0, + + // Win32 only section + commt_t Win32ReadIntervalTimeout; ///< Maximum time between read chars. Win32 only. + commt_t Win32ReadTotalTimeoutMultiplier; ///< Multiplier of characters. Win32 only. + commt_t Win32ReadTotalTimeoutConstant; ///< Constant in milliseconds. Win32 only. + commt_t Win32WriteTotalTimeoutMultiplier; ///< Multiplier of characters. Win32 only. + commt_t Win32WriteTotalTimeoutConstant; ///< Constant in milliseconds. Win32 only. + + // Posix only section + commt_t PosixVTIME; ///< Read timeout. Posix only. + commt_t PosixVMIN; ///< Minimum number of bytes before returning from + ///< read operation. Posix only. + CommTimeouts() + : Win32ReadIntervalTimeout(NoTimeout), Win32ReadTotalTimeoutMultiplier(0), Win32ReadTotalTimeoutConstant(0), + Win32WriteTotalTimeoutMultiplier(25), Win32WriteTotalTimeoutConstant(250), + PosixVTIME(0), PosixVMIN(1) + { + } + }; + + /** + * Wrapper class for serial port settings. + */ + class TONIX_EXPORT QPortSettings + { + public: + enum BaudRate { + BAUDR_UNKNOWN = 0, #ifdef TNX_POSIX_SERIAL_PORT - BAUDR_50, - BAUDR_75, - BAUDR_134, - BAUDR_150, - BAUDR_200, - BAUDR_1800, - //BAUDR_76800, + BAUDR_50, + BAUDR_75, + BAUDR_134, + BAUDR_150, + BAUDR_200, + BAUDR_1800, + //BAUDR_76800, #endif #ifdef Q_OS_LINUX - BAUDR_230400, - BAUDR_460800, - BAUDR_500000, - BAUDR_576000, + BAUDR_230400, + BAUDR_460800, + BAUDR_500000, + BAUDR_576000, #endif #ifdef TNX_WINDOWS_SERIAL_PORT - BAUDR_14400, - BAUDR_56000, - BAUDR_128000, - BAUDR_230400, - BAUDR_256000, - BAUDR_460800, + BAUDR_14400, + BAUDR_56000, + BAUDR_128000, + BAUDR_230400, + BAUDR_256000, + BAUDR_460800, #endif - // baud rates supported by all OSs - BAUDR_110, - BAUDR_300, - BAUDR_600, - BAUDR_1200, - BAUDR_2400, - BAUDR_4800, - BAUDR_9600, - BAUDR_19200, - BAUDR_38400, - BAUDR_57600, - BAUDR_115200, - BAUDR_921600 - }; - - enum DataBits { - DB_5, // simulated in POSIX - DB_6, - DB_7, - DB_8, - DB_UNKNOWN - }; - - enum Parity { - PAR_NONE, - PAR_ODD, - PAR_EVEN, + // baud rates supported by all OSs + BAUDR_110, + BAUDR_300, + BAUDR_600, + BAUDR_1200, + BAUDR_2400, + BAUDR_4800, + BAUDR_9600, + BAUDR_19200, + BAUDR_38400, + BAUDR_57600, + BAUDR_115200, + BAUDR_921600 + }; + + enum DataBits { + DB_5, // simulated in POSIX + DB_6, + DB_7, + DB_8, + DB_UNKNOWN + }; + + enum Parity { + PAR_NONE, + PAR_ODD, + PAR_EVEN, #ifdef TNX_WINDOWS_SERIAL_PORT - PAR_MARK, + PAR_MARK, #endif - PAR_SPACE, // simulated in POSIX - PAR_UNKNOWN - }; - - enum StopBits { - STOP_1, + PAR_SPACE, // simulated in POSIX + PAR_UNKNOWN + }; + + enum StopBits { + STOP_1, #ifdef TNX_WINDOWS_SERIAL_PORT - STOP_1_5, + STOP_1_5, #endif - STOP_2, - STOP_UNKNOWN - }; - - enum FlowControl { - FLOW_OFF, - FLOW_HARDWARE, - FLOW_XONXOFF, - FLOW_UNKNOWN - }; - - QPortSettings(); - QPortSettings(const QString &settings); - - // port configuration methods - - bool set(const QString &settings); - - inline BaudRate baudRate() const { - return baudRate_; - } - void setBaudRate(BaudRate baudRate) { - baudRate_ = baudRate; - - switch ( baudRate_ ) { - #ifdef TNX_POSIX_SERIAL_PORT - case BAUDR_50: baudRateInt_=50; break; - case BAUDR_75: baudRateInt_=75; break; - case BAUDR_134: baudRateInt_=134; break; - case BAUDR_150: baudRateInt_=150; break; - case BAUDR_200: baudRateInt_=200; break; - case BAUDR_1800: baudRateInt_=1800; break; - //case 76800: baudRateInt_=76800; break; - #endif - #ifdef TNX_WINDOWS_SERIAL_PORT - case BAUDR_14400: baudRateInt_=14400; break; - case BAUDR_56000: baudRateInt_=56000; break; - case BAUDR_128000: baudRateInt_=128000; break; - case BAUDR_256000: baudRateInt_=256000; break; - case BAUDR_230400: baudRateInt_=230400; break; - case BAUDR_460800: baudRateInt_=460800; break; - #endif - #if defined(Q_OS_LINUX) - case BAUDR_230400: baudRateInt_=230400; break; - case BAUDR_460800: baudRateInt_=460800; break; - case BAUDR_500000: baudRateInt_=500000; break; - case BAUDR_576000: baudRateInt_=576000; break; - #endif - // baud rates supported by all platforms - case BAUDR_110: baudRateInt_=110; break; - case BAUDR_300: baudRateInt_=300; break; - case BAUDR_600: baudRateInt_=600; break; - case BAUDR_1200: baudRateInt_=1200; break; - case BAUDR_2400: baudRateInt_=2400; break; - case BAUDR_4800: baudRateInt_=4800; break; - case BAUDR_9600: baudRateInt_=9600; break; - case BAUDR_19200: baudRateInt_=19200; break; - case BAUDR_38400: baudRateInt_=38400; break; - case BAUDR_57600: baudRateInt_=57600; break; - case BAUDR_115200: baudRateInt_=115200; break; - case BAUDR_921600: baudRateInt_=921600; break; - default: - baudRateInt_ = 0; // unknown baudrate - } - } - - inline Parity parity() const { - return parity_; - } - inline void setParity(Parity parity) { - parity_ = parity; - } - - inline StopBits stopBits() const { - return stopBits_; - } - inline void setStopBits(StopBits stopBits) { - stopBits_ = stopBits; - } - - inline DataBits dataBits() const { - return dataBits_; - } - inline void setDataBits(DataBits dataBits) { - dataBits_ = dataBits; - } - - inline FlowControl flowControl() const { - return flowControl_; - } - inline void setFlowControl(FlowControl flowControl) { - flowControl_ = flowControl; - } - - QString toString() const; - - // helper methods to configure port settings -private: - static BaudRate baudRateFromInt(int baud, bool &ok); - static DataBits dataBitsFromString(const QString &databits, bool &ok); - static Parity parityFromString(const QString &parity, bool &ok); - static StopBits stopBitsFromString(const QString &stopbits, bool &ok); - static FlowControl flowControlFromString(const QString &flow, bool &ok); - -private: - BaudRate baudRate_; - DataBits dataBits_; - Parity parity_; - StopBits stopBits_; - FlowControl flowControl_; - qint32 baudRateInt_; -}; - + STOP_2, + STOP_UNKNOWN + }; + + enum FlowControl { + FLOW_OFF, + FLOW_HARDWARE, + FLOW_XONXOFF, + FLOW_UNKNOWN + }; + + QPortSettings(); + QPortSettings(const QString &settings); + + // port configuration methods + + bool set(const QString &settings); + + inline BaudRate baudRate() const { + return baudRate_; + } + void setBaudRate(BaudRate baudRate) { + baudRate_ = baudRate; + + switch ( baudRate_ ) { +#ifdef TNX_POSIX_SERIAL_PORT + case BAUDR_50: baudRateInt_=50; break; + case BAUDR_75: baudRateInt_=75; break; + case BAUDR_134: baudRateInt_=134; break; + case BAUDR_150: baudRateInt_=150; break; + case BAUDR_200: baudRateInt_=200; break; + case BAUDR_1800: baudRateInt_=1800; break; + //case 76800: baudRateInt_=76800; break; +#endif +#ifdef TNX_WINDOWS_SERIAL_PORT + case BAUDR_14400: baudRateInt_=14400; break; + case BAUDR_56000: baudRateInt_=56000; break; + case BAUDR_128000: baudRateInt_=128000; break; + case BAUDR_256000: baudRateInt_=256000; break; + case BAUDR_230400: baudRateInt_=230400; break; + case BAUDR_460800: baudRateInt_=460800; break; +#endif +#if defined(Q_OS_LINUX) + case BAUDR_230400: baudRateInt_=230400; break; + case BAUDR_460800: baudRateInt_=460800; break; + case BAUDR_500000: baudRateInt_=500000; break; + case BAUDR_576000: baudRateInt_=576000; break; +#endif + // baud rates supported by all platforms + case BAUDR_110: baudRateInt_=110; break; + case BAUDR_300: baudRateInt_=300; break; + case BAUDR_600: baudRateInt_=600; break; + case BAUDR_1200: baudRateInt_=1200; break; + case BAUDR_2400: baudRateInt_=2400; break; + case BAUDR_4800: baudRateInt_=4800; break; + case BAUDR_9600: baudRateInt_=9600; break; + case BAUDR_19200: baudRateInt_=19200; break; + case BAUDR_38400: baudRateInt_=38400; break; + case BAUDR_57600: baudRateInt_=57600; break; + case BAUDR_115200: baudRateInt_=115200; break; + case BAUDR_921600: baudRateInt_=921600; break; + default: + baudRateInt_ = 0; // unknown baudrate + } + } + + inline Parity parity() const { + return parity_; + } + inline void setParity(Parity parity) { + parity_ = parity; + } + + inline StopBits stopBits() const { + return stopBits_; + } + inline void setStopBits(StopBits stopBits) { + stopBits_ = stopBits; + } + + inline DataBits dataBits() const { + return dataBits_; + } + inline void setDataBits(DataBits dataBits) { + dataBits_ = dataBits; + } + + inline FlowControl flowControl() const { + return flowControl_; + } + inline void setFlowControl(FlowControl flowControl) { + flowControl_ = flowControl; + } + + QString toString() const; + + // helper methods to configure port settings + private: + static BaudRate baudRateFromInt(int baud, bool &ok); + static DataBits dataBitsFromString(const QString &databits, bool &ok); + static Parity parityFromString(const QString &parity, bool &ok); + static StopBits stopBitsFromString(const QString &stopbits, bool &ok); + static FlowControl flowControlFromString(const QString &flow, bool &ok); + + private: + BaudRate baudRate_; + DataBits dataBits_; + Parity parity_; + StopBits stopBits_; + FlowControl flowControl_; + qint32 baudRateInt_; + }; + } #endif // TNX_QSERIALPORTSETTINGS_H__