app/src/main/java/safeluck/drive/evaluation/DB/WorkRoomDataBase.java
@@ -10,8 +10,10 @@ import androidx.room.migration.Migration; import androidx.sqlite.db.SupportSQLiteDatabase; import androidx.work.OneTimeWorkRequest; import androidx.work.WorkContinuation; import androidx.work.WorkManager; import java.util.Arrays; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -95,15 +97,24 @@ OneTimeWorkRequest examStatusInitWorker = OneTimeWorkRequest.from(ExamStatusInitWorker.class); OneTimeWorkRequest signalConigInitWorker = OneTimeWorkRequest.from(SignalConfigInitWorker.class); Log.i(TAG, "onCreate: 创建数据库后建立数据表插入数据"); WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest); WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest1); WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest2); WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest3); WorkManager.getInstance(mContext).enqueue(mCriteriaForIIIWorker); WorkManager.getInstance(mContext).enqueue(RTKConfigWorkRequest); WorkManager.getInstance(mContext).enqueue(appStatusInitWork); WorkManager.getInstance(mContext).enqueue(examStatusInitWorker); WorkManager.getInstance(mContext).enqueue(signalConigInitWorker); // WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest); // WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest1); // WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest2); // WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest3); // WorkManager.getInstance(mContext).enqueue(mCriteriaForIIIWorker); // WorkManager.getInstance(mContext).enqueue(RTKConfigWorkRequest); // WorkManager.getInstance(mContext).enqueue(appStatusInitWork); // WorkManager.getInstance(mContext).enqueue(examStatusInitWorker); // WorkManager.getInstance(mContext).enqueue(signalConigInitWorker); //单路径执行,可以实现更加复杂的多路径执行方式 WorkContinuation chain1= WorkManager.getInstance(mContext).beginWith(Arrays.asList(oneTimeWorkRequest,oneTimeWorkRequest1)) .then(mCriteriaForIIIWorker).then(oneTimeWorkRequest3); WorkContinuation chain2 = WorkManager.getInstance(mContext).beginWith(Arrays.asList(RTKConfigWorkRequest,appStatusInitWork,signalConigInitWorker)) .then(oneTimeWorkRequest2).then(examStatusInitWorker); WorkContinuation chain3 = WorkContinuation.combine(Arrays.asList(chain1,chain2)); chain3.enqueue(); } @Override app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatus.java
@@ -26,9 +26,7 @@ //1 进入(正在进行考试) 2-待考 private int enter; public ExamStatus(int map_id) { this.map_id = map_id; } public void setResult(int result) { this.result = result; @@ -39,11 +37,7 @@ //表示已经点击了开始考试,并且收到了考试应答 0-未考试 2-场地 3-模拟灯光,路考, 4-路考 private int startExam; @Ignore public ExamStatus(int map_id, int enter) { this.map_id = map_id; this.enter = enter; } public int getMap_item() { return map_item; @@ -53,8 +47,7 @@ this.map_item = map_item; } public ExamStatus() { } public int getMap_id() { return map_id; app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatusOutWorker.kt
@@ -2,7 +2,6 @@ import android.content.Context import android.util.Log import android.widget.Toast import androidx.work.Data import androidx.work.Worker import androidx.work.WorkerParameters @@ -13,6 +12,7 @@ import org.json.JSONObject import safeluck.drive.evaluation.DB.Constant import safeluck.drive.evaluation.DB.WorkRoomDataBase import safeluck.drive.evaluation.DB.rtktb.RTKConfig import safeluck.drive.evaluation.DB.signalConfigdb.SingalConfig import safeluck.drive.evaluation.bean.SignalConfigRemote @@ -24,6 +24,8 @@ override fun doWork(): Result { val examType =WorkRoomDataBase.getWorkRoomDataBase(applicationContext).examStatusDao.startExamInt; singalConfigs = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).signalConfigDao._getSignalConfigs() sendRtkConfigInfo(WorkRoomDataBase.getWorkRoomDataBase(applicationContext).rtkConfigDao._getRtkConfig()) for (i in singalConfigs.indices) { val signalConfigRemote = SignalConfigRemote() signalConfigRemote.func_id = i @@ -73,4 +75,25 @@ return false } private fun sendRtkConfigInfo(mRTKConfig: RTKConfig) { if (mRTKConfig != null) { var rtkjson = gson.toJson(mRTKConfig) //去除id字段 var jsonObject: JSONObject? = null try { jsonObject = JSONObject(rtkjson) } catch (e: JSONException) { e.printStackTrace() } jsonObject!!.remove("_id") rtkjson = null rtkjson = jsonObject.toString() MyLog.i(TAG, "RTK配置信息:$rtkjson") AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_RTK_PLATFORM_INFO, rtkjson) } else { MyLog.d(TAG, "RTKConfig未取到数据") } } } app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigDao.java
@@ -21,5 +21,6 @@ @Query("Update rtkconfig_table SET sn=:sn ,imei=:imei ,phone=:phone where _id =0") void update(String sn,String imei,String phone); @Query("SELECT * from rtkconfig_table") RTKConfig _getRtkConfig(); } app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt
@@ -5,6 +5,10 @@ import android.util.Log import androidx.work.Worker import androidx.work.WorkerParameters import com.anyun.exam.lib.AYSdk import com.anyun.exam.lib.MyLog import com.google.gson.Gson import org.json.JSONException import org.json.JSONObject import safeluck.drive.evaluation.DB.Constant import safeluck.drive.evaluation.DB.WorkRoomDataBase @@ -12,6 +16,7 @@ class RTKConfigUpdateWorker(context:Context, workerParams: WorkerParameters) :Worker(context, workerParams){ val TAG:String = "RTKConfigUpdateWorker" private val gson = Gson() override fun doWork(): Result { @@ -32,14 +37,37 @@ 0311200200000011,前4位是设备编码,接下来4位是年月,后面8位是流水号; 电话号码前2位固定13,第三位取SN的第4位,第4-7位取SN的年月,第8-11位取SN流水号的后4位;即13120020011 */ phone = "13"+sn.subSequence(3,8)+sn.substring(sn.length-4,sn.length) phone = sn Log.i(TAG,"phone="+phone) } var rtkConfigDao = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).rtkConfigDao.also { it.update(sn, imei, phone) } sendRtkConfigInfo(WorkRoomDataBase.getWorkRoomDataBase(applicationContext).rtkConfigDao._getRtkConfig()) return Result.success() } private fun sendRtkConfigInfo(mRTKConfig: RTKConfig) { if (mRTKConfig != null) { var rtkjson = gson.toJson(mRTKConfig) //去除id字段 var jsonObject: JSONObject? = null try { jsonObject = JSONObject(rtkjson) } catch (e: JSONException) { e.printStackTrace() } jsonObject!!.remove("_id") rtkjson = null rtkjson = jsonObject.toString() MyLog.i(TAG, "RTK配置信息:$rtkjson") AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_RTK_PLATFORM_INFO, rtkjson) } else { MyLog.d(TAG, "RTKConfig未取到数据") } } } app/src/main/java/safeluck/drive/evaluation/MainActivity.java
@@ -56,10 +56,12 @@ import safeluck.drive.evaluation.im.MessageProcessor; import safeluck.drive.evaluation.platformMessage.JKMessage0100; import safeluck.drive.evaluation.platformMessage.JKMessage0101; import safeluck.drive.evaluation.platformMessage.PlatFormConstant; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; import safeluck.drive.evaluation.util.PermissionManager; import safeluck.drive.evaluation.util.SPUtils; import safeluck.drive.evaluation.util.Utils; import safeluck.drive.evaluation.viewmodels.ExamPlatformModel; import safeluck.drive.evaluation.viewmodels.MainViewModel; import safeluck.drive.evaluation.viewmodels.RTKConnAndLogin; @@ -82,7 +84,7 @@ @Override public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { if (msgCode == Constant.FETCH_RTK_PLATFORM_INFO) { sendRtkConfigInfo(); // sendRtkConfigInfo(); } if (msgCode == Constant.RTK_PLATFORM_REGISTER_STATUS) { try { @@ -102,8 +104,8 @@ } } if (msgCode == Constant.NDK_START){ MyLog.i(TAG,"NDK_start,发送RTK配置"); sendRtkConfigInfo(); MyLog.i(TAG,"NDK_start"); // sendRtkConfigInfo(); sendMcuUprgrade(); } } @@ -134,27 +136,27 @@ } private void sendRtkConfigInfo() { if (mRTKConfig != null) { String rtkjson = gson.toJson(mRTKConfig); //去除id字段 JSONObject jsonObject = null; try { jsonObject = new JSONObject(rtkjson); } catch (JSONException e) { e.printStackTrace(); } jsonObject.remove("_id"); rtkjson = null; rtkjson = jsonObject.toString(); MyLog.i(TAG, "RTK配置信息:" + rtkjson); AYSdk.getInstance().sendCmd(Constant.PUSH_RTK_PLATFORM_INFO, rtkjson); } else { MyLog.d(TAG, "RTKConfig未取到数据"); onlySendOnceRTKConfig = true; } } // private void sendRtkConfigInfo() { // if (mRTKConfig != null) { // String rtkjson = gson.toJson(mRTKConfig); // // //去除id字段 // JSONObject jsonObject = null; // try { // jsonObject = new JSONObject(rtkjson); // } catch (JSONException e) { // e.printStackTrace(); // } // jsonObject.remove("_id"); // rtkjson = null; // rtkjson = jsonObject.toString(); // MyLog.i(TAG, "RTK配置信息:" + rtkjson); // AYSdk.getInstance().sendCmd(Constant.PUSH_RTK_PLATFORM_INFO, rtkjson); // } else { // MyLog.d(TAG, "RTKConfig未取到数据"); // onlySendOnceRTKConfig = true; // } // } public ExamPlatformModel examPlatformModel; @Override protected void onCreate(Bundle savedInstanceState) { @@ -200,13 +202,13 @@ MyLog.i(TAG, "RTKConfig Changed: " + (rtkConfig != null ? rtkConfig.toString() : "null")); mRTKConfig = rtkConfig; if (rtkConfig != null) ExamPlatformData.getInstance().setPhone(rtkConfig.getPhone()); ExamPlatformData.getInstance().setPhone(rtkConfig.getSn()); synchronized (MainActivity.this){ if (onlySendOnceRTKConfig){ MyLog.i(TAG,"进入 synchronized (MainActivity.this)"); onlySendOnceRTKConfig = false; sendRtkConfigInfo(); } // if (onlySendOnceRTKConfig){ // MyLog.i(TAG,"进入 synchronized (MainActivity.this)"); // onlySendOnceRTKConfig = false; // sendRtkConfigInfo(); // } } } @@ -365,8 +367,15 @@ }else{ JKMessage0101 jkMessage0101 = new JKMessage0101(); jkMessage0101.phone = ExamPlatformData.getInstance().getPhone(); jkMessage0101.des =hexPwd; jkMessage0101.timestamp = (int) System.currentTimeMillis(); String des = hexPwd; int time = (int) System.currentTimeMillis(); jkMessage0101.timestamp = time; byte[] miwen = Utils.encrypt(com.anyun.im_lib.util.ByteUtil.intGetBytes(time),des); MyLog.i(PlatFormConstant.TAG,"鉴权密文="+BytesUtils.bytesToHexString(miwen)+" time="+time); jkMessage0101.des = BytesUtils.bytesToHexString(miwen); MessageProcessor.getInstance().sendMessage(jkMessage0101); } } app/src/main/java/safeluck/drive/evaluation/app.java
@@ -23,8 +23,6 @@ import com.anyun.exam.lib.MyLog; import com.anyun.exam.lib.crash.CrashHandler; import com.anyun.im_lib.ExecutorServiceFactory; import com.anyun.im_lib.listener.IMSConnectStatusCallback; import com.facebook.stetho.Stetho; import com.google.gson.Gson; import com.google.gson.JsonArray; app/src/main/java/safeluck/drive/evaluation/bean/ExamPlatformData.java
@@ -1,6 +1,7 @@ package safeluck.drive.evaluation.bean; import android.content.Context; import android.text.TextUtils; import android.util.Log; import androidx.lifecycle.LiveData; @@ -25,6 +26,8 @@ import safeluck.drive.evaluation.viewmodels.MainViewModel; public class ExamPlatformData { private static final String TAG = "ExamPlatformData"; private static final ExamPlatformData ourInstance = new ExamPlatformData(); private int exam_id =12345;//考试唯一ID @@ -37,7 +40,10 @@ public static final int DEV_REGISTERED = 4; public static final int DEV_NOT_LOGIN = 5; public static final int DEV_LOGIN = 6; private boolean isTrainingMode = false;//是否训练模式 private static HashMap<Integer,String> examPlatformStrs = new HashMap<>(); private List<Integer> sns =new ArrayList<>();//保存所有失败项目的sn private static HashMap<Integer,String> enter_exit_item_tts = new HashMap<>(); private static List<SimulateNightBean.QuestionBean> simulate_light_tips = new ArrayList<>(); static { @@ -96,6 +102,9 @@ private int port; private String mapPath;//绝对路径包含文件名的path private String carPath;//绝对路径包含文件名的path private StringBuffer stringBuffer; private int rtkPort = 12125; private String rtkIP = "47.93.80.84"; public static ExamPlatformData getInstance() { return ourInstance; @@ -103,6 +112,7 @@ private ExamPlatformData() { stringBuffer = new StringBuffer(); } public String getPlatformIP(){ @@ -134,6 +144,19 @@ public boolean compareIPandPort(String ip,int port){ MyLog.i( "compareIPandPort: "+ip+" "+port); if(!getPlatformIP().equalsIgnoreCase(ip) || getPlatformPort()!=port){ MyLog.i("ip和端口有变化"); return true; } return false; } /** * 比较RTK ip地址和端口号, * @param ip * @param port * @return ip和端口其中有变化,返回true,否则返回false */ public boolean compareRTKIPandPort(String ip,int port){ MyLog.i( "compareIPandPort: "+ip+" "+port); if(!getRtkIP().equalsIgnoreCase(ip) || getRtkPort()!=port){ MyLog.i("ip和端口有变化"); return true; } @@ -237,6 +260,15 @@ } } public boolean isTrainingMode() { isTrainingMode = (boolean) SPUtils.get(app.getAppContext(),SPUtils.TRAIN_MODE,false); return isTrainingMode; } public void setTrainingMode(boolean trainingMode) { SPUtils.put(app.getAppContext(),SPUtils.TRAIN_MODE,trainingMode); isTrainingMode = trainingMode; } public void setPhone(String phone) { this.mPhone = phone; @@ -249,4 +281,47 @@ public List<SimulateNightBean.QuestionBean> getSimulate_light_tips() { return simulate_light_tips; } public List<Integer> getSns() { // if (sns.size()<=0){ // String snsstr = (String) SPUtils.get(app.getAppContext(),SPUtils.FAIL_PROJ_SNS,""); // if (!TextUtils.isEmpty(snsstr)){ // String[] strings=snsstr.split("#"); // for (int i = 0; i < strings.length; i++) { // Log.i(TAG, String.format("strings[%d]=%s",i,strings[i])); // if (!TextUtils.isEmpty(strings[i])) // sns.add(Integer.parseInt(strings[i])); // } // } // } return sns; } public void addSn(int sn) { // stringBuffer.append("#"+String.valueOf(sn)); // SPUtils.put(app.getAppContext(),SPUtils.FAIL_PROJ_SNS,stringBuffer.toString()); this.sns.add(sn); } public void clearSns() { // SPUtils.clear(app.getAppContext()); sns.clear(); } public void setRTKPort(int port) { this.rtkPort = port; } public void setRTKIP(String ip) { this.rtkIP = ip; } public int getRtkPort() { return rtkPort; } public String getRtkIP() { return rtkIP; } } app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java
@@ -104,9 +104,9 @@ if (mRtkConfig != null){ datas.add("省ID:"+mRtkConfig.getProvince()); datas.add("市ID:"+mRtkConfig.getCity()); datas.add("电话:"+mRtkConfig.getPhone()); datas.add("RTK平台地址:"+mRtkConfig.getIp()+":"+mRtkConfig.getPort()); datas.add("考试平台地址:"+ExamPlatformData.getInstance().getPlatformIP()+":"+ExamPlatformData.getInstance().getPlatformPort()); } if (appStatus != null){ app/src/main/java/safeluck/drive/evaluation/fragment/HomeFragment.java
@@ -8,6 +8,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -18,6 +19,7 @@ import me.yokeyword.fragmentation.SupportFragment; import safeluck.drive.evaluation.BuildConfig; import safeluck.drive.evaluation.R; import safeluck.drive.evaluation.bean.ExamPlatformData; /** @@ -73,14 +75,19 @@ } break; case R.id.network_train: NetWorkTrainFragment netWorkTrainFragment = findFragment(NetWorkTrainFragment.class); if (netWorkTrainFragment == null) { netWorkTrainFragment = (NetWorkTrainFragment) NetWorkTrainFragment.newInstance(); start(netWorkTrainFragment); } else { start(netWorkTrainFragment); if (ExamPlatformData.getInstance().isTrainingMode()){ Toast.makeText(_mActivity, "当前正处于训练模式,无法进入联网考试,请先结束训练", Toast.LENGTH_SHORT).show(); }else{ NetWorkTrainFragment netWorkTrainFragment = findFragment(NetWorkTrainFragment.class); if (netWorkTrainFragment == null) { netWorkTrainFragment = (NetWorkTrainFragment) NetWorkTrainFragment.newInstance(); start(netWorkTrainFragment); } else { start(netWorkTrainFragment); } //联网考试 } //联网考试 break; case R.id.exit_sys: //退出系统 app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
@@ -746,7 +746,6 @@ car[line][0] = points.get(i); } else { double value = 0 - points.get(i); Log.i(TAG, "onCEvent: 新值=" + value + " 位置:" + i); car[line][1] = value; line++; } @@ -783,7 +782,6 @@ byte[] fileContent = FileUtil.readFile(mapPath); if (fileContent != null){ newmap= new String(fileContent); Log.i(TAG, "文件内容:"+newmap); }else{ MyLog.i(String.format("文件:%s不存在",mapPath)); } app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
@@ -127,7 +127,7 @@ av_zhijiao.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_ANGLE)); } if (msg.what == SPEED_DATA){ tv_speed.setText(getResources().getString(R.string.speed,speed)); tv_speed.setText(getActivity().getApplicationContext().getResources().getString(R.string.speed,speed)); } if (msg.what == Constant.IC_ID){ try { @@ -186,7 +186,13 @@ return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过倒车入库合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 2: @@ -194,7 +200,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过坡道定点停车和起步合格合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 3: @@ -202,7 +214,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过侧方停车合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 4: @@ -210,8 +228,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("曲线行驶合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); if (examStatus.getResult() ==1){ MyLog.i("已经播放过曲线行驶合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("曲线行驶合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 5: @@ -219,8 +242,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ MyLog.i("该项考试成功,type="+type); ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过直角转弯合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } @@ -270,7 +298,7 @@ MyLog.i("当前得分:"+currTotalScore); if (currTotalScore < Constant.PASSING_SCORE){ MyLog.i("低于80,不合格"+currTotalScore); ExamPlatformData.getInstance().getTTS().speak("考试不合格"); // ExamPlatformData.getInstance().getTTS().speak("考试不合格"); // stopExam(); } MyLog.i("监测到有失败项目加入,通知UI更新颜色"); @@ -401,53 +429,6 @@ } private int whatPaintColor(ExamStatus examStat) { int map_id = examStat.getMap_id(); int status = examStat.getEnter(); MyLog.i(TAG, "whatPaintColor: map_id="+map_id+" status="+status); switch (status) { case 0://考试完成 switch (map_id) { case 1://倒库 if (item_conents.contains("倒车入库")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 2: if (item_conents.contains("坡道定点停车和起步")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 3: if (item_conents.contains("侧方停车")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 4: if (item_conents.contains("曲线行驶")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 5: if (item_conents.contains("直角转弯")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } } case 1://进入考场项目 MyLog.i("pink 进入某个考场项目"); return getResources().getColor(R.color.pink); case 2://待考 return getResources().getColor(R.color.examing); } return getResources().getColor(R.color.examing); } private void initView(View view) { @@ -546,6 +527,8 @@ @Override public void changKao() { exam_type = 2; iv_head.getDrawable().setLevel(1); examStatusViewModel.updateStartExam(exam_type); sendExamJson(1,exam_type); ExamPlatformData.getInstance().getTTS().speak("开始考试"); @@ -571,6 +554,7 @@ MessageProcessor.getInstance().sendMessage(jkMessage0202); iv_head.getDrawable().setLevel(1); tempQs.add(list.get(0)); int [] a =Utils.getRandomInts(4,12); for (int i = 0; i < a.length; i++) { @@ -589,7 +573,6 @@ } }); iv_head.getDrawable().setLevel(1); //清空sns sns.clear(); app/src/main/java/safeluck/drive/evaluation/fragment/SetArgumentsFragment.java
@@ -20,12 +20,16 @@ import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.work.WorkManager; 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 org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -51,6 +55,7 @@ import safeluck.drive.evaluation.cEventCenter.ICEventListener; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; import safeluck.drive.evaluation.util.SPUtils; /** * 设置所有参数 @@ -68,12 +73,13 @@ private int request_code = REQUEST_CODE_MAP; private Button btn_config_signal; private Button btn_mcu_upgrade,btn_map_select; private EditText et_ip,et_port; private EditText et_ip,et_port,et_simulte_ip,et_simulate_port; private Gson gson = new Gson(); private EditText et_ip_rtk,et_port_rtk,et_city_id,et_city_province,et_phone; private RTKConfigViewModel rtkConfigViewModel; private RTKConfig mRtkConfig; private Toolbar toolbar; private boolean needSendRtk = false; public static SetArgumentsFragment newInstance() { return new SetArgumentsFragment(); @@ -98,6 +104,9 @@ et_city_province.setText(String.valueOf(rtkConfig.getProvince())); et_port_rtk.setText(String.valueOf(rtkConfig.getPort())); et_phone.setText(rtkConfig.getPhone()); ExamPlatformData.getInstance().setRTKPort(rtkConfig.getPort()); ExamPlatformData.getInstance().setRTKIP(rtkConfig.getIp()); } @@ -107,6 +116,29 @@ return view; } private void sendRtkConfigInfo(RTKConfig mRTKConfig) { if (mRTKConfig != null) { String rtkjson = gson.toJson(mRTKConfig); //去除id字段 JSONObject jsonObject = null; try { jsonObject = new JSONObject(rtkjson); } catch (JSONException e) { e.printStackTrace(); } jsonObject.remove("_id"); rtkjson = null; rtkjson = jsonObject.toString(); MyLog.i( "need resend RTK配置信息:" + rtkjson+"标志位:"+needSendRtk); AYSdk.getInstance().sendCmd(Constant.PUSH_RTK_PLATFORM_INFO, rtkjson); } else { MyLog.i("RTKConfig未取到数据"); } needSendRtk = false; } private void initView(View view) { // toolbar =view.findViewById(R.id.toolbar); @@ -133,10 +165,12 @@ et_ip_rtk = view.findViewById(R.id.rtk_addr_ip); et_simulte_ip = view.findViewById(R.id.simulate_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); et_simulate_port = view.findViewById(R.id.simulate_port); } @Override @@ -150,7 +184,6 @@ signalFragment= SignalConfigFragment.newInstance(); } start(signalFragment); // ((BaseSettingFragment)getParentFragment()).startBrotherFragment(SignalConfigFragment.newInstance()); break; case R.id.btn_mcu_upgrade: @@ -174,19 +207,35 @@ case R.id.btn_save_platform: Toast.makeText(_mActivity, "保存成功", Toast.LENGTH_SHORT).show(); if(ExamPlatformData.getInstance().compareIPandPort(et_ip.getText().toString().trim(),Integer.parseInt(et_port.getText().toString().trim()))){ SPUtils.put(getActivity(), SPUtils.DES_HEX_PWD,""); ((MainActivity)getActivity()).examPlatformModel.getDataChange().postValue(1); 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())); String rtkip = et_ip_rtk.getText().toString().trim(); int rtkport = Integer.parseInt(et_port_rtk.getText().toString().trim()); mRtkConfig.setPort(rtkport); 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.setIp(rtkip); mRtkConfig.setPhone(et_phone.getText().toString().trim()); if (ExamPlatformData.getInstance().compareRTKIPandPort(rtkip,rtkport)){ mRtkConfig.setRegistered(0); MyLog.i("rtk ip和地址有变化"); needSendRtk = true; sendRtkConfigInfo(mRtkConfig); } rtkConfigViewModel.insertRTKConfig(mRtkConfig); } _mActivity.onBackPressed(); break; case R.id.btn_car_select://车辆模型和地图公用一套代码 区别在于REQUEST_CODE app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
@@ -12,6 +12,8 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProviders; import androidx.work.OneTimeWorkRequest; import androidx.work.PeriodicWorkRequest; import androidx.work.WorkInfo; import androidx.work.WorkManager; import android.os.Handler; @@ -41,6 +43,7 @@ import java.util.Date; import java.util.List; import java.util.Random; import java.util.concurrent.TimeUnit; import me.yokeyword.fragmentation.SupportFragment; import safeluck.drive.evaluation.Constant; @@ -69,6 +72,9 @@ import safeluck.drive.evaluation.platformMessage.JKMessage0203; import safeluck.drive.evaluation.platformMessage.JKMessage0204; import safeluck.drive.evaluation.util.Utils; import safeluck.drive.evaluation.worker.TimeWorker; import static androidx.work.PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS; /**单机训练UI * MyApplication2 @@ -100,7 +106,7 @@ private int item_id;//扣分分数总和 private ExamStatusViewModel examStatusViewModel; private static final int ADD_DATA = 1; private TextView tv_speed,tv_total_score,tv_sat_num,tv_name,tv_id,tv_work_platform; private TextView tv_speed,tv_total_score,tv_sat_num,tv_name,tv_id,tv_work_platform,tv_network_time; private double speed=0.0; private ImageView iv_rtk_status,iv_head; @@ -111,8 +117,6 @@ String icson;//返回的ic卡信息 json private Random random = new Random(); private List<SimulateNightBean.QuestionBean> tempQs= new ArrayList<>(); private Handler mHandler = new Handler(new Handler.Callback() { @@ -128,7 +132,7 @@ av_zhijiao.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_ANGLE)); } if (msg.what == SPEED_DATA){ tv_speed.setText(getResources().getString(R.string.speed,speed)); tv_speed.setText(_mActivity.getApplicationContext().getResources().getString(R.string.speed,speed)); } if (msg.what == Constant.IC_ID){ try { @@ -187,7 +191,13 @@ return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过倒车入库合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 2: @@ -195,7 +205,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过坡道定点停车和起步合格合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 3: @@ -203,7 +219,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过侧方停车合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 4: @@ -211,7 +233,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ ExamPlatformData.getInstance().getTTS().speak("曲线行驶合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过曲线行驶合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("曲线行驶合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } case 5: @@ -219,8 +247,13 @@ MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }else{ MyLog.i("该项考试成功,type="+type); ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); if (examStatus.getResult() ==1){ MyLog.i("已经播放过直角转弯合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } @@ -270,8 +303,8 @@ MyLog.i("当前得分:"+currTotalScore); if (currTotalScore < Constant.PASSING_SCORE){ MyLog.i("低于80,不合格"+currTotalScore); ExamPlatformData.getInstance().getTTS().speak("考试不合格"); stopExam(); // ExamPlatformData.getInstance().getTTS().speak("考试不合格"); // stopExam(); } MyLog.i("监测到有失败项目加入,通知UI更新颜色"); mHandler.obtainMessage(ADD_DATA).sendToTarget(); @@ -346,7 +379,7 @@ return view; } private List<Integer> sns =new ArrayList<>(); private void sendJKMessage0203(List<FailedProj_select> failedProj_selects) { JKMessage0203 jkMessage0203 = new JKMessage0203(); jkMessage0203.phone = ExamPlatformData.getInstance().getPhone(); @@ -361,7 +394,7 @@ failedProj_selects.get(i).getScore_deducting()==100?"不合格":"扣"+ failedProj_selects.get(i).getScore_deducting()+"分")); MyLog.i("没有相同的sn,发送"+failedProj_selects.get(i).getSn()); sns.add(failedProj_selects.get(i).getSn()); ExamPlatformData.getInstance().addSn(failedProj_selects.get(i).getSn()); String utc = failedProj_selects.get(i).getUtc(); if (!TextUtils.isEmpty(utc)&&utc.length()>12){ utc =utc.substring(0,12); @@ -385,11 +418,11 @@ } private boolean hasSnEqulas(int failedProjSn){ if (sns.size() > 0){ for (int j = 0; j < sns.size(); j++) { MyLog.i("已存在的sn"+sns.get(j)); if (sns.get(j) == failedProjSn){ MyLog.i("sn相同,不发"+sns.get(j)); if (ExamPlatformData.getInstance().getSns().size() > 0){ for (int j = 0; j < ExamPlatformData.getInstance().getSns().size(); j++) { MyLog.i("已存在的sn"+ExamPlatformData.getInstance().getSns().get(j)); if (ExamPlatformData.getInstance().getSns().get(j) == failedProjSn){ MyLog.i("sn相同,不发"+ExamPlatformData.getInstance().getSns().get(j)); return true; }else{ continue; @@ -401,63 +434,9 @@ } private int whatPaintColor(ExamStatus examStat) { int map_id = examStat.getMap_id(); int status = examStat.getEnter(); MyLog.i(TAG, "whatPaintColor: map_id="+map_id+" status="+status); switch (status) { case 0://考试完成 switch (map_id) { case 1://倒库 if (item_conents.contains("倒车入库")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 2: if (item_conents.contains("坡道定点停车和起步")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 3: if (item_conents.contains("侧方停车")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 4: if (item_conents.contains("曲线行驶")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } case 5: if (item_conents.contains("直角转弯")) { return getResources().getColor(R.color.colorAccent); }else{ return getResources().getColor(R.color.train_btn_return); } } case 1://进入考场项目 MyLog.i("pink 进入某个考场项目"); return getResources().getColor(R.color.pink); case 2://待考 return getResources().getColor(R.color.examing); } return getResources().getColor(R.color.examing); } private void initView(View view) { Intent intent = new Intent(ALARM_ACTION_CODE); PendingIntent pendingIntent = PendingIntent.getBroadcast(_mActivity.getApplicationContext(), REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) _mActivity.getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),pendingIntent); view.findViewById(R.id.iv_head).setOnClickListener(this); av_curve = view.findViewById(R.id.av3); @@ -474,6 +453,25 @@ tv_sat_num = view.findViewById(R.id.tv_sat_num); tv_speed = view.findViewById(R.id.tv_speed); tv_total_score = view.findViewById(R.id.tv_total_score); tv_network_time = view.findViewById(R.id.network_time); PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(TimeWorker.class,MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MICROSECONDS).build(); WorkManager.getInstance(getContext().getApplicationContext()).enqueue(periodicWorkRequest); WorkManager.getInstance(getContext().getApplicationContext()).getWorkInfoByIdLiveData(periodicWorkRequest.getId()) .observe(this, new Observer<WorkInfo>() { @Override public void onChanged(WorkInfo workInfo) { if (workInfo!= null&&workInfo.getState().isFinished()){ String time = workInfo.getOutputData().getString(Constant.TIME_MINUTE); MyLog.i("Time="+time); tv_network_time.setText(time); } } }); tv_network_time.setText(Utils.getHHmm()); tv_speed.setText(getResources().getString(R.string.speed,speed)); view.findViewById(R.id.btn_return).setOnClickListener(this); @@ -500,8 +498,10 @@ mScoreAdapter = new ScoreAdapter(_mActivity); mListView.setAdapter(mScoreAdapter); btn_start_exam = view.findViewById(R.id.btn_start); btn_start_exam.setText("开始训练"); btn_start_exam.setOnClickListener(this); tv_stop = view.findViewById(R.id.tv_stop); tv_stop.setText("结束训练"); tv_stop.setOnClickListener(this); mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item, null)); @@ -514,10 +514,7 @@ public void onClick(View v) { switch (v.getId()) { case R.id.btn_start: OneTimeWorkRequest examStatusInitWork = OneTimeWorkRequest.from(ExamStatusInitWorker.class); WorkManager.getInstance(_mActivity).enqueue(examStatusInitWork); item_id = 0; currTotalScore = 100; //TODO 发送JKMessage0202 给平台,开始考试 final JKMessage0202 jkMessage0202 = new JKMessage0202(); jkMessage0202.phone = ExamPlatformData.getInstance().getPhone(); @@ -525,7 +522,6 @@ jkMessage0202.ID = ExamPlatformData.getInstance().getID(); jkMessage0202.exam_id = ExamPlatformData.getInstance().getExam_id(); failedProjViewModel.deleteAll(); if (myDialogFragment == null){ myDialogFragment = new MyDialogFragment(); @@ -535,10 +531,13 @@ @Override public void changKao() { exam_type = 2; iv_head.getDrawable().setLevel(1); examStatusViewModel.updateStartExam(exam_type); sendExamJson(1,exam_type); ExamPlatformData.getInstance().getTTS().speak("开始考试"); ExamPlatformData.getInstance().getTTS().speak("开始训练"); jkMessage0202.curr_exam = 0; ExamPlatformData.getInstance().setTrainingMode(true);//设置为训练模式 MessageProcessor.getInstance().sendMessage(jkMessage0202); } @@ -551,8 +550,10 @@ if (simulateNightBean == null){ simulateNightBean = new SimulateNightBean(); } iv_head.getDrawable().setLevel(1); simulateNightBean.setExam(0); ExamPlatformData.getInstance().getTTS().speak("开始训练"); ExamPlatformData.getInstance().setTrainingMode(true);//设置为训练模式 final List<SimulateNightBean.QuestionBean> list = ExamPlatformData.getInstance().getSimulate_light_tips(); simulateNightBean.setQuestion(list.subList(list.size()-2,list.size()-1)); AYSdk.getInstance().sendCmd(0x8012,gson.toJson(simulateNightBean)); @@ -561,7 +562,7 @@ MessageProcessor.getInstance().sendMessage(jkMessage0202); tempQs.add(list.get(0)); int [] a = Utils.getRandomInts(4,12); int [] a =Utils.getRandomInts(4,12); for (int i = 0; i < a.length; i++) { tempQs.add(list.get(a[i])); } @@ -578,9 +579,8 @@ } }); iv_head.getDrawable().setLevel(1); //清空sns sns.clear(); @@ -627,11 +627,22 @@ private void stopExam() { MyLog.i(TAG,"结束考试"); //清空sns ExamPlatformData.getInstance().clearSns(); //设置训练模式为false ExamPlatformData.getInstance().setTrainingMode(false); //恢复初始数据 OneTimeWorkRequest examStatusInitWork = OneTimeWorkRequest.from(ExamStatusInitWorker.class); WorkManager.getInstance(_mActivity).enqueue(examStatusInitWork); item_id = 0; currTotalScore = 100; failedProjViewModel.deleteAll(); tv_total_score.setText(String.valueOf(currTotalScore)); iv_head.getDrawable().setLevel(0); ExamPlatformData.getInstance().getTTS().speak("结束考试"); ExamPlatformData.getInstance().getTTS().speak("结束训练"); examStatusViewModel.updateStartExam(Constant.NONE_BEEN_START_EXAM); sendExamJson(0,0);//结束考试 exstart=0 //TODO 发送JKMessage0204给平台 结束考试 app/src/main/java/safeluck/drive/evaluation/im/MessageProcessor.java
@@ -32,6 +32,7 @@ import safeluck.drive.evaluation.platformMessage.utils.MessageManager; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.SPUtils; import safeluck.drive.evaluation.util.Utils; /** * MyApplication2 @@ -69,11 +70,17 @@ JK2019MessageBase jk2019MessageBase = MessageManager.get(BytesUtils.bytesToHexString(datas)); if (jk2019MessageBase instanceof JKMessage8100){ if (((JKMessage8100) jk2019MessageBase).result == JKMessage8100.SUCCESS){ SPUtils.put(app.getAppContext(),SPUtils.DES_HEX_PWD,((JKMessage8100) jk2019MessageBase).des); MyLog.i(PlatFormConstant.TAG,"注册成功"); String des = ((JKMessage8100) jk2019MessageBase).des; SPUtils.put(app.getAppContext(),SPUtils.DES_HEX_PWD,des); JKMessage0101 jkMessage0101 = new JKMessage0101(); jkMessage0101.des =((JKMessage8100) jk2019MessageBase).des; jkMessage0101.timestamp = (int) System.currentTimeMillis(); // jkMessage0101.des =((JKMessage8100) jk2019MessageBase).des; int time =(int) System.currentTimeMillis(); jkMessage0101.timestamp = time; byte[] miwen =Utils.encrypt(ByteUtil.intGetBytes(time),des); MyLog.i(PlatFormConstant.TAG,"鉴权密文="+BytesUtils.bytesToHexString(miwen)+" time="+time); jkMessage0101.des = BytesUtils.bytesToHexString(miwen); sendMessage(jkMessage0101); ExamPlatformData.getInstance().setExamplatformStatus(ExamPlatformData.DEV_REGISTERED); }else{ ExamPlatformData.getInstance().setExamplatformStatus(ExamPlatformData.DEV_REGISTERED); app/src/main/java/safeluck/drive/evaluation/platformMessage/decoder/PhoneCoder.java
@@ -21,6 +21,9 @@ // str ="00000000000"; str ="0000000000000000"; } if (str.length()<16){ str = "0000"+str; } byte[] bcdBytes = ByteUtil.str2Bcd(str); // return "00000"+str; return BytesUtils.bytesToHexString(bcdBytes); app/src/main/java/safeluck/drive/evaluation/util/SPUtils.java
@@ -20,6 +20,8 @@ public static final String PLATFORM_PORT = "platform_port"; public static final String MAP_PATH = "map_path"; public static final String CAR_PATH = "car_path"; public static final String TRAIN_MODE = "training_mode"; public static final String FAIL_PROJ_SNS = "failed_projs_sns"; /** * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 app/src/main/java/safeluck/drive/evaluation/util/Utils.java
@@ -8,8 +8,14 @@ import com.anyun.exam.lib.util.ByteUtil; import com.safeluck.aykj.utils.BytesUtils; import java.security.SecureRandom; import java.util.Calendar; import java.util.Random; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; /** * MyApplication2 @@ -214,4 +220,55 @@ } return stringBuffer.toString(); } /** * 加密 * @param datasource byte[] * @param password String * @return byte[] */ public static byte[] encrypt(byte[] datasource, String password) { try{ SecureRandom random = new SecureRandom(); DESKeySpec desKey = new DESKeySpec(password.getBytes()); //创建一个密匙工厂,然后用它把DESKeySpec转换成 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey securekey = keyFactory.generateSecret(desKey); //Cipher对象实际完成加密操作 Cipher cipher = Cipher.getInstance("DES"); //用密匙初始化Cipher对象 cipher.init(Cipher.ENCRYPT_MODE, securekey, random); //现在,获取数据并加密 //正式执行加密操作 return cipher.doFinal(datasource); }catch(Throwable e){ e.printStackTrace(); } return null; } /** * 解密 * @param src byte[] * @param password String * @return byte[] * @throws Exception */ public static byte[] decrypt(byte[] src, String password) throws Exception { // DES算法要求有一个可信任的随机数源 SecureRandom random = new SecureRandom(); // 创建一个DESKeySpec对象 DESKeySpec desKey = new DESKeySpec(password.getBytes()); // 创建一个密匙工厂 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); // 将DESKeySpec对象转换成SecretKey对象 SecretKey securekey = keyFactory.generateSecret(desKey); // Cipher对象实际完成解密操作 Cipher cipher = Cipher.getInstance("DES"); // 用密匙初始化Cipher对象 cipher.init(Cipher.DECRYPT_MODE, securekey, random); // 真正开始解密操作 return cipher.doFinal(src); } } app/src/main/res/layout/layout_base_datas.xml
@@ -60,6 +60,47 @@ <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" 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="IP:"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/simulate_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/simulate_port" android:text="9001" android:background="@android:drawable/editbox_background_normal"/> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:visibility="gone" 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" im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java
@@ -73,7 +73,7 @@ byte b = (byte) a; bbt[p] = b; } // Log.i(TAG, "str2Bcd: "+byte2HexStr(bbt)); Log.i(TAG, "str2Bcd: "+byte2HexStr(bbt)); return bbt; }