Commit 71e3ea8d by patpat

增加检查设备接口

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