Revision 11
trunk/web/index.jsp | ||
---|---|---|
17 | 17 |
</head> |
18 | 18 |
<body class="claro"> |
19 | 19 |
<div id="wrap"> |
20 |
<h1>LIDAR Web Console</h1>
|
|
20 |
<h1>LIDAR Web Service</h1>
|
|
21 | 21 |
<hr/> |
22 | 22 |
|
23 | 23 |
<div dojoType="dijit.layout.TabContainer" style="width: 100%;" doLayout="false"> |
24 |
<div dojoType="dijit.layout.ContentPane" title="Info" href="info.jsp" selected="true" closable="true"></div>
|
|
24 |
<!--<div dojoType="dijit.layout.ContentPane" title="Info" href="info.jsp" selected="true" closable="true"></div>-->
|
|
25 | 25 |
<div dojoType="dijit.layout.ContentPane" title="Status" href="status.jsp"></div> |
26 |
<div dojoType="dojox.layout.ContentPane" title="API Key" href="apikey.jsp"></div> |
|
26 | 27 |
<div dojoType="dijit.layout.ContentPane" title="Log" href="log.json" closable="true"></div> |
27 | 28 |
</div> |
28 | 29 |
|
... | ... | |
32 | 33 |
<script type="text/javascript" src="dojo/dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script> |
33 | 34 |
<script type="text/javascript" src="dojo/dijit/dijit.js"></script> |
34 | 35 |
<script type="text/javascript" src="dojo/dijit/dijit-all.js"></script> |
36 |
<script type="text/javascript"> |
|
37 |
dojo.require('dojox.layout.ContentPane'); |
|
38 |
</script> |
|
35 | 39 |
<script type="text/javascript" src="js/main.js"></script> |
36 | 40 |
</body> |
37 | 41 |
</html> |
trunk/web/apikey.jsp | ||
---|---|---|
1 |
<%@page contentType="text/html" pageEncoding="UTF-8"%> |
|
2 |
<p>Za uporabo LIDAR naprave morate pridobiti API ključ. To lahko storite spodaj...</p> |
|
3 |
<hr/> |
|
4 |
<label for="key">API Key:</label> <input type="text" id="key" name="key" dojoType="dijit.form.TextBox" trim="true"/> |
|
5 |
<button dojoType="dijit.form.Button" type="button">Generate<script type="dojo/method" event="onClick" args="evt"> |
|
6 |
dijit.byId("key").setValue("Thank you!"); |
|
7 |
</script></button> |
trunk/web/status.jsp | ||
---|---|---|
15 | 15 |
%> |
16 | 16 |
Laser port: <strong><%= c.getString("devices.laser.port") %></strong><br/> |
17 | 17 |
Sensor port: <strong><%= c.getString("devices.sensor.port") %></strong><br/> |
18 |
Motion port: <strong><%= c.getString("devices.motion.port") %></strong><br/> |
|
18 |
Motion port: <strong><%= c.getString("devices.motion.port") %></strong><br/> |
|
19 |
<script type="text/javascript"> |
|
20 |
alert('status'); |
|
21 |
</script> |
trunk/nbproject/project.properties | ||
---|---|---|
1 | 1 |
annotation.processing.enabled=true |
2 | 2 |
annotation.processing.enabled.in.editor=true |
3 |
annotation.processing.processors.list= |
|
4 | 3 |
annotation.processing.run.all.processors=true |
5 | 4 |
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output |
6 | 5 |
build.classes.dir=${build.web.dir}/WEB-INF/classes |
trunk/src/java/org/lidar/Position.java | ||
---|---|---|
5 | 5 |
* @author Andrej Cimpersek |
6 | 6 |
*/ |
7 | 7 |
public class Position { |
8 |
|
|
8 | 9 |
public int position0; |
9 | 10 |
public int position1; |
10 | 11 |
} |
trunk/src/java/org/lidar/Config.java | ||
---|---|---|
8 | 8 |
* @author Andrej Cimpersek |
9 | 9 |
*/ |
10 | 10 |
public class Config { |
11 |
|
|
11 | 12 |
private static XMLConfiguration configuration; |
12 | 13 |
|
13 |
public static XMLConfiguration getConfiguration(){ |
|
14 |
if(configuration == null){
|
|
14 |
public static XMLConfiguration getConfiguration() {
|
|
15 |
if (configuration == null) {
|
|
15 | 16 |
try { |
16 | 17 |
configuration = new XMLConfiguration("/etc/lidar/config.xml"); |
17 | 18 |
configuration.setAutoSave(true); |
... | ... | |
23 | 24 |
return configuration; |
24 | 25 |
} |
25 | 26 |
|
26 |
public static void save(){ |
|
27 |
public static void save() {
|
|
27 | 28 |
try { |
28 | 29 |
configuration.save("/etc/lidar/config.xml"); |
29 | 30 |
} catch (Exception e) { |
trunk/src/java/org/lidar/db/AuthTokens.java | ||
---|---|---|
8 | 8 |
* @author Andrej Cimpersek |
9 | 9 |
*/ |
10 | 10 |
public class AuthTokens implements Serializable { |
11 |
|
|
11 | 12 |
private Integer id; |
12 | 13 |
private String token; |
13 | 14 |
private Date access; |
14 | 15 |
private String ip; |
15 | 16 |
|
16 |
public AuthTokens(){ |
|
17 |
public AuthTokens() {
|
|
17 | 18 |
} |
18 | 19 |
|
19 |
public AuthTokens(Integer id, String token, Date access, String ip){ |
|
20 |
public AuthTokens(Integer id, String token, Date access, String ip) {
|
|
20 | 21 |
this.id = id; |
21 | 22 |
this.token = token; |
22 | 23 |
this.access = access; |
trunk/src/java/org/lidar/db/Client.java | ||
---|---|---|
4 | 4 |
import javax.persistence.*; |
5 | 5 |
|
6 | 6 |
/** |
7 |
* |
|
7 |
* Client DB table
|
|
8 | 8 |
* @author Andrej Cimpersek |
9 | 9 |
*/ |
10 | 10 |
@Entity |
11 |
@Table(name="client")
|
|
11 |
@Table(name = "client")
|
|
12 | 12 |
public class Client implements Serializable { |
13 |
|
|
13 | 14 |
private Integer id; |
14 | 15 |
private String apiKey; |
15 | 16 |
private String token; |
17 |
private String username; |
|
16 | 18 |
|
17 |
public Client(){ |
|
19 |
public Client() {
|
|
18 | 20 |
} |
19 | 21 |
|
20 |
public Client(Integer id, String apiKey, String token){ |
|
22 |
public Client(Integer id, String apiKey, String token) {
|
|
21 | 23 |
this.id = id; |
22 | 24 |
this.apiKey = apiKey; |
23 | 25 |
this.token = token; |
24 | 26 |
} |
25 | 27 |
|
26 | 28 |
@Id |
27 |
@GeneratedValue(strategy=GenerationType.AUTO)
|
|
29 |
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
28 | 30 |
public Integer getId() { |
29 | 31 |
return this.id; |
30 | 32 |
} |
... | ... | |
33 | 35 |
this.id = id; |
34 | 36 |
} |
35 | 37 |
|
36 |
@Column(name="apikey")
|
|
38 |
@Column(name = "apikey")
|
|
37 | 39 |
public String getApiKey() { |
38 | 40 |
return this.apiKey; |
39 | 41 |
} |
... | ... | |
50 | 52 |
this.token = token; |
51 | 53 |
} |
52 | 54 |
|
55 |
public String getUsername() { |
|
56 |
return this.username; |
|
57 |
} |
|
58 |
|
|
59 |
public void setUsername(String username) { |
|
60 |
this.username = username; |
|
61 |
} |
|
53 | 62 |
} |
trunk/src/java/org/lidar/LogServlet.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this template, choose Tools | Templates |
|
3 |
* and open the template in the editor. |
|
4 |
*/ |
|
5 |
|
|
6 | 1 |
package org.lidar; |
7 | 2 |
|
8 | 3 |
import com.google.gson.Gson; |
... | ... | |
19 | 14 |
import org.lidar.HibernateUtil; |
20 | 15 |
|
21 | 16 |
/** |
22 |
* |
|
17 |
* Log Servlet
|
|
23 | 18 |
* @author Andrej Cimpersek |
24 | 19 |
*/ |
25 | 20 |
public class LogServlet extends HttpServlet { |
26 |
|
|
27 |
/**
|
|
21 |
|
|
22 |
/** |
|
28 | 23 |
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. |
29 | 24 |
* @param request servlet request |
30 | 25 |
* @param response servlet response |
... | ... | |
32 | 27 |
* @throws IOException if an I/O error occurs |
33 | 28 |
*/ |
34 | 29 |
protected void processRequest(HttpServletRequest request, HttpServletResponse response) |
35 |
throws ServletException, IOException { |
|
30 |
throws ServletException, IOException {
|
|
36 | 31 |
response.setContentType("application/json;charset=UTF-8"); |
37 | 32 |
PrintWriter out = response.getWriter(); |
38 | 33 |
Gson gson = new Gson(); |
39 | 34 |
try { |
40 | 35 |
int start = 0; |
41 | 36 |
int limit = 15; |
42 |
if(request.getParameter("limit") != null){
|
|
37 |
if (request.getParameter("limit") != null) {
|
|
43 | 38 |
limit = Integer.parseInt(request.getParameter("limit")); |
44 | 39 |
} |
45 |
if(request.getParameter("start") != null){
|
|
40 |
if (request.getParameter("start") != null) {
|
|
46 | 41 |
start = Integer.parseInt(request.getParameter("start")); |
47 | 42 |
} |
48 | 43 |
|
... | ... | |
54 | 49 |
Query query = session.createQuery("from Log as log order by log.date desc"); |
55 | 50 |
query.setFirstResult(start); |
56 | 51 |
query.setMaxResults(limit); |
57 |
JSONResponse resp = new JSONResponse(true, total, (ArrayList)query.list()); |
|
52 |
JSONResponse resp = new JSONResponse(true, total, (ArrayList) query.list());
|
|
58 | 53 |
out.write(gson.toJson(resp)); |
59 | 54 |
tx.commit(); |
60 | 55 |
} catch (Exception e) { |
... | ... | |
66 | 61 |
} |
67 | 62 |
|
68 | 63 |
class JSONResponse { |
64 |
|
|
69 | 65 |
private boolean success = true; |
70 | 66 |
private int total; |
71 | 67 |
private ArrayList rows; |
72 | 68 |
|
73 |
public JSONResponse(boolean success, int total, ArrayList rows){ |
|
69 |
public JSONResponse(boolean success, int total, ArrayList rows) {
|
|
74 | 70 |
this.success = success; |
75 | 71 |
this.total = total; |
76 | 72 |
this.rows = rows; |
... | ... | |
78 | 74 |
} |
79 | 75 |
|
80 | 76 |
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> |
81 |
/**
|
|
77 |
/** |
|
82 | 78 |
* Handles the HTTP <code>GET</code> method. |
83 | 79 |
* @param request servlet request |
84 | 80 |
* @param response servlet response |
... | ... | |
87 | 83 |
*/ |
88 | 84 |
@Override |
89 | 85 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) |
90 |
throws ServletException, IOException { |
|
86 |
throws ServletException, IOException {
|
|
91 | 87 |
processRequest(request, response); |
92 |
}
|
|
88 |
} |
|
93 | 89 |
|
94 |
/**
|
|
90 |
/** |
|
95 | 91 |
* Handles the HTTP <code>POST</code> method. |
96 | 92 |
* @param request servlet request |
97 | 93 |
* @param response servlet response |
... | ... | |
100 | 96 |
*/ |
101 | 97 |
@Override |
102 | 98 |
protected void doPost(HttpServletRequest request, HttpServletResponse response) |
103 |
throws ServletException, IOException { |
|
99 |
throws ServletException, IOException {
|
|
104 | 100 |
processRequest(request, response); |
105 | 101 |
} |
106 | 102 |
|
107 |
/**
|
|
103 |
/** |
|
108 | 104 |
* Returns a short description of the servlet. |
109 | 105 |
* @return a String containing servlet description |
110 | 106 |
*/ |
... | ... | |
112 | 108 |
public String getServletInfo() { |
113 | 109 |
return "Short description"; |
114 | 110 |
}// </editor-fold> |
115 |
|
|
116 | 111 |
} |
trunk/src/java/org/lidar/api/Management.java | ||
---|---|---|
19 | 19 |
*/ |
20 | 20 |
@WebService() |
21 | 21 |
public class Management { |
22 |
|
|
22 | 23 |
private final Object lock = new Object(); |
23 | 24 |
public static Boolean locked = false; |
24 | 25 |
public static String lockToken; |
25 | 26 |
public static Date lockAccess; |
26 |
|
|
27 | 27 |
@Resource |
28 | 28 |
private WebServiceContext wsContext; |
29 | 29 |
|
... | ... | |
31 | 31 |
* Web service operation |
32 | 32 |
*/ |
33 | 33 |
@WebMethod() |
34 |
public boolean getLockStatus(String authToken){ |
|
34 |
public boolean getLockStatus(String authToken) {
|
|
35 | 35 |
Client c = getClient(String.format("token = '%s'", authToken)); |
36 |
if(c == null) return true; |
|
37 |
|
|
36 |
if (c == null) { |
|
37 |
return true; |
|
38 |
} |
|
39 |
|
|
38 | 40 |
return Management.locked; |
39 | 41 |
} |
40 | 42 |
|
... | ... | |
43 | 45 |
* @param where |
44 | 46 |
* @return Client |
45 | 47 |
*/ |
46 |
private Client getClient(String where){ |
|
48 |
private Client getClient(String where) {
|
|
47 | 49 |
Client c = null; |
48 | 50 |
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
49 | 51 |
Transaction tx = null; |
... | ... | |
53 | 55 |
tx = session.beginTransaction(); |
54 | 56 |
|
55 | 57 |
Query query = session.createQuery(String.format("from Client as client where %s", where)); |
56 |
c = (Client)query.list().get(0); |
|
58 |
c = (Client) query.list().get(0);
|
|
57 | 59 |
tx.commit(); |
58 | 60 |
} catch (Exception e) { |
59 | 61 |
tx.rollback(); |
... | ... | |
70 | 72 |
* @return null | authentication token |
71 | 73 |
*/ |
72 | 74 |
@WebMethod() |
73 |
public String getAuthenticationToken(String api_key, String username, String password){ |
|
75 |
public String getAuthenticationToken(String api_key, String username, String password) {
|
|
74 | 76 |
String token = null; |
75 | 77 |
MessageContext mc = wsContext.getMessageContext(); |
76 | 78 |
Pam pam = new Pam(); |
77 | 79 |
boolean auth = pam.authenticateSuccessful(username, password); |
78 | 80 |
|
79 |
if(auth){
|
|
81 |
if (auth) {
|
|
80 | 82 |
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
81 | 83 |
Transaction tx = null; |
82 | 84 |
try { |
... | ... | |
84 | 86 |
// TODO: generate new auth token and save it to DB |
85 | 87 |
Client c = getClient(String.format("apikey = '%s'", api_key)); |
86 | 88 |
|
87 |
if(c != null){
|
|
89 |
if (c != null) {
|
|
88 | 90 |
token = c.getToken(); |
89 | 91 |
} |
90 | 92 |
} catch (Exception e) { |
... | ... | |
96 | 98 |
} |
97 | 99 |
|
98 | 100 |
@WebMethod() |
99 |
public String getLockToken(String authToken){ |
|
100 |
synchronized(lock){
|
|
101 |
public String getLockToken(String authToken) {
|
|
102 |
synchronized (lock) {
|
|
101 | 103 |
Client c = getClient(String.format("token = '%s'", authToken)); |
102 |
if(Management.locked || c == null) return null; |
|
104 |
if (Management.locked || c == null) { |
|
105 |
return null; |
|
106 |
} |
|
103 | 107 |
|
104 | 108 |
Management.locked = true; |
105 | 109 |
Management.lockToken = authToken; // TODO: generate token |
106 | 110 |
Management.lockAccess = new Date(); |
107 | 111 |
} |
108 |
|
|
112 |
|
|
109 | 113 |
return Management.lockToken; |
110 | 114 |
} |
111 | 115 |
|
112 | 116 |
@WebMethod |
113 |
public boolean unlock(String lockToken){ |
|
114 |
synchronized(lock){ |
|
115 |
if(!Management.locked || !Management.lockToken.equals(lockToken)) return false; |
|
117 |
public boolean unlock(String lockToken) { |
|
118 |
synchronized (lock) { |
|
119 |
if (!Management.locked || !Management.lockToken.equals(lockToken)) { |
|
120 |
return false; |
|
121 |
} |
|
116 | 122 |
Management.locked = false; |
117 | 123 |
Management.lockToken = null; |
118 | 124 |
} |
119 | 125 |
|
120 | 126 |
return true; |
121 | 127 |
} |
122 |
|
|
123 | 128 |
} |
trunk/src/java/org/lidar/api/Motion.java | ||
---|---|---|
14 | 14 |
@WebService() |
15 | 15 |
public class Motion extends Serial { |
16 | 16 |
|
17 |
public Motion(){ |
|
17 |
public Motion() {
|
|
18 | 18 |
super("motion"); |
19 | 19 |
openPort(); |
20 | 20 |
} |
... | ... | |
25 | 25 |
* @param freq |
26 | 26 |
*/ |
27 | 27 |
@WebMethod() |
28 |
public void setMove0(int steps, float freq){ |
|
29 |
|
|
30 |
} |
|
28 |
public void setMove0(int steps, float freq) { |
|
29 |
} |
|
31 | 30 |
|
32 | 31 |
/** |
33 | 32 |
* Sets parameters for next motor move |
... | ... | |
35 | 34 |
* @param freq |
36 | 35 |
*/ |
37 | 36 |
@WebMethod() |
38 |
public void setMove1(int steps, float freq){ |
|
37 |
public void setMove1(int steps, float freq) { |
|
38 |
} |
|
39 | 39 |
|
40 |
} |
|
41 |
|
|
42 | 40 |
/** |
43 | 41 |
* Moves motors according to set moves |
44 | 42 |
*/ |
45 | 43 |
@WebMethod() |
46 |
public void run(){ |
|
44 |
public void run() { |
|
45 |
} |
|
47 | 46 |
|
48 |
} |
|
49 |
|
|
50 | 47 |
/** |
51 | 48 |
* Sets angular velocity in steps / sec |
52 | 49 |
* @param omega0 |
53 | 50 |
*/ |
54 | 51 |
@WebMethod() |
55 |
public void setInitialAngularVel0(float omega0){ |
|
52 |
public void setInitialAngularVel0(float omega0) { |
|
53 |
} |
|
56 | 54 |
|
57 |
} |
|
58 |
|
|
59 | 55 |
/** |
60 | 56 |
* Sets angular velocity in steps / sec |
61 | 57 |
* @param omega0 |
62 | 58 |
*/ |
63 | 59 |
@WebMethod() |
64 |
public void setInitialAngularVel1(float omega0){ |
|
60 |
public void setInitialAngularVel1(float omega0) { |
|
61 |
} |
|
65 | 62 |
|
66 |
} |
|
67 |
|
|
68 | 63 |
/** |
69 | 64 |
* Sets angular acceleration in steps / sec^2 |
70 | 65 |
* @param accel |
71 | 66 |
*/ |
72 | 67 |
@WebMethod() |
73 |
public void setAngularAcceleration0(float accel){ |
|
68 |
public void setAngularAcceleration0(float accel) { |
|
69 |
} |
|
74 | 70 |
|
75 |
} |
|
76 |
|
|
77 | 71 |
/** |
78 | 72 |
* Sets angular acceleration in steps / sec^2 |
79 | 73 |
* @param accel |
80 | 74 |
*/ |
81 | 75 |
@WebMethod() |
82 |
public void setAngularAcceleration1(float accel){ |
|
76 |
public void setAngularAcceleration1(float accel) { |
|
77 |
} |
|
83 | 78 |
|
84 |
} |
|
85 |
|
|
86 | 79 |
/** |
87 | 80 |
* |
88 | 81 |
* @param steps |
89 | 82 |
*/ |
90 | 83 |
@WebMethod() |
91 |
public void setLackCorrection0(short steps){ |
|
84 |
public void setLackCorrection0(short steps) { |
|
85 |
} |
|
92 | 86 |
|
93 |
} |
|
94 |
|
|
95 | 87 |
/** |
96 | 88 |
* |
97 | 89 |
* @param steps |
98 | 90 |
*/ |
99 | 91 |
@WebMethod() |
100 |
public void setLackCorrection1(short steps){ |
|
92 |
public void setLackCorrection1(short steps) { |
|
93 |
} |
|
101 | 94 |
|
102 |
} |
|
103 |
|
|
104 | 95 |
/** |
105 | 96 |
* Sets angular deceleration in steps / sec^2 |
106 | 97 |
* @param decel |
107 | 98 |
*/ |
108 | 99 |
@WebMethod() |
109 |
public void setAngularDeceleration0(float decel){ |
|
100 |
public void setAngularDeceleration0(float decel) { |
|
101 |
} |
|
110 | 102 |
|
111 |
} |
|
112 |
|
|
113 | 103 |
/** |
114 | 104 |
* Sets angular deceleration in steps / sec^2 |
115 | 105 |
* @param decel |
116 | 106 |
*/ |
117 | 107 |
@WebMethod() |
118 |
public void setAngularDeceleration1(float decel){ |
|
108 |
public void setAngularDeceleration1(float decel) { |
|
109 |
} |
|
119 | 110 |
|
120 |
} |
|
121 |
|
|
122 | 111 |
/** |
123 | 112 |
* Sets position for stepper 0 |
124 | 113 |
* @param position |
125 | 114 |
*/ |
126 | 115 |
@WebMethod() |
127 |
public void setPosition0(int position){ |
|
116 |
public void setPosition0(int position) { |
|
117 |
} |
|
128 | 118 |
|
129 |
} |
|
130 |
|
|
131 | 119 |
/** |
132 | 120 |
* Sets position for stepper 1 |
133 | 121 |
* @param position |
134 | 122 |
*/ |
135 | 123 |
@WebMethod() |
136 |
public void setPosition1(int position){ |
|
124 |
public void setPosition1(int position) { |
|
125 |
} |
|
137 | 126 |
|
138 |
} |
|
139 |
|
|
140 | 127 |
/** |
141 | 128 |
* Stops motor 0 |
142 | 129 |
*/ |
143 | 130 |
@WebMethod() |
144 |
public void stopMotor0(){ |
|
131 |
public void stopMotor0() { |
|
132 |
} |
|
145 | 133 |
|
146 |
} |
|
147 |
|
|
148 | 134 |
/** |
149 | 135 |
* Stops motor 1 |
150 | 136 |
*/ |
151 | 137 |
@WebMethod() |
152 |
public void stopMotor1(){ |
|
138 |
public void stopMotor1() { |
|
139 |
} |
|
153 | 140 |
|
154 |
} |
|
155 |
|
|
156 | 141 |
/** |
157 | 142 |
* Disables current on motor 0 |
158 | 143 |
*/ |
159 | 144 |
@WebMethod() |
160 |
public void setMotorOff0(){ |
|
145 |
public void setMotorOff0() { |
|
146 |
} |
|
161 | 147 |
|
162 |
} |
|
163 |
|
|
164 | 148 |
/** |
165 | 149 |
* Disables current on motor 1 |
166 | 150 |
*/ |
167 | 151 |
@WebMethod() |
168 |
public void setMotorOff1(){ |
|
152 |
public void setMotorOff1() { |
|
153 |
} |
|
169 | 154 |
|
170 |
} |
|
171 |
|
|
172 | 155 |
/** |
173 | 156 |
* Gets positions of both motors |
174 | 157 |
* @return Position |
175 | 158 |
*/ |
176 | 159 |
@WebMethod() |
177 |
public Position getPosition(){ |
|
160 |
public Position getPosition() {
|
|
178 | 161 |
return new Position(); |
179 |
}
|
|
162 |
}
|
|
180 | 163 |
|
181 | 164 |
/** |
182 | 165 |
* Set continuous key movement |
183 | 166 |
*/ |
184 | 167 |
@WebMethod() |
185 |
public void setContinuousKeyMovement(){ |
|
168 |
public void setContinuousKeyMovement() { |
|
169 |
} |
|
186 | 170 |
|
187 |
} |
|
188 |
|
|
189 | 171 |
/** |
190 | 172 |
* Set single step key movement |
191 | 173 |
*/ |
192 | 174 |
@WebMethod() |
193 |
public void setSingleStepKeyMovement(){ |
|
175 |
public void setSingleStepKeyMovement() { |
|
176 |
} |
|
194 | 177 |
|
195 |
} |
|
196 |
|
|
197 | 178 |
/** |
198 | 179 |
* Simulate Left Key Press |
199 | 180 |
*/ |
200 | 181 |
@WebMethod() |
201 |
public void simulateLeftKeyPress(){ |
|
182 |
public void simulateLeftKeyPress() { |
|
183 |
} |
|
202 | 184 |
|
203 |
} |
|
204 |
|
|
205 | 185 |
/** |
206 | 186 |
* Simulate Left Key Release |
207 | 187 |
*/ |
208 | 188 |
@WebMethod() |
209 |
public void simulateLeftKeyRelease(){ |
|
189 |
public void simulateLeftKeyRelease() { |
|
190 |
} |
|
210 | 191 |
|
211 |
} |
|
212 |
|
|
213 | 192 |
/** |
214 | 193 |
* Simulate Right Key Press |
215 | 194 |
*/ |
216 | 195 |
@WebMethod() |
217 |
public void simulateRightKeyPress(){ |
|
196 |
public void simulateRightKeyPress() { |
|
197 |
} |
|
218 | 198 |
|
219 |
} |
|
220 |
|
|
221 | 199 |
/** |
222 | 200 |
* Simulate Right Key Release |
223 | 201 |
*/ |
224 | 202 |
@WebMethod() |
225 |
public void simulateRightKeyRelease(){ |
|
203 |
public void simulateRightKeyRelease() { |
|
204 |
} |
|
226 | 205 |
|
227 |
} |
|
228 |
|
|
229 | 206 |
/** |
230 | 207 |
* Simulate Up Key Press |
231 | 208 |
*/ |
232 | 209 |
@WebMethod() |
233 |
public void simulateUpKeyPress(){ |
|
210 |
public void simulateUpKeyPress() { |
|
211 |
} |
|
234 | 212 |
|
235 |
} |
|
236 |
|
|
237 | 213 |
/** |
238 | 214 |
* Simulate Up Key Release |
239 | 215 |
*/ |
240 | 216 |
@WebMethod() |
241 |
public void simulateUpKeyRelease(){ |
|
217 |
public void simulateUpKeyRelease() { |
|
218 |
} |
|
242 | 219 |
|
243 |
} |
|
244 |
|
|
245 | 220 |
/** |
246 | 221 |
* Simulate Down Key Press |
247 | 222 |
*/ |
248 | 223 |
@WebMethod() |
249 |
public void simulateDownKeyPress(){ |
|
224 |
public void simulateDownKeyPress() { |
|
225 |
} |
|
250 | 226 |
|
251 |
} |
|
252 |
|
|
253 | 227 |
/** |
254 | 228 |
* Simulate Down Key Release |
255 | 229 |
*/ |
256 | 230 |
@WebMethod() |
257 |
public void simulateDownKeyRelease(){ |
|
231 |
public void simulateDownKeyRelease() { |
|
232 |
} |
|
258 | 233 |
|
259 |
} |
|
260 |
|
|
261 | 234 |
/** |
262 | 235 |
* Sets automatic position reporting. |
263 | 236 |
* 0..turns off automatic position reporting, 50..9999 autoreport interval in milliseconds |
264 | 237 |
* @param interval |
265 | 238 |
*/ |
266 | 239 |
@WebMethod() |
267 |
public void setAutomaticPositionReporting(short interval){ |
|
268 |
|
|
269 |
} |
|
240 |
public void setAutomaticPositionReporting(short interval) { |
|
241 |
} |
|
270 | 242 |
} |
trunk/src/java/org/lidar/api/Laser.java | ||
---|---|---|
13 | 13 |
*/ |
14 | 14 |
@WebService() |
15 | 15 |
public class Laser extends Serial { |
16 |
public Laser(){ |
|
16 |
|
|
17 |
public Laser() { |
|
17 | 18 |
super("laser"); |
18 | 19 |
openPort(); |
19 | 20 |
} |
... | ... | |
22 | 23 |
* Vkljuci laser, ki zacne delovati v skladu z nastavljenimi parametri. |
23 | 24 |
*/ |
24 | 25 |
@WebMethod() |
25 |
public boolean fire(String lockToken){ |
|
26 |
public boolean fire(String lockToken) {
|
|
26 | 27 |
return sendCommand(lockToken, "$FIRE 01\r"); |
27 | 28 |
} |
28 | 29 |
|
... | ... | |
30 | 31 |
* Izkljuci laser. |
31 | 32 |
*/ |
32 | 33 |
@WebMethod() |
33 |
public boolean stop(String lockToken){ |
|
34 |
public boolean stop(String lockToken) {
|
|
34 | 35 |
return sendCommand(lockToken, "$STOP 00\r"); |
35 |
}
|
|
36 |
}
|
|
36 | 37 |
|
37 | 38 |
/** |
38 | 39 |
* Shrani trenutno konfiguracijo parametrov v interni pomnilnik laserja, ki se bodo nalozili ob naslednjem zagonu napajanja. |
39 | 40 |
*/ |
40 | 41 |
@WebMethod() |
41 |
public boolean saveConfig(String lockToken){ |
|
42 |
public boolean saveConfig(String lockToken) {
|
|
42 | 43 |
return sendCommand(lockToken, "$SAVE 01\r"); |
43 |
}
|
|
44 |
}
|
|
44 | 45 |
|
45 | 46 |
/** |
46 | 47 |
* Mnozica vseh nacinov delovanja laserja. |
47 | 48 |
*/ |
48 |
public enum LaserMode { Continuous, Burst, ExternalTrigger};
|
|
49 |
public enum LaserMode { |
|
49 | 50 |
|
51 |
Continuous, Burst, ExternalTrigger |
|
52 |
}; |
|
53 |
|
|
50 | 54 |
/** |
51 | 55 |
* Izbere nacin delovanja laserja. Nacini mode so nasteti v mnozici LaserMode. |
52 | 56 |
* @param mode Nacin delovanja laserja. |
53 | 57 |
*/ |
54 | 58 |
@WebMethod() |
55 |
public boolean setMode(String lockToken, LaserMode mode){ |
|
56 |
switch(mode){
|
|
59 |
public boolean setMode(String lockToken, LaserMode mode) {
|
|
60 |
switch (mode) {
|
|
57 | 61 |
case Continuous: |
58 | 62 |
return sendCommand(lockToken, "$MODE 01\r"); |
59 | 63 |
case Burst: |
... | ... | |
63 | 67 |
} |
64 | 68 |
|
65 | 69 |
return false; |
66 |
}
|
|
70 |
}
|
|
67 | 71 |
|
68 | 72 |
/** |
69 | 73 |
* Omogoci oz. onemogoci Q-Switch opcijo. |
70 | 74 |
* @param enabled Omogoci oz. onemogoci.. |
71 | 75 |
*/ |
72 | 76 |
@WebMethod() |
73 |
public boolean setQSwitch(String lockToken, boolean enabled){ |
|
74 |
if(enabled){
|
|
77 |
public boolean setQSwitch(String lockToken, boolean enabled) {
|
|
78 |
if (enabled) {
|
|
75 | 79 |
return sendCommand(lockToken, "$QSWITCH 01\r"); |
76 | 80 |
} else { |
77 | 81 |
return sendCommand(lockToken, "$QSWITCH 00\r"); |
78 | 82 |
} |
79 |
}
|
|
83 |
}
|
|
80 | 84 |
|
81 | 85 |
/** |
82 | 86 |
* Zaklene oz. odklene tipkovnico na napajalniku laserja. |
83 | 87 |
* @param locked Zaklep oz. odklep. |
84 | 88 |
*/ |
85 | 89 |
@WebMethod() |
86 |
public boolean setKeypad(String lockToken, boolean enabled){ |
|
87 |
if(enabled){
|
|
90 |
public boolean setKeypad(String lockToken, boolean enabled) {
|
|
91 |
if (enabled) {
|
|
88 | 92 |
return sendCommand(lockToken, "$KEYPAD 01\r"); |
89 | 93 |
} else { |
90 | 94 |
return sendCommand(lockToken, "$KEYPAD 00\r"); |
91 | 95 |
} |
92 |
}
|
|
96 |
}
|
|
93 | 97 |
|
94 | 98 |
/** |
95 | 99 |
* Nastavi stevilo sunkov laserja, pulses, ki se bodo zaporedoma izbvrsili, ce je izbran nacin delovanje LaserMode.Continuous. |
... | ... | |
97 | 101 |
* @param pulses Stevilo sunkov laserja. |
98 | 102 |
*/ |
99 | 103 |
@WebMethod() |
100 |
public boolean setBurstPulseCount(String lockToken, byte pulses){ |
|
101 |
if(pulses < 0 && pulses > 99){
|
|
104 |
public boolean setBurstPulseCount(String lockToken, byte pulses) {
|
|
105 |
if (pulses < 0 && pulses > 99) {
|
|
102 | 106 |
return false; |
103 | 107 |
} |
104 | 108 |
|
105 | 109 |
String p = "" + pulses; |
106 |
if (p.length() == 1) p = "0" + p; |
|
110 |
if (p.length() == 1) { |
|
111 |
p = "0" + p; |
|
112 |
} |
|
107 | 113 |
|
108 | 114 |
return sendCommand(lockToken, "$BURST " + p + "\r"); |
109 |
}
|
|
115 |
}
|
|
110 | 116 |
|
111 | 117 |
/** |
112 | 118 |
* Zazene Q-Switch na vsakih freq sunkov. |
... | ... | |
114 | 120 |
* @param freq Frekvenca sunkov. |
115 | 121 |
*/ |
116 | 122 |
@WebMethod() |
117 |
public boolean setQSwitchFrequency(String lockToken, byte freq){ |
|
118 |
if(freq < 0 && freq > 99){
|
|
123 |
public boolean setQSwitchFrequency(String lockToken, byte freq) {
|
|
124 |
if (freq < 0 && freq > 99) {
|
|
119 | 125 |
return false; |
120 | 126 |
} |
121 | 127 |
|
122 | 128 |
String f = "" + freq; |
123 |
if (f.length() == 1) f = "0" + f; |
|
129 |
if (f.length() == 1) { |
|
130 |
f = "0" + f; |
|
131 |
} |
|
124 | 132 |
|
125 | 133 |
return sendCommand(lockToken, "$QFREQ " + f + "\r"); |
126 |
}
|
|
134 |
}
|
|
127 | 135 |
|
128 | 136 |
/** |
129 | 137 |
* Zakasnitev aktivacije v stevilu sunkov delay. |
130 | 138 |
* Dovoljeno obmocje je od 0 - 99. |
131 | 139 |
* @param delay Zakasnitev aktivacije. |
132 | 140 |
*/ |
133 |
public boolean setQSwitchDelay(String lockToken, byte delay){ |
|
134 |
if(delay < 0 && delay > 99){
|
|
141 |
public boolean setQSwitchDelay(String lockToken, byte delay) {
|
|
142 |
if (delay < 0 && delay > 99) {
|
|
135 | 143 |
return false; |
136 | 144 |
} |
137 | 145 |
|
138 | 146 |
String d = "" + delay; |
139 |
if (d.length() == 1) d = "0" + d; |
|
147 |
if (d.length() == 1) { |
|
148 |
d = "0" + d; |
|
149 |
} |
|
140 | 150 |
|
141 | 151 |
return sendCommand(lockToken, "$QDLY " + d + "\r"); |
142 |
}
|
|
152 |
}
|
|
143 | 153 |
|
144 | 154 |
/** |
145 | 155 |
* Nastavi energijo laserja, eneryLevel, pri posameznem sunku aktivcaije. |
146 | 156 |
* @param energyLevel Energija laserja. |
147 | 157 |
*/ |
148 | 158 |
@WebMethod() |
149 |
public boolean setEnergyLevel(String lockToken, byte energyLevel){ |
|
150 |
if(energyLevel < 1 && energyLevel > 20){
|
|
159 |
public boolean setEnergyLevel(String lockToken, byte energyLevel) {
|
|
160 |
if (energyLevel < 1 && energyLevel > 20) {
|
|
151 | 161 |
return false; |
152 | 162 |
} |
153 | 163 |
|
154 | 164 |
String e = "" + energyLevel; |
155 |
if (e.length() == 1) e = "0" + e; |
|
156 |
|
|
165 |
if (e.length() == 1) { |
|
166 |
e = "0" + e; |
|
167 |
} |
|
168 |
|
|
157 | 169 |
return sendCommand(lockToken, "$EPFN " + e + "\r"); |
158 |
}
|
|
170 |
}
|
|
159 | 171 |
|
160 | 172 |
/** |
161 | 173 |
* Nastavi frekvenco, s katero naj se prozi lase po aktivaciji. Frekvenca je izrazena v sunkih na sekundo, rate. |
... | ... | |
163 | 175 |
* @param rate Frekvenca s katero se prozi laser. |
164 | 176 |
*/ |
165 | 177 |
@WebMethod() |
166 |
public boolean setRepetitionRate(String lockToken, byte rate){ |
|
167 |
if (rate == 1 || rate == 2 || rate == 5 || rate == 10 || rate == 20){ |
|
178 |
public boolean setRepetitionRate(String lockToken, byte rate) {
|
|
179 |
if (rate == 1 || rate == 2 || rate == 5 || rate == 10 || rate == 20) {
|
|
168 | 180 |
String r = "" + rate; |
169 |
if (r.length() == 1) r = "0" + r; |
|
181 |
if (r.length() == 1) { |
|
182 |
r = "0" + r; |
|
183 |
} |
|
170 | 184 |
|
171 | 185 |
return sendCommand(lockToken, "$LPRF " + r + "\r"); |
172 | 186 |
} |
173 | 187 |
|
174 | 188 |
return false; |
175 |
}
|
|
189 |
}
|
|
176 | 190 |
} |
trunk/src/java/org/lidar/api/Video.java | ||
---|---|---|
11 | 11 |
*/ |
12 | 12 |
@WebService() |
13 | 13 |
public class Video { |
14 |
|
|
14 | 15 |
/** |
15 | 16 |
* Returns image |
16 | 17 |
* @return byte[] PNG image |
17 | 18 |
*/ |
18 | 19 |
@WebMethod() |
19 |
public byte[] getImage(String lockToken){ |
|
20 |
public byte[] getImage(String lockToken) {
|
|
20 | 21 |
try { |
21 | 22 |
return Util.GetBytesFromFile(new File("capture.png")); |
22 | 23 |
} catch (Exception e) { |
23 | 24 |
return null; |
24 | 25 |
} |
25 | 26 |
} |
26 |
} |
|
27 |
} |
trunk/src/java/org/lidar/api/Sensor.java | ||
---|---|---|
13 | 13 |
@WebService() |
14 | 14 |
public class Sensor extends Serial { |
15 | 15 |
|
16 |
public Sensor(){ |
|
16 |
public Sensor() {
|
|
17 | 17 |
super("sensor"); |
18 | 18 |
openPort(); |
19 | 19 |
} |
... | ... | |
22 | 22 |
* Kaj natancno naredi ukaz ni znano. Pred zajemom podatkov ga je potrebno izvesti. |
23 | 23 |
* TODO: odstranit oz. samodejen klic pred zajemom podatkov. |
24 | 24 |
*/ |
25 |
private void readQuery(){ |
|
25 |
private void readQuery() { |
|
26 |
} |
|
26 | 27 |
|
27 |
} |
|
28 |
|
|
29 | 28 |
/** |
30 | 29 |
* Pripravi senzor na zajemanje podatkov. Ob naslednjih prozenjih laserja bodo meritve dostopne preko lastnosti ReceivedMeasurement. |
31 | 30 |
* TODO: drugačen dostop do podatkov |
32 | 31 |
*/ |
33 | 32 |
@WebMethod() |
34 |
public void runAcqusition(){ |
|
33 |
public void runAcqusition() {
|
|
35 | 34 |
// TODO: preveri ce je ok |
36 | 35 |
readQuery(); |
37 |
}
|
|
36 |
}
|
|
38 | 37 |
|
39 | 38 |
/** |
40 | 39 |
* Ustavi zajemanje podatkov ob prozenju laserja. Z drugimi besadami, ob naslednjih sprozitvah laserja ne bomo dobili podatkov meritev. |
41 | 40 |
*/ |
42 | 41 |
@WebMethod() |
43 |
public void stopAcqusition(){ |
|
42 |
public void stopAcqusition() { |
|
43 |
} |
|
44 | 44 |
|
45 |
} |
|
46 |
|
|
47 | 45 |
/** |
48 | 46 |
* Podobno kot RunAcqusition, natancnejsi podatki zal niso znani. |
49 | 47 |
*/ |
50 | 48 |
@WebMethod() |
51 |
public void forceTrigger(){ |
|
49 |
public void forceTrigger() { |
|
50 |
} |
|
52 | 51 |
|
53 |
} |
|
54 |
|
|
55 | 52 |
/** |
56 | 53 |
* Mnozica doloca vse mozne tipe meritev. |
57 | 54 |
*/ |
58 |
public enum DataType { Data, Background, DataMinusBackground }
|
|
55 |
public enum DataType { |
|
59 | 56 |
|
57 |
Data, Background, DataMinusBackground |
|
58 |
} |
|
59 |
|
|
60 | 60 |
/** |
61 | 61 |
* Nastavi tip type meritve. |
62 | 62 |
* @param type Tip meritve. |
63 | 63 |
*/ |
64 | 64 |
@WebMethod() |
65 |
public void setDataType(DataType type){ |
|
65 |
public void setDataType(DataType type) { |
|
66 |
} |
|
66 | 67 |
|
67 |
} |
|
68 |
|
|
69 | 68 |
/** |
70 | 69 |
* Vrne status senzurja, predstavljen v enem byte-u. |
71 | 70 |
* @return byte Status senzorja. |
72 | 71 |
*/ |
73 | 72 |
@WebMethod() |
74 |
public byte getStatus(){ |
|
75 |
return (byte)'0'; |
|
76 |
}
|
|
73 |
public byte getStatus() {
|
|
74 |
return (byte) '0';
|
|
75 |
}
|
|
77 | 76 |
|
78 | 77 |
/** |
79 | 78 |
* Poslje gain profil gainData v senzor. |
80 | 79 |
* @param gainData Gain profil. |
81 | 80 |
*/ |
82 | 81 |
@WebMethod() |
83 |
public void sendGain(short[] gainData){ |
|
84 |
|
|
85 |
} |
|
86 |
|
|
82 |
public void sendGain(short[] gainData) { |
|
83 |
} |
|
87 | 84 |
} |
trunk/src/java/org/lidar/Util.java | ||
---|---|---|
10 | 10 |
* @author Andrej Cimpersek |
11 | 11 |
*/ |
12 | 12 |
public class Util { |
13 |
public static byte CalcXOR(byte[] data, int offset, int count) |
|
14 |
{ |
|
13 |
|
|
14 |
public static byte CalcXOR(byte[] data, int offset, int count) {
|
|
15 | 15 |
byte x = data[offset]; |
16 |
for (int i = 1; i < count; i++) x ^= data[offset + i]; |
|
16 |
for (int i = 1; i < count; i++) { |
|
17 |
x ^= data[offset + i]; |
|
18 |
} |
|
17 | 19 |
return x; |
18 | 20 |
} |
19 | 21 |
|
20 |
private static byte CalcXOR(String data) |
|
21 |
{ |
|
22 |
byte x = (byte)(data.charAt(0)); |
|
23 |
for (int i = 1; i < data.length(); i++) x ^= (byte)(data.charAt(i)); |
|
22 |
private static byte CalcXOR(String data) { |
|
23 |
byte x = (byte) (data.charAt(0)); |
|
24 |
for (int i = 1; i < data.length(); i++) { |
|
25 |
x ^= (byte) (data.charAt(i)); |
|
26 |
} |
|
24 | 27 |
return x; |
25 | 28 |
} |
26 | 29 |
|
... | ... | |
35 | 38 |
} |
36 | 39 |
|
37 | 40 |
// Create the byte array to hold the data |
38 |
byte[] bytes = new byte[(int)length]; |
|
41 |
byte[] bytes = new byte[(int) length];
|
|
39 | 42 |
|
40 | 43 |
// Read in the bytes |
41 | 44 |
int offset = 0; |
42 | 45 |
int numRead = 0; |
43 | 46 |
while (offset < bytes.length |
44 |
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
|
|
47 |
&& (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
|
|
45 | 48 |
offset += numRead; |
46 | 49 |
} |
47 | 50 |
|
48 | 51 |
// Ensure all the bytes have been read in |
49 | 52 |
if (offset < bytes.length) { |
50 |
throw new IOException("Could not completely read file "+file.getName());
|
|
53 |
throw new IOException("Could not completely read file " + file.getName());
|
|
51 | 54 |
} |
52 | 55 |
|
53 | 56 |
// Close the input stream and return bytes |
trunk/src/java/org/lidar/HibernateUtil.java | ||
---|---|---|
7 | 7 |
* |
8 | 8 |
* @author Andrej Cimpersek |
9 | 9 |
*/ |
10 |
public class HibernateUtil { |
|
10 | 11 |
|
11 |
public class HibernateUtil { |
|
12 |
private static final SessionFactory sessionFactory; |
|
13 |
static { |
|
14 |
try { |
|
15 |
// Create the SessionFactory from hibernate.cfg.xml |
|
16 |
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); |
|
17 |
} catch (Throwable ex) { |
|
18 |
// Make sure you log the exception, as it might be swallowed |
|
19 |
System.err.println("Initial SessionFactory creation failed." + ex); |
|
20 |
throw new ExceptionInInitializerError(ex); |
|
12 |
private static final SessionFactory sessionFactory; |
|
13 |
|
|
14 |
static { |
|
15 |
try { |
|
16 |
// Create the SessionFactory from hibernate.cfg.xml |
|
17 |
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); |
|
18 |
} catch (Throwable ex) { |
|
19 |
// Make sure you log the exception, as it might be swallowed |
|
20 |
System.err.println("Initial SessionFactory creation failed." + ex); |
|
21 |
throw new ExceptionInInitializerError(ex); |
|
22 |
} |
|
21 | 23 |
} |
22 |
} |
|
23 | 24 |
|
24 |
public static SessionFactory getSessionFactory() { |
|
25 |
return sessionFactory; |
|
26 |
} |
|
27 |
} |
|
25 |
public static SessionFactory getSessionFactory() { |
|
26 |
return sessionFactory; |
|
27 |
} |
|
28 |
} |
trunk/src/java/org/lidar/Serial.java | ||
---|---|---|
12 | 12 |
* @author Andrej Cimpersek |
13 | 13 |
*/ |
14 | 14 |
public class Serial { |
15 |
|
|
15 | 16 |
private boolean isOpened = false; |
16 | 17 |
private String deviceName; |
17 | 18 |
private String portName; |
... | ... | |
22 | 23 |
protected OutputStream outputStream; |
23 | 24 |
private int baudRate, dataBits, stopBits, parity; |
24 | 25 |
private XMLConfiguration configuration; |
25 |
|
|
26 |
public Serial(String deviceName){ |
|
26 |
|
|
27 |
public Serial(String deviceName) {
|
|
27 | 28 |
configuration = Config.getConfiguration(); |
28 | 29 |
this.portName = configuration.getString(String.format("devices.%s.port", deviceName)); |
29 | 30 |
this.baudRate = configuration.getInt(String.format("devices.%s.baudRate", deviceName)); |
... | ... | |
38 | 39 |
* (b) matches the desired name. |
39 | 40 |
* @return boolean |
40 | 41 |
*/ |
41 |
protected boolean identfy(){ |
|
42 |
protected boolean identfy() {
|
|
42 | 43 |
this.portIdentifiers = CommPortIdentifier.getPortIdentifiers(); |
43 | 44 |
this.portId = null; // will be set if port found |
44 |
while (portIdentifiers.hasMoreElements()) |
|
45 |
{ |
|
46 |
CommPortIdentifier pid = (CommPortIdentifier)portIdentifiers.nextElement(); |
|
47 |
if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL && pid.getName().equals(this.portName)){ |
|
45 |
while (portIdentifiers.hasMoreElements()) { |
|
46 |
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement(); |
|
47 |
if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL && pid.getName().equals(this.portName)) { |
|
48 | 48 |
this.portId = pid; |
49 | 49 |
return true; |
50 | 50 |
} |
... | ... | |
56 | 56 |
* Destructor - close port |
57 | 57 |
*/ |
58 | 58 |
@Override() |
59 |
protected void finalize() throws Throwable{ |
|
59 |
protected void finalize() throws Throwable {
|
|
60 | 60 |
closePort(); |
61 | 61 |
} |
62 | 62 |
|
63 |
public boolean acquirePort(){ |
|
64 |
if(this.portId == null) return false; |
|
63 |
public boolean acquirePort() { |
|
64 |
if (this.portId == null) { |
|
65 |
return false; |
|
66 |
} |
|
65 | 67 |
// Use port identifier for acquiring the port |
66 | 68 |
try { |
67 |
this.port = (SerialPort)this.portId.open( |
|
68 |
this.deviceName, // Name of the application asking for the port |
|
69 |
10000 // Wait max. 10 sec. to acquire port
|
|
70 |
); |
|
71 |
} catch(PortInUseException e) { |
|
69 |
this.port = (SerialPort) this.portId.open(
|
|
70 |
this.deviceName, // Name of the application asking for the port
|
|
71 |
10000 // Wait max. 10 sec. to acquire port
|
|
72 |
);
|
|
73 |
} catch (PortInUseException e) {
|
|
72 | 74 |
return false; |
73 | 75 |
} |
74 | 76 |
|
75 | 77 |
return true; |
76 | 78 |
} |
77 | 79 |
|
78 |
public boolean openPort(){ |
|
79 |
if(!acquirePort()) return false; |
|
80 |
public boolean openPort() { |
|
81 |
if (!acquirePort()) { |
|
82 |
return false; |
|
83 |
} |
|
80 | 84 |
closePort(); |
81 | 85 |
try { |
82 | 86 |
this.port.setSerialPortParams(this.baudRate, this.dataBits, this.stopBits, this.parity); |
83 | 87 |
this.port.removeEventListener(); |
84 | 88 |
this.port.addEventListener(new SerialPortEventListener() { |
85 |
public void serialEvent(SerialPortEvent event){ |
|
86 |
switch(event.getEventType()) { |
|
89 |
|
|
90 |
public void serialEvent(SerialPortEvent event) { |
|
91 |
switch (event.getEventType()) { |
|
87 | 92 |
case SerialPortEvent.OUTPUT_BUFFER_EMPTY: |
88 | 93 |
onOutputBufferEmpty(event); |
89 | 94 |
break; |
... | ... | |
104 | 109 |
} |
105 | 110 |
} |
106 | 111 |
|
107 |
public void closePort(){ |
|
108 |
if(this.port == null) return; |
|
112 |
public void closePort() { |
|
113 |
if (this.port == null) { |
|
114 |
return; |
|
115 |
} |
|
109 | 116 |
try { |
110 | 117 |
this.inputStream.close(); |
111 | 118 |
this.outputStream.close(); |
... | ... | |
119 | 126 |
/** |
120 | 127 |
* Write shortcut for string |
121 | 128 |
*/ |
122 |
public boolean sendCommand(String lockToken, String string){ |
|
129 |
public boolean sendCommand(String lockToken, String string) {
|
|
123 | 130 |
return sendCommand(lockToken, string.getBytes()); |
124 | 131 |
} |
125 | 132 |
|
... | ... | |
128 | 135 |
* @param bytes |
129 | 136 |
* @return boolean |
130 | 137 |
*/ |
Also available in: Unified diff