|
|
|
@ -121,6 +121,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
//接收内部消息的处理器,用于处理内部消息
|
|
|
|
|
recvHandler = new Handler()
|
|
|
|
|
{
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
|
|
@Override
|
|
|
|
|
public void handleMessage(Message msg)
|
|
|
|
|
{
|
|
|
|
@ -128,6 +129,20 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
//内部消息:收到图片;执行操作:更新GUI上的图片
|
|
|
|
|
if (msg.what == Flags.RECEIVED_IMAGE)
|
|
|
|
|
pic_received.setImageBitmap(currImage);
|
|
|
|
|
//内部消息:打印数组;操作:打印收到的数组
|
|
|
|
|
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;
|
|
|
|
|
if (str != null)
|
|
|
|
|
ToastLog(str, false, false);
|
|
|
|
|
}
|
|
|
|
|
//内部消息:收到主车数据;执行操作:解析指令并执行
|
|
|
|
|
if (msg.what == Flags.RECEIVED_CAR_DATA)
|
|
|
|
|
{
|
|
|
|
@ -135,7 +150,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
if (recv != null)
|
|
|
|
|
{
|
|
|
|
|
//打印接收到的指令
|
|
|
|
|
ToastLog("RECV: [" + ByteArray2String(recv) + "]", true, false);
|
|
|
|
|
ToastLog("RECV: [" + ByteArray2String(recv) + "]", false, false);
|
|
|
|
|
//解析指令
|
|
|
|
|
CommandDecoder decoder = new CommandDecoder(recv);
|
|
|
|
|
if (decoder.CommandReady())
|
|
|
|
@ -201,21 +216,6 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
//收到NULL,输出日志,不做操作
|
|
|
|
|
else
|
|
|
|
|
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;
|
|
|
|
|
if (str != null)
|
|
|
|
|
ToastLog(str, false, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -455,6 +455,35 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
return msg_str.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//向主车发送一条任务指令
|
|
|
|
|
private void SendTaskCommand(byte task_cmd)
|
|
|
|
|
{
|
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
|
{
|
|
|
|
|
if (dtc_client.Send(encoder.GenerateCommand(Commands.RUN_SINGE_TASK, task_cmd, (byte) 0x00, (byte) 0x00)))
|
|
|
|
|
ToastLog("Send Task Command: " + byte_str[task_cmd & 0xff], false, true);
|
|
|
|
|
else
|
|
|
|
|
ToastLog("Failed to Send Task Command: " + byte_str[task_cmd & 0xff], false, true);
|
|
|
|
|
});
|
|
|
|
|
th_send.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//初始化比赛任务按钮
|
|
|
|
|
private void InitTaskButton()
|
|
|
|
|
{
|
|
|
|
|
findViewById(R.id.btn_task_0).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_0));
|
|
|
|
|
findViewById(R.id.btn_task_1).setOnClickListener(view -> SendTaskCommand(Commands.TASK_NUMBER_1));
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
@ -548,7 +577,6 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
findViewById(R.id.btn_start_ocr).setOnClickListener(view ->
|
|
|
|
|
{
|
|
|
|
|
ToastLog("OCR Started", false, false);
|
|
|
|
|
/*ToastLog("OCR Result: " + OCR.DecodeImage(currImage), false, false);*/
|
|
|
|
|
Thread th_debug = new Thread(this::OCRRecognizeText);
|
|
|
|
|
th_debug.start();
|
|
|
|
|
});
|
|
|
|
@ -589,6 +617,8 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
ToastLog("Image Save Failure", true, false);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
InitTaskButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//打印日志
|
|
|
|
@ -599,12 +629,14 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
text_toast = findViewById(R.id.text_toast);
|
|
|
|
|
if (real_toast)
|
|
|
|
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
|
|
|
|
Log.i("ToastBackup", text);
|
|
|
|
|
if (on_thread)
|
|
|
|
|
Message.obtain(recvHandler, Flags.PRINT_SYSTEM_LOG, text);
|
|
|
|
|
Message.obtain(recvHandler, Flags.PRINT_SYSTEM_LOG, text).sendToTarget();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.i("ToastBackup", text);
|
|
|
|
|
text_toast.setText(text_toast.getText().toString() + "\n" + text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//等待一段时间
|
|
|
|
|
private void Sleep(long ms)
|
|
|
|
@ -754,5 +786,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
|
//Activity销毁时关闭通信
|
|
|
|
|
dtc_client.DisableAutoReconnect();
|
|
|
|
|
dtc_client.CloseConnection();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|