From e206c2d03ec1137efbafcc14d806bb03774d9924 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Thu, 7 Jan 2021 21:11:37 +0100 Subject: [PATCH 1/2] changed default config.json --- APED/app/src/main/assets/defaultConfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/APED/app/src/main/assets/defaultConfig.json b/APED/app/src/main/assets/defaultConfig.json index a3f1800..5b5b54a 100644 --- a/APED/app/src/main/assets/defaultConfig.json +++ b/APED/app/src/main/assets/defaultConfig.json @@ -1,6 +1,6 @@ { "address": "192.168.1.100", "port" : 8080, - "currentView" : "", + "currentView" : -1, "favorites" : [ ] } \ No newline at end of file From cdb3e1ec2133cb8e86df9bdd4746f1aeb1d5241e Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Thu, 7 Jan 2021 21:57:04 +0100 Subject: [PATCH 2/2] added ability to read buffer size from the xml --- APED/app/src/main/assets/XML | 2 +- .../java/com/example/aped/utils/IXML.java | 7 +++++ .../com/example/aped/utils/XMLHandler.java | 27 +++++++++++++++- .../com/example/aped/XMLHandlerUnitTest.java | 31 ++++++------------- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/APED/app/src/main/assets/XML b/APED/app/src/main/assets/XML index 2fddb6a..74b98ac 160000 --- a/APED/app/src/main/assets/XML +++ b/APED/app/src/main/assets/XML @@ -1 +1 @@ -Subproject commit 2fddb6ae3ff3247f684c89c34d0d859b7b2076bc +Subproject commit 74b98acdc7fe19ceb480b7a2d5034b4bde9c5729 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 109e9eb..c825bfe 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 @@ -17,4 +17,11 @@ public interface IXML { * @return the value info as a Dictionary */ Dictionary getPort(String deviceName); + + /** + * Method to read the buffer size of a given device from the XML. + * @param deviceName the name of the relevant device + * @return the buffer size as an {@link Integer} + */ + int getBufferSize(String deviceName); } 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 8bba0a8..05fe053 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,6 +70,31 @@ public class XMLHandler implements IXML { return returnList; } + /** + * reads the buffer size from the XML file + * @param deviceName the name of the relevant device + * @return the buffer size as an {@link Integer} + */ + @Override + public int getBufferSize(String deviceName) { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xPath = xPathFactory.newXPath(); + try { + XPathExpression xPathExpression = xPath.compile( + "//Device[@name='" + deviceName + "']"); + Element result = (Element) xPathExpression.evaluate( + root, XPathConstants.NODE); + return Integer.parseInt(result.getAttribute("buffer_size")); + } catch (XPathExpressionException e) { + Log.e( + "XMLHandler", + "the XPath for getting the buffer size has errors:" + + e.getMessage() + ); + } + return 0; + } + /** * reads the port information from the XML file. * @param deviceName the name of the relevant device @@ -99,7 +124,7 @@ public class XMLHandler implements IXML { } catch (XPathExpressionException e) { Log.e( "XMLHandler", - "the XPath for getting the value info has errors:" + "the XPath for getting the port info has errors:" + e.getMessage() ); } 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 00f6789..8fbcab0 100644 --- a/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java +++ b/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java @@ -22,9 +22,6 @@ public class XMLHandlerUnitTest { public void TestFiles_AreValid(){ try{ XMLHandler xmlHandler = new XMLHandler(xmlFile); - }catch(IOException | ParserConfigurationException | SAXException e){ - System.out.println("XMLHandler failed"); - assert(false); }catch(VerifyError e){ System.out.println("XML not valid"); assert(false); @@ -33,37 +30,29 @@ public class XMLHandlerUnitTest { @Test public void Test_getDeviceNames(){ - try{ XMLHandler xmlHandler = new XMLHandler(xmlFile); List deviceNames = xmlHandler.getDeviceNames(); - assertArrayEquals(new String[]{"example","sensorarray"},deviceNames.toArray()); - }catch(IOException | ParserConfigurationException | SAXException e){ - System.out.println("XMLHandler failed"); - assert(false); - } + assertArrayEquals(new String[]{"example","PWM_example","sensorarray"},deviceNames.toArray()); } @Test public void TestInput_SimplePort(){ - try{ XMLHandler xmlHandler = new XMLHandler(xmlFile); Dictionary port = xmlHandler.getPort("example"); - assertEquals("{pins=[GPIO_2], protocol=DI}",port.toString()); - }catch(IOException | ParserConfigurationException | SAXException e){ - System.out.println("XMLHandler failed"); - assert(false); - } + assertEquals("{pins=[GPIO_2], frequency=, protocol=DI}",port.toString()); } @Test public void TestInput_ComplexPort(){ - try{ XMLHandler xmlHandler = new XMLHandler(xmlFile); Dictionary port = xmlHandler.getPort("sensorarray"); - assertEquals("{pins=[GPIO_3, GPIO_4, GPIO_5, GPIO_6], protocol=DI}",port.toString()); - }catch(IOException | ParserConfigurationException | SAXException e){ - System.out.println("XMLHandler failed"); - assert(false); - } + assertEquals("{pins=[GPIO_3, GPIO_4, GPIO_5, GPIO_6], frequency=, protocol=DI}",port.toString()); + } + + @Test + public void TestInput_BufferSize(){ + XMLHandler xmlHandler = new XMLHandler(xmlFile); + int bufferSize = xmlHandler.getBufferSize("PWM_example"); + assertEquals(1000,bufferSize); } }