TavernerPOS - Source Code
Clone:
git clone http://www.librarysmith.co.uk/tavernerPOS
viewgit/viewgit/inc/functions.php:49 Function create_function() is deprecated [8192]Fix Windows batch file error.
Filename
etc/tavernerpos.bat
src/com/floreantpos/config/TerminalConfig.java
src/com/floreantpos/getnetinfo/NetInfo.java
diff --git a/etc/tavernerpos.bat b/etc/tavernerpos.bat
index 7215e8c..3c37e87 100755
--- a/etc/tavernerpos.bat
+++ b/etc/tavernerpos.bat
@@ -1,3 +1,3 @@
@echo off
-java -jar java -jar ./tavernerPOS.jar
\ No newline at end of file
+java -jar ./tavernerPOS.jar
\ No newline at end of file
diff --git a/src/com/floreantpos/config/TerminalConfig.java b/src/com/floreantpos/config/TerminalConfig.java
index a083501..a4dbf49 100755
--- a/src/com/floreantpos/config/TerminalConfig.java
+++ b/src/com/floreantpos/config/TerminalConfig.java
@@ -54,7 +54,7 @@ public class TerminalConfig {
if (isAutoTerminalID()==true) {
int terminalID=NetInfo.getTerminalIDFromMACAddr();
- if (terminalID!=-1l) {
+ if (terminalID!=-1) {
return(terminalID);
}
}
diff --git a/src/com/floreantpos/getnetinfo/NetInfo.java b/src/com/floreantpos/getnetinfo/NetInfo.java
index f26f3c8..514a4c7 100755
--- a/src/com/floreantpos/getnetinfo/NetInfo.java
+++ b/src/com/floreantpos/getnetinfo/NetInfo.java
@@ -27,15 +27,42 @@ public class NetInfo {
public static String getMACAddr() {
- InetAddress ip;
try {
+ byte[] mac = null;
+ NetworkInterface network = null;
+ int c=0;
+ while((network==null) && (c<100)) {
+ System.out.print("Auto Terminal ID - Trying Network Interface: "+c+"\n");
+ network = NetworkInterface.getByIndex(c);
+ if (network != null) {
+ mac = network.getHardwareAddress();
+
+ if (mac == null) {
+ network=null;
+ c++;
+ continue;
+ }
+
+ if (network.isLoopback()) {
+ network=null;
+ c++;
+ continue;
+ }
+
+ }
+ c++;
+ }
- ip = InetAddress.getLocalHost();
-
- NetworkInterface network = NetworkInterface.getByInetAddress(ip);
-
- byte[] mac = network.getHardwareAddress();
-
+ if (network==null) {
+ System.out.print("MAC (interface) could not be determined for deriving TerminalID.\n");
+ return(null);
+ }
+
+ if (mac==null) {
+ System.out.print("MAC (hardware address) could not be determined for deriving TerminalID.\n");
+ return(null);
+ }
+
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
//sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
@@ -43,16 +70,14 @@ public class NetInfo {
}
return(sb.toString());
- } catch (UnknownHostException e) {
-
- //e.printStackTrace();
} catch (SocketException e){
//e.printStackTrace();
}
-
+
+
return(null);
}
@@ -63,7 +88,8 @@ public class NetInfo {
String terminalID = null;
if ( mac != null) {
terminalID=mac.replace("-","");
- terminalID=terminalID.substring(terminalID.length() - 10);
+ System.out.println("MAC Address: "+terminalID);
+ terminalID=terminalID.substring(terminalID.length() - 8);
} else return(-1);
return(Integer.parseInt(terminalID));
}
- Details
- Last Updated: Monday, 04 April 2016 02:04
- Hits: 39551002