Fixes #1 with the topic "Getting started...". The network interface property in the SECCConfig.properties and EVCCConfig.properties should now be provided as an integer value (an index value) instead of a string value (such as 'lo0' or 'eth1')

This commit is contained in:
Marc Mültin 2015-06-17 18:29:53 +02:00
parent 27b186996f
commit 27992b59c9
3 changed files with 21 additions and 14 deletions

View File

@ -15,9 +15,9 @@
# Network interface # Network interface
#------------------ #------------------
# #
# The network interface (see also scope id from IPv6-address%scope_id) given as a String on which # The network interface index of the network interface on which to communicate with the EV via a
# to communicate with the EVSE # link-local IPv6 address
NetworkInterface = lo0 NetworkInterfaceIndex = 1
# Security # Security

View File

@ -15,9 +15,9 @@
# Network interface # Network interface
#------------------ #------------------
# #
# The network interface (see also scope id from IPv6-address%scope_id) given as a String on which # The network interface index of the network interface on which to communicate with the EV via a
# to communicate with the EV # link-local IPv6 address
NetworkInterface = lo0 NetworkInterfaceIndex = 1
# Supported energy transfer modes # Supported energy transfer modes

View File

@ -48,11 +48,12 @@ public final class MiscUtils {
* @return The link-local address given as a String * @return The link-local address given as a String
*/ */
public static Inet6Address getLinkLocalAddress() { public static Inet6Address getLinkLocalAddress() {
String networkInterfaceConfig = (String) MiscUtils.getPropertyValue("NetworkInterface"); int networkInterfaceConfig = (int) getPropertyValue("NetworkInterfaceIndex");
NetworkInterface nif = null; NetworkInterface nif = null;
try { try {
nif = NetworkInterface.getByName(networkInterfaceConfig); nif = NetworkInterface.getByIndex(networkInterfaceConfig);
Enumeration<InetAddress> inetAddresses = nif.getInetAddresses(); Enumeration<InetAddress> inetAddresses = nif.getInetAddresses();
while (inetAddresses.hasMoreElements()) { while (inetAddresses.hasMoreElements()) {
@ -69,7 +70,7 @@ public final class MiscUtils {
getLogger().fatal("SocketException while trying to get network interface for configured name " + getLogger().fatal("SocketException while trying to get network interface for configured name " +
networkInterfaceConfig + "'", e); networkInterfaceConfig + "'", e);
} catch (NullPointerException e2) { } catch (NullPointerException e2) {
getLogger().fatal("No network interface for configured network interface name '" + getLogger().fatal("No network interface for configured network interface index '" +
networkInterfaceConfig + "' found"); networkInterfaceConfig + "' found");
} }
@ -78,12 +79,12 @@ public final class MiscUtils {
public static byte[] getMacAddress() { public static byte[] getMacAddress() {
String networkInterfaceConfig = (String) MiscUtils.getPropertyValue("NetworkInterface"); int networkInterfaceConfig = (int) getPropertyValue("NetworkInterfaceIndex");
NetworkInterface nif = null; NetworkInterface nif = null;
byte[] macAddress = null; byte[] macAddress = null;
try { try {
nif = NetworkInterface.getByName(networkInterfaceConfig); nif = NetworkInterface.getByIndex(networkInterfaceConfig);
macAddress = nif.getHardwareAddress(); macAddress = nif.getHardwareAddress();
} catch (SocketException e) { } catch (SocketException e) {
getLogger().error("Failed to retrieve local mac address (SocketException)", e); getLogger().error("Failed to retrieve local mac address (SocketException)", e);
@ -124,8 +125,14 @@ public final class MiscUtils {
} }
switch (propertyName) { switch (propertyName) {
case "NetworkInterface": // EV + EVSE property case "NetworkInterfaceIndex": // EV + EVSE property
returnValue = propertyValue; try {
returnValue = Integer.parseInt(propertyValue);
} catch (NumberFormatException e) {
getLogger().warn("NetworkInterface index value '" + propertyValue + "' not supported. " +
"Trying index value 0", e);
returnValue = 0;
}
break; break;
case "SessionID": // EV property case "SessionID": // EV property
try { try {
@ -209,7 +216,7 @@ public final class MiscUtils {
returnValue = Boolean.parseBoolean(propertyValue); returnValue = Boolean.parseBoolean(propertyValue);
break; break;
default: default:
break; getLogger().error("No property with name '" + propertyName + "' found");
} }
return returnValue; return returnValue;