| | |
| | | import com.sandu.ximon.dao.enums.OrderStatus; |
| | | import com.sandu.ximon.dao.mapper.C3mChargingMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | * |
| | | * @return 是否成功 |
| | | */ |
| | | @SneakyThrows |
| | | public boolean saveReporEquipment(String deviceName, String mcuUdid, String c3Mac) { |
| | | C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, mcuUdid)); |
| | | boolean flag; |
| | |
| | | String date = new SimpleDateFormat("yyMMddHHmmss").format(new Date()); |
| | | String s = SetCalendar(c3Mac, Integer.parseInt(date.substring(0, 2)), Integer.parseInt(date.substring(2, 4)), |
| | | Integer.parseInt(date.substring(4, 6)), Integer.parseInt(date.substring(6, 8)), |
| | | Integer.parseInt(date.substring(8, 10)), Integer.parseInt(date.substring(10, 12))); |
| | | Integer.parseInt(date.substring(8, 10)), Integer.parseInt(date.substring(10, 12)), true); |
| | | if (!"操作成功".equals(s)) { |
| | | LogUtils.error("发送设置C3时间同步失败!"); |
| | | return false; |
| | | } |
| | | System.out.println("同步时间戳结束"); |
| | | |
| | | Thread.sleep(1000); |
| | | |
| | | //设置费率 |
| | | System.out.println("设置费率开始"); |
| | |
| | | if (list.size() == 0) {//费率表中没有此充电桩数据时 添加默认费率 |
| | | c3mChargingChargeService.initCharge((c3mCharging1.getC3Id()).intValue()); |
| | | } |
| | | String rateState = setRate(c3Mac, list); |
| | | String rateState = setRate(c3Mac, list, true); |
| | | System.out.println("设置费率结果:" + rateState); |
| | | System.out.println("设置费率结束"); |
| | | |
| | | Thread.sleep(1000); |
| | | |
| | | |
| | | /** 跳包时间同步 |
| | | * 设置时间规则:充电时为1倍,非充电状态为1.5倍时间 |
| | |
| | | Set<String> keys = RedisUtils.getBean().keys(C3mRedisConstant.C3_STATUS.getCode() + "*"); |
| | | |
| | | C3mRedisConfig.reFlushTime(keys.size()); |
| | | String time1 = SetHeartbeatPacketTimeCharging(c3Mac, C3mRedisConfig.parseInt(C3mRedisConfig.HEART_BEAT_TIME) * 2, false); |
| | | String time1 = SetHeartbeatPacketTimeCharging(c3Mac, C3mRedisConfig.parseInt(C3mRedisConfig.HEART_BEAT_TIME) * 2, false, true); |
| | | LogUtils.error("C3空闲心跳包时间同步响应结果:" + time1); |
| | | String time2 = SetHeartbeatPacketTimeCharging(c3Mac, C3mRedisConfig.parseInt(C3mRedisConfig.HEART_BEAT_TIME), true); |
| | | String time2 = SetHeartbeatPacketTimeCharging(c3Mac, C3mRedisConfig.parseInt(C3mRedisConfig.HEART_BEAT_TIME), true, true); |
| | | LogUtils.error("C3充电时心跳包时间同步响应结果:" + time2); |
| | | System.out.println("设置心跳包间隔时间结束"); |
| | | |
| | | Thread.sleep(1000); |
| | | |
| | | /** |
| | | * 获取心跳包,判断在线 |
| | | */ |
| | | System.out.println("获取心跳包开始"); |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage aPackage = ReadTheHeartbeatPackage(c3Mac); |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage aPackage = ReadTheHeartbeatPackage(c3Mac, true); |
| | | if (aPackage == null) { |
| | | LogUtils.error("读取心跳包为空"); |
| | | return false; |
| | |
| | | C3mRedisConfig.OUTLINE_TIME |
| | | ); |
| | | System.out.println("获取心跳包结束"); |
| | | Thread.sleep(1000); |
| | | |
| | | /** |
| | | * finally、同步结束 |
| | | */ |
| | | System.out.println("同步结束 开始"); |
| | | String end = EndOfTheSynchronization(c3Mac); |
| | | String end = EndOfTheSynchronization(c3Mac, true); |
| | | if (!"操作成功".equals(end)) { |
| | | LogUtils.error("C3同步结束响应结果" + end); |
| | | return false; |
| | |
| | | if (one == null) { |
| | | throw new BusinessException("充电桩信息不存在!"); |
| | | } |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage beatDataPackage = ReadTheHeartbeatPackage(one.getC3Mac()); |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage beatDataPackage = ReadTheHeartbeatPackage(one.getC3Mac(), false); |
| | | if (beatDataPackage != null) { |
| | | //充电桩ID |
| | | chargingDto.setC3Id(one.getC3Id()); |
| | |
| | | * 同步结束 |
| | | * |
| | | * @param c3Mac |
| | | * @param resendFlag 重发标志 |
| | | */ |
| | | public String EndOfTheSynchronization(String c3Mac) { |
| | | public String EndOfTheSynchronization(String c3Mac, boolean resendFlag) { |
| | | C3EndOfTheSynchronizationReqInnerFrame c3EndOfTheSynchronizationReqInnerFrame = |
| | | new C3EndOfTheSynchronizationReqInnerFrame(c3Mac); |
| | | |
| | |
| | | if (c3mCharging == null) { |
| | | throw new BusinessException("C3充电桩硬件mcu_udid不存在"); |
| | | } |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | CommonFrame commonFrame; |
| | | if (resendFlag) { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame, true); |
| | | } else { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | } |
| | | StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-同步结束", a5Frame, commonFrame); |
| | | |
| | | |
| | |
| | | * 读心跳包 |
| | | * |
| | | * @param c3Mac |
| | | * @param resendFlag 重发标志 |
| | | */ |
| | | public A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage ReadTheHeartbeatPackage(String c3Mac) { |
| | | public A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage ReadTheHeartbeatPackage(String c3Mac, boolean resendFlag) { |
| | | C3ReadTheHeartbeatPackageReqInnerFrame readTheHeartbeatPackageReqInnerFrame = |
| | | new C3ReadTheHeartbeatPackageReqInnerFrame(c3Mac); |
| | | |
| | |
| | | if (c3mCharging == null) { |
| | | throw new BusinessException("C3充电桩硬件mcu_udid不存在"); |
| | | } |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | CommonFrame commonFrame; |
| | | if (resendFlag) { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame, true); |
| | | } else { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | } |
| | | StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-读取心跳包", a5Frame, commonFrame); |
| | | |
| | | |
| | |
| | | * |
| | | * @param c3Mac |
| | | * @param setTime |
| | | * @param resndFlag 重发标志 |
| | | * @return |
| | | */ |
| | | public String SetHeartbeatPacketTimeCharging(String c3Mac, int setTime, boolean flag) { |
| | | public String SetHeartbeatPacketTimeCharging(String c3Mac, int setTime, boolean flag, boolean resndFlag) { |
| | | if (setTime <= 0) { |
| | | throw new BusinessException("设置的心跳包间隔时间错误!"); |
| | | } |
| | |
| | | if (c3mCharging == null) { |
| | | throw new BusinessException("C3充电桩硬件mcu_udid不存在"); |
| | | } |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | CommonFrame commonFrame; |
| | | if (resndFlag) { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame, true); |
| | | } else { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | } |
| | | StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置心跳包间隔时间", a5Frame, commonFrame); |
| | | |
| | | |
| | |
| | | * 设置日历(同心跳包中的6字节日期时间) |
| | | * |
| | | * @param c3Mac |
| | | * @param resendFlag 是否需要重发标志 |
| | | * @return |
| | | */ |
| | | public String SetCalendar(String c3Mac, int year, int month, int day, int hour, int min, int sec) { |
| | | public String SetCalendar(String c3Mac, int year, int month, int day, int hour, int min, int sec, boolean resendFlag) { |
| | | |
| | | |
| | | C3SetCalendarReqInnerFrame setCalendarReqInnerFrame = |
| | |
| | | if (c3mCharging == null) { |
| | | throw new BusinessException("C3充电桩硬件mcu_udid不存在"); |
| | | } |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | CommonFrame commonFrame; |
| | | if (resendFlag) { |
| | | //需要重发 |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame, true); |
| | | } else { |
| | | //不需要重发 |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | } |
| | | StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置日历", a5Frame, commonFrame); |
| | | |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public String setRate(String c3Mac, List<C3mChargingCharge> list) { |
| | | public String setRate(String c3Mac, List<C3mChargingCharge> list, boolean resendFlag) { |
| | | if (StringUtil.strIsNullOrEmpty(c3Mac)) { |
| | | throw new BusinessException("C3Mac地址不能为空!"); |
| | | } |
| | |
| | | if (c3mCharging == null) { |
| | | throw new BusinessException("C3充电桩硬件mcu_udid不存在"); |
| | | } |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | CommonFrame commonFrame; |
| | | if (resendFlag) { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame, true); |
| | | } else { |
| | | commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | } |
| | | StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置费率", a5Frame, commonFrame); |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |