-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #3: prepare for raspberry pi integration
reworked package structure and classes for more generic wired/wireless robots added calliope as generic wired robot for serial monitor usage only removed launcher class extracted help popup time to properties
- Loading branch information
Showing
38 changed files
with
645 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/de/fhg/iais/roberta/connection/AutoConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.fhg.iais.roberta.connection; | ||
|
||
/** | ||
* Connector class for robots that do not need server connection. | ||
* Automatically sets robots to connected. | ||
*/ | ||
public class AutoConnector extends AbstractConnector<IRobot> { | ||
public AutoConnector(IRobot robot) { | ||
super(robot); | ||
} | ||
|
||
@Override | ||
protected void runLoopBody() { | ||
if ( this.state == State.DISCOVER ) { | ||
this.fire(State.WAIT_FOR_CONNECT_BUTTON_PRESS); | ||
this.fire(State.WAIT_FOR_CMD); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/main/java/de/fhg/iais/roberta/connection/ev3/Ev3Detector.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/de/fhg/iais/roberta/connection/wired/IWiredRobot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.fhg.iais.roberta.connection.wired; | ||
|
||
import de.fhg.iais.roberta.connection.IRobot; | ||
|
||
/** | ||
* Interface for wired robots. | ||
*/ | ||
public interface IWiredRobot extends IRobot { | ||
@Override | ||
default ConnectionType getConnectionType() { | ||
return ConnectionType.WIRED; | ||
} | ||
|
||
/** | ||
* Returns the port of the wired robot. | ||
* | ||
* @return the port of the wired robot | ||
*/ | ||
String getPort(); | ||
|
||
/** | ||
* Returns the type of the wired robot. | ||
* | ||
* @return the type of the wired robot | ||
*/ | ||
WiredRobotType getType(); | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/de/fhg/iais/roberta/connection/wired/RndisDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package de.fhg.iais.roberta.connection.wired; | ||
|
||
import org.apache.http.entity.ContentType; | ||
import org.asynchttpclient.AsyncCompletionHandler; | ||
import org.asynchttpclient.AsyncHttpClient; | ||
import org.asynchttpclient.Dsl; | ||
import org.asynchttpclient.ListenableFuture; | ||
import org.asynchttpclient.Response; | ||
import org.json.JSONObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import de.fhg.iais.roberta.connection.IDetector; | ||
import de.fhg.iais.roberta.connection.IRobot; | ||
import de.fhg.iais.roberta.connection.wired.ev3.Ev3; | ||
import de.fhg.iais.roberta.util.PropertyHelper; | ||
|
||
import static de.fhg.iais.roberta.connection.IConnector.CMD_REGISTER; | ||
import static de.fhg.iais.roberta.connection.IConnector.KEY_CMD; | ||
|
||
public class RndisDetector implements IDetector { | ||
private static final Logger LOG = LoggerFactory.getLogger(RndisDetector.class); | ||
|
||
private static final Map<String, Class<? extends AbstractWiredRobot>> DEVICES = new HashMap<>(1); | ||
static { | ||
DEVICES.put(PropertyHelper.getInstance().getProperty("brickIp"), Ev3.class); | ||
} | ||
|
||
@Override | ||
public List<IRobot> detectRobots() { | ||
try (AsyncHttpClient client = Dsl.asyncHttpClient()) { | ||
JSONObject request = new JSONObject(); | ||
request.put(KEY_CMD, CMD_REGISTER); | ||
|
||
List<IRobot> robots = new ArrayList<>(5); | ||
for ( Entry<String, Class<? extends AbstractWiredRobot>> entry : DEVICES.entrySet() ) { | ||
ListenableFuture<String> | ||
name = | ||
client.preparePost("http://" + entry.getKey() + "/brickinfo") | ||
.addHeader("ContentType", ContentType.APPLICATION_JSON) | ||
.setBody(request.toString()) | ||
.execute(new StringAsyncCompletionHandler()); | ||
robots.add(entry.getValue().getConstructor(String.class).newInstance(name.get())); | ||
} | ||
return robots; | ||
} catch ( IOException e ) { | ||
LOG.error("Could not close async client: {}", e.getMessage()); | ||
} catch ( InterruptedException e ) { | ||
LOG.error("Robot request was interrupted: {}", e.getMessage()); | ||
} catch ( ExecutionException e ) { | ||
LOG.info("Could not find RNDIS robot: {}", e.getMessage()); | ||
} catch ( InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e ) { | ||
LOG.error("Robot not implemented: {}", e.getMessage()); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
|
||
private static class StringAsyncCompletionHandler extends AsyncCompletionHandler<String> { | ||
@Override | ||
public String onCompleted(Response response) { | ||
JSONObject jsonObject = new JSONObject(response.getResponseBody()); | ||
return jsonObject.getString("brickname"); | ||
} | ||
} | ||
} |
Oops, something went wrong.