From a8e4d29c5b9304a0dd9fc8431cbe8dcc8d288cc2 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 4 Jan 2021 13:33:47 +0100 Subject: [PATCH 1/6] xml error will now trigger red toast --- .../com/example/aped/communication/Communicator.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/APED/app/src/main/java/com/example/aped/communication/Communicator.java b/APED/app/src/main/java/com/example/aped/communication/Communicator.java index 2441268..0b3f350 100644 --- a/APED/app/src/main/java/com/example/aped/communication/Communicator.java +++ b/APED/app/src/main/java/com/example/aped/communication/Communicator.java @@ -21,6 +21,7 @@ import com.example.aped.MainActivity; import com.example.aped.R; import com.example.aped.utils.ExternalStorageHandler; +import org.json.JSONException; import org.json.JSONObject; import java.io.File; @@ -112,7 +113,16 @@ public class Communicator { Request.Method.POST, url, xmlFile, - response -> System.out.println(response.toString()), + response -> { + try { + JSONObject jsonObject = new JSONObject(response.toString()); + if (!jsonObject.getString("error").equals("")) { + makeToast(jsonObject.getString("error")); + } + } catch (JSONException e) { + Log.e("Communicator","JSON error on response during UPLOAD: " + e.getMessage()); + } + }, error -> handleError(error, "UPLOAD XML") ); requestQueue.add(request); From 7fadd4771f69930014236f51e4cdbd81075d6a1b Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 4 Jan 2021 17:30:10 +0100 Subject: [PATCH 2/6] improved json conversion --- .../com/example/aped/communication/Communicator.java | 2 -- .../com/example/aped/utils/ConfigurationHandler.java | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/APED/app/src/main/java/com/example/aped/communication/Communicator.java b/APED/app/src/main/java/com/example/aped/communication/Communicator.java index 0b3f350..c642647 100644 --- a/APED/app/src/main/java/com/example/aped/communication/Communicator.java +++ b/APED/app/src/main/java/com/example/aped/communication/Communicator.java @@ -1,7 +1,5 @@ package com.example.aped.communication; -import android.content.Context; -import android.graphics.Color; import android.util.Log; import android.view.View; import android.view.ViewGroup; diff --git a/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java b/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java index ee69943..d0d2873 100644 --- a/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java +++ b/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java @@ -247,10 +247,14 @@ public class ConfigurationHandler implements IFAVORITES { @NonNull @Override public String toString() { + List favoriteNamesString = new ArrayList<>(); + for (String favoriteName : favoriteNames){ + favoriteNamesString.add("\"" + favoriteName + "\""); + } return "{\n" - + "\"address\":\"" + address + "\",\n" - + "\"port\":\"" + port + "\",\n" - + "\"favorites\":" + favoriteNames.toString() + "\n" + + "\t\"address\":\"" + address + "\",\n" + + "\t\"port\":\"" + port + "\",\n" + + "\t\"favorites\":" + favoriteNamesString.toString() + "\n" + "}"; } } From 4ca7f99941daf56499b9a0e2ff7ae3e0829bbcf1 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 4 Jan 2021 23:18:20 +0100 Subject: [PATCH 3/6] updated XML submodule --- APED/app/src/main/assets/XML | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/APED/app/src/main/assets/XML b/APED/app/src/main/assets/XML index 594fc1e..2fddb6a 160000 --- a/APED/app/src/main/assets/XML +++ b/APED/app/src/main/assets/XML @@ -1 +1 @@ -Subproject commit 594fc1ea61264673706a2e26120e3b4b95af4f2f +Subproject commit 2fddb6ae3ff3247f684c89c34d0d859b7b2076bc From b2f263e5ed4352d3f851667b3331fc7201adbef7 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 4 Jan 2021 23:20:46 +0100 Subject: [PATCH 4/6] value info is no longer needed --- .../com/example/aped/utils/XMLHandler.java | 46 ------------------- .../com/example/aped/XMLHandlerUnitTest.java | 24 ---------- 2 files changed, 70 deletions(-) diff --git a/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java b/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java index 52d388a..8a91098 100644 --- a/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java +++ b/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java @@ -70,52 +70,6 @@ public class XMLHandler implements IXML { return returnList; } - /** - * reads the value info from the XML file. - * @param deviceName the name of the relevant device - * @return the value info as a dictionary {'unit','type','Offset','Factor'} - */ - @Override - public Dictionary getValueInfo(final String deviceName) { - Dictionary returnDictionary = new Hashtable<>(); - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xPath = xPathFactory.newXPath(); - try { - XPathExpression xPathExpression = xPath.compile( - "//Device[@name='" + deviceName + "']/ValueInfo"); - Element result = (Element) xPathExpression.evaluate( - root, XPathConstants.NODE); - returnDictionary.put("type", result.getAttribute("type")); - returnDictionary.put("unit", result.getAttribute("unit")); - NodeList childNodes = result.getChildNodes(); - float offset = 0.0f; - float factor = 1.0f; - for (int i = 0; i < childNodes.getLength(); i++) { - switch (childNodes.item(i).getNodeName()) { - case "Offset": - offset = Float.parseFloat(childNodes.item(i) - .getTextContent()); - break; - case "Factor": - factor = Float.parseFloat(childNodes.item(i) - .getTextContent()); - break; - default: - break; - } - } - returnDictionary.put("offset", offset); - returnDictionary.put("factor", factor); - } catch (XPathExpressionException e) { - Log.e( - "XMLHandler", - "the XPath for getting the value info has errors:" - + e.getMessage() - ); - } - return returnDictionary; - } - /** * reads the port information from the XML file. * @param deviceName the name of the relevant device diff --git a/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java b/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java index b8072a6..00f6789 100644 --- a/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java +++ b/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java @@ -43,30 +43,6 @@ public class XMLHandlerUnitTest { } } - @Test - public void TestInput_SimpleValueInfo(){ - try{ - XMLHandler xmlHandler = new XMLHandler(xmlFile); - Dictionary valueInfo = xmlHandler.getValueInfo("example"); - assertEquals("{factor=1.0, type=boolean, unit=, offset=0.0}",valueInfo.toString()); - }catch(IOException | ParserConfigurationException | SAXException e){ - System.out.println("XMLHandler failed"); - assert(false); - } - } - - @Test - public void TestInput_ComplexValueInfo(){ - try{ - XMLHandler xmlHandler = new XMLHandler(xmlFile); - Dictionary valueInfo = xmlHandler.getValueInfo("sensorarray"); - assertEquals("{factor=2.5, type=int, unit=°C, offset=1.2}",valueInfo.toString()); - }catch(IOException | ParserConfigurationException | SAXException e){ - System.out.println("XMLHandler failed"); - assert(false); - } - } - @Test public void TestInput_SimplePort(){ try{ From 39bab72621ea2158933d9c40e6a78ae919ce76bb Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 4 Jan 2021 23:22:22 +0100 Subject: [PATCH 5/6] added frequency to the return info of the port --- APED/app/src/main/java/com/example/aped/utils/XMLHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java b/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java index 8a91098..8bba0a8 100644 --- a/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java +++ b/APED/app/src/main/java/com/example/aped/utils/XMLHandler.java @@ -86,6 +86,7 @@ public class XMLHandler implements IXML { Element result = (Element) xPathExpression.evaluate( root, XPathConstants.NODE); returnDictionary.put("protocol", result.getAttribute("protocol")); + returnDictionary.put("frequency", result.getAttribute("frequency")); NodeList childNodes = result.getChildNodes(); List pins = new ArrayList<>(); for (int i = 0; i < childNodes.getLength(); i++) { From e5cdfb05a802d38fd803912158e28ddbb4644ddd Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 4 Jan 2021 23:32:40 +0100 Subject: [PATCH 6/6] removed last traces of value info --- .../app/src/main/java/com/example/aped/utils/IXML.java | 7 ------- .../src/main/java/com/example/aped/utils/TestXML.java | 10 ---------- 2 files changed, 17 deletions(-) diff --git a/APED/app/src/main/java/com/example/aped/utils/IXML.java b/APED/app/src/main/java/com/example/aped/utils/IXML.java index ec38d82..109e9eb 100644 --- a/APED/app/src/main/java/com/example/aped/utils/IXML.java +++ b/APED/app/src/main/java/com/example/aped/utils/IXML.java @@ -11,13 +11,6 @@ public interface IXML { */ List getDeviceNames(); - /** - * reads the value info of a given device from the XML. - * @param deviceName the name of the relevant device - * @return the value info as a Dictionary - */ - Dictionary getValueInfo(String deviceName); - /** * reads the port information of a given device from the XML. * @param deviceName the name of the relevant device diff --git a/APED/app/src/main/java/com/example/aped/utils/TestXML.java b/APED/app/src/main/java/com/example/aped/utils/TestXML.java index 701014a..ed10000 100644 --- a/APED/app/src/main/java/com/example/aped/utils/TestXML.java +++ b/APED/app/src/main/java/com/example/aped/utils/TestXML.java @@ -17,16 +17,6 @@ public class TestXML implements IXML { return returnList; } - @Override - public Dictionary getValueInfo(String deviceName) { - Dictionary returnDict = new Hashtable<>(); - returnDict.put("type", "boolean"); - returnDict.put("unit", ""); - returnDict.put("Offset", 1.0); - returnDict.put("Factor", 1.0); - return returnDict; - } - @Override public Dictionary getPort(String deviceName) { Dictionary returnDict = new Hashtable<>();