package org.yzh.protocol.t808;
|
|
import io.github.yezhihao.protostar.annotation.Field;
|
import io.github.yezhihao.protostar.annotation.Message;
|
import io.github.yezhihao.protostar.util.KeyValuePair;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
import lombok.Data;
|
import lombok.ToString;
|
import lombok.experimental.Accessors;
|
import org.yzh.protocol.basics.JTMessage;
|
import org.yzh.protocol.commons.JT808;
|
import org.yzh.protocol.commons.transform.PassthroughConverter;
|
import org.yzh.protocol.commons.transform.passthrough.PeripheralStatus;
|
import org.yzh.protocol.commons.transform.passthrough.PeripheralSystem;
|
import org.yzh.protocol.t808.T8900Lock.*;
|
|
import java.nio.ByteBuffer;
|
|
/**
|
* @author yezhihao
|
* https://gitee.com/yezhihao/jt808-server
|
*/
|
@ToString
|
@Data
|
@Accessors(chain = true)
|
@Message(JT808.数据下行透传)
|
public class T8900 extends JTMessage {
|
|
/** GNSS模块详细定位数据 */
|
public static final int GNSSLocation = 0x00;
|
/** 道路运输证IC卡信息上传消息为64Byte,下传消息为24Byte,道路运输证IC卡认证透传超时时间为30s.超时后,不重发 */
|
public static final int ICCardInfo = 0x0B;
|
/** 串口1透传消息 */
|
public static final int SerialPortOne = 0x41;
|
/** 串口2透传消息 */
|
public static final int SerialPortTow = 0x42;
|
/** 用户自定义透传 0xF0~0xFF */
|
public static final int Custom = 0xF0;
|
|
@Field(desc = "透传消息", converter = PassthroughConverter.class)
|
private KeyValuePair<Integer, Object> message;
|
|
@Schema(description = "状态查询(外设状态信息:外设工作状态、设备报警信息)")
|
private PeripheralStatus peripheralStatus;
|
|
@Schema(description = "信息查询(外设传感器的基本信息:公司信息、产品代码、版本号、外设ID、客户代码)")
|
private PeripheralSystem peripheralSystem;
|
|
// 新增:蝶阀锁协议字段
|
@Schema(description = "蝶阀锁控制消息")
|
private ValveLockProtocol valveLockProtocol;
|
// 新增:蝶阀锁状态协议字段
|
@Schema(description = "蝶阀锁状态消息")
|
private T8900State t8900State;
|
// 新增:蝶阀锁读设备号字段
|
@Schema(description = "蝶阀锁读设备号协议")
|
private T8900ReadDeviceID readDeviceID;
|
// 新增:蝶阀锁设置设备号
|
@Schema(description = "蝶阀锁设置设备号")
|
private T8900SetDeviceID setDeviceID;
|
// 新增:蝶阀锁读所有信息
|
@Schema(description = "蝶阀锁读所有信息")
|
private T8900ReadAllInformation readAllInformation;
|
// 新增:蝶阀锁设置离线开锁密码
|
@Schema(description = "蝶阀锁设置离线开锁密码")
|
private T8900SetPassword setPassword;
|
|
public T8900 build() {
|
KeyValuePair<Integer, Object> message = new KeyValuePair<>();
|
|
/*2025-05-24 zwy新增*/
|
if (valveLockProtocol != null) {
|
// 计算蝶阀锁协议的校验和(修正为求和取低8位)
|
valveLockProtocol.calculateChecksum();
|
//VALVE_LOCK_MESSAGE_TYPE
|
message.setKey(SerialPortOne);
|
//****组建蝶阀消息体****
|
// 锁芯状态
|
byte statusByte = valveLockProtocol.getStatus();
|
// 计算校验和 (前4个字节的和)
|
byte checksum = valveLockProtocol.getChecksum();
|
// 构建完整消息
|
ByteBuffer buffer = ByteBuffer.allocate(5);
|
buffer.put(valveLockProtocol.getLockId()); // AA AA
|
buffer.put(valveLockProtocol.getFixedValue()); // 固定值02
|
buffer.put(statusByte); // CC
|
buffer.put(checksum); // BB
|
|
message.setValue(buffer.array());
|
} else if (t8900State != null) {
|
//查询碟阀锁状态
|
byte checksum = t8900State.calculateChecksum();
|
ByteBuffer buffer = ByteBuffer.allocate(4);
|
buffer.put(t8900State.getLockId());
|
buffer.put(t8900State.getCommandType());
|
buffer.put(checksum);
|
message.setKey(SerialPortOne);
|
message.setValue(buffer.array());
|
} else if(readDeviceID != null){
|
//读设备号
|
byte checksum = readDeviceID.calculateChecksum();
|
ByteBuffer buffer = ByteBuffer.allocate(4);
|
buffer.put(readDeviceID.getLockId());
|
buffer.put(readDeviceID.getCommandType());
|
buffer.put(checksum);
|
message.setKey(SerialPortOne);
|
message.setValue(buffer.array());
|
} else if(setDeviceID != null){
|
//设置设备号
|
byte checksum = setDeviceID.calculateChecksum();
|
ByteBuffer buffer = ByteBuffer.allocate(6);
|
buffer.put(setDeviceID.getLockId());
|
buffer.put(setDeviceID.getCommandType());
|
buffer.put(setDeviceID.getNewlockId());
|
buffer.put(checksum);
|
message.setKey(SerialPortOne);
|
message.setValue(buffer.array());
|
} else if (readAllInformation != null ){
|
// 读所有信息
|
byte checksum = readAllInformation.calculateChecksum();
|
ByteBuffer buffer = ByteBuffer.allocate(10);
|
buffer.put(readAllInformation.getLockId());
|
buffer.put(readAllInformation.getCommandType());
|
buffer.put(readAllInformation.getYear());
|
buffer.put(readAllInformation.getMonth());
|
buffer.put(readAllInformation.getDay());
|
buffer.put(readAllInformation.getHour());
|
buffer.put(readAllInformation.getMinute());
|
buffer.put(readAllInformation.getSecond());
|
buffer.put(checksum);
|
message.setKey(SerialPortOne);
|
message.setValue(buffer.array());
|
} else if(setPassword != null){
|
//设置蝶阀锁离线开锁密码
|
ByteBuffer buffer = ByteBuffer.allocate(64);
|
buffer.put(setPassword.getLockId());
|
buffer.put(setPassword.getCommandType());
|
buffer.put(setPassword.getPassword1());
|
buffer.put(setPassword.getPassword2());
|
buffer.put(setPassword.getPassword3());
|
buffer.put(setPassword.getPassword4());
|
buffer.put(setPassword.getPassword5());
|
buffer.put(setPassword.getPassword6());
|
buffer.put(setPassword.getPassword7());
|
buffer.put(setPassword.getPassword8());
|
buffer.put(setPassword.getPassword9());
|
buffer.put(setPassword.getPassword10());
|
byte checksum =setPassword.calculateSUMChecksum(buffer.array());
|
buffer.put(checksum);
|
message.setKey(SerialPortOne);
|
message.setValue(buffer.array());
|
} else if (peripheralStatus != null) {
|
message.setKey(PeripheralStatus.key);
|
message.setValue(peripheralStatus);
|
|
} else if (peripheralSystem != null) {
|
message.setKey(PeripheralSystem.key);
|
message.setValue(peripheralSystem);
|
}
|
this.message = message;
|
return this;
|
}
|
}
|