Merge branch 'FBS9600' of http://whychdw@118.89.139.230:10101/r/FBS9600App.git into FBS9600
| | |
| | | if(battDataThread.isInstall){
|
| | | List<BattAlarmData> alarmDatas = battDataThread.state.makeAlarmData(battDataThread,alarmParam);
|
| | | if(alarmDatas.size() > 0){
|
| | | Log.e(TAG, "run: 更新告警条数"+ alarmDatas.size());
|
| | | //Log.e(TAG, "run: 更新告警条数"+ alarmDatas.size());
|
| | |
|
| | | //更新当前告警记录
|
| | | for(int k = 0;k<alarmDatas.size();k++){
|
| | | Log.e(TAG, "run: "+alarmDatas.get(k) );
|
| | | //Log.e(TAG, "run: "+alarmDatas.get(k) );
|
| | | insertOrUpdateBattAlarmData(dbHelper,alarmDatas.get(k)); //插入或更新当前的告警记录
|
| | | }
|
| | | }
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.close();
|
| | | // if(db != null){
|
| | | // db.close();
|
| | | // }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally{
|
| | | db.close();
|
| | | // if(db != null){
|
| | | // db.close();
|
| | | // }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally{
|
| | | if(db != null){
|
| | | db.close();
|
| | | }
|
| | | // if(db != null){
|
| | | // db.close();
|
| | | // }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | //创建tb_battalarm_data表 |
| | | //Create_battalarm_data(db); |
| | | |
| | | db.close(); |
| | | //db.close(); |
| | | |
| | | } |
| | | |
| | |
| | | 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){
|
| | |
| | | readSystemState("");
|
| | | }
|
| | |
|
| | | if(runCount % 20 == 0){
|
| | | if(runCount % 25 == 0){
|
| | | int maxCount = (int)Math.ceil((double)state.monCount/100); //最多需要读取次数
|
| | | int monindex = monRCount % maxCount; //单体索引
|
| | | //读取单体电压
|
| | |
| | | }else{
|
| | | isOutTime = false;
|
| | | }
|
| | |
|
| | | sleep(200);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | 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(); |
| | | // } |
| | | } |
| | | } |
| | | |
| | |
| | | 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(); |
| | | // } |
| | | } |
| | | } |
| | | |
| | |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally{ |
| | | if(db != null){ |
| | | db.close(); |
| | | } |
| | | // if(db != null){ |
| | | // db.close(); |
| | | // } |
| | | } |
| | | return max_test_record_count; |
| | | } |
| | |
| | | insertBattTestDatainf(dbHelper,battData); |
| | | |
| | | lastRecordTime = new Date(); |
| | | isStartRecord = false; |
| | | |
| | | } |
| | | int testTimelong = (int)((battData.state.record_time.getTime() - battData.state.testStartTime.getTime())/1000); //测试时长 |
| | | battData.state.testTimelong = testTimelong; |
| | |
| | | isRecording = false; |
| | | } |
| | | int recordInterver = (int)Math.abs(new Date().getTime()-lastRecordTime.getTime())/1000; //距离上次记录数据的时长 |
| | | if(recordInterver >= saveDataIntever || !isStartRecord){ |
| | | if(recordInterver >= saveDataIntever || !isRecording){ |
| | | lastRecordTime = new Date(); |
| | | //放电结束或者记录时间到 |
| | | //记录当前的充放电记录 |
| | | insertBattTestData(dbHelper,battData); |
| | | } |
| | | battData.state.record_num++; |
| | | |
| | | isStartRecord = false; |
| | | }else{ |
| | | //暂无记录充放电数据 |
| | | if(battData.state.battstate == Concentrator_State.WORKSTATE_DISCH && battData.isInstall && battData.loseTimeLong <= 60*60){ |
| | |
| | | } |
| | | |
| | | } |
| | | sleep(1000); |
| | | sleep(3000); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally{ |
| | | if(db != null){ |
| | | db.close(); |
| | | } |
| | | // if(db != null){ |
| | | // db.close(); |
| | | // } |
| | | } |
| | | return max_test_record_count; |
| | | } |
| | |
| | | "(BattGroupId,test_record_count,test_type,record_time_interval,record_num,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,max_monnum,max_monvol,min_monnum,min_monvol) " + |
| | | " VALUES("+battData.battIndex+","+state.test_record_count+","+state.test_type+","+saveDataIntever+","+state.record_num+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+state.max_monnum+","+state.max_monvol+","+state.min_monnum+","+state.min_monvol+") "; |
| | | |
| | | String batt_id_sql_str="INSERT INTO tb_batttestdata_"+battData.battIndex+"(BattGroupId,test_record_count,test_type,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol,mon_tmp,mon_res) " + |
| | | String batt_id_sql_str="INSERT INTO tb_batttestdata_"+battData.battIndex+"(BattGroupId,test_record_count,test_type,record_num,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol,mon_tmp,mon_res) " + |
| | | "VALUES"; |
| | | for(int i=0;i<state.monCount;i++){ |
| | | if(i != 0){ |
| | | batt_id_sql_str += ","; |
| | | } |
| | | batt_id_sql_str += "("+battData.battIndex+","+state.test_record_count+","+state.test_type+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+(i+1)+","+state.mon_vols[i]+","+state.mon_tmps[i]+","+state.mon_ress[i]+")"; |
| | | batt_id_sql_str += "("+battData.battIndex+","+state.test_record_count+","+state.test_type+","+state.record_num+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+(i+1)+","+state.mon_vols[i]+","+state.mon_tmps[i]+","+state.mon_ress[i]+")"; |
| | | } |
| | | SQLiteDatabase db = null; |
| | | try { |
| | |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if(db != null){ |
| | | try { |
| | | db.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | // if(db != null){ |
| | | // try { |
| | | // db.close(); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | } |
| | | } |
| | | |
| | |
| | | Concentrator_State state = battData.state; |
| | | String batt_inf_sql_str = " UPDATE tb_batttestdata_inf SET record_num ="+state.record_num+" ,record_time='"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',test_timelong="+state.testTimelong+",group_vol="+state.getGroupvol()+",test_curr="+state.getGroupcurr()+",test_cap=0,max_monnum="+state.max_monnum+",max_monvol="+state.max_monvol+",min_monnum="+state.min_monnum+",min_monvol="+state.min_monvol+" WHERE BattGroupId = "+battData.battIndex+" AND test_record_count = "+state.test_record_count; |
| | | |
| | | String batt_id_sql_str="INSERT INTO tb_batttestdata_"+battData.battIndex+"(BattGroupId,test_record_count,test_type,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol,mon_tmp,mon_res) " + |
| | | String batt_id_sql_str="INSERT INTO tb_batttestdata_"+battData.battIndex+"(BattGroupId,test_record_count,test_type,record_num,test_starttime,record_time,test_timelong,group_vol,test_curr,test_cap,mon_num,mon_vol,mon_tmp,mon_res) " + |
| | | "VALUES"; |
| | | for(int i=0;i<state.monCount;i++){ |
| | | if(i != 0){ |
| | | batt_id_sql_str += ","; |
| | | } |
| | | batt_id_sql_str += "("+battData.battIndex+","+state.test_record_count+","+state.test_type+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+(i+1)+","+state.mon_vols[i]+","+state.mon_tmps[i]+","+state.mon_ress[i]+")"; |
| | | batt_id_sql_str += "("+battData.battIndex+","+state.test_record_count+","+state.test_type+","+state.record_num+",'"+Com.getDateTimeFormat(state.testStartTime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(state.record_time,Com.DTF_YMDhms)+"',"+state.testTimelong+","+state.getGroupvol()+","+state.getGroupcurr()+","+0+","+(i+1)+","+state.mon_vols[i]+","+state.mon_tmps[i]+","+state.mon_ress[i]+")"; |
| | | } |
| | | SQLiteDatabase db = null; |
| | | try { |
| | |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if(db != null){ |
| | | try { |
| | | db.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | // if(db != null){ |
| | | // try { |
| | | // db.close(); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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();
|
| | |
| | | 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++) {
|
| | |
| | |
|
| | | 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
|