plc-s7驱动开发

This commit is contained in:
2026-03-04 17:49:38 +08:00
parent 79ce8f976b
commit 21bdd8bda1
42 changed files with 4513 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2016-present the IoT DC3 original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.nl.common.exception;
/**
* 异常 相关常量
*
* @author pnoker
* @version 2025.9.0
* @since 2022.1.0
*/
public class ExceptionConstant {
/**
* 公共类实例化错误提示
*/
public static final String UTILITY_CLASS = "Utility class";
/**
* 没有可用的服务
*/
public static final String NO_AVAILABLE_SERVER = "No available server for client";
/**
* 租户, 用户信息不匹配
*/
public static final String NO_AVAILABLE_AUTH = "Tenant, user information does not match";
private ExceptionConstant() {
throw new IllegalStateException(ExceptionConstant.UTILITY_CLASS);
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright 2016-present the IoT DC3 original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.nl.common.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.nl.common.exception.ExceptionConstant;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HexFormat;
/**
* 编码 相关工具类
*
* @author pnoker
* @version 2025.9.0
* @since 2022.1.0
*/
@Slf4j
public class DecodeUtil {
private DecodeUtil() {
throw new IllegalStateException(ExceptionConstant.UTILITY_CLASS);
}
/**
* 字节转字符串
* <p>
* UTF-8
*
* @param bytes 字节数组
* @return 字符串
*/
public static String byteToString(byte[] bytes) {
return new String(bytes, StandardCharsets.UTF_8);
}
/**
* 字符串转字节
* <p>
* UTF-8
*
* @param content 字符串
* @return 字节数组
*/
public static byte[] stringToByte(String content) {
return content.getBytes(StandardCharsets.UTF_8);
}
/**
* 获取 MD5 编码
*
* @param content 字符串
* @return MD5 字符串
*/
public static String md5(String content) {
return DigestUtils.md5Hex(content);
}
/**
* 获取 MD5 编码
*
* @param content 字符串
* @param salt 盐值
* @return MD5 字符串
*/
public static String md5(String content, String salt) {
return md5(content + salt);
}
/**
* 将字节流进行Base64编码
*
* @param bytes Byte Array
* @return Byte Array
*/
public static byte[] encode(byte[] bytes) {
return Base64.getEncoder().encode(bytes);
}
/**
* 将字符串进行Base64编码
*
* @param content 字符串
* @return Byte Array
*/
public static byte[] encode(String content) {
return encode(stringToByte(content));
}
/**
* 必须配合encode使用, 用于encode编码之后解码
*
* @param bytes Byte Array
* @return Byte Array
*/
public static byte[] decode(byte[] bytes) {
return Base64.getDecoder().decode(bytes);
}
/**
* 必须配合encode使用, 用于encode编码之后解码
*
* @param content 字符串
* @return Byte Array
*/
public static byte[] decode(String content) {
return decode(stringToByte(content));
}
/**
* 将字符串进行16进制编码
*
* @param content 字符串
* @return String
*/
public static String enHexCode(String content) {
return HexFormat.of().formatHex((stringToByte(content)));
}
/**
* 必须配合enHexCode使用, 用于enHexCode编码之后解码
*
* @param content 字符串
* @return Byte Array
*/
public static byte[] deHexCode(String content) {
return HexFormat.of().parseHex(content);
}
}