| | |
| | | byte destBye = (byte) despChar; |
| | | List<Byte> result = new ArrayList<>(); |
| | | byte[] rawContent = request.getRawContent(); |
| | | if (rawContent == null) { |
| | | return null; |
| | | } |
| | | for (int i = 0; i < rawContent.length; i++) { |
| | | if (rawContent[i] == destBye) { |
| | | boolean resul = false; |
| | |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | /** |
| | | * SIP命令类型: NOTIFY请求 |
| | | * SIP命令类型: NOTIFY请求,这是作为上级发送订阅请求后,设备才会响应的 |
| | | */ |
| | | @Component |
| | | public class NotifyRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { |
| | |
| | | } |
| | | |
| | | storager.updateChannelPosition(deviceChannel); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", time); |
| | |
| | | return; |
| | | } |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ NotifyAlarm ] content cannot be null"); |
| | | return; |
| | | } |
| | | DeviceAlarm deviceAlarm = new DeviceAlarm(); |
| | | deviceAlarm.setDeviceId(deviceId); |
| | | deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); |
| | |
| | | mobilePosition.setLatitude(deviceAlarm.getLatitude()); |
| | | mobilePosition.setReportSource("GPS Alarm"); |
| | | |
| | | |
| | | |
| | | // 更新device channel 的经纬度 |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setDeviceId(device.getDeviceId()); |
| | |
| | | } |
| | | |
| | | storager.updateChannelPosition(deviceChannel); |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | |
| | | } |
| | | // TODO: 需要实现存储报警信息、报警分类 |
| | | |
| | |
| | | return; |
| | | } |
| | | Element rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 收到目录订阅 ] content cannot be null"); |
| | | return; |
| | | } |
| | | Element deviceListElement = rootElement.element("DeviceList"); |
| | | if (deviceListElement == null) { |
| | | return; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 命令类型: 通知命令 |
| | | * 命令类型: 通知命令, 参看 A.2.5 通知命令 |
| | | * 命令类型: 状态信息(心跳)报送, 报警通知, 媒体通知, 移动设备位置数据,语音广播通知(TODO), 设备预置位(TODO) |
| | | * @author lin |
| | | */ |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; |
| | | |
| | | /** |
| | | * 报警事件的处理,参考:9.4 |
| | | */ |
| | | @Component |
| | | public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| | | |
| | |
| | | // 回复200 OK |
| | | try { |
| | | responseAck(evt, Response.OK); |
| | | } catch (SipException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (InvalidArgumentException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[收到报警通知], 回复200OK失败", e); |
| | | } |
| | | |
| | | Element deviceIdElement = rootElement.element("DeviceID"); |
| | |
| | | mobilePosition.setLatitude(deviceAlarm.getLatitude()); |
| | | mobilePosition.setReportSource("GPS Alarm"); |
| | | |
| | | |
| | | // 更新device channel 的经纬度 |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setDeviceId(device.getDeviceId()); |
| | |
| | | storager.insertMobilePosition(mobilePosition); |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | } |
| | | } |
| | | if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) { |
| | |
| | | alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); |
| | | alarmChannelMessage.setGbId(channelId); |
| | | redisCatchStorage.sendAlarmMsg(alarmChannelMessage); |
| | | |
| | | return; |
| | | } |
| | | |
| | |
| | | if (sipConfig.isAlarm()) { |
| | | deviceAlarmService.add(deviceAlarm); |
| | | } |
| | | |
| | | |
| | | if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { |
| | | publisher.deviceAlarmEventPublish(deviceAlarm); |
| | |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | | |
| | | /** |
| | | * 状态信息(心跳)报送 |
| | | */ |
| | | @Component |
| | | public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| | | |
| | |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| | | |
| | | /** |
| | | * 媒体通知 |
| | | */ |
| | | @Component |
| | | public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| | | |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; |
| | | import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; |
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| | | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import com.genersoft.iot.vmp.utils.GpsUtil; |
| | | import org.dom4j.DocumentException; |
| | | import org.dom4j.Element; |
| | | import org.slf4j.Logger; |
| | |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| | | |
| | | /** |
| | | * 移动设备位置数据通知,设备主动发起,不需要上级订阅 |
| | | */ |
| | | @Component |
| | | public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| | | |
| | |
| | | private IVideoManagerStorage storager; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private IDeviceChannelService deviceChannelService; |
| | | |
| | | @Override |
| | |
| | | |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | |
| | | if (rootElement == null) { |
| | | logger.warn("[ 移动设备位置数据通知 ] content cannot be null"); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | | mobilePosition.setCreateTime(DateUtil.getNow()); |
| | | if (!StringUtils.isEmpty(device.getName())) { |
| | |
| | | storager.updateChannelPosition(deviceChannel); |
| | | //回复 200 OK |
| | | responseAck(evt, Response.OK); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | |
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | HandlerCatchData take = taskQueue.poll(); |
| | | try { |
| | | Element rootElement = getRootElement(take.getEvt(), take.getDevice().getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 收到通道 ] content cannot be null"); |
| | | continue; |
| | | } |
| | | Element deviceListElement = rootElement.element("DeviceList"); |
| | | Element sumNumElement = rootElement.element("SumNum"); |
| | | Element snElement = rootElement.element("SN"); |
| | | if (snElement == null || sumNumElement == null || deviceListElement == null) { |
| | | responseAck(take.getEvt(), Response.BAD_REQUEST, "xml error"); |
| | | return; |
| | | continue; |
| | | } |
| | | int sumNum = Integer.parseInt(sumNumElement.getText()); |
| | | |
| | |
| | | catalogDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, take.getDevice(), channelList); |
| | | logger.info("[收到通道]设备: {} -> {}个,{}/{}", take.getDevice().getDeviceId(), channelList.size(), catalogDataCatch.get(take.getDevice().getDeviceId()) == null ? 0 :catalogDataCatch.get(take.getDevice().getDeviceId()).size(), sumNum); |
| | | if (catalogDataCatch.get(take.getDevice().getDeviceId()).size() == sumNum) { |
| | | // 数据已经完整接收 |
| | | // 数据已经完整接收, 此时可能存在某个设备离线变上线的情况,但是考虑到性能,此处不做处理, |
| | | // 目前支持设备通道上线通知时和设备上线时向上级通知 |
| | | boolean resetChannelsResult = storager.resetChannels(take.getDevice().getDeviceId(), catalogDataCatch.get(take.getDevice().getDeviceId())); |
| | | if (!resetChannelsResult) { |
| | | String errorMsg = "接收成功,写入失败,共" + sumNum + "条,已接收" + catalogDataCatch.get(take.getDevice().getDeviceId()).size() + "条"; |
| | |
| | | } |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 接收到DeviceInfo应答消息 ] content cannot be null"); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | Element deviceIdElement = rootElement.element("DeviceID"); |
| | | String channelId = deviceIdElement.getTextTrim(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + device.getDeviceId() + channelId; |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| | |
| | | import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; |
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| | | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import com.genersoft.iot.vmp.utils.GpsUtil; |
| | |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| | | |
| | | /** |
| | | * 移动设备位置数据查询回复 |
| | | * @author lin |
| | | */ |
| | | @Component |
| | | public class MobilePositionResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| | | |
| | |
| | | private IVideoManagerStorage storager; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private IDeviceChannelService deviceChannelService; |
| | | |
| | | @Override |
| | |
| | | |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | |
| | | if (rootElement == null) { |
| | | logger.warn("[ 移动设备位置数据查询回复 ] content cannot be null"); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | MobilePosition mobilePosition = new MobilePosition(); |
| | | mobilePosition.setCreateTime(DateUtil.getNow()); |
| | | if (!StringUtils.isEmpty(device.getName())) { |
| | |
| | | storager.insertMobilePosition(mobilePosition); |
| | | } |
| | | storager.updateChannelPosition(deviceChannel); |
| | | |
| | | // 发送redis消息。 通知位置信息的变化 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", mobilePosition.getTime()); |
| | | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| | | jsonObject.put("code", deviceChannel.getChannelId()); |
| | | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| | | jsonObject.put("latitude", mobilePosition.getLatitude()); |
| | | jsonObject.put("altitude", mobilePosition.getAltitude()); |
| | | jsonObject.put("direction", mobilePosition.getDirection()); |
| | | jsonObject.put("speed", mobilePosition.getSpeed()); |
| | | redisCatchStorage.sendMobilePositionMsg(jsonObject); |
| | | //回复 200 OK |
| | | responseAck(evt, Response.OK); |
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| | |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| | | |
| | | /** |
| | | * 设备预置位查询应答 |
| | | */ |
| | | @Component |
| | | public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| | | |
| | |
| | | Element rootElement = null; |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | |
| | | if (rootElement == null) { |
| | | logger.warn("[ 设备预置位查询应答 ] content cannot be null"); |
| | | responseAck(evt, Response.BAD_REQUEST); |
| | | return; |
| | | } |
| | | Element presetListNumElement = rootElement.element("PresetList"); |
| | | Element snElement = rootElement.element("SN"); |
| | | //该字段可能为通道或则设备的id |
| | |
| | | } |
| | | int sumNum = Integer.parseInt(presetListNumElement.attributeValue("Num")); |
| | | List<PresetQuerySipReq> presetQuerySipReqList = new ArrayList<>(); |
| | | if (sumNum == 0) { |
| | | // 数据无预置位信息 |
| | | |
| | | |
| | | }else { |
| | | if (sumNum > 0) { |
| | | for (Iterator<Element> presetIterator = presetListNumElement.elementIterator();presetIterator.hasNext();){ |
| | | Element itemListElement = presetIterator.next(); |
| | | PresetQuerySipReq presetQuerySipReq = new PresetQuerySipReq(); |
| | |
| | | try { |
| | | HandlerCatchData take = taskQueue.poll(); |
| | | Element rootElementForCharset = getRootElement(take.getEvt(), take.getDevice().getCharset()); |
| | | if (rootElement == null) { |
| | | logger.warn("[ 国标录像 ] content cannot be null"); |
| | | continue; |
| | | } |
| | | String sn = getText(rootElementForCharset, "SN"); |
| | | String channelId = getText(rootElementForCharset, "DeviceID"); |
| | | RecordInfo recordInfo = new RecordInfo(); |