| | |
| | | package com.sandu.ximon.admin; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.aliyuncs.iot.model.v20180120.QueryDeviceDetailResponse; |
| | | import com.aliyuncs.iot.model.v20180120.RegisterDeviceResponse; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.ximon.admin.dto.DeviceStatus; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A1Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A5Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder; |
| | |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A2OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.service.PoleService; |
| | | import com.sandu.ximon.admin.service.RoleMenuRelationService; |
| | | import com.sandu.ximon.dao.domain.RoleMenuRelation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import java.util.List; |
| | | |
| | | @SpringBootTest |
| | | @Slf4j |
| | | class BaseTopicTests { |
| | | @Autowired |
| | | PoleService poleService; |
| | | @Autowired |
| | | RoleMenuRelationService roleMenuRelationService; |
| | | |
| | | |
| | | // 查询设备详情 |
| | | @Test |
| | | void queryDeviceDetail() { |
| | | QueryDeviceDetailResponse.Data data = MainBoardInvokeSyncService.getInstance().queryDeviceDetail("baseDevice", null); |
| | | QueryDeviceDetailResponse.Data data = MainBoardInvokeSyncService.getInstance().queryDeviceDetail("32313243305007ff8d60ffff", null); |
| | | System.out.println(data.toString()); |
| | | |
| | | List<DeviceStatus> statusList = poleService.listStatusByDeviceCode(CollectionUtil.toList("32313243305008ff0805ffff","32313243305007ff8d60ffff")); |
| | | System.out.println(statusList); |
| | | } |
| | | |
| | | |
| | | // 控制灯的亮度级别 0-100 |
| | | @Test |
| | | void rrpcLightControl() { |
| | | // 32313243305008ff1a06ffff |
| | | A5LightBrightnessReqInnerFrame lightControlFrame = new A5LightBrightnessReqInnerFrame(80); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), lightControlFrame); |
| | | WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC("32313243305008ff1a06ffff", a5Frame, A5LightBrightnessRespInnerFrame.class); |
| | | System.out.println(frame.toString()); |
| | | try { |
| | | WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC("32313243305005ff2930ffff", a5Frame, A5LightBrightnessRespInnerFrame.class); |
| | | System.out.println(frame.toString()); |
| | | }catch (BusinessException e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | // 设备注册 |
| | | @Test |
| | | void register() { |
| | | // 1 |
| | | // 1获取新的Mac |
| | | String baseMac = "baseDevice"; |
| | | A1Frame a1Frame = new A1Frame(A1OrderEnum.REQUEST_READ_DEVICE_UNIQUE_MAC.getCode(), new EmptyRequestInnerFrame()); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance() |
| | |
| | | uniqueMac = uniqueMac.toLowerCase(); |
| | | log.info("唯一码{}",uniqueMac); |
| | | |
| | | // 2 |
| | | // 2 从阿里注册 |
| | | MainBoardInvokeSyncService.getInstance().registerDevice(uniqueMac); |
| | | |
| | | // 3 |
| | | // 3 获取设备详情 |
| | | QueryDeviceDetailResponse.Data deviceDetail = MainBoardInvokeSyncService.getInstance().queryDeviceDetail(uniqueMac, null); |
| | | if(deviceDetail == null){ |
| | | throw new BusinessException("注册失败"); |
| | | } |
| | | log.info(deviceDetail.toString()); |
| | | |
| | | // 4 |
| | | // 4 配置Mac① |
| | | WrapResponseCommonFrame<A1TernaryCodeRespInnerFrame> productKeyResp = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(baseMac, |
| | | FrameBuilder.builderA1().innerFrame(new A1TernaryCodeReqInnerFrame(MainBoardInvokeSyncService.getInstance().getProductKey())) |
| | |
| | | throw new BusinessException("设备配置ProductKey失败"); |
| | | } |
| | | |
| | | // 5 |
| | | // 5 配置Mac② |
| | | WrapResponseCommonFrame<A1TernaryCodeRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(baseMac, |
| | | FrameBuilder.builderA1().innerFrame(new A1TernaryCodeReqInnerFrame(uniqueMac)) |
| | |
| | | throw new BusinessException("设备配置名失败"); |
| | | } |
| | | |
| | | // 6 |
| | | // 6 配置Mac③ |
| | | WrapResponseCommonFrame<A1TernaryCodeRespInnerFrame> wrapResponseCommonFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(baseMac, |
| | | FrameBuilder.builderA1().innerFrame(new A1TernaryCodeReqInnerFrame(deviceDetail.getDeviceSecret())) |
| | |
| | | throw new BusinessException("设备密钥失败"); |
| | | } |
| | | |
| | | // 7 |
| | | // 7 重启设备 并使用新的Mac |
| | | CommonFrame rebootFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(baseMac, |
| | | FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame()) |