Commit 59e5ebadfde6491854e4b1bc4859d8fb0dd30551

Authored by wugian
1 parent c30c8753

all function need use

@@ -111,7 +111,7 @@ public class Device implements Serializable, Cloneable { @@ -111,7 +111,7 @@ public class Device implements Serializable, Cloneable {
111 char point = '.'; 111 char point = '.';
112 StringBuilder builder = new StringBuilder(); 112 StringBuilder builder = new StringBuilder();
113 for (byte b : DeviceIp) { 113 for (byte b : DeviceIp) {
114 - builder.append(b & GlobalVar.MAX_BYTE).append(point); 114 + builder.append((b & GlobalVar.MAX_BYTE)).append(point);
115 } 115 }
116 builder.deleteCharAt(builder.length() - 1); 116 builder.deleteCharAt(builder.length() - 1);
117 strIp = builder.toString(); 117 strIp = builder.toString();
@@ -151,6 +151,34 @@ public class Device implements Serializable, Cloneable { @@ -151,6 +151,34 @@ public class Device implements Serializable, Cloneable {
151 return DeviceNum; 151 return DeviceNum;
152 } 152 }
153 153
  154 + //添加 转化成16进制显示 17.03.23
  155 + public String getStringDeviceNum() {
  156 + String strIp = "null";
  157 + if (null != DeviceNum) {
  158 + char point = ':';
  159 + StringBuilder builder = new StringBuilder();
  160 + for (byte b : DeviceNum) {
  161 + builder.append(decimal2hex(b & GlobalVar.MAX_BYTE)).append(point);
  162 + }
  163 + builder.deleteCharAt(builder.length() - 1);
  164 + strIp = builder.toString();
  165 + }
  166 + return strIp;
  167 + }
  168 + // precondition: d is a nonnegative integer
  169 + public static String decimal2hex(int d) {
  170 + String digits = "0123456789ABCDEF";
  171 + if (d <= 0) return "00";
  172 + int base = 16; // flexible to change in any base under 16
  173 + String hex = "";
  174 + while (d > 0) {
  175 + int digit = d % base; // rightmost digit
  176 + hex = digits.charAt(digit) + hex; // string concatenation
  177 + d = d / base;
  178 + }
  179 + return hex;
  180 + }
  181 +
154 public void setDeviceNum(byte[] deviceNum) { 182 public void setDeviceNum(byte[] deviceNum) {
155 DeviceNum = deviceNum; 183 DeviceNum = deviceNum;
156 } 184 }
@@ -192,11 +192,18 @@ public class FistJni { @@ -192,11 +192,18 @@ public class FistJni {
192 192
193 } else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) { 193 } else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) {
194 sendJsonDevice(START_ADD, device); 194 sendJsonDevice(START_ADD, device);
195 -  
196 - } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网  
197 -// if (0 == device.getIntDeviceIp()) return;  
198 // FistJni.stopAddSubDevice(jsonDevice); 195 // FistJni.stopAddSubDevice(jsonDevice);
199 - 196 + device.setCmdType(49);
  197 + getInstance().query(gson.toJson(device));
  198 +// getInstance().query(gson.toJson(device));
  199 + FistJni.stopAddSubDevice(jsonDevice);
  200 + } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网
  201 + if (0 == device.getIntDeviceIp()) return;
  202 + device.setCmdType(49);
  203 +// getInstance().query(gson.toJson(device));
  204 + getInstance().query(gson.toJson(device));
  205 + FistJni.stopAddSubDevice(jsonDevice);
  206 +// getInstance().query(jsonDevice);
200 } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL == cmdTpye) {//控制超时 207 } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL == cmdTpye) {//控制超时
201 sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device); 208 sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
202 209
@@ -22,7 +22,7 @@ import org.greenrobot.eventbus.ThreadMode; @@ -22,7 +22,7 @@ import org.greenrobot.eventbus.ThreadMode;
22 import java.util.ArrayList; 22 import java.util.ArrayList;
23 23
24 public class SwitchControlActivity extends AppCompatActivity { 24 public class SwitchControlActivity extends AppCompatActivity {
25 - private String deviceStrKey = "x85bau"; 25 + private String deviceStrKey = "MtfuJL";
26 26
27 @Override 27 @Override
28 protected void onCreate(Bundle savedInstanceState) { 28 protected void onCreate(Bundle savedInstanceState) {
@@ -132,13 +132,58 @@ public class SwitchControlActivity extends AppCompatActivity { @@ -132,13 +132,58 @@ public class SwitchControlActivity extends AppCompatActivity {
132 132
133 @Override 133 @Override
134 public void onMenuClick(View v, int position) { 134 public void onMenuClick(View v, int position) {
  135 + Device device = null;
  136 + for (Device deviceCur : FistJni.getHubs()) {
  137 + if (deviceCur.getDeviceStrKey().equals(deviceStrKey)) {
  138 + device = deviceCur;
  139 + }
  140 + }
  141 + if (device == null) {
  142 + Toast.makeText(SwitchControlActivity.this, "当前控制口令出错,请重新选择控制主机按menu设置", Toast.LENGTH_SHORT).show();
  143 + return;
  144 + }
135 145
  146 + ArrayList<SubDevice> subDevices = new ArrayList<>();
  147 + subDevices.add(FistJni.getSubDevices().get(position));
  148 + device.setSubDevices(subDevices);
  149 + FistJni.getInstance().delSub(new Gson().toJson(device));
136 } 150 }
137 }); 151 });
138 switchRv.setAdapter(switchAdapter); 152 switchRv.setAdapter(switchAdapter);
139 switchRv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); 153 switchRv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
140 } 154 }
141 155
  156 + public void startAdd(View view) {
  157 + FistJni fistJni = FistJni.getInstance();
  158 + final Device device = FistJni.getHubs().get(0);
  159 + fistJni.startAdd(new Gson().toJson(device));
  160 + }
  161 +
  162 + public void stopAdd(View view) {
  163 + FistJni fistJni = FistJni.getInstance();
  164 +
  165 + final Device device = FistJni.getHubs().get(0);
  166 + fistJni.stopAdd(new Gson().toJson(device));
  167 + }
  168 +
  169 + public void resetPwd(View view) {
  170 + FistJni fistJni = FistJni.getInstance();
  171 + Device device = FistJni.getHubs().get(0);
  172 + fistJni.modifyPwd(new Gson().toJson(device), "123456");
  173 + }
  174 +
  175 + public void getLinkStatus(View view) {
  176 + FistJni fistJni = FistJni.getInstance();
  177 + Device device = FistJni.getHubs().get(0);
  178 + fistJni.getLinkStatus(new Gson().toJson(device));
  179 + }
  180 +
  181 + public void setLinkMsg(View view) {
  182 + FistJni fistJni = FistJni.getInstance();
  183 + Device device = FistJni.getHubs().get(0);
  184 + fistJni.getlinkRouter(new Gson().toJson(device),"Xiaomi123","88888888");
  185 + }
  186 +
142 public class MovieItemDecoration extends RecyclerView.ItemDecoration { 187 public class MovieItemDecoration extends RecyclerView.ItemDecoration {
143 @Override 188 @Override
144 public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 189 public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
@@ -131,7 +131,7 @@ public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.De @@ -131,7 +131,7 @@ public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.De
131 } 131 }
132 132
133 void render(Device light) { 133 void render(Device light) {
134 - deviceNumTv.setText(light.getLongDeviceNum() + ""); 134 + deviceNumTv.setText("设备号:" + light.getStringDeviceNum() + "");
135 deviceIp.setText("IP:" + light.getStringDeviceIp()); 135 deviceIp.setText("IP:" + light.getStringDeviceIp());
136 deviceKey.setText("控制口令:" + light.getDeviceStrKey()); 136 deviceKey.setText("控制口令:" + light.getDeviceStrKey());
137 } 137 }
@@ -12,6 +12,26 @@ @@ -12,6 +12,26 @@
12 tools:showIn="@layout/activity_switch_control" 12 tools:showIn="@layout/activity_switch_control"
13 tools:context="com.qnbar.switchcontrol.SwitchControlActivity"> 13 tools:context="com.qnbar.switchcontrol.SwitchControlActivity">
14 14
  15 +
  16 + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
  17 +
  18 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始添加"
  19 + android:onClick="startAdd"/>
  20 +
  21 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="结束添加"
  22 + android:onClick="stopAdd"/>
  23 +
  24 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="重设置密码"
  25 + android:onClick="resetPwd"/>
  26 +
  27 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="设置路由信息"
  28 + android:onClick="setLinkMsg"/>
  29 +
  30 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="获取路由信息"
  31 + android:onClick="getLinkStatus"/>
  32 +
  33 +
  34 + </LinearLayout>
15 <TextView android:layout_width="wrap_content" 35 <TextView android:layout_width="wrap_content"
16 android:layout_height="wrap_content" 36 android:layout_height="wrap_content"
17 android:text="控制主机" 37 android:text="控制主机"
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" 11 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
12 android:id="@+id/deviceNumTv" 12 android:id="@+id/deviceNumTv"
13 android:textSize="16sp" 13 android:textSize="16sp"
14 - android:visibility="gone" 14 + android:visibility="visible"
15 android:textColor="@android:color/black" 15 android:textColor="@android:color/black"
16 android:text="device num" 16 android:text="device num"
17 /> 17 />
Please register or login to post a comment