|
|
@ -6,6 +6,7 @@
|
|
|
|
package com.uns.maincar.gui;
|
|
|
|
package com.uns.maincar.gui;
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
@ -26,8 +27,6 @@ import android.widget.Toast;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
|
|
import com.bkrcl.control_car_video.camerautil.CameraCommandUtil;
|
|
|
|
|
|
|
|
import com.bkrcl.control_car_video.camerautil.SearchCameraUtil;
|
|
|
|
|
|
|
|
import com.uns.maincar.R;
|
|
|
|
import com.uns.maincar.R;
|
|
|
|
import com.uns.maincar.communication.CommandDecoder;
|
|
|
|
import com.uns.maincar.communication.CommandDecoder;
|
|
|
|
import com.uns.maincar.communication.CommandEncoder;
|
|
|
|
import com.uns.maincar.communication.CommandEncoder;
|
|
|
@ -49,6 +48,8 @@ import com.uns.maincar.cpp_interface.TrafficSign;
|
|
|
|
import com.uns.maincar.tools.ImageReleaser;
|
|
|
|
import com.uns.maincar.tools.ImageReleaser;
|
|
|
|
import com.uns.maincar.tools.OCRDataReleaser;
|
|
|
|
import com.uns.maincar.tools.OCRDataReleaser;
|
|
|
|
import com.uns.maincar.tools.TextFilter;
|
|
|
|
import com.uns.maincar.tools.TextFilter;
|
|
|
|
|
|
|
|
import com.uns.maincar.tools.camera.CameraOperator;
|
|
|
|
|
|
|
|
import com.uns.maincar.tools.camera.CameraSearcher;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
@ -74,10 +75,8 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
private ImageView pic_received;
|
|
|
|
private ImageView pic_received;
|
|
|
|
//控件——存储Toast的内容,由ToastLog()进行管理
|
|
|
|
//控件——存储Toast的内容,由ToastLog()进行管理
|
|
|
|
private TextView text_toast;
|
|
|
|
private TextView text_toast;
|
|
|
|
//控制主车相机
|
|
|
|
|
|
|
|
private CameraCommandUtil cameraCommandUtil;
|
|
|
|
|
|
|
|
//寻找主车相机
|
|
|
|
//寻找主车相机
|
|
|
|
private SearchCameraUtil searchCameraUtil = null;
|
|
|
|
private CameraSearcher cameraSearcher = null;
|
|
|
|
//程序状态,通过所有自检后会设置为true
|
|
|
|
//程序状态,通过所有自检后会设置为true
|
|
|
|
private boolean SystemStatus = false;
|
|
|
|
private boolean SystemStatus = false;
|
|
|
|
//文件状态,获取到存储权限并释放完毕所有文件会设置为true
|
|
|
|
//文件状态,获取到存储权限并释放完毕所有文件会设置为true
|
|
|
@ -224,7 +223,22 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
//处理二维码数据,使用从C++代码中导出的算法
|
|
|
|
//处理二维码数据,使用从C++代码中导出的算法
|
|
|
|
private byte[] ProcessQRData(ArrayList<String> qr_data)
|
|
|
|
private byte[] ProcessQRData(ArrayList<String> qr_data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return MainCarAES.CalcAES(qr_data.get(0));
|
|
|
|
String validate_result = "";
|
|
|
|
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
|
|
|
|
TextFilter filter = new TextFilter();
|
|
|
|
|
|
|
|
for (String data : qr_data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String processed_data = filter.LetterAndNumber(data);
|
|
|
|
|
|
|
|
if (processed_data.length() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
validate_result = processed_data;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validate_result.equals(""))
|
|
|
|
|
|
|
|
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return MainCarAES.CalcAES(validate_result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取程序自检指令,根据自检状态返回成功或失败
|
|
|
|
//获取程序自检指令,根据自检状态返回成功或失败
|
|
|
@ -414,7 +428,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
private void OCRRecognizeText()
|
|
|
|
private void OCRRecognizeText()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TextFilter filter = new TextFilter();
|
|
|
|
TextFilter filter = new TextFilter();
|
|
|
|
String str = filter.NoUnderLine(filter.RemoveEmptyCharacter(OCR.DecodeImage(currImage)));
|
|
|
|
String str = filter.ChineseOnly(filter.RemoveEmptyCharacter(OCR.DecodeImage(currImage)));
|
|
|
|
ToastLog("OCR Result: [" + str + "]", false, true);
|
|
|
|
ToastLog("OCR Result: [" + str + "]", false, true);
|
|
|
|
byte[] b_str;
|
|
|
|
byte[] b_str;
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -455,8 +469,8 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
return msg_str.toString();
|
|
|
|
return msg_str.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//向主车发送一条任务指令
|
|
|
|
//向主车发送一条任务指令(改为protected允许类外调用)
|
|
|
|
private void SendTaskCommand(byte task_cmd)
|
|
|
|
protected void SendTaskCommand(byte task_cmd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
@ -469,98 +483,101 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//初始化比赛任务按钮
|
|
|
|
/*
|
|
|
|
private void InitTaskButton()
|
|
|
|
以下protected函数用于在主界面外允许对主界面功能的调用,利用静态MainActivity对象绕过Android对不同Activity间函数调用的限制
|
|
|
|
|
|
|
|
此操(mo)作(fa)仅用于实现UI分离和操作逻辑优化,与实际功能代码无关。
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
//----------------------------------------由此处开始----------------------------------------
|
|
|
|
|
|
|
|
//用于调试页面的发送调试信息函数
|
|
|
|
|
|
|
|
protected void DebugPageCallback_DebugSend()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
findViewById(R.id.btn_task_0).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_0));
|
|
|
|
byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
|
|
|
|
findViewById(R.id.btn_task_1).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_1));
|
|
|
|
dtc_client.ThreadSend(data);
|
|
|
|
findViewById(R.id.btn_task_2).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_2));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_3).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_3));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_4).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_4));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_5).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_5));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_6).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_6));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_7).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_7));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_8).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_8));
|
|
|
|
|
|
|
|
findViewById(R.id.btn_task_9).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_9));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//初始化图形界面
|
|
|
|
//用于调试页面的发送调试信息函数
|
|
|
|
private void InitGUI()
|
|
|
|
protected void DebugPageCallback_SendByInput(Activity context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pic_received = findViewById(R.id.camera_image);
|
|
|
|
try
|
|
|
|
text_toast = findViewById(R.id.text_toast);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text_toast.setMovementMethod(ScrollingMovementMethod.getInstance());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_debug_send).setOnClickListener(view ->
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
|
|
|
|
byte cmd0 = (byte) Integer.parseInt(((EditText) context.findViewById(R.id.edit_cmd0)).getText().toString(), 16);
|
|
|
|
dtc_client.ThreadSend(data);
|
|
|
|
byte cmd1 = (byte) Integer.parseInt(((EditText) context.findViewById(R.id.edit_cmd1)).getText().toString(), 16);
|
|
|
|
});
|
|
|
|
byte cmd2 = (byte) Integer.parseInt(((EditText) context.findViewById(R.id.edit_cmd2)).getText().toString(), 16);
|
|
|
|
|
|
|
|
byte cmd3 = (byte) Integer.parseInt(((EditText) context.findViewById(R.id.edit_cmd3)).getText().toString(), 16);
|
|
|
|
findViewById(R.id.btn_camera_up).setOnClickListener(view ->
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
|
|
|
|
byte[] cmd = encoder.GenerateCommand(cmd0, cmd1, cmd2, cmd3);
|
|
|
|
|
|
|
|
dtc_client.ThreadSend(cmd);
|
|
|
|
|
|
|
|
//print debug information
|
|
|
|
|
|
|
|
Message.obtain(recvHandler, Flags.PRINT_DATA_ARRAY, cmd).sendToTarget();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() -> cameraCommandUtil.postHttp(IPCamera, Flags.CAMERA_UP, 5));
|
|
|
|
ToastLog("Input Data Invalidate", true, false);
|
|
|
|
th_send.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_camera_down).setOnClickListener(view ->
|
|
|
|
//提供给单元测试页面用于初始化按钮的回调函数
|
|
|
|
|
|
|
|
protected void InitSingleFunctionTestUnit(Activity context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.findViewById(R.id.btn_camera_up).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() -> cameraCommandUtil.postHttp(IPCamera, Flags.CAMERA_DOWN, 5));
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_UP, 5))
|
|
|
|
|
|
|
|
ToastLog("Camera Command (UP) Failure.", false, true);
|
|
|
|
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_camera_left).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_camera_down).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() -> cameraCommandUtil.postHttp(IPCamera, Flags.CAMERA_LEFT, 5));
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_DOWN, 5))
|
|
|
|
|
|
|
|
ToastLog("Camera Command (DOWN) Failure.", false, true);
|
|
|
|
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_camera_right).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_camera_left).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() -> cameraCommandUtil.postHttp(IPCamera, Flags.CAMERA_RIGHT, 5));
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_LEFT, 5))
|
|
|
|
|
|
|
|
ToastLog("Camera Command (LEFT) Failure.", false, true);
|
|
|
|
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_send).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_camera_right).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
byte cmd0 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd0)).getText().toString(), 16);
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_RIGHT, 5))
|
|
|
|
byte cmd1 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd1)).getText().toString(), 16);
|
|
|
|
ToastLog("Camera Command (RIGHT) Failure.", false, true);
|
|
|
|
byte cmd2 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd2)).getText().toString(), 16);
|
|
|
|
});
|
|
|
|
byte cmd3 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd3)).getText().toString(), 16);
|
|
|
|
th_send.start();
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
|
|
|
|
byte[] cmd = encoder.GenerateCommand(cmd0, cmd1, cmd2, cmd3);
|
|
|
|
|
|
|
|
dtc_client.ThreadSend(cmd);
|
|
|
|
|
|
|
|
//print debug information
|
|
|
|
|
|
|
|
Message.obtain(recvHandler, Flags.PRINT_DATA_ARRAY, cmd).sendToTarget();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ToastLog("Input Data Invalidate", true, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_start_qr).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_qr).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("QR Code Started", false, false);
|
|
|
|
ToastLog("QR Code Started", false, false);
|
|
|
|
ToastLog("QR Result: " + ByteArray2String(RecognizeQrCode()), false, false);
|
|
|
|
ToastLog("QR Result: " + ByteArray2String(RecognizeQrCode()), false, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_start_light).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_light).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("Traffic Light Started", false, false);
|
|
|
|
ToastLog("Traffic Light Started", false, false);
|
|
|
|
ToastLog("TL Result: " + ByteArray2String(RecognizeTrafficLight()), false, false);
|
|
|
|
ToastLog("TL Result: " + ByteArray2String(RecognizeTrafficLight()), false, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_start_color_shape).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_color_shape).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("Color Shape Started", false, false);
|
|
|
|
ToastLog("Color Shape Started", false, false);
|
|
|
|
ToastLog("CS Result: " + ByteArray2String(RecognizeShapeColor()), false, false);
|
|
|
|
ToastLog("CS Result: " + ByteArray2String(RecognizeShapeColor()), false, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_start_car_id).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_car_id).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("Car ID Started", false, false);
|
|
|
|
ToastLog("Car ID Started", false, false);
|
|
|
|
Thread th_debug = new Thread(this::RecognizeCarID);
|
|
|
|
Thread th_debug = new Thread(this::RecognizeCarID);
|
|
|
@ -568,38 +585,70 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
ToastLog("CID Finished", false, false);
|
|
|
|
ToastLog("CID Finished", false, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_start_sign).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_sign).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("Traffic Sign Started", false, false);
|
|
|
|
ToastLog("Traffic Sign Started", false, false);
|
|
|
|
ToastLog("TS Result: " + ByteArray2String(RecognizeTrafficSign()), false, false);
|
|
|
|
ToastLog("TS Result: " + ByteArray2String(RecognizeTrafficSign()), false, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_start_ocr).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_ocr).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("OCR Started", false, false);
|
|
|
|
ToastLog("OCR Started", false, false);
|
|
|
|
Thread th_debug = new Thread(this::OCRRecognizeText);
|
|
|
|
Thread th_debug = new Thread(this::OCRRecognizeText);
|
|
|
|
th_debug.start();
|
|
|
|
th_debug.start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_tft_page_down).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_tft_page_down).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
dtc_client.ThreadSend(encoder.GenerateCommand(Commands.TFT_PAGE_DOWN, (byte) 0, (byte) 0, (byte) 0));
|
|
|
|
dtc_client.ThreadSend(encoder.GenerateCommand(Commands.TFT_PAGE_DOWN, (byte) 0, (byte) 0, (byte) 0));
|
|
|
|
ToastLog("TFT Page Down Command Send.", false, true);
|
|
|
|
ToastLog("TFT Page Down Command Send.", false, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_movement_control).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_movement_control).setOnClickListener(view -> startActivity(new Intent(this, MovementController.class)));
|
|
|
|
{
|
|
|
|
|
|
|
|
startActivity(new Intent(this, MovementController.class));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_crash).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_crash).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//崩溃按钮的作用:频繁调试时省去手动退出程序,清理后台的操作,节省时间。
|
|
|
|
//崩溃按钮的作用:频繁调试时省去手动退出程序,清理后台的操作,节省时间。
|
|
|
|
dtc_client.DisableAutoReconnect();
|
|
|
|
dtc_client.DisableAutoReconnect();
|
|
|
|
dtc_client.CloseConnection(); //关闭通信
|
|
|
|
dtc_client.CloseConnection(); //关闭通信
|
|
|
|
throw new NullPointerException(); //通过异常来崩溃。
|
|
|
|
throw new NullPointerException(); //通过异常来崩溃。
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------到此处终止----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//初始化图形界面
|
|
|
|
|
|
|
|
private void InitGUI()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pic_received = findViewById(R.id.camera_image);
|
|
|
|
|
|
|
|
text_toast = findViewById(R.id.text_toast);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text_toast.setMovementMethod(ScrollingMovementMethod.getInstance());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_debug_page).setOnClickListener(view ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DebugPage.Parent = this;
|
|
|
|
|
|
|
|
startActivity(new Intent(this, DebugPage.class));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_function_test).setOnClickListener(view ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SingleFunctionTest.Parent = this;
|
|
|
|
|
|
|
|
startActivity(new Intent(this, SingleFunctionTest.class));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_race_tasks).setOnClickListener(view ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RaceTasks.Parent = this;
|
|
|
|
|
|
|
|
startActivity(new Intent(this, RaceTasks.class));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.btn_program_exit).setOnClickListener(view ->
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dtc_client.DisableAutoReconnect();
|
|
|
|
|
|
|
|
dtc_client.CloseConnection(); //关闭通信
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.text_toast).setOnLongClickListener(view ->
|
|
|
|
findViewById(R.id.text_toast).setOnLongClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -617,8 +666,6 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
ToastLog("Image Save Failure", true, false);
|
|
|
|
ToastLog("Image Save Failure", true, false);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
InitTaskButton();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//打印日志
|
|
|
|
//打印日志
|
|
|
@ -650,14 +697,14 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//启动寻找摄像头的线程
|
|
|
|
//启动获取摄像头拍摄到的图片的线程
|
|
|
|
private void StartCameraImageUpdate(int duration)
|
|
|
|
private void StartCameraImageUpdate(int duration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_image = new Thread(() ->
|
|
|
|
Thread th_image = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
currImage = cameraCommandUtil.httpForImage(IPCamera);
|
|
|
|
currImage = CameraOperator.GetImage(IPCamera);
|
|
|
|
recvHandler.sendEmptyMessage(Flags.RECEIVED_IMAGE);
|
|
|
|
recvHandler.sendEmptyMessage(Flags.RECEIVED_IMAGE);
|
|
|
|
Sleep(duration);
|
|
|
|
Sleep(duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -723,29 +770,20 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
Sleep(10); //Wait for Connection Thread
|
|
|
|
Sleep(10); //Wait for Connection Thread
|
|
|
|
dtc_client.EnableAutoReconnect(); //启动自动重连
|
|
|
|
dtc_client.EnableAutoReconnect(); //启动自动重连
|
|
|
|
|
|
|
|
|
|
|
|
//初始化摄像头控制
|
|
|
|
|
|
|
|
cameraCommandUtil = new CameraCommandUtil();
|
|
|
|
|
|
|
|
ToastLog("CameraCommandUtil Ready.", false, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//寻找摄像头,获取其IP地址
|
|
|
|
//寻找摄像头,获取其IP地址
|
|
|
|
Thread camera_thread = new Thread(() ->
|
|
|
|
Thread camera_thread = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IPCamera = null;
|
|
|
|
boolean success;
|
|
|
|
ToastLog("CameraSearchThread: Camera Thread Start", false, true);
|
|
|
|
ToastLog("CameraSearchThread: Camera Thread Start", false, true);
|
|
|
|
while (IPCamera == null || IPCamera.equals(""))
|
|
|
|
cameraSearcher = new CameraSearcher();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
{
|
|
|
|
searchCameraUtil = new SearchCameraUtil();
|
|
|
|
success = cameraSearcher.SearchOnce();
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
IPCamera = searchCameraUtil.send();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (NullPointerException e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
IPCamera = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!success); //避免”while循环具有空体“警告
|
|
|
|
|
|
|
|
IPCamera = cameraSearcher.GetCameraIP();
|
|
|
|
ToastLog("CameraSearchThread: Camera Found. IP: " + IPCamera, false, true);
|
|
|
|
ToastLog("CameraSearchThread: Camera Found. IP: " + IPCamera, false, true);
|
|
|
|
IPCamera = IPCamera + ":81";
|
|
|
|
IPCamera += ":81";
|
|
|
|
ToastLog("Camera Address: " + IPCamera, false, true);
|
|
|
|
ToastLog("Camera Address: " + IPCamera, false, true);
|
|
|
|
StartCameraImageUpdate(50);
|
|
|
|
StartCameraImageUpdate(50);
|
|
|
|
//这里是程序初始化的最后一步,能到达此处标志着自检通过
|
|
|
|
//这里是程序初始化的最后一步,能到达此处标志着自检通过
|
|
|
@ -786,7 +824,5 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
//Activity销毁时关闭通信
|
|
|
|
//Activity销毁时关闭通信
|
|
|
|
dtc_client.DisableAutoReconnect();
|
|
|
|
dtc_client.DisableAutoReconnect();
|
|
|
|
dtc_client.CloseConnection();
|
|
|
|
dtc_client.CloseConnection();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|