public void read_param(HttpServletRequest request, HttpServletResponse response) throws IOException { String uuid = this.getStringParam(request, "uuid", null); final Map<String, String> result = new HashMap<String, String>(); result.put("status", "error"); if (uuid == null) { result.put("msg", "-2:Parameter error"); } else { ASC100Client ascClient = server.getMonitorClient(uuid); if (ascClient == null) { result.put("msg", "1$Not found base station"); } else { result.put("status", "timeout"); ImageClientListener l = new AbstractImageListener() { public void message(ImageClientEvent event) { if (event.data.len == 32) { ByteBuffer b = event.data.inBuffer.asReadOnlyBuffer(); /* "X固定为2表示读取命令,Y固定为4,表示读取当前设备参数, A(通道1模式),B(通道2模式),C(亮度),D(对比度),E(饱和度),F(色调), G(敏感度),H(压缩比),I(分辨率),J(告警图片数量),K(门禁联动开关设置), L(串口流控参数(L1,L2),(T1,T2)),M(错误机制设置(T1,T2),(Cnt1)),N图片策略(单字节), O(通道3模式),P(通道4模式), (其它字节预留) "*/ byte b1 = b.get(); byte b2 = b.get(); if (b1 != 2 || b2 != 4) return; result.put("status", "ok"); result.put("mode_ch1", String.format("%x", b.get())); result.put("mode_ch2", String.format("%x", b.get())); int d = b.get(); result.put("color_x", (d < 0 ? d + 256 : d) + ""); d = b.get(); result.put("color_y", (d < 0 ? d + 256 : d) + ""); d = b.get(); result.put("color_z", (d < 0 ? d + 256 : d) + ""); d = b.get(); result.put("color_a", (d < 0 ? d + 256 : d) + ""); d = b.get(); result.put("mg_ch", (d < 0 ? d + 256 : d) + ""); d = b.get(); result.put("zip_rate", (d < 0 ? d + 256 : d) + ""); // 分辨率 d = b.get(); result.put("fbl", (d < 0 ? d + 256 : d) + ""); d = b.get(); result.put("image_count", (d < 0 ? d + 256 : d) + ""); // 门禁联动 d = b.get(); result.put("mjld", (d < 0 ? d + 256 : d) + ""); b.get(); b.get(); b.get(); b.get(); b.get(); b.get(); b.get(); b.get(); // 空5个字节,兼容老设备 b.get(); b.get(); b.get(); b.get(); b.get(); result.put("mode_ch3", String.format("%x", b.get())); result.put("mode_ch4", String.format("%x", b.get())); synchronized (this) { this.notifyAll(); } } }; }; ascClient.addListener(l); try { if (ascClient.readParam()) { synchronized (l) { l.wait(1000 * 10); } } else { result.put("status", "image"); } } catch (InterruptedException e) { } finally { ascClient.removeListener(l); } } } JSONValue.writeJSONString(result, response.getWriter()); }