From 560d53cafc4aa81b949d3a0b46e1e5837b47f775 Mon Sep 17 00:00:00 2001 From: haijiang <181069201@qq.com> Date: Fri, 20 Apr 2018 11:59:03 +0800 Subject: [PATCH] 修复bug --- app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java | 66 ++++++++++++++++++++++----------- 1 files changed, 44 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java index 15673c0..7713628 100644 --- a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java +++ b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java @@ -82,6 +82,8 @@ private ImageView iv_his, iv_status, iv_search, iv_bottom_status, iv_dianliang; private BluetoothService mBluetoothService; private ArrayList<String> realResult = new ArrayList<>(); + private ArrayList<String> realHourResult = new ArrayList<>(); + private ArrayList<String> realHisResult = new ArrayList<>(); //������������ private ArrayList<RecData> submitResult = new ArrayList<>(); private ArrayList<RecData> submitHisResult = new ArrayList<>(); @@ -144,7 +146,7 @@ getActivity().runOnUiThread(new Runnable() { @Override public void run() { - Log.d("haijiang", "������������====" + StringUtils.byteArrayToHexStr(characteristic.getValue())); +// Log.d("haijiang", "������������====" + StringUtils.byteArrayToHexStr(characteristic.getValue())); String result = StringUtils.byteArrayToHexStr(characteristic.getValue()); //������������ parseCurrentData(result); @@ -562,27 +564,27 @@ tv_tishi.setText("������������������"); tv_tishi.setBackgroundResource(R.mipmap.bt_blue); iv_bottom_status.setImageResource(R.mipmap.icon_qingwei); - tv_desc.setText("���������������������������\n���������������������������������������������������"); + tv_desc.setText("���������������������������\n���������������������������������������"); iv_status.setImageResource(R.mipmap.icon_head_qingwei); - tv_status.setText("������"); + tv_status.setText("������"); tv_status.setTextColor(getResources().getColor(R.color.blue_txt)); ll_status.setBackgroundResource(R.mipmap.bg_corner_blue); } else if (level == 2) { tv_tishi.setText("������������������"); tv_tishi.setBackgroundResource(R.mipmap.bt_zise); iv_bottom_status.setImageResource(R.mipmap.icon_zhongdu); - tv_desc.setText("���������������������������\n���������������������������������������������������"); + tv_desc.setText("���������������������������\n������������������������������������������"); iv_status.setImageResource(R.mipmap.icon_head_zhongfu); - tv_status.setText("������"); + tv_status.setText("������"); tv_status.setTextColor(getResources().getColor(R.color.zi_txt)); ll_status.setBackgroundResource(R.mipmap.bg_corner_zise); } else if (level == 3) { tv_tishi.setText("������������������"); tv_tishi.setBackgroundResource(R.mipmap.bt_red); iv_bottom_status.setImageResource(R.mipmap.icon_yanzhong); - tv_desc.setText("���������������������������\n���������������������������������������������������"); + tv_desc.setText("���������������������������\n������������������������������������������"); iv_status.setImageResource(R.mipmap.icon_danger); - tv_status.setText("������"); + tv_status.setText("������"); tv_status.setTextColor(getResources().getColor(R.color.red_txt)); ll_status.setBackgroundResource(R.mipmap.bg_conner_red); } else if (level == -1) { @@ -613,19 +615,18 @@ for (String s : realResult) { nowResult += s; } - Log.d("haijiang", "������������===nowResult=" + nowResult); +// Log.d("haijiang", "������������===nowResult=" + nowResult); /** * 20������������5A������ 5B������ */ if (!TextUtils.isEmpty(nowResult) && nowResult.length() == 40 && nowResult.startsWith("5A") && nowResult.endsWith("5B")) { - int shunshiValue = Integer.parseInt(nowResult.substring(24, 26), 16) * 256 + Integer.parseInt(nowResult.substring(26, 28), 16); int leijiValue = Integer.parseInt(nowResult.substring(28, 30), 16) * 1024 + Integer.parseInt(nowResult.substring(30, 32), 16) * 512 + Integer.parseInt(nowResult.substring(32, 34), 16) * 256 + Integer.parseInt(nowResult.substring(34, 36), 16); // float level = (float) (shunshiValue / 10 * 0.01); int b1 = Integer.parseInt(nowResult.substring(6, 8), 16); int b2 = Integer.parseInt(nowResult.substring(12, 14), 16); - XLog.d("���������" + shunshiValue + "|���������" + leijiValue + "-----���������" + b1 + "|" + b2); - tv_ljjl.setText(NumberUtils.getBigDecimalValue(leijiValue * 0.01, 3) + ""); +// XLog.d("���������" + shunshiValue + "|���������" + leijiValue + "-----���������" + b1 + "|" + b2); + tv_ljjl.setText(NumberUtils.getBigDecimalValue(leijiValue * 0.001, 3) + ""); double shishiValue = NumberUtils.getBigDecimalValue((shunshiValue) / 100.0, 3); tv_shishi.setText(shishiValue + ""); @@ -659,12 +660,12 @@ } } - if (shishiValue < 0.25) { + if (shishiValue < 0.16) { data.setIs_warn(0); - pv.setPercent((float) (shishiValue)); + pv.setPercent((float) (shishiValue * (0.25 / 0.16))); showStatus(0); stop(); - } else if (shishiValue >= 0.25 && shishiValue < 0.8) { + } else if (shishiValue >= 0.16 && shishiValue < 0.8) { data.setIs_warn(1); pv.setPercent((float) (0.25 + shishiValue * (0.25 / 0.8))); showStatus(1); @@ -695,8 +696,19 @@ * @param result */ private void parseHoutData(String result) { - if (!TextUtils.isEmpty(result) && result.length() == 8 && result.startsWith("7A") && result.endsWith("7B")) { - int hourValue = Integer.parseInt(result.substring(2, 4), 16) * 256 + Integer.parseInt(result.substring(4, 6), 16); + if (result.startsWith("7A")) { + realHourResult.clear(); + realHourResult.add(result); + } else { + realHourResult.add(result); + } + String nowResult = ""; + for (String s : realHourResult) { + nowResult += s; + } + if (!TextUtils.isEmpty(nowResult)&& nowResult.length() == 8&&nowResult.startsWith("7A") && nowResult.endsWith("7B")) { + int hourValue = Integer.parseInt(nowResult.substring(2, 4), 16) * 256 + Integer.parseInt(nowResult.substring(4, 6), 16); + Log.d("haijiang", "������������������������="+ nowResult+"���������"+nowResult.substring(2, 4)+"|"+Integer.parseInt(nowResult.substring(2, 4), 16) * 256+"���������"+nowResult.substring(4, 6)+"|"+Integer.parseInt(nowResult.substring(4, 6), 16) +"���������"+(hourValue/100.0)); sendHourDataRec(); RecData data = new RecData(); data.setType(1); @@ -713,16 +725,26 @@ * ��������������������������������� */ private void parseHisData(String result) { - if (!TextUtils.isEmpty(result) && result.length() == 16 && result.startsWith("3A") && result.endsWith("3B")) { + if (result.startsWith("3A")) { + realHisResult.clear(); + realHisResult.add(result); + } else { + realHisResult.add(result); + } + String nowResult = ""; + for (String s : realHisResult) { + nowResult += s; + } + if (!TextUtils.isEmpty(nowResult) && nowResult.length() == 16 && nowResult.startsWith("3A") && nowResult.endsWith("3B")) { if (submitHisResult.size() == 0) { //��������������������� checkResComplete(result); } - String year = "20" + Integer.parseInt(result.substring(2, 4), 16); - String month = Integer.parseInt(result.substring(4, 6), 16) + ""; - String day = Integer.parseInt(result.substring(6, 8), 16) + ""; - String hour = Integer.parseInt(result.substring(8, 10), 16) + ""; - int resValue = Integer.parseInt(result.substring(10, 12), 16) * 256 + Integer.parseInt(result.substring(12, 14), 16); + String year = "20" + Integer.parseInt(nowResult.substring(2, 4), 16); + String month = Integer.parseInt(nowResult.substring(4, 6), 16) + ""; + String day = Integer.parseInt(nowResult.substring(6, 8), 16) + ""; + String hour = Integer.parseInt(nowResult.substring(8, 10), 16) + ""; + int resValue = Integer.parseInt(nowResult.substring(10, 12), 16) * 256 + Integer.parseInt(nowResult.substring(12, 14), 16); RecData data = new RecData(); StringBuilder time = new StringBuilder(); //yyyy-MM-dd HH:mm:ss -- Gitblit v1.8.0