This commit is contained in:
m_broelemann 2021-01-07 22:00:39 +01:00
commit 71a48796c3
5 changed files with 45 additions and 24 deletions

@ -1 +1 @@
Subproject commit 2fddb6ae3ff3247f684c89c34d0d859b7b2076bc
Subproject commit 74b98acdc7fe19ceb480b7a2d5034b4bde9c5729

View File

@ -1,6 +1,6 @@
{
"address": "192.168.1.100",
"port" : 8080,
"currentView" : "",
"currentView" : -1,
"favorites" : [ ]
}

View File

@ -17,4 +17,11 @@ public interface IXML {
* @return the value info as a Dictionary
*/
Dictionary<String, Object> 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);
}

View File

@ -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()
);
}

View File

@ -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<String> 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<String, Object> 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<String, Object> 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);
}
}