/********************************* head of file SocketClient.java ***********************************/
|
package com.dev.fbs9100;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.Socket;
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Date;
|
|
import com.base.Com;
|
import com.battdata_rt.BattData_RT;
|
import com.battdata_rt.BattData_RT_Array;
|
import com.dev.fbs9100.FBS9100_CapState;
|
import com.dev.fbs9100.FBS9100_ChargeState;
|
import com.dev.fbs9100.FBS9100_Cmd;
|
import com.dev.fbs9100.FBS9100_ComBase;
|
import com.dev.fbs9100.FBS9100_ComBuf;
|
import com.dev.fbs9100.FBS9100_ParamBatt;
|
import com.dev.fbs9100.FBS9100_ParamCharge;
|
import com.dev.fbs9100.FBS9100_ParamSystem;
|
import com.dev.fbs9100.FBS9100_ResCapData;
|
import com.dev.fbs9100.FBS9100_ResState;
|
import com.dev.fbs9100.FBS9100_VCData;
|
import com.dev.fbs9600.FBS9600_CommData;
|
import com.sql.MysqlConnPool;
|
|
/****************************************************************************************************/
|
public class FBS9100S_SocketClient2 extends Thread
|
{
|
private FBS9100_Cmd m_FBS_Cmd = new FBS9100_Cmd();
|
|
private FBS9100_ParamBatt m_FBS_BattParam = null;
|
private FBS9100_ParamSystem m_FBS_SystemParam = null;
|
private FBS9100_ParamCharge m_FBS_ChargeParam = null;
|
private FBS9100_ResState m_ResTestState = null;
|
private FBS9100_CapState m_CapTestState = null;
|
private FBS9100_ChargeState m_ChrTestState = null;
|
private FBS9100_ResCapData m_FBS_ResCapData = null;
|
private FBS9100S_DFU m_FBS9100S_DFU = null;
|
|
private FBS9100_StatAndParam m_StatAndParam = null;
|
private BattData_RT[] m_RTData = new BattData_RT[FBS9100_ComBase.BattGroupCountMax];
|
private Socket socket = null;
|
private ByteBuffer bytebuffer_for_socket_RX = ByteBuffer.allocate(1500);
|
//private int m_FBSDevId = 0;
|
private int m_BattMonCount = 0;
|
|
private static final String TAG = "FBS9100S_Thread";
|
private MysqlConnPool m_ConnPool = null;
|
private boolean S_thread_run_flag = true;
|
private int rx_errcount_for_live_of_thread = 0 ; //ÓÃÓÚͳ¼ÆsocketͨÐÅÖеÄÒì³£´ÎÊýͳ¼Æ
|
private BattData_RT_Array AL_RTdata = null;
|
private int DevReadCount = 0;
|
private int DevReadCount_Rate = 1;
|
private int DevReadCount_Rate_CFG = 1;
|
/*********************************************************************************************/
|
public FBS9100S_SocketClient2(MysqlConnPool m_cp, BattData_RT_Array AL_RTdata_t, Socket socket, int comm_rate)
|
{
|
this.m_StatAndParam = new FBS9100_StatAndParam(socket.getInetAddress().getHostAddress(), 0);
|
this.socket = socket;
|
this.m_ConnPool = m_cp;
|
this.AL_RTdata = AL_RTdata_t;
|
|
this.DevReadCount_Rate_CFG = comm_rate;
|
if(this.DevReadCount_Rate_CFG < 1) {
|
this.DevReadCount_Rate_CFG = 1;
|
}
|
if(this.DevReadCount_Rate_CFG > 60) {
|
this.DevReadCount_Rate_CFG = 60;
|
}
|
this.DevReadCount_Rate = this.DevReadCount_Rate_CFG;
|
}
|
|
public FBS9100S_SocketClient2() {
|
// TODO Auto-generated constructor stub
|
}
|
|
/**
|
* ɸѡÉ豸idÊÇ·ñºÏ·¨
|
* @return
|
*/
|
private boolean initFBS9100SComm(BattData_RT_Array m_Data) {
|
boolean reg_in_st = false;
|
for(int cnt=0; cnt<3; cnt++) {
|
try {
|
Thread.sleep(1000);
|
boolean f = SocketComm(FBS9100_ComBase.CMD_GetDeviceInf, ByteBuffer.allocate(0), socket);
|
System.out.println(m_StatAndParam.dev_id+"====="+f);
|
if(((m_StatAndParam.dev_id/1000000) == 910) && f) {
|
for(int i=0; i<m_Data.getItemCount(); i++) {
|
if(m_Data.getItem(i).FBSDeviceId == m_StatAndParam.dev_id){
|
m_StatAndParam.dev_name = m_Data.getItem(i).FBSDeviceName;
|
reg_in_st = true;
|
break;
|
}
|
}
|
} else {
|
System.err.println("FBS9100S_SocketClient2::initFBS9100SComm() ʶ±ð¶þÆÚ FBS9100SÉ豸ʧ°Ü @ "
|
+ Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
reg_in_st = false;
|
}
|
|
if(true == reg_in_st) {
|
break;
|
}
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
}
|
|
return reg_in_st;
|
}
|
/*********************************************************************************************/
|
public void run()
|
{
|
this.setName(TAG + ": " + this.getId());
|
//System.out.println("ʶ±ðµ±Ç°µÄ»úÆ÷ÊÇ·ñÊÇFBS9100SÉ豸");
|
S_thread_run_flag = initFBS9100SComm(AL_RTdata);
|
if(true == S_thread_run_flag) {
|
m_FBS_BattParam = new FBS9100_ParamBatt();
|
m_FBS_SystemParam = new FBS9100_ParamSystem();
|
m_FBS_ChargeParam = new FBS9100_ParamCharge();
|
m_ResTestState = new FBS9100_ResState();
|
m_CapTestState = new FBS9100_CapState();
|
m_ChrTestState = new FBS9100_ChargeState();
|
m_FBS_ResCapData = new FBS9100_ResCapData();
|
|
FBS9100_Task_Thread_SQL.updateFbs9100StateByDev_Id(m_ConnPool, m_StatAndParam);
|
FBS9100_Task_Thread_SQL.updateFbs9100S_DCDC_Data_ByDev_Id(m_ConnPool, m_StatAndParam.m_al_DCDC_Data,
|
m_StatAndParam.dev_id);
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_GetDischargeParmAck;
|
FBS9100_Task_Thread_SQL.updateFbs9100SetParamBydev_id(m_ConnPool, m_StatAndParam);
|
FBS9100_Task_Thread_SQL.updateFbs9100CmccPowerDataByDev_Id(m_ConnPool, m_StatAndParam.m_CMCC_Power, m_StatAndParam.dev_id);
|
m_FBS9100S_DFU = new FBS9100S_DFU(m_ConnPool, m_StatAndParam.dev_id);
|
|
int group_max = FBS9600_CommData.BATT_GROUP_COUNT_MAX;
|
for(int n=0; n < group_max; n++) {
|
m_RTData[n] = null;
|
}
|
|
for(int n=0; n < AL_RTdata.getItemCount(); n++) {
|
if(AL_RTdata.getItem(n).FBSDeviceId == m_StatAndParam.dev_id) {
|
m_RTData[AL_RTdata.getItem(n).GroupIndexInFBSDevice % group_max] = AL_RTdata.getItem(n);
|
m_BattMonCount += AL_RTdata.getItem(n).MonCount;
|
/*BattData_RT_SQL.createBattData_RT_RamDB_Table(m_ConnPool,
|
AL_RTdata.getItem(n).BattGroupId,
|
AL_RTdata.getItem(n).getBattCount());*/
|
}
|
}
|
|
if(m_BattMonCount > (FBS9600_CommData.BATT_MON_COUNT_MAX-120)) {
|
m_BattMonCount = (FBS9600_CommData.BATT_MON_COUNT_MAX-120);
|
}
|
/*
|
System.out.println(this.getName() + " ¶þÆÚ "
|
+ " DevId: " + m_StatAndParam.dev_id + ", DevVer: " + m_StatAndParam.m_DevVersion
|
+ " - FBS9100S_SocketServer For GPRS Thread Started @ "
|
+ Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
*/
|
} else {
|
return;
|
}
|
|
while(S_thread_run_flag)
|
{
|
try {
|
if(m_StatAndParam != null) {
|
//¸ù¾Ý tb_fbs9100_setparam±íÖеÄÊý¾Ý¸øÖ¸¶¨É豸idµÄm_FBS_DiscParam²ÎÊýÉèÖÃÖµ
|
FBS9100_Task_Thread_SQL.queryFbs9100SetParamBydev_id(m_ConnPool, m_StatAndParam);
|
}
|
|
if(FBS9100_ComBase.CMD_NULL == m_StatAndParam.op_cmd)
|
{
|
if(FBS9100_ComBase.CMD_SetDischargeParm == m_StatAndParam.m_FBS_DiscParam.op_cmd) {
|
//System.out.println("ÉèÖ÷ŵç²ÎÊý---------------------------------------------");
|
if(true == SocketComm(FBS9100_ComBase.CMD_SetDischargeParm,
|
m_StatAndParam.m_FBS_DiscParam.getByteBuffer(),socket))
|
{
|
//System.err.println("ÉèÖ÷ŵç²ÎÊý³É¹¦");
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_SetDischargeParmAck;
|
}
|
} else if(FBS9100_ComBase.CMD_Start == m_StatAndParam.m_FBS_DiscParam.op_cmd) {
|
//System.out.println("Æô¶¯²âÊÔ");
|
int cmd = FBS9100_ComBase.CMD_StartDischarge; //Æô¶¯·Åµç²âÊÔ
|
if(cmd != m_StatAndParam.m_FBS_DiscParam.test_cmd) {
|
cmd = FBS9100_ComBase.CMD_StartResDischarge; //Æô¶¯ÄÚ×è²âÊÔ
|
}
|
|
if(true == SocketComm(cmd, ByteBuffer.allocate(0),socket)) {
|
// System.err.println("Æô¶¯²âÊԳɹ¦");
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_StartAck;
|
}
|
} else if(FBS9100_ComBase.CMD_Stop == m_StatAndParam.m_FBS_DiscParam.op_cmd) {
|
//System.out.println("Í£Ö¹²âÊÔ");
|
if(true == SocketComm(FBS9100_ComBase.CMD_Stop, ByteBuffer.allocate(0),socket)) {
|
// System.err.println("Í£Ö¹·Åµç²âÊԳɹ¦");
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_StopAck;
|
}
|
} else if(FBS9100_ComBase.CMD_GetDischargeParm == m_StatAndParam.m_FBS_DiscParam.op_cmd) {
|
//System.out.println("¶ÁÈ¡·Åµç²ÎÊý");
|
if(true == SocketComm( FBS9100_ComBase.CMD_GetDischargeParm , ByteBuffer.allocate(0),socket)) {
|
// System.out.println("¶ÁÈ¡·Åµç²âÊÔ²ÎÊý³É¹¦");
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_GetDischargeParmAck;
|
FBS9100_Task_Thread_SQL.updateFbs9100SetParamBydev_id(m_ConnPool, m_StatAndParam);
|
}
|
}
|
|
FBS9100_Task_Thread_SQL.updateFbs9100SetParamCmdBydev_id(m_ConnPool, m_StatAndParam);
|
}
|
//-----------------------------------------------------------------------------------//
|
sleep(20);
|
//===================================================================================
|
DevReadCount += 1;
|
//-----------------------------------------------------------------------------------//
|
if(0 == (DevReadCount%(6*DevReadCount_Rate))) {
|
SocketComm(FBS9100_ComBase.CMD_GetVIData, ByteBuffer.allocate(0), socket);
|
|
if(m_StatAndParam != null) {
|
FBS9100_Task_Thread_SQL.updateFbs9100StateByDev_Id(m_ConnPool, m_StatAndParam);
|
if(FBS9100_SysState.SYS_STATE_STOPPED != m_StatAndParam.m_FBS_VCData.m_SysState.WorkState) {
|
FBS9100_Task_Thread_SQL.updateFbs9100S_DCDC_Data_ByDev_Id(m_ConnPool,
|
m_StatAndParam.m_al_DCDC_Data,
|
m_StatAndParam.dev_id);
|
}
|
}
|
}
|
//-----------------------------------------------------------------------------------//
|
if(0 == (DevReadCount%4)) {
|
if(true == m_FBS9100S_DFU.check_If_DFU_Is_Eanbled()) {
|
boolean res_t = m_FBS9100S_DFU.runDFU(socket);
|
if(true == res_t) {
|
if((true == m_FBS9100S_DFU.DFU_EN)
|
&& (FBS9100S_DFU_SQL.DFU_STATE_CHECK_OK == m_FBS9100S_DFU.DFU_WR_State)) {
|
if(true == SocketComm(FBS9100_ComBase.CMD_SystemUpdate, ByteBuffer.allocate(0), socket)) {
|
m_FBS9100S_DFU.DFU_EN = false;
|
m_FBS9100S_DFU.DFU_WR_State = FBS9100S_DFU_SQL.DFU_STATE_NULL;
|
FBS9100S_DFU_SQL.updateFbs9100S_DFU_StatByDev_Id(m_ConnPool, m_StatAndParam.dev_id, m_FBS9100S_DFU);
|
//System.out.println(String.format("DevId:%d, DFU Done, FBS9100S_DFU_SQL.updateFbs9100S_DFU_StatByDev_Id",
|
// m_StatAndParam.dev_id));
|
//------- Ö÷¶¯Í˳öµ±Ç°Á¬½Ó,ÒªÇóÔ¶³ÌFBS9100SÖØÐÂÁ¬½Ó½øÀ´½ø¶ø¶ÁÈ¡É豸°æ±¾ºÅ ------
|
S_thread_run_flag = false;
|
//--------------------------------------------------------------------------
|
}
|
}
|
}
|
sleep(20);
|
}
|
}
|
//--------------------------- ¶ÁÈ¡ÔËÓªÉ̵çÁ¿Êý¾Ý ------------------------------------//
|
if(0 == (DevReadCount%(37*DevReadCount_Rate))) {
|
SocketComm(FBS9100_ComBase.CMD_ReadCMCCVolCurr, ByteBuffer.allocate(0) , socket);
|
if(m_StatAndParam != null) {
|
FBS9100_Task_Thread_SQL.updateFbs9100CmccPowerDataByDev_Id(m_ConnPool,
|
m_StatAndParam.m_CMCC_Power,
|
m_StatAndParam.dev_id);
|
}
|
}
|
//--------------------------- ¶ÁÈ¡µ¥ÌåζÈÊý¾Ý --------------------------------------//
|
if(0 == (DevReadCount%(68*DevReadCount_Rate))) {
|
SocketComm(FBS9100_ComBase.CMD_GetMonomerTMP, ByteBuffer.allocate(0) , socket);
|
}
|
//--------------------------- ¶ÁÈ¡µ¥ÌåÄÚ×èÊý¾Ý --------------------------------------//
|
if(0 == (DevReadCount%(99*DevReadCount_Rate))) {
|
SocketComm(FBS9100_ComBase.CMD_GetMonomerRES, ByteBuffer.allocate(0) , socket);
|
}
|
//---------------------------------------------------------------------------------//
|
if(DevReadCount >= (99*DevReadCount_Rate)) {
|
DevReadCount = 0;
|
if(FBS9100_SysState.SYS_STATE_STOPPED == m_StatAndParam.m_FBS_VCData.m_SysState.WorkState) {
|
DevReadCount_Rate = DevReadCount_Rate_CFG;
|
}
|
}
|
//---------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------//
|
/*
|
if(FBS9100_ComBase.BattState_Discharge == m_FBS_VCData.m_SysState.WorkState)
|
{
|
//------------- Èç¹ûÊÇÄÚ×è²âÊÔ,Ôò×Ô¶¯¶Áȡһ´ÎFBS9100É豸ÉϵIJÎÊý -----------//
|
if(FBS9100_ComBase.TestType_RES == m_FBS_VCData.m_SysState.TestType) {
|
if ((FBS9100_ComBase.TestType_RES != m_StatAndParam.test_type)
|
&& (FBS9100_ComBase.CMD_NULL == m_StatAndParam.op_cmd)) {
|
//System.out.println("¶ÁÈ¡·Åµç²ÎÊý $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
|
if(true == SocketComm(FBS9100_ComBase.CMD_GetDischargeParm, ByteBuffer.allocate(0),socket)) {
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_GetDischargeParmAck;
|
|
m_StatAndParam.test_type = FBS9100_ComBase.TestType_RES;
|
}
|
}
|
} else {//------ Èç¹ûÊÇÈÝÁ¿·Åµç²âÊÔ,Ôò×Ô¶¯¶Áȡһ´ÎFBS9100É豸ÉϵIJÎÊý ------//
|
if ((FBS9100_ComBase.TestType_CAP != m_StatAndParam.test_type)
|
&&(FBS9100_ComBase.CMD_NULL == m_StatAndParam.op_cmd)) {
|
//System.out.println("ÈÝÁ¿·Åµç²âÊÔ¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£");
|
if(true == SocketComm(FBS9100_ComBase.CMD_GetDischargeParm, ByteBuffer.allocate(0),socket)) {
|
m_StatAndParam.op_cmd = FBS9100_ComBase.CMD_GetDischargeParmAck;
|
m_StatAndParam.test_type = FBS9100_ComBase.TestType_CAP;
|
//System.err.println("ÈÝÁ¿·Åµç²âÊԳɹ¦ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
|
}
|
}
|
}
|
}
|
*/
|
//sleep(200);
|
//SocketComm(FBS9100_ComBase.CMD_GetMonomerRES , ByteBuffer.allocate(0) ,socket);
|
|
//sleep(200);
|
//SocketComm(FBS9100_ComBase.CMD_GetMonomerTMP , ByteBuffer.allocate(0) ,socket);
|
/*
|
if(FBS9100_ComBase.TestType_RES == m_StatAndParam.test_type)
|
{
|
sleep(20);
|
//¶ÁÈ¡ÄÚ×è²âÊÔ״̬
|
if(true == SocketComm(FBS9100_ComBase.CMD_GetResTestState, ByteBuffer.allocate(0),socket))
|
{
|
m_FBS_VCData.m_SysState.ResBattIndexMax = m_ResTestState.ResBattIndexMax;
|
m_FBS_VCData.m_SysState.ResBattIndex = m_ResTestState.ResBattIndex;
|
}
|
|
//------ ÄÚ×è²âÊÔÍ£Ö¹µÄʱºò,×Ô¶¯¼Ç¼һ´ÎÄÚ×èÖµµ½Êý¾Ý¿â ------//
|
if(FBS9100_ComBase.TestType_RES != m_FBS_VCData.m_SysState.TestType)
|
{
|
//System.err.println("ÄÚ×è²âÊÔ½áÊø");
|
m_StatAndParam.test_type = FBS9100_ComBase.TestType_NULL;
|
|
int index = m_ResTestState.BattGroupNum - 1;
|
if((index >= 0) && (index < m_RTData.length) && (null != m_RTData[index])) {
|
m_RTData[index].setStoreBattRes_DataEnStat(true);
|
}
|
}
|
} else if (FBS9100_ComBase.TestType_CAP == m_StatAndParam.test_type) {
|
if(FBS9100_ComBase.TestType_CAP != m_FBS_VCData.m_SysState.TestType)
|
{
|
m_StatAndParam.test_type = FBS9100_ComBase.TestType_NULL;
|
}
|
}
|
*/
|
//-----------------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------------//
|
sleep(100);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
try {
|
sleep(2000);
|
} catch (InterruptedException e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
try {
|
if(socket != null){
|
socket.close();
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
/*
|
System.out.println(this.getName()
|
+ " ¶þÆÚ "
|
+ " DevId: " + m_StatAndParam.dev_id + ", DevVer: " + m_StatAndParam.m_DevVersion
|
+ " Ï߳̽áÊø: Error Count: "
|
+ m_StatAndParam.m_FBS_VCData.m_SysState.ErrCommCount
|
+ Com.getNowTimeWithAt());
|
*/
|
}
|
/*********************************************************************************************/
|
/*********************************************************************************************/
|
|
/**
|
* ÏòÖ¸¶¨µÄsocketͨµÀ·¢ËÍÊý¾Ý£¬ÒÔ¼°½ÓÊÕÊý¾Ý
|
* @param cmd
|
* @param bf
|
* @return
|
* @throws InterruptedException
|
*/
|
|
public boolean SocketComm(int cmd, ByteBuffer bf, Socket socket) throws InterruptedException
|
{
|
boolean res_t = false;
|
try
|
{
|
socket.setSoTimeout(3000);
|
if(/*socket.isConnected() && (!socket.isClosed()) && */S_thread_run_flag)
|
{
|
InputStream in = socket.getInputStream();
|
OutputStream out = socket.getOutputStream();
|
//----------------- clear rx buff for tcp resend packet ----------------//
|
byte[] rx_buf_t = new byte[1024];
|
/*
|
int buf_clr_read_count = 0;
|
while(in.available() > 0) {
|
in.read(rx_buf_t);
|
if(buf_clr_read_count >= 10) {
|
S_thread_run_flag = false;
|
System.err.println(this.getName()
|
+ " dev_id: " + m_StatAndParam.dev_id
|
+ " socket rx_buff clear error......");
|
res_t = false;
|
return res_t;
|
}
|
}*/
|
//----------------------------------------------------------------------//
|
bytebuffer_for_socket_RX.order(ByteOrder.LITTLE_ENDIAN);
|
bytebuffer_for_socket_RX.clear();
|
//--------------------- socket write -----------------------------------//
|
boolean aes_en = true;
|
byte[] plain_tx_t = makeCommBuf(cmd, bf, 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(cipher_tx_t);
|
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;
|
}
|
}
|
|
if(bytebuffer_for_socket_RX.position() > 8) {
|
break;
|
}
|
} catch (SocketTimeoutException soe) {
|
//soe.printStackTrace();
|
}
|
//----------------------------------------------------------------//
|
}
|
//=====================================================================//
|
*/
|
int rx_read_time_out = 0;
|
out.write(cipher_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);
|
}
|
} else {
|
rx_read_time_out += 1;
|
if((bytebuffer_for_socket_RX.position()>8) && (rx_read_time_out>10)){
|
res_t = 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_StatAndParam.m_FBS_VCData.m_SysState.CommCount
|
+ " rx_err_sum:" + m_StatAndParam.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);
|
|
if(true == getDataFromCommBuf(plain_buf)) {
|
m_StatAndParam.m_FBS_VCData.m_SysState.setCommCountInc();
|
rx_errcount_for_live_of_thread = 0;
|
res_t = true;
|
} else {
|
/*
|
System.err.println(ComFn.bytesToHexString(plain_buf, plain_buf.length));
|
System.err.println(this.getName() + " DevId: " + m_StatAndParam.dev_id
|
+ "%%%% cmd:" + cmd + " ͨÐÅʧ°Ü" + Com.getNowTimeWithAt());
|
*/
|
res_t = false;
|
m_StatAndParam.m_FBS_VCData.m_SysState.setErrCommCountInc(bytebuffer_for_socket_RX.limit());
|
rx_errcount_for_live_of_thread++;
|
}
|
} else {
|
m_StatAndParam.m_FBS_VCData.m_SysState.setErrCommCountInc(0);
|
//System.out.println(this.getName() + "-------socket Òì³£¹Ø±Õ-------" + Com.getNowTimeWithAt());
|
S_thread_run_flag = false;
|
}
|
} catch (IOException e) {
|
//e.printStackTrace();
|
/*
|
System.err.println(this.getName() + " DevId: " + m_StatAndParam.dev_id
|
+ " %%%% cmd: " + cmd + " ͨÐŹÊÕÏ, IOÒì³£...... " + Com.getNowTimeWithAt());
|
*/
|
S_thread_run_flag = false;
|
m_StatAndParam.m_FBS_VCData.m_SysState.setErrCommCountInc(0);
|
} finally {
|
//ÈôÔÚͨÐŵĹý³ÌÖгöÏÖ4´ÎͨÐÅÒì³£¹Ø±ÕÁ¬½Ó
|
if(rx_errcount_for_live_of_thread >= 5){
|
S_thread_run_flag = false;
|
}
|
}
|
return res_t;
|
}
|
/*********************************************************************************************/
|
/*********************************************************************************************/
|
public byte[] makeCommBuf(final int cmd, ByteBuffer bf, boolean aes_en)
|
{
|
ByteBuffer bbf = FBS9100_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)
|
{
|
boolean isSuccess = false;
|
ByteBuffer bf = ByteBuffer.allocate(bytes.length);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(bytes);
|
bf.flip();
|
|
if(true == m_FBS_Cmd.putByteBuffer(bf))
|
{
|
if((FBS9100_ComBase.CMD_StartDischarge == m_FBS_Cmd.CMD)
|
||(FBS9100_ComBase.CMD_StartResDischarge == m_FBS_Cmd.CMD)
|
||(FBS9100_ComBase.CMD_StartCharge == m_FBS_Cmd.CMD)
|
||(FBS9100_ComBase.CMD_Stop == m_FBS_Cmd.CMD))
|
{
|
isSuccess = true;
|
}
|
//------------------- ¶ÁÈ¡FBS9100µçѹµçÁ÷Êý¾Ý --------------------
|
if(FBS9100_ComBase.CMD_GetVIData == m_FBS_Cmd.CMD)
|
{
|
if(true == m_StatAndParam.m_FBS_VCData.m_SysState.putByteBuffer(bf))
|
{
|
if(true == m_StatAndParam.m_FBS_VCData.putByteBuffer(bf))
|
{
|
getFBS9100MonVolData(m_StatAndParam.m_FBS_VCData);
|
isSuccess = true;
|
for(int n=0; n<2; n++) {
|
if(false == m_StatAndParam.m_al_DCDC_Data[n].putByteBuffer(bf)) {
|
break;
|
}
|
}
|
}
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100ÄÚ×è²âÊÔ״̬ -----------------------
|
if(FBS9100_ComBase.CMD_GetResTestState == m_FBS_Cmd.CMD)
|
{
|
if(true == m_ResTestState.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100·Åµç²âÊÔ״̬ -----------------------
|
if(FBS9100_ComBase.CMD_GetDischargeState == m_FBS_Cmd.CMD)
|
{
|
if(true == m_CapTestState.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100³äµç²âÊÔ״̬ -----------------------
|
if(FBS9100_ComBase.CMD_GetChargeState == m_FBS_Cmd.CMD)
|
{
|
if(true == m_ChrTestState.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100µç³Ø²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_GetBattParam == m_FBS_Cmd.CMD)
|
{
|
if(true == m_FBS_BattParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ÉèÖÃFBS9100µç³Ø²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_SetBattParam == m_FBS_Cmd.CMD) {
|
if(true == m_FBS_BattParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100ϵͳ²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_GetSYSSetParam == m_FBS_Cmd.CMD)
|
{
|
if(true == m_FBS_SystemParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ÉèÖÃFBS9100ϵͳ²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_SetSYSSetParam == m_FBS_Cmd.CMD)
|
{
|
if(true == m_FBS_SystemParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100·Åµç²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_GetDischargeParm == m_FBS_Cmd.CMD)
|
{
|
if(true == m_StatAndParam.m_FBS_DiscParamFromDev.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ÉèÖÃFBS9100·Åµç²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_SetDischargeParm == m_FBS_Cmd.CMD)
|
{
|
if(true == m_StatAndParam.m_FBS_DiscParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100³äµç²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_GetChargeParm == m_FBS_Cmd.CMD)
|
{
|
if(true == m_FBS_ChargeParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ÉèÖÃFBS9100³äµç²ÎÊý -------------------------
|
else if(FBS9100_ComBase.CMD_SetChargeParm == m_FBS_Cmd.CMD)
|
{
|
if(true == m_FBS_ChargeParam.putByteBuffer(bf)){
|
isSuccess = true;
|
}
|
}
|
//------------------- ¶ÁÈ¡FBS9100ÈÝÁ¿ÄÚ×è²âÊÔÊý¾Ý ------------------
|
else if((FBS9100_ComBase.CMD_GetMonomerRES == m_FBS_Cmd.CMD)
|
||(FBS9100_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_ResCapData.putByteBuffer(bf, m_FBS_Cmd.CMD))
|
{
|
isSuccess = true;
|
getFBS9100MonResData(m_FBS_Cmd.CMD, m_FBS_ResCapData);
|
//msg = "Get MonomerCAP or MonomerRES from FBS9100 OK!!!";
|
}
|
} else if(FBS9100_ComBase.CMD_GetDeviceInf == m_FBS_Cmd.CMD) {
|
FBS9100_DeviceInf deviceinf = new FBS9100_DeviceInf();
|
if(true == deviceinf.putByteBuffer(bf)) {
|
m_StatAndParam.m_DevVersion = String.format("V%d.%02d.%02d",
|
deviceinf.DeviceVersion,
|
deviceinf.HardwareVersion,
|
deviceinf.SoftwareVersion);
|
m_StatAndParam.dev_id = deviceinf.BackUp6*256*256*256
|
+ deviceinf.BackUp5*256*256
|
+ deviceinf.BackUp4*256
|
+ deviceinf.BackUp3;
|
isSuccess = true;
|
}
|
} else if(FBS9100_ComBase.CMD_ReadCMCCVolCurr == m_FBS_Cmd.CMD) {
|
if(m_StatAndParam.m_CMCC_Power.putByteBuffer(bf)) {
|
isSuccess = true;
|
}
|
} else if(FBS9100_ComBase.CMD_SystemUpdate == m_FBS_Cmd.CMD) {
|
System.out.println(this.getName() + " DevId: " + m_StatAndParam.dev_id
|
+ " FBS9100_ComBase.CMD_SystemUpdate Done!");
|
isSuccess = true;
|
}
|
}
|
return isSuccess;
|
}
|
|
/*********************************************************************************************/
|
private void getFBS9100MonVolData(FBS9100_VCData vc_data)
|
{
|
boolean fbsdev_statchange_record_tag = false;
|
int mon_index = 0;
|
for(int n=0; n<FBS9100_ComBase.BattGroupCountMax; n++) {
|
if(null != m_RTData[n]) {
|
//--------------------- ÏȶÁÈ¡µ¥Ìåµçѹ ---------------------------------------//
|
for(int index=0; index < m_RTData[n].MonCount; index++) {
|
if(mon_index >= FBS9600_CommData.BATT_MON_COUNT_MAX) {
|
break;
|
}
|
|
m_RTData[n].al_MonVol.get(index).monVol = (float) vc_data.vol[mon_index];
|
mon_index++;
|
}
|
//--------------------- ÔÙ¶Áȡϵͳ״̬ ---------------------------------------//
|
int work_stat = m_RTData[n].mTestData.dev_FBS9100S_WorkState;
|
m_RTData[n].mTestData.setDevFBS9100S_WorkState(vc_data.m_SysState.CapTestStopType,
|
vc_data.m_SysState.TestType,
|
vc_data.m_SysState.WorkState);
|
//--------------------- FBSÉ豸¹¤×÷״̬±ä»¯¼Ç¼ ------------------------------//
|
if(false == fbsdev_statchange_record_tag) {
|
if(work_stat != vc_data.m_SysState.WorkState) {
|
int stat_change_reason = 0;
|
if(FBS9100_SysState.SYS_STATE_DISCHARGING == work_stat) {
|
stat_change_reason = vc_data.m_SysState.CapTestStopType;
|
}
|
FBS9100_Task_Thread_SQL.insertFBSDevStatChangeInfToTable(m_ConnPool, m_StatAndParam.dev_id,
|
work_stat, vc_data.m_SysState.WorkState, stat_change_reason);
|
fbsdev_statchange_record_tag = true;
|
}
|
}
|
//--------------------- ÔÙ¶ÁÈ¡¶Ëµçѹ -----------------------------------------//
|
m_RTData[n].mTestData.updateOnlineVolFrom_FBSDev((float) vc_data.onlinevol[n]);
|
m_RTData[n].mTestData.updateGroupVolFrom_FBSDev((float) vc_data.groupvol[n]);
|
//--------------------- ×îºó¶ÁÈ¡µçÁ÷ -----------------------------------------//
|
if(FBS9100_ComBase.BattState_Discharge == vc_data.battstate[n]) {
|
vc_data.battcurr[n] *= -1;
|
}
|
m_RTData[n].mTestData.updateCurrFrom_FBSDev((float) vc_data.battcurr[n]);
|
//---------------------------------------------------------------------------//
|
//--------------------- DCDC½ÚÄÜÄ£¿é״̬Êý¾Ý ---------------------------------//
|
m_RTData[n].m_DCDC_Data.copyData(m_StatAndParam.m_al_DCDC_Data[0]);
|
//---------------------------------------------------------------------------//
|
//--------------------- Ïȸüе¥ÌåÊý¾Ý,ÔÙ¸üÐÂµç³Ø×´Ì¬Êý¾Ý ----------------------//
|
m_RTData[n].updata_BattRtData_To_RamDb();
|
m_RTData[n].updata_BattRtSate_To_RamDb();
|
//---------------------------------------------------------------------------//
|
}
|
}
|
|
if (FBS9100_SysState.SYS_STATE_STOPPED != vc_data.m_SysState.WorkState) {
|
DevReadCount_Rate = 1;
|
}
|
}
|
/*********************************************************************************************/
|
private void getFBS9100MonResData(int cmd, FBS9100_ResCapData res_data)
|
{
|
int mon_index = 0;
|
for(int n=0; n<FBS9100_ComBase.BattGroupCountMax; n++)
|
{
|
if(null != m_RTData[n])
|
{
|
for(int index=0; index<m_RTData[n].MonCount; index++)
|
{
|
if(mon_index >= FBS9600_CommData.BATT_MON_COUNT_MAX) {
|
break;
|
}
|
|
if(FBS9100_ComBase.CMD_GetMonomerRES == cmd) {
|
m_RTData[n].al_MonVol.get(index).monRes = (float) res_data.m_DATA[mon_index];
|
} else if(FBS9100_ComBase.CMD_GetMonomerTMP == cmd) {
|
m_RTData[n].al_MonVol.get(index).monTmp = (float) res_data.m_DATA[mon_index];
|
}
|
|
mon_index++;
|
}
|
}
|
}
|
}
|
/*********************************************************************************************/
|
}
|
/********************************* end of file SocketClient.java *************************************/
|