|
@@ -211,7 +211,39 @@ public class MainActivity extends SerialPortActivity {
|
|
|
|
|
|
@Override
|
|
|
protected void onDataReceivedString(String data) {
|
|
|
- Log.e("TAG", "receiveData: " + data);
|
|
|
+ //$8C:FC:A0:F1:01:A7{"action":"ACK","type":"S433"}#
|
|
|
+ Log.e(TAG, "receiveData: " + data);
|
|
|
+
|
|
|
+ if (BuildConfig.DEBUG) {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (mReception != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ mReception.append(sdf.format(new Date()) + " 收到数据:" + data + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //收到433回复后转发给服务器
|
|
|
+ if (data.startsWith("$") && data.endsWith("#")) {
|
|
|
+ //只有收到的是ACK才转发服务器
|
|
|
+ String tempData = data.substring(1, data.length()-1);
|
|
|
+ int sepIndex = tempData.indexOf("{");
|
|
|
+ String mac = tempData.substring(0, sepIndex);
|
|
|
+ String tcpData = tempData.substring(sepIndex);
|
|
|
+ //Log.e("Application", "tempData: " + tempData + ", mac: " + mac + ", tcpData: " + tcpData);
|
|
|
+ TcpModel tcpModel = TcpModel.getModelByJson(tcpData);
|
|
|
+ if (tcpModel != null) {
|
|
|
+ if (TcpAction.S433Action.ACK == tcpModel.getAction()) {
|
|
|
+ JSONObject jsonData = new JSONObject();
|
|
|
+ jsonData.put("receiverMac", mac);
|
|
|
+ tcpModel.setData(jsonData);
|
|
|
+ TcpClient.getInstance().sendMsg(tcpModel.toJson());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void openNetworkDebug() {
|
|
@@ -415,6 +447,7 @@ public class MainActivity extends SerialPortActivity {
|
|
|
String mac = tcpData.getString("receiverMac");
|
|
|
s433Send.put("data", data);
|
|
|
s433Data.add(mac + s433Send.toJSONString());
|
|
|
+
|
|
|
send433Data();
|
|
|
}
|
|
|
}
|