灯光模式 5

This commit is contained in:
2025-11-10 10:37:03 +08:00
parent 92df1c8668
commit 1be80be309
8 changed files with 234 additions and 75 deletions

View File

@ -9,6 +9,7 @@ import java.util.List;
*/
@Data
public class MqttMessage {
/**
* 请求ID用于匹配请求和响应
*/
@ -27,7 +28,7 @@ public class MqttMessage {
/**
* 功能类型
*/
private String funcType;
private Integer funcType;
/**
* 数据内容
@ -43,4 +44,5 @@ public class MqttMessage {
* 批量数据(设备上报时使用)
*/
private List<SensorData> batch;
}

View File

@ -0,0 +1,82 @@
package com.fuyuanshen.global.mqtt.enums;
/**
* 设备功能类型枚举
* 基于AppDeviceBJQ6075Controller中的功能注释1-9设计
*/
public enum DeviceFunctionType6075 {
/**
* 人员信息登记
*/
REGISTER_PERSON_INFO(1, "REGISTER_PERSON_INFO", "人员信息登记"),
/**
* 发送信息
*/
SEND_MESSAGE(2, "SEND_MESSAGE", "发送信息"),
/**
* 发送报警信息
*/
SEND_ALARM_MESSAGE(3, "SEND_ALARM_MESSAGE", "发送报警信息"),
/**
* 上传设备logo图片
*/
UPLOAD_LOGO(4, "UPLOAD_LOGO", "上传设备logo图片"),
/**
* 灯光模式(主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/
LIGHT_MODE(5, "LIGHT_MODE", "灯光模式"),
/**
* 灯光模式(辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/
AUXILIARY_LIGHT_MODE(6, "AUXILIARY_LIGHT_MODE", "辅光模式"),
/**
* 灯光亮度设置
*/
LIGHT_BRIGHTNESS(7, "LIGHT_BRIGHTNESS", "灯光亮度设置"),
/**
* 激光模式设置
*/
LASER_MODE(8, "LASER_MODE", "激光模式设置"),
/**
* 声光报警模式设置
*/
SOUND_AND_LIGHT_ALARM(9, "SOUND_AND_LIGHT_ALARM", "声光报警模式设置");
private final int number;
private final String code;
private final String description;
DeviceFunctionType6075(int number, String code, String description) {
this.number = number;
this.code = code;
this.description = description;
}
public int getNumber() {
return number;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return code;
}
}

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.global.mqtt.service;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
/**
* 通用IoT设备MQTT协议服务接口
@ -10,87 +11,96 @@ public interface IotMqttService {
/**
* 构建下发指令主题
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param imei 设备IMEI
* @return 指令主题
*/
String buildCommandTopic(String tenantCode, String deviceType, String imei);
String buildCommandTopic(String tenantCode, Long deviceType, String imei);
/**
* 构建响应数据主题
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param imei 设备IMEI
* @return 响应主题
*/
String buildStatusTopic(String tenantCode, String deviceType, String imei);
/**
* 构建设备上报数据主题
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param imei 设备IMEI
* @return 上报主题
*/
String buildReportTopic(String tenantCode, String deviceType, String imei);
/**
* 发送指令到设备
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 指令消息 (JSON格式)
* @param imei 设备IMEI
* @param message 指令消息 (JSON格式)
*/
void sendCommand(String tenantCode, String deviceType, String imei, JSONObject message);
void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message);
/**
* 发送响应消息到设备
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 响应消息 (JSON格式)
* @param imei 设备IMEI
* @param message 响应消息 (JSON格式)
*/
void sendStatus(String tenantCode, String deviceType, String imei, JSONObject message);
/**
* 发送设备上报数据的确认消息
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 确认消息 (JSON格式)
* @param imei 设备IMEI
* @param message 确认消息 (JSON格式)
*/
void sendReportAck(String tenantCode, String deviceType, String imei, JSONObject message);
/**
* 处理设备上报的单个传感器数据
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param sensor 传感器名称
* @param value 传感器值
* @param timestamp 时间戳
* @param imei 设备IMEI
* @param sensor 传感器名称
* @param value 传感器值
* @param timestamp 时间戳
*/
void handleSingleReport(String tenantCode, String deviceType, String imei,
String sensor, Object value, Long timestamp);
void handleSingleReport(String tenantCode, String deviceType, String imei,
String sensor, Object value, Long timestamp);
/**
* 处理设备上报的批量传感器数据
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param batchData 批量数据
* @param timestamp 时间戳
* @param imei 设备IMEI
* @param batchData 批量数据
* @param timestamp 时间戳
*/
void handleBatchReport(String tenantCode, String deviceType, String imei,
JSONObject batchData, Long timestamp);
void handleBatchReport(String tenantCode, String deviceType, String imei,
JSONObject batchData, Long timestamp);
/**
* 处理设备对指令的响应
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 响应消息 (JSON格式)
* @param imei 设备IMEI
* @param message 响应消息 (JSON格式)
*/
void handleCommandResponse(String tenantCode, String deviceType, String imei, JSONObject message);
}

View File

@ -2,6 +2,7 @@ package com.fuyuanshen.global.mqtt.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.service.IotMqttService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,38 +18,38 @@ import java.lang.reflect.Method;
@Slf4j
@Service
public class IotMqttServiceImpl implements IotMqttService {
@Autowired
private ApplicationContext applicationContext;
// MQTT主题前缀
private static final String COMMAND_PREFIX = "command";
private static final String STATUS_PREFIX = "status";
private static final String REPORT_PREFIX = "report";
@Override
public String buildCommandTopic(String tenantCode, String deviceType, String imei) {
public String buildCommandTopic(String tenantCode, Long deviceType, String imei) {
return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei);
}
@Override
public String buildStatusTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", STATUS_PREFIX, tenantCode, deviceType, imei);
}
@Override
public String buildReportTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", REPORT_PREFIX, tenantCode, deviceType, imei);
}
@Override
public void sendCommand(String tenantCode, String deviceType, String imei, JSONObject message) {
public void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message) {
String topic = buildCommandTopic(tenantCode, deviceType, imei);
String payload = message.toJSONString();
String payload = JSON.toJSONString(message);
sendMqttMessage(topic, 1, payload);
log.info("发送指令到设备: topic={}, payload={}", topic, payload);
}
@Override
public void sendStatus(String tenantCode, String deviceType, String imei, JSONObject message) {
String topic = buildStatusTopic(tenantCode, deviceType, imei);
@ -56,7 +57,7 @@ public class IotMqttServiceImpl implements IotMqttService {
sendMqttMessage(topic, 1, payload);
log.info("发送响应消息到设备: topic={}, payload={}", topic, payload);
}
@Override
public void sendReportAck(String tenantCode, String deviceType, String imei, JSONObject message) {
String topic = buildReportTopic(tenantCode, deviceType, imei);
@ -64,37 +65,38 @@ public class IotMqttServiceImpl implements IotMqttService {
sendMqttMessage(topic, 1, payload);
log.info("发送设备上报数据确认消息: topic={}, payload={}", topic, payload);
}
@Override
public void handleSingleReport(String tenantCode, String deviceType, String imei,
String sensor, Object value, Long timestamp) {
log.info("处理设备上报的单个传感器数据: tenantCode={}, deviceType={}, imei={}, sensor={}, value={}, timestamp={}",
public void handleSingleReport(String tenantCode, String deviceType, String imei,
String sensor, Object value, Long timestamp) {
log.info("处理设备上报的单个传感器数据: tenantCode={}, deviceType={}, imei={}, sensor={}, value={}, timestamp={}",
tenantCode, deviceType, imei, sensor, value, timestamp);
// TODO: 实现具体的业务逻辑,如更新设备状态、存储传感器数据等
}
@Override
public void handleBatchReport(String tenantCode, String deviceType, String imei,
JSONObject batchData, Long timestamp) {
log.info("处理设备上报的批量传感器数据: tenantCode={}, deviceType={}, imei={}, batchData={}, timestamp={}",
public void handleBatchReport(String tenantCode, String deviceType, String imei,
JSONObject batchData, Long timestamp) {
log.info("处理设备上报的批量传感器数据: tenantCode={}, deviceType={}, imei={}, batchData={}, timestamp={}",
tenantCode, deviceType, imei, JSON.toJSONString(batchData), timestamp);
// TODO: 实现具体的业务逻辑,如批量更新设备状态、存储传感器数据等
}
@Override
public void handleCommandResponse(String tenantCode, String deviceType, String imei, JSONObject message) {
log.info("处理设备对指令的响应: tenantCode={}, deviceType={}, imei={}, message={}",
log.info("处理设备对指令的响应: tenantCode={}, deviceType={}, imei={}, message={}",
tenantCode, deviceType, imei, JSON.toJSONString(message));
// TODO: 实现具体的业务逻辑,如更新指令执行状态等
}
/**
* 通过反射方式发送MQTT消息
* @param topic 主题
* @param qos 服务质量等级
*
* @param topic 主题
* @param qos 服务质量等级
* @param payload 消息内容
*/
private void sendMqttMessage(String topic, int qos, String payload) {