| | |
| | | import com.flightfeather.uav.common.utils.GsonUtils |
| | | import com.flightfeather.uav.domain.entity.BaseRealTimeData |
| | | import com.flightfeather.uav.domain.repository.SceneInfoRep |
| | | import com.flightfeather.uav.domain.repository.SourceTraceRep |
| | | import com.flightfeather.uav.lightshare.bean.DataVo |
| | | import com.flightfeather.uav.socket.sender.UnderwayWebSocketSender |
| | | import io.netty.channel.ChannelHandlerContext |
| | |
| | | * @date 2025/5/13 |
| | | * @author feiyu02 |
| | | */ |
| | | class UnderwayWebSocketServerHandler(sceneInfoRep: SceneInfoRep) : BaseHandler() { |
| | | class UnderwayWebSocketServerHandler(sceneInfoRep: SceneInfoRep, sourceTraceRep: SourceTraceRep) : BaseHandler() { |
| | | |
| | | private val sourceTraceController = SourceTraceController(sceneInfoRep) |
| | | private val sourceTraceController = SourceTraceController(sceneInfoRep, sourceTraceRep) |
| | | |
| | | override var tag: String = "UAV-WS" |
| | | |
| | |
| | | } |
| | | |
| | | override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) { |
| | | super.channelRead(ctx, msg) |
| | | // super.channelRead(ctx, msg) |
| | | when (msg) { |
| | | is TextWebSocketFrame -> { |
| | | val msgTxt = msg.text() |
| | | |
| | | println(msgTxt) |
| | | // ctx?.channel()?.writeAndFlush(msg) |
| | | |
| | | // Test |
| | | try { |
| | | if (msgTxt == "start") { |
| | | sourceTraceController.initTask() |
| | | } else { |
| | | val data = GsonUtils.parserJsonToArrayBeans(msgTxt, DataVo::class.java) |
| | | data.forEach { |
| | | sourceTraceController.addOneData( |
| | | it.toBaseRealTimeData(BaseRealTimeData::class.java) |
| | | ) |
| | | when (msgTxt) { |
| | | "start" -> { |
| | | sourceTraceController.initTask() |
| | | println(msgTxt) |
| | | } |
| | | "ping" -> { |
| | | ctx?.channel()?.writeAndFlush(TextWebSocketFrame("ping checked")) |
| | | } |
| | | else -> { |
| | | println(msgTxt) |
| | | val data = GsonUtils.parserJsonToArrayBeans(msgTxt, DataVo::class.java) |
| | | data.forEach { |
| | | sourceTraceController.addOneData( |
| | | it.toBaseRealTimeData(BaseRealTimeData::class.java) |
| | | ) |
| | | } |
| | | } |
| | | } |
| | | } catch (e: Exception) { |