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
package com.dec.fbs9100;
 
import java.util.TimeZone;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import com.base.AppConfig;
import com.battdata_rt.BattData_RT_Array;
import com.dec.fbs9100.AppParam;
import com.iedscout.BTS61850_IEDScout_Task_Thread;
 
/**
 *  
 * @author LiJun
 *
 */
public class main_BTS_APP_IEC61850 {
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    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 = 6.109;
    public final static String m_Version = "Welcome To Use BattMonitor_BTS_IEC61850 V" 
                                            + m_VersionNum + " RC_20201003";
    /**************************************************************************/
    /**************************************************************************/
    public static final int DEF_MysqlServerFBS9100S_Port = 3360;
    public static final int DEF_MysqlServer_Port = 5306;
    public static final int DEF_MysqlServerFBS_Port = 5307;
    public static final int DEF_MysqlServerFBO_Port = 5308;
    public static final int DEF_MysqlServerBPM7100_Port = 5309;
    
    public static final int DEF_Socket_Server_Port = 1982;
    public static final int DEF_Socket_ServerFBS_Port = 1992;
    public static final int DEF_Socket_ServerFBO_Port = 2002;
    public static final int DEF_Socket_ServerBPM7100_Port = 2001;
    
    public static final int DEF_Socket_Server_FBI_Port = 1983;
    public static final int DEF_Socket_Server_FBIFBS_Port = 1993;
    public static final int DEF_Socket_Server_FBIFBO_Port = 2003;
    
    public static final int DEF_Socket_Server_IDCE8200_Port = 8200;
    public static final int DEF_Socket_Server_IDCE8200FBS_Port = 8210;
    public static final int DEF_Socket_Server_IDCE8200FBO_Port = 8220;
    
    public static final int DEF_Socket_Server_MOBILE_Port = 2016;
    public static final int DEF_Socket_Server_MOBILEFBS_Port = 2026;
    public static final int DEF_Socket_Server_MOBILEFBO_Port = 2036;
    public static final int DEF_Socket_Server_MOBILEBPM7100_Port = 2037;
    
    public static final int DEF_FTP_Server_Port = 2110;
    public static final int DEF_FTP_ServerFBS_Port = 2116;
    public static final int DEF_FTP_ServerFBO_Port = 2122;
    public static final int DEF_FTP_ServerBPM7100_Port = 2123;
    
    public static int MysqlServer_Port = DEF_MysqlServer_Port;
    public static int Socket_Server_Port = DEF_Socket_Server_Port;
    public static int Socket_Server_FBI_Port = DEF_Socket_Server_FBI_Port;
    public static int Socket_Server_IDCE8200_Port = DEF_Socket_Server_IDCE8200_Port;
    public static int Socket_Server_Mobile_Port = DEF_Socket_Server_MOBILE_Port;
    public static int FTP_Server_Port = DEF_FTP_Server_Port;
    
    private static AppConfig m_AppConfig;
    
    private static MysqlConnPool GB_MysqlConnPool;
    private static BattData_RT_Array GB_DataArray;
    public static AppParam GB_App_Param;
    
    private static BTS61850_Task_Thread GB_task_61850;
    
    public static Logger logger;
    /*********************************************************************************************/
    /*********************************************************************************************/
    static {
        System.setProperty("log4j.configurationFile", "log4j2_batt_61850_dev_x64.xml");
    //    System.setProperty("contextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
    }
    /*********************************************************************************************/
    /*********************************************************************************************/
    public static void main(String[] args) {
        String ver = m_Version;
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        logger = LogManager.getLogger(main_BTS_APP_IEC61850.class);
 
        logger.info("/****************************************************************");
        logger.info("*****************************************************************");
        logger.info("****************************************************************/");
        logger.info(ver);
        logger.info("Server Started ...");
        /*
        logger.debug("This is debug.");
        logger.info("This is an info.");
        logger.warn("This is a warning.");
        logger.error("This is an error.");
        logger.fatal("This is a fatal error.");
        */
        
        m_AppConfig = new AppConfig();
        do {
            GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), DEF_MysqlServerFBS9100S_Port, 
                                                    m_AppConfig.getMysqlConnCountMax());
            if(null == GB_MysqlConnPool) {
                logger.info("GB_MysqlConnPool connect to sql server timeout, continue...");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    logger.error(e.toString(), e);
                }
            } else {
                break;
            }
        } while (true);
        
        GB_App_Param = new AppParam(GB_MysqlConnPool);
        //GB_App_Param.checkAndCreateLog4jTable();
        
        GB_DataArray = new BattData_RT_Array(m_AppConfig, GB_App_Param, GB_MysqlConnPool);
        GB_DataArray.initBattDataRT_Inf(m_VersionNum);
        
        //更新线程启动时间
        FBS9100_Task_Thread_SQL.updateAppStartTime(GB_MysqlConnPool,m_VersionNum);
        
        {
            GB_task_61850 = new BTS61850_Task_Thread(GB_MysqlConnPool, GB_DataArray, m_AppConfig);
            GB_task_61850.start();
        }
        
        {
            BattDataTestPro_Thread batt_test = new BattDataTestPro_Thread(GB_App_Param, m_AppConfig, GB_DataArray);
            batt_test.start();
        }
        
        /************************************ 记录历史实时数据 ***************************************************************/
        {
            BattRealDataPro_Thread batt_realdata = new BattRealDataPro_Thread(GB_MysqlConnPool, GB_App_Param, GB_DataArray);
            batt_realdata.start();
        }
        /*********************************************************************************/
        /************************************ 新增IED简单调试工具 *********************************************/
        {
            BTS61850_IEDScout_Task_Thread ied_thread = new BTS61850_IEDScout_Task_Thread(GB_MysqlConnPool);
            ied_thread.start();
        }
        /*********************************************************************************/
        while(true)
        {
            try {
                Thread.sleep(1000);
                FBS9100_Task_Thread_SQL.runinsertime(GB_MysqlConnPool);
                
                Thread.sleep(2000);
                if(true == GB_DataArray.checkAndReinitBattGroupData()) {
                    GB_task_61850.reInitClient();
                    logger.warn("GB_task_61850.reInitClient()");
                }
                
                Thread.sleep(2000);
                /******************************************
                GB_App_Param.checkAndDeleteLog4jOldData();
                ******************************************/
            } catch (Exception e) {
                logger.error(e.toString(), e);
            }
        }
        /*********************************************************************************/
    }
}