LED显示和语音播报需要用到命令穿透、直接调接口不好实现、返回状态是成功实际没有相应,
穿透命令的接口路径特别坑,路径中间必须加一个空格, 不加空格一直提示参数有误
调用示例:
//PUT后边必须带空格、要不然会失败(特别坑的是海康的文档里也不说明)
//语音播报
//参数说明: 穿透命令接口路径,车牌识别机IP, 要发送的语音内容
yyXMLConfig("PUT /ISAPI/Parking/channels/1/voiceBroadcastInfo", ip,yybb);
//LED显示(可显示4行和2行)
//参数说明: 穿透命令接口路径,车牌识别机IP, 要发送的显示内容 , 类型0展示2行 1展示4行
LedXMLConfig("PUT /ISAPI/Parking/channels/1/LEDConfigurationDz", aip, led, 1);
//说明: led显示内容多行以;;隔开
代码
/**
* Led屏幕展示
* @param url
* @param ip
* @param content 多行以;;隔开
* @param type 0展示2行 1展示4行
*/
public static void LedXMLConfig(String url,String ip,String content,int type) {
try {
String xml="";
if(type==0) {
String[] str=content.split(";;");
if(str.length>1) {
xml=ledPz1(str[0],str[1]);
}else {
log.error("Led屏幕展示命令执行:内容有误");
return;
}
}else if(type==1) {
String[] str=content.split(";;");
if(str.length>3) {
xml=ledPz(str[0],str[1],str[2],str[3]);
}else {
log.error("Led屏幕展示命令执行:内容有误");
return;
}
}else {
log.error("Led屏幕展示命令执行:类型有误");
return;
}
System.out.println("设置LED显示---"+putISAPI(Config.getLogidMap(ip),url,xml));
System.out.println("LED设置---"+content);
} catch (Exception e) {
log.error("Led屏幕展示出错:",e);
}
}
/**
* 语音播报配置
* @param url
* @param ip
* @param content
*/
public static void yyXMLConfig(String url,String ip,String content) {
try {
// 语音播报配置
//xml数据转换
String xml=yybbPz(content);
System.out.println("设置语音---"+putISAPI(Config.getLogidMap(ip),url,xml));
System.out.println("语音设置---"+content +" --- 打印xml---"+ xml);
} catch (Exception e) {
log.error("语音播报配置出错:",e);
}
}
/**
* LED屏幕显示的数据 显示2行
*/
private static String ledPz1(String xml1,String xml2) {
String ret="<?xml version=\"1.0\"?><LEDConfigurationList xmlns=\"http://www.hikvision.com/ver20/XMLSchema\" version=\"2.0\"><LEDConfiguration><information>"+xml1+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate> <fontSize>32</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml2+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate> <fontSize>32</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>";
return ret;
// <?xml version="1.0"?><LEDConfigurationListxmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0"><LEDConfiguration><information>1111</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate> <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>2222</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate> <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>3333</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>4444</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>
}
/**
* LED屏幕显示的数据
* @param xml1 第一行数据
* @param xml2 第二行数据
* @param xml3 第三行数据
* @param xml4 第四行数据
*/
private static String ledPz(String xml1,String xml2,String xml3,String xml4) {
String ret="<?xml version=\"1.0\"?><LEDConfigurationList xmlns=\"http://www.hikvision.com/ver20/XMLSchema\" version=\"2.0\"><LEDConfiguration><information>"+xml1+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate> <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml2+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate> <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml3+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml4+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>";
return ret;
// <?xml version="1.0"?><LEDConfigurationListxmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0"><LEDConfiguration><information>1111</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate> <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>2222</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate> <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>3333</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>4444</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>
}
/**
* 语音播报配置
* @param xml
* @return
*/
private static String yybbPz(String xml) {
// <?xml version="1.0" encoding="utf-8"?><VoiceBroadcastInfo version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema"><information min="0" max="128"></information></VoiceBroadcastInfo>
String ret="<VoiceBroadcastInfo version=\"2.0\" xmlns=\"http://www.isapi.org/ver20/XMLSchema\"><information min=\"0\" max=\"128\">"+xml+"</information></VoiceBroadcastInfo>";
return ret;
}
// 设置穿透
public static String putISAPI(int lUserID,String strUrl,String json){
String strURL = strUrl;
HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(BYTE_ARRAY_LEN);
System.arraycopy(strURL.getBytes(), 0, ptrUrl.byValue, 0, strURL.length());
ptrUrl.write();
HCNetSDK.BYTE_ARRAY ptrInBuffer = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
ptrInBuffer.read();
String strInbuffer =json;
try {
ptrInBuffer.byValue = strInbuffer.getBytes("UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
ptrInBuffer.write();
HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
struXMLInput.read();
struXMLInput.dwSize = struXMLInput.size();
struXMLInput.lpRequestUrl = ptrUrl.getPointer();
struXMLInput.dwRequestUrlLen = ptrUrl.byValue.length;
struXMLInput.lpInBuffer = ptrInBuffer.getPointer();
struXMLInput.dwInBufferSize = ptrInBuffer.byValue.length;
struXMLInput.write();
HCNetSDK.BYTE_ARRAY ptrStatusByte = new HCNetSDK.BYTE_ARRAY(ISAPI_STATUS_LEN);
ptrStatusByte.read();
HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
ptrOutByte.read();
HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
struXMLOutput.read();
struXMLOutput.dwSize = struXMLOutput.size();
struXMLOutput.lpOutBuffer = ptrOutByte.getPointer();
struXMLOutput.dwOutBufferSize = ptrOutByte.size();
struXMLOutput.lpStatusBuffer = ptrStatusByte.getPointer();
struXMLOutput.dwStatusSize = ptrStatusByte.size();
struXMLOutput.write();
if(!hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) {
int iErr = hCNetSDK.NET_DVR_GetLastError();
return "错误码-"+iErr;
} else {
struXMLOutput.read();
ptrOutByte.read();
ptrStatusByte.read();
String strOutXML = new String(ptrStatusByte.byValue).trim();
return "返回状态-"+strOutXML;
}
}
// 获取穿透
public static String getISAPI(int lUserID,String strUrl){
String strURL = strUrl;
HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(BYTE_ARRAY_LEN);
System.arraycopy(strURL.getBytes(), 0, ptrUrl.byValue, 0, strURL.length());
ptrUrl.write();
HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
struXMLInput.read();
struXMLInput.dwSize = struXMLInput.size();
struXMLInput.lpRequestUrl = ptrUrl.getPointer();
struXMLInput.dwRequestUrlLen = ptrUrl.byValue.length;
struXMLInput.lpInBuffer = null;
struXMLInput.dwInBufferSize = 0;
struXMLInput.write();
HCNetSDK.BYTE_ARRAY ptrStatusByte = new HCNetSDK.BYTE_ARRAY(ISAPI_STATUS_LEN);
ptrStatusByte.read();
HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
ptrOutByte.read();
HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
struXMLOutput.read();
struXMLOutput.dwSize = struXMLOutput.size();
struXMLOutput.lpOutBuffer = ptrOutByte.getPointer();
struXMLOutput.dwOutBufferSize = ptrOutByte.size();
struXMLOutput.lpStatusBuffer = ptrStatusByte.getPointer();
struXMLOutput.dwStatusSize = ptrStatusByte.size();
struXMLOutput.write();
if(!hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) {
int iErr = hCNetSDK.NET_DVR_GetLastError();
return "错误码-"+iErr;
} else {
struXMLOutput.read();
ptrOutByte.read();
ptrStatusByte.read();
String strOutXML ="";
try {
strOutXML= new String(ptrOutByte.byValue,"UTF-8").trim();
} catch (Exception e) {
e.printStackTrace();
}
return strOutXML;
}
}
开发文档和SDK我就不附了, 官网都有