New file |
| | |
| | | package com.fbo2206; |
| | | |
| | | import android.os.Looper; |
| | | import android.os.Message; |
| | | |
| | | import com.comm.ServiceModel; |
| | | import com.fbs9100.ComFn; |
| | | import com.fbs9100.Ecb_Aes; |
| | | import com.fbs9100.FBS_CapState; |
| | | import com.fbs9100.FBS_ChargeState; |
| | | import com.fbs9100.FBS_Cmd; |
| | | import com.fbs9100.FBS_ComBase; |
| | | import com.fbs9100.FBS_ComBuf; |
| | | import com.fbs9100.FBS_ParamBatt; |
| | | import com.fbs9100.FBS_ParamCharge; |
| | | import com.fbs9100.FBS_ParamDischarge; |
| | | import com.fbs9100.FBS_ParamSystem; |
| | | import com.fbs9100.FBS_ResCapData; |
| | | import com.fbs9100.FBS_ResState; |
| | | import com.fbs9100.FBS_VCData; |
| | | import com.google.gson.Gson; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.Serializable; |
| | | import java.net.Socket; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.util.Date; |
| | | import com.fbo2206.FBO_ParamDischarge; |
| | | import com.fbo2206.FBO_ReadData; |
| | | import com.fbs9100.ComFn; |
| | | import com.fbs9100.Ecb_Aes; |
| | | import com.fbs9100.FBS_CapState; |
| | | import com.fbs9100.FBS_ChargeState; |
| | | import com.fbs9100.FBS_Cmd; |
| | | import com.fbs9100.FBS_ComBase; |
| | | import com.fbs9100.FBS_ComBuf; |
| | | import com.fbs9100.FBS_ParamBatt; |
| | | import com.fbs9100.FBS_ParamCharge; |
| | | import com.fbs9100.FBS_ParamDischarge; |
| | | import com.fbs9100.FBS_ParamSystem; |
| | | import com.fbs9100.FBS_ResCapData; |
| | | import com.fbs9100.FBS_ResState; |
| | | import com.fbs9100.FBS_VCData; |
| | | import com.google.gson.Gson; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.Serializable; |
| | | import java.net.Socket; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.util.Date; |
| | | import android.os.Handler; |
| | | import android.util.Log; |
| | | |
| | | |
| | | /** |
| | | * Created by LiJun on 2019-04-28. |
| | | */ |
| | | |
| | | public class MySocketClientThread extends Thread implements Serializable |
| | | { |
| | | |
| | | private FBS_Cmd m_FBS_Cmd = new FBS_Cmd(); |
| | | private FBS_VCData m_FBS_VCData = new FBS_VCData(); |
| | | private FBS_ParamBatt m_FBS_BattParam = new FBS_ParamBatt(); |
| | | private FBS_ParamSystem m_FBS_SystemParam = new FBS_ParamSystem(); |
| | | private FBS_ParamDischarge m_FBS_DiscParam = new FBS_ParamDischarge(); |
| | | private FBS_ParamCharge m_FBS_ChargeParam = new FBS_ParamCharge(); |
| | | private FBS_ResState m_ResTestState = new FBS_ResState(); |
| | | private FBS_CapState m_CapTestState = new FBS_CapState(); |
| | | private FBS_ChargeState m_ChrTestState = new FBS_ChargeState(); |
| | | |
| | | public FBO_ParamDischarge fbo_DiscParam = new FBO_ParamDischarge(); |
| | | public FBO_ReadData fbo_ReadData = new FBO_ReadData(); |
| | | |
| | | |
| | | private FBS_ResCapData m_FBS_BaseData = new FBS_ResCapData(); //单体基础数据 |
| | | private FBS_ResCapData m_FBS_ResCapData = new FBS_ResCapData(); //单体内阻数据 |
| | | private FBS_ResCapData m_FBS_TmpCapData = new FBS_ResCapData(); //单体温度数据 |
| | | |
| | | private static final String TAG = "SocketClient_Thread"; |
| | | |
| | | private ServiceModel revicemodel; |
| | | private ServiceModel returnmodel; |
| | | |
| | | public static String server_ip = "127.0.0.1"; //设备iP |
| | | public static int server_port = 9006; //设备监听断开 |
| | | |
| | | private ByteBuffer sendByteBuffer = ByteBuffer.allocate(0); |
| | | |
| | | |
| | | private ByteBuffer bytebuffer_for_socket_RX = ByteBuffer.allocate(1500); |
| | | private boolean thread_run_flag = true; |
| | | |
| | | public static Socket socket; |
| | | |
| | | public static Date lastConTime = new Date(); |
| | | |
| | | private static volatile com.comm.MyWebSocketTestThread client = null; |
| | | |
| | | public Handler mHandler = null; |
| | | /*********************************************************************************************/ |
| | | public MySocketClientThread() { |
| | | //initConnectDevice(); |
| | | } |
| | | |
| | | /*public static SerialPortSocketClient createSerialPortSocketClient(){ |
| | | if(client == null){ |
| | | synchronized (SerialPortSocketClient.class) { |
| | | if(client == null){ |
| | | client = new SerialPortSocketClient(); |
| | | } |
| | | } |
| | | } |
| | | return client; |
| | | }*/ |
| | | |
| | | /*********************************************************************************************/ |
| | | public void run() |
| | | { |
| | | |
| | | //初始化消息循环队列,需要在Handler创建之前 |
| | | Looper.prepare(); |
| | | |
| | | mHandler = new Handler() |
| | | { |
| | | public void handleMessage(Message msg) |
| | | { |
| | | ServiceModel model = (ServiceModel)msg.obj; |
| | | Log.e(TAG, "handleMessage: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" +model); |
| | | try |
| | | { |
| | | if(null != model.handler) |
| | | { |
| | | ServiceModel remodel = new ServiceModel(); |
| | | |
| | | if(true == SocketComm(model.cmd, (ByteBuffer)(model.createByteBuffer()), remodel)) |
| | | { |
| | | remodel.cmd = m_FBS_Cmd.CMD; |
| | | //--------------- 新建消息与句柄 ----------------- |
| | | Handler handler = model.handler; |
| | | Message toMain = handler.obtainMessage(); |
| | | toMain.obj = remodel; |
| | | handler.sendMessage(toMain); |
| | | //----------------------------------------------- |
| | | sleep(100); |
| | | }else{ |
| | | remodel.cmd = model.cmd; |
| | | //--------------- 新建消息与句柄 ----------------- |
| | | Handler handler = model.handler; |
| | | Message toMain = handler.obtainMessage(); |
| | | toMain.obj = remodel; |
| | | handler.sendMessage(toMain); |
| | | } |
| | | } |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }; |
| | | //启动子线程消息循环队列 |
| | | Looper.loop(); |
| | | } |
| | | /*********************************************************************************************/ |
| | | /* |
| | | public boolean isConnect(Context context) |
| | | { |
| | | try |
| | | { |
| | | ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | if (connectivity != null) |
| | | { |
| | | // 获取网络连接管理的对象 |
| | | NetworkInfo info = connectivity.getActiveNetworkInfo(); |
| | | if ((info != null) && info.isConnected()) |
| | | { |
| | | // 判断当前网络是否已经连接 |
| | | if(info.getState() == NetworkInfo.State.CONNECTED) |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Log.v("error",e.toString()); |
| | | } |
| | | return false; |
| | | } |
| | | */ |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 向指定的socket通道发送数据,以及接收数据 |
| | | * @return |
| | | */ |
| | | |
| | | public boolean SocketComm(int cmd,ByteBuffer byteBuffer,ServiceModel model) |
| | | { |
| | | boolean res_t = false; |
| | | InputStream in = null; |
| | | OutputStream out = null; |
| | | try |
| | | { |
| | | |
| | | Thread.sleep(2000); |
| | | socket = new Socket(server_ip, server_port); |
| | | |
| | | if(this.socket != null) |
| | | { |
| | | in = this.socket.getInputStream(); |
| | | out = this.socket.getOutputStream(); |
| | | //----------------- clear rx buff for tcp resend packet ----------------// |
| | | byte[] rx_buf_t = new byte[1024]; |
| | | |
| | | //----------------------------------------------------------------------// |
| | | bytebuffer_for_socket_RX.order(ByteOrder.LITTLE_ENDIAN); |
| | | bytebuffer_for_socket_RX.clear(); |
| | | //--------------------- socket write -----------------------------------// |
| | | //--------------------- socket write -----------------------------------// |
| | | boolean aes_en = false; |
| | | byte[] plain_tx_t = makeCommBuf(cmd, byteBuffer, aes_en); |
| | | byte[] cipher_tx_t = new byte[plain_tx_t.length]; |
| | | Ecb_Aes my_aes = new Ecb_Aes(); |
| | | my_aes.ecb_encrypt(plain_tx_t, cipher_tx_t, plain_tx_t.length); |
| | | Date d1 = new Date(); |
| | | //=====================================================================// |
| | | /* |
| | | for(int n=0; n<3; n++) { |
| | | out.write(b); |
| | | out.flush(); |
| | | //-----------------------------------------------------------------// |
| | | try { |
| | | while(true) { |
| | | int rx_len_t = in.read(rx_buf_t); |
| | | if(rx_len_t > 0) { |
| | | if((bytebuffer_for_socket_RX.position()+rx_len_t) |
| | | < (bytebuffer_for_socket_RX.capacity()-16)) { |
| | | |
| | | bytebuffer_for_socket_RX.put(rx_buf_t, 0, rx_len_t); |
| | | } |
| | | } |
| | | if(bytebuffer_for_socket_RX.position() > 8) { |
| | | break; |
| | | } |
| | | } |
| | | } catch (SocketTimeoutException soe) { |
| | | //soe.printStackTrace(); |
| | | } |
| | | //-----------------------------------------------------------------// |
| | | } |
| | | //=====================================================================// |
| | | */ |
| | | int rx_read_time_out = 0; |
| | | //int rx_len = 0; |
| | | System.out.println("数据长度" + plain_tx_t.length + "\t发送数据:" + ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length)); |
| | | out.write(plain_tx_t); |
| | | out.flush(); |
| | | while(true) { |
| | | if(in.available() > 0) { |
| | | rx_read_time_out = 0; |
| | | int rx_len_t = in.read(rx_buf_t); |
| | | if((bytebuffer_for_socket_RX.position()+rx_len_t) |
| | | < (bytebuffer_for_socket_RX.capacity()-1)) { |
| | | bytebuffer_for_socket_RX.put(rx_buf_t, 0, rx_len_t); |
| | | } |
| | | //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)){ |
| | | // res = true; |
| | | break; |
| | | } |
| | | if(rx_read_time_out > 220) { |
| | | break; |
| | | } |
| | | } |
| | | Thread.sleep(10); |
| | | } |
| | | |
| | | 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 |
| | | + " d2-d1:" + (comm_tms)+"ms" |
| | | + " rx_len:" + bytebuffer_for_socket_RX.limit() |
| | | + " tx_count:" + m_FBS_VCData.m_SysState.CommCount |
| | | + " rx_err_sum:" + m_FBS_VCData.m_SysState.ErrCommCount |
| | | + " rx_err_count:" + rx_errcount_for_live_of_thread |
| | | + Com.getNowTimeWithAt()); |
| | | */ |
| | | byte[] cipher_buf = new byte[bytebuffer_for_socket_RX.limit()]; |
| | | byte[] plain_buf = new byte[bytebuffer_for_socket_RX.limit()]; |
| | | bytebuffer_for_socket_RX.get(cipher_buf); |
| | | my_aes.ecb_decrypt(cipher_buf, plain_buf, cipher_buf.length); |
| | | |
| | | System.err.println("数据长度"+cipher_buf.length+"\t返回数据:"+ComFn.bytesToHexString(cipher_buf, cipher_buf.length)); |
| | | //Log.e(TAG, "SocketComm: "+ComFn.bytesToHexString(plain_buf, plain_buf.length)); |
| | | if(true == getDataFromCommBuf(cipher_buf,model)) { |
| | | res_t = true; |
| | | /* |
| | | System.err.println(ComFn.bytesToHexString(buffer, buffer.length)); |
| | | System.err.println(this.getName() + " DevId: " + m_StatAndParam.dev_id |
| | | + "---- cmd:" + cmd + " RxLen: " + buffer.length |
| | | + " 通信失败" + Com.getNowTimeWithAt()); |
| | | */ |
| | | model.code = 1; |
| | | } else { |
| | | res_t = false; |
| | | model.code = 0; |
| | | } |
| | | } else { |
| | | //System.out.println(this.getName() + "-------socket 异常关闭-------" + Com.getNowTimeWithAt()); |
| | | thread_run_flag = false; |
| | | } |
| | | } catch (IOException | InterruptedException e) { |
| | | thread_run_flag = false; |
| | | } finally { |
| | | if(in != null) { |
| | | try { |
| | | in.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if(out != null) { |
| | | try { |
| | | out.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if(socket != null){ |
| | | try { |
| | | socket.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return res_t; |
| | | } |
| | | |
| | | |
| | | /*********************************************************************************************/ |
| | | // @SuppressWarnings("finally") |
| | | // public boolean SocketComm1(int cmd, ByteBuffer bf, MyWebSocketTestThread.ServiceModel msgobj) throws InterruptedException |
| | | // { |
| | | // boolean res = false; |
| | | // try |
| | | // { |
| | | // //Socket socket = new Socket(); |
| | | // //socket.connect(new InetSocketAddress("192.168.1.48", 9001), 200); |
| | | // |
| | | // if(this.socket != null) |
| | | // { |
| | | // InputStream in = socket.getInputStream(); |
| | | // OutputStream out = socket.getOutputStream(); |
| | | // |
| | | // out.write(makeCommBuf(cmd, bf,false)); |
| | | // |
| | | // for(int n=0; n<10; n++) |
| | | // { |
| | | // sleep(10); |
| | | // int len1 = in.available(); |
| | | // if(len1 <= 0) |
| | | // continue; |
| | | // |
| | | // sleep(10); |
| | | // |
| | | // if(in.available() == len1) |
| | | // break; |
| | | // } |
| | | // |
| | | // byte[] buffer = new byte[in.available()]; |
| | | // in.read(buffer); |
| | | // |
| | | // msgobj.msg = getDataFromCommBuf(buffer); |
| | | // |
| | | // in.close(); |
| | | // socket.close(); |
| | | // res = true; |
| | | // } |
| | | // } |
| | | // catch (UnknownHostException e) |
| | | // { |
| | | // //e.printStackTrace(); |
| | | // msgobj.msg = e.getMessage(); |
| | | // } |
| | | // catch (IOException e) |
| | | // { |
| | | // //e.printStackTrace(); |
| | | // msgobj.msg = e.getMessage(); |
| | | // } |
| | | // finally |
| | | // { |
| | | // return res; |
| | | // } |
| | | // } |
| | | /*********************************************************************************************/ |
| | | |
| | | |
| | | |
| | | |
| | | /*********************************************************************************************/ |
| | | public byte[] makeCommBuf(final int cmd, ByteBuffer bf, boolean aes_en) |
| | | { |
| | | ByteBuffer bbf = FBS_ComBuf.makeFbs9100CommBuf(0xFF, cmd, bf, aes_en); |
| | | byte byte_rest[] = new byte[bbf.limit()]; |
| | | bbf.get(byte_rest); |
| | | return byte_rest; |
| | | } |
| | | /*********************************************************************************************/ |
| | | public Boolean getDataFromCommBuf(final byte[] bytes,ServiceModel model) |
| | | { |
| | | boolean isSuccess = false; |
| | | ByteBuffer bf = ByteBuffer.allocate(bytes.length); |
| | | bf.order(ByteOrder.LITTLE_ENDIAN); |
| | | bf.put(bytes); |
| | | bf.flip(); |
| | | |
| | | String msg = ""; |
| | | if(true == m_FBS_Cmd.putByteBuffer(bf)) |
| | | { |
| | | lastConTime = new Date(); |
| | | |
| | | //------------------- 开始通讯 -------------------- |
| | | if(FBS_ComBase.CMD_STARTCNNECT == m_FBS_Cmd.CMD |
| | | && FBS_ComBase.DataReturn_Successs == m_FBS_Cmd.RES_Index |
| | | ) { |
| | | model.msg = "Connect Device Success !!!"; |
| | | isSuccess = true; |
| | | } |
| | | //------------------- 读取FBS9100电压电流数据 -------------------- |
| | | else if(FBS_ComBase.CMD_GetVIData == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == fbo_ReadData.putByteBuffer(bf)) { |
| | | System.out.println("读取实时数据成功:"+fbo_ReadData); |
| | | model.data = fbo_ReadData; |
| | | model.msg = "Get realdata from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | /*if(true == m_FBS_VCData.m_SysState.putByteBuffer(bf)) |
| | | { |
| | | if(true == m_FBS_VCData.putByteBuffer(bf)){ |
| | | returnmodel.data = m_FBS_VCData; |
| | | returnmodel.msg = "Get data from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | }*/ |
| | | } |
| | | //------------------- 读取FBS9100内阻测试状态 ----------------------- |
| | | if(FBS_ComBase.CMD_GetResTestState == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_ResTestState.putByteBuffer(bf)) { |
| | | model.data = m_ResTestState; |
| | | model.msg = "Get ResTest State from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100容量测试状态 ----------------------- |
| | | if(FBS_ComBase.CMD_GetDischargeState == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_CapTestState.putByteBuffer(bf)) { |
| | | model.msg = "Get CapTest State from FBS9100 OK!!!"; |
| | | model.data = m_CapTestState; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100充电测试状态 ----------------------- |
| | | if(FBS_ComBase.CMD_GetChargeState == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_ChrTestState.putByteBuffer(bf)) { |
| | | model.msg = "Get ChrTest State from FBS9100 OK!!!"; |
| | | model.data = m_ChrTestState; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100电池参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_GetBattParam == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_FBS_BattParam.putByteBuffer(bf)) { |
| | | model.msg = "Get battparam from FBS9100 OK!!!"; |
| | | model.data = m_FBS_BattParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 设置FBS9100电池参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_SetBattParam == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_FBS_BattParam.putByteBuffer(bf)) { |
| | | model.msg = "Set battparam to FBS9100 OK!!!"; |
| | | model.data = m_FBS_BattParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100系统参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_GetSYSSetParam == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_FBS_SystemParam.putByteBuffer(bf)) { |
| | | model.msg = "Get sysparam from FBS9100 OK!!!"; |
| | | model.data = m_FBS_SystemParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 设置FBS9100系统参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_SetSYSSetParam == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_FBS_SystemParam.putByteBuffer(bf)) { |
| | | model.msg = "Set sysparam to FBS9100 OK!!!"; |
| | | model.data = m_FBS_SystemParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100放电参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_GetDischargeParm == m_FBS_Cmd.CMD) |
| | | { |
| | | //System.out.println("获取FBO参数"); |
| | | if(true == fbo_DiscParam.putByteBuffer(bf)){ |
| | | System.out.println("读取放电参数成功" + fbo_DiscParam); |
| | | model.msg = "Get DischargeParm from FBS9100S OK!!!"; |
| | | model.data = fbo_DiscParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 设置FBS9100放电参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_SetDischargeParm == m_FBS_Cmd.CMD) |
| | | { |
| | | System.out.println("设置放电参数"); |
| | | if(FBS_ComBase.DataReturn_Successs == m_FBS_Cmd.RES_Index){ |
| | | System.out.println("设置放电参数成功:" + fbo_DiscParam); |
| | | model.msg = "Set DischargeParam to FBS9100 OK!!!"; |
| | | model.data = fbo_DiscParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100充电参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_GetChargeParm == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_FBS_ChargeParam.putByteBuffer(bf)){ |
| | | model.msg = "Get ChargeParam from FBS9100 OK!!!"; |
| | | model.data = m_FBS_ChargeParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 设置FBS9100充电参数 ------------------------- |
| | | else if(FBS_ComBase.CMD_SetChargeParm == m_FBS_Cmd.CMD) |
| | | { |
| | | if(true == m_FBS_ChargeParam.putByteBuffer(bf)){ |
| | | model.msg = "Set ChargeParam to FBS9100 OK!!!"; |
| | | model.data = m_FBS_ChargeParam; |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | //------------------- 读取FBS9100内阻温度测试数据 ------------------ |
| | | else if((FBS_ComBase.CMD_GetMonomerRES == m_FBS_Cmd.CMD) |
| | | ||(FBS_ComBase.CMD_GetMonomerTMP == m_FBS_Cmd.CMD) |
| | | /*||(FBS_ComBase.CMD_GetMonomerCAP == m_FBS_Cmd.CMD) |
| | | ||(FBS_ComBase.CMD_GetMonomerChargeCAP == m_FBS_Cmd.CMD)*/) |
| | | { |
| | | if(true == m_FBS_BaseData.putByteBuffer(bf, m_FBS_Cmd.CMD)) { |
| | | //getFBS9100MonResData(m_FBS_Cmd.CMD, m_FBS_ResCapData); |
| | | model.msg = "Get MonomerRES or MonomerTMP from FBS9100 OK!!!"; //获取单体内阻和单体温度数据成功 |
| | | model.data = m_FBS_BaseData; |
| | | isSuccess = true; |
| | | } |
| | | |
| | | } |
| | | //------------------- 启动内阻测试启动核容测试成功 --------------------------------------------- |
| | | else if((FBS_ComBase.CMD_StartDischarge == m_FBS_Cmd.CMD) |
| | | || (FBS_ComBase.CMD_StartResDischarge == m_FBS_Cmd.CMD) |
| | | &&(FBS_ComBase.DataReturn_Successs == m_FBS_Cmd.RES_Index) |
| | | ){ |
| | | System.out.println("启动放电成功"); |
| | | model.msg = "Start MonomerRESTest or MonomerCapTest from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | //------------------- 启动充电测试 --------------------------------------------- |
| | | else if(FBS_ComBase.CMD_StartCharge == m_FBS_Cmd.CMD |
| | | && (FBS_ComBase.DataReturn_Successs == m_FBS_Cmd.RES_Index) |
| | | ){ |
| | | System.out.println("启动充电成功"); |
| | | model.msg = "Start MonomerChargeTest from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | //-------------------- 停止测试成功 ----------------------------------------- |
| | | else if(FBS_ComBase.CMD_Stop == m_FBS_Cmd.CMD |
| | | && (FBS_ComBase.DataReturn_Successs == m_FBS_Cmd.RES_Index) |
| | | ){ |
| | | System.out.println("停止成功"); |
| | | model.msg = "Stop MonomerCapTest from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | //-------------------- 暂停测试成功 ----------------------------------------- |
| | | else if(FBS_ComBase.CMD_Suspended == m_FBS_Cmd.CMD |
| | | && (FBS_ComBase.DataReturn_Successs == m_FBS_Cmd.RES_Index) |
| | | ){ |
| | | System.out.println("暂停成功"); |
| | | model.msg = "Suspended MonomerCapTest from FBS9100 OK!!!"; |
| | | isSuccess = true; |
| | | } |
| | | |
| | | } |
| | | return isSuccess; |
| | | } |
| | | |
| | | /** |
| | | * 根据指定的命令给制定的但他数据赋值 |
| | | * @param cmd |
| | | * @param res_data |
| | | */ |
| | | private void getFBS9100MonResData(int cmd, FBS_ResCapData res_data) |
| | | { |
| | | int mon_index = 0; |
| | | if(null != m_FBS_BaseData) |
| | | { |
| | | if(FBS_ComBase.CMD_GetMonomerRES == cmd) { |
| | | m_FBS_ResCapData = m_FBS_BaseData.clone(); |
| | | //Log.d(TAG, "getFBS9100MonResData: 获取单体内阻数据成功。。。"); |
| | | } else if(FBS_ComBase.CMD_GetMonomerTMP == cmd) { |
| | | m_FBS_TmpCapData = m_FBS_BaseData.clone(); |
| | | //Log.d(TAG, "getFBS9100MonResData: 获取单体内阻数据成功。。。"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | public FBS_ResCapData getM_FBS_ResCapData() { |
| | | return m_FBS_ResCapData; |
| | | } |
| | | |
| | | public FBS_ResCapData getM_FBS_TmpCapData() { |
| | | return m_FBS_TmpCapData; |
| | | } |
| | | |
| | | /** |
| | | * js前台接收返回数据 |
| | | * @return |
| | | */ |
| | | public String getServiceModel() { |
| | | Gson gson = new Gson(); |
| | | return gson.toJson(returnmodel); |
| | | } |
| | | |
| | | /** |
| | | * js前台传入的数据 |
| | | * @param json |
| | | */ |
| | | public void setServiceModel(String json) { |
| | | Gson gson = new Gson(); |
| | | revicemodel = gson.fromJson(json, ServiceModel.class); |
| | | |
| | | sendByteBuffer = ByteBuffer.allocate(0); |
| | | if(revicemodel.cmd == FBS_ComBase.CMD_SetDischargeParm) { |
| | | //设置放电参数时 |
| | | FBO_ParamDischarge param = (FBO_ParamDischarge)revicemodel.data; |
| | | sendByteBuffer = param.getByteBuffer(); |
| | | } |
| | | } |
| | | |
| | | public void setFBO2206Param(com.comm.MyWebSocketTestThread therad) { |
| | | FBO_ParamDischarge param = therad.fbo_DiscParam; |
| | | |
| | | param.test_mode = 1; //放电模式 0-离线放电 1在线放电 |
| | | param.acstop_op = 1; //停电处理 0-停止放电 1继续放电 |
| | | param.nominal_cap = 300; //标称容量 |
| | | param.hourly_rate = 10 ; //小时率 |
| | | param.preset_cur = 20; //预放电流 (0.1) |
| | | param.preset_cap = 50; //预放容量 |
| | | param.preset_time = 60; //预放时间(分钟) |
| | | param.mon_lower = 10.8; //单体下限 (0.01) |
| | | param.group_lower = 45; //组端下限 (0.1) |
| | | param.mon_number = 12; //单体数量 |
| | | param.group_number = 4; //电池组数 |
| | | param.lower_number = 5; //单体下限个数 |
| | | param.mon_vol = 12; //标称单体电压 |
| | | param.booster_ceiling = 56; //升压上限 |
| | | param.charge_limit = 20; //充电电流 (0.1) |
| | | param.onlinevol_lowlimit = 60 ; //在线阀值 (0.1) |
| | | param.battName = "新建"; //电池组名称 |
| | | |
| | | sendByteBuffer = fbo_DiscParam.getByteBuffer(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 修改服务器的ip和通讯的端口号 |
| | | * @param server_ip 服务器IP |
| | | * @param server_port 服务器端口号 |
| | | */ |
| | | public void setServerParam(String server_ip,int server_port){ |
| | | this.server_ip = server_ip; |
| | | this.server_port = server_port; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | |
| | | |
| | | |
| | | com.comm.MyWebSocketTestThread thread = new com.comm.MyWebSocketTestThread(); |
| | | ServiceModel model = new ServiceModel(); |
| | | //thread.server_ip = "192.168.1.126"; |
| | | //thread.server_port = 9600; |
| | | |
| | | //thread.revicemodel = model; |
| | | model.cmd = FBS_ComBase.CMD_STARTCNNECT; //开始通讯 |
| | | thread.SocketComm(); |
| | | |
| | | |
| | | //thread.setFBO2206Param(thread); |
| | | //model.cmd = FBS_ComBase.CMD_SetDischargeParm; //设置放电参数 |
| | | |
| | | |
| | | model.cmd = FBS_ComBase.CMD_GetDischargeParm; //获取放电参数 |
| | | |
| | | |
| | | model.cmd = FBS_ComBase.CMD_GetVIData; //获取电池组状态 |
| | | |
| | | |
| | | |
| | | thread.SocketComm(); |
| | | |
| | | |
| | | } |
| | | /*********************************************************************************************/ |
| | | /********************************* end of file SocketClient1.java *************************************/ |
| | | } |