From aaa1d3a46f2c336045e7f6a7c620374ca086559b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sun, 12 May 2024 07:36:29 +0800 Subject: [PATCH] =?UTF-8?q?1078-=E6=91=84=E5=83=8F=E5=A4=B4=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E6=8B=8D=E6=91=84=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/jt1078/bean/JTShootingCommand.java | 160 ++++++++++++++++++ .../iot/vmp/jt1078/cmd/JT1078Template.java | 13 ++ .../jt1078/controller/JT1078Controller.java | 14 ++ .../jt1078/controller/bean/ShootingParam.java | 37 ++++ .../iot/vmp/jt1078/proc/request/J0805.java | 78 +++++++++ .../iot/vmp/jt1078/proc/response/J8801.java | 31 ++++ .../vmp/jt1078/service/Ijt1078Service.java | 3 + .../service/impl/jt1078ServiceImpl.java | 8 + 8 files changed, 344 insertions(+) create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTShootingCommand.java create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/controller/bean/ShootingParam.java create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0805.java create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8801.java diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTShootingCommand.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTShootingCommand.java new file mode 100644 index 000000000..aba9478d9 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTShootingCommand.java @@ -0,0 +1,160 @@ +package com.genersoft.iot.vmp.jt1078.bean; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.swagger.v3.oas.annotations.media.Schema; + +@Schema(description = "拍摄命令参数") +public class JTShootingCommand { + + @Schema(description = "通道 ID") + private int chanelId; + + @Schema(description = "0:停止拍摄;0xFFFF:录像;其他:拍照张数") + private int command; + + @Schema(description = "拍照间隔/录像时间, 单位为秒(s) ,0 表示按最小间隔拍照或一直录像") + private int time; + + @Schema(description = "1:保存; 0:实时上传") + private int save; + + @Schema(description = "分辨率: " + + "0x00:最低分辨率" + + "0x01:320 x240;" + + "0x02:640 x480;" + + "0x03:800 x600;" + + "0x04:1024 x768;" + + "0x05:176 x144;" + + "0x06:352 x288;" + + "0x07:704 x288;" + + "0x08:704 x576;" + + "0xff:最高分辨率") + private int resolvingPower; + + @Schema(description = "图像/视频质量: 取值范围为 1 ~ 10 ,1 代表质量损失最小 ,10 表示压缩 比最大") + private int quality; + + @Schema(description = "亮度, 0 ~ 255") + private int brightness; + + @Schema(description = "对比度,0 ~ 127") + private int contrastRatio; + + @Schema(description = "饱和度,0 ~ 127") + private int saturation; + + @Schema(description = "色度,0 ~ 255") + private int chroma; + + public ByteBuf decode() { + ByteBuf byteBuf = Unpooled.buffer(); + byteBuf.writeByte(chanelId); + byteBuf.writeShort((short)(command & 0xffff)); + byteBuf.writeShort((short)(time & 0xffff)); + byteBuf.writeByte(save); + byteBuf.writeByte(resolvingPower); + byteBuf.writeByte(quality); + byteBuf.writeByte(brightness); + byteBuf.writeByte(contrastRatio); + byteBuf.writeByte(saturation); + byteBuf.writeByte(chroma); + return byteBuf; + } + + public int getChanelId() { + return chanelId; + } + + public void setChanelId(int chanelId) { + this.chanelId = chanelId; + } + + public int getCommand() { + return command; + } + + public void setCommand(int command) { + this.command = command; + } + + public int getSave() { + return save; + } + + public void setSave(int save) { + this.save = save; + } + + public int getResolvingPower() { + return resolvingPower; + } + + public void setResolvingPower(int resolvingPower) { + this.resolvingPower = resolvingPower; + } + + public int getQuality() { + return quality; + } + + public void setQuality(int quality) { + this.quality = quality; + } + + public int getBrightness() { + return brightness; + } + + public void setBrightness(int brightness) { + this.brightness = brightness; + } + + public int getContrastRatio() { + return contrastRatio; + } + + public void setContrastRatio(int contrastRatio) { + this.contrastRatio = contrastRatio; + } + + public int getSaturation() { + return saturation; + } + + public void setSaturation(int saturation) { + this.saturation = saturation; + } + + public int getChroma() { + return chroma; + } + + public void setChroma(int chroma) { + this.chroma = chroma; + } + + public int getTime() { + return time; + } + + public void setTime(int time) { + this.time = time; + } + + @Override + public String toString() { + return "JTShootingCommand{" + + "chanelId=" + chanelId + + ", command=" + command + + ", time=" + time + + ", save=" + save + + ", resolvingPower=" + resolvingPower + + ", quality=" + quality + + ", brightness=" + brightness + + ", contrastRatio=" + contrastRatio + + ", saturation=" + saturation + + ", chroma=" + chroma + + '}'; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java b/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java index bb441c246..3c3287512 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java @@ -40,6 +40,7 @@ public class JT1078Template { private static final String H8607 = "8607"; private static final String H8608 = "8608"; private static final String H8702 = "8702"; + private static final String H8801 = "8801"; private static final String H9101 = "9101"; private static final String H9102 = "9102"; private static final String H9201 = "9201"; @@ -61,6 +62,7 @@ public class JT1078Template { private static final String H0500 = "0500"; private static final String H0608 = "0608"; private static final String H0702 = "0702"; + private static final String H0805 = "0805"; private static final String H1205 = "1205"; /** @@ -567,4 +569,15 @@ public class JT1078Template { .build(); return SessionManager.INSTANCE.request(cmd, timeOut); } + + public Object shooting(String devId, J8801 j8801, int timeOut) { + Cmd cmd = new Cmd.Builder() + .setDevId(devId) + .setPackageNo(randomInt()) + .setMsgId(H8801) + .setRespId(H0805) + .setRs(j8801) + .build(); + return SessionManager.INSTANCE.request(cmd, timeOut); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java index 4b7f9cb57..9d672fa0a 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java @@ -749,5 +749,19 @@ public class JT1078Controller { return WVPResult.fail(ErrorCode.ERROR100); } } + + @Operation(summary = "1078-摄像头立即拍摄命令", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "设备编号", required = true) + @PostMapping("/shooting") + public WVPResult> shooting(@RequestBody ShootingParam param){ + + logger.info("[1078-摄像头立即拍摄命令] param: {}", param ); + List ids = service.shooting(param.getDeviceId(), param.getShootingCommand()); + if (ids != null) { + return WVPResult.success(ids); + }else { + return WVPResult.fail(ErrorCode.ERROR100); + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/bean/ShootingParam.java b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/bean/ShootingParam.java new file mode 100644 index 000000000..22e77a03c --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/bean/ShootingParam.java @@ -0,0 +1,37 @@ +package com.genersoft.iot.vmp.jt1078.controller.bean; + +import com.genersoft.iot.vmp.jt1078.bean.JTShootingCommand; +import io.swagger.v3.oas.annotations.media.Schema; +@Schema(description = "设备") +public class ShootingParam { + + @Schema(description = "设备") + private String deviceId; + + @Schema(description = "拍摄命令参数") + private JTShootingCommand shootingCommand; + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public JTShootingCommand getShootingCommand() { + return shootingCommand; + } + + public void setShootingCommand(JTShootingCommand shootingCommand) { + this.shootingCommand = shootingCommand; + } + + @Override + public String toString() { + return "ShootingParam{" + + "deviceId='" + deviceId + '\'' + + ", shootingCommand=" + shootingCommand + + '}'; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0805.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0805.java new file mode 100644 index 000000000..a621f67a0 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0805.java @@ -0,0 +1,78 @@ +package com.genersoft.iot.vmp.jt1078.proc.request; + +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; +import com.genersoft.iot.vmp.jt1078.proc.Header; +import com.genersoft.iot.vmp.jt1078.proc.response.Rs; +import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service; +import com.genersoft.iot.vmp.jt1078.session.Session; +import com.genersoft.iot.vmp.jt1078.session.SessionManager; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import org.springframework.context.ApplicationEvent; + +import java.util.List; + +/** + * 摄像头立即拍摄命令应答 + */ +@MsgId(id = "0805") +public class J0805 extends Re { + + private int respNo; + /** + * 0:成功/确认;1:失败;2:消息有误;3:不支持 + */ + private int result; + + /** + * 表示拍摄成功的多媒体个数 + */ + private List ids; + + @Override + protected Rs decode0(ByteBuf buf, Header header, Session session) { + respNo = buf.readUnsignedShort(); + result = buf.readUnsignedByte(); + int length = buf.readUnsignedByte(); + for (int i = 0; i < length; i++) { + ids.add(buf.readUnsignedInt()); + } + SessionManager.INSTANCE.response(header.getTerminalId(), "0805", (long) respNo, ids); + return null; + } + + @Override + protected Rs handler(Header header, Session session, Ijt1078Service service) { + SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, result); + return null; + } + + public int getRespNo() { + return respNo; + } + + public void setRespNo(int respNo) { + this.respNo = respNo; + } + + public int getResult() { + return result; + } + + public void setResult(int result) { + this.result = result; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + @Override + public ApplicationEvent getEvent() { + return null; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8801.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8801.java new file mode 100644 index 000000000..72749b69d --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8801.java @@ -0,0 +1,31 @@ +package com.genersoft.iot.vmp.jt1078.proc.response; + +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; +import com.genersoft.iot.vmp.jt1078.bean.JTShootingCommand; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; + +import java.util.List; + +/** + * 摄像头立即拍摄命令 + */ +@MsgId(id = "8801") +public class J8801 extends Rs { + + JTShootingCommand command; + + @Override + public ByteBuf encode() { + return command.decode(); + } + + public JTShootingCommand getCommand() { + return command; + } + + public void setCommand(JTShootingCommand command) { + this.command = command; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java index 6b7c10ee6..11a3732c6 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java @@ -95,4 +95,7 @@ public interface Ijt1078Service { List queryRoute(String deviceId, List ids); JTDriverInformation queryDriverInformation(String deviceId); + + List shooting(String deviceId, JTShootingCommand shootingCommand); + } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java index b3471d115..787ebe379 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java @@ -35,6 +35,7 @@ import org.springframework.stereotype.Service; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -705,4 +706,11 @@ public class jt1078ServiceImpl implements Ijt1078Service { J8702 j8702 = new J8702(); return (JTDriverInformation)jt1078Template.queryDriverInformation(deviceId, j8702, 20); } + + @Override + public List shooting(String deviceId, JTShootingCommand shootingCommand) { + J8801 j8801 = new J8801(); + j8801.setCommand(shootingCommand); + return (List)jt1078Template.shooting(deviceId, j8801, 20); + } }