lizhanwei
2020-02-18 1b8164d97200ce08486b48ba179b83c5d70bd97b
app启动发送信号配置
6个文件已删除
4个文件已修改
587 ■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/MainActivity.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/SignalConfigFragment.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/im/IMSEventListener.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/im/MessageProcessor.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/platformMessage/DriveExamProtocol.java 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/platformMessage/KeepaliveMessage.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/platformMessage/RegisterMessage.java 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/platformMessage/RegisterResp.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/platformMessage/ServerCommonRsp.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/platformMessage/ServerProtocol.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/MainActivity.java
@@ -5,6 +5,7 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
@@ -21,6 +22,9 @@
import safeluck.drive.evaluation.DB.WokViewModel;
import safeluck.drive.evaluation.DB.rtktb.RTKConfig;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel;
import safeluck.drive.evaluation.DB.signalConfigdb.SignalConfigViewModel;
import safeluck.drive.evaluation.DB.signalConfigdb.SingalConfig;
import safeluck.drive.evaluation.bean.SignalConfigRemote;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.fragment.HomeFragment;
@@ -35,7 +39,9 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
import safeluck.drive.evaluation.util.FileUtil;
@@ -48,7 +54,7 @@
    private static final int PERMISSIONS_REQUEST_CODE = 1001;
    private String TAG = MainActivity.class.getCanonicalName();
    SignalConfigViewModel signalConfigViewModel;
    private PermissionManager mPermissionsManager;
    private RTKConfig mRTKConfig;//RTK配置信息
    private Gson gson = new Gson();
@@ -81,10 +87,12 @@
            }
            if (msgCode == Constant.NDK_START){
                sendRtkConfigInfo();
                sendSignalConfigsToRemote();
                sendMcuUprgrade();
            }
        }
    };
    private List<SignalConfigRemote> signalConfiglist = new ArrayList<>();
    private void sendMcuUprgrade() {
        CThreadPoolExecutor.runInBackground(new Runnable() {
@@ -166,7 +174,23 @@
            }
        });
        signalConfigViewModel = ViewModelProviders.of(this).get(SignalConfigViewModel.class);
        signalConfigViewModel.getSignalConfigs().observe(this, new Observer<List<SingalConfig>>() {
            @Override
            public void onChanged(List<SingalConfig> singalConfigs) {
                signalConfiglist.clear();
                MyLog.i(TAG, "信号配置发生变化");
                for (int i = 0; i < singalConfigs.size(); i++) {
                    SignalConfigRemote signalConfigRemote = new SignalConfigRemote();
                    signalConfigRemote.setFunc_id(i);
                    signalConfigRemote.setGpio_num(singalConfigs.get(i).getIndex());
                    signalConfigRemote.setLevel(singalConfigs.get(i).getHighLevel());
                    signalConfiglist.add(signalConfigRemote);
                }
                sendSignalConfigsToRemote();
            }
        });
        mPermissionsManager = new PermissionManager(this) {
            @Override
@@ -215,6 +239,32 @@
        CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_CONNECT_RTK_TOPIC);
        Log.i(TAG, "onDestroy: ");
    }
    private void sendSignalConfigsToRemote() {
        if (signalConfiglist.size()>0){
            new AsyncTask<Void, Void, List<Integer>>(
            ) {
                @Override
                protected List<Integer> doInBackground(Void... voids) {
                    return   signalConfigViewModel.getAllIndexs();
                }
                @Override
                protected void onPostExecute(List<Integer> indexs) {
                    if (listContainsSameValue(indexs)){
                        Log.i(TAG, "sendSignalConfigsToRemote: 有相同的index,不能发送"+gson.toJson(signalConfiglist));
                        Toast.makeText(getApplicationContext(), "不能有相同的物理所引!", Toast.LENGTH_SHORT).show();
                    }else{
                        AYSdk.getInstance().sendCmd(Constant.SEND_CONFIG_SIGNAL,gson.toJson(signalConfiglist));
                    }
                }
            }.execute();
        }
    }
    @Override
    protected void onResume() {
@@ -227,4 +277,20 @@
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        mPermissionsManager.recheckPermissions(PERMISSIONS_REQUEST_CODE, permissions, grantResults);
    }
    private boolean listContainsSameValue(List<Integer> indexs) {
        for (int i = 0; i < indexs.size(); i++) {
            //可以默认是0  0不判断是否有相同的index
            if (indexs.get(i) == 0){
                continue;
            }
            for (int j=i+1;j<indexs.size();j++){
                if (indexs.get(i) == indexs.get(j)){
                    return true;
                }
            }
        }
        return false;
    }
}
app/src/main/java/safeluck/drive/evaluation/fragment/SignalConfigFragment.java
@@ -135,7 +135,6 @@
                    signalConfigRemote.setLevel(singalConfigs.get(i).getHighLevel());
                    list.add(signalConfigRemote);
                }
                sendSignalConfigsToRemote();
                for (int i = 0; i < singalConfigs.size(); i++) {
                    SingalConfig singalConfig = singalConfigs.get(i);
@@ -155,47 +154,9 @@
    }
private Gson gson = new Gson();
    private void sendSignalConfigsToRemote() {
      new AsyncTask<Void, Void, List<Integer>>(
        ) {
            @Override
            protected List<Integer> doInBackground(Void... voids) {
                return   signalConfigViewModel.getAllIndexs();
            }
            @Override
            protected void onPostExecute(List<Integer> indexs) {
                if (listContainsSameValue(indexs)){
                    Log.i(TAG, "sendSignalConfigsToRemote: 有相同的index,不能发送"+gson.toJson(list));
                    Toast.makeText(_mActivity, "不能有相同的物理所引!", Toast.LENGTH_SHORT).show();
                }else{
                    AYSdk.getInstance().sendCmd(Constant.SEND_CONFIG_SIGNAL,gson.toJson(list));
                }
            }
        }.execute();
    }
    private boolean listContainsSameValue(List<Integer> indexs) {
        for (int i = 0; i < indexs.size(); i++) {
            //可以默认是0  0不判断是否有相同的index
            if (indexs.get(i) == 0){
                continue;
            }
           for (int j=i+1;j<indexs.size();j++){
               if (indexs.get(i) == indexs.get(j)){
                   return true;
               }
           }
        }
        return false;
    }
    private  class MySignalsAdapter extends BaseAdapter{
app/src/main/java/safeluck/drive/evaluation/im/IMSEventListener.java
@@ -2,8 +2,6 @@
import com.anyun.im_lib.listener.OnEventListener;
import safeluck.drive.evaluation.platformMessage.RegisterMessage;
/**
 * MyApplication2
 * Created by lzw on 2019/12/12. 16:12:40
@@ -71,12 +69,6 @@
    @Override
    public byte[] getRegisterMessage() {
        RegisterMessage registerMessage = new RegisterMessage((short)0x0100);
        registerMessage.setCityid((short) 1);
        registerMessage.setProviceId((short)23);
        registerMessage.setImei("460123874561");
        registerMessage.setModel("123");
        registerMessage.setSn("0314200100000004");
        return registerMessage.toBytes();
        return null;
    }
}
app/src/main/java/safeluck/drive/evaluation/im/MessageProcessor.java
@@ -8,12 +8,9 @@
import safeluck.drive.evaluation.platformMessage.JK2019MessageBase;
import safeluck.drive.evaluation.platformMessage.PlatFormConstant;
import safeluck.drive.evaluation.platformMessage.RegisterResp;
import safeluck.drive.evaluation.platformMessage.ServerCommonRsp;
import safeluck.drive.evaluation.platformMessage.utils.MessageEscaper;
import safeluck.drive.evaluation.platformMessage.utils.MessageManager;
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
import safeluck.drive.evaluation.util.Utils;
/**
 * MyApplication2
@@ -49,23 +46,7 @@
    }
    private void parseMessage(byte[] datas) {
        byte[] msgidBytes = ByteUtil.subArray(datas,1,2);
        short msgid = ByteUtil.getShort(msgidBytes);
        switch (msgid){
            case (short) 0x8100:
                RegisterResp registerResp = new RegisterResp(datas);
                break;
            case (short) 0x8001://服务器端 通用应答
                ServerCommonRsp serverCommonRsp = new ServerCommonRsp(datas);
                if (serverCommonRsp.getResult() == PlatFormConstant.SUCCESS){
                    MyLog.i(PlatFormConstant.TAG,"确认"+serverCommonRsp.getMsgId()+"消息成功");
                }
                break;
        }
    }
    @Override
    public void sendMessage(final byte[] msg) {
app/src/main/java/safeluck/drive/evaluation/platformMessage/DriveExamProtocol.java
File was deleted
app/src/main/java/safeluck/drive/evaluation/platformMessage/KeepaliveMessage.java
File was deleted
app/src/main/java/safeluck/drive/evaluation/platformMessage/RegisterMessage.java
File was deleted
app/src/main/java/safeluck/drive/evaluation/platformMessage/RegisterResp.java
File was deleted
app/src/main/java/safeluck/drive/evaluation/platformMessage/ServerCommonRsp.java
File was deleted
app/src/main/java/safeluck/drive/evaluation/platformMessage/ServerProtocol.java
File was deleted