|
@@ -4,19 +4,18 @@ import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.io.file.FileReader;
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import com.ruoyi.advertiser25.domain.AdFirmwareUpgrade25;
|
|
|
import com.ruoyi.advertiser25.domain.AdHandle25;
|
|
|
import com.ruoyi.advertiser25.domain.AdHeartbeatData25;
|
|
|
+import com.ruoyi.advertiser25.domain.Upgrade25;
|
|
|
import com.ruoyi.advertiser25.domain.dto.CarouselPlanRedisDto25;
|
|
|
import com.ruoyi.advertiser25.domain.dto.ImageBindDto;
|
|
|
-import com.ruoyi.advertiser25.service.IScreenDeviceService;
|
|
|
-import com.ruoyi.advertiser25.service.IDeviceHeartbeatService;
|
|
|
-import com.ruoyi.advertiser25.service.IRotationPlanService;
|
|
|
-import com.ruoyi.advertiser25.service.ISysParamService;
|
|
|
+import com.ruoyi.advertiser25.mapper.ScreenMaterialMapper;
|
|
|
+import com.ruoyi.advertiser25.service.*;
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.mcu25.config.McuSm4KeyConfig25;
|
|
|
+import com.ruoyi.mcu25.config.McuSocketConfig25;
|
|
|
import com.ruoyi.mcu25.constant.*;
|
|
|
import com.ruoyi.mcu25.domain.AdHeartBeatPackage25;
|
|
|
import com.ruoyi.mcu25.domain.AdMessageBody25;
|
|
@@ -57,6 +56,15 @@ public class DealServer25 {
|
|
|
@Resource(name= "deviceHeartbeatServiceImpl")
|
|
|
private IDeviceHeartbeatService adHeartbeatDataService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IUpgradeService upgradeService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private McuSocketConfig25 mcuSocketConfig25;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ScreenMaterialMapper screenMaterialMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 处理心跳包
|
|
|
* @param beatPack
|
|
@@ -153,18 +161,21 @@ public class DealServer25 {
|
|
|
info[i++] = (byte) ((msgLen >> 8) & 0xff);
|
|
|
info[i++] = (byte) ((msgLen) & 0xff);
|
|
|
// 根据屏幕类型、硬件版本查询最新的固件包
|
|
|
- AdFirmwareUpgrade25 adFirmwareUpgrade25 = null;
|
|
|
+ String screenType = Convert.toHex(equipmentType);
|
|
|
+ Integer hardwareVersion = Integer.parseInt(Integer.toHexString(beatPack.getDeviceInfo().getHw())) ;
|
|
|
+ Upgrade25 param = new Upgrade25().setScreenType(screenType).setHardwareVersion(hardwareVersion).setPublishStatus("1");
|
|
|
+ Upgrade25 upgrade25 = upgradeService.selectLatestFirmware(param);
|
|
|
// 硬件版本
|
|
|
info[i++] = McuBeatPackTagConstant25.TAG_DEV_HW_REV;
|
|
|
info[i++] = 0x00;
|
|
|
info[i++] = 0x01;
|
|
|
- info[i++] = 0x10;
|
|
|
+ info[i++] = upgrade25 != null ? Convert.hexToBytes(upgrade25.getHardwareVersion().toString())[0] : 0x10;
|
|
|
// 软件版本:如果没有固件包,就不传
|
|
|
- if (adFirmwareUpgrade25 != null) {
|
|
|
+ if (upgrade25 != null) {
|
|
|
info[i++] = McuBeatPackTagConstant25.TAG_DEV_SW_REV;
|
|
|
info[i++] = 0x00;
|
|
|
info[i++] = 0x01;
|
|
|
- String softwareVersion = adFirmwareUpgrade25.getMajorVersion().toString() + adFirmwareUpgrade25.getSubVersion().toString();
|
|
|
+ String softwareVersion = upgrade25.getMajorVersion().toString() + upgrade25.getSubVersion().toString();
|
|
|
info[i++] = Convert.hexToBytes(softwareVersion)[0];
|
|
|
}
|
|
|
// 心跳周期
|
|
@@ -282,6 +293,176 @@ public class DealServer25 {
|
|
|
return crc16Data;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 演示模式的上行心跳
|
|
|
+ * @param beatPack
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public byte[] upBeatReply1(AdHeartBeatPackage25 beatPack) {
|
|
|
+ String imei=beatPack.getImeiStr();
|
|
|
+
|
|
|
+ //如果数据库没有拉手数据,则不回复心跳。忽略该条心跳数据
|
|
|
+ AdHandle25 adHandle25Local = adHandleService.selectAdHandleByImei(imei);
|
|
|
+ if(adHandle25Local ==null){
|
|
|
+ log.info("数据库没有此拉手数据:" + imei);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ AdHandle25 adHandle25 =null;
|
|
|
+ try {
|
|
|
+ // 存储心跳数据
|
|
|
+ AdHeartbeatData25 adHeartbeatData25 = decodingAdHeartbeatData(beatPack.getDeviceInfo());
|
|
|
+ // 不需要保存首位的0
|
|
|
+ adHeartbeatData25.setImei(imei);
|
|
|
+ //存入数据库
|
|
|
+ adHeartbeatDataService.insertAdHeartbeatData(adHeartbeatData25);
|
|
|
+ // 根据心跳修改拉手信息
|
|
|
+ adHandle25 = new AdHandle25();
|
|
|
+ // 15位的imei
|
|
|
+ adHandle25.setImei(adHeartbeatData25.getImei());
|
|
|
+ adHandle25.setIccid(adHeartbeatData25.getIccid());
|
|
|
+ adHandle25.setOnlineStatus("1");
|
|
|
+ adHandle25.setSoftwareVersion(adHeartbeatData25.getSw());
|
|
|
+ adHandle25.setHardwareVersion(adHeartbeatData25.getHw());
|
|
|
+ adHandle25.setUpdateTime(new Date());
|
|
|
+ try {
|
|
|
+ adHandleService.updateHandleByHeartbeat(adHandle25);
|
|
|
+ }catch(Exception e2){
|
|
|
+ log.error("更新拉手信息发生错误:adHandle:{}", adHandle25);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据转换异常:", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("已接收到MCU发来的普通心跳包,开始解析并回复心跳包。。。<br/>");
|
|
|
+
|
|
|
+ //获取演示模式图片
|
|
|
+ Map imageSeq = screenMaterialMapper.selectDemoPic();
|
|
|
+
|
|
|
+ // 获取音频--@TODO
|
|
|
+ Map audioSeq = imageSeq;
|
|
|
+
|
|
|
+ // 服务器地址
|
|
|
+ byte[] downHttpSeq = Convert.hexToBytes(Convert.toHex(mcuSocketConfig25.getHttpServer(), CharsetUtil.CHARSET_UTF_8));
|
|
|
+
|
|
|
+ int imgLen = 1 * 4 * 2; // 图片序号4字节+创建时间2字节
|
|
|
+ int audLen = 1 * 4 * 2; // 音频长度
|
|
|
+ int len = imgLen + audLen + downHttpSeq.length + 1;
|
|
|
+
|
|
|
+ byte[] info = new byte[len + 3000];
|
|
|
+ int i = 0; // info数组下标
|
|
|
+ // 包头
|
|
|
+ info[i++] = McuBeatPackHeadAndTailConstant25.PACKAGE_HEAD;
|
|
|
+ // IMEI
|
|
|
+ byte[] imeiByte = DataTransitionUtil25.intsToBytes(beatPack.getIMEI());
|
|
|
+ System.arraycopy(imeiByte, 0, info, i, imeiByte.length);
|
|
|
+ i += imeiByte.length;
|
|
|
+ // 协议版本
|
|
|
+ info[i++] = 0x10;
|
|
|
+ // 设备类型
|
|
|
+ byte[] equipmentType = DataTransitionUtil25.intsToBytes(beatPack.getEquipmentType());
|
|
|
+ System.arraycopy(equipmentType, 0, info, i, equipmentType.length);
|
|
|
+ i += equipmentType.length;
|
|
|
+ // 包序号
|
|
|
+ info[i++] = (byte) ((beatPack.getPackageSeq() >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) (beatPack.getPackageSeq() & 0xff);
|
|
|
+ // 标识
|
|
|
+ info[i++] = McuBeatIdentificationConstant25.BEAT_IDENTIFICATION_0X00;
|
|
|
+ // 包类型
|
|
|
+ info[i++] = McuBeatPackTypeConstant25.DOWN_BEAT_PACKAGE_TYPE;
|
|
|
+ // 心跳包回复标签数量
|
|
|
+ info[i++] = McuOtherConstant25.BEAT_PACKAGE_REPLY_LABEL_NUM_1;
|
|
|
+ // 消息体长度
|
|
|
+ int msgLen = len + McuOtherConstant25.BEAT_PACKAGE_REPLY_ELSE_LENGTH_1;
|
|
|
+ int msgLenIndex = i; //消息体长度下标
|
|
|
+ info[i++] = (byte) ((msgLen >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((msgLen) & 0xff);
|
|
|
+ // 根据屏幕类型、硬件版本查询最新的固件包
|
|
|
+ String screenType = Convert.toHex(equipmentType);
|
|
|
+ Integer hardwareVersion = Integer.parseInt(Integer.toHexString(beatPack.getDeviceInfo().getHw())) ;
|
|
|
+ Upgrade25 param = new Upgrade25().setScreenType(screenType).setHardwareVersion(hardwareVersion).setPublishStatus("1");
|
|
|
+ Upgrade25 upgrade25 = upgradeService.selectLatestFirmware(param);
|
|
|
+ // 硬件版本
|
|
|
+ info[i++] = McuBeatPackTagConstant25.TAG_DEV_HW_REV;
|
|
|
+ info[i++] = 0x00;
|
|
|
+ info[i++] = 0x01;
|
|
|
+ info[i++] = upgrade25 != null ? Convert.hexToBytes(upgrade25.getHardwareVersion().toString())[0] : 0x10;
|
|
|
+ // 软件版本:如果没有固件包,就不传
|
|
|
+ if (upgrade25 != null) {
|
|
|
+ info[i++] = McuBeatPackTagConstant25.TAG_DEV_SW_REV;
|
|
|
+ info[i++] = 0x00;
|
|
|
+ info[i++] = 0x01;
|
|
|
+ String softwareVersion = upgrade25.getMajorVersion().toString() + upgrade25.getSubVersion().toString();
|
|
|
+ info[i++] = Convert.hexToBytes(softwareVersion)[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 服务器端设备绑定图片列表-25寸
|
|
|
+ info[i++] = McuBeatPackTagConstant25.TAG_DEV_SERVER_IMAGE_INFO_25;
|
|
|
+ int bindiImageNum = 1; // 图片数量
|
|
|
+ int lenTag0E = bindiImageNum * 4 * 2 + 2;
|
|
|
+ info[i++] = (byte) ((lenTag0E >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((lenTag0E) & 0xff);
|
|
|
+
|
|
|
+ info[i++] = (byte) ((bindiImageNum >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((bindiImageNum) & 0xff);
|
|
|
+
|
|
|
+ int picId = Integer.valueOf(imageSeq.get("regId").toString());
|
|
|
+ info[i++] = (byte) ((picId >> 24) & 0xff);
|
|
|
+ info[i++] = (byte) ((picId >> 16) & 0xff);
|
|
|
+ info[i++] = (byte) ((picId >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((picId) & 0xff);
|
|
|
+ byte[] picTime = Convert.hexToBytes(imageSeq.get("signTime").toString());
|
|
|
+ info[i++] = picTime[0];
|
|
|
+ info[i++] = picTime[1];
|
|
|
+ info[i++] = picTime[2];
|
|
|
+ info[i++] = picTime[3];
|
|
|
+
|
|
|
+ // 绑定音频列表
|
|
|
+ info[i++] = McuBeatPackTagConstant25.TAG_DEV_SERVER_AUDIO_INFO;
|
|
|
+ int bindAudioNum = 1; // 图片数量
|
|
|
+ int lenTag13 = bindAudioNum * 4 * 2 + 2;
|
|
|
+ info[i++] = (byte) ((lenTag13 >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((lenTag13) & 0xff);
|
|
|
+
|
|
|
+ info[i++] = (byte) ((bindAudioNum >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((bindAudioNum) & 0xff);
|
|
|
+
|
|
|
+ int audId = Integer.valueOf(imageSeq.get("regId").toString());
|
|
|
+ info[i++] = (byte) ((audId >> 24) & 0xff);
|
|
|
+ info[i++] = (byte) ((audId >> 16) & 0xff);
|
|
|
+ info[i++] = (byte) ((audId >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((audId) & 0xff);
|
|
|
+ byte[] audTime = Convert.hexToBytes(imageSeq.get("signTime").toString());
|
|
|
+ info[i++] = audTime[0];
|
|
|
+ info[i++] = audTime[1];
|
|
|
+ info[i++] = audTime[2];
|
|
|
+ info[i++] = audTime[3];
|
|
|
+
|
|
|
+ // 绑定 HTTP 服务器地址
|
|
|
+ info[i++] = McuBeatPackTagConstant25.TAG_DEV_SERVER_DOWN_HTTP;
|
|
|
+ int downHttpNum = downHttpSeq.length; // 图片数量
|
|
|
+ int lenTag25 = downHttpNum + 2;
|
|
|
+ info[i++] = (byte) ((lenTag25 >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((lenTag25) & 0xff);
|
|
|
+
|
|
|
+ info[i++] = (byte) ((downHttpNum >> 8) & 0xff);
|
|
|
+ info[i++] = (byte) ((downHttpNum) & 0xff);
|
|
|
+ System.arraycopy(downHttpSeq, 0, info, i, downHttpSeq.length);
|
|
|
+ i += downHttpSeq.length;
|
|
|
+ // 工作模式设置
|
|
|
+ info[i++] = McuBeatPackTagConstant25.TAG_DEV_WORK_STATUS;
|
|
|
+ info[i++] = (byte) (0x00);
|
|
|
+ info[i++] = (byte) (0x03);
|
|
|
+ info[i++] = (byte) (0x00);
|
|
|
+
|
|
|
+ // end
|
|
|
+
|
|
|
+ info[msgLenIndex++] = (byte) (((i - 19) >> 8) & 0xff);
|
|
|
+ info[msgLenIndex++] = (byte) (((i - 19)) & 0xff);
|
|
|
+
|
|
|
+ byte[] crc16Data = getCrc16Data(i, info, beatPack, msgLenIndex);
|
|
|
+ return crc16Data;
|
|
|
+ }
|
|
|
+
|
|
|
private AdHeartbeatData25 decodingAdHeartbeatData(AdMessageBody25 messageBody) {
|
|
|
AdHeartbeatData25 obj = new AdHeartbeatData25();
|
|
|
obj.setCsq(messageBody.getCsq());
|
|
@@ -620,19 +801,19 @@ public class DealServer25 {
|
|
|
return BaseTag25.reply(beatPack, McuBeatIdentificationConstant25.BEAT_IDENTIFICATION_0X80,
|
|
|
McuBeatPackTypeConstant25.UPGRADE_PACKAGE_TYPE, tagList);
|
|
|
}
|
|
|
- // 固件包下载
|
|
|
|
|
|
+ // 固件包下载
|
|
|
log.info("imei:{},下载升级包数据,当前包序号为:{}。。。<br/>", imei, beatPack.getPackageSeq());
|
|
|
// 根据屏幕类型、硬件版本查询最新的固件包
|
|
|
AdMessageBody25 deviceInfo = beatPack.getDeviceInfo();
|
|
|
String screenType = Convert.toHex(DataTransitionUtil25.intsToBytes(beatPack.getEquipmentType()));
|
|
|
Integer hardwareVersion = Integer.parseInt(Integer.toHexString(beatPack.getDeviceInfo().getHw())) ;
|
|
|
- AdFirmwareUpgrade25 param = new AdFirmwareUpgrade25().setScreenType(screenType).setHardwareVersion(hardwareVersion).setPublishStatus("1");
|
|
|
- AdFirmwareUpgrade25 adFirmwareUpgrade25 = null;
|
|
|
- if (adFirmwareUpgrade25 == null) {
|
|
|
+ Upgrade25 param = new Upgrade25().setScreenType(screenType).setHardwareVersion(hardwareVersion).setPublishStatus("1");
|
|
|
+ Upgrade25 upgrade25 = upgradeService.selectLatestFirmware(param);
|
|
|
+ if (upgrade25 == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- String filePath = RuoYiConfig.getProfile() + adFirmwareUpgrade25.getAttachment().replace("/profile", "");
|
|
|
+ String filePath = RuoYiConfig.getProfile() + upgrade25.getAttachment().replace("/profile", "");
|
|
|
FileReader fileReader = new FileReader(filePath);
|
|
|
byte[] fileDatas = fileReader.readBytes();
|
|
|
|
|
@@ -674,7 +855,7 @@ public class DealServer25 {
|
|
|
resDatas[index++] = McuBeatPackTagConstant25.TAG_DEV_HW_REV;
|
|
|
resDatas[index++] = 0x00;
|
|
|
resDatas[index++] = 0x01;
|
|
|
- resDatas[index++] = Convert.hexToBytes(adFirmwareUpgrade25.getHardwareVersion().toString())[0];
|
|
|
+ resDatas[index++] = Convert.hexToBytes(upgrade25.getHardwareVersion().toString())[0];
|
|
|
// tlv t:下载升级文件传输
|
|
|
resDatas[index++] = McuBeatPackTagConstant25.TAG_DEV_UPGRADE_TRANSFER;
|
|
|
// tlv l:t(0x18)的长度 固件包数据长度 + 6个字节的长度
|