Commit 71e3ea8d by patpat

增加检查设备接口

parent 77bc4ac8
......@@ -6,12 +6,12 @@ public class AppConfig {
TEST,
PROD
}
public static final Server SERVER = Server.PROD;
public static final boolean DEBUG = false;
public static final Server SERVER = Server.DEV;
public static final boolean DEBUG = true;
public static String getMainWebSocketServerUrl() {
switch (SERVER) {
case DEV: return "ws://10.187.30.128:9001/websocket/%s";
case DEV: return "ws://10.187.17.22:9001/websocket/%s";
case TEST: return "ws://diningservicetest.bgy.com.cn:9001/websocket/%s";
default:
case PROD: return "ws://10.10.182.48:9001/websocket/%s";
......
......@@ -2,6 +2,9 @@ package com.bgycc.smartcanteen.action;
public enum ActionEnum {
// 检查设备
CHECK_DEVICE,
// 支付
PAY_,
PAY_ONLINE,
......
......@@ -79,6 +79,8 @@ class MainActivity : BaseActivity() {
private fun initView() {
if (!AppConfig.DEBUG) {
_debug.visibility = View.GONE
} else {
_logo.visibility = View.GONE
}
_setting.alpha = 0f
_setting_img.post{
......@@ -164,7 +166,7 @@ class MainActivity : BaseActivity() {
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: ConnectStateEvent) {
val base = "Server: " + AppConfig.getMainWebSocketServerUrl() + " "
val base = "Server: " + String.format(AppConfig.getMainWebSocketServerUrl(), App.getDeviceSN()) + " "
if (event.state == ConnectStateEvent.OFFLINE) _server.text = base + "未连接"
else if (event.state == ConnectStateEvent.CONNECTING) _server.text = base + "正在连接..."
else if (event.state == ConnectStateEvent.CONNECTED) _server.text = base + "已连接"
......
package com.bgycc.smartcanteen.server.websocket;
import android.util.Log;
import android.util.SparseArray;
import com.bgycc.smartcanteen.App;
import com.bgycc.smartcanteen.AppConfig;
......@@ -10,10 +9,7 @@ import com.bgycc.smartcanteen.helper.TimerHelper;
import com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent;
import com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent;
import com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent;
import com.example.zhoukai.modemtooltest.ModemToolTest;
import com.example.zhoukai.modemtooltest.NvConstants;
import com.maxrocky.vmatrix.module.Device;
import com.szxb.jni.libszxb;
import com.bgycc.smartcanteen.util.LogUtil;
import org.greenrobot.eventbus.EventBus;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
......@@ -24,7 +20,6 @@ import org.json.JSONObject;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.*;
public class MainWebSocket extends WebSocketClient {
......@@ -124,7 +119,7 @@ public class MainWebSocket extends WebSocketClient {
json.put(FieldEnum.message.name(), message);
String msg = json.toString();
Log.i(TAG, String.format("send: %s", msg));
LogUtil.i(TAG, String.format("send: %s", msg));
EventBus.getDefault().post(new SendMessageEvent(msg));
sInstance.send(msg);
} catch (JSONException e) {
......@@ -157,7 +152,7 @@ public class MainWebSocket extends WebSocketClient {
mRequestList.put(mSessionId, request);
String msg = request.params.toString();
Log.i(TAG, String.format("send: %s", msg));
LogUtil.i(TAG, String.format("send: %s", msg));
EventBus.getDefault().post(new SendMessageEvent(msg));
super.send(msg);
} catch (Exception e) {
......@@ -167,14 +162,14 @@ public class MainWebSocket extends WebSocketClient {
@Override
public void onOpen(ServerHandshake handshakeData) {
Log.i(TAG, String.format("onOpen: %d %s", handshakeData.getHttpStatus(), handshakeData.getHttpStatusMessage()));
LogUtil.i(TAG, String.format("onOpen: %d %s", handshakeData.getHttpStatus(), handshakeData.getHttpStatusMessage()));
EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.CONNECTED));
PayOfflineAction.getDefault().upload();
}
@Override
public void onMessage(String message) {
Log.i(TAG, String.format("onMessage: %s", message));
LogUtil.i(TAG, String.format("onMessage: %s", message));
EventBus.getDefault().post(new RecvMessageEvent(message));
try {
......@@ -183,6 +178,19 @@ public class MainWebSocket extends WebSocketClient {
String action = json.optString(FieldEnum.action.name(), "");
String code = json.optString(FieldEnum.code.name(), "");
// 检查设备
if (ActionEnum.CHECK_DEVICE.name().equals(action)) {
JSONObject data = new JSONObject();
data.put(FieldEnum.equipmentId.name(), json.getString(FieldEnum.data.name()));
JSONObject j = new JSONObject();
j.put(FieldEnum.data.name(), data);
j.put(FieldEnum.serialNumber.name(), sessionId);
LogUtil.i(TAG, String.format("send: %s", j.toString()));
EventBus.getDefault().post(new SendMessageEvent(j.toString()));
super.send(j.toString());
return;
}
ArrayList<Response> list = mSubscribeList.get(action);
if (list != null && list.size() > 0) {
for (Response res : list) {
......@@ -201,13 +209,13 @@ public class MainWebSocket extends WebSocketClient {
@Override
public void onClose(int code, String reason, boolean remote) {
Log.i(TAG, String.format("onClose: %d %s", code, reason));
LogUtil.i(TAG, String.format("onClose: %d %s", code, reason));
EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.OFFLINE));
}
@Override
public void onError(Exception ex) {
Log.i(TAG, "onError");
LogUtil.i(TAG, "onError");
ex.printStackTrace();
}
......
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