工控机升级
工控机升级云端获取数据版本
This commit is contained in:
@@ -16,6 +16,8 @@ import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
@@ -63,6 +65,27 @@ public class BindingcarProvider implements IMoGoBindingcarProvider {
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认升级工控机docker版本
|
||||
* @param images docker列表
|
||||
* @param padSn SN
|
||||
* @param releaseId 任务ID
|
||||
*/
|
||||
@Override
|
||||
public void upgradeConfirm(List<String> images, String padSn, String releaseId) {
|
||||
IPCUpgradeManager.Companion.getINSTANCE().upgradeConfirm(images, padSn, releaseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新工控机docker版本
|
||||
* @param padSn SN
|
||||
* @param dockerVersion 当前工控机版本
|
||||
*/
|
||||
@Override
|
||||
public void queryContainers(String padSn,String dockerVersion) {
|
||||
IPCUpgradeManager.Companion.getINSTANCE().queryContainers(padSn,dockerVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyCarInfo(BindingcarCallBack callBack) {
|
||||
BindingcarNetWorkManager.getInstance().modifyBindingcar(mAddress, mWidevineIDWithMd5, callBack, getScreenType());
|
||||
|
||||
@@ -4,10 +4,17 @@ import android.content.Context
|
||||
import android.util.Log
|
||||
import com.mogo.aicloud.services.socket.IMogoOnMessageListener
|
||||
import com.mogo.aicloud.services.socket.MogoAiCloudSocketManager
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
|
||||
import com.mogo.eagle.core.data.bindingcar.IPCUpgradeStateInfo
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
|
||||
import com.mogo.eagle.core.function.call.bindingcar.CallerBindingCarListenerManager
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
|
||||
import com.mogo.eagle.core.function.ipcupgrade.network.IPCUpgradeNetWorkModel
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
@@ -26,6 +33,11 @@ class IPCUpgradeManager: IMogoOnMessageListener<IPCUpgradeStateInfo> ,
|
||||
}
|
||||
|
||||
private var mContext: Context? = null
|
||||
private val ipcUpgradeNetWorkModel = IPCUpgradeNetWorkModel()
|
||||
private var autopilotStatus: Int? = null //自动驾驶状态 0代表不可自动驾驶,1代表可自动驾驶,2代表自动驾驶中
|
||||
|
||||
private var hasIPCUpgradeTask = false //是否有工控机升级任务,默认没有该任务
|
||||
private var ipcUpgradeStateInfoTask: IPCUpgradeStateInfo?=null
|
||||
|
||||
fun initServer(context: Context){
|
||||
mContext = context
|
||||
@@ -40,8 +52,32 @@ class IPCUpgradeManager: IMogoOnMessageListener<IPCUpgradeStateInfo> ,
|
||||
return IPCUpgradeStateInfo::class.java
|
||||
}
|
||||
|
||||
override fun onMsgReceived(obj: IPCUpgradeStateInfo?) {
|
||||
override fun onMsgReceived(ipcUpgradeStateInfo: IPCUpgradeStateInfo?) {
|
||||
CallerLogger.i(TAG,"IPCUpgradeManager received msg${ipcUpgradeStateInfo}")
|
||||
ipcUpgradeStateInfo?.let {
|
||||
if(it.status.isEmpty() || it.status == "0"){
|
||||
if(autopilotStatus == 2){
|
||||
//当前处于自动驾驶状态时,不弹窗提示,结束自动驾驶时弹窗
|
||||
hasIPCUpgradeTask = true
|
||||
ipcUpgradeStateInfoTask=it
|
||||
}else{
|
||||
var releaseId=""
|
||||
if(it.releaseId!=null){
|
||||
releaseId = it.releaseId.toString()
|
||||
}
|
||||
//弹窗提示,确认是否进行工控机升级
|
||||
CallerHmiManager.showAdUpgradeDialog(
|
||||
it.images,
|
||||
MoGoAiCloudClient.getInstance().aiCloudClientConfig.sn,
|
||||
releaseId)
|
||||
}
|
||||
}else{
|
||||
//更新下载or升级状态
|
||||
CallerHmiManager.showAdUpgradeStatus(it)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +85,62 @@ class IPCUpgradeManager: IMogoOnMessageListener<IPCUpgradeStateInfo> ,
|
||||
* @param autoPilotStatusInfo 状态信息
|
||||
*/
|
||||
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
|
||||
autopilotStatus = autoPilotStatusInfo.state
|
||||
//有升级任务,且不处于自动驾驶状态,进行升级提示
|
||||
if(hasIPCUpgradeTask && autopilotStatus!=2){
|
||||
ipcUpgradeStateInfoTask?.let {
|
||||
var releaseId=""
|
||||
if(it.releaseId!=null){
|
||||
releaseId = it.releaseId.toString()
|
||||
}
|
||||
CallerHmiManager.showAdUpgradeDialog(
|
||||
it.images,
|
||||
MoGoAiCloudClient.getInstance().aiCloudClientConfig.sn,
|
||||
releaseId)
|
||||
//将升级任务置为false
|
||||
hasIPCUpgradeTask = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认升级工控机docker版本
|
||||
* @param images docker列表
|
||||
* @param padSn SN
|
||||
* @param releaseId 任务ID
|
||||
*/
|
||||
fun upgradeConfirm(images: List<String>,padSn: String,releaseId: String){
|
||||
ipcUpgradeNetWorkModel.upgradeConfirm(images,padSn,releaseId,
|
||||
onSuccess = {
|
||||
|
||||
},
|
||||
onError = {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新工控机docker版本
|
||||
* @param padSn SN
|
||||
* @param dockerVersion 当前工控机版本
|
||||
*/
|
||||
fun queryContainers(padSn: String,dockerVersion: String){
|
||||
ipcUpgradeNetWorkModel.queryContainers(padSn,
|
||||
onSuccess = {
|
||||
val jsonObject = JSONObject(it)
|
||||
val images = jsonObject.getJSONArray("images")
|
||||
val dockerList = ArrayList<String>()
|
||||
for(i in 0 until images.length()){
|
||||
if(!i.toString().contains(dockerVersion)){
|
||||
dockerList.add(images[i].toString())
|
||||
}
|
||||
}
|
||||
//将数组结果回调
|
||||
CallerBindingCarListenerManager.invokeQueryContainersResponse(dockerList)
|
||||
},
|
||||
onError = {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun destroy(){
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.mogo.eagle.core.function.ipcupgrade.network
|
||||
|
||||
import com.mogo.eagle.core.data.BaseResponse
|
||||
import com.mogo.eagle.core.data.Response
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.http.*
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
* @description 工控机升级网络请求接口
|
||||
* @since: 2022/5/17
|
||||
*/
|
||||
interface IPCUpgradeApiService {
|
||||
|
||||
/**
|
||||
* 确认升级工控机docker版本
|
||||
* @param imageName docker域名
|
||||
* @param imageVersion docker版本
|
||||
* @param padSn SN
|
||||
* @param releaseId 任务ID
|
||||
*/
|
||||
@Headers(
|
||||
"Content-Type:application/json",
|
||||
"Accept: application/json"
|
||||
)
|
||||
@POST("/api/pushServer/confirm")
|
||||
suspend fun upgradeConfirm(@Body requestBody: RequestBody): BaseResponse<Any>
|
||||
|
||||
/**
|
||||
* 获取新工控机docker版本
|
||||
* @param padSn SN
|
||||
*/
|
||||
@GET("/api/pushServer/queryContainers")
|
||||
suspend fun queryContainers(@Query("padSn") padSn: String): Response<Any>
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mogo.eagle.core.function.ipcupgrade.network
|
||||
|
||||
import com.mogo.eagle.core.data.BaseResponse
|
||||
import com.mogo.eagle.core.data.Response
|
||||
import com.mogo.eagle.core.function.ipcupgrade.network.UpgradeHostConst.Companion.getBaseUrl
|
||||
import com.mogo.eagle.core.network.MoGoRetrofitFactory
|
||||
import com.mogo.eagle.core.network.apiCall
|
||||
import com.mogo.eagle.core.network.apiResponseCall
|
||||
import com.mogo.eagle.core.network.request
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
* @description 工控机升级网络请求
|
||||
* @since: 2022/5/17
|
||||
*/
|
||||
class IPCUpgradeNetWorkModel {
|
||||
|
||||
private fun getNetWorkApi(baseUrl: String =getBaseUrl()): IPCUpgradeApiService{
|
||||
return MoGoRetrofitFactory.getInstanceNoCallAdapter(baseUrl)
|
||||
.create(IPCUpgradeApiService::class.java)
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认升级工控机docker版本
|
||||
* @param images docker列表
|
||||
* @param padSn SN
|
||||
* @param releaseId 任务ID
|
||||
*/
|
||||
fun upgradeConfirm(images: List<String>,padSn: String,releaseId: String,
|
||||
onSuccess: ((String) -> Unit),onError: ((String) -> Unit)){
|
||||
request<BaseResponse<Any?>> {
|
||||
val requestJson = JSONObject()
|
||||
val imagesJsonArray = JSONArray()
|
||||
images.iterator().forEach {
|
||||
imagesJsonArray.put(it)
|
||||
}
|
||||
requestJson.put("images",imagesJsonArray)
|
||||
requestJson.put("padSn",padSn)
|
||||
requestJson.put("releaseId",releaseId)
|
||||
val requestBody:RequestBody= RequestBody.create(
|
||||
MediaType.parse("application/json; charset=utf-8"),
|
||||
requestJson.toString()
|
||||
)
|
||||
loader{
|
||||
apiCall{
|
||||
getNetWorkApi(getBaseUrl()).upgradeConfirm(requestBody)
|
||||
}
|
||||
}
|
||||
onSuccess{
|
||||
onSuccess.invoke("")
|
||||
}
|
||||
|
||||
onError {
|
||||
onError.invoke("")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新工控机docker版本
|
||||
* @param padSn SN
|
||||
*/
|
||||
fun queryContainers(padSn: String,onSuccess: ((String) -> Unit),onError: ((String) -> Unit)){
|
||||
request<Response<Any?>>{
|
||||
loader {
|
||||
apiResponseCall{
|
||||
getNetWorkApi(getBaseUrl()).queryContainers(padSn)
|
||||
}
|
||||
}
|
||||
onSuccess{
|
||||
if(it.msg == "success"){
|
||||
onSuccess.invoke(GsonUtils.toJson(it.data))
|
||||
}else{
|
||||
onError.invoke("query Containers fail")
|
||||
}
|
||||
}
|
||||
|
||||
onError {
|
||||
if(it.message!=null){
|
||||
onError.invoke(it.message!!)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.eagle.core.function.ipcupgrade.network
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
* @description 工控机升级域名管理
|
||||
* @since: 2022/5/17
|
||||
*/
|
||||
class UpgradeHostConst {
|
||||
|
||||
companion object{
|
||||
|
||||
private const val HOST_DEV = "http://mysunflower-qa.zhidaoauto.com"
|
||||
private const val HOST_RELEASE = "http://mysunflower-qa.zhidaoauto.com"
|
||||
|
||||
fun getBaseUrl(): String {
|
||||
return when (DebugConfig.getNetMode()) {
|
||||
DebugConfig.NET_MODE_DEV -> HOST_DEV
|
||||
DebugConfig.NET_MODE_QA -> HOST_DEV
|
||||
DebugConfig.NET_MODE_DEMO -> HOST_RELEASE
|
||||
DebugConfig.NET_MODE_RELEASE -> HOST_RELEASE
|
||||
else -> HOST_RELEASE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user