import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* This is a simple example of an HTTP Servlet. It responds to the GET
* and HEAD methods of the HTTP protocol.
*/
public class SensorStatus extends HttpServlet
{
rs485 rs = rs485.getInstance();
/**
* Handle the GET and HEAD methods by building a simple web page.
* HEAD is just like GET, except that the server returns only the
* headers (including content length) not the body we write.
*/
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
String title = "Sensor status";
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
out = response.getWriter();
rs.requestSensorStatus();
int header = rs.readData();
int address = rs.readData();
int command = rs.readData();
int data1 = rs.readData();
int data2 = rs.readData();
int data3 = rs.readData();
int trailer = rs.readData();
out.println("
");
out.println("");
out.println("" + title + "
");
out.println("return to Home page");
out.println(" Sensor status
");
out.println("
");
//first row front door status
int temp_byte = (byte) data1;
out.println("");
out.println("| ");
out.println("Front Door");
out.println(" | ");
out.println("");
if ((0x08 & temp_byte) == 0x00)
out.println("Closed");
else
out.println("Open");
out.println(" | ");
out.println("
");
//second row back door status
temp_byte = (byte) data1;
out.println("");
out.println("| ");
out.println("Back Door");
out.println(" | ");
out.println("");
if ((0x04 & temp_byte) == 0x04)
out.println("Closed");
else
out.println("Open");
out.println(" | ");
out.println("
");
// third row garage door
temp_byte = (byte) data1;
out.println("");
out.println("| ");
out.println("Garage door");
out.println(" | ");
out.println("");
if ((0x02 & temp_byte) == 0x00)
out.println("Closed");
else
out.println("Open");
out.println(" | ");
// fourth row
out.println("
");
out.println("| ");
out.println("Toggle switch");
out.println(" | ");
out.println("
");
out.println("
");
out.println("");
out.close();
}
}