forked from GideonLeGrange/panstamp-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
117 lines (98 loc) · 3.46 KB
/
Copy pathExample.java
File metadata and controls
117 lines (98 loc) · 3.46 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
109
110
111
112
113
114
115
116
117
package example;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Arrays;
import me.legrange.panstamp.EndpointNotFoundException;
import me.legrange.panstamp.Network;
import me.legrange.panstamp.NetworkException;
import me.legrange.panstamp.PanStamp;
import me.legrange.panstamp.PanStampListener;
import me.legrange.panstamp.Register;
import me.legrange.panstamp.devicestore.MemoryStore;
import me.legrange.panstamp.devicestore.PersistentMemoryStore;
import me.legrange.panstamp.xml.FileLibrary;
/**
*
* @author gideon
*/
public abstract class Example {
private static final String PORT = "COM6";
private static final int BAUD = 38400;
protected Network nw;
protected abstract void doExampleCode(Network nw) throws NetworkException;
protected void run() throws NetworkException, InterruptedException, MalformedURLException {
// nw = Network.openSerial(PORT, BAUD);
// nw = Network.create(
// PORT,
// BAUD,
// new FileLibrary(new File("src/main/resources/devices")),
// new PersistentMemoryStore(new File("resources/store.db")));
nw = Network.create(
PORT,
BAUD,
new FileLibrary(new File("src/main/resources/devices")),
new MemoryStore());
nw.setDefaultListener(new PanStampListener() {
@Override
public void syncStateChange(PanStamp dev, int syncState) {
System.out.println("Cenas tolas 2");
}
@Override
public void syncRequired(PanStamp dev) {
System.out.println("Cenas tolas 3");
}
@Override
public void registerDetected(PanStamp dev, Register reg) {
if(reg.hasValue()) {
try {
System.out.println( Arrays.toString(dev.getMAC()) + " --> " + reg.getName() + " (" + reg.getId() + ")" );
} catch (NetworkException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(reg.getId() == 11)
try {
System.out.println(javax.xml.bind.DatatypeConverter.printHexBinary(reg.getEndpoint("Device UID").getValue().toString().getBytes()));
} catch (EndpointNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NetworkException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else if(reg.getId() == 12)
try {
System.out.println(reg.getEndpoint("Device Password").getValue().toString());
} catch (EndpointNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NetworkException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else if(reg.getId() == 10)
try {
System.out.println("TX --> " + dev.getTxInterval());
} catch (EndpointNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NetworkException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
System.out.println("Unkown Data");
}
@Override
public void productCodeChange(PanStamp dev, int manufacturerId, int productId) {
System.out.println("Cenas tolas");
}
});
nw.open();
// nw.setDeviceStore(new PersistentMemoryStore());
doExampleCode(nw);
Thread.sleep(100000);
nw.close();
System.exit(0);
}
}