SlugsMAV.cc 7.01 KB
Newer Older
1 2
#include "SlugsMAV.h"

3 4
#include <QDebug>

5 6 7 8 9 10
SlugsMAV::SlugsMAV(MAVLinkProtocol* mavlink, int id) :
        UAS(mavlink, id)//,
        // Place other initializers here
{
}

11 12 13 14 15 16 17 18
/**
 * This function is called by MAVLink once a complete, uncorrupted (CRC check valid)
 * mavlink packet is received.
 *
 * @param link Hardware link the message came from (e.g. /dev/ttyUSB0 or UDP port).
 *             messages can be sent back to the system via this link
 * @param message MAVLink message, as received from the MAVLink protocol stack
 */
19 20
void SlugsMAV::receiveMessage(LinkInterface* link, mavlink_message_t message)
{
21 22 23
    // Let UAS handle the default message set
    UAS::receiveMessage(link, message);

unknown's avatar
unknown committed
24
    // Handle your special messages mavlink_message_t* msg = &message;
25 26 27 28
    switch (message.msgid)
    {
    case MAVLINK_MSG_ID_HEARTBEAT:
        {
29
            qDebug() << "SLUGS RECEIVED HEARTBEAT";
unknown's avatar
unknown committed
30 31
            break;
        }
32

tecnosapiens's avatar
tecnosapiens committed
33
#ifdef MAVLINK_ENABLED_SLUGS
34

unknown's avatar
unknown committed
35 36 37 38 39 40
    case MAVLINK_MSG_ID_CPU_LOAD:
        {
            mavlink_cpu_load_t cpu_load;
            quint64 time = getUnixTime(0);
            mavlink_msg_cpu_load_decode(&message,&cpu_load);

41 42 43
                emit valueChanged(uasId, tr("SensorDSC Load"), cpu_load.sensLoad, time);
                emit valueChanged(uasId, tr("ControlDSC Load"), cpu_load.ctrlLoad, time);
                emit valueChanged(uasId, tr("Battery Volt"), cpu_load.batVolt, time);
unknown's avatar
unknown committed
44

tecnosapiens's avatar
tecnosapiens committed
45 46 47 48 49
//                emit slugsCPULoad(uasId,
//                                  cpu_load.sensLoad,
//                                  cpu_load.ctrlLoad,
//                                  cpu_load.batVolt,
//                                  0);
50

unknown's avatar
unknown committed
51 52 53 54 55 56 57
            break;
        }
    case MAVLINK_MSG_ID_AIR_DATA:
        {
            mavlink_air_data_t air_data;
            quint64 time = getUnixTime(0);
            mavlink_msg_air_data_decode(&message,&air_data);
58 59 60
                emit valueChanged(uasId, tr("Dynamic Pressure"), air_data.dynamicPressure,time);
                emit valueChanged(uasId, tr("Static Pressure"),air_data.staticPressure, time);
                emit valueChanged(uasId, tr("Temp"),air_data.temperature,time);
unknown's avatar
unknown committed
61

tecnosapiens's avatar
tecnosapiens committed
62 63 64 65 66
//                emit slugsAirData(uasId,
//                                  air_data.dynamicPressure,
//                                  air_data.staticPressure,
//                                  air_data.temperature,
//                                  time);
67

unknown's avatar
unknown committed
68 69 70 71 72 73 74
            break;
        }
    case MAVLINK_MSG_ID_SENSOR_BIAS:
        {
            mavlink_sensor_bias_t sensor_bias;
            quint64 time = getUnixTime(0);
            mavlink_msg_sensor_bias_decode(&message,&sensor_bias);
75 76 77 78 79 80
                emit valueChanged(uasId,tr("Ax Bias"),sensor_bias.axBias, time);
                emit valueChanged(uasId,tr("Ay Bias"),sensor_bias.ayBias,time);
                emit valueChanged(uasId,tr("Az Bias"),sensor_bias.azBias,time);
                emit valueChanged(uasId,tr("Gx Bias"),sensor_bias.gxBias,time);
                emit valueChanged(uasId,tr("Gy Bias"),sensor_bias.gyBias,time);
                emit valueChanged(uasId,tr("Gz Bias"),sensor_bias.gzBias,time);
unknown's avatar
unknown committed
81

tecnosapiens's avatar
tecnosapiens committed
82
                emit slugsSensorBias(this,
83 84 85 86 87 88
                                     sensor_bias.axBias,
                                     sensor_bias.ayBias,
                                     sensor_bias.azBias,
                                     sensor_bias.gxBias,
                                     sensor_bias.gyBias,
                                     sensor_bias.gzBias,
tecnosapiens's avatar
tecnosapiens committed
89 90
                                     0);
                qDebug()<<"Entro";
91 92


unknown's avatar
unknown committed
93 94 95 96 97 98 99
            break;
        }
    case MAVLINK_MSG_ID_DIAGNOSTIC:
        {
            mavlink_diagnostic_t diagnostic;
            quint64 time = getUnixTime(0);
            mavlink_msg_diagnostic_decode(&message,&diagnostic);
100 101 102 103 104 105
                emit valueChanged(uasId,tr("Diag F1"),diagnostic.diagFl1,time);
                emit valueChanged(uasId,tr("Diag F2"),diagnostic.diagFl2,time);
                emit valueChanged(uasId,tr("Diag F3"),diagnostic.diagFl3,time);
                emit valueChanged(uasId,tr("Diag S1"),diagnostic.diagSh1,time);
                emit valueChanged(uasId,tr("Diag S2"),diagnostic.diagSh2,time);
                emit valueChanged(uasId,tr("Diag S3"),diagnostic.diagSh3,time);
unknown's avatar
unknown committed
106

tecnosapiens's avatar
tecnosapiens committed
107 108 109 110 111 112 113 114
//                emit slugsDiagnostic(uasId,
//                                     diagnostic.diagFl1,
//                                     diagnostic.diagFl2,
//                                     diagnostic.diagFl3,
//                                     diagnostic.diagSh1,
//                                     diagnostic.diagSh2,
//                                     diagnostic.diagSh3,
//                                     0);
115

unknown's avatar
unknown committed
116 117 118 119 120 121 122
            break;
        }
    case MAVLINK_MSG_ID_PILOT_CONSOLE:
        {
            mavlink_pilot_console_t pilot;
            quint64 time = getUnixTime(0);
            mavlink_msg_pilot_console_decode(&message,&pilot);
123 124 125 126 127
                emit valueChanged(uasId,"dt",pilot.dt,time);
                emit valueChanged(uasId,"dla",pilot.dla,time);
                emit valueChanged(uasId,"dra",pilot.dra,time);
                emit valueChanged(uasId,"dr",pilot.dr,time);
                emit valueChanged(uasId,"de",pilot.de,time);
unknown's avatar
unknown committed
128

tecnosapiens's avatar
tecnosapiens committed
129 130 131 132 133 134 135
//                emit slugsPilotConsolePWM(uasId,
//                                          pilot.dt,
//                                          pilot.dla,
//                                          pilot.dra,
//                                          pilot.dr,
//                                          pilot.de,
//                                          0);
136 137


unknown's avatar
unknown committed
138 139 140 141 142 143 144
            break;
        }
    case MAVLINK_MSG_ID_PWM_COMMANDS:
        {
            mavlink_pwm_commands_t pwm;
            quint64 time = getUnixTime(0);
            mavlink_msg_pwm_commands_decode(&message,&pwm);
145 146 147 148 149 150 151 152 153 154
                emit valueChanged(uasId,"dt_c",pwm.dt_c,time);
                emit valueChanged(uasId,"dla_c",pwm.dla_c,time);
                emit valueChanged(uasId,"dra_c",pwm.dra_c,time);
                emit valueChanged(uasId,"dr_c",pwm.dr_c,time);
                emit valueChanged(uasId,"dle_c",pwm.dle_c,time);
                emit valueChanged(uasId,"dre_c",pwm.dre_c,time);
                emit valueChanged(uasId,"dlf_c",pwm.dlf_c,time);
                emit valueChanged(uasId,"drf_c",pwm.drf_c,time);
                emit valueChanged(uasId,"da1_c",pwm.aux1,time);
                emit valueChanged(uasId,"da2_c",pwm.aux2,time);
unknown's avatar
unknown committed
155

tecnosapiens's avatar
tecnosapiens committed
156 157 158 159 160 161 162 163 164 165 166 167
//                emit slugsPWM(uasId,
//                              pwm.dt_c,
//                              pwm.dla_c,
//                              pwm.dra_c,
//                              pwm.dr_c,
//                              pwm.dle_c,
//                              pwm.dre_c,
//                              pwm.dlf_c,
//                              pwm.drf_c,
//                              pwm.aux1,
//                              pwm.aux2,
//                              0);
168

unknown's avatar
unknown committed
169

170 171
            break;
        }
tecnosapiens's avatar
tecnosapiens committed
172

173 174
#endif

175
    default:
176
        qDebug() << "\nSLUGS RECEIVED MESSAGE WITH ID" << message.msgid;
177 178 179
        break;
    }
}