Commit d3e221c7 authored by p x's avatar p x
Browse files

111

parent 28fd8c31
# wsmock
WebSockset 服务用来推送模拟数据
# main 分支
stomp协议是先链接后订阅是2步骤,前端要新增js依赖,修改代码
# ws_netty 分支
netty包实现的 websockset
# avp_netty 分支
netty包实现的 websockset
package com.inzy.wsmock
import com.alibaba.fastjson2.JSON
import com.inzy.wsmock.bean.LoginSuccBean
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController
@RestController
class LoginController {
/**
* 登录
*/
@PostMapping("api/perm/admin/auth/passLogin")
fun findDrFence(@RequestBody any: Any): LoginSuccBean {
val json ="{\"code\":1,\"msg\":\"操作成功\",\"result\":{\"token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJjNzNkNzA4M2I1YjU0OWI0OTBiZWZlMGEyMmVlM2I3OSIsImNyZWF0ZVRpbWUiOjE3NjkwNzA4OTQ1NDYsInVzZXJUeXBlIjoxLCJzb3VyY2UiOjAsInB3ZEV4cGlyZWQiOmZhbHNlLCJ1c2VybmFtZSI6ImhtaSJ9.F5Vfef1DX_H2JoNo-5zUPzIP5geXzpnj6TYOCjpSunA\",\"username\":\"HMI\",\"loginTime\":1769070894547,\"expire\":1440,\"returnUri\":null,\"pwdExpiredFlag\":false,\"tenantId\":1000000001},\"success\":true}"
val loginSuccBean = JSON.parseObject(json, LoginSuccBean::class.java)
return loginSuccBean
}
}
\ No newline at end of file
package com.inzy.wsmock
import jakarta.annotation.PreDestroy
import org.springframework.stereotype.Component
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
@Component
class PushConfig {
// 定时推送开关(默认关闭)
val pushStart = AtomicInteger(0)
// 推送间隔(毫秒,默认5秒)
var pushInterval: Long = 5000
@PreDestroy
fun destroy() {
pushStart.set(0)
}
}
\ No newline at end of file
package com.inzy.wsmock
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
/**
* 推送配置控制接口
*/
//@RestController
//@RequestMapping("/api/push")
class PushConfigController(
// 注入PushConfig组件(Spring自动管理单例)
// private val pushConfig: PushConfig
) {
/**
* 设置推送开关状态
*/
/* @GetMapping("mock/startnavi")
fun setPushStatus(
// 必传参数:是否启用推送
@RequestParam("start") start: Int
): NaviMockBean {
pushConfig.pushStart.set(start)
val message = if (start == 1) "推送开关已启用" else "推送开关已禁用"
var naviMockBean = NaviMockBean().apply {
code = 200
msg = message
}
return naviMockBean
// return JSON.toJSONString(naviMockBean)
}*/
}
\ No newline at end of file
package com.sd.cavphmi.bean
/***网联车辆位姿
* {
* "data": {
* "businessStatus": "DRIVING",
* "spaceName": "B075",
* "vehiclePos": [
* 116.50268,
* 39.808735,
* 59.688720703125
* ],
* "routing": [
*
* ],
* "progress": null
* }
* }
* **/
//data class CarVehicle(
// val data: VehData
//)
class CarVehicle {
var businessStatus: String = ""
// val progress: Any = ""
// val routing: List<Any>? = null
var spaceName: String = ""
//vehiclePos 里面分别是 经度、纬度、航向角
var vehiclePos: List<Double>? = null
}
\ No newline at end of file
package com.inzy.wsmock.bean
/***登录成功返回
* {
* "code": 1,
* "msg": "操作成功",
* "result": {
* "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJjNzNkNzA4M2I1YjU0OWI0OTBiZWZlMGEyMmVlM2I3OSIsImNyZWF0ZVRpbWUiOjE3NjMxMDg5MzUyMzQsInVzZXJUeXBlIjoxLCJzb3VyY2UiOjAsInB3ZEV4cGlyZWQiOmZhbHNlLCJ1c2VybmFtZSI6ImhtaSJ9.0GJtC7YaduYUHpknLTpvRd4f4876uygPWKgioMvwRtM",
* "username": "HMI",
* "loginTime": 1763108935236,
* "expire": 1440,
* "returnUri": null,
* "pwdExpiredFlag": false
* },
* "success": true
* }
* **/
data class LoginSuccBean(
val code: Int,
val msg: String,
val result: LoginResult,
val success: Boolean
)
data class LoginResult(
val expire: Int,
val loginTime: Long,
val pwdExpiredFlag: Boolean,
val returnUri: Any="",
val token: String,
val username: String
)
\ No newline at end of file
package com.inzy.wsmock.bean
//模拟倒车路径
data class ParkPath(
val code: String,
val msg: String,
val result: PResult
)
data class PResult(
val execType: Any="",
val execTypeDesc: Any="",
val parkingPlace: Any="",
val parkingPlaceId: String,
val points: Any="",
val routes: List<PRoute>,
val time: Any="",
val vehicleId: String,
val vehicleInfo: Any=""
)
data class PRoute(
val destination: List<Double>,
val gear: Int,//3=前进 1=后退
val origin: List<Double>,
val polyline: List<List<Double>>,
val routeId: Int
)
\ No newline at end of file
......@@ -5,10 +5,12 @@ import com.alibaba.fastjson2.JSONObject
import com.inzy.wsmock.ChannelManager
import com.inzy.wsmock.RequestParamHandler
import com.inzy.wsmock.bean.CarVeh
import com.inzy.wsmock.bean.ParkPath
import com.inzy.wsmock.bean.V2xStartBean
import com.inzy.wsmock.bean.VObject
import com.inzy.wsmock.utils.FileIoUtil
import com.inzy.wsmock.utils.MyMapUtils
import com.sd.cavphmi.bean.CarVehicle
import io.netty.channel.Channel
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame
import jakarta.annotation.PostConstruct
......@@ -37,6 +39,9 @@ class AvpPushTask(
// private var carDstPark = mutableListOf<String>()
private var carVehPark: CarVeh? = null
//倒车路径
private var parkPath: ParkPath? = null
//车辆位姿,召车
// private var carDstCall = mutableListOf<String>()
private var carVehCall: CarVeh? = null
......@@ -63,11 +68,43 @@ class AvpPushTask(
//读取泊车数据
val parkStr = FileIoUtil.getFileDate(classpathResource.inputStream)
carVehPark = JSON.parseObject(parkStr, CarVeh::class.java)
//计算航向角
carVehPark!!.rs?.forEachIndexed { i, doubles ->
if (i > 0) {
val p1 = carVehPark?.rs!!.get(i - 1)
val pc = doubles
val head = MyMapUtils.calculateBearing(
p1[0], p1[1],
pc[0], pc[1]
)
doubles.add(head)
} else {
carVehPark!!.rs!!.get(0).add(0.0)
}
}
//读取倒车入库数据
classpathResource = resourceLoader.getResource("classpath:avpm/parkpath.txt")
val parking = FileIoUtil.getFileDate(classpathResource.inputStream)
parkPath = JSON.parseObject(parking, ParkPath::class.java)
//读取召车数据
classpathResource = resourceLoader.getResource("classpath:avpm/Car_fangzhen_call.txt")
val callStr = FileIoUtil.getFileDate(classpathResource.inputStream)
carVehCall = JSON.parseObject(callStr, CarVeh::class.java)
//计算航向角
carVehCall!!.rs?.forEachIndexed { i, doubles ->
if (i > 0) {
val p1 = carVehCall?.rs!!.get(i - 1)
val pc = doubles
val head = MyMapUtils.calculateBearing(
p1[0], p1[1],
pc[0], pc[1]
)
doubles.add(head)
} else {
carVehCall!!.rs!!.get(0).add(0.0)
}
}
//读取感知物数据
classpathResource = resourceLoader.getResource("classpath:avpm/PerTarget.txt")
......@@ -78,8 +115,6 @@ class AvpPushTask(
@PreDestroy
fun destroy() {
// logger.info("销毁 AdasPushTask 实例,ID: $instanceId")
// carDstPark.clear()
// carDstCall.clear()
preDst.clear()
}
......@@ -98,69 +133,60 @@ class AvpPushTask(
}
else -> {
val msg = JSONObject()
msg.put("type", "avp")
sendMsg(channel, msg.toJSONString())
// val msg = JSONObject()
// msg.put("type", "avp")
// sendMsg(channel, msg.toJSONString())
}
}
}
private var carVehicle = CarVehicle()
/**
* 推送车辆位姿
*/
private fun pushCarPos(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch {
delay(10000)
delay(12000)
if (carVehPark?.rs?.count() == 0 || carVehCall?.rs?.count() == 0)
return@launch
status = "park"
//开始推送泊车
if (carVehPark != null) {
carVehPark!!.status = status
val total = carVehPark!!.rs?.count()
for (i in 0 until total!!) {
carIndex = i
carVehPark?.carPos = i
if (i > 0) {
var p1 = carVehPark?.rs!!.get(i - 1)
var pc = carVehPark?.rs!!.get(i)
var head = MyMapUtils.calculateBearing(
p1[0], p1[1],
pc[0], pc[1]
)
carVehPark!!.rs!!.get(i).add(head)
}
sendMsg(channel, JSON.toJSONString(carVehPark))
delay(300)
}
carVehicle.businessStatus = status
carVehPark!!.status = status
carVehPark!!.rs?.forEachIndexed { i, doubles ->
carIndex++
carVehicle.vehiclePos = doubles
sendMsg(channel, JSON.toJSONString(carVehPark))
delay(300)
}
//开始倒车入库
status = "parking"
carVehicle.businessStatus = status
//开始后退
var forword = parkPath!!.result.routes.find { it.gear == 1 }
forword?.polyline?.forEachIndexed { index, doubles ->
carIndex++
carVehicle.vehiclePos = listOf<Double>(doubles[0], doubles[1], doubles[3])
sendMsg(channel, JSON.toJSONString(carVehicle))
delay(300)
}
//泊车完成
status = "park_com"
carVehPark?.apply {
this.status = this@AvpPushTask.status
carPos = 0
rs = listOf()
}
carVehicle.businessStatus = status
carVehicle.vehiclePos = emptyList()
//泊车完成消息
sendMsg(channel, JSON.toJSONString(carVehPark))
delay(3000)
//开始推送召车
status = "call"
if (carVehCall != null) {
carVehCall!!.status = status
val total = carVehCall!!.rs?.count()
for (i in 0 until total!!) {
carIndex = i
carVehCall?.carPos = i
if (i > 0) {
var p1 = carVehCall?.rs!!.get(i - 1)
var pc = carVehCall?.rs!!.get(i)
var head = MyMapUtils.calculateBearing(
p1[0], p1[1],
pc[0], pc[1]
)
carVehCall!!.rs!!.get(i).add(head)
}
sendMsg(channel, JSON.toJSONString(carVehCall))
delay(300)
}
/* //开始推送召车
carVehCall!!.status = status
carVehCall!!.rs?.forEachIndexed { i, doubles ->
carIndex = i
carVehCall?.carPos = i
sendMsg(channel, JSON.toJSONString(carVehCall))
delay(300)
}
//召车完成
status = "call_com"
......@@ -169,6 +195,7 @@ class AvpPushTask(
carPos = 0
rs = listOf()
}
//发送召车完成消息
sendMsg(channel, JSON.toJSONString(carVehCall))
//全部完成
carIndex = 0
......@@ -178,7 +205,7 @@ class AvpPushTask(
carPos = 0
rs = listOf()
}
sendMsg(channel, JSON.toJSONString(carVehCall))
sendMsg(channel, JSON.toJSONString(carVehCall))*/
}
}
......@@ -212,16 +239,16 @@ class AvpPushTask(
// objects =
// listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
// }
pushV2xAtomic(channel, 6,"f117fdfa-feff-0100-85dc-35850000acb0")
pushV2xAtomic(channel, 6, "f117fdfa-feff-0100-85dc-35850000acb0")
}
30 -> {//前向碰撞
/* val v2x = V2xStartBean().apply {
type = 1
objects =
listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
}*/
pushV2xAtomic(channel, 1,"f117fdfa-feff-0100-85dc-35850000acb0")
/* val v2x = V2xStartBean().apply {
type = 1
objects =
listOf(VObject(""), VObject("f117fdfa-feff-0100-85dc-35850000acb0"))
}*/
pushV2xAtomic(channel, 1, "f117fdfa-feff-0100-85dc-35850000acb0")
}
60 -> {//弱势交通参与者
......@@ -230,19 +257,19 @@ class AvpPushTask(
objects =
listOf(VObject(""), VObject("50332456-3030-3030-3530-303334533955"))
}*/
pushV2xAtomic(channel, 12,"50332456-3030-3030-3530-303334533955")
pushV2xAtomic(channel, 12, "50332456-3030-3030-3530-303334533955")
}
}
} else if (status.equals("call")) {
when (carIndex) {
70 -> {//盲区预警
/* val v2x = V2xStartBean().apply {
type = 4
objects =
listOf(VObject(""), VObject("2435"))
}*/
pushV2xAtomic(channel, 4,"2345")
/* val v2x = V2xStartBean().apply {
type = 4
objects =
listOf(VObject(""), VObject("2435"))
}*/
pushV2xAtomic(channel, 4, "2345")
}
}
}
......
......@@ -5,7 +5,7 @@ spring:
application:
name: avpmock
server:
port: 8088
port: 8090 # HTTP 端口
servlet:
encoding:
charset: UTF-8
......@@ -39,10 +39,10 @@ logging:
max-file-size: 10MB
max-history: 30
total-size-cap: 1GB
file-name-pattern: logs/wsmock-.%d{yyyy-MM-dd}.%i.log
file-name-pattern: logs/avpmock-.%d{yyyy-MM-dd}.%i.log
# Netty WebSocket配置
netty:
websocket:
port: 8090 # Netty WebSocket端口
port: 8091 # Netty WebSocket端口
{
"code": "1",
"msg": "执行成功",
"result": {
"vehicleId": "9",
"parkingPlaceId": "421",
"routes": [
{
"routeId": 1,
"origin": [
116.50254394816011,
39.809039362307594
],
"destination": [
116.50257504818846,
39.80900097735677
],
"gear": 3,
"polyline": [
[
116.50254394816011,
39.809039362307594,
0.5,
148.10218269263586
],
[
116.50254457016067,
39.80903859460858,
0.5,
148.10218229911192
],
[
116.50254519216124,
39.80903782690956,
0.5,
148.1021822250557
],
[
116.5025458141618,
39.80903705921054,
0.5,
148.10218183153174
],
[
116.50254643616238,
39.80903629151153,
0.5,
148.10218154449709
],
[
116.50254705816295,
39.80903552381251,
0.5,
148.10218115097314
],
[
116.50254768016352,
39.8090347561135,
0.5,
148.10218086393846
],
[
116.50254830216409,
39.809033988414484,
0.5,
148.10218194783928
],
[
116.50254892416464,
39.809033220715456,
0.5,
148.10217902542288
],
[
116.50254954616523,
39.80903245301645,
0.5,
148.10218126728074
],
[
116.50255016816578,
39.80903168531743,
0.5,
148.10218076726758
],
[
116.50255079016634,
39.809030917618415,
0.5,
148.10217964174365
],
[
116.50255141216691,
39.809030149919394,
0.5,
148.10217924821978
],
[
116.50255203416748,
39.80902938222038,
0.5,
148.10217885469592
],
[
116.50255265616805,
39.80902861452137,
0.5,
148.10217878063978
],
[
116.50255327816862,
39.809027846822346,
0.5,
148.10217943858373
],
[
116.50255390016918,
39.809027079123325,
0.5,
148.10217788710278
],
[
116.50255452216973,
39.80902631142431,
0.5,
148.1021780260252
],
[
116.50255514417032,
39.8090255437253,
0.5,
148.1021773130336
],
[
116.50255576617087,
39.80902477602628,
0.5,
148.1021772389775
],
[
116.50255638817144,
39.80902400832726,
0.5,
148.1021769519429
],
[
116.50255701017201,
39.80902324062825,
0.5,
148.10217677139758
],
[
116.5025576321726,
39.80902247292923,
0.5,
148.10217637787377
],
[
116.50255825417315,
39.809021705230215,
0.5,
148.10217598434994
],
[
116.50255887617372,
39.8090209375312,
0.5,
148.10217601678315
],
[
116.50255949817429,
39.80902016983218,
0.5,
148.10217635525942
],
[
116.50256012017485,
39.80901940213316,
0.5,
148.1021741782677
],
[
116.50256074217543,
39.80901863443415,
0.5,
148.10217620714738
],
[
116.50256136417599,
39.80901786673513,
0.5,
148.10217465566646
],
[
116.50256198617654,
39.80901709903611,
0.5,
148.10217426214265
],
[
116.50256260817713,
39.8090163313371,
0.5,
148.10217502657602
],
[
116.50256323017769,
39.809015563638084,
0.5,
148.10217400754144
],
[
116.50256385217826,
39.80901479593906,
0.5,
148.1021734010391
],
[
116.50256447417883,
39.80901402824005,
0.5,
148.10217300751535
],
[
116.50256509617938,
39.809013260541036,
0.5,
148.10217293345937
],
[
116.50256571817995,
39.809012492842015,
0.5,
148.10217264642492
],
[
116.50256634018052,
39.809011725143,
0.5,
148.1021734108583
],
[
116.50256696218108,
39.80901095744399,
0.5,
148.10217207235593
],
[
116.50256758418166,
39.80901018974497,
0.5,
148.10217210478928
],
[
116.50256820618223,
39.809009422045946,
0.5,
148.1021711788192
],
[
116.50256882818279,
39.80900865434693,
0.5,
148.10217121125254
],
[
116.50256945018336,
39.80900788664792,
0.5,
148.10217071123955
],
[
116.50257007218393,
39.809007118948905,
0.5,
148.10217127611924
],
[
116.50257069418448,
39.80900635124988,
0.5,
148.10217024365994
],
[
116.50257131618505,
39.809005583550864,
0.5,
148.10216995662552
],
[
116.50257193818562,
39.80900481585185,
0.5,
148.10216988256963
],
[
116.5025725601862,
39.80900404815283,
0.5,
148.10216948904593
],
[
116.50257318218677,
39.809003280453815,
0.5,
148.10216898903298
],
[
116.50257380418734,
39.8090025127548,
0.5,
148.10217017942364
],
[
116.50257442618789,
39.80900174505578,
0.5,
148.10216841496418
],
[
116.50257504818846,
39.80900097735677,
0.5,
148.10216841496418
]
]
},
{
"routeId": 2,
"origin": [
116.50257504818846,
39.80900097735677
],
"destination": [
116.5024625,
39.8090317
],
"gear": 1,
"polyline": [
[
116.50257504818846,
39.80900097735677,
0.5,
150.47794433755706
],
[
116.50257218918523,
39.80900485570903,
0.5,
154.27310728039356
],
[
116.5025697015945,
39.80900882155232,
0.5,
156.67295798187433
],
[
116.50256745223952,
39.80901282852125,
0.5,
157.8133738046629
],
[
116.50256532727003,
39.80901683117987,
0.5,
157.84012669821846
],
[
116.50256323087986,
39.80902078528453,
0.5,
156.88041033745833
],
[
116.50256108403372,
39.80902464804938,
0.5,
155.0349202584366
],
[
116.50255882320319,
39.80902837841471,
0.5,
152.37984099954474
],
[
116.50255639911234,
39.809031937318096,
0.5,
148.9730402515233
],
[
116.50255377549128,
39.80903528796794,
0.5,
144.86214711490197
],
[
116.50255092784093,
39.8090383961204,
0.5,
140.09356276594684
],
[
116.50254784220454,
39.80904123035833,
0.5,
134.7219998248488
],
[
116.50254451395082,
39.8090437623737,
0.5,
128.81951628621687
],
[
116.5025409465643,
39.80904596725211,
0.5,
122.48239643592717
],
[
116.50253715044603,
39.809047823760544,
0.5,
115.83350619337386
],
[
116.50253314172312,
39.80904931463762,
0.5,
109.01823320278112
],
[
116.50252894106745,
39.809050426886664,
0.5,
102.19391587555128
],
[
116.50252457252354,
39.80905115207155,
0.5,
95.5153521727076
],
[
116.50252006234572,
39.80905148661524,
0.5,
89.12084176468869
],
[
116.50251543784445,
39.80905143210117,
0.5,
83.12290608687363
],
[
116.50251072624177,
39.80905099557725,
0.5,
77.60560229976858
],
[
116.5025059535361,
39.80905018986276,
0.5,
72.62772394588927
],
[
116.50250114337594,
39.80904903385788,
0.5,
68.22973689932553
],
[
116.50249631594309,
39.80904755285604,
0.5,
64.44221270751927
],
[
116.50249148684485,
39.80904577885904,
0.5,
61.29429364132028
],
[
116.50248666601549,
39.8090437508948,
0.5,
58.821619453979906
],
[
116.50248185662682,
39.80904151533802,
0.5,
57.07376338261474
],
[
116.50247705400817,
39.809039126233515,
0.5,
56.12142584978807
],
[
116.50247224457523,
39.80903664562224,
0.5,
56.063314828195246
],
[
116.50246740476837,
39.8090341438702,
0.5,
57.03146193036804
],
[
116.5024625,
39.8090317,
0.5,
57.03146193036804
]
]
}
],
"points": null,
"execType": null,
"execTypeDesc": null,
"vehicleInfo": null,
"time": null,
"parkingPlace": null
}
}
\ No newline at end of file
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