-
Notifications
You must be signed in to change notification settings - Fork 0
/
DroneDataService.java
79 lines (66 loc) · 2.48 KB
/
DroneDataService.java
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
package com.dronerecon.ws;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.URL;
import java.util.*;
import java.security.SecureRandom;
/**
*
* @author Emma Vuksich :-)
*/
public class DroneDataService extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/json;charset=utf-8");
response.addHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter();
String sArea_id = request.getParameter("area_id");
String stilex = request.getParameter("tilex");
String stiley = request.getParameter("tiley");
String stotalcols = request.getParameter("totalcols");
String stotalrows = request.getParameter("totalrows");
String sg = request.getParameter("g");
String sr = request.getParameter("r");
try
{
URL url = new URL("http://127.0.0.1:8080/dronereconportal/PortalDBService?area_id=" + sArea_id + "&tilex=" + stilex +"&tiley=" + stiley + "&r= " + sr +"&g=" + sg);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String strDrone = "";
while (null != (strDrone = br.readLine()))
{
}
} catch (Exception ex) {
ex.printStackTrace();
}
String sDirection = "right";
int tilex = Integer.parseInt(stilex);
int tiley = Integer.parseInt(stiley);
int totalcols = Integer.parseInt(stotalcols);
int totalrows = Integer.parseInt(stotalrows);
if (tiley % 2 == 0) {
if (tilex == totalcols - 1) {
tiley++;
sDirection = "left";
} else {
tilex++;
sDirection = "right";
}
} else {
if (tilex == 0) {
tiley++;
sDirection = "right";
} else {
tilex--;
sDirection = "left";
}
}
if (tiley == totalrows) {
sDirection = "stop";
}
String sReturnJson = "{\"area_id\":\"" + sArea_id + "\", \"nextTileX\":\"" + tilex + "\", \"nextTileY\":\"" + tiley + "\", \"direction\":\"" + sDirection + "\"}";
out.println(sReturnJson);
}
}