From 76367431fdd5ef1f7e1a68a0f28fe7b7cba06990 Mon Sep 17 00:00:00 2001 From: sdvdxl Date: Tue, 11 May 2021 16:05:25 +0800 Subject: [PATCH 1/3] init Signed-off-by: sdvdxl --- .gitignore | 2 + .idea/$PROJECT_FILE$ | 11 + .idea/.gitignore | 3 + .idea/compiler.xml | 22 + .idea/encodings.xml | 6 + .idea/google-java-format.xml | 6 + .idea/inspectionProfiles/Project_Default.xml | 36 + .idea/iotos-soft-gateway-demo.iml | 65 ++ .idea/jarRepositories.xml | 85 ++ .idea/misc.xml | 25 + .idea/modules.xml | 8 + .idea/qaplug_profiles.xml | 763 ++++++++++++++++++ .idea/vcs.xml | 6 + assembly.xml | 38 + pom.xml | 63 ++ .../subsystem/IoTGatewayApplication.java | 16 + .../config/SpringScheduleConfig.java | 36 + .../softgateway/subsystem/package-info.java | 8 + .../DemoSubSystemCommandServiceImpl.java | 24 + src/main/resources/application.yml | 42 + 20 files changed, 1265 insertions(+) create mode 100644 .idea/$PROJECT_FILE$ create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/google-java-format.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/iotos-soft-gateway-demo.iml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/qaplug_profiles.xml create mode 100644 .idea/vcs.xml create mode 100644 assembly.xml create mode 100644 pom.xml create mode 100644 src/main/java/me/hekr/iotos/softgateway/subsystem/IoTGatewayApplication.java create mode 100644 src/main/java/me/hekr/iotos/softgateway/subsystem/config/SpringScheduleConfig.java create mode 100644 src/main/java/me/hekr/iotos/softgateway/subsystem/package-info.java create mode 100644 src/main/java/me/hekr/iotos/softgateway/subsystem/service/DemoSubSystemCommandServiceImpl.java create mode 100644 src/main/resources/application.yml diff --git a/.gitignore b/.gitignore index 72f4d98..9ea85e7 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,5 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +target +logs \ No newline at end of file diff --git a/.idea/$PROJECT_FILE$ b/.idea/$PROJECT_FILE$ new file mode 100644 index 0000000..58b7e3e --- /dev/null +++ b/.idea/$PROJECT_FILE$ @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9c79187 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml new file mode 100644 index 0000000..8b57f45 --- /dev/null +++ b/.idea/google-java-format.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/iotos-soft-gateway-demo.iml b/.idea/iotos-soft-gateway-demo.iml new file mode 100644 index 0000000..65eb2b6 --- /dev/null +++ b/.idea/iotos-soft-gateway-demo.iml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..3797bdd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..edd11c1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..61230f4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml new file mode 100644 index 0000000..c1ac4dc --- /dev/null +++ b/.idea/qaplug_profiles.xml @@ -0,0 +1,763 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/assembly.xml b/assembly.xml new file mode 100644 index 0000000..915163b --- /dev/null +++ b/assembly.xml @@ -0,0 +1,38 @@ + + full + + + + zip + + + + false + + + ${basedir}/target + . + + *.jar + + 0755 + + + + ${maven.multiModuleProjectDirectory} + . + + README.md + + + + ${maven.multiModuleProjectDirectory}/docs + . + + * + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7b3a1c5 --- /dev/null +++ b/pom.xml @@ -0,0 +1,63 @@ + + + + iotos-soft-gateway + me.hekr.iotos.softgateway + 0.0.1 + + 4.0.0 + jar + iotos-soft-gateway-demo + + + 8 + 8 + + + + + hekr-iotos-soft-gateway + https://gitee.com/sdvdxl/iotos-soft-gateway/raw/feature-modules-maven/maven/repository + + + + + + + me.hekr.iotos.softgateway + framework-core + 0.0.1 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + assembly.xml   + + + + + make-assembly + package + + single + + + + + + + \ No newline at end of file diff --git a/src/main/java/me/hekr/iotos/softgateway/subsystem/IoTGatewayApplication.java b/src/main/java/me/hekr/iotos/softgateway/subsystem/IoTGatewayApplication.java new file mode 100644 index 0000000..40d3be6 --- /dev/null +++ b/src/main/java/me/hekr/iotos/softgateway/subsystem/IoTGatewayApplication.java @@ -0,0 +1,16 @@ +package me.hekr.iotos.softgateway.subsystem; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** @author iotos */ +@SuppressWarnings("AlibabaClassNamingShouldBeCamel") +@SpringBootApplication +@EnableScheduling +public class IoTGatewayApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(IoTGatewayApplication.class, args); + } +} diff --git a/src/main/java/me/hekr/iotos/softgateway/subsystem/config/SpringScheduleConfig.java b/src/main/java/me/hekr/iotos/softgateway/subsystem/config/SpringScheduleConfig.java new file mode 100644 index 0000000..20c9f5a --- /dev/null +++ b/src/main/java/me/hekr/iotos/softgateway/subsystem/config/SpringScheduleConfig.java @@ -0,0 +1,36 @@ +package me.hekr.iotos.softgateway.subsystem.config; + +import java.util.concurrent.ScheduledExecutorService; +import me.hekr.iotos.softgateway.core.utils.ThreadPoolUtil; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +/** + *
+ * + * @author iotos + */ +@Configuration +@EnableScheduling +public class SpringScheduleConfig implements SchedulingConfigurer { + + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + taskRegistrar.setScheduler(taskExecutor()); + } + + @Bean(destroyMethod = "shutdown") + public ScheduledExecutorService taskExecutor() { + return (ScheduledExecutorService) + new ThreadPoolUtil.Builder() + .setPrefix("spring-schedule") + .setCore(12) + .setMax(32) + .setQueueSize(1000) + .setScheduled(true) + .build(); + } +} diff --git a/src/main/java/me/hekr/iotos/softgateway/subsystem/package-info.java b/src/main/java/me/hekr/iotos/softgateway/subsystem/package-info.java new file mode 100644 index 0000000..7e1cad7 --- /dev/null +++ b/src/main/java/me/hekr/iotos/softgateway/subsystem/package-info.java @@ -0,0 +1,8 @@ +/** + * 子系统自定义开发在这个包 + * + * @see me.hekr.iotos.softgateway.core.config.DeviceMapper 通过网关的远程配置自动更新子系统和iot 设备缓存关系 + * @see me.hekr.iotos.softgateway.core.network.mqtt.listener.MqttConnectedListener 自定义 mqtt 连接监听器 + * @see me.hekr.iotos.softgateway.core.network.mqtt.listener.CoreMqttConnectedListenerImpl 内置连接监听器 + */ +package me.hekr.iotos.softgateway.subsystem; diff --git a/src/main/java/me/hekr/iotos/softgateway/subsystem/service/DemoSubSystemCommandServiceImpl.java b/src/main/java/me/hekr/iotos/softgateway/subsystem/service/DemoSubSystemCommandServiceImpl.java new file mode 100644 index 0000000..4de854e --- /dev/null +++ b/src/main/java/me/hekr/iotos/softgateway/subsystem/service/DemoSubSystemCommandServiceImpl.java @@ -0,0 +1,24 @@ +package me.hekr.iotos.softgateway.subsystem.service; + +import lombok.extern.slf4j.Slf4j; +import me.hekr.iotos.softgateway.core.config.DeviceMapper; +import me.hekr.iotos.softgateway.core.klink.ModelData; +import me.hekr.iotos.softgateway.core.subsystem.SubsystemCommandService; +import org.springframework.stereotype.Service; + +/** + * demo 命令测试用例,如果需要处理,则需要在 iot 上物模型中定义一个 demo 的命令 + * + * @see me.hekr.iotos.softgateway.core.subsystem.SubsystemCommandService#handle(DeviceMapper, + * ModelData) + * @author iot + */ +@Service("demoSubSystemCommandService") +@Slf4j +public class DemoSubSystemCommandServiceImpl implements SubsystemCommandService { + + @Override + public void handle(DeviceMapper device, ModelData data) { + log.info("设备收到命令, 设备:{},命令:{}", device, data); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..ecf6bf0 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,42 @@ +server: + port: 8070 + +connect: + mqtt: + endpoint: 'tcp://106.75.50.110:1883' + # 链接超时时间,秒 + connectionTimeout: 10 + # 心跳保持,秒 + keepAliveTime: 60 + +gateway: + pk: 'b6e2cc8aaf6c4255a15106d4806cd7ec' + devId: 'demo_gateway' + devSecret: 'ae0122eeb6cd48e4b10405d04987946f' + +# 日志配置,注意仅针对 springboot 项目有效 +logging: + # 日志级别 + # 如果要加其他日志过滤,格式为: level.包名: LEVEL + # 比如 level.me.hekr.iotos: DEBUG + level: + root: INFO + me.hekr.iotos: INFO + io.netty: INFO + + # 日志文件保存位置 + file: logs/iotos-soft-gateway.log + pattern: + file: '%date{"yyyy-MM-dd HH:mm:ss.SSS"} %-5level [%thread] %logger{128}.%M:%line - %msg %n' + console: '%date{"yyyy-MM-dd HH:mm:ss.SSS"} %-5level [%thread] %logger{128}.%M:%line - %msg %n' + charset: + console: UTF-8 + file: UTF-8 + logback: + rollingpolicy: + file-name-pattern: ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz + clean-history-on-start: true + # 日志文件大小 + max-file-size: '500mb' + # 历史日志文件保存天数 + max-history: 7 \ No newline at end of file -- Gitee From 3f003ea99fe638ce97af11d7243937a55185d4ec Mon Sep 17 00:00:00 2001 From: sdvdxl Date: Tue, 11 May 2021 16:19:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sdvdxl --- .idea/encodings.xml | 1 + .idea/iotos-soft-gateway-demo.iml | 50 ------------------------------- .idea/jarRepositories.xml | 5 ++++ pom.xml | 2 +- 4 files changed, 7 insertions(+), 51 deletions(-) diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 63e9001..aa00ffa 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/iotos-soft-gateway-demo.iml b/.idea/iotos-soft-gateway-demo.iml index 65eb2b6..c035f0b 100644 --- a/.idea/iotos-soft-gateway-demo.iml +++ b/.idea/iotos-soft-gateway-demo.iml @@ -11,55 +11,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index 3797bdd..d4d1a5f 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -81,5 +81,10 @@