whyclj
2019-11-28 4098b3f61bb7ffd9275d54612f68142fedefa0ea
修改线程中的数据库操作语句避免造成sqlite数据库bug
3个文件已修改
40 ■■■■■ 已修改文件
platforms/android/app/src/main/java/com/socket/BattDataThread.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/BattResDataRecordThread.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/CommSockClientThread.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platforms/android/app/src/main/java/com/socket/BattDataThread.java
@@ -146,7 +146,6 @@
    public void run() {
        Log.e(TAG, "run: battindex"+battIndex +"\t start at "+ Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
        Date nowTime = new Date();                  //当前时间
        int monRCount = 0;                          //单体读取
        int runCount = 0;                           //执行次数
        while(true){
@@ -166,7 +165,7 @@
                            readSystemState("");
                        }
                        if(runCount % 20 == 0){
                        if(runCount % 25 == 0){
                            int maxCount = (int)Math.ceil((double)state.monCount/100);              //最多需要读取次数
                            int monindex = monRCount % maxCount;                                     //单体索引
                            //读取单体电压
@@ -190,7 +189,6 @@
                }else{
                    isOutTime = false;
                }
                sleep(200);
            } catch (Exception e) {
                e.printStackTrace();
platforms/android/app/src/main/java/com/socket/BattResDataRecordThread.java
@@ -39,13 +39,13 @@
                        if(battData.state.monCount >0 && battData.state.mon_ress[battData.state.monCount-1] > 0){
                            //开始记录内阻历史数据
                            int max_test_record_count = queryMaxTestRecordCount(battData.battIndex,dbHelper);                           //查询当前电池组最大的记录笔数
                            Log.e(TAG, "run: MAXCOUNT:"+max_test_record_count );
                            //Log.e(TAG, "run: MAXCOUNT:"+max_test_record_count );
                            //插入 tb_battresdata_inf 表中
                            insertBattResDataInf(battData.battIndex, battData.state,dbHelper,max_test_record_count);
                            //插入 tb_battresdata_id 表中
                            insertBattResDataID(battData.battIndex,battData.state,dbHelper,max_test_record_count);
                            Log.e(TAG, "run: battindex:"+battData.battIndex+"记录历史数据成功 #############################");
                            //Log.e(TAG, "run: battindex:"+battData.battIndex+"记录历史数据成功 #############################");
                            lastResTestCount = battData.state.getRestestcount();
                        }
                    }
@@ -70,11 +70,12 @@
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {
            db.execSQL(sql_str_start+sql_str_base);
            if(db != null){
                db.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
//            if(db != null){
//                db.close();
//            }
        }
    }
@@ -101,11 +102,13 @@
        try {
            Log.d(TAG, "insertBattResDataInf: "+sql_str);
            db.execSQL(sql_str);
            if(db != null){
                db.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
//            if(db != null){
//                db.close();
//            }
        }
    }
@@ -128,9 +131,9 @@
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            if(db != null){
                db.close();
            }
//            if(db != null){
//                db.close();
//            }
        }
        return max_test_record_count;
    }
platforms/android/app/src/main/java/com/socket/CommSockClientThread.java
@@ -44,6 +44,7 @@
    private boolean thread_run_flag = true;
    private Gson gson = new Gson();
    private ServiceModel remodel = new ServiceModel();
    byte[] rx_buf_t = new byte[1024];
    private CommSockClientThread(){
        this.concentratorState = new Concentrator_State();
@@ -150,17 +151,14 @@
                InputStream in = this.socket.getInputStream();
                OutputStream out = this.socket.getOutputStream();
                //----------------- clear rx buff for tcp resend packet ----------------//
                byte[] rx_buf_t = new byte[1024];
                //----------------------------------------------------------------------//
                bytebuffer_for_socket_RX.order(ByteOrder.BIG_ENDIAN);
                bytebuffer_for_socket_RX.clear();
                //--------------------- socket write -----------------------------------//
                //--------------------- socket write -----------------------------------//
                boolean aes_en = true;
                byte[] plain_tx_t = datasource;
                byte[] cipher_tx_t = new byte[plain_tx_t.length];
                Date d1 = new Date();
                //=====================================================================//
                /*
                for(int n=0; n<3; n++) {
@@ -217,11 +215,6 @@
                bytebuffer_for_socket_RX.flip();
//                Date d2 = new Date();
//                long comm_tms = (d2.getTime() - d1.getTime());
//                if(comm_tms < 200) {
//                    Thread.sleep(200 - comm_tms);
//                }
                /*
                System.out.println(this.getName()
                                    + "  dev_id: " + m_StatAndParam.dev_id