Skip to content

Instantly share code, notes, and snippets.

@ensonic
Created February 7, 2020 16:52
Show Gist options
  • Save ensonic/b19ee4229185f8923a0e6001fdc786bd to your computer and use it in GitHub Desktop.
Save ensonic/b19ee4229185f8923a0e6001fdc786bd to your computer and use it in GitHub Desktop.
From cb812f74b8bc97dd539ab65dbff9b8615252d32a Mon Sep 17 00:00:00 2001
From: Stefan Sauer <ensonic@users.sf.net>
Date: Fri, 7 Feb 2020 17:51:25 +0100
Subject: [PATCH] Add server side support for updating ev3dev updates.
---
.../restServices/robot/ev3/ev3dev/Update.java | 49 +++++++++++++++++++
RobotEV3/src/main/resources/ev3dev.properties | 5 +-
2 files changed, 52 insertions(+), 2 deletions(-)
create mode 100644 RobotEV3/src/main/java/de/fhg/iais/roberta/javaServer/restServices/robot/ev3/ev3dev/Update.java
diff --git a/RobotEV3/src/main/java/de/fhg/iais/roberta/javaServer/restServices/robot/ev3/ev3dev/Update.java b/RobotEV3/src/main/java/de/fhg/iais/roberta/javaServer/restServices/robot/ev3/ev3dev/Update.java
new file mode 100644
index 000000000..0a38ae9d0
--- /dev/null
+++ b/RobotEV3/src/main/java/de/fhg/iais/roberta/javaServer/restServices/robot/ev3/ev3dev/Update.java
@@ -0,0 +1,49 @@
+package de.fhg.iais.roberta.javaServer.restServices.robot.ev3.ev3dev;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+import de.fhg.iais.roberta.factory.IRobotFactory;
+import de.fhg.iais.roberta.util.AliveData;
+
+/**
+ * REST service for updating brick libraries and menu.<br>
+ */
+@Path("/update/ev3dev")
+public class Update {
+ private static final Logger LOG = LoggerFactory.getLogger(Update.class);
+
+ private final String robotUpdateResourcesDir;
+
+ @Inject
+ public Update(@Named("robotPluginMap") Map<String, IRobotFactory> robotPluginMap) {
+ this.robotUpdateResourcesDir = robotPluginMap.get("ev3dev").getPluginProperties().getUpdateDir();
+ }
+
+ @GET
+ @Path("/runtime")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response getRuntime() throws FileNotFoundException {
+ AliveData.rememberRobotCall(-1);
+ LOG.info("/update/ev3dev/runtime called");
+ File bin = new File(this.robotUpdateResourcesDir + "roberta.zip");
+ Response.ResponseBuilder response = Response.ok(new FileInputStream(bin));
+ response.header("Content-Disposition", "attachment; filename=roberta.zip");
+ response.header("Filename", "roberta.zip");
+ return response.build();
+ }
+}
diff --git a/RobotEV3/src/main/resources/ev3dev.properties b/RobotEV3/src/main/resources/ev3dev.properties
index 1b7d355d4..36b09de29 100644
--- a/RobotEV3/src/main/resources/ev3dev.properties
+++ b/RobotEV3/src/main/resources/ev3dev.properties
@@ -1,7 +1,7 @@
robot.plugin.group = ev3
robot.plugin.factory = de.fhg.iais.roberta.factory.EV3Factory
robot.plugin.compiler.resources.dir = RobotEV3/crossCompilerResources/
-robot.plugin.update.dir = RobotEV3/updateResources/
+robot.plugin.update.dir = RobotEV3/updateResources/ev3dev/
robot.plugin.fileExtension.source = py
robot.plugin.fileExtension.binary = py
@@ -33,10 +33,11 @@ robot.sim = true
robot.multisim = true
robot.connection = token
-
robot.descriptor = classpath:/ev3.yml
robot.helperMethods = classpath:/ev3dev.methods.yml
+robot.menu.version = 1.7.4
+
robot.plugin.worker.validate.robot = de.fhg.iais.roberta.worker.validate.Ev3BrickValidatorWorker
robot.plugin.worker.validate.sim = de.fhg.iais.roberta.worker.validate.Ev3SimValidatorWorker
robot.plugin.worker.collect.hardware = de.fhg.iais.roberta.worker.collect.Ev3UsedHardwareCollectorWorker
--
2.25.0.341.g760bfbb309-goog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment