1、推送打印改为debug级别

2、增加中南院MQTT推送
This commit is contained in:
weidong 2025-06-20 09:09:46 +08:00
parent 528003e39e
commit e33ff7aa71
17 changed files with 275 additions and 102 deletions

View File

@ -0,0 +1,19 @@
package com.imdroid.beidou_fwd.entity;
import lombok.Data;
/**
* MQTT数据推送 api
*
* @author LiGang
*/
@Data
public class ZNYMQTTData {
private String timestamp;
// gnss数据
private double rpose;
private double rposn;
private double rposu;
}

View File

@ -266,11 +266,11 @@ public class Forwarder {
updateWrapper.ge("createtime", LocalDateTime.now().minusDays(30));
updateWrapper.set("state",ResendRecord.STATE_FWDING);
int updateNum = resendRecordMapper.update(null, updateWrapper);
logger.info("{} forward history records: {}, update {}",fwdGroupId, resendRecordsList.size(),updateNum);
logger.debug("{} forward history records: {}, update {}",fwdGroupId, resendRecordsList.size(),updateNum);
// 2.检索这个这个时间段的解算结果如果有数据则单个终端转发标志记录为已补传
for(ResendRecord record:resendRecordsList){
if(record.getProjectid()!=null)
logger.info("{} forward history {}",fwdGroupId, record.getProjectid());
logger.debug("{} forward history {}",fwdGroupId, record.getProjectid());
forwardBatchGnssRecords(record);
}
}
@ -404,7 +404,7 @@ public class Forwarder {
tranData.setDeviceType(2);
tranData.setDeviceSn(locationRecord.getDeviceid());
String json = GsonUtil.toJson(tranData);
logger.info("forward to GZY mqtt: {}",json);
logger.debug("forward to GZY mqtt: {}",json);
sendNum++;
}

View File

@ -46,7 +46,7 @@ public class GXJKForwarder extends Forwarder {
*/
@Scheduled(cron = "0 0/10 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("gxjk forwardGnss");
logger.debug("gxjk forwardGnss");
forwardCurrentGnss();
}
@ -76,8 +76,8 @@ public class GXJKForwarder extends Forwarder {
sendNum++;
}
String json = "#" + GsonUtil.toJson(sendData) + "!";
logger.info("project " + projectId + ": push calculation result to GXJK");
logger.info(json);
logger.debug("project " + projectId + ": push calculation result to GXJK");
logger.debug(json);
// /slope/项目号-all/gnss/all/publish
String topic = "/slope/"+projectId+"-all/gnss/all/publish";
try {

View File

@ -21,7 +21,7 @@ import java.util.List;
@Configuration
@EnableScheduling
public class GXXfzForwarder extends Forwarder{
private String FORWARDER_NAME = "广西新发展";
private final String FORWARDER_NAME = "广西新发展";
@Value("${xfz.server.host}")
private String host;
@ -69,13 +69,13 @@ public class GXXfzForwarder extends Forwarder{
*/
@Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("xfz forwardGnss");
logger.debug("xfz forwardGnss");
forwardCurrentGnss();
}
/*
@Scheduled(cron = "0 0/10 * * * ?") // 每30分钟执行一次
private void checkDevice() {
//logger.info("zny checkDevice");
//logger.debug("zny checkDevice");
checkOfflineDevice("2345053","2350106","2350124");
}*/
@ -107,8 +107,8 @@ public class GXXfzForwarder extends Forwarder{
sendNum++;
}
String json = "#" + GsonUtil.toJson(xfzTcpMessage) + "!";
logger.info("project " + projectId + ": push calculation result to XFZ");
logger.info(json);
logger.debug("project " + projectId + ": push calculation result to XFZ");
logger.debug(json);
try {
listener.clear();
xfzTcpClient.writeAndFlush(json);

View File

@ -40,7 +40,7 @@ public class GZYForwarder extends Forwarder{
@Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
// @Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("gzy UDP forwardGnss");
logger.debug("gzy UDP forwardGnss");
forwardCurrentGnss();
}
@ -62,8 +62,8 @@ public class GZYForwarder extends Forwarder{
tranData.setZ(d);
gzyData.setTranData(tranData);
String msg = "JGKJ" + GsonUtil.toJson(gzyData) + "#!";
logger.info("forward to GZY");
logger.info(msg);
logger.debug("forward to GZY");
logger.debug(msg);
udpClient.sendMessage(msg);
sendNum++;
}

View File

@ -56,7 +56,7 @@ public class GZYMQTTForwarder extends Forwarder {
@Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
//@Scheduled(cron = "0 0/5 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("gzy mqtt forwardGnss");
logger.debug("gzy mqtt forwardGnss");
forwardCurrentGnss();
//forwardAngleData();
}
@ -77,7 +77,7 @@ public class GZYMQTTForwarder extends Forwarder {
tranData.setDeviceType(2);
tranData.setDeviceSn(locationRecord.getDeviceid());
String json = GsonUtil.toJson(tranData);
logger.info("forward to GZY mqtt: {}",json);
logger.debug("forward to GZY mqtt: {}",json);
try {
if(!mqttClient.publish(topic, json)) break;
Thread.sleep(50);
@ -116,7 +116,7 @@ public class GZYMQTTForwarder extends Forwarder {
tranData.setAngleAz(NumberUtils.scale((double) az,2));
String json = GsonUtil.toJson(tranData);
logger.info("forward to GZY mqtt angles: {}",json);
logger.debug("forward to GZY mqtt angles: {}",json);
try {
if(!mqttClient.publish(topic, json)) break;
Thread.sleep(10);
@ -125,7 +125,7 @@ public class GZYMQTTForwarder extends Forwarder {
}
sendNum++;
}
logger.info("total number of angles sent to GZY: {}",sendNum);
logger.debug("total number of angles sent to GZY: {}",sendNum);
}

View File

@ -55,7 +55,7 @@ public class KingMaForwarder extends Forwarder{
@Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
//@Scheduled(cron = "0 0/5 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("kingma forwardGnss");
logger.debug("kingma forwardGnss");
forwardCurrentGnss();
}
@ -88,12 +88,12 @@ public class KingMaForwarder extends Forwarder{
if(header == null || nowTime.isAfter(lastTokenTime.plusMinutes(59))){
try {
if (!updateToken()) {
logger.info("update token failed!");
logger.debug("update token failed!");
return 0;
}
}
catch (Exception e){
logger.info("update token failed!");
logger.debug("update token failed!");
return 0;
}
lastTokenTime = nowTime;
@ -135,10 +135,10 @@ public class KingMaForwarder extends Forwarder{
sendNum++;
}
String json = GsonUtil.toJson(dataList);
logger.info(json);
logger.debug(json);
String result = HttpUtils.postJson(data_host,header,json);
logger.info("project " + projectId + ": push calculation result to Kingma");
logger.info("result: "+result);
logger.debug("project " + projectId + ": push calculation result to Kingma");
logger.debug("result: "+result);
JSONObject obj = (JSONObject) JSONObject.parse(result);
String msg = obj.getString("message");
if(msg.equals("Success")) return sendNum;

View File

@ -75,7 +75,7 @@ public class SaasForwarder extends Forwarder{
@Scheduled(cron = "0 20,50 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
if(enabled) {
logger.info("saas forwardGnss");
logger.debug("saas forwardGnss");
forwardCurrentGnss();
}
}
@ -107,8 +107,8 @@ public class SaasForwarder extends Forwarder{
sendNum++;
}
String json = "#" + GsonUtil.toJson(tcpMessage) + "!";
logger.info("project " + projectId + ": push calculation result to SAAS");
logger.info(json);
logger.debug("project " + projectId + ": push calculation result to SAAS");
logger.debug(json);
try {
listener.clear();
tcpClient.writeAndFlush(json);

View File

@ -34,14 +34,14 @@ public class ZNYForwarder extends Forwarder{
*/
@Scheduled(cron = "0 0/10 * * * ?") // 每30分钟执行一次
private void checkDevice() {
//logger.info("zny checkDevice");
//logger.debug("zny checkDevice");
//checkNoDataDevice("2345078","2345065","2345073");
//checkNoDataDevice("2345085","2345068","2345075");
}
@Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("zny forwardGnss");
logger.debug("zny forwardGnss");
forwardCurrentGnss();
}
@ -60,12 +60,12 @@ public class ZNYForwarder extends Forwarder{
sendNum++;
}
String json = GsonUtil.toJson(defoData);
logger.info("发送数据到武汉中南设计院平台:{}", json);
logger.debug("发送数据到武汉中南设计院平台:{}", json);
//return sendNum;
try {
String result = HttpUtils.postJson(data_host, json);
logger.info("发送数据到武汉中南设计院平台返回结果:{}", result);
logger.debug("发送数据到武汉中南设计院平台返回结果:{}", result);
JSONObject obj = (JSONObject) JSONObject.parse(result);
String msg = obj.getString("msg");
if (msg.contains("成功")) return sendNum;

View File

@ -34,12 +34,12 @@ public class ZNYForwarder2 extends Forwarder{
*/
@Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("zny2 forwardGnss");
logger.debug("zny2 forwardGnss");
forwardCurrentGnss();
}
@Scheduled(cron = "0 0/10 * * * ?") // 每30分钟执行一次
private void checkDevice() {
//logger.info("zny checkDevice");
//logger.debug("zny checkDevice");
//checkOfflineDevice("2419374","2410188","2410194");
//checkOfflineDevice("2419350","2410232","2410232");
//checkOfflineDevice("2345074","2345065","2345089");
@ -59,12 +59,12 @@ public class ZNYForwarder2 extends Forwarder{
sendNum++;
}
String json = GsonUtil.toJson(defoData);
logger.info("发送数据到武汉中南设计院2.0平台:{}", json);
logger.debug("发送数据到武汉中南设计院2.0平台:{}", json);
//return sendNum;
try {
String result = HttpUtils.postJson(data_host, json);
logger.info("武汉中南设计院2.0平台返回结果:{}", result);
logger.debug("武汉中南设计院2.0平台返回结果:{}", result);
JSONObject obj = (JSONObject) JSONObject.parse(result);
String msg = obj.getString("msg");
if (msg.contains("成功")) return sendNum;

View File

@ -1,14 +1,12 @@
package com.imdroid.beidou_fwd.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imdroid.beidou_fwd.entity.GZYMQTTAngle;
import com.imdroid.beidou_fwd.entity.GZYMQTTData;
import com.imdroid.beidou_fwd.entity.ZNYMQTTData;
import com.imdroid.beidou_fwd.service.MQTTClient;
import com.imdroid.common.util.Des3Utils;
import com.imdroid.common.util.GsonUtil;
import com.imdroid.common.util.NumberUtils;
import com.imdroid.secapi.dto.GnssCalcData;
import com.imdroid.secapi.dto.GnssStatusMsg;
import com.imdroid.secapi.dto.GnssStatusMsgMapper;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,7 +18,6 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
@Component
@ -28,6 +25,10 @@ import java.util.List;
@EnableScheduling
public class ZNYMQTTForwarder extends Forwarder {
static final String FORWARDER_NAME = "中南院MQTT";
static byte[] key = new byte[] { (byte) 0x8c, (byte) 0xc7, 0x2b, 0x05, 0x70, 0x5d, 0x5c, 0x46, (byte) 0xf4, 0x12, (byte) 0xaf, (byte) 0x8c, (byte) 0xbe,
(byte) 0xd5, 0x5a, (byte) 0xad, (byte) 0x8c, (byte) 0xc7, 0x2b, 0x05, 0x70, 0x5d, 0x5c, 0x46 };
static byte[] iv = new byte[] { 0x66, 0x7b, 0x02, (byte) 0xa8, 0x5c, 0x61, (byte) 0xc7, (byte) 0x86 };
@Value("${zny.mqtt.brokerUrl}")
private String brokerUrl;
@Value("${zny.mqtt.username}")
@ -36,8 +37,6 @@ public class ZNYMQTTForwarder extends Forwarder {
private String password;
@Value("${zny.mqtt.clientid}")
private String clientid;
@Value("${mqtt.server.topic}")
private String topic;
@Autowired
GnssStatusMsgMapper statusMsgMapper;
@ -45,7 +44,7 @@ public class ZNYMQTTForwarder extends Forwarder {
@PostConstruct
void registerMe() throws MqttException {
//init(FORWARDER_NAME, "MQTT "+brokerUrl,4,FWD_DEVICE_ALIAS_NAME,30);
init(FORWARDER_NAME, "MQTT "+brokerUrl,4,FWD_DEVICE_ALIAS_NAME,30);
mqttClient = new MQTTClient(brokerUrl, username, password,clientid);
//mqttClient.connect();
}
@ -54,9 +53,9 @@ public class ZNYMQTTForwarder extends Forwarder {
* 每半小时转发GNSS解算结果
*/
//@Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
//@Scheduled(cron = "0 0/5 * * * ?") // 每30分钟执行一次
@Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
private void forwardGnss() {
logger.info("gzy mqtt forwardGnss");
logger.debug("zny mqtt forwardGnss");
forwardCurrentGnss();
//forwardAngleData();
}
@ -66,20 +65,20 @@ public class ZNYMQTTForwarder extends Forwarder {
int sendNum = 0;
for (GnssCalcData locationRecord : records) {
GZYMQTTData tranData = new GZYMQTTData();
tranData.setCollectTime(locationRecord.getCreatetime().format(formatter));
ZNYMQTTData tranData = new ZNYMQTTData();
tranData.setTimestamp(locationRecord.getCreatetime().format(formatter));
double n = NumberUtils.scale(locationRecord.getRposn(), 2);
double e = NumberUtils.scale(locationRecord.getRpose(), 2);
double d = NumberUtils.scale(locationRecord.getRposd(), 2);
tranData.setX(n);
tranData.setY(e);
tranData.setZ(d);
tranData.setDeviceType(2);
tranData.setDeviceSn(locationRecord.getDeviceid());
tranData.setRposn(n);
tranData.setRpose(e);
tranData.setRposu(d);
String json = GsonUtil.toJson(tranData);
logger.info("forward to GZY mqtt: {}",json);
String cryptJson = Des3Utils.encrypt(json,key,iv);
logger.debug("forward to ZNY mqtt: {}, {}",json, cryptJson);
String topic = "/GnssData/"+locationRecord.getDeviceid()+"/Increment";
try {
if(!mqttClient.publish(topic, json)) break;
if(!mqttClient.publish(topic, cryptJson)) break;
Thread.sleep(20);
} catch (Exception e1) {
e1.printStackTrace();
@ -90,43 +89,5 @@ public class ZNYMQTTForwarder extends Forwarder {
return sendNum;
}
void forwardAngleData() {
// 获取最近半小时的状态消息
LocalDateTime sentTime = LocalDateTime.now();
QueryWrapper<GnssStatusMsg> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenantid",tenantId);
queryWrapper.le("createtime",sentTime);
queryWrapper.ge("createtime",sentTime.minusMinutes(fwdCycleMinutes));
queryWrapper.orderByDesc("createtime");
HashMap<String,String> sendDeviceMap = new HashMap<>();
List<GnssStatusMsg> statusMsgs = statusMsgMapper.selectList(queryWrapper);
int sendNum = 0;
for(GnssStatusMsg msg:statusMsgs){
if(sendDeviceMap.get(msg.getDeviceid())!=null) continue;
sendDeviceMap.put(msg.getDeviceid(),msg.getDeviceid());
GZYMQTTAngle tranData = new GZYMQTTAngle();
tranData.setDeviceSn(msg.getDeviceid());
tranData.setCollectTime(msg.getCreatetime().format(formatter));
float x = msg.getRoll()==null?0:msg.getRoll();
float y = msg.getPitch()==null?0:msg.getPitch();
float az = msg.getYaw()==null?0:msg.getYaw();
tranData.setAngleX(NumberUtils.scale((double) x,2));
tranData.setAngleY(NumberUtils.scale((double) y,2));
tranData.setAngleAz(NumberUtils.scale((double) az,2));
String json = GsonUtil.toJson(tranData);
logger.info("forward to GZY mqtt angles: {}",json);
try {
if(!mqttClient.publish(topic, json)) break;
Thread.sleep(20);
} catch (Exception e1) {
e1.printStackTrace();
}
sendNum++;
}
logger.info("total number of angles sent to GZY: {}",sendNum);
}
}

View File

@ -59,4 +59,10 @@ gxjk.mqtt.server.clientid = GXJK_client
sass.server.host = 127.0.0.1
sass.server.port = 9933
sass.server.enabled = false
sass.server.enabled = false
zny.mqtt.brokerUrl=42.194.196.91:51883
zny.mqtt.username=testuser
zny.mqtt.password=Test@20b39#
zny.mqtt.clientid = ZNY_client
zny.mqtt.topic = /GnssData/testgnss/Increment

View File

@ -2,9 +2,11 @@ package com.imdroid.beidou.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imdroid.beidou.common.HttpResult;
import com.imdroid.common.util.HexUtil;
import com.imdroid.secapi.client.HttpResp;
import com.imdroid.secapi.client.RtcmClient;
import com.imdroid.secapi.client.VersionClient;
@ -17,6 +19,7 @@ import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.*;
@ -39,6 +42,8 @@ public class VersionController extends BasicController{
TenantMapper tenantMapper;
@Autowired
VersionClient versionClient;
@Value("${ver_server.connect.cmd}")
String verServerConnectCmd;
@Data
public class FirmwareInfo{
@ -54,8 +59,33 @@ public class VersionController extends BasicController{
}
// 正在升级的设备mapdeviceId <-> UpgradeInfo(高字节升级结果低字节进度)
final ConcurrentHashMap<String, Short> upgradingDeviceList = new ConcurrentHashMap<>();
final Map<String, Short> upgradingDeviceList = new ConcurrentHashMap<>();
final Map<String, String> deviceSNtoFirmwareMap=new HashMap<>();
@PostConstruct
public void init(){
deviceSNtoFirmwareMap.put("2353","2353");
deviceSNtoFirmwareMap.put("2410","2410");
deviceSNtoFirmwareMap.put("2412","2410");
deviceSNtoFirmwareMap.put("2415","2415");
deviceSNtoFirmwareMap.put("2419","2415");
deviceSNtoFirmwareMap.put("2421","2421");
deviceSNtoFirmwareMap.put("2435","2421");
deviceSNtoFirmwareMap.put("2439","2439");
deviceSNtoFirmwareMap.put("2445","2439");
deviceSNtoFirmwareMap.put("8450","8450");
deviceSNtoFirmwareMap.put("8507","8450");
deviceSNtoFirmwareMap.put("8512","8450");
deviceSNtoFirmwareMap.put("8513","8450");
deviceSNtoFirmwareMap.put("8516","8515");
deviceSNtoFirmwareMap.put("8522","8515");
deviceSNtoFirmwareMap.put("9450","9450");
deviceSNtoFirmwareMap.put("9513","9450");
deviceSNtoFirmwareMap.put("9522","9515");
deviceSNtoFirmwareMap.put("6516","6515");
deviceSNtoFirmwareMap.put("6521","6515");
deviceSNtoFirmwareMap.put("6522","6515");
}
/**** 推送页面 *****/
@RequestMapping("/sys/ver_mgr")
public String gnssDevCfg(Model m, HttpSession session) {
@ -150,17 +180,22 @@ public class VersionController extends BasicController{
public HttpResult upgradeApp(@RequestParam String firmware, @RequestParam String id_list) throws Exception {
HttpResp rsp;
if(firmware!=null && !firmware.equals("undefined")) {
String[] deviceList = id_list.split(";");
//请求版本服务升级
try {
rsp = versionClient.upgrade(id_list, firmware);
System.out.println(id_list);
String invalidId = checkUpgradeList(deviceList, firmware);
if(invalidId==null) {
rsp = versionClient.upgrade(id_list, firmware);
}
else return HttpResult.fail("设备型号和固件不匹配:"+invalidId);
//System.out.println(id_list);
}
catch (Exception e){
return HttpResult.fail("版本服务未启动");
}
if(rsp.getCode() == HttpResp.HTTP_RSP_OK){
//设置设备的使用状态为升级下发连接版本服务器指令
startUpgrade(deviceList);
return HttpResult.success("开始升级");
}
else{
@ -204,11 +239,29 @@ public class VersionController extends BasicController{
return files.length;
}
void startUpgrade(String id_list){
String[] deviceList = id_list.split(",");
String checkUpgradeList(String[] deviceList, String firmware){
for(String deviceId:deviceList){
String snHigh = deviceId.substring(0,4);
if(!firmware.contains(deviceSNtoFirmwareMap.get(snHigh))){
return deviceId;
}
}
return null;
}
void startUpgrade(String[] deviceList){
for(String deviceId:deviceList){
UpdateWrapper<GnssDevice> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("deviceid",deviceId).set("opmode",GnssDevice.OP_MODE_UPGRADING);
gnssDeviceMapper.update(null, updateWrapper);
rtcmClient.config(deviceId,getConnectVerServerCmd(deviceId));
}
}
String getConnectVerServerCmd(String deviceId){
short len = (short) (verServerConnectCmd.length() + 5);
return "d31a" + HexUtil.Short2HexString(len)+
HexUtil.Int2HexString(Integer.parseInt(deviceId))+
"01"+HexUtil.String2HexString(verServerConnectCmd);
}
}

View File

@ -0,0 +1,109 @@
package com.imdroid.common.util;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.nio.charset.StandardCharsets;
import java.security.Key;
public class Des3Utils {
private static final String KEY_ALGORITHM = "DESede";
private static final String CIPHER_ALGORITHM_CBC = "DESede/CBC/PKCS5Padding";
private static final String CIPHER_ALGORITHM_ECB = "DESede/ECB/PKCS5Padding";
static String mode = "DESede/CFB/NoPadding";
public static byte[] encrypt(Key deskey, IvParameterSpec desiv, String mode, byte[] data) {
byte[] res = null;
Cipher cipher;
try {
cipher = Cipher.getInstance(mode);
cipher.init(Cipher.ENCRYPT_MODE, deskey, desiv);
res = cipher.doFinal(data);
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
public static String encrypt(String data, byte[] key, byte[] iv) {
String res = "";
ByteBuf buf = Unpooled.buffer(256);
byte[] databyte = data.getBytes(StandardCharsets.UTF_8);
buf.writeBytes(databyte);
int a = (8 - databyte.length % 8);
for (int c = 0; c < a; c++) {
buf.writeByte(0x00);
}
databyte = new byte[buf.readableBytes()];
buf.readBytes(databyte);
DESedeKeySpec spec;
SecretKeyFactory keyfactory;
Key deskey;
try {
keyfactory = SecretKeyFactory.getInstance("DESede");
spec = new DESedeKeySpec(key);
deskey = keyfactory.generateSecret(spec);
IvParameterSpec desiv = new IvParameterSpec(iv);
byte[] encryptbyte = encrypt(deskey, desiv, mode, databyte);
res = Base64.encodeBase64String(encryptbyte);
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
public static String encryptCBC(byte[] key, byte[] iv, String data) throws Exception {
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
Key desKey = keyFactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance(mode);
IvParameterSpec ips = new IvParameterSpec(iv);
cipher.init(Cipher.ENCRYPT_MODE, desKey, ips);
byte[] encryptedData = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBase64String(encryptedData);
}
public static String decryptCBC(byte[] key, byte[] iv, String data) throws Exception {
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
Key desKey = keyFactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM_CBC);
IvParameterSpec ips = new IvParameterSpec(iv);
cipher.init(Cipher.DECRYPT_MODE, desKey, ips);
byte[] decryptedData = cipher.doFinal(Base64.decodeBase64(data));
return new String(decryptedData, StandardCharsets.UTF_8);
}
public static String encryptECB(byte[] key, String data) throws Exception {
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
Key desKey = keyFactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM_ECB);
cipher.init(Cipher.ENCRYPT_MODE, desKey);
byte[] encryptedData = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBase64String(encryptedData);
}
public static String decryptECB(byte[] key, String data) throws Exception {
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
Key desKey = keyFactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM_ECB);
cipher.init(Cipher.DECRYPT_MODE, desKey);
byte[] decryptedData = cipher.doFinal(Base64.decodeBase64(data));
return new String(decryptedData, StandardCharsets.UTF_8);
}
}

View File

@ -0,0 +1,25 @@
package com.imdroid.vermgr;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
/**
* @author Layton
* @date 2023/1/31 20:33
*/
@SpringBootApplication(scanBasePackages = {"com.imdroid"})
@MapperScan({"com.imdroid.secapi","com.imdroid.beidou.entity"})
@ComponentScan({"com.imdroid.*"})
@EntityScan({"com.imdroid.*"})
@EnableFeignClients(basePackages = "com.imdroid.*")
public class VerMgrApp {
public static void main(String[] args) {
SpringApplication.run(VerMgrApp.class, args);
}
}

View File

@ -56,7 +56,7 @@ public class UpgradeManager {
@PostMapping("/upgrade_cmd")
HttpResp upgrade(@RequestParam(name = "deviceList") String deviceList, @RequestParam(name = "verFile") String verFile){
HttpResp resp = new HttpResp();
if(onRxUpgradeDeviceList(deviceList.split(","),verFile)){
if(onRxUpgradeDeviceList(deviceList.split(";"),verFile)){
resp.setCode(HttpResp.HTTP_RSP_OK);
}
else{

View File

@ -127,7 +127,7 @@ public class UpgradeSession {
else {
long sn = deviceApp.getDevice_sn();
byte[] ind_msg = new byte[5];
ind_msg[0] = VerManager.UPGRADE_IND;
ind_msg[0] = UpgradeManager.UPGRADE_IND;
ind_msg[1] = (byte) (sn >> 24);
ind_msg[2] = (byte) (sn >> 16);
ind_msg[3] = (byte) (sn >> 8);