whyclj
2019-11-18 1017b813b733444819ae5fa15b1e2faafe4ef2e4
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
package com.socket;
 
import android.drm.DrmStore;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
 
import com.fgkj.action.ServiceModel;
import com.fgkj.dao.ActionUtil;
import com.fgkj.dao.DBHelper;
 
import java.util.ArrayList;
import java.util.List;
 
public class FBS9600S_DeviceService {
    public static final int MAXCONCENTRATORCOUNT = 16;                                  //最多连接的汇集器数量
    public static final String JS_INTERFACE_NAME = "FBS9600S_DeviceService";            //JS调用类名
 
    public List<BattDataThread> allBattDatt;
    public DBHelper dbHelper;
    public WebView webView;
    public FBS9600S_DeviceService(WebView webView,DBHelper dbHelper){
        this.dbHelper = dbHelper;
        this.webView = webView;
        allBattDatt = new ArrayList<>();
        for(int i=0;i<MAXCONCENTRATORCOUNT;i++){
            BattDataThread thread = new BattDataThread(i+1,this.dbHelper,webView);
            allBattDatt.add(thread);
            thread.start();
        }
        allBattDatt.get(0).isInstall = true;
    }
 
    //读取系统状态
    @JavascriptInterface
    public void readSystemState(String index){
        int battindex = Integer.parseInt(index);
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            allBattDatt.get(battindex).readSystemState("readSystemState");
        }
    }
 
    //读取系统参数
    @JavascriptInterface
    public void readSystemParam(String index){
        int battindex = Integer.parseInt(index);
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            allBattDatt.get(battindex).readSystemParam("readSystemParam");
        }
    }
 
    //设置系统参数
    @JavascriptInterface
    public void writeSystemParam(String index,String json){
        int battindex = Integer.parseInt(index);
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            allBattDatt.get(battindex).writeSystemParam("writeSystemParam",json);
        }
    }
 
    //读取电池信息
    @JavascriptInterface
    public void readBattMonInfo(String index){
        int battindex = Integer.parseInt(index);
        ServiceModel model = new ServiceModel();
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            model.code = 1;
            model.data = allBattDatt.get(battindex).state;
        }
        ActionUtil.SendCallDataToJS("readBattMonInfo",model,webView, ActionUtil.getGson());
    }
 
    //启动内阻测试
    @JavascriptInterface
    public void startBattResTest(String index){
        int battindex = Integer.parseInt(index);
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            allBattDatt.get(battindex).startBattResTest("startBattResTest");
        }
    }
 
    //启动内阻测试
    @JavascriptInterface
    public void stopBattResTest(String index){
        int battindex = Integer.parseInt(index);
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            allBattDatt.get(battindex).stopBattResTest("stopBattResTest");
        }
    }
 
    //启动内阻测试
    @JavascriptInterface
    public void reStartSystem(String index){
        int battindex = Integer.parseInt(index);
        if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){
            allBattDatt.get(battindex).reStartSystem("reStartSystem");
        }
    }
}