Files
UniversalTestSoftware/client/script/pretreatment/Pretreatment_decd90acf4a122b4b2117dc43b4eeb7e.java

65 lines
3.0 KiB
Java
Raw Normal View History

package com.cbsd.client.pretreatment;
import com.cbsd.client.pretreatment.CalculateUtils;
import com.cbsd.client.pretreatment.IPreTreatmentInterface;
import java.util.Map;
public class Pretreatment_decd90acf4a122b4b2117dc43b4eeb7e implements IPreTreatmentInterface {
/**
* 预处理
* @param command 指令内容
* @param repeatCount 重复次数
* @param hitCount 命中次数
* @param latestHitTime 最后命中时间
* @param dataMap 数据集合key为协议字段属性名labelvalue为物理值
* @param calculateUtils 计算工具类
* @return 结果
*/
@Override
public String pretreatment(String command, int repeatCount, int hitCount, String latestHitTime, Map<String, String> dataMap, CalculateUtils calculateUtils) {
// 卫星时间预处理相关字符串变量
String messageTypeAndLength = "8206"; // 消息类型和长度
// 计算weekCount每6048000个hitCount为一周
int weekValue = hitCount / 6048000; // 计算完整的周数
String weekCount = String.format("%04X", weekValue); // 转换为4位十六进制字符串
// 计算secondCounthitCount表示多少个100ms除以10得到多少个1秒
int adjustedHitCount = hitCount % 6048000; // 对6048000取模实现周期性重置
int secondValue = adjustedHitCount / 10; // 每秒有10个100ms所以用hitCount除以10
String secondCount = String.format("%06X", secondValue); // 转换为6位十六进制字符串
// 计算hundredMsCount根据hitCount在01-0F之间循环变化
int hundredMsValue = ((hitCount - 1) % 15) + 1; // 在1-15(0x1-0xF)之间循环
String hundredMsCount = String.format("%02X", hundredMsValue); // 转换为2位十六进制字符串
// 计算checkWord将前面的字节数据单个字节挨个异或最终结果是一个字节后面补两个零
// 首先将各个字段转换为字节数组
String combinedData = messageTypeAndLength + weekCount + secondCount + hundredMsCount;
// 将组合数据按字节进行异或运算
int xorResult = 0;
for (int i = 0; i < combinedData.length(); i += 2) { // 每次处理两个字符(一个字节)
String byteStr = combinedData.substring(i, i + 2);
int byteValue = Integer.parseInt(byteStr, 16); // 将十六进制字符串转换为整数
xorResult ^= byteValue; // 与当前字节进行异或运算
}
String checkWord = String.format("%02X", xorResult) + "00"; // 将异或结果扩展为4位十六进制字符串后面补两个0
// 将所有字段按数据拼接在一起
String result = messageTypeAndLength + weekCount + secondCount + hundredMsCount + checkWord;
return result;
}
/**
* 描述
*
* @return 描述内容
*/
@Override
public String comment() {
return "";
}
}