/** ****************************************************************************** * * @file telemetry.h * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup * @{ * *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TELEMETRY_H #define TELEMETRY_H #include "uavtalk.h" #include "uavobjects/uavobjectmanager.h" #include #include #include #include class Telemetry: public QThread { Q_OBJECT public: Telemetry(UAVTalk* utalk, UAVObjectManager* objMngr); void run(); signals: private slots: void objectUpdatedAuto(UAVObject* obj); void objectUpdatedManual(UAVObject* obj); void objectUnpacked(UAVObject* obj); void updateRequested(UAVObject* obj); void newObject(UAVObject* obj); void newInstance(UAVObject* obj); void processPeriodicUpdates(); private: // Constants static const int REQ_TIMEOUT_MS = 500; static const int MAX_RETRIES = 3; static const int MAX_UPDATE_PERIOD_MS = 1000; static const int MIN_UPDATE_PERIOD_MS = 1; // Types /** * Events generated by objects */ typedef enum { EV_UNPACKED = 0x01, /** Object data updated by unpacking */ EV_UPDATED = 0x02, /** Object data updated by changing the data structure */ EV_UPDATED_MANUAL = 0x04, /** Object update event manually generated */ EV_UPDATE_REQ = 0x08 /** Request to update object data */ } EventMask; typedef struct { UAVObject* obj; qint32 updatePeriodMs; /** Update period in ms or 0 if no periodic updates are needed */ qint32 timeToNextUpdateMs; /** Time delay to the next update */ } ObjectTimeInfo; // Variables UAVObjectManager* objMngr; UAVTalk* utalk; QList objList; QMutex* mutex; QTimer* timer; qint32 timeToNextUpdateMs; // Methods void registerObject(UAVObject* obj); void addObject(UAVObject* obj); void setUpdatePeriod(UAVObject* obj, qint32 periodMs); void connectToObjectInstances(UAVObject* obj, quint32 eventMask); void updateObject(UAVObject* obj); void processObjectUpdates(UAVObject* obj, EventMask event, bool allInstances); }; #endif // TELEMETRY_H