Commit 6c7fe9df authored by p x's avatar p x
Browse files

1

parent cd1198f8
...@@ -14,6 +14,15 @@ tasks.jar { ...@@ -14,6 +14,15 @@ tasks.jar {
enabled = false enabled = false
} }
// 配置 Spring Boot 可执行 JAR 的名称(核心配置)
tasks.bootJar {
// 方式1:固定名称(推荐,简洁)
archiveFileName.set("avpmock-${project.version}.jar")
// 可选:自定义输出目录(默认是 build/libs,无需修改可注释)
// destinationDirectory.set(file("${project.buildDir}/custom-libs"))
}
java { java {
toolchain { toolchain {
languageVersion = JavaLanguageVersion.of(17) languageVersion = JavaLanguageVersion.of(17)
......
...@@ -206,3 +206,72 @@ Consider defining a bean of type 'io.netty.channel.Channel' in your configuratio ...@@ -206,3 +206,72 @@ Consider defining a bean of type 'io.netty.channel.Channel' in your configuratio
2026-01-12 10:11:49 [Test worker] INFO c.inzy.wsmock.WsmockApplicationTests.logStarted - Started WsmockApplicationTests in 1.352 seconds (process running for 2.091) 2026-01-12 10:11:49 [Test worker] INFO c.inzy.wsmock.WsmockApplicationTests.logStarted - Started WsmockApplicationTests in 1.352 seconds (process running for 2.091)
2026-01-12 10:11:49 [DefaultDispatcher-worker-1 @coroutine#2] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭 2026-01-12 10:11:49 [DefaultDispatcher-worker-1 @coroutine#2] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 10:11:49 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭 2026-01-12 10:11:49 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:00:08 [Test worker] INFO c.inzy.wsmock.WsmockApplicationTests.logStarting - Starting WsmockApplicationTests using Java 17.0.15 with PID 19636 (started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:00:08 [Test worker] INFO c.inzy.wsmock.WsmockApplicationTests.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:00:09 [DefaultDispatcher-worker-1 @coroutine#2] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:00:09 [Test worker] INFO c.inzy.wsmock.WsmockApplicationTests.logStarted - Started WsmockApplicationTests in 1.364 seconds (process running for 2.114)
2026-01-12 15:00:09 [DefaultDispatcher-worker-1 @coroutine#2] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:00:09 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:05:25 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 19296 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:05:25 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:05:25 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:05:25 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:05:25 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:05:26 [DefaultDispatcher-worker-2] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:05:26 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.452 seconds (process running for 1.773)
2026-01-12 15:08:35 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:08:35 [DefaultDispatcher-worker-2] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:21:14 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 33924 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:21:14 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:21:14 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:21:14 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:21:14 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:21:15 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:21:15 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.145 seconds (process running for 1.543)
2026-01-12 15:22:23 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:22:23 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:22:26 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 21448 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:22:26 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:22:27 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:22:27 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:22:27 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:22:27 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:22:27 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.124 seconds (process running for 1.443)
2026-01-12 15:23:17 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:23:17 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:23:32 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 28708 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:23:32 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:23:32 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:23:32 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:23:32 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:23:32 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:23:32 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.038 seconds (process running for 1.31)
2026-01-12 15:24:29 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:24:29 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:24:32 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 27420 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:24:32 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:24:33 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:24:33 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:24:33 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:24:33 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:24:33 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.156 seconds (process running for 1.443)
2026-01-12 15:25:03 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:25:03 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:32:28 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 6800 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:32:28 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:32:29 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:32:29 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:32:29 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:32:29 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:32:29 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.117 seconds (process running for 1.428)
2026-01-12 15:33:00 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
2026-01-12 15:33:00 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:34:26 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarting - Starting WsmockApplicationKt using Java 17.0.15 with PID 6596 (D:\JavaWorkSpace\wsmock\build\classes\kotlin\main started by Administrator in D:\JavaWorkSpace\wsmock)
2026-01-12 15:34:26 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStartupProfileInfo - No active profile set, falling back to 1 default profile: "default"
2026-01-12 15:34:26 [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2026-01-12 15:34:26 [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/10.1.50]
2026-01-12 15:34:26 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/].log - Initializing Spring embedded WebApplicationContext
2026-01-12 15:34:26 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty WebSocket服务启动成功,端口:8089
2026-01-12 15:34:26 [main] INFO com.inzy.wsmock.WsmockApplicationKt.logStarted - Started WsmockApplicationKt in 1.064 seconds (process running for 1.333)
2026-01-12 15:41:19 [SpringApplicationShutdownHook] INFO c.inzy.wsmock.NettyWebSocketServer.stop - Netty WebSocket服务已关闭
2026-01-12 15:41:19 [DefaultDispatcher-worker-1] INFO c.inzy.wsmock.NettyWebSocketServer.invokeSuspend - Netty线程组已关闭
package com.inzy.wsmock package com.inzy.wsmock
import com.inzy.wsmock.bean.NaviMockBean
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
...@@ -20,7 +19,7 @@ class PushConfigController( ...@@ -20,7 +19,7 @@ class PushConfigController(
/** /**
* 设置推送开关状态 * 设置推送开关状态
*/ */
@GetMapping("mock/startnavi") /* @GetMapping("mock/startnavi")
fun setPushStatus( fun setPushStatus(
// 必传参数:是否启用推送 // 必传参数:是否启用推送
@RequestParam("start") start: Int @RequestParam("start") start: Int
...@@ -33,5 +32,5 @@ class PushConfigController( ...@@ -33,5 +32,5 @@ class PushConfigController(
} }
return naviMockBean return naviMockBean
// return JSON.toJSONString(naviMockBean) // return JSON.toJSONString(naviMockBean)
} }*/
} }
\ No newline at end of file
package com.inzy.wsmock package com.inzy.wsmock
import com.inzy.wsmock.push.AdasPushTask
import com.inzy.wsmock.push.PushFactory import com.inzy.wsmock.push.PushFactory
import io.netty.channel.ChannelHandler.Sharable import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext
......
package com.sd.cavphmi.bean.mock package com.inzy.wsmock.bean
//模拟路径 //模拟路径
data class MRoutes( class MRoutes {
val rs: List<List<Double>> /**业务状态 park call park_com call_com**/
) var status = "park"
\ No newline at end of file /***车辆行驶的点位**/
var carPos = 0
var rs: List<List<Double>>? = null
}
\ No newline at end of file
package com.sd.cavphmi.bean package com.inzy.wsmock.bean
/**V2x 预警开始 /**V2x 预警开始
* {"id":"39846582477537280","objects":[{"id":"267","name":"Vehicle","longitude":117.3461065,"latitude":38.9985969,"elevation":500.0},{"id":"1600009","name":"Participants","longitude":117.3463289,"latitude":38.9986373,"elevation":500.0}],"type":1,"typeName":"前向碰撞预警","level":1,"startTime":1755582898300,"reportTime":1755582898300} * {"id":"39846582477537280","objects":[{"id":"267","name":"Vehicle","longitude":117.3461065,"latitude":38.9985969,"elevation":500.0},{"id":"1600009","name":"Participants","longitude":117.3463289,"latitude":38.9986373,"elevation":500.0}],"type":1,"typeName":"前向碰撞预警","level":1,"startTime":1755582898300,"reportTime":1755582898300}
......
...@@ -3,12 +3,10 @@ package com.inzy.wsmock.push ...@@ -3,12 +3,10 @@ package com.inzy.wsmock.push
import com.alibaba.fastjson2.JSON import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject import com.alibaba.fastjson2.JSONObject
import com.inzy.wsmock.ChannelManager import com.inzy.wsmock.ChannelManager
import com.inzy.wsmock.PushConfig
import com.inzy.wsmock.RequestParamHandler import com.inzy.wsmock.RequestParamHandler
import com.inzy.wsmock.RequestParamHandler.Companion.PARAM_TYPE_KEY import com.inzy.wsmock.bean.MRoutes
import com.inzy.wsmock.RequestParamHandler.Companion.PARAM_TYPE_VALUE_3 import com.inzy.wsmock.bean.V2xStartBean
import com.inzy.wsmock.RequestParamHandler.Companion.REQUEST_PARAMS_KEY import com.inzy.wsmock.bean.VObject
import com.inzy.wsmock.bean.DriveInOrOut
import com.inzy.wsmock.utils.FileIoUtil import com.inzy.wsmock.utils.FileIoUtil
import io.netty.channel.Channel import io.netty.channel.Channel
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame import io.netty.handler.codec.http.websocketx.TextWebSocketFrame
...@@ -19,47 +17,53 @@ import org.slf4j.LoggerFactory ...@@ -19,47 +17,53 @@ import org.slf4j.LoggerFactory
import org.springframework.core.io.ResourceLoader import org.springframework.core.io.ResourceLoader
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
@Component @Component
//@Scope("prototype") //@Scope("prototype")
class AdasPushTask( class AvpPushTask(
// 注入Spring资源加载器(Spring自动装配) // 注入Spring资源加载器(Spring自动装配)
private val resourceLoader: ResourceLoader, private val resourceLoader: ResourceLoader,
private val pushConfig: PushConfig, // private val pushConfig: PushConfig,
) : PushTask { ) : PushTask {
private val instanceId = System.currentTimeMillis() // 实例唯一标识,用于验证多实例 // private val instanceId = System.currentTimeMillis() // 实例唯一标识,用于验证多实例
private val logger = LoggerFactory.getLogger(javaClass) private val logger = LoggerFactory.getLogger(javaClass)
// 注入ChannelManager单例 // 注入ChannelManager单例
private val channelManager = ChannelManager.instance private val channelManager = ChannelManager.instance
//车辆位姿 //车辆位姿,泊车
private var carDst = mutableListOf<String>() private var carDstPark = mutableListOf<String>()
//车辆位姿,召车
private var carDstCall = mutableListOf<String>()
//车辆行驶的位置 //车辆行驶的位置
// private var carIndex = AtomicInteger(0)
private var carPos = 0 private var carPos = 0
//AVP状态 park call
private var status = ""
//感知物 //感知物
private var preDst = mutableListOf<String>() private var preDst = mutableListOf<String>()
//电子围栏只推一次开关
private var isFence = AtomicBoolean(false)
//v2x只推一次开关 //v2x只推一次开关
private var isV2x = AtomicBoolean(false) private var isV2x = AtomicBoolean(false)
@PostConstruct @PostConstruct
fun readMockFile() { fun readMockFile() {
logger.info("创建 AdasPushTask 实例,ID: $instanceId") // logger.info("创建 AdasPushTask 实例,ID: $instanceId")
var classpathResource = resourceLoader.getResource("classpath:adasm/CarVehicle_fz.txt") var classpathResource = resourceLoader.getResource("classpath:avpm/Car_fangzhen_park.txt")
// 读取文件内容(Kotlin简化写法) // 读取文件内容(Kotlin简化写法)
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
FileIoUtil.getMockToList(classpathResource.inputStream, carDst) //读取泊车数据
// println("读取到文件内容:${dst.count()}") FileIoUtil.getMockToList(classpathResource.inputStream, carDstPark)
classpathResource = resourceLoader.getResource("classpath:adasm/PerTarget.txt") //读取召车数据
classpathResource = resourceLoader.getResource("classpath:avpm/Car_fangzhen_call.txt")
FileIoUtil.getMockToList(classpathResource.inputStream, carDstCall)
//读取感知物数据
classpathResource = resourceLoader.getResource("classpath:avpm/PerTarget.txt")
FileIoUtil.getMockToList(classpathResource.inputStream, preDst) FileIoUtil.getMockToList(classpathResource.inputStream, preDst)
} }
} }
...@@ -67,7 +71,8 @@ class AdasPushTask( ...@@ -67,7 +71,8 @@ class AdasPushTask(
@PreDestroy @PreDestroy
fun destroy() { fun destroy() {
// logger.info("销毁 AdasPushTask 实例,ID: $instanceId") // logger.info("销毁 AdasPushTask 实例,ID: $instanceId")
carDst.clear() carDstPark.clear()
carDstCall.clear()
preDst.clear() preDst.clear()
} }
...@@ -81,17 +86,13 @@ class AdasPushTask( ...@@ -81,17 +86,13 @@ class AdasPushTask(
pushPre(channel) pushPre(channel)
} }
RequestParamHandler.PARAM_TYPE_VALUE_3 -> {//电子围栏驶入驶出 RequestParamHandler.PARAM_TYPE_VALUE_3 -> {//v2x 预警
pushFence(channel)
}
RequestParamHandler.PARAM_TYPE_VALUE_4 -> {//v2x 预警
pushV2x(channel) pushV2x(channel)
} }
else -> { else -> {
val msg = JSONObject() val msg = JSONObject()
msg.put("type", "adas") msg.put("type", "avp")
sendMsg(channel, msg.toJSONString()) sendMsg(channel, msg.toJSONString())
} }
} }
...@@ -102,36 +103,43 @@ class AdasPushTask( ...@@ -102,36 +103,43 @@ class AdasPushTask(
*/ */
private fun pushCarPos(channel: Channel) { private fun pushCarPos(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
while (isActive) { delay(8000)
if (pushConfig.pushStart.get() == 0) { status = "park"
// println("------------没开始推") //开始推送泊车
// carIndex = 0 carDstPark.forEachIndexed { i, str ->
carPos = 0 val mRoutes = JSON.parseObject(str, MRoutes::class.java)
isV2x.set(false) mRoutes.status = status
// carIndex.set(0) mRoutes.carPos = i
isFence.set(false) sendMsg(channel, JSON.toJSONString(mRoutes))
delay(200) delay(300)
// sendMsg(channel, carDst.first()) }
continue //泊车完成
} val parkTemp=MRoutes().apply {
if (carDst.isNotEmpty()) { status = "park_com"
carDst.forEachIndexed { index, string -> }
// println("carIndex = ${carIndex}") sendMsg(channel, JSON.toJSONString(parkTemp))
if (pushConfig.pushStart.get() == 0) { delay(3000)
return@forEachIndexed status = "call"
} //开始推送召车
//推送电子围栏 carDstCall.forEachIndexed { i, str ->
carPos = index val mRoutes = JSON.parseObject(str, MRoutes::class.java)
// takeFen(index) mRoutes.status = status
// carIndex.set(index) mRoutes.carPos = i
sendMsg(channel, string) sendMsg(channel, JSON.toJSONString(mRoutes))
delay(200) delay(200)
}
// println("---- pushConfig.pushStart.set(0)")
// carIndex.set(0)
pushConfig.pushStart.set(0)
}
} }
//召车完成
val callTemp=MRoutes().apply {
status = "call_com"
}
sendMsg(channel, JSON.toJSONString(callTemp))
//全部完成
val temp=MRoutes().apply {
status = ""
}
sendMsg(channel, JSON.toJSONString(temp))
status = ""
} }
} }
...@@ -143,127 +151,69 @@ class AdasPushTask( ...@@ -143,127 +151,69 @@ class AdasPushTask(
preDst.forEachIndexed { index, string -> preDst.forEachIndexed { index, string ->
// println("index = ${index}") // println("index = ${index}")
sendMsg(channel, string) sendMsg(channel, string)
delay(500) delay(4500)
} }
pushPre(channel) pushPre(channel)
} }
} }
} }
/**电子围栏**/ private fun pushV2x(channel: Channel) {
private fun pushFence(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
while (isActive) { while (isActive) {
// println("---carPos = ${carPos}") carPos = 8
if (carPos == 0) { if (status.equals("park")) {
delay(100) when (carPos) {
continue 8 -> {//紧急制动预警
} val v2x = V2xStartBean().apply {
if (carPos == 30) {//驶入 130 type = 6
if (isFence.compareAndSet(false, true)) { objects =
val driveInOrOut = DriveInOrOut().apply { listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
finished = true }
} pushV2xAtomic(channel, v2x)
sendMsg(channel, JSON.toJSONString(driveInOrOut))
isFence.set(false)
}
} else if (carPos == 500) {//驶出 500
if (isFence.compareAndSet(false, true)) {
val driveInOrOut = DriveInOrOut().apply {
finished = false
} }
sendMsg(channel, JSON.toJSONString(driveInOrOut))
}
}
delay(50)
}
}
}
private fun takeFen(index: Int) { 30 -> {//前向碰撞
if (index == 0) { val v2x = V2xStartBean().apply {
isFence.set(false) type = 1
return objects =
} listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
if (index == 130) { }
if (isFence.compareAndSet(false, true)) { pushV2xAtomic(channel, v2x)
val driveInOrOut = DriveInOrOut().apply { }
finished = true
}
val fenChannels = filterTypeChannels(PARAM_TYPE_VALUE_3)
fenChannels.forEach { string, channel ->
sendMsg(channel, JSON.toJSONString(driveInOrOut))
}
isFence.set(false)
}
} else if (index == 500) {
if (isFence.compareAndSet(false, true)) {
val driveInOrOut = DriveInOrOut().apply {
finished = true
}
val fenChannels = filterTypeChannels(PARAM_TYPE_VALUE_3)
fenChannels.forEach { string, channel ->
sendMsg(channel, JSON.toJSONString(driveInOrOut))
}
}
}
}
/**施工**/
private val SHIGONG_V2X =
"F2000004193C01000001980D93029B14323731323800000000000000000000011102004500030004000139373737353064302D616162662D346462312D623234622D303263653862343662623238000001980D9302993E0E8555123AFBF9FFFFFFFF0026050064000001000000000000000000000000000000000000000000000000000000000"
/****交叉路口***/
private val JIAOCHALUKOU_V2X =
"F2000004193C01000001980D93029B14323731323800000000000000000000011102004500030004000139373737353064302D616162662D346462312D623234622D303263653862343662623238000001980D9302993E0E8555123AFBF9FFFFFFFF00840500640000010000000000000000000000000000000000000000000000000000000000"
/****人行横道***/
private val RENXINGHENGDAO_V2X =
"F2000004193C01000001980D93029B14323731323800000000000000000000011102004500030004000139373737353064302D616162662D346462312D623234622D303263653862343662623238000001980D9302993E0E8555123AFBF9FFFFFFFF007205006400000100000000000000000000000000000000000000000000000000000000"
/****前向碰撞***/
private val QIANPENG_V2X =
"F2000000745E01000001995C134B2914595A4D4E3030340000000000000023B8006266313137666466612D666566662D303130302D383564632D33353835303030306163623001000001995C134B294570A9A217BA61FFFFFFFFFF008B0031B92E4570A95117BA62B1FFFFFFFF0089000493E00100020000000000000000000000000000"
/****弱势交通***/
private val RUOSHI_V2X =
"F2000004193C01000001995BD8FCB114595A4D4E3030340000000000000000011101004500030004000166623031303331332D663633662D343138312D623633322D333537623463383635646361000001995BD8FC544570F8E817BA370BFFFFFFFF159005000A000001FFFFFFFFFFFFFFFFFFFFFFFFFFFF00002435303333323435362D333033302D333033302D333533302D33303333333435333339353500000000000000000000000000000"
/****限速***/ 60 -> {//弱势交通参与者
private val XIANSU_V2X = val v2x = V2xStartBean().apply {
"F2000004193C010000019B8793FAE914534D3030303030310000000000000001110207D000030004000137656266346363372D383133322D343530302D386262632D6132356539386138356433380000019B8793FAE94570A34217BA687AFFFFFFFF0055050064000001FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000" type = 12
objects =
listOf(VObject(""), VObject("50332456-3030-3030-3530-303334533955"))
}
pushV2xAtomic(channel, v2x)
}
}
private fun pushV2x(channel: Channel) { } else if (status.equals("call")) {
CoroutineScope(Dispatchers.Default).launch { when (carPos) {
while (isActive) { 70 -> {//盲区预警
if (pushConfig.pushStart.get() == 0) { val v2x = V2xStartBean().apply {
delay(100) type = 4
continue objects =
} listOf(VObject(""), VObject("2435"))
if (carPos < 100) }
continue pushV2xAtomic(channel, v2x)
if (carPos == 200) {//施工 }
pushV2xAtomic(channel, SHIGONG_V2X) }
} else if (carPos == 230) {//交叉路口
pushV2xAtomic(channel, JIAOCHALUKOU_V2X)
} else if (carPos == 260) {//人行横道
pushV2xAtomic(channel, RENXINGHENGDAO_V2X)
} else if (carPos == 320) {//前向碰撞
pushV2xAtomic(channel, QIANPENG_V2X)
} else if (carPos == 350) {//弱势交通
pushV2xAtomic(channel, RUOSHI_V2X)
} else if (carPos == 400) {//车内限速标牌
pushV2xAtomic(channel, XIANSU_V2X, false)
} }
delay(150) delay(300)
} }
} }
} }
private fun pushV2xAtomic(channel: Channel, str: String, change: Boolean = true) { private fun pushV2xAtomic(channel: Channel, v2xStartBean: V2xStartBean, change: Boolean = true) {
if (isV2x.compareAndSet(false, true)) { if (isV2x.compareAndSet(false, true)) {
// val msgObj = JSONObject() // val msgObj = JSONObject()
// msgObj["content"] = "定时推送消息 type=2 ${LocalDateTime.now()}" // msgObj["content"] = "定时推送消息 type=2 ${LocalDateTime.now()}"
val str = JSONObject.toJSONString(v2xStartBean)
sendMsg(channel, str) sendMsg(channel, str)
if (change) { if (change) {
isV2x.set(false) isV2x.set(false)
...@@ -272,25 +222,6 @@ class AdasPushTask( ...@@ -272,25 +222,6 @@ class AdasPushTask(
} }
/**
* 返回某个type的channel
* @param type 前端的查询参数
**/
private fun filterTypeChannels(type: String): Map<String, Channel> {
val onlineChannels = channelManager.getAllChannels()
//得到设置了type属性的channel
val typeChannels =
onlineChannels.filter { (id, channel) ->
if (channel.hasAttr(REQUEST_PARAMS_KEY)) {
val params = channel.attr(REQUEST_PARAMS_KEY).get()
return@filter params.get(PARAM_TYPE_KEY) == type
}
false
}
return typeChannels
}
private fun sendMsg(channel: Channel, msg: String) { private fun sendMsg(channel: Channel, msg: String) {
if (!channel.isActive()) { if (!channel.isActive()) {
// println("无在线客户端,跳过推送") // println("无在线客户端,跳过推送")
......
...@@ -2,22 +2,13 @@ package com.inzy.wsmock.push ...@@ -2,22 +2,13 @@ package com.inzy.wsmock.push
import com.inzy.wsmock.RequestParamHandler import com.inzy.wsmock.RequestParamHandler
import io.netty.channel.Channel import io.netty.channel.Channel
import jakarta.annotation.PreDestroy
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@Component @Component
class PushFactory( class PushFactory(
private val adasPushTask: AdasPushTask private val avpPushTask: AvpPushTask
) { ) {
// @Autowired
// private lateinit var applicationContext: ApplicationContext
// private var adasPushTask: AdasPushTask? = null
/**根据路径推送***/ /**根据路径推送***/
fun pushMsgFormPath(channel: Channel) { fun pushMsgFormPath(channel: Channel) {
var path = "" var path = ""
...@@ -38,12 +29,9 @@ class PushFactory( ...@@ -38,12 +29,9 @@ class PushFactory(
private fun createPushProduct(path: String): PushTask { private fun createPushProduct(path: String): PushTask {
when (path) { when (path) {
"/ws/adas" -> { "/ws/avp" -> {
// 关键:每次调用 getBean 都会创建新的 AdasPushTask 实例 return avpPushTask
// return applicationContext.getBean(AdasPushTask::class.java)
return adasPushTask
} }
else -> { else -> {
throw IllegalArgumentException("Unknown product type") throw IllegalArgumentException("Unknown product type")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment