lizhanwei
2020-02-28 b5044d0daf6e6b5702b824d8f6f97c23fec454a0
提交mcu  info ,修改崩溃bug
5个文件已修改
1个文件已添加
373 ■■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/Constant.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/app.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/MCUInfo.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java 187 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/layout_base_datas.xml 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/strings.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -80,5 +80,6 @@
    public static final String STU_INFO_PLATFORM = "STU_INFO_PLATFORM";
    public static final int SHUTDOWN_TIME = 16;
    public static final int READ_PHYSICAL_ID = 0x8011;//4.    读取IC卡
    public static final String BIND_MCUINFO_TOPIC = "bind_mcu_info_topic";
    public static String exam_enter_exitdata="exam_enter_exitdata";
}
app/src/main/java/safeluck/drive/evaluation/app.java
@@ -264,6 +264,7 @@
                CEventCenter.dispatchEvent(Constant.BIND_DEBUG_TXT,cmd,0,json);
                break;
            case Constant.MCU_SN:
                CEventCenter.dispatchEvent(Constant.BIND_MCUINFO_TOPIC,cmd,0,json);
                break;
            case Constant.IC_ID:
app/src/main/java/safeluck/drive/evaluation/bean/MCUInfo.java
New file
@@ -0,0 +1,68 @@
package safeluck.drive.evaluation.bean;
public class MCUInfo {
    /**
     * version : 414B535F335F30315F32303139313132395FB2FAB2E2
     * selftest : 0
     * gpio : 0
     * speed : 0
     * engine : 0
     * sn : 0314200100000005
     */
    private String version;
    private int selftest;
    private int gpio;
    private int speed;
    private int engine;
    private String sn;
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
    public int getSelftest() {
        return selftest;
    }
    public void setSelftest(int selftest) {
        this.selftest = selftest;
    }
    public int getGpio() {
        return gpio;
    }
    public void setGpio(int gpio) {
        this.gpio = gpio;
    }
    public int getSpeed() {
        return speed;
    }
    public void setSpeed(int speed) {
        this.speed = speed;
    }
    public int getEngine() {
        return engine;
    }
    public void setEngine(int engine) {
        this.engine = engine;
    }
    public String getSn() {
        return sn;
    }
    public void setSn(String sn) {
        this.sn = sn;
    }
}
app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java
@@ -1,10 +1,13 @@
package safeluck.drive.evaluation.fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import android.util.Log;
import android.view.LayoutInflater;
@@ -12,20 +15,32 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.anyun.exam.lib.AYSdk;
import com.anyun.exam.lib.MyLog;
import com.anyun.exam.lib.util.ByteUtil;
import com.google.gson.Gson;
import com.safeluck.aykj.utils.BytesUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatus;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusViewModel;
import safeluck.drive.evaluation.DB.rtktb.RTKConfig;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel;
import safeluck.drive.evaluation.MainActivity;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.bean.MCUInfo;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
import safeluck.drive.evaluation.util.FileUtil;
@@ -47,6 +62,51 @@
    private Button btn_config_signal;
    private Button btn_mcu_upgrade,btn_map_select;
    private EditText et_ip,et_port;
    private Gson gson;
    StringBuffer stringBuffer = new StringBuffer();
    private EditText et_ip_rtk,et_port_rtk,et_city_id,et_city_province,et_phone;
    private TextView tv_mcu;
    //              RTK注册状态、RTK连接状态、
//    private TextView tv_reg,tv_connect,tv_model,tv_sn,tv_imei,tv_login;
    private RTKConfigViewModel rtkConfigViewModel;
    private RTKConfig mRtkConfig;
    private AppStatusViewModel appStatusViewModel;
    private ICEventListener icEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
            if (msgCode == Constant.MCU_SN){
                String mcuinfoStr = (String)obj;
                if (gson != null){
                    final MCUInfo mcuInfo=gson.fromJson(mcuinfoStr, MCUInfo.class);
                    stringBuffer.delete(0,stringBuffer.toString().length());
                            Field [] fields = mcuInfo.getClass().getDeclaredFields();
                            for (int i = 0; i < fields.length; i++) {
                                fields[i].setAccessible(true);
                                try {
                                    if (fields[i].getName().equalsIgnoreCase("version")){
                                        String version = (String) fields[i].get(mcuInfo);
                                        version = new String(BytesUtils.hexStringToBytes(version),"GBK");
                                        stringBuffer.append("   "+fields[i].getName() + ":" + version);
                                    }else
                                    stringBuffer.append("   "+fields[i].getName() + ":" + fields[i].get(mcuInfo));
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                }
                            }
                            tv_mcu.post(new Runnable() {
                                @Override
                                public void run() {
                                    tv_mcu.setText(getString(R.string.mcu_info)+stringBuffer.toString());
                                }
                            });
                }
            }
        }
    };
    public static SupportFragment newInstance() {
        return new BaseDatasFragment();
    }
@@ -58,10 +118,43 @@
        View view = inflater.inflate(R.layout.layout_base_datas, container, false);
        initView(view);
        rtkConfigViewModel= ViewModelProviders.of(this).get(RTKConfigViewModel.class);
        rtkConfigViewModel.getRTKConfig().observe(this, new Observer<RTKConfig>() {
            @Override
            public void onChanged(RTKConfig rtkConfig) {
                if (rtkConfig != null){
                    Log.i(TAG, "RTKConfig Changed: "+rtkConfig.toString());
                    mRtkConfig = rtkConfig;
                    et_ip_rtk.setText(rtkConfig.getIp());
                    et_city_id.setText(String.valueOf(rtkConfig.getCity()));
                    et_city_province.setText(String.valueOf(rtkConfig.getProvince()));
                    et_port_rtk.setText(String.valueOf(rtkConfig.getPort()));
                    et_phone.setText(rtkConfig.getPhone());
//                    tv_sn.setText(getResources().getString(R.string.rtk_config_sn,rtkConfig.getSn()));
//                    tv_model.setText(getResources().getString(R.string.rtk_config_model,rtkConfig.getModel()));
//                    tv_imei.setText(getResources().getString(R.string.rtk_config_imei,rtkConfig.getImei()));
//                    tv_reg.setText(getResources().getString(R.string.rtk_register_status,rtkConfig.getRegistered()));
                }
            }
        });
        appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class);
        appStatusViewModel.getAppStatus().observe(this, new Observer<AppStatus>() {
            @Override
            public void onChanged(AppStatus appStatus) {
                if (appStatus != null){
//                    tv_login.setText(getResources().getString(R.string.rtk_config_login,appStatus.getRtk_login_code()));
//                    tv_connect.setText(getResources().getString(R.string.rtk_connect_status,appStatus.getRtk_connect_status()));
                }
            }
        });
        return view;
    }
    private void initView(View view) {
        gson = new Gson();
        view.findViewById(R.id.btn_save_platform).setOnClickListener(this);
        et_ip = view.findViewById(R.id.et_platform_ip);
        et_port = view.findViewById(R.id.et_platform_port);
@@ -76,6 +169,21 @@
        btn_inspect_signal.setOnClickListener(this);
        btn_config_signal = view.findViewById(R.id.btn_signal_conf);
        btn_config_signal.setOnClickListener(this);
        et_ip_rtk = view.findViewById(R.id.rtk_addr_ip);
        et_city_id = view.findViewById(R.id.et_city_id);
        et_city_province = view.findViewById(R.id.et_provice_id);
        et_phone = view.findViewById(R.id.et_phone);
        et_port_rtk = view.findViewById(R.id.rtk_addr_port);
        tv_mcu = view.findViewById(R.id.tv_mcu_info);
//        tv_connect = view.findViewById(R.id.tv_rtk_connect);//RTK平台连接状态
//        tv_imei = view.findViewById(R.id.tv_rtk_imei);
//        tv_login = view.findViewById(R.id.tv_rtk_login);//RTK平台登录结果
//        tv_model = view.findViewById(R.id.tv_rtk_model);
//        tv_reg = view.findViewById(R.id.tv_rtk_reg);//RTK平台注册状态
//        tv_sn = view.findViewById(R.id.tv_rtk_sn);
    }
    @Override
@@ -112,6 +220,15 @@
                    ExamPlatformData.getInstance().insertPlatformIp(et_ip.getText().toString().trim());
                    ExamPlatformData.getInstance().insertPlatformPort(Integer.parseInt(et_port.getText().toString().trim()));
                }
                if (mRtkConfig != null){
                    mRtkConfig.setPort(Integer.parseInt(et_port_rtk.getText().toString().trim()));
                    mRtkConfig.setCity(Integer.parseInt(et_city_id.getText().toString().trim()));
                    mRtkConfig.setProvince(Integer.parseInt(et_city_province.getText().toString().trim()));
                    mRtkConfig.setIp(et_ip_rtk.getText().toString().trim());
                    mRtkConfig.setPhone(et_phone.getText().toString().trim());
                    rtkConfigViewModel.insertRTKConfig(mRtkConfig);
                }
                break;
            case R.id.btn_car_select://车辆模型和地图公用一套代码 区别在于REQUEST_CODE
                request_code = REQUEST_CODE_CAR;
@@ -142,37 +259,55 @@
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (REQUEST_CODE_MAP == requestCode){
           final Uri uri= data.getData();
            Log.i(TAG, "onActivityResult: "+uri.getPath());
            ExamPlatformData.getInstance().setNewMapPath(uri.getPath());
            CThreadPoolExecutor.runInBackground(new Runnable() {
                @Override
                public void run() {
                    byte[] fileContent = FileUtil.readFile(uri.getPath());
                    if (fileContent != null){
                        String str = new String(fileContent);
                        Log.i(TAG, "文件内容:"+str);
                        AYSdk.getInstance().sendCmd(Constant.PUSH_MAP_INFO,str);
            if (data != null){
                final Uri uri= data.getData();
                Log.i(TAG, "onActivityResult: "+uri.getPath());
                ExamPlatformData.getInstance().setNewMapPath(uri.getPath());
                CThreadPoolExecutor.runInBackground(new Runnable() {
                    @Override
                    public void run() {
                        byte[] fileContent = FileUtil.readFile(uri.getPath());
                        if (fileContent != null){
                            String str = new String(fileContent);
                            Log.i(TAG, "文件内容:"+str);
                            AYSdk.getInstance().sendCmd(Constant.PUSH_MAP_INFO,str);
                        }
                    }
                }
            });
                });
            }
        }else if (requestCode == REQUEST_CODE_CAR){
            final Uri uri= data.getData();
            Log.i(TAG, "onActivityResult: "+uri.getPath());
            ExamPlatformData.getInstance().setCarModelPath(uri.getPath());
            CThreadPoolExecutor.runInBackground(new Runnable() {
                @Override
                public void run() {
                    byte[] fileContent = FileUtil.readFile(uri.getPath());
                    if (fileContent != null){
                        String str = new String(fileContent);
                        Log.i(TAG, "文件内容:"+str);
                        AYSdk.getInstance().sendCmd(Constant.PUSH_VECHILE_PROFILE,str);
            if (data != null){
                final Uri uri= data.getData();
                Log.i(TAG, "onActivityResult: "+uri.getPath());
                ExamPlatformData.getInstance().setCarModelPath(uri.getPath());
                CThreadPoolExecutor.runInBackground(new Runnable() {
                    @Override
                    public void run() {
                        byte[] fileContent = FileUtil.readFile(uri.getPath());
                        if (fileContent != null){
                            String str = new String(fileContent);
                            Log.i(TAG, "文件内容:"+str);
                            AYSdk.getInstance().sendCmd(Constant.PUSH_VECHILE_PROFILE,str);
                        }
                    }
                }
            });
                });
            }
        }
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_MCUINFO_TOPIC);
    }
    @Override
    public void onDetach() {
        super.onDetach();
        CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_MCUINFO_TOPIC);
    }
}
app/src/main/res/layout/layout_base_datas.xml
@@ -54,6 +54,98 @@
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"
                android:text="@string/rtk_addr_des"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="IP:"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/rtk_addr_ip"
                android:text="192.168.23.12"
                android:background="@android:drawable/editbox_background_normal"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="Port:"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/rtk_addr_port"
                android:text="8080"
                android:background="@android:drawable/editbox_background_normal"/>
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:background="@color/colorAccent"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"
                android:text="登录信息:"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="省ID:"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/et_provice_id"
                android:text="12"
                android:inputType="numberDecimal"
                android:background="@android:drawable/editbox_background_normal"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="市ID:"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/et_city_id"
                android:text="192"
                android:inputType="numberDecimal"
                android:background="@android:drawable/editbox_background_normal"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="电话:"/>
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/et_phone"
                android:text="19234567894"
                android:inputType="numberDecimal"
                android:background="@android:drawable/editbox_background_normal"/>
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:background="@color/colorAccent"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"
                android:text="车载信号输入:"/>
            <TableLayout
                android:layout_width="match_parent"
@@ -160,6 +252,7 @@
            android:layout_marginBottom="10dp"
            android:background="@color/colorAccent"
            />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
@@ -207,6 +300,28 @@
            android:layout_marginBottom="10dp"
            android:background="@color/colorAccent"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:textColor="@android:color/black"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/tv_mcu_info"
                android:text="@string/mcu_info"
                android:layout_weight="1"/>
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:background="@color/colorAccent"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
app/src/main/res/values/strings.xml
@@ -31,4 +31,5 @@
    <string name="name">姓名:</string>
    <string name="sex">性别:</string>
    <string name="begin_time">开始时间:</string>
    <string name="mcu_info">协处理器信息:</string>
</resources>