Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
108 lines (90 loc) · 3.07 KB
/
Copy pathMain.java
File metadata and controls
108 lines (90 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
public static boolean running = true; // Main control variable that
// determines if the scanner
// searches for values
public static boolean masterCard = false;
static Thread guiThread = new Thread(){
public void run(){
while(true){
Interface.guiUpdate();
}
}
};
public static void main( String[] args ) throws InterruptedException {
// // Connect to database
try {
Class.forName( "com.mysql.jdbc.Driver" ).newInstance( );
} catch ( Exception e ) {
e.printStackTrace( );
return;
}
// Connect to scanner and read
String command = "python RFIDTest.py";
String rfid = "";
ArrayList<String> master = new ArrayList<String>( );
// List of master card values
master.add( "88002BDE26" );
master.add( "88002AC92D" );
//Initial connect to database
Database.connect( );
Interface.guiInit( );
guiThread.start();
try {
Process p;
BufferedReader output = null;
while ( running ) {
p = Runtime.getRuntime( ).exec( command );
output = new BufferedReader( new InputStreamReader( ( p.getInputStream( ) ) ) );
while ( rfid == null || rfid.length( ) != 10 ) {
rfid = output.readLine( );
}
System.out.println( rfid );
for(int index = 0; index < master.size( ); index++){
if(master.get( index ).equals( rfid )){
masterCard = true;
break;
} else {
masterCard = false;
}
}
if ( masterCard ) {
// Do master card things
System.out.println( "Master" );
} else {
System.out.println( "Card scanned" );
database( rfid );
}
rfid = "";
if (output != null){
output.close( );
}
long t = System.currentTimeMillis( );
while(true){
if(System.currentTimeMillis( ) - 5000 > t){
break;
}
}
}
} catch ( IOException e ) {
e.printStackTrace( );
}
}
public static void database( String tag ) {
if ( Database.getInOut( tag ) ) {
Database.logOut( tag );
Interface.print( String.format( "Goodbye, %s", Database.getName( tag ) ) );
} else {
Database.logIn( tag );
Interface.print( String.format( "Welcome, %s", Database.getName( tag ) ) );
}
// try {
// Thread.sleep(5000);
// } catch ( InterruptedException e ) {
// e.printStackTrace();
// }
}
}