12 constexpr int kMaxRetries = 3;
21 qCDebug(QGCCameraParamIOLog) <<
this;
23 _paramWriteTimer.setSingleShot(
true);
24 _paramWriteTimer.setInterval(3000);
25 _paramRequestTimer.setSingleShot(
true);
26 _paramRequestTimer.setInterval(3500);
28 if (_fact->writeOnly()) {
32 (void) connect(&_paramRequestTimer, &QTimer::timeout,
this, &QGCCameraParamIO::_paramRequestTimeout);
34 (void) connect(&_paramWriteTimer, &QTimer::timeout,
this, &QGCCameraParamIO::_paramWriteTimeout);
38 switch (_fact->type()) {
41 _mavParamType = MAV_PARAM_EXT_TYPE_UINT8;
44 _mavParamType = MAV_PARAM_EXT_TYPE_INT8;
47 _mavParamType = MAV_PARAM_EXT_TYPE_UINT16;
50 _mavParamType = MAV_PARAM_EXT_TYPE_INT16;
53 _mavParamType = MAV_PARAM_EXT_TYPE_UINT32;
56 _mavParamType = MAV_PARAM_EXT_TYPE_UINT64;
59 _mavParamType = MAV_PARAM_EXT_TYPE_INT64;
62 _mavParamType = MAV_PARAM_EXT_TYPE_REAL32;
65 _mavParamType = MAV_PARAM_EXT_TYPE_REAL64;
70 _mavParamType = MAV_PARAM_EXT_TYPE_CUSTOM;
73 qCWarning(QGCCameraParamIOLog) <<
"Unsupported fact type" << _fact->type() <<
"for" << _fact->name();
76 _mavParamType = MAV_PARAM_EXT_TYPE_INT32;
83 qCDebug(QGCCameraParamIOLog) <<
this;
86void QGCCameraParamIO::_paramRequestTimeout()
88 if (++_requestRetries > kMaxRetries) {
89 qCWarning(QGCCameraParamIOLog) <<
"No response for param request:" << _fact->name();
96 qCDebug(QGCCameraParamIOLog) <<
"Param request retry:" << _fact->name();
98 _paramRequestTimer.start();
102void QGCCameraParamIO::_paramWriteTimeout()
104 if (++_sentRetries > kMaxRetries) {
105 qCWarning(QGCCameraParamIOLog) <<
"No response for param set:" << _fact->name();
106 _updateOnSet =
false;
109 qCDebug(QGCCameraParamIOLog) <<
"Param set retry:" << _fact->name() << _sentRetries;
111 _paramWriteTimer.start();
115void QGCCameraParamIO::_factChanged(
const QVariant &value)
119 if (!_forceUIUpdate) {
120 qCDebug(QGCCameraParamIOLog) <<
"UI Fact" << _fact->name() <<
"changed to" << value;
125void QGCCameraParamIO::_containerRawValueChanged(
const QVariant &value)
129 if (!_fact->readOnly()) {
130 qCDebug(QGCCameraParamIOLog) <<
"Update Fact from camera" << _fact->name();
136void QGCCameraParamIO::_sendParameter()
140 mavlink_param_ext_set_t p{};
141 p.param_type = _mavParamType;
143 QGCMAVLink::param_ext_union_t union_value{};
149 union_value.param_uint8 =
static_cast<uint8_t
>(_fact->rawValue().toUInt(&ok));
152 union_value.param_int8 =
static_cast<int8_t
>(_fact->rawValue().toInt(&ok));
155 union_value.param_uint16 =
static_cast<uint16_t
>(_fact->rawValue().toUInt(&ok));
158 union_value.param_int16 =
static_cast<int16_t
>(_fact->rawValue().toInt(&ok));
161 union_value.param_uint32 =
static_cast<uint32_t
>(_fact->rawValue().toUInt(&ok));
164 union_value.param_int64 =
static_cast<int64_t
>(_fact->rawValue().toLongLong(&ok));
167 union_value.param_uint64 =
static_cast<uint64_t
>(_fact->rawValue().toULongLong(&ok));
170 union_value.param_float = _fact->rawValue().toFloat(&ok);
173 union_value.param_double = _fact->rawValue().toDouble(&ok);
178 const QByteArray custom = _fact->rawValue().toByteArray();
179 (void) memcpy(union_value.bytes, custom.constData(),
static_cast<size_t>(std::max(custom.size(),
static_cast<qsizetype
>(MAVLINK_MSG_PARAM_EXT_SET_FIELD_PARAM_VALUE_LEN))));
183 qCCritical(QGCCameraParamIOLog) <<
"Unsupported fact type" << factType <<
"for" << _fact->name();
186 union_value.param_int32 =
static_cast<int32_t
>(_fact->rawValue().toInt(&ok));
191 qCCritical(QGCCameraParamIOLog) <<
"Invalid value for" << _fact->name() <<
":" << _fact->rawValue();
194 (void) memcpy(&p.param_value[0], &union_value.bytes[0], MAVLINK_MSG_PARAM_EXT_SET_FIELD_PARAM_VALUE_LEN);
195 p.target_system =
static_cast<uint8_t
>(_vehicle->
id());
196 p.target_component =
static_cast<uint8_t
>(_control->
compID());
197 (void) qstrncpy(p.param_id, _fact->name().toStdString().c_str(), MAVLINK_MSG_PARAM_EXT_SET_FIELD_PARAM_ID_LEN);
200 (void) mavlink_msg_param_ext_set_encode_chan(
203 sharedLink->mavlinkChannel(),
210 _paramWriteTimer.start();
215 _paramWriteTimer.stop();
217 switch (ack.param_result) {
218 case PARAM_ACK_ACCEPTED: {
219 QVariant val = _valueFromMessage(ack.param_value, ack.param_type);
220 if (_fact->rawValue() != val) {
221 _fact->containerSetRawValue(val);
223 _updateOnSet =
false;
229 case PARAM_ACK_IN_PROGRESS:
231 qCDebug(QGCCameraParamIOLog) <<
"Param set in progress:" << _fact->name();
232 _paramWriteTimer.start();
234 case PARAM_ACK_FAILED:
235 if (++_sentRetries < kMaxRetries) {
237 qCWarning(QGCCameraParamIOLog) <<
"Param set failed:" << _fact->name() << _sentRetries;
238 _paramWriteTimer.start();
241 case PARAM_ACK_VALUE_UNSUPPORTED:
242 qCWarning(QGCCameraParamIOLog) <<
"Param set unsuported:" << _fact->name();
246 QVariant val = _valueFromMessage(ack.param_value, ack.param_type);
247 if (_fact->rawValue() != val) {
249 _fact->containerSetRawValue(val);
257QVariant QGCCameraParamIO::_valueFromMessage(
const char *value, uint8_t param_type)
260 QGCMAVLink::param_ext_union_t u{};
261 (void) memcpy(u.bytes, value, MAVLINK_MSG_PARAM_EXT_SET_FIELD_PARAM_VALUE_LEN);
262 switch (param_type) {
263 case MAV_PARAM_EXT_TYPE_REAL32:
264 var = QVariant(u.param_float);
266 case MAV_PARAM_EXT_TYPE_UINT8:
267 var = QVariant(u.param_uint8);
269 case MAV_PARAM_EXT_TYPE_INT8:
270 var = QVariant(u.param_int8);
272 case MAV_PARAM_EXT_TYPE_UINT16:
273 var = QVariant(u.param_uint16);
275 case MAV_PARAM_EXT_TYPE_INT16:
276 var = QVariant(u.param_int16);
278 case MAV_PARAM_EXT_TYPE_UINT32:
279 var = QVariant(u.param_uint32);
281 case MAV_PARAM_EXT_TYPE_INT32:
282 var = QVariant(u.param_int32);
284 case MAV_PARAM_EXT_TYPE_UINT64:
285 var = QVariant(
static_cast<quint64
>(u.param_uint64));
287 case MAV_PARAM_EXT_TYPE_INT64:
288 var = QVariant(
static_cast<qint64
>(u.param_int64));
290 case MAV_PARAM_EXT_TYPE_CUSTOM: {
292 char strValueWithNull[MAVLINK_MSG_PARAM_EXT_SET_FIELD_PARAM_VALUE_LEN + 1] = {};
293 (void) strncpy(strValueWithNull, value, MAVLINK_MSG_PARAM_EXT_SET_FIELD_PARAM_VALUE_LEN);
294 const QString strValue(strValueWithNull);
295 var = QVariant(strValue);
300 qCCritical(QGCCameraParamIOLog) <<
"Invalid param_type used for camera setting:" << param_type;
309 _paramRequestTimer.stop();
311 QVariant newValue = _valueFromMessage(value.param_value, value.param_type);
313 _fact->containerSetRawValue(newValue);
316 _paramRequestReceived =
true;
318 if (_forceUIUpdate) {
321 _forceUIUpdate =
false;
329 qCDebug(QGCCameraParamIOLog) << QStringLiteral(
"handleParamValue() %1 %2").arg(_fact->name(), _fact->rawValueString());
335 if (_fact->writeOnly()) {
345 _forceUIUpdate =
true;
348 qCDebug(QGCCameraParamIOLog) <<
"Request parameter:" << _fact->name();
351 char param_id[MAVLINK_MSG_PARAM_EXT_REQUEST_READ_FIELD_PARAM_ID_LEN + 1] = {};
352 (void) strncpy(param_id, _fact->name().toStdString().c_str(), MAVLINK_MSG_PARAM_EXT_REQUEST_READ_FIELD_PARAM_ID_LEN);
354 (void) mavlink_msg_param_ext_request_read_pack_chan(
357 sharedLink->mavlinkChannel(),
359 static_cast<uint8_t
>(_vehicle->
id()),
360 static_cast<uint8_t
>(_control->
compID()),
366 _paramRequestTimer.start();
371 qCDebug(QGCCameraParamIOLog) <<
"Send Fact" << _fact->name();
373 _updateOnSet = updateUI;
379 if (!_fact->writeOnly()) {
380 _paramRequestReceived =
false;
382 _paramRequestTimer.start();
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
struct __mavlink_message mavlink_message_t
#define QGC_LOGGING_CATEGORY(name, categoryStr)
A Fact is used to hold a single value within the system.
void rawValueChanged(const QVariant &value)
void containerRawValueChanged(const QVariant &value)
This signal is meant for use by Fact container implementations. Used to send changed values to vehicl...
void valueChanged(const QVariant &value)
This signal is only meant for use by the QT property system. It should not be connected to by client ...
static int getComponentId()
Get the component id of this application.
static MAVLinkProtocol * instance()
int getSystemId() const
Get the system id of this application.
Abstract base class for all camera controls: real and simulated.
virtual void _paramDone()=0
virtual void factChanged(Fact *pFact)=0
Notify controller a parameter has changed.
virtual bool incomingParameter(Fact *pFact, QVariant &newValue)=0
Allow controller to modify or invalidate incoming parameter.
virtual int compID() const =0
virtual bool validateParameter(Fact *pFact, QVariant &newValue)=0
Allow controller to modify or invalidate parameter change.
Camera parameter handler.
QGCCameraParamIO(MavlinkCameraControl *control, Fact *fact, Vehicle *vehicle)
void handleParamAck(const mavlink_param_ext_ack_t &ack)
void sendParameter(bool updateUI=false)
void handleParamValue(const mavlink_param_ext_value_t &value)
void paramRequest(bool reset=true)
WeakLinkInterfacePtr primaryLink() const
VehicleLinkManager * vehicleLinkManager()
bool sendMessageOnLinkThreadSafe(LinkInterface *link, mavlink_message_t message)