@Override public void run() { byte[] respPacket = InitAlarmEventPacket.init(PUID, (byte) 1).toByteArray(); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---ALARMEVENT_PRO req 报警结束", devSeqStr); // PrintHelper.printByteArr(respPacket, 0); sendPacket(respPacket); }
/** 对接收到的数据包进行分类处理 */ private void processPacket(byte[] receivedPacket) { byte packet_head = receivedPacket[0]; // 数据包类型 if (packet_head == ProtocolVar.PacketType.PACKET_HEAD) { int packet_type = receivedPacket[1]; // 数据包类型 switch (packet_type) { // 处理接收到的心跳请求 case ProtocolVar.PacketType.HEARTBEAT_PRO: /// 打印心跳数据包 // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---心跳回复", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); Kaer_heartbeat_resp heartbeat_resp = new Kaer_heartbeat_resp(); heartbeat_resp.parsePacket(receivedPacket); heartbeatFreq = heartbeat_resp.getIntervalTime(); break; // 处理接收到的报警设置请求 case ProtocolVar.PacketType.ALARMSET_PRO: // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---报警设置 req", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); Kaer_alarmset_req alarmsetReq = new Kaer_alarmset_req(); alarmsetReq.parsePacket(receivedPacket); // 发送报警设置确认数据包 byte[] alarmSetRespPacet = InitAlarmSettingPacket.init(PUID).toByteArray(); sendPacket(alarmSetRespPacet); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---报警设置 resp", devSeqStr); // PrintHelper.printByteArr(alarmSetRespPacet, 0); if (alarmsetReq.getTypeAlarm() == ProtocolVar.ALARM_OFF) { // 上传报警开始数据包 byte[] respPacket = InitAlarmEventPacket.init(PUID, (byte) 0).toByteArray(); sendPacket(respPacket); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---报警事件上传 req 报警开始", // devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); // 20秒后发送报警结束 setAlarmOffTask(); } else { // do nothing } break; // 处理布放时间设置请求 case ProtocolVar.PacketType.ALARMTIME_PRO: // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---时间设置 req", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); Kaer_alarmTime_req alarmTimeReq = new Kaer_alarmTime_req(); alarmTimeReq.parsePacket(receivedPacket); byte[] respPacket = InitAlarmTimePacket.init(PUID).toByteArray(); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---时间设置 resp", devSeqStr); // PrintHelper.printByteArr(respPacket, 0); sendPacket(respPacket); break; // 处理报警事件上传请求 case ProtocolVar.PacketType.ALARMEVENT_PRO: // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---报警事件上传 resp", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); // Kaer_alarmEvent_resp alarmEventResp = new Kaer_alarmEvent_resp(); // alarmEventResp.parsePacket(receivedPacket); break; // 处理接视频请求的回复 case ProtocolVar.PacketType.CAPTURE_PRO: // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---视频请求 req", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); Kaer_capture_req captureReq = new Kaer_capture_req(); captureReq.parsePacket(receivedPacket); byte[] respCapturePacket = InitCapturePacket.init(PUID).toByteArray(); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---视频请求 resp", devSeqStr); // PrintHelper.printByteArr(respCapturePacket, 0); sendPacket(respCapturePacket); // --------------------发送图片 sendPicture(); break; // 处理获取视频编码参数的回复 case ProtocolVar.PacketType.GET_VIDEOCODEPARA: // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---获取视频编码参数 req", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); byte[] getVideoParaRespPacket = InitGetVideoCodeParaPacket.init(PUID).toByteArray(); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---获取视频编码参数 resp", devSeqStr); // PrintHelper.printByteArr(getVideoParaRespPacket, 0); sendPacket(getVideoParaRespPacket); break; // 处理设置视频编码参数的回复 case ProtocolVar.PacketType.SET_VIDEOCODEPARA: // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---设置视频编码参数 req", devSeqStr); // PrintHelper.printByteArr(receivedPacket, 0); byte[] setVideoParaRespPacket = InitSetVideoCodeParaPacket.init(PUID).toByteArray(); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---设置视频编码参数 resp", devSeqStr); // PrintHelper.printByteArr(setVideoParaRespPacket, 0); sendPacket(setVideoParaRespPacket); break; case ProtocolVar.PacketType.GET_DEVICE_TIME: byte[] getTimeResp = InitDeviceTimePacket.initGetTime(PUID).toByteArray(); // Logger.getLogger(CameraTask.class.getName()). // log(Level.INFO, devSeqStr + "---GET_DEVICE_TIME resp", // devSeqStr); // PrintHelper.printByteArr(setVideoParaRespPacket, 0); sendPacket(getTimeResp); break; default: // Logger.getLogger(CameraTask.class.getName()).log(Level.INFO, // ConvertTools.devSeqByteArr2Str(devSeq) + " 的不知名数据包"); // PrintHelper.printByteArr(receivedPacket, 0); // System.out.println(""); } } }