void ConfigStabilizationWidget::swapBankAndCurrent(int bank)
{
    UAVObject *fromStabBankObject = getStabBankObject(m_currentStabSettingsBank);
    UAVObject *toStabBankObject   = getStabBankObject(bank);

    if (fromStabBankObject && toStabBankObject) {
        quint8 fromStabBankObjectData[fromStabBankObject->getNumBytes()];
        quint8 toStabBankObjectData[toStabBankObject->getNumBytes()];
        fromStabBankObject->pack(fromStabBankObjectData);
        toStabBankObject->pack(toStabBankObjectData);
        toStabBankObject->unpack(fromStabBankObjectData);
        fromStabBankObject->unpack(toStabBankObjectData);
    }
}
Ejemplo n.º 2
0
/**
 * Update the data of an object from a byte array (unpack).
 * If the object instance could not be found in the list, then a
 * new one is created.
 */
UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data)
{
    // Get object
    UAVObject* obj = objMngr->getObject(objId, instId);
    // If the instance does not exist create it
    if (obj == NULL)
    {
        // Get the object type
        UAVObject* tobj = objMngr->getObject(objId);
        if (tobj == NULL)
        {
            return NULL;
        }
        // Make sure this is a data object
        UAVDataObject* dobj = dynamic_cast<UAVDataObject*>(tobj);
        if (dobj == NULL)
        {
            return NULL;
        }
        // Create a new instance, unpack and register
        UAVDataObject* instobj = dobj->clone(instId);
        if ( !objMngr->registerObject(instobj) )
        {
            return NULL;
        }
        instobj->unpack(data);
        return instobj;
    }
    else
    {
        // Unpack data into object instance
        obj->unpack(data);
        return obj;
    }
}
void ConfigStabilizationWidget::copyFromBankToBank(int fromBank, int toBank)
{
    UAVObject *fromStabBankObject = getStabBankObject(fromBank);
    UAVObject *toStabBankObject   = getStabBankObject(toBank);

    if (fromStabBankObject && toStabBankObject) {
        quint8 data[fromStabBankObject->getNumBytes()];
        fromStabBankObject->pack(data);
        toStabBankObject->unpack(data);
    }
}
void ConfigStabilizationWidget::copyCurrentStabBank()
{
    UAVObject *fromStabBankObject = getStabBankObject(m_currentStabSettingsBank);

    if (fromStabBankObject) {
        quint8 fromStabBankObjectData[fromStabBankObject->getNumBytes()];
        fromStabBankObject->pack(fromStabBankObjectData);
        for (int i = 0; i < m_stabSettingsBankCount; i++) {
            if (i != m_currentStabSettingsBank) {
                UAVObject *toStabBankObject = getStabBankObject(i);
                if (toStabBankObject) {
                    toStabBankObject->unpack(fromStabBankObjectData);
                }
            }
        }
    }
}