code clean
This commit is contained in:
@@ -64,7 +64,6 @@ public class MainActivity extends AppCompatActivity
|
||||
//存储小车的IP
|
||||
private String IPCar;
|
||||
//通信客户端
|
||||
// private Client client;
|
||||
private DataTransferCore dtc_client;
|
||||
//DHCP相关信息,用于获取IP地址
|
||||
private DhcpInfo dhcpInfo;
|
||||
@@ -72,7 +71,7 @@ public class MainActivity extends AppCompatActivity
|
||||
private WifiManager wifiManager;
|
||||
//控件——存储从摄像头获取到的图像
|
||||
private ImageView pic_received;
|
||||
//控件——存储Toast的内容,由MakeToast()进行管理
|
||||
//控件——存储Toast的内容,由ToastLog()进行管理
|
||||
private TextView text_toast;
|
||||
//控制主车相机
|
||||
private CameraCommandUtil cameraCommandUtil;
|
||||
@@ -116,10 +115,10 @@ public class MainActivity extends AppCompatActivity
|
||||
public void handleMessage(Message msg)
|
||||
{
|
||||
super.handleMessage(msg);
|
||||
//处理接收到的图片
|
||||
if (msg.what == Flags.RECEIVED_IMAGE)
|
||||
{
|
||||
pic_received.setImageBitmap(currImage);
|
||||
}
|
||||
//处理接收到的指令
|
||||
if (msg.what == Flags.RECEIVED_CAR_DATA)
|
||||
{
|
||||
byte[] recv = (byte[]) msg.obj;
|
||||
@@ -139,16 +138,9 @@ public class MainActivity extends AppCompatActivity
|
||||
case Commands.RECEIVE_QR:
|
||||
byte[] cmd = RecognizeQrCode();
|
||||
CommandEncoder encoder = new CommandEncoder();
|
||||
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_1,cmd[0],cmd[1],cmd[2]));
|
||||
try
|
||||
{
|
||||
Thread.sleep(500);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_2,cmd[3],cmd[4],cmd[5]));
|
||||
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_1, cmd[0], cmd[1], cmd[2]));
|
||||
Sleep(500);
|
||||
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_2, cmd[3], cmd[4], cmd[5]));
|
||||
break;
|
||||
case Commands.RECEIVE_TRAFFIC_LIGHT:
|
||||
dtc_client.Send(RecognizeTrafficLight());
|
||||
@@ -174,12 +166,14 @@ public class MainActivity extends AppCompatActivity
|
||||
ToastLog("NULL Received", true, false);
|
||||
|
||||
}
|
||||
//接收到打印数组的指令,打印数组
|
||||
if (msg.what == Flags.PRINT_DATA_ARRAY)
|
||||
{
|
||||
byte[] data = (byte[]) msg.obj;
|
||||
if (data != null)
|
||||
ToastLog("SEND: [" + ByteArray2String(data) + "]", false, false);
|
||||
}
|
||||
//接收到打印日志的指令,打印日志
|
||||
if(msg.what == Flags.PRINT_SYSTEM_LOG)
|
||||
{
|
||||
String str = (String)msg.obj;
|
||||
@@ -322,6 +316,8 @@ public class MainActivity extends AppCompatActivity
|
||||
return;
|
||||
}
|
||||
CommandEncoder encoder = new CommandEncoder();
|
||||
dtc_client.Send(encoder.GenerateCommand(Commands.OCR_TEXT_SUCCESS, (byte) 0x00, (byte) 0x00, (byte) 0x00));
|
||||
Sleep(500);
|
||||
dtc_client.Send(encoder.GenerateCommand(Commands.OCR_TEXT_LENGTH, (byte) b_str.length, (byte) 0x00, (byte) b_str.length));
|
||||
for (int i = 0; i < b_str.length; i += 2)
|
||||
{
|
||||
@@ -446,6 +442,7 @@ public class MainActivity extends AppCompatActivity
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void ToastLog(String text, boolean real_toast, boolean on_thread)
|
||||
{
|
||||
if (text_toast == null)
|
||||
@@ -526,7 +523,6 @@ public class MainActivity extends AppCompatActivity
|
||||
ToastLog("DHCP Server Address: " + IPCar, false, false);
|
||||
|
||||
//建立连接
|
||||
// client = new Client(IPCar, 60000, recvHandler); //在此启动接收数据方法
|
||||
if(CommunicationUsingWifi)
|
||||
dtc_client = new WifiTransferCore(IPCar,60000, recvHandler);
|
||||
else
|
||||
@@ -539,7 +535,7 @@ public class MainActivity extends AppCompatActivity
|
||||
});
|
||||
th_connect.start();
|
||||
while(th_connect.isAlive())
|
||||
Sleep(1); //Wait for Connection Thread
|
||||
Sleep(10); //Wait for Connection Thread
|
||||
dtc_client.EnableAutoReconnect(); //启动自动重连
|
||||
|
||||
//初始化摄像头控制
|
||||
@@ -602,6 +598,7 @@ public class MainActivity extends AppCompatActivity
|
||||
protected void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
dtc_client.DisableAutoReconnect();
|
||||
dtc_client.CloseConnection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user