[6.4.4]
[优化局域网内通讯]
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package com.mogo.och.common.module.biz.lansocket
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.och.common.module.BuildConfig
|
||||
import com.mogo.och.common.module.biz.login.ILoginCallback
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusEnum
|
||||
@@ -28,7 +25,7 @@ object LoginLanDriverSocket : ILoginCallback {
|
||||
return BaseDPMsg::class.java
|
||||
}
|
||||
|
||||
override fun onMsgReceived(obj: Array<in BaseDPMsg>) {
|
||||
override fun onMsgReceived(obj: BaseDPMsg?) {
|
||||
println("-------${obj}")
|
||||
if(LoginStatusManager.isLogin()) {
|
||||
FlavorUtils.getEnvCheck()
|
||||
@@ -53,7 +50,6 @@ object LoginLanDriverSocket : ILoginCallback {
|
||||
// 注册监听乘客屏和报站屏注册信息
|
||||
LanSocketManager.registerSocketMessageListener(
|
||||
DPMsgType.TYPE_CLIENT_REGISTER.type,
|
||||
TAG,
|
||||
registerListener
|
||||
)
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ object LoginLanPassengerSocket : IReceivedMsgListener {
|
||||
// 司机屏发生变化
|
||||
val msg = BaseDPMsg(type = DPMsgType.TYPE_CLIENT_REGISTER.type)
|
||||
LanSocketManager.sendMsgToServer(msg)
|
||||
LoginStatusManager.changeStatus("连接成功 司机SN:${newV}")
|
||||
LoginStatusManager.changeStatus("sn 变化 连接成功 司机SN:${newV}")
|
||||
if(newV.isNotEmpty()){
|
||||
OchChainLogManager.writeChainLogNetLanSocketConnect("局域网socket链接状态","已连接 sn${newV}")
|
||||
OchChainLogManager.writeChainLogNetLanSocketConnect("局域网socket链接状态","sn 变化 已连接 sn${newV}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,14 +48,18 @@ object LoginLanPassengerSocket : IReceivedMsgListener {
|
||||
LanSocketManager.sendMsgToServer(msg)
|
||||
if(driverSn.isEmpty()){
|
||||
LoginStatusManager.changeStatus("连接成功 未收到司机屏sn")
|
||||
OchChainLogManager.writeChainLogNetLanSocketConnect("局域网socket链接状态","已连接 sn 未收到司机屏sn")
|
||||
}else{
|
||||
LoginStatusManager.changeStatus("连接成功 司机SN:${driverSn}")
|
||||
OchChainLogManager.writeChainLogNetLanSocketConnect("局域网socket链接状态","已连接 sn${driverSn}")
|
||||
}
|
||||
}else{// 未连接
|
||||
if(driverSn.isEmpty()){
|
||||
LoginStatusManager.changeStatus("当前状态:连接司机屏中")
|
||||
OchChainLogManager.writeChainLogNetLanSocketConnect("局域网socket链接状态","连接断开 司机SN:${driverSn}")
|
||||
}else{
|
||||
LoginStatusManager.changeStatus("连接断开 司机SN:${driverSn}")
|
||||
OchChainLogManager.writeChainLogNetLanSocketConnect("局域网socket链接状态","连接断开 司机SN:${driverSn}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,9 +71,8 @@ object LoginLanPassengerSocket : IReceivedMsgListener {
|
||||
return EnvCheck::class.java
|
||||
}
|
||||
|
||||
override fun onMsgReceived(obj: Array<in EnvCheck>) {
|
||||
if (obj.isNotEmpty()) {
|
||||
val first = obj.first() as EnvCheck
|
||||
override fun onMsgReceived(first: EnvCheck?) {
|
||||
first?.let {
|
||||
val checkEnv = checkEnv(first.projectType, first.envType, first.vehicleType, first.businessType)
|
||||
if (first.sourceScreenType== ScreenType.Driver) {
|
||||
driverSn = first.sourceSn
|
||||
@@ -99,9 +102,8 @@ object LoginLanPassengerSocket : IReceivedMsgListener {
|
||||
return ChangeBusinessType::class.java
|
||||
}
|
||||
|
||||
override fun onMsgReceived(obj: Array<in ChangeBusinessType>) {
|
||||
if (obj.isNotEmpty()) {
|
||||
val first = obj.first() as ChangeBusinessType
|
||||
override fun onMsgReceived(first: ChangeBusinessType?) {
|
||||
first?.let {
|
||||
val checkEnv = checkEnv(
|
||||
first.projectType,
|
||||
first.envType,
|
||||
@@ -146,13 +148,11 @@ object LoginLanPassengerSocket : IReceivedMsgListener {
|
||||
// 乘客屏监听司机端发送的环境校验
|
||||
LanSocketManager.registerSocketMessageListener(
|
||||
DPMsgType.TYPE_ENV_CHECK.type,
|
||||
TAG,
|
||||
checkListener
|
||||
)
|
||||
// 乘客屏监听司机端发送的业务修改通知(
|
||||
LanSocketManager.registerSocketMessageListener(
|
||||
DPMsgType.TYPE_CHANGE_BUSINESS_TYPE.type,
|
||||
TAG,
|
||||
changeBusinessType
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ object OchChainLogManager {
|
||||
fun writeChainLogNetLanSocketConnect(title: String, info: String){
|
||||
writeChainLog(title,info,true,EVENT_KEY_INFO_SOCKET_CONNECT)
|
||||
}
|
||||
@JvmStatic
|
||||
fun writeChainLogLanSocket(title: String, info: String, action:String){
|
||||
val map = hashMapOf<String, Any>()
|
||||
map["action"] = action
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mogo.och.common.module.manager.socket.lan;
|
||||
|
||||
|
||||
public interface ILanMessageListener<T> {
|
||||
Class<T> target();
|
||||
|
||||
void onMsgReceived(T obj);
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.mogo.och.common.module.manager.socket.lan
|
||||
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
*
|
||||
*
|
||||
* 消息回调
|
||||
*/
|
||||
interface ILanMessageListener<T:BaseDPMsg> {
|
||||
|
||||
fun target(): Class<T>
|
||||
|
||||
fun onMsgReceived(obj: Array<in T>)
|
||||
|
||||
}
|
||||
@@ -1,22 +1,16 @@
|
||||
package com.mogo.och.common.module.manager.socket.lan
|
||||
|
||||
import com.mogo.eagle.core.function.api.telematic.IReceivedMsgListener
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
|
||||
object LanSocketManager : IReceivedMsgListener {
|
||||
object LanSocketManager : LanSocketManagerJava() {
|
||||
private const val TAG = "LanSocketManager"
|
||||
|
||||
init {
|
||||
CallerTelematicListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
fun load(){
|
||||
OchChainLogManager.writeChainLogInit("初始化信息","初始局域网监听和发送封装")
|
||||
@@ -39,52 +33,8 @@ object LanSocketManager : IReceivedMsgListener {
|
||||
}
|
||||
|
||||
override fun onReceivedMsg(type: Int, byteArray: ByteArray) {
|
||||
CallerLogger.d(TAG, "收到数据:_type:${type},byteArray:${String(byteArray)}")
|
||||
OchChainLogManager.writeChainLogLanSocket("收到数据","type:${type},byteArray:${String(byteArray)}","receive")
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
try {
|
||||
val baseMsg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java)
|
||||
baseMsg?.let {
|
||||
mListeners.forEach { action ->
|
||||
if(action.key==it.type){
|
||||
action.value.let {keyAndListenerMap->
|
||||
var fromJson:BaseDPMsg?=null
|
||||
keyAndListenerMap.forEach {listeners->
|
||||
if(fromJson==null) {
|
||||
val target = listeners.value.target()
|
||||
fromJson = GsonUtils.fromJson(
|
||||
String(byteArray), target
|
||||
)
|
||||
}
|
||||
|
||||
listeners.value.onMsgReceived(arrayOf(fromJson))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (e:Exception){
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
CallerLogger.d(TAG, "收到数据:_type:${type},byteArray:${String(byteArray)}");
|
||||
OchChainLogManager.writeChainLogLanSocket("收到数据","type:${type},byteArray:${String(byteArray)}","receive");
|
||||
super.onReceivedMsg(type, byteArray)
|
||||
}
|
||||
fun <T:BaseDPMsg> registerSocketMessageListener(msgType:Int, tag:String ,mogoOnMessageListener : ILanMessageListener<T>){
|
||||
val typeMap = mListeners[msgType]
|
||||
if (typeMap==null) {
|
||||
val concurrentHashMap = ConcurrentHashMap<String, ILanMessageListener<*>>()
|
||||
concurrentHashMap[tag] = mogoOnMessageListener
|
||||
mListeners[msgType] = concurrentHashMap
|
||||
}else{
|
||||
if (!typeMap.contains(tag)) {
|
||||
typeMap[tag] = mogoOnMessageListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val mListeners: ConcurrentHashMap<Int, ConcurrentHashMap<String, ILanMessageListener<out BaseDPMsg>>> =
|
||||
ConcurrentHashMap()
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.mogo.och.common.module.manager.socket.lan;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.eagle.core.function.api.telematic.IReceivedMsgListener;
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager;
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils;
|
||||
import com.mogo.och.common.module.constant.OchCommonConst;
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by pangfan on 2021/8/19
|
||||
* <p>
|
||||
* 网约车 - 出租车业务逻辑处理
|
||||
*/
|
||||
public class LanSocketManagerJava implements IReceivedMsgListener {
|
||||
|
||||
private static final String TAG = LanSocketManagerJava.class.getSimpleName();
|
||||
|
||||
public LanSocketManagerJava() {
|
||||
CallerTelematicListenerManager.INSTANCE.addListener(TAG, this);
|
||||
}
|
||||
|
||||
|
||||
private ConcurrentHashMap<Integer, List<ILanMessageListener>> mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
public void registerSocketMessageListener(int msgType, ILanMessageListener mogoOnMessageListener){
|
||||
List<ILanMessageListener> listenerJavas = mListeners.get(msgType);
|
||||
if (listenerJavas==null) {
|
||||
ArrayList<ILanMessageListener> list = new ArrayList<>();
|
||||
list.add(mogoOnMessageListener);
|
||||
mListeners.put(msgType,list);
|
||||
}else {
|
||||
if(!listenerJavas.contains(mogoOnMessageListener)){
|
||||
listenerJavas.add(mogoOnMessageListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedMsg(int type, @NonNull byte[] byteArray) {
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
try {
|
||||
BaseDPMsg baseMsg = GsonUtils.fromJson(new String(byteArray), BaseDPMsg.class);
|
||||
if(baseMsg!=null){
|
||||
List<ILanMessageListener> iLanMessageListenerJavas = mListeners.get(baseMsg.getType());
|
||||
if(iLanMessageListenerJavas!=null){
|
||||
for (ILanMessageListener iLanMessageListenerJava : iLanMessageListenerJavas) {
|
||||
Class<? extends BaseDPMsg> target = iLanMessageListenerJava.target();
|
||||
BaseDPMsg baseDPMsg = GsonUtils.fromJson(new String(byteArray), target);
|
||||
iLanMessageListenerJava.onMsgReceived(baseDPMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedServerSn(@Nullable String sn) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDemoMode(boolean isDemoMode) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -7,6 +7,10 @@ import com.mogo.eagle.core.utilcode.util.CoordinateTransform
|
||||
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.ILanMessageListener
|
||||
import com.mogo.och.common.module.manager.socket.lan.LanSocketManagerJava
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.EnvCheck
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import org.junit.Test
|
||||
|
||||
@@ -73,6 +77,24 @@ class ExampleUnitTest {
|
||||
TrajectoryAndDistanceManager.distanceWithTrajectory(mutableListOf,mogoLocation)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLanSocketManager(){
|
||||
LanSocketManagerJava.getInstance().registerSocketMessageListener(4,object :
|
||||
ILanMessageListener<EnvCheck> {
|
||||
override fun target(): Class<EnvCheck> {
|
||||
return EnvCheck::class.java
|
||||
}
|
||||
|
||||
override fun onMsgReceived(obj: EnvCheck?) {
|
||||
println(obj)
|
||||
}
|
||||
})
|
||||
val envCheck = TaskDetailsMsg("name")
|
||||
val message = GsonUtils.toJson(envCheck)
|
||||
LanSocketManagerJava.getInstance().onReceivedMsg(100,message.toByteArray())
|
||||
}
|
||||
|
||||
|
||||
fun resetData(){
|
||||
val mutableListOf = mutableListOf<Data>()
|
||||
mutableListOf.add(Data(26.81618164239085,112.58250175297606,55.55709771386404 ,0.046407543))
|
||||
|
||||
Reference in New Issue
Block a user