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

添加停车场车位数据

parent 1141bca5
......@@ -5,3 +5,38 @@ https://protobuf.dev/getting-started/javatutorial/
protoc --java_out=app\src\main\java\ -I app\src\main\proto\ response.proto
protoc --java_out=app\src\main\java\ -I d:\WorkSpace\suzhouavp\app\src\main\proto\ response.proto
## websocket 订阅字典
var subDic = mapOf(
"/topic/vehicle" to "/avp/api/VL961/vehicle/1694264612474306561",//车辆位姿数据
"/topic/dataMerge" to "/avp/api/VL961/dataMerge",//感知目标物
"/topic/signal" to "/avp/api/VL961/signal",
"/topic/v2xStart" to "/avp/api/VL961/v2xStart",//v2x预警开始
"/topic/v2xEnd" to "/avp/api/VL961/v2xEnd",//v2x预警结束
"/topic/vehicleStatus" to "/avp/api/VL961/vehicleStatus",//联网车辆数据
"/topic/timeDelay" to "/avp/api/VL961/timeDelay",
"/topic/points" to "/avp/api/VL961/points",//停车位变更
"/topic/linePlaning" to "/avp/api/VL961/linePlaning",//全局路径发生切换
"/topic/partLine" to "/avp/api/VL961/partLine",// // 局部路径
"/topic/rsiEvent" to "/avp/api/VL961/rsiEvent",// rsi事件
)
## websocket回调字典
var dic = mapOf(
5231 to "/topic/vehicle",
5232 to "/topic/dataMerge",
5233 to "topic/signa",
5234 to "/topic/v2xStart",
5235 to "/topic/v2xEnd",
5236 to "/topic/vehicleStatus",
5237 to "/topic/timeDelay",
1 to "/topic/point",
52310 to "/topic/linePlaning",
52311 to "/topic/rsiEvent",
52312 to "/topic/partLine",
)
## 获取订单信息 getOrderData 后只有当avpStatus=3或5的时候需要路径规划
This diff is collapsed.
package com.sd.cavphmi.bean
/**全局路径发生切换***/
class LinePlaningBean {
}
\ No newline at end of file
data class LinePlaningBean(
val objectData: List<LinePlaning>,
val wsTime: Long
)
data class LinePlaning(var line:List<List<Double>>)
\ No newline at end of file
package com.sd.cavphmi.bean
/**局部路径***/
class PartLineBean {
}
\ No newline at end of file
data class PartLineBean(val objectData: List<PartLine>)
data class PartLine(
var type: Int,
var pointStr: String,
val globalPath: List<List<Double>>,
)
\ No newline at end of file
package com.sd.cavphmi.bean
//class SpaceDataLocBean : ArrayList<SpaceDataLocBeanItem>()
/***本地停车场***/
data class SpaceDataLocBeanItem(
val center: List<Double>,
val controlPoint: List<Double>,
val coordinates: List<List<Double>>,
val heading: Int,
val spaceCode: String,
val type: String
)
\ No newline at end of file
......@@ -4,12 +4,12 @@ object WebSetBean {
/* "/topic/vehicle"to "/topic/vehicle/1556919708184276993", */
//目前只有车辆和感知
var subDic = mapOf(
"/topic/vehicle" to "/avp/api/VL961/vehicle/1694264612474306561",
"/topic/dataMerge" to "/avp/api/VL961/dataMerge",
"/topic/vehicle" to "/avp/api/VL961/vehicle/1694264612474306561",//车辆位姿数据
"/topic/dataMerge" to "/avp/api/VL961/dataMerge",//感知目标物
"/topic/signal" to "/avp/api/VL961/signal",
"/topic/v2xStart" to "/avp/api/VL961/v2xStart",
"/topic/v2xEnd" to "/avp/api/VL961/v2xEnd",
"/topic/vehicleStatus" to "/avp/api/VL961/vehicleStatus",
"/topic/v2xStart" to "/avp/api/VL961/v2xStart",//v2x预警开始
"/topic/v2xEnd" to "/avp/api/VL961/v2xEnd",//v2x预警结束
"/topic/vehicleStatus" to "/avp/api/VL961/vehicleStatus",//联网车辆数据
"/topic/timeDelay" to "/avp/api/VL961/timeDelay",
"/topic/points" to "/avp/api/VL961/points",//停车位变更
"/topic/linePlaning" to "/avp/api/VL961/linePlaning",//全局路径发生切换
......
......@@ -37,7 +37,7 @@ object NetworkModule {
var logging = HttpLoggingInterceptor()
init {
logging.level = HttpLoggingInterceptor.Level.NONE
logging.level = HttpLoggingInterceptor.Level.BODY
}
......
......@@ -80,7 +80,7 @@ class ParseSocketRepo @Inject constructor(private val clientRetrofitMethod: Clie
}
/***获取路径规划***/
suspend fun getLinePlaning(vehiclePlate:String): MyResult<ParkLinePlan> {
suspend fun getLinePlaning(vehiclePlate: String = "吉AC242"): MyResult<ParkLinePlan> {
var map = mutableMapOf("vehiclePlate" to vehiclePlate)
var body = RequestBodyUtil.toRequestBody(map)
try {
......
......@@ -51,6 +51,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainVm>() {
viewModel.getCurrentTime()
viewModel.getMobileNetworkSignal()
viewModel.getOrderData()
viewModel.getSpaceDataLoc()
// viewModel.getSpaceData()
//test
// viewModel.findPathPlanning()
......
......@@ -21,7 +21,8 @@ object FileIoUtils {
/**
* 读取asset 文件
*/
fun getAssetContent(context: Context, fileName: String): String {
suspend fun getAssetContent(context: Context, fileName: String):String {
return withContext(Dispatchers.IO) {
val assetManager = context.assets
var stringBuilder = StringBuilder()
var bf: BufferedReader? = null
......@@ -36,15 +37,15 @@ object FileIoUtils {
stringBuilder.append(line)
}
bf?.close()
assetManager.close()
return stringBuilder.toString()
return@withContext stringBuilder.toString()
} catch (e: IOException) {
e.printStackTrace()
return ""
} finally {
bf?.close()
assetManager.close()
}
return@withContext ""
}
}
......
package com.sd.cavphmi.viewmodels
import android.content.Context
import android.text.TextUtils
import androidx.activity.viewModels
import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.sd.cavphmi.base.MyBaseViewModel
import com.sd.cavphmi.bean.CarVehicle
import com.sd.cavphmi.bean.LinePlaningBean
......@@ -17,6 +16,7 @@ import com.sd.cavphmi.bean.PartLineBean
import com.sd.cavphmi.bean.PerTarget
import com.sd.cavphmi.bean.ReqBean
import com.sd.cavphmi.bean.RsiEventBean
import com.sd.cavphmi.bean.SpaceDataLocBeanItem
import com.sd.cavphmi.bean.SpaceNoBean
import com.sd.cavphmi.bean.VToXImgBean
import com.sd.cavphmi.bean.VehicleStats
......@@ -35,6 +35,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.java_websocket.handshake.ServerHandshake
import protocol.Response
import java.lang.reflect.Type
import java.net.URI
import java.util.Timer
import java.util.TimerTask
......@@ -51,6 +52,7 @@ class MainVm @Inject constructor(
private var client: MyWebSocketClient? = null
private var gson = Gson()
//模拟操作
lateinit var mockVM: MockVM
......@@ -73,7 +75,7 @@ class MainVm @Inject constructor(
var orderBean = MutableLiveData<OrderBean>()
//老停车状态,用于判断状态切换
private var oldAvpStatus = -1
// private var oldAvpStatus = -1
// 是否处理路径规划显示的路径
private var needDealPath = false
......@@ -143,10 +145,11 @@ class MainVm @Inject constructor(
fun getOrderData() {
orderTimer.schedule(object : TimerTask() {
override fun run() {
var vehiclePlate = carVehicle.value?.vehicleData?.get(0)?.vehiclePlate ?: ""
if (TextUtils.isEmpty(vehiclePlate)) {
return
}
// var vehiclePlate = carVehicle.value?.vehicleData?.get(0)?.vehiclePlate ?: ""
// if (TextUtils.isEmpty(vehiclePlate)) {
// return
// }
var vehiclePlate = "吉AC242"
viewModelScope.launch {
var result =
parseSocketRepo.getOrderData(vehiclePlate)
......@@ -155,24 +158,31 @@ class MainVm @Inject constructor(
println("-------订单信息---- = ${result.data}")
orderBean.value = result.data
var avpStatus = result.data.avpStatus
var plateNo = result.data.plateNo
if (oldAvpStatus != avpStatus) {
if (avpStatus != 3 && oldAvpStatus == 3) {
// endParkingVehicle() // 结束泊车
} else if (avpStatus == 3) {
startParkingVehicle(plateNo) // 开始泊车
}
if (avpStatus != 5 && oldAvpStatus == 5) {
// 由招车转为其他状态
endRecruitmentVehicle()
} else if (avpStatus == 5) {
// 招车需要显示路径
startRecruitmentVehicle(plateNo)
}
oldAvpStatus = avpStatus
// var plateNo = result.data.plateNo
if (avpStatus == 3) {//泊车
startParkingVehicle("吉AC242")
} else if (avpStatus == 5) {//招车
startRecruitmentVehicle("吉AC242")
} else {
endParkingVehicle() // 结束泊车
endRecruitmentVehicle()//// 由招车转为其他状态
}
}
// if (oldAvpStatus != avpStatus) {
// if (avpStatus != 3 && oldAvpStatus == 3) {
//// endParkingVehicle() // 结束泊车
// } else if (avpStatus == 3) {
// startParkingVehicle(plateNo) // 开始泊车
// }
// if (avpStatus != 5 && oldAvpStatus == 5) {
//
// endRecruitmentVehicle()
// } else if (avpStatus == 5) {
// // 招车需要显示路径
// startRecruitmentVehicle(plateNo)
// }
// oldAvpStatus = avpStatus
// }
is MyResult.Error -> {
println("-------订单信息 ERROR---- = ${result}")
}
......@@ -180,7 +190,7 @@ class MainVm @Inject constructor(
// FileIoUtils.writeToFile(gson.toJson(bean), "carvehicle.txt")
}
}
}, 3000, 1000 * 10)
}, 3000, 1000 * 50)
}
/**开始泊车*/
......@@ -259,7 +269,7 @@ class MainVm @Inject constructor(
/**
* 获取路径规划
*/
fun findPathPlanning(vehiclePlate: String = "吉AC242", ifParking: Boolean = true) {
fun findPathPlanning(vehiclePlate: String, ifParking: Boolean = true) {
viewModelScope.launch {
var result = parseSocketRepo.getLinePlaning(vehiclePlate)
when (result) {
......@@ -285,8 +295,7 @@ class MainVm @Inject constructor(
}
/**查询车位信息**/
/**查询车位信息 判断车位上是否有车**/
fun getSpaceData() {
carSpaNoTimer.schedule(object : TimerTask() {
override fun run() {
......@@ -308,6 +317,17 @@ class MainVm @Inject constructor(
}, 4000, 1000 * 20)
}
/**获取本地车位**/
fun getSpaceDataLoc() {
viewModelScope.launch {
var str = FileIoUtils.getAssetContent(context, "SpaceJSON.json")
var ty = object : TypeToken<List<SpaceDataLocBeanItem>>() {
}.type
var carNo = gson.fromJson<List<SpaceDataLocBeanItem>>(str, ty)
}
}
/**
* 根据停车位编号,获取停车位的具体信息
* @param {*} parkingValue
......@@ -468,7 +488,7 @@ class MainVm @Inject constructor(
/*** 联网车辆位姿数据**/
fun subVehicle(mock: Boolean = false): LiveData<CarVehicle> {
if (mock) {
mockVM.onVehicleMock(carVehicle,heading,speed)
mockVM.onVehicleMock(carVehicle, heading, speed)
} else {
client?.send(getSendData("/topic/vehicle"))
}
......
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