Commit 69ae40f0 by pye52

删除冗余设计(不再需要响应服务器的check_device指令)

parent fc38dd28
package com.bgycc.smartcanteen.entity;
import java.util.Objects;
public class CheckDevice {
private String action;
private CheckDeviceData data;
private long serialNumber;
public CheckDevice(String action, String deviceSN) {
this.action = action;
this.data = new CheckDeviceData(deviceSN);
this.serialNumber = System.currentTimeMillis();
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public CheckDeviceData getData() {
return data;
}
public void setData(CheckDeviceData data) {
this.data = data;
}
public long getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(long serialNumber) {
this.serialNumber = serialNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CheckDevice that = (CheckDevice) o;
return serialNumber == that.serialNumber &&
Objects.equals(action, that.action) &&
Objects.equals(data, that.data);
}
@Override
public int hashCode() {
return Objects.hash(action, data, serialNumber);
}
@Override
public String toString() {
return "CheckDevice{" +
"action='" + action + '\'' +
", data=" + data +
", serialNumber=" + serialNumber +
'}';
}
private static class CheckDeviceData {
private String equipmentId;
private CheckDeviceData(String deviceSN) {
this.equipmentId = deviceSN;
}
public String getEquipmentId() {
return equipmentId;
}
public void setEquipmentId(String equipmentId) {
this.equipmentId = equipmentId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CheckDeviceData that = (CheckDeviceData) o;
return Objects.equals(equipmentId, that.equipmentId);
}
@Override
public int hashCode() {
return Objects.hash(equipmentId);
}
@Override
public String toString() {
return "CheckDeviceData{" +
"equipmentId='" + equipmentId + '\'' +
'}';
}
}
}
...@@ -3,13 +3,11 @@ package com.bgycc.smartcanteen.socket; ...@@ -3,13 +3,11 @@ package com.bgycc.smartcanteen.socket;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import com.bgycc.smartcanteen.entity.CheckDevice;
import com.bgycc.smartcanteen.entity.Heartbeat; import com.bgycc.smartcanteen.entity.Heartbeat;
import com.bgycc.smartcanteen.executor.SCTaskExecutor; import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.bgycc.smartcanteen.state.ConnectState; import com.bgycc.smartcanteen.state.ConnectState;
...@@ -45,8 +43,6 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -45,8 +43,6 @@ public class SCWebSocketClient extends WebSocketClient {
private static final long SWITCH_INTERVAL = 10 * 1000; private static final long SWITCH_INTERVAL = 10 * 1000;
private static final String RESPONSE_ACTION = "action"; private static final String RESPONSE_ACTION = "action";
private static final String RESPONSE_DATA = "data";
private static final String CHECK_DEVICE = "CHECK_DEVICE";
private static SCWebSocketClient instance; private static SCWebSocketClient instance;
private Gson gson; private Gson gson;
...@@ -169,21 +165,6 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -169,21 +165,6 @@ public class SCWebSocketClient extends WebSocketClient {
if (jsonObject.has(RESPONSE_ACTION)) { if (jsonObject.has(RESPONSE_ACTION)) {
action = jsonObject.get(RESPONSE_ACTION).getAsString(); action = jsonObject.get(RESPONSE_ACTION).getAsString();
} }
// 是否服务器下发的心跳通知(响应则告知服务器设备未断开链接)
if (action.equals(CHECK_DEVICE)) {
String data = "";
if (jsonObject.has(RESPONSE_DATA)) {
data = jsonObject.get(RESPONSE_DATA).getAsString();
}
if (!TextUtils.isEmpty(data)) {
CheckDevice ack = new CheckDevice(CHECK_DEVICE, data);
String requestStr = gson.toJson(ack);
send(requestStr);
}
// 该指令不需要向外通知Listener
LogUtils.d(TAG, "后台下发心跳包: " + response);
return;
}
LogUtils.d(TAG, "收到后台消息: " + response); LogUtils.d(TAG, "收到后台消息: " + response);
for (SCWebSocketListener l : listener) { for (SCWebSocketListener l : listener) {
l.onMessage(action, jsonObject, response); l.onMessage(action, jsonObject, response);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment