Commit f6ca6cb6 authored by tstellanova's avatar tstellanova

fix updating of pending param list after transmit

parent 4ace23f9
......@@ -80,8 +80,8 @@ void UASParameterCommsMgr::requestParameterList()
transmissionListSizeKnown.clear();
transmissionListMode = true;
foreach (int key, transmissionMissingPackets.keys()) {
transmissionMissingPackets.value(key)->clear();
foreach (int key, missingReadPackets.keys()) {
missingReadPackets.value(key)->clear();
}
transmissionActive = true;
......@@ -106,10 +106,10 @@ void UASParameterCommsMgr::clearRetransmissionLists(int& missingReadCount, int&
qDebug() << __FILE__ << __LINE__ << "clearRetransmissionLists";
missingReadCount = 0;
QList<int> readKeys = transmissionMissingPackets.keys();
QList<int> readKeys = missingReadPackets.keys();
foreach (int compId, readKeys) {
missingReadCount += transmissionMissingPackets.value(compId)->count();
transmissionMissingPackets.value(compId)->clear();
missingReadCount += missingReadPackets.value(compId)->count();
missingReadPackets.value(compId)->clear();
}
missingWriteCount = 0;
......@@ -169,10 +169,11 @@ void UASParameterCommsMgr::resendReadWriteRequests()
// Re-request at maximum retransmissionBurstRequestSize parameters at once
// to prevent link flooding'
int requestedReadCount = 0;
compIds = transmissionMissingPackets.keys();
compIds = missingReadPackets.keys();
foreach (compId, compIds) {
// Request n parameters from this component (at maximum)
QList<int>* missingReadParams = transmissionMissingPackets.value(compId, NULL);
QList<int>* missingReadParams = missingReadPackets.value(compId, NULL);
qDebug() << "missingReadParams:" << missingReadParams->count();
foreach (int paramId, *missingReadParams) {
if (requestedReadCount < retransmissionBurstRequestSize) {
//qDebug() << __FILE__ << __LINE__ << "RETRANSMISSION GUARD REQUESTS RETRANSMISSION OF PARAM #" << paramId << "FROM COMPONENT #" << compId;
......@@ -423,11 +424,11 @@ void UASParameterCommsMgr::receivedParameterUpdate(int uas, int compId, int para
paramDataModel->handleParamUpdate(compId,paramName,value);
// Missing packets list has to be instantiated for all components
if (!transmissionMissingPackets.contains(compId)) {
transmissionMissingPackets.insert(compId, new QList<int>());
if (!missingReadPackets.contains(compId)) {
missingReadPackets.insert(compId, new QList<int>());
}
QList<int>* compXmitMissing = transmissionMissingPackets.value(compId);
QList<int>* compMissReadPackets = missingReadPackets.value(compId);
// List mode is different from single parameter transfers
if (transmissionListMode) {
......@@ -439,8 +440,8 @@ void UASParameterCommsMgr::receivedParameterUpdate(int uas, int compId, int para
qDebug() << "Mark all parameters as missing: " << paramCount;
for (int i = 1; i < paramCount; ++i) { //TODO check: param Id 0 is "all parameters" and not valid ?
if (!compXmitMissing->contains(i)) {
compXmitMissing->append(i);
if (!compMissReadPackets->contains(i)) {
compMissReadPackets->append(i);
}
}
......@@ -456,28 +457,27 @@ void UASParameterCommsMgr::receivedParameterUpdate(int uas, int compId, int para
}
// Mark this parameter as received in read list
int index = compXmitMissing->indexOf(paramId);
// If the MAV sent the parameter without request, it wont be in missing list
int index = compMissReadPackets->indexOf(paramId);
if (index != -1) {
compXmitMissing->removeAt(index);
compMissReadPackets->removeAt(index);
}
bool justWritten = false;
bool writeMismatch = false;
// Mark this parameter as received in write ACK list
QMap<QString, QVariant>* map = missingWriteAckPackets.value(compId);
if (map && map->contains(paramName)) {
QMap<QString, QVariant>* compMissWritePackets = missingWriteAckPackets.value(compId);
if (compMissWritePackets && compMissWritePackets->contains(paramName)) {
justWritten = true;
if (map->value(paramName) != value) {
if (compMissWritePackets->value(paramName) != value) {
writeMismatch = true;
}
map->remove(paramName);
compMissWritePackets->remove(paramName);
}
int missReadCount = 0;
foreach (int key, transmissionMissingPackets.keys()) {
missReadCount += transmissionMissingPackets.value(key)->count();
foreach (int key, missingReadPackets.keys()) {
missReadCount += missingReadPackets.value(key)->count();
}
int missWriteCount = 0;
......@@ -488,15 +488,14 @@ void UASParameterCommsMgr::receivedParameterUpdate(int uas, int compId, int para
//TODO simplify this if-else tree
if (justWritten) {
if (!writeMismatch) {
setParameterStatusMsg(tr("SUCCESS: Wrote %2 (#%1/%4): %3").arg(paramId+1).arg(paramName).arg(value.toDouble()).arg(paramCount));
setParameterStatusMsg(tr("SUCCESS: Wrote %2 (#%1/%4): %3 [%5]").arg(paramId+1).arg(paramName).arg(value.toDouble()).arg(paramCount).arg(missWriteCount));
if (0 == missWriteCount) {
setParameterStatusMsg(tr("SUCCESS: WROTE ALL PARAMETERS"));
paramDataModel->commitAllPendingParams();
}
}
else {
// Mismatch, tell user
setParameterStatusMsg(tr("FAILURE: Wrote %1: sent %2 != onboard %3").arg(paramName).arg(map->value(paramName).toDouble()).arg(value.toDouble()),
setParameterStatusMsg(tr("FAILURE: Wrote %1: sent %2 != onboard %3").arg(paramName).arg(compMissWritePackets->value(paramName).toDouble()).arg(value.toDouble()),
ParamCommsStatusLevel_Warning);
}
}
......@@ -512,6 +511,7 @@ void UASParameterCommsMgr::receivedParameterUpdate(int uas, int compId, int para
QString val = QString("%1").arg(value.toFloat(), 5, 'f', 1, QChar(' '));
setParameterStatusMsg(tr("OK: %1 %2 (%3/%4)").arg(paramName).arg(val).arg(paramCount-missReadCount).arg(paramCount),
ParamCommsStatusLevel_Warning);
//transmissionMissingPackets
}
}
......@@ -598,6 +598,8 @@ void UASParameterCommsMgr::sendPendingParameters()
}
// Enable guard
setRetransmissionGuardEnabled(true);
qDebug() << "Pending parameters now:" << paramDataModel->countPendingParams();
}
}
......
......@@ -92,7 +92,7 @@ protected:
// Communications management
QVector<bool> receivedParamsList; ///< Successfully received parameters
QMap<int, QList<int>* > transmissionMissingPackets; ///< Missing packets
QMap<int, QList<int>* > missingReadPackets; ///< Missing packets
QMap<int, QMap<QString, QVariant>* > missingWriteAckPackets; ///< Missing write ACK packets
bool transmissionListMode; ///< Currently requesting list
QMap<int, bool> transmissionListSizeKnown; ///< List size initialized?
......
......@@ -31,27 +31,6 @@ int UASParameterDataModel::countPendingParams()
return totalPending;
}
void UASParameterDataModel::commitAllPendingParams()
{
qDebug() << "commitAllPendingParams:" << countPendingParams();
QList<int> allCompIds = pendingParameters.keys();
foreach (int compId, allCompIds) {
// Iterate through the parameters of the component
QMap<QString, QVariant>* compParams = pendingParameters.value(compId);
QList<QString> paramNames = compParams->keys();
qDebug() << paramNames.count() << "committed params for component" << compId;
foreach (QString paramName, paramNames) {
QVariant value = compParams->value(paramName);
setOnboardParamWithType( compId, paramName, value);//update the onboard value to match pending value
emit pendingParamUpdate(compId,paramName,value,false); //no longer pending
emit parameterUpdated(compId,paramName,value);//ensure the new onboard value is broadcast
}
}
}
bool UASParameterDataModel::updatePendingParamWithValue(int compId, QString& key, const QVariant& value)
{
......@@ -163,26 +142,27 @@ void UASParameterDataModel::addComponent(int compId)
}
void UASParameterDataModel::handleParamUpdate(int compId, QString& key, QVariant& value)
void UASParameterDataModel::handleParamUpdate(int compId, QString& paramName, QVariant& value)
{
//verify that the value requested by the user matches the set value
//if it doesn't match, leave the pending parameter in the pending list!
if (pendingParameters.contains(compId)) {
QMap<QString , QVariant> *pendingParams = pendingParameters.value(compId);
if ((NULL != pendingParams) && pendingParams->contains(key)) {
QVariant reqVal = pendingParams->value(key);
if ((NULL != pendingParams) && pendingParams->contains(paramName)) {
QVariant reqVal = pendingParams->value(paramName);
if (reqVal == value) {
pendingParams->remove(key);
//notify everyone that this item is being removed from the pending parameters list since it's now confirmed
emit pendingParamUpdate(compId, paramName, value, false);
pendingParams->remove(paramName);
}
else {
qDebug() << "Pending commit for " << key << " want: " << reqVal << " got: " << value;
qDebug() << "Pending commit for " << paramName << " want: " << reqVal << " got: " << value;
}
}
}
setOnboardParam(compId,key,value);
emit parameterUpdated(compId,key,value);
emit parameterUpdated(compId,paramName,value);
setOnboardParam(compId,paramName,value);
}
......
......@@ -35,8 +35,6 @@ public:
virtual void addComponent(int compId);
virtual void removePendingParam(int compId, QString& key);
virtual void commitAllPendingParams();///< Called by eg params comms mgr when all pending params have been sent & acked
/** @brief Save the onboard parameter with a the type specified in the QVariant as fixed */
virtual void setOnboardParamWithType(int componentId, QString& key, QVariant& value);
......@@ -70,6 +68,9 @@ public:
return &onboardParameters;
}
/** @brief return a count of all pending parameters */
int countPendingParams();
virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName);
virtual void readUpdateParamsFromStream(QTextStream &stream);
......@@ -79,11 +80,14 @@ public:
void setUASID(int anId) { this->uasId = anId; }
protected:
/** @brief set the confirmed value of a parameter in the onboard params list */
virtual void setOnboardParam(int componentId, QString& key, const QVariant& value);
/** @brief Write a new pending parameter value that may be eventually sent to the UAS */
virtual void setPendingParam(int componentId, QString& key, const QVariant& value);
/** @brief remove a parameter from the pending list */
virtual void removePendingParam(int compId, QString& key);
int countPendingParams();
signals:
......
......@@ -509,16 +509,7 @@ void QGCParamWidget::requestAllParamsUpdate()
*/
void QGCParamWidget::writeParameters()
{
int changedParamCount = 0;
QMap<int, QMap<QString, QVariant>*>::iterator i;
QMap<int, QMap<QString, QVariant>*>* changedValues = paramDataModel->getAllPendingParams();
for (i = changedValues->begin(); (i != changedValues->end()) && (0 == changedParamCount); ++i) {
// Iterate through the pending parameters of the component, break on the first changed parameter
QMap<QString, QVariant>* compPending = i.value();
changedParamCount += compPending->count();
}
int changedParamCount = paramDataModel->countPendingParams();
if (changedParamCount > 0) {
QMessageBox msgBox;
......@@ -534,7 +525,7 @@ void QGCParamWidget::writeParameters()
void QGCParamWidget::readParameters()
{
if (!mav) return;
mav->readParametersFromStorage();
mav->readParametersFromStorage(); //TODO use data model / mgr instead?
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment