FBS9600通信程序,带了均衡电压版本
Administrator
2021-08-12 8467d3be4ce3be340d36f45c83d370def9e7e50f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.battmonitor;
 
import java.util.Date;
import java.util.Timer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
import main.main_MonitorServer_FBS9600S;
 
import com.base.Com;
import com.battdata_rt.BattData_RT;
import com.battdata_rt.BattData_RT_Array;
import com.battdata_rt.BattStatData;
import com.config.AppConfig;
import com.config.AppParam;
 
public class BattDataTestPro_Thread extends Thread {
    
    private ExecutorService m_WorkThreadPool;
    private BattData_RT_Array m_Data;
    private int BattTestCountMax = 10;
    private int WorkThreadCountMax = 300;
    
    BattTestState m_BattTestState;
    
    public BattDataTestPro_Thread(AppParam param, AppConfig cfg, BattData_RT_Array data)
    {
        BattTestCountMax = param.getBattTestGroupCountMax(AppParam.AppParam_Discharge);
        WorkThreadCountMax = cfg.getWorkThreadCountMax();
        m_Data = data;
        
        m_WorkThreadPool = Executors.newFixedThreadPool(WorkThreadCountMax);
        m_BattTestState = new BattTestState(BattTestCountMax);
    }
    //-----------------------------------------------------------------------------//
    private class BattTestState{
        
        private int[] battgroup_working_num;
        
        public BattTestState(int size)
        {
            battgroup_working_num = new int[size];
            for(int n=0; n<BattTestCountMax; n++)
            {
                battgroup_working_num[n] = -1;
            }
        }
        
        public boolean putBattTesttingState( int index, boolean is_testting )
        {
            boolean res = false;
            
            int search_index = 0;
            for( search_index=0; search_index<battgroup_working_num.length; search_index++ )
            {
                if( index == battgroup_working_num[search_index] )
                {
                    if(false == is_testting)
                    {
                        battgroup_working_num[search_index] = -1;
                    }
                    else 
                    {
                        res = true;
                    }
                    break;
                }
            }
            
            if(search_index >= battgroup_working_num.length)
            {
                if(true == is_testting)
                {
                    for(int n=0; n<battgroup_working_num.length; n++)
                    {
                        if(battgroup_working_num[n] < 0)
                        {
                            battgroup_working_num[n] = index;
                            res = true;
                            break;
                        }
                    }
                }
            }
            
            return res;
        }
    }
    //-----------------------------------------------------------------------------//
    @Override
    public void run() {
        System.out.println(this.getName() + " - BattDataTestPro_Thread Started By TimerTask ...");
        Timer timer = new Timer();
        MyBattTestTask myTask1 = new MyBattTestTask(); 
        timer.scheduleAtFixedRate(myTask1, 1000, 1000);        //ÈÎÎñ 1Ãëºó¿ªÊ¼½øÐÐÖØ¸´µÄ¹Ì¶¨ËÙÂÊÖ´ÐУ¨1ÃëÖÓÖØ¸´Ò»´Î£©
        
        while(true)
        {
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    class MyBattTestTask extends java.util.TimerTask{
        String info = "MyBattTestTask By TimerTask";
        
        @Override
        public void run() {
            // TODO Auto-generated method stub
            try 
            {
                for(int n=0; n<m_Data.getItemCount(); n++)
                {
                    BattData_RT rt_data = m_Data.getItem(n);
                    
                    boolean need_to_store = false;
                    if(main_MonitorServer_FBS9600S.is_app_for_bpm7100_only) {
                        need_to_store = rt_data.check_If_Bpm7100_DataNeedStore();
                    } else {
                        need_to_store = rt_data.checkIfDataNeedStore();
                    }
                    
                    boolean batt_is_testing = false;
                    if((BattStatData.BATTSTATE_CHARGE == rt_data.getBattTestType())
                        || (BattStatData.BATTSTATE_DISCHARGE == rt_data.getBattTestType())
                        || (BattStatData.BATTSTATE_MONITOR == rt_data.getBattTestType())
                        || (true == need_to_store))
                    {
                        batt_is_testing = true;
                    }
                    
                    if(true == m_BattTestState.putBattTesttingState(n, batt_is_testing))
                    {
                        if(true == need_to_store)
                        {
                            m_WorkThreadPool.execute(rt_data.mSqlTask);
                        }
                    }
                    else
                    {
                        rt_data.clearStoreDataBusyTag();
                    }
                }
            } catch (Exception e) {
                System.err.println("MyBattTestTask: " + e.getMessage() 
                        + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            }
        }
        
        public String getInfo(){
            return info;     
        }     
        public void setInfo(String info){
            this.info = info;     
        }
    }     
}