Commit af397019 authored by Julian Zobel's avatar Julian Zobel
Browse files

Public battery replacement request function with callback

parent d3e62a60
......@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.Actuator;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
/**
......@@ -60,6 +61,8 @@ public interface ControllableLocationActuator extends Actuator {
public void removeAllTargetLocations();
public void batteryReplacement(BatteryReplacementCallback cb);
public void returnToBase(ReachedLocationCallback cb);
public void connectToBase(BaseConnectedCallback cb);
......
......@@ -44,6 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.UAVToBaseInterface;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
/**
......@@ -54,7 +55,7 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocation
*/
public class UAVTopologyComponent extends AbstractTopologyComponent implements SimUAVLocationActuator {
public enum UAVstate {OFFLINE, ACTION, RETURN, CRASHED}
public enum UAVstate {OFFLINE, BASE_CONNECTION, ACTION, RETURN, CRASHED}
private UAVMovementModel movement;
......@@ -268,15 +269,19 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
movement.setTargetLocation(baseLocation, returnCallback);
}
protected void batteryReplacement() {
public void batteryReplacement(BatteryReplacementCallback cb) {
if(state != UAVstate.BASE_CONNECTION)
throw new UnsupportedOperationException("Cannot recharge if not connected to base!");
BaseTopologyComponent base = UAVBasePlacement.base;
base.getCharger().charge(this, null);
base.getCharger().charge(this, cb);
}
public void setControllerInterface(UAVToBaseInterface controllerInterface) {
this.controllerInterface = controllerInterface;
UAVBasePlacement.base.connectUAVToBase(this.controllerInterface);
state = UAVstate.OFFLINE;
this.connectToBase(null);
}
@Override
......@@ -286,6 +291,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
if(cb != null)
cb.successfulConnection();
this.state = UAVstate.BASE_CONNECTION;
}
@Override
......@@ -295,6 +302,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
if(cb != null)
cb.successfulDisconnection();
this.state = UAVstate.OFFLINE;
}
......
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