<module>
package com.smhrd.module;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.smhrd.dao.moduleDAO;
import com.smhrd.domain.moduleVO;
@WebServlet("/module")
public class module extends HttpServlet {
public static String hel_number_gps ="";
public static String hel_number_shock ="";
public static int press = 0;
public static String gps_lat= "";
public static String gps_long = "";
public static int shock= 0;
moduleDAO dao = new moduleDAO();
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//자이로
if(request.getParameter("shock") != null) {
shock = Integer.parseInt(request.getParameter("shock"));
hel_number_shock = request.getParameter("helmetNum1");
System.out.println("shock:"+shock);
System.out.println("helmetNum1:"+hel_number_shock);
}
// GPS 위도
if(request.getParameter("gps_lat") != null&&request.getParameter("gps_long") != null) {
gps_lat = request.getParameter("gps_lat");
gps_long = request.getParameter("gps_long");
System.out.println("gps,압력 wifi 연결중");
if(!gps_lat.equals("")&&!gps_long.equals("")) {
System.out.println("gps_lat:"+gps_lat);
System.out.println("gps_long:"+gps_long);
hel_number_gps = request.getParameter("helmetNum");
moduleVO gps_vo = new moduleVO(hel_number_gps,gps_lat,gps_long);
dao.updateGPS(gps_vo);
System.out.println(" GPS DB저장 완료");
}
}
// 압력 센서
if(request.getParameter("press") != null) {
press = Integer.parseInt(request.getParameter("press"));
System.out.println("press: " +press);
}
}
}
<moduleController>
package com.smhrd.module;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.smhrd.dao.moduleDAO;
import com.smhrd.domain.moduleVO;
@SuppressWarnings("serial")
@WebServlet("/moduleController")
public class moduleController extends HttpServlet {
public static int motor = 0;
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
motor = Integer.parseInt(request.getParameter("motor"));
String hel_number = module.hel_number_gps;
int magnetic = returnMotor.magnetic;
moduleDAO dao = new moduleDAO();
System.out.println("moduleController motor data : " + motor);
if (motor == 0) {
if (magnetic == 0) {
dao.updateLost(hel_number);
}
}
response.sendRedirect("returnMotor");
}
}
<returnMotor>
package com.smhrd.module;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@SuppressWarnings("serial")
@WebServlet("/returnMotor")
public class returnMotor extends HttpServlet {
public static int magnetic = 0;
public static int alcoholYES = 1;
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF-8");
int press = module.press;
PrintWriter out = response.getWriter();
// System.out.println("returnMotor press: "+press);
// arduino에서 알코올 값 받아오기
if (request.getParameter("alcohol") != null) {
System.out.println("motor,alcohol,piezo wifi연결 중");
int alcohol = Integer.parseInt(request.getParameter("alcohol"));
System.out.println("alcohol : " + alcohol);
if(alcohol>650) {
alcoholYES=1;
}
}
// 마그네틱 센서
if(request.getParameter("magnetic") != null) {
magnetic = Integer.parseInt(request.getParameter("magnetic"));
System.out.println("magnetic : "+ magnetic);
}
// motor값 받아오기
int motor = moduleController.motor;
System.out.println("motor값 :" + motor);
// press>0&&
if (motor == 1) {
out.print("1");
System.out.println("아두이노로 1 간다");
} else if (motor == 2||module.shock==1) {
System.out.println("아두이노로 2 간다");
out.print("2");
} else if (motor==0) {
System.out.println("아두이노로 0 간다");
out.print("0");
alcoholYES=0;
}
}
}
<returnMotor2>
package com.smhrd.module;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@SuppressWarnings("serial")
@WebServlet("/returnMotor2")
public class returnMotor2 extends HttpServlet {
public static int alcohol = 0;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
int motor = Integer.parseInt((String)session.getAttribute("motor"));
int mag = Integer.parseInt((String)session.getAttribute("mag"));
System.out.println(motor);
System.out.println(mag);
//if(request.getParameter("alcohol") != null) {
// alcohol = Integer.parseInt(request.getParameter("alcohol"));
// System.out.println(alcohol);
//}
// System.out.println(module.press);
// PrintWriter out = response.getWriter();
//if (module.press > 10&&motor==1) {
// out.println("1");
//System.out.println("presson");
// } else if(motor==0) {
// out.println("2");
// System.out.println("pressoff");
// } else {
// out.println("0");
// // System.out.println("pressoff");
// }
}
}
<sosAlert>
package com.smhrd.module;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.smhrd.dao.MemberDAO;
import com.smhrd.domain.UlocationVO;
@WebServlet("/sosAlert")
public class sosAlert extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/json;charset=utf-8");
int ex = Integer.parseInt(request.getParameter("ex"));
System.out.println(ex);
String shock = Integer.toString(module.shock);
String hel_number = module.hel_number_shock;
String[] list = {shock, hel_number};
System.out.println("list목록 , shock : "+ shock + ", hel_number : "+ hel_number);
PrintWriter out = response.getWriter();
Gson g = new Gson();
String json = g.toJson(list);
out.print(json);
// 임의값 넣어줌
// int shock = 1;
// int hel_number = 1;
}
}
'2차 프로젝트' 카테고리의 다른 글
.JSP 파일 코드 (0) | 2022.07.22 |
---|---|
FrontController 코드 (0) | 2022.07.22 |
Domain 코드 (0) | 2022.07.22 |
DAO 코드 (0) | 2022.07.22 |
Controller 코드 (0) | 2022.07.22 |