| | |
| | | package com.flightfeather.obd.socket |
| | | |
| | | import com.flightfeather.obd.common.utils.FileUtil |
| | | import com.flightfeather.obd.lightshare.bean.BaseJson |
| | | import com.flightfeather.obd.lightshare.bean.ObdDataVo |
| | | import com.flightfeather.obd.repository.ObdDataRepository |
| | | import com.flightfeather.obd.socket.decoder.VehicleDataDecoder |
| | | import com.google.gson.Gson |
| | | import io.netty.channel.ChannelHandlerContext |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.stereotype.Component |
| | | import org.springframework.util.FileSystemUtils |
| | | import javax.annotation.PostConstruct |
| | | import javax.annotation.Resource |
| | | |
| | |
| | | @Autowired |
| | | lateinit var obdDataRepository: ObdDataRepository |
| | | |
| | | val vehicleDataDecoder = VehicleDataDecoder() |
| | | |
| | | @PostConstruct |
| | | fun init() { |
| | | instance = this |
| | | instance.obdDataRepository = this.obdDataRepository |
| | | } |
| | | |
| | | fun dealMsg(msg: String, ctx: ChannelHandlerContext?) { |
| | | try { |
| | | val baseJson = Gson().fromJson<BaseJson>(msg, BaseJson::class.java) |
| | | when (baseJson.cmdCode) { |
| | | 2001 -> { |
| | | val data = Gson().fromJson(msg, ObdDataVo::class.java) |
| | | DeviceSession.saveDevice(data.obdVin, ctx) |
| | | instance.obdDataRepository.saveObdData(data) |
| | | } |
| | | } |
| | | } catch (e: Throwable) { |
| | | // println("------收到格式错误的数据:$msg") |
| | | } |
| | | fun dealStringMsg(msg: String, ctx: ChannelHandlerContext?) { |
| | | // try { |
| | | // val baseJson = Gson().fromJson<BaseJson>(msg, BaseJson::class.java) |
| | | // when (baseJson.cmdCode) { |
| | | // 2001 -> { |
| | | // val data = Gson().fromJson(msg, ObdDataVo::class.java) |
| | | // DeviceSession.saveDevice(data.obdVin, ctx) |
| | | // instance.obdDataRepository.saveObdData(data) |
| | | // } |
| | | // } |
| | | // } catch (e: Throwable) { |
| | | // } |
| | | |
| | | saveToTxt(msg) |
| | | val packageData = vehicleDataDecoder.decode(msg) |
| | | } |
| | | |
| | | fun dealByteArrayMsg(msg: ByteArray, ctx: ChannelHandlerContext?) { |
| | | val b = ByteArray(20) {19} |
| | | println(b) |
| | | } |
| | | |
| | | fun saveToTxt(msg: String) { |
| | | val data = "data=> $msg" |
| | | FileUtil.instance?.saveObdData(data) |
| | | } |
| | | } |