whyclj
2019-10-24 c251059cae817966089ffed0226123e39d0113c6
platforms/android/app/src/main/java/com/socket/MySocketClientThread.java
@@ -11,6 +11,7 @@
import com.mode.BattTestRtData;
import com.mode.DeviceState;
import com.mode.ServiceModel;
import com.service.MyInteractionService;
import com.util.Com;
import com.util.ComFn;
import com.util.Ecb_Aes;
@@ -52,6 +53,7 @@
    ServiceModel returnmodel = new ServiceModel();
    private static MySocketClientThread thread ;
    public static MyInteractionService service = null;
    private MySocketClientThread(String server_ip){
        this.server_ip = server_ip;
@@ -61,10 +63,16 @@
    }
    public static MySocketClientThread createThread(String server_ip){
    public static MySocketClientThread createThread(String server_ip, MyInteractionService service){
        MySocketClientThread.service = service;
        if(thread == null){
           thread = new MySocketClientThread(server_ip);
        }
        return thread;
    }
    //获取当前正在运行的线程
    public static MySocketClientThread getNowThread(){
        return thread;
    }
@@ -208,11 +216,11 @@
                        //bytebuffer_for_socket_RX.put((byte)in.read());
                    } else {
                        rx_read_time_out++;
                        if((bytebuffer_for_socket_RX.position() >= 8) && (rx_read_time_out>10)){
                        if((bytebuffer_for_socket_RX.position() >= 18) && (rx_read_time_out>10)){
                            //   res = true;
                            break;
                        }
                        if(rx_read_time_out > 220) {
                        if(rx_read_time_out > 300) {
                            break;
                        }
                    }
@@ -256,6 +264,7 @@
                thread_run_flag = false;
            }
        } catch (IOException | InterruptedException e) {
            model.code = 0;
            thread_run_flag = false;
        } finally {
            if(!thread_run_flag){
@@ -499,6 +508,22 @@
                    System.out.println("切换界面成功");
                }
            }
            //---------------------  退出上位机控制   ----------------------------------
            else if(FBS_ComBase.CMD_EXITMACHINECONTROL == m_FBS_Cmd.CMD) {
                if(FBS_ComBase.RETURN_SUCCESS == m_FBS_Cmd.RecState) {
                    isSuccess = true;
                    System.out.println("退出上位机控制");
                }
            }
            //---------------------  控制活化(启动/停止/暂停)   ----------------------------------
            else if(FBS_ComBase.CMD_STARTHHTEST == m_FBS_Cmd.CMD || FBS_ComBase.CMD_PAUSEHHTEST == m_FBS_Cmd.CMD || FBS_ComBase.CMD_STOPHHTEST == m_FBS_Cmd.CMD) {
                if(FBS_ComBase.RETURN_SUCCESS == m_FBS_Cmd.RecState) {
                    isSuccess = true;
                    System.out.println("启动/停止/暂停活化测试成功");
                }
            }
        }
        return isSuccess;
    }
@@ -510,6 +535,7 @@
        }else{
            synchronized (socket){
                if (this.server_ip != null && server_ip.length() > 0){
                    this.server_ip = server_ip;
                    flag = reConnectDevice();
                }
            }
@@ -517,6 +543,17 @@
        return false;
    }
    //关闭socket连接
    public void closeConn(){
        if(this.socket != null){
            try {
                this.socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    //测试当前ip是否可以连接
    public boolean testSockConn(String server_ip){
        boolean flag = false;