whyclj
2020-08-29 166f2f34ffed7ee9562eff02482ac6a3f7168bcd
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package main;
import java.util.Date;
 
import com.battmonitor.base.AppParam;
import com.battmonitor.base.Com;
import com.battmonitor.data.BattData_RT_Array;
import com.battmonitor.sql.MysqlConnPool;
import com.battmonitor.sql.Sql_Mysql;
import com.batttest.BattDataTestPro_Thread;
import com.batttest.BattResStorePro_Thread;
import com.config.AppConfig;
import com.dev_fbs9600.data.FBS9600_ServerSocket_Thread;
import com.dev_fbs9600.data.FBS9600_Task_Thread;
import com.dev_fbs9600s.data.FBS9600S_ServerSocket_Thread;
import com.dev_fbs9600s.data.FBS9600S_SocketClient_Thread_SQL;
 
public class main_MonitorServer_FBS9600SMore {
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /*********************  Ï·½É豸ֻÄÜÑ¡ÔñÒ»¸ö    *******************************/
    public final static boolean is_app_for_cmcc_only = false;
    public final static boolean is_app_for_fbo_data_only = false;
    public final static boolean is_app_for_fbs_free_only = false;
    public final static boolean is_app_for_bpm7100_only = false;
    public final static boolean is_app_for_FBS9100S_only = true;
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    public final static boolean app_debug = false;
    public final static double m_VersionNum = 1.591;
    public final static String m_Version = "Welcome To Use main_MonitorServer_FBS9600SMore V" 
                                            + m_VersionNum + " RC_20190112";
    /**************************************************************************/
    /**************************************************************************/
    public static final int DEF_MysqlServerFBS9100S_Port = 3360;
    public static int MysqlServer_Port = DEF_MysqlServerFBS9100S_Port;
    
    private static AppConfig m_AppConfig;
    
    private static MysqlConnPool GB_MysqlConnPool;
    private static BattData_RT_Array GB_DataArray;
    private static AppParam GB_App_Param;
    /*********************************************************************************************/
    /*********************************************************************************************/
    public static void main(String[] args) {
        String ver = m_Version;
        MysqlServer_Port = DEF_MysqlServerFBS9100S_Port;
        
        System.out.println("/****************************************************************");
        System.out.println("*****************************************************************");
        System.out.println("****************************************************************/");
        System.out.println(ver);
        System.out.println("Server Started At DateTime: " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        //´´½¨config.xmlÎļþ
        m_AppConfig = new AppConfig();
        
        System.out.println("ÕýÔÚÁ¬½ÓÊý¾Ý¿â DBserver IP£º" + m_AppConfig.getMysqlServerIp() + ", port: " + MysqlServer_Port);
        
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 
                                                m_AppConfig.getMysqlConnCountMax());
        
        Sql_Mysql sql_ck = new Sql_Mysql(GB_MysqlConnPool.getConn());
        try {
            if(null != sql_ck.mysql_con) {
                System.out.println("³É¹¦Á¬½ÓÊý¾Ý¿â" 
                                    + " DBserver IP£º" + m_AppConfig.getMysqlServerIp() 
                                    + ", port: " + MysqlServer_Port 
                                    + " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            }
        } finally {
            sql_ck.close_con();
        }
        System.out.println("/****************************************************************/");
        /*
        try {
            Process ps = null;
            ps = Runtime.getRuntime().exec("cmd.exe /c start /b java -jar BTSE_DB_Builder.jar");
            SequenceInputStream sis = new SequenceInputStream(ps.getInputStream(), ps.getErrorStream());
            InputStreamReader isr = new InputStreamReader (sis, "GBK");
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while (null != ( line = br.readLine () ))
            {
                System.out.println (line);
            }
            ps.waitFor();
        }  catch (Exception e) {
            e.printStackTrace(); 
        }
        */
        System.out.println("/****************************************************************/");
        //´´½¨tb_app_param±í,²¢ÇÒÉèÖñíÖеÄÊý¾Ý
        GB_App_Param = new AppParam(GB_MysqlConnPool);
        
        GB_DataArray = new BattData_RT_Array(m_AppConfig, GB_App_Param, GB_MysqlConnPool);
        //¸üÐÂtb_batt_rtdata,tb_server_state,tb_batt_rtstate±íÖеÄÊý¾Ý
        GB_DataArray.initBattDataRT_Inf(m_VersionNum);
        
        System.out.println( "------------------- AppConfig start -----------------------------------\n"
                            + "MysqlServerIp=" + m_AppConfig.getMysqlServerIp() + "\n"
                            + "SybaseServerIp=" + m_AppConfig.getSourceSQLServerIp() + "\n"
                            + "MysqlConnCountMax=" + m_AppConfig.getMysqlConnCountMax() + "\n"
                            + "WorkThreadCountMax=" + m_AppConfig.getWorkThreadCountMax() + "\n"
                            + "SourceBattDataType=" + m_AppConfig.getSourceBattDataType() + "\n"
                            + "FbsDeviceBaseIp=" + m_AppConfig.getFbsDeviceBaseIp() + "\n"
                            + "BattAlarmFnEn=" + m_AppConfig.getBattAlarmFnEn() + "\n"
                            + "BattAlarmFnStartDelay=" + m_AppConfig.getBattAlarmFnStartDelay() + "\n"
                            + "BattAlarmClearedDelay=" + m_AppConfig.getBattAlarmClearedDelay() + "\n"
                            + "BattResStoreFnEn=" + m_AppConfig.getBattResStoreFnEn() + "\n"
                            + "BattResStoreDelayForTestManual=" + m_AppConfig.getBattResStoreDelayForTestManual() + "\n"
                            + "BattResStoreDayInterval=" + m_AppConfig.getBattResStoreDayInterval() + "\n"
                            + "------------------- AppConfig end -----------------------------------\n");
                            
        System.out.println( "--------------------- App_Param start---------------------------------\n"
                            + "Discharge_TestTimeLongMinimum=" 
                            + GB_App_Param.getTestTimeLongMinimum(AppParam.AppParam_Discharge) + "\n"
                            + "Discharge_SaveDataTimeInterval=" 
                            + GB_App_Param.getSaveDataTimeInterval(AppParam.AppParam_Discharge) + "\n"
                            + "Discharge_MonVolChangeLevel=" 
                            + GB_App_Param.getMonVolChangeLevel(AppParam.AppParam_Discharge) + "\n"
                            + "Discharge_BattTestGroupCountMax=" 
                            + GB_App_Param.getBattTestGroupCountMax(AppParam.AppParam_Discharge) + "\n"
                            + "Discharge_TestDataRecordCountMax=" 
                            + GB_App_Param.getTestDataRecordCountMax(AppParam.AppParam_Discharge) + "\n"
                            + "--------------------------------------------------------------------\n"
                            + "Charge_TestTimeLongMinimum=" 
                            + GB_App_Param.getTestTimeLongMinimum(AppParam.AppParam_Charge) + "\n"
                            + "Charge_SaveDataTimeInterval=" 
                            + GB_App_Param.getSaveDataTimeInterval(AppParam.AppParam_Charge) + "\n"
                            + "Charge_MonVolChangeLevel=" 
                            + GB_App_Param.getMonVolChangeLevel(AppParam.AppParam_Charge) + "\n"
                            + "Charge_BattTestGroupCountMax=" 
                            + GB_App_Param.getBattTestGroupCountMax(AppParam.AppParam_Charge) + "\n"
                            + "Charge_TestDataRecordCountMax=" 
                            + GB_App_Param.getTestDataRecordCountMax(AppParam.AppParam_Charge) + "\n"
                            + "--------------------------------------------------------------------\n"
                            + "Poweroff_TestTimeLongMinimum=" 
                            + GB_App_Param.getTestTimeLongMinimum(AppParam.AppParam_PowerOff) + "\n"
                            + "Poweroff_SaveDataTimeInterval=" 
                            + GB_App_Param.getSaveDataTimeInterval(AppParam.AppParam_PowerOff) + "\n"
                            + "Poweroff_MonVolChangeLevel=" 
                            + GB_App_Param.getMonVolChangeLevel(AppParam.AppParam_PowerOff) + "\n"
                            + "Poweroff_BattTestGroupCountMax=" 
                            + GB_App_Param.getBattTestGroupCountMax(AppParam.AppParam_PowerOff) + "\n"
                            + "Poweroff_TestDataRecordCountMax=" 
                            + GB_App_Param.getTestDataRecordCountMax(AppParam.AppParam_PowerOff) + "\n"
                            + "--------------------------------------------------------------------\n"
                            + "Discharge_BattJunHengFN=" + GB_App_Param.getBattJunHengFN() + "\n" 
                            + "--------------------- App_Param end---------------------------------\n");
        /*********************************************************************************/
        /*********************************************************************************/
        /*********************************************************************************/
        /*********************************************************************************/
        System.out.println("SourceBattDataType is DATA_SOURCE_FBSDEV");
        System.out.println("Recreate RamDB Tables State Is '" + m_AppConfig.getMysqlDB_RecreateEn() + "'");
        {
            //------------------------- FBS9100É豸Ïà¹ØµÄÊý¾Ý±íÔÚ´ËÀàÖн¨Á¢ ------------------------------//
            //FBS9100S_ServerSocketThread fbs9100S_Thread = new FBS9100S_ServerSocketThread(GB_MysqlConnPool, GB_DataArray);
            //fbs9100S_Thread.start();
            /*
            if(true == m_AppConfig.getFbs9100_ClientCommEn()) {
                FBS9100_Task_Thread task_9100 = new FBS9100_Task_Thread(GB_MysqlConnPool, GB_DataArray, m_AppConfig);
                task_9100.start();
            }
            */
            /*
            if(true == m_AppConfig.getFbs9100_ServerCommEn()) {
                FBS9100_ServerSocketThread fbs9100Thread 
                = new FBS9100_ServerSocketThread(GB_MysqlConnPool, GB_DataArray, m_AppConfig.getFbsDevCommRate());
                fbs9100Thread.start();
            }
            */
        }
        
        {
            //FBS9600     ´´½¨ tb_fbs9600_state£¬ÒÔ¼°ÊµÊ±¸üÐÂtb_fbs9600_state  Í¬Ê±¼à²â  ²¢Ìí¼Óµ½tb_devalarm_data
            //System.out.println(9600+"%%%%%%%%%%%%%%%%");
            //´´½¨tb_fbs9600_stateÊý¾Ý¿â±í
            
            //FBS9600_Task_Thread task_9600 = new FBS9600_Task_Thread(GB_MysqlConnPool, GB_DataArray);
            //task_9600.start();
            
            /*
            FBS9600_ServerSocket_Thread task_9600_server 
                = new FBS9600_ServerSocket_Thread(GB_MysqlConnPool, GB_DataArray, m_AppConfig);
            task_9600_server.start();
            */
        }
        {
            FBS9600S_ServerSocket_Thread task_9600s_server = new FBS9600S_ServerSocket_Thread(GB_MysqlConnPool, GB_DataArray);
            task_9600s_server.start();
        }
        {
            BattDataTestPro_Thread batt_test 
                = new BattDataTestPro_Thread(GB_MysqlConnPool, GB_App_Param, m_AppConfig, GB_DataArray);
            batt_test.start();
        }
        
        //¸üÐÂÒÔ¼°´´½¨tb_BattResData_id±í ÒÔ¼°´´½¨tb_battresdata_inf±íºÍÌí¼ÓÊý¾Ý
        if(true == m_AppConfig.getBattResStoreFnEn()) 
        {
            BattResStorePro_Thread res_pro = new BattResStorePro_Thread(GB_MysqlConnPool, m_AppConfig, GB_DataArray);
            res_pro.start();
        }
        /*
        
        if(true == m_AppConfig.getBattAutoStoreFnEn())
        {
            System.out.println("BattAutoStoreFnEn%%%%%%%%%%%%%%%%");
            BattAutoStorePro_Thread auto_save_pro 
            = new BattAutoStorePro_Thread(GB_MysqlConnPool, m_AppConfig, GB_DataArray);
            auto_save_pro.start();
        }
        */
        /*********************************************************************************/
        /*
        try {
            Runtime rt = Runtime.getRuntime();
            Process ps = rt.exec("cmd.exe /c sc config BMS_FBS61850_BATT start= demand");    //ÊÖ¶¯Æô¶¯Ä£Ê½
            ps.waitFor();
            ps = rt.exec("cmd.exe /c net stop BMS_FBS61850_BATT");
            ps.waitFor();
            ps = rt.exec("cmd.exe /c net start BMS_FBS61850_BATT");
            ps.waitFor();
            System.out.println("restart service BMS_FBS61850_BATT done" 
                                + " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            
            ps = rt.exec("cmd.exe /c sc config BMS_FBSDEV_ALARM start= demand");            //ÊÖ¶¯Æô¶¯Ä£Ê½
            ps.waitFor();
            ps = rt.exec("cmd.exe /c net stop BMS_FBSDEV_ALARM");
            ps.waitFor();
            ps = rt.exec("cmd.exe /c net start BMS_FBSDEV_ALARM");
            ps.waitFor();
            System.out.println("restart service BMS_FBSDEV_ALARM done" 
                                + " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            
            ps = rt.exec("cmd.exe /c sc config BMS_FBSDEV_BADBATT start= demand");            //ÊÖ¶¯Æô¶¯Ä£Ê½
            ps.waitFor();
            ps = rt.exec("cmd.exe /c net stop BMS_FBSDEV_BADBATT");
            ps.waitFor();
            ps = rt.exec("cmd.exe /c net start BMS_FBSDEV_BADBATT");
            ps.waitFor();
            System.out.println("restart service BMS_FBSDEV_BADBATT done" 
                                + " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        } catch (IOException | InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        */
        /*********************************************************************************/
        
        FBS9600S_SocketClient_Thread_SQL.updateServerStartInfTo_RamDB_Table(GB_MysqlConnPool,m_VersionNum);
        while(true) {
            try {
                Thread.sleep(2000);
                //System.out.println("getNumBusyConnections: " + GB_MysqlConnPool.getNumBusyConnections());
                //System.out.println("getNumIdleConnections: " + GB_MysqlConnPool.getNumIdleConnections());
                GB_DataArray.checkAndReinitBattGroupData();
                FBS9600S_SocketClient_Thread_SQL.updateServerTimeTo_RamDB_Table(GB_MysqlConnPool);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        /*********************************************************************************/
    }
}