Browse Source

20210320v1.0

master
zy_Java 4 years ago
parent
commit
c9c0b218c2
  1. 12
      ccmq/src/main/java/com/ccsens/ccmq/lowlevel/client/netty/tcphexserver/ModbusConverter.java
  2. 7
      ccmq/src/main/java/com/ccsens/ccmq/lowlevel/client/netty/tcphexserver/ModbusDecoder.java
  3. 16
      ccmq/src/main/java/com/ccsens/ccmq/lowlevel/message/MessageHandler.java
  4. 2
      ccmq/src/main/java/wiki/tall/ccmq/common/bean/dto/ccmodbus/CCModBusEntity.java
  5. 6
      ccmq/src/main/resources/application-dev.properties
  6. 2
      ccmq/src/main/resources/application.properties

12
ccmq/src/main/java/com/ccsens/ccmq/lowlevel/client/netty/tcphexserver/ModbusConverter.java

@ -107,20 +107,20 @@ public class ModbusConverter {
return null;
}
int majorIndex = CCModBusEntity.SIZE_MAJOR - 1;
int minorIndex = majorIndex + CCModBusEntity.SIZE_MINOR;
int mqIndex = minorIndex + CCModBusEntity.SIZE_MQ;
int majorIndex = 0;
int minorIndex = majorIndex + CCModBusEntity.SIZE_MAJOR;
int mqIndex = minorIndex + CCModBusEntity.SIZE_MINOR;
byte major = values[majorIndex];
byte minor = values[minorIndex];
byte mq = values[mqIndex];
byte mq = (byte) (values[mqIndex] >> 8 | values[mqIndex + 1]);
long userId = 0;
for(int i=mqIndex + 1;i<values.length;i++){
for(int i=mqIndex + CCModBusEntity.SIZE_MQ;i<values.length;i++){
userId <<= 8;
userId |= values[i] & 0xFF;
}
log.info("major:{},minor:{},mq:{},userId:{}", major, minor, mq, userId);
AuthMessage message = new AuthMessage(userId, major, minor, mq);
InMessage inMessage = new InMessage();
inMessage.setData(JacksonUtil.beanToJson(message));

7
ccmq/src/main/java/com/ccsens/ccmq/lowlevel/client/netty/tcphexserver/ModbusDecoder.java

@ -64,6 +64,10 @@ public class ModbusDecoder extends ByteToMessageDecoder {
CCModBusEntity ccModBusEntity = new CCModBusEntity(in);
// for (int i = 0; i < ccModBusEntity.getModbusData().length; i++) {
// log.info("modBus数据包:{}",ccModBusEntity.getModbusData()[i]);
// }
CCModBusEntity.Error error = ccModBusEntity.valid();
log.info("modBus数据检查:{}", error);
switch (error) {
@ -89,6 +93,7 @@ public class ModbusDecoder extends ByteToMessageDecoder {
// }
byte addr = ccModBusEntity.getAddr();
log.info("接收地址。{}",ccModBusEntity.getAddr());
if (addr == WebConstant.SLAVE_ID) {
// 消息系统作为从设备,接收主设备的消息
InMessage message = ModbusConverter.convertCCModbusToMessage(ccModBusEntity);
@ -98,7 +103,7 @@ public class ModbusDecoder extends ByteToMessageDecoder {
}
} else {
// 消息系统作为主设备,接收从设备的返回消息
log.info("地址不正确。{}",addr);
}

16
ccmq/src/main/java/com/ccsens/ccmq/lowlevel/message/MessageHandler.java

@ -304,9 +304,9 @@ public class MessageHandler {
logger.info("authid授权");
// authId有值默认授权通过
ChannelManager.authChannel(ChannelManager.getCurrentChannel(),String.valueOf(inSysData.getData().getAuthId()),inSysData.getData().getMajor(),inSysData.getData().getMinor(), inSysData.getMessage(), inSysData.getData().getMq());
logger.info("授权完成");
logger.info("授权完成:{}",inSysData.getData().getAuthId());
onClientOnLine(MessageConstant.DomainType.User,String.valueOf(inSysData.getData().getAuthId()));
logger.info("设置在线");
logger.info("设置在线:{}",inSysData.getData().getAuthId());
authSuccess = true;
}
}
@ -454,17 +454,19 @@ public class MessageHandler {
byte oper = modBusMessage.getData().getOper();
WrapperedChannel wrapperedChannel = ChannelManager.getWrapperedChannelByChannel(ChannelManager.getCurrentChannel());
if (StrUtil.isEmpty(wrapperedChannel.getUserId())) {
// 未授权不允许读写
//未授权不允许读写
ClientManager.sendServerMessage(inMessage.getFromDomain(), inMessage.getInvokerMessage(),
OutMessageSet.newInstance().ackId(null).add(new OutMessage(JacksonUtil.beanToJson(new UnAuthMessage())))
);
return;
}
Map<String, Long> register = wrapperedChannel.getRegister();
// 授权数据
//授权数据
Long authId = Long.parseLong(wrapperedChannel.getUserId());
// 接收数据的业务放
// Long authId = 1L;
//接收数据的业务放
byte mqType = wrapperedChannel.getMqType();
// byte mqType = 1;
// 版本信息
String version = wrapperedChannel.getVersion();
switch (oper) {
@ -525,8 +527,6 @@ public class MessageHandler {
}
default:break;
}
}
default: break;
}
@ -604,7 +604,7 @@ public class MessageHandler {
String []stringArray = CcMessageUtil.splitTypeAndUserId(domainTypeAndUserId);
MessageConstant.DomainType toDomain = MessageConstant.DomainType.valueOf(stringArray[0]);
String to = stringArray[1];
logger.info("查询ack");
logger.info("查询ack:{}",redisWaitAckSetKey);
//1.1 当前用户是否在pendingClients列表中
if (!RedisUtil.sHas(redisUnPendingClientSetKey,domainTypeAndUserId)) {
logger.info("当前用户不在pendingClients列表中");

2
ccmq/src/main/java/wiki/tall/ccmq/common/bean/dto/ccmodbus/CCModBusEntity.java

@ -48,7 +48,7 @@ public class CCModBusEntity {
public static final int SIZE_MAX = 255;
public static final int SIZE_MAJOR = 1;
public static final int SIZE_MINOR = 1;
public static final int SIZE_MQ = 1;
public static final int SIZE_MQ = 2;
public static final int SIZE_DATA_MAX = SIZE_MAX - SIZE_ADDR - SIZE_OPER - SIZE_CRC - SIZE_FILTER - SIZE_LEN;
public static final int SIZE_MIN = SIZE_FILTER + SIZE_LEN + SIZE_ADDR + SIZE_OPER + SIZE_CRC;
public static final byte ADDRESS = 0x14;

6
ccmq/src/main/resources/application-dev.properties

@ -22,10 +22,10 @@ spring.redis.jedis.pool.min-idle=0
# RabbitMQ配置信息
#spring.rabbitmq.host=49.233.89.188
#spring.rabbitmq.host=192.168.0.99
spring.rabbitmq.host=www.tall.wiki
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=111111
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
# spring.rabbitmq.listener.simple.acknowledge-mode=manual
# MongoDB配置信息

2
ccmq/src/main/resources/application.properties

@ -1,5 +1,5 @@
# 选择开发环境{dev|test|prod}
spring.profiles.active=dev
spring.profiles.active=test
# 设置应用名
spring.application.name=tall-message

Loading…
Cancel
Save