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

1

parent cd1198f8
......@@ -14,6 +14,15 @@ tasks.jar {
enabled = false
}
// 配置 Spring Boot 可执行 JAR 的名称(核心配置)
tasks.bootJar {
// 方式1:固定名称(推荐,简洁)
archiveFileName.set("avpmock-${project.version}.jar")
// 可选:自定义输出目录(默认是 build/libs,无需修改可注释)
// destinationDirectory.set(file("${project.buildDir}/custom-libs"))
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
......
......@@ -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 [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 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
import com.inzy.wsmock.bean.NaviMockBean
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
......@@ -20,7 +19,7 @@ class PushConfigController(
/**
* 设置推送开关状态
*/
@GetMapping("mock/startnavi")
/* @GetMapping("mock/startnavi")
fun setPushStatus(
// 必传参数:是否启用推送
@RequestParam("start") start: Int
......@@ -33,5 +32,5 @@ class PushConfigController(
}
return naviMockBean
// return JSON.toJSONString(naviMockBean)
}
}*/
}
\ No newline at end of file
package com.inzy.wsmock
import com.inzy.wsmock.push.AdasPushTask
import com.inzy.wsmock.push.PushFactory
import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel.ChannelHandlerContext
......
package com.sd.cavphmi.bean.mock
package com.inzy.wsmock.bean
//模拟路径
data class MRoutes(
val rs: List<List<Double>>
)
\ No newline at end of file
class MRoutes {
/**业务状态 park call park_com call_com**/
var status = "park"
/***车辆行驶的点位**/
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 预警开始
* {"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
import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject
import com.inzy.wsmock.ChannelManager
import com.inzy.wsmock.PushConfig
import com.inzy.wsmock.RequestParamHandler
import com.inzy.wsmock.RequestParamHandler.Companion.PARAM_TYPE_KEY
import com.inzy.wsmock.RequestParamHandler.Companion.PARAM_TYPE_VALUE_3
import com.inzy.wsmock.RequestParamHandler.Companion.REQUEST_PARAMS_KEY
import com.inzy.wsmock.bean.DriveInOrOut
import com.inzy.wsmock.bean.MRoutes
import com.inzy.wsmock.bean.V2xStartBean
import com.inzy.wsmock.bean.VObject
import com.inzy.wsmock.utils.FileIoUtil
import io.netty.channel.Channel
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame
......@@ -19,47 +17,53 @@ import org.slf4j.LoggerFactory
import org.springframework.core.io.ResourceLoader
import org.springframework.stereotype.Component
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
@Component
//@Scope("prototype")
class AdasPushTask(
class AvpPushTask(
// 注入Spring资源加载器(Spring自动装配)
private val resourceLoader: ResourceLoader,
private val pushConfig: PushConfig,
// private val pushConfig: PushConfig,
) : PushTask {
private val instanceId = System.currentTimeMillis() // 实例唯一标识,用于验证多实例
// private val instanceId = System.currentTimeMillis() // 实例唯一标识,用于验证多实例
private val logger = LoggerFactory.getLogger(javaClass)
// 注入ChannelManager单例
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
//AVP状态 park call
private var status = ""
//感知物
private var preDst = mutableListOf<String>()
//电子围栏只推一次开关
private var isFence = AtomicBoolean(false)
//v2x只推一次开关
private var isV2x = AtomicBoolean(false)
@PostConstruct
fun readMockFile() {
logger.info("创建 AdasPushTask 实例,ID: $instanceId")
var classpathResource = resourceLoader.getResource("classpath:adasm/CarVehicle_fz.txt")
// logger.info("创建 AdasPushTask 实例,ID: $instanceId")
var classpathResource = resourceLoader.getResource("classpath:avpm/Car_fangzhen_park.txt")
// 读取文件内容(Kotlin简化写法)
CoroutineScope(Dispatchers.IO).launch {
FileIoUtil.getMockToList(classpathResource.inputStream, carDst)
// println("读取到文件内容:${dst.count()}")
classpathResource = resourceLoader.getResource("classpath:adasm/PerTarget.txt")
//读取泊车数据
FileIoUtil.getMockToList(classpathResource.inputStream, carDstPark)
//读取召车数据
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)
}
}
......@@ -67,7 +71,8 @@ class AdasPushTask(
@PreDestroy
fun destroy() {
// logger.info("销毁 AdasPushTask 实例,ID: $instanceId")
carDst.clear()
carDstPark.clear()
carDstCall.clear()
preDst.clear()
}
......@@ -81,17 +86,13 @@ class AdasPushTask(
pushPre(channel)
}
RequestParamHandler.PARAM_TYPE_VALUE_3 -> {//电子围栏驶入驶出
pushFence(channel)
}
RequestParamHandler.PARAM_TYPE_VALUE_4 -> {//v2x 预警
RequestParamHandler.PARAM_TYPE_VALUE_3 -> {//v2x 预警
pushV2x(channel)
}
else -> {
val msg = JSONObject()
msg.put("type", "adas")
msg.put("type", "avp")
sendMsg(channel, msg.toJSONString())
}
}
......@@ -102,36 +103,43 @@ class AdasPushTask(
*/
private fun pushCarPos(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch {
while (isActive) {
if (pushConfig.pushStart.get() == 0) {
// println("------------没开始推")
// carIndex = 0
carPos = 0
isV2x.set(false)
// carIndex.set(0)
isFence.set(false)
delay(200)
// sendMsg(channel, carDst.first())
continue
}
if (carDst.isNotEmpty()) {
carDst.forEachIndexed { index, string ->
// println("carIndex = ${carIndex}")
if (pushConfig.pushStart.get() == 0) {
return@forEachIndexed
}
//推送电子围栏
carPos = index
// takeFen(index)
// carIndex.set(index)
sendMsg(channel, string)
delay(200)
}
// println("---- pushConfig.pushStart.set(0)")
// carIndex.set(0)
pushConfig.pushStart.set(0)
}
delay(8000)
status = "park"
//开始推送泊车
carDstPark.forEachIndexed { i, str ->
val mRoutes = JSON.parseObject(str, MRoutes::class.java)
mRoutes.status = status
mRoutes.carPos = i
sendMsg(channel, JSON.toJSONString(mRoutes))
delay(300)
}
//泊车完成
val parkTemp=MRoutes().apply {
status = "park_com"
}
sendMsg(channel, JSON.toJSONString(parkTemp))
delay(3000)
status = "call"
//开始推送召车
carDstCall.forEachIndexed { i, str ->
val mRoutes = JSON.parseObject(str, MRoutes::class.java)
mRoutes.status = status
mRoutes.carPos = i
sendMsg(channel, JSON.toJSONString(mRoutes))
delay(200)
}
//召车完成
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(
preDst.forEachIndexed { index, string ->
// println("index = ${index}")
sendMsg(channel, string)
delay(500)
delay(4500)
}
pushPre(channel)
}
}
}
/**电子围栏**/
private fun pushFence(channel: Channel) {
private fun pushV2x(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch {
while (isActive) {
// println("---carPos = ${carPos}")
if (carPos == 0) {
delay(100)
continue
}
if (carPos == 30) {//驶入 130
if (isFence.compareAndSet(false, true)) {
val driveInOrOut = DriveInOrOut().apply {
finished = true
}
sendMsg(channel, JSON.toJSONString(driveInOrOut))
isFence.set(false)
}
} else if (carPos == 500) {//驶出 500
if (isFence.compareAndSet(false, true)) {
val driveInOrOut = DriveInOrOut().apply {
finished = false
carPos = 8
if (status.equals("park")) {
when (carPos) {
8 -> {//紧急制动预警
val v2x = V2xStartBean().apply {
type = 6
objects =
listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
}
pushV2xAtomic(channel, v2x)
}
sendMsg(channel, JSON.toJSONString(driveInOrOut))
}
}
delay(50)
}
}
}
private fun takeFen(index: Int) {
if (index == 0) {
isFence.set(false)
return
}
if (index == 130) {
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))
}
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"
30 -> {//前向碰撞
val v2x = V2xStartBean().apply {
type = 1
objects =
listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
}
pushV2xAtomic(channel, v2x)
}
/****限速***/
private val XIANSU_V2X =
"F2000004193C010000019B8793FAE914534D3030303030310000000000000001110207D000030004000137656266346363372D383133322D343530302D386262632D6132356539386138356433380000019B8793FAE94570A34217BA687AFFFFFFFF0055050064000001FFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000"
60 -> {//弱势交通参与者
val v2x = V2xStartBean().apply {
type = 12
objects =
listOf(VObject(""), VObject("50332456-3030-3030-3530-303334533955"))
}
pushV2xAtomic(channel, v2x)
}
}
private fun pushV2x(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch {
while (isActive) {
if (pushConfig.pushStart.get() == 0) {
delay(100)
continue
}
if (carPos < 100)
continue
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)
} else if (status.equals("call")) {
when (carPos) {
70 -> {//盲区预警
val v2x = V2xStartBean().apply {
type = 4
objects =
listOf(VObject(""), VObject("2435"))
}
pushV2xAtomic(channel, v2x)
}
}
}
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)) {
// val msgObj = JSONObject()
// msgObj["content"] = "定时推送消息 type=2 ${LocalDateTime.now()}"
val str = JSONObject.toJSONString(v2xStartBean)
sendMsg(channel, str)
if (change) {
isV2x.set(false)
......@@ -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) {
if (!channel.isActive()) {
// println("无在线客户端,跳过推送")
......
......@@ -2,22 +2,13 @@ package com.inzy.wsmock.push
import com.inzy.wsmock.RequestParamHandler
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
@Component
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) {
var path = ""
......@@ -38,12 +29,9 @@ class PushFactory(
private fun createPushProduct(path: String): PushTask {
when (path) {
"/ws/adas" -> {
// 关键:每次调用 getBean 都会创建新的 AdasPushTask 实例
// return applicationContext.getBean(AdasPushTask::class.java)
return adasPushTask
"/ws/avp" -> {
return avpPushTask
}
else -> {
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