| | |
| | | import android.util.Log;
|
| | | import android.webkit.WebView;
|
| | |
|
| | | import com.alarms.AlarmParam.*;
|
| | | import com.alarms.BattAlarmCheckThread;
|
| | | import com.alarms.BattAlarmData;
|
| | | import com.concentrator.Concentrator_ComBase;
|
| | | import com.concentrator.Concentrator_Param;
|
| | | import com.concentrator.Concentrator_State;
|
| | |
| | | import com.google.gson.Gson;
|
| | | import com.util.Com;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 电池组组操作相关类
|
| | |
| | | public static final int TESTTYPE_DISTEST = 3; //放电测试
|
| | | public static final int TESTTYPE_RESTEST = 5; //内阻测试
|
| | |
|
| | |
|
| | |
|
| | | public static final String TAG = "BattDataThread";
|
| | |
|
| | |
|
| | | public Handler mSocketHandler = null;
|
| | | private CommSockClientThread clientThread = null;
|
| | | public transient Handler mSocketHandler = null;
|
| | | private transient CommSockClientThread clientThread = null;
|
| | | public boolean isInstall = false; //是否安装
|
| | | public int battIndex = 1; //电池组ID 默认电池组ID
|
| | | public Concentrator_Param param; //汇集器参数
|
| | | public boolean isAlarmClear = true;
|
| | | public transient Concentrator_Param param; //汇集器参数
|
| | | public Concentrator_State state; //汇集器状态
|
| | | public Battinf battinf; //电池组信息
|
| | | public DBHelper dbHelper;
|
| | | public WebView webView;
|
| | | public transient DBHelper dbHelper;
|
| | | public transient WebView webView;
|
| | |
|
| | |
|
| | | public Date lastUpdateTime = new Date(); //上一次获取数据时间
|
| | | public Date lastUpdateTime = new Date(0,1,1); //上一次获取数据时间
|
| | | public boolean isOutTime = true; //通讯是否超时 超时重连时会重新获取设备的系统参数
|
| | | public long loseTimeLong = 0; //断开连接时长
|
| | |
|
| | | private BattDataThread(){
|
| | |
|
| | | }
|
| | |
|
| | | public BattDataThread(int battIndex, DBHelper dbHelper,WebView webView){
|
| | | this.webView = webView;
|
| | |
| | | state = new Concentrator_State();
|
| | | clientThread = CommSockClientThread.createClientThread(); //串口通讯线程 //每个电池组通用同一个串口线程
|
| | |
|
| | |
|
| | | //内阻记录线程
|
| | | BattResDataRecordThread battResDataRecordThread = new BattResDataRecordThread(this,dbHelper);
|
| | | battResDataRecordThread.start();
|
| | |
|
| | | //充放电记录线程
|
| | | //BattTestDataRecordThread battTestDataRecordThread = new BattTestDataRecordThread(dbHelper,this);
|
| | | //battTestDataRecordThread.start();
|
| | |
|
| | |
|
| | |
|
| | | this.mSocketHandler = new Handler(){
|
| | | @Override
|
| | | public void handleMessage(Message msg) {
|
| | |
| | | if(model != null){
|
| | | if(model.code ==1){
|
| | | lastUpdateTime = new Date();
|
| | | //Log.e(TAG, "handleMessage: cmd:"+model.cmd+"\t cmd_type:"+model.cmd_type );
|
| | | //操作执行成功
|
| | | if(model.cmd_type == Concentrator_ComBase.CMD_MODEBUS_READCMD){
|
| | | //读取成功
|
| | |
| | | //读取设备参数成功
|
| | | param.clone((Concentrator_Param)model.data); //获取当前设备额参数
|
| | | state.monCount = param.countMonCount(); //统计当前设备的单体数量
|
| | | //Log.e(TAG, "handleMessage: 获取设备参数成功" );
|
| | | //state.monCount = 300; //统计当前设备的单体数量
|
| | | Log.e(TAG, "handleMessage: 获取设备参数成功" +state.monCount);
|
| | | }
|
| | |
|
| | | if(model.cmd == Concentrator_ComBase.CMD_MODEBUS_DEVICESTATE_INDEX){
|
| | |
| | | Log.e(TAG, "handleMessage: battindex"+battIndex + "重启汇集器成功" );
|
| | | }
|
| | | }
|
| | | }else{
|
| | | if(model.cmd == Concentrator_ComBase.CMD_RESTART_INDEX && isInstall && !isOutTime){
|
| | | model.code = 1;
|
| | | }
|
| | | }
|
| | | if(model.methodName != null && model.methodName.length()>0){
|
| | | ActionUtil.SendCallDataToJS(model.methodName,model,webView,ActionUtil.getGson());
|
| | |
| | | public void run() {
|
| | | Log.e(TAG, "run: battindex"+battIndex +"\t start at "+ Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
|
| | | Date nowTime = new Date(); //当前时间
|
| | |
|
| | | int monRCount = 0; //单体读取
|
| | | int runCount = 0; //执行次数
|
| | | while(true){
|
| | | try {
|
| | |
|
| | | //Log.e(TAG, "run: &&&&&&&&&&&&&&&&"+battIndex+"&&&&&&&&&&&&&&&&&&&&&&&&&&&install" + isInstall+"\tOutTime"+isOutTime);
|
| | | if(isInstall){
|
| | | //Log.e(TAG, "run: &&&&&&&&&&&&&&&&"+battIndex+"&&&&&&&&&&&&&&&&&&&&&&&&&&&install" + isInstall+"\tOutTime"+isOutTime+"\t"+Com.getDateTimeFormat(lastUpdateTime,Com.DTF_YMDhms));
|
| | | //如果当前电池组已安装则实时获取当前电池组的单体信息
|
| | | if( isOutTime ){
|
| | | if(runCount %15 == 0) {
|
| | |
| | | readSystemState("");
|
| | | }
|
| | |
|
| | | if(runCount % 20 == 0){
|
| | | if(runCount % 25 == 0){
|
| | | int maxCount = (int)Math.ceil((double)state.monCount/100); //最多需要读取次数
|
| | | int monindex = monRCount % maxCount; //单体索引
|
| | | //读取单体电压
|
| | |
| | | }
|
| | | runCount ++;
|
| | | nowTime = new Date();
|
| | | loseTimeLong = (nowTime.getTime() - lastUpdateTime.getTime())/1000;
|
| | | loseTimeLong = Math.abs(nowTime.getTime() - lastUpdateTime.getTime())/1000;
|
| | | if(loseTimeLong > 60){
|
| | | isOutTime = true; //60秒未通讯判定为通讯超时
|
| | | }else{
|
| | | isOutTime = false;
|
| | | }
|
| | |
|
| | | sleep(200);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * @return
|
| | | */
|
| | | public BattDataThread cloneRtData(){
|
| | | BattDataThread battDataThread = new BattDataThread();
|
| | | battDataThread.state = this.state;
|
| | | battDataThread.battinf =this.battinf;
|
| | | return battDataThread;
|
| | | }
|
| | |
|
| | |
|
| | |
| | | battinf.setMonTmpStd(24);
|
| | | return battinf;
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return "BattDataThread{" +
|
| | | "mSocketHandler=" + mSocketHandler +
|
| | | ", clientThread=" + clientThread +
|
| | | ", isInstall=" + isInstall +
|
| | | ", battIndex=" + battIndex +
|
| | | ", param=" + param +
|
| | | ", state=" + state +
|
| | | ", battinf=" + battinf +
|
| | | ", dbHelper=" + dbHelper +
|
| | | ", webView=" + webView +
|
| | | ", lastUpdateTime=" + lastUpdateTime +
|
| | | ", isOutTime=" + isOutTime +
|
| | | ", loseTimeLong=" + loseTimeLong +
|
| | | '}';
|
| | | }
|
| | |
|
| | |
|
| | | public static void main(String[] args) {
|
| | | List list = new ArrayList<>();
|
| | | for(int i = 0;i<10;i++){
|
| | | BattDataThread battDataThread = new BattDataThread();
|
| | | list.add(battDataThread.state);
|
| | | list.add(battDataThread.battinf);
|
| | | }
|
| | | Gson gson = new Gson();
|
| | | System.out.println(gson.toJson(list));
|
| | |
|
| | | }
|
| | | }
|