65 lines
1.9 KiB
Java
65 lines
1.9 KiB
Java
|
|
package com.cbsd.client.pretreatment;
|
|||
|
|
|
|||
|
|
import com.cbsd.client.pretreatment.CalculateUtils;
|
|||
|
|
import com.cbsd.client.pretreatment.IPreTreatmentInterface;
|
|||
|
|
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
public class Pretreatment_1840c817327c7a4109270605898ba82d implements IPreTreatmentInterface {
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 预处理
|
|||
|
|
* @param command 指令内容
|
|||
|
|
* @param repeatCount 重复次数
|
|||
|
|
* @param hitCount 命中次数
|
|||
|
|
* @param latestHitTime 最后命中时间
|
|||
|
|
* @param dataMap 数据集合,key为协议字段属性名(label),value为物理值
|
|||
|
|
* @param calculateUtils 计算工具类
|
|||
|
|
* @return 结果
|
|||
|
|
*/
|
|||
|
|
@Override
|
|||
|
|
public String pretreatment(String command, int repeatCount, int hitCount, String latestHitTime, Map<String, String> dataMap, CalculateUtils calculateUtils) {
|
|||
|
|
// 使用正则表达式分割命令,支持中文和英文逗号
|
|||
|
|
if (command == null) {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
String[] parts = command.split(",|,");
|
|||
|
|
|
|||
|
|
// 检查hitCount是否在有效范围内
|
|||
|
|
if (hitCount < 1 || hitCount > parts.length) {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 获取对应位置的数据
|
|||
|
|
String selectedData = parts[hitCount-1].trim();
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// 将数据转换为长整型
|
|||
|
|
long numericValue = Long.parseLong(selectedData);
|
|||
|
|
|
|||
|
|
// 将数值转换为40位二进制字符串
|
|||
|
|
String binaryStr = Long.toBinaryString(numericValue);
|
|||
|
|
|
|||
|
|
// 确保是40位,前面补0
|
|||
|
|
while (binaryStr.length() < 40) {
|
|||
|
|
binaryStr = "0" + binaryStr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return binaryStr;
|
|||
|
|
} catch (NumberFormatException e) {
|
|||
|
|
// 如果转换失败,返回空字符串
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 描述
|
|||
|
|
*
|
|||
|
|
* @return 描述内容
|
|||
|
|
*/
|
|||
|
|
@Override
|
|||
|
|
public String comment() {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|