Skip to content

Commit

Permalink
Fix parameter update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Sep 2, 2016
1 parent 2da149b commit c6f4503
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;

import timber.log.Timber;
Expand Down Expand Up @@ -58,6 +59,7 @@ public void run() {
};

private final AtomicBoolean isRefreshing = new AtomicBoolean(false);
private final ConcurrentLinkedQueue<String> paramsToReadFromVehicle = new ConcurrentLinkedQueue<>();

private int expectedParams;

Expand All @@ -80,6 +82,7 @@ public ParameterManager(MavLinkDrone myDrone, Context context, Handler handler)

public void refreshParameters() {
if (isRefreshing.compareAndSet(false, true)) {
paramsToReadFromVehicle.clear();
expectedParams = 0;
parameters.clear();
paramsRollCall.clear();
Expand Down Expand Up @@ -115,13 +118,14 @@ public boolean processMessage(MAVLinkMessage msg) {
}

protected void processReceivedParam(msg_param_value m_value) {
int paramIndex = m_value.param_index;
if(!isRefreshing.get() && paramIndex != -1)
String paramName = m_value.getParam_Id();
if(!paramsToReadFromVehicle.remove(paramName) && !isRefreshing.get())
return;
// collect params in parameter list
Parameter param = new Parameter(m_value.getParam_Id(), m_value.param_value, m_value.param_type);
Parameter param = new Parameter(paramName, m_value.param_value, m_value.param_type);
loadParameterMetadata(param);

int paramIndex = m_value.param_index;
parameters.put(param.getName().toLowerCase(Locale.US), param);
if (paramIndex == -1) {
// update listener
Expand All @@ -141,9 +145,8 @@ protected void processReceivedParam(msg_param_value m_value) {
if (parameters.size() >= m_value.param_count) {
if(isRefreshing.compareAndSet(true, false)) {
killWatchdog();

notifyParametersReceiptEnd();
}
notifyParametersReceiptEnd();
} else {
resetWatchdog();
}
Expand All @@ -158,10 +161,12 @@ private void reRequestMissingParams(int howManyParams) {
}

public void sendParameter(Parameter parameter) {
paramsToReadFromVehicle.add(parameter.getName());
MavLinkParameters.sendParameter(myDrone, parameter);
}

public void readParameter(String name) {
paramsToReadFromVehicle.add(name);
MavLinkParameters.readParameter(myDrone, name);
}

Expand Down

0 comments on commit c6f4503

Please sign in to comment.