Last active
February 12, 2016 12:59
-
-
Save ensonic/245f7171f11eb7a5f970 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
From 96b680ac7127c741f49983f59755dfdc0a6df824 Mon Sep 17 00:00:00 2001 | |
From: Stefan Sauer <[email protected]> | |
Date: Fri, 12 Feb 2016 13:54:44 +0100 | |
Subject: [PATCH] Disconnect the previous robot when switching between ev3 and | |
sim. | |
Otherwise the robot stays connected and if it tries to reconnect we get an | |
exception thrown. | |
Fixes #43 | |
--- | |
.../javaServer/restServices/all/ClientAdmin.java | 24 ++++++++++++++-------- | |
1 file changed, 15 insertions(+), 9 deletions(-) | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java | |
index 4ef0853..a929abc 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java | |
@@ -75,17 +75,23 @@ public class ClientAdmin { | |
RobotDao robotDao = new RobotDao(dbSession); | |
Robot robot = robotDao.loadRobot(robotName); | |
if ( robot != null ) { | |
- // TODO remove this and use a communicator | |
- if ( robotName.equals("oraSim") ) { | |
- httpSessionState.setToken("00000000"); | |
+ Util.addSuccessInfo(response, Key.TOKEN_SET_SUCCESS); | |
+ if ( httpSessionState.getRobotId() != robot.getId() ) { | |
+ // disconnect previous robot | |
+ this.brickCommunicator.disconnect(httpSessionState.getToken()); | |
+ // TODO remove this and use a communicator | |
+ if ( robotName.equals("oraSim") ) { | |
+ httpSessionState.setToken("00000000"); | |
+ } else { | |
+ httpSessionState.setToken("123"); | |
+ } | |
+ httpSessionState.setRobotId(robot.getId()); | |
+ response.put("robotId", robot.getId()); | |
+ response.put("robotName", robot.getName()); | |
+ LOG.info("set Robot: robot {} with id {}", robot.getName(), robot.getId()); | |
} else { | |
- httpSessionState.setToken("123"); | |
+ LOG.info("set Robot: robot {} with id {} already set", robot.getName(), robot.getId()); | |
} | |
- Util.addSuccessInfo(response, Key.TOKEN_SET_SUCCESS); | |
- httpSessionState.setRobotId(robot.getId()); | |
- response.put("robotId", robot.getId()); | |
- response.put("robotName", robot.getName()); | |
- LOG.info("set Robot: robot {} with id {} ", robot.getName(), robot.getId()); | |
} else { | |
LOG.error("Invalid command: " + cmd + " " + robotName); | |
Util.addErrorInfo(response, Key.COMMAND_INVALID); | |
-- | |
2.7.0.rc3.207.g0ac5344 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment