code clean

master
UnknownObject 3 years ago
parent 88f450c48a
commit 254ef1e18b

@ -237,7 +237,7 @@ namespace uns
extern "C" JNIEXPORT
jint JNICALL
Java_com_uns_maincar_cpp_1interface_TrafficLight_Recognize(JNIEnv *env, jclass _this, jobject image, jint offset)
Java_com_uns_maincar_cpp_1interface_TrafficLight_Recognize(JNIEnv *env, jclass _this, jobject image)
{
cv::Mat img;
if(!BitmapToMat(env,image,img))

@ -1,682 +0,0 @@
package com.uns.maincar.communication;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.uns.maincar.constants.Flags;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
/*
*
*/
public class Client
{
private final int port;
private final String IP;
private final Handler handler;
private final byte[] tema = new byte[6];
private final int[] a = new int[48];
private final int[] a1 = new int[48];
private final int[] a2 = new int[8];
private final int[] a3 = new int[6];
private Socket socket;
private DataInputStream dis;
private DataOutputStream dos; //输出流,写入数据
private byte[] mByte;
private final Thread recive = new Thread(new Runnable()
{
@Override
public void run()
{
Log.i(Flags.CLIENT_TAG, "启动线程方法");
try
{
socket = new Socket(IP, port);
Log.i(Flags.CLIENT_TAG, "接收方法");
if (!socket.isClosed())
{
Log.i(Flags.CLIENT_TAG, "socket未关闭执行");
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
while (socket.isConnected())
{
mByte = new byte[30];
dis.read(mByte, 0, mByte.length);
Log.i(Flags.CLIENT_TAG, "接收来自小车消息" + mByte[0] + mByte[1] + mByte[2] + mByte[3] + mByte[4] + mByte[5]);
// if (mByte[0]==0x55){
//
// Message msg=new Message();
// msg.what=1;
// handler.sendMessage(msg);
//
// }
Message message = Message.obtain(handler, Flags.RECEIVED_CAR_DATA, mByte); //新建message对象
message.sendToTarget(); //给handler发送消息
}
}
}
catch (UnknownHostException e)
{
Log.i(Flags.TAG, "socket 未知主机名称");
}
catch (IOException e)
{
Log.i(Flags.TAG, "socket 创建Socket时发生IO错误" + e.getMessage());
}
catch (NullPointerException e)
{
Log.i(Flags.TAG, "socket Socket为空");
}
}
});
private byte main = 0x00, three = 0x00, four = 0x00, five = 0x00, sum = 0x00;
public boolean ConnectionValidate()
{
return (socket != null && !socket.isClosed());
}
public Client(String IP, int port, Handler handler)
{
Log.i(Flags.CLIENT_TAG, "初始化client");
this.IP = IP;
this.port = port;
this.handler = handler;
recive.start();
}
public static String getEvery(char[] ch, int i, int j)
{ //自定义截取部分字符串
int length = ch.length;
while (i >= 0 && j <= length - 1 && ch[i] == ch[j])
{
i--;
j++;
}
return String.valueOf(ch).substring(i + 1, j); //将char转为字符串从i开始截取到j并返回。
}
public static String getPalindrome(String s)
{ //回文算法
char[] ch = s.toCharArray();
String str = " ";
String re = "";
for (int i = 0; i < ch.length; i++)
{
re = getEvery(ch, i, i); // 当以一个字符为中轴也就是回文串为奇数时
if (re.length() > str.length())
{
str = re;
}
re = getEvery(ch, i, i + 1); // 当以当前和他后一个字符为轴心,也就是回文串为偶数时
if (re.length() > str.length())
{
str = re;
}
}
return str;
}
/**
* 8
*/
private void send()
{
Log.e(Flags.SEND_TAG, "send测试开始");
sum = (byte) ((main + three + four + five) % 0xff);
Log.e(Flags.SEND_TAG, "send测试1");
/* 0x55,0xaa,主指令,[3],[4],[5],sum,0xbb */
byte[] mbyte = {0x55, (byte) 0xaa, main, three, four, five, sum, (byte) 0xbb};
Log.e(Flags.SEND_TAG, "send测试2");
//Log.e("123", "send测试mbyte数组内容"+mbyte[0]+" "+mbyte[1]+" "+mbyte[2]+" "+mbyte[3]+" "+mbyte[4]+" "+mbyte[5]+" "+mbyte[6]+" "+mbyte[7]+" ");
try
{
if (!socket.isClosed() && socket != null)
{
dos.write(mbyte, 0, mbyte.length);
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
catch (NullPointerException e)
{
e.printStackTrace();
}
}
/**
*
*
* @param rbyte
*/
public void send(byte[] rbyte)
{ //制定dos文件的长度
try
{
if (socket != null && !socket.isClosed())
{
dos.write(rbyte, 0, rbyte.length);
dos.flush(); //刷新dos数据
Message.obtain(handler, Flags.PRINT_DATA_ARRAY, rbyte).sendToTarget();
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
catch (NullPointerException e)
{
e.printStackTrace();
}
}
public String find(String s)
{ //找最长回文
String str = s;
String result = getPalindrome(str);
return result;
}
public void sendlt(int i)
{ //发送回文长度届时直接用str.length作为参数即可。
try
{
if (!socket.isClosed() && socket != null)
{
dos.write(i);
dos.flush();
}
}
catch (Exception ioe)
{
}
}
/**
*
*
* @param head1
* @param head2
*/
private void send(byte head1, byte head2)
{
sum = (byte) ((main + three + four + five) % 0xff);
/* 0x55,0x0b,主指令,[3],[4],[5],sum,0xbb */
byte[] mbyte = {head1, head2, main, three, four, five, sum, (byte) 0xbb};
try
{
if (!socket.isClosed() && socket != null)
{
dos.write(mbyte, 0, mbyte.length);
dos.flush();
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
catch (NullPointerException e)
{
e.printStackTrace();
}
}
/**
*
*
* @param textbyte
*/
public void send_voice(final byte[] textbyte)
{
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
// 发送数据字节数组
if (socket != null && !socket.isClosed())
{
dos.write(textbyte, 0, textbyte.length);
dos.flush();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}).start();
}
/* public void scanComplate() {
send();
}*/
/**
*
*/
public void sendCheTouCheKu(final byte[] rbyte)
{
new Thread(new Runnable()
{
@Override
public void run()
{
String s = "";
for (int i = 0; i < 16; i++)
{
s += (char) rbyte[i + 4];
}
String chetou = s.substring(s.indexOf("->") - 2, s.indexOf("->"));
int cheku = s.substring(s.indexOf("->") + 2, s.indexOf("->") + 3).charAt(0);
if (chetou.equals("B4"))
{
main = 1;
}
else if (chetou.equals("D6"))
{
main = 2;
}
else if (chetou.equals("D2"))
{
main = 3;
}
else
{
main = 4;
}
switch (cheku)
{
case 'A':
three = 1;
break;
case 'B':
three = 2;
break;
case 'C':
three = 3;
break;
case 'D':
three = 4;
break;
case 'E':
three = 5;
break;
case 'F':
three = 6;
break;
default:
three = 3;
break;
}
Log.i(Flags.TAG, "发送, 车头:" + chetou + "车库:" + cheku);
delayMs(300);
send();
}
}).start();
}
public void startDelectRemind(final int startRemindCode)
{
new Thread(new Runnable()
{
@Override
public void run()
{
main = (byte) 0x60;
Log.e("123", "提醒待发送1");
if (startRemindCode == Flags.NUMBER_DETECT_REMIND)
{
three = (byte) 0x01;
}
else if (startRemindCode == Flags.DIRECTION_DETECT_REMIND)
{
three = (byte) 0x02;
}
else if (startRemindCode == Flags.QR1_DETECT_REMIND)
{
three = (byte) 0x03;
}
else if (startRemindCode == Flags.QR2_DETECT_REMIND)
{
three = (byte) 0x04;
}
else if (startRemindCode == Flags.SHAPES_DETECT_REMIND)
{
three = (byte) 0x05;
}
Log.e(Flags.SEND_TAG, "提醒待发送if");
send();
Log.e(Flags.SEND_TAG, "提醒发送完成");
}
}).start();
}
public void sendCarNumber(final String number)
{
// main = (byte) number.charAt(0);
// three = (byte) number.charAt(2); //数据发送[3]根据为车牌号[2]所制定的指令码
// four = (byte) number.charAt(2);
// five = (byte) number.charAt(3);
// send();
int a = Integer.valueOf(number.charAt(2)) - 48;
//main = (byte) number.charAt(0);
main = (byte) 0x21;
if (a % 2 != 0)
{
three = (byte) 0x11;
}
else
{
three = (byte) 0x22;
}
// three = (byte) number.charAt(2);
four = (byte) 0x00;
five = (byte) 0x00;
sum = (byte) 0x21;
delayMs(300);
// main = (byte) number.charAt(4);
// three = (byte) number.charAt(5);
send();
Log.i(Flags.TAG, "车牌号发送完成");
}
public void sendCarNumber(byte[] number)
{
send(number); //发送数据
Log.i(Flags.TAG, "车牌号发送完成");
}
public void sendDirection(String direction)
{
if (direction.equals("左转"))
{
five = 0x04;
}
else if (direction.equals("右转"))
{
five = 0x05;
}
else
{
five = 0x06;
}
send();
}
public void sendDirection(byte[] direction)
{
send(direction);
}
public void sendShapeInfo(byte rectangle, byte circle, byte triangle)
{
main = rectangle;
three = circle;
four = triangle;
send();
}
public void sendShapeInfo(byte[] info)
{
send(info);
}
public void sendPassWD()
{
new Thread(new Runnable()
{
@Override
public void run()
{
main = 0x01;
three = 0x02;
four = 0x03;
five = 0x04;
send();
delayMs(300);
main = 0x05;
three = 0x06;
send();
}
}).start();
}
public void sendLightValue(final int v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
switch (v)
{
case 1:
five = 0x07;
break;
case 2:
five = 0x08;
break;
case 3:
five = 0x09;
break;
case 4:
five = 0x10;
break;
default:
five = 0x09;
break;
}
delayMs(300);
send();
}
}).start();
}
public void sendArray(byte[] rbyte)
{
byte[] bytes = new byte[16];
int c = 0;
for (byte b : rbyte)
{
Log.d(Flags.TAG, "[" + c++ + "] =" + Integer.toHexString(b));
}
for (int i = 0; i < bytes.length; i++)
{
bytes[i] = rbyte[4 + i];
}
send(bytes);
}
public void sendCRC(byte[] mBytes)
{ //CRC校验。。
char reg = 0xffff;
byte[] bytes = {mBytes[4], mBytes[5], mBytes[6], mBytes[7]};
// for (int i = 0; i < bytes.length; i++) {
// Log.d(Flag.TAG, "bytes[" + i + "]=" + Integer.toHexString(bytes[i]));
// }
for (int i = 0; i < bytes.length; i++)
{
reg = (char) (bytes[i] ^ reg);
for (int j = 0; j < 8; j++)
{
if ((byte) (reg & 0x01) == 0x01)
{
reg = (char) (reg >> 1);
reg = (char) (reg ^ 0xa001);
}
else
{
reg = (char) (reg >> 1);
}
}
}
four = (byte) (reg & 0xff);
five = (byte) ((reg >> 8) & 0xff);
Log.d(Flags.TAG, "sendCRC: four:" + Integer.toHexString(four) + ", five:" + Integer.toHexString(five));
Log.i(Flags.TAG, "four" + Integer.toHexString(four) + ", five:" + Integer.toHexString(five));
send();
}
private int hanmingma()
{
int i, N = 1, temp, j;
//此for语句作用讲16进制转成数组形式的二进制。如将0X03转成啊a[]={1,1,0,...},
//并将12481632位置变为0.
for (i = 0; i < 6; i++)
{
for (j = 0; j < 7; j++)
{
temp = tema[i];
if (N == 0 || N == 1 || N == 3 || N == 7 || N == 15 || N == 31)
{
N = N + 1;
}
if ((temp & 0x40) == 0x40)
{
a[N] = 1;
}
else
{
a[N] = 0;
}
tema[i] = (byte) (tema[i] << 1);
N = N + 1;
}
}
for (int v : a)
{
System.out.print(v + ", ");
}
//
for (i = 0; i < 48; i++)
{
if (a[i] == 1)
{
a1[i] = i + 1;
}
else
{
a1[i] = 0;
}
}
N = 0;
for (i = 0; i < 48; i++)
{
N = N ^ a1[i];
}
for (i = 0; i < 8; i++)
{
if ((N & 0x01) == 1)
{
a2[i] = 0x01;
}
else
{
a2[i] = 0;
}
N = N >> 1;
}
a[0] = a2[0];
a[1] = a2[1];
a[3] = a2[2];
a[7] = a2[3];
a[15] = a2[4];
a[31] = a2[5];
a3[0] = a[0] * 128 + a[1] * 64 + a[2] * 32 + a[3] * 16 + a[4] * 8 + a[5] * 4 + a[6] * 2 + a[7];
a3[1] = a[8] * 128 + a[9] * 64 + a[10] * 32 + a[11] * 16 + a[12] * 8 + a[13] * 4 + a[14] * 2 + a[15];
a3[2] = a[16] * 128 + a[17] * 64 + a[18] * 32 + a[19] * 16 + a[20] * 8 + a[21] * 4 + a[22] * 2 + a[23];
a3[3] = a[24] * 128 + a[25] * 64 + a[26] * 32 + a[27] * 16 + a[28] * 8 + a[29] * 4 + a[30] * 2 + a[31];
a3[4] = a[32] * 128 + a[33] * 64 + a[34] * 32 + a[35] * 16 + a[36] * 8 + a[37] * 4 + a[38] * 2 + a[39];
a3[5] = a[40] * 128 + a[41] * 64 + a[42] * 32 + a[43] * 16 + a[44] * 8 + a[45] * 4 + a[46] * 2 + a[47];
Log.d(Flags.TAG, "a3:");
for (int v : a3)
{
Log.d(Flags.TAG, v + ", ");
}
return N;
}
private void delayMs(int ms)
{
try
{
Thread.sleep(ms);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}

@ -5,8 +5,6 @@
package com.uns.maincar.communication;
import android.os.Handler;
/**
* @apiNote
* @implSpec Wifi

@ -37,8 +37,6 @@ public class SerialPortTransferCore implements DataTransferCore
private final File sp_device;
//数据处理器
private final Handler handler;
//最大单次数据接收大小
private final int MaxArraySize = 256;
//自动重连标志位
private boolean AutoReconnectFlag = false;
//数据接收线程运行标志位
@ -116,10 +114,10 @@ public class SerialPortTransferCore implements DataTransferCore
while(fd.valid())
{
DataReceivingFlag = true;
byte[] data = new byte[MaxArraySize];
try
{
if(fis.read(data, 0, MaxArraySize) != 0)
byte[] data = new byte[fis.available()];
if (fis.read(data, 0, data.length) != 0)
{
Log.i(Flags.CLIENT_TAG, "SerialPort Received.");
Message.obtain(handler, Flags.RECEIVED_CAR_DATA, data).sendToTarget();

@ -34,8 +34,6 @@ public class WifiTransferCore implements DataTransferCore
private DataOutputStream dos;
//数据处理器
private final Handler handler;
//最大单次数据接收大小
private final int MaxArraySize = 256;
//自动重连标志位
private boolean AutoReconnectFlag = false;
//数据接收线程运行标志位
@ -79,10 +77,10 @@ public class WifiTransferCore implements DataTransferCore
while(socket.isConnected())
{
DataReceivingFlag = true;
byte[] data = new byte[MaxArraySize];
try
{
if(dis.read(data, 0, MaxArraySize) != 0)
byte[] data = new byte[dis.available()];
if (dis.read(data, 0, data.length) != 0)
{
Log.i(Flags.CLIENT_TAG, "Wifi Socket Received.");
Message.obtain(handler, Flags.RECEIVED_CAR_DATA, data).sendToTarget();

@ -8,13 +8,8 @@ package com.uns.maincar.constants;
public class Flags
{
public static final String TAG = "MAIN-CAR-DEBUG";
//日志TAG
public static final String CLIENT_TAG = "MAIN-CAR-CLIENT";
public static final String SEND_TAG = "MAIN-CAR-CLIENT_SEND";
//摄像头运动步数
public static final int CAMERA_ONE_STEP = 1;
public static final int CAMERA_TWO_STEP = 2;
//摄像头控制指令
public static final int CAMERA_UP = 0;
@ -22,26 +17,7 @@ public class Flags
public static final int CAMERA_LEFT = 4;
public static final int CAMERA_RIGHT = 6;
public static final int CAMERA_INIT = 25;
//摄像头预设位调用与设置指令
public static final int CAMERA_RESET = 31;
public static final int CAMERA_SET_POS_1 = 32;
public static final int CAMERA_GET_POS_1 = 33;
public static final int CAMERA_SET_POS_2 = 34;
public static final int CAMERA_GET_POS_2 = 35;
public static final int CAMERA_SET_POS_3 = 36;
public static final int CAMERA_GET_POS_3 = 37;
public static final int CAMERA_SET_POS_4 = 38;
public static final int CAMERA_GET_POS_4 = 39;
//主/从车移动控制指令
public static final byte CMD_PACKET_HEAD = (byte) 0x55;
public static final byte CMD_PACKET_END = (byte) 0xBB;
public static final byte CMD_PACKET_MAIN_CAR = (byte) 0xAA;
public static final byte CMD_PACKET_SUB_CAR = (byte) 0x02;
public static final byte CMD_PACKET_MOVE_FORWARD = (byte) 0x02;
@ -51,52 +27,13 @@ public class Flags
public static final byte CMD_PACKET_MOVE_STOP = (byte) 0x01;
public static final byte CMD_PACKET_MOVE_TO_LINE = (byte) 0x06;
//图像和数据包
//recvHandler指令
public static final int RECEIVED_IMAGE = 11;
public static final int RECEIVED_CAR_DATA = 12;
public static final int PRINT_DATA_ARRAY = 13;
public static final int PRINT_SYSTEM_LOG = 14;
//颜色
//UnknownObject at 2022-09-18: 枚举类型足够用来替代这些常量了
/*public static final int ID_RED = 0;
public static final int ID_BLUE = 1;
public static final int ID_GREEN = 2;
public static final int ID_YELLOW = 3;
public static final int ID_CYAN = 4;
public static final int ID_MAGENTA = 5;
public static final int ID_BLACK = 6;
public static final int ID_WHITE = 7;
////////////////////////////////////////////////
public static final int ID_Light_RED = 8;
public static final int ID_Light_YELLOW = 9;
public static final int ID_Light_GREEN = 10;*/
//////////////////////////////////////////////////
//UnknownObject at 2022-09-18: 使用枚举类型替代字符串进行内部存储 (此类型已独立存储在GlobalColor类中)
/*public static final String RED = "red";
public static final String BLUE = "blue";
public static final String GREEN = "green";
public static final String YELLOW = "yellow";
public static final String CYAN = "cyan";
public static final String MAGENTA = "magenta";
public static final String BLACK = "black";
public static final String WHITE = "white";*/
/*public enum ShapeColors
{
RED,
BLUE,
GREEN,
YELLOW,
CYAN,
MAGENTA,
BLACK,
WHITE
}*/
//////////////////////////////////////////////////////
/*public static final String LIGHT_RED = "light_red";
public static final String LIGHT_YELLOW = "light_yellow";
public static final String LIGHT_GREEN = "light_green";*/
//交通灯颜色定义
public enum TrafficLightColors
{
RED,
@ -104,45 +41,4 @@ public class Flags
GREEN,
NULL
}
/////////////////////////////////////////////////////////////////
// 形状
//UnknownObject at 2022-09-18: 将常量封装进枚举类型中 (此类型已独立存储在GlobalShape类中)
/*public static final int SHAPE_RECTANGLE = 12, SHAPE_SQUARE = 8,
SHAPE_TRIANGLE = 9, SHAPE_CIRCLE = 10, SHAPE_STAR = 11,
SHAPE_DIAMOND = 13, SHAPE_OTERS = 14;*/
/*public enum Shapes
{
RECTANGLE,
SQUARE,
TRIANGLE,
CIRCLE,
STAR,
DIAMOND,
OTHERS
}*/
//箭头方向
public static final int LEFT = 15, RIGHT = 16, BACK = 17;
//超时标志qr1 - qr4
public static final int QR1_TIMER_OUT = 102;
public static final int QR2_TIMER_OUT = 103;
public static final int QR3_TIMER_OUT = 104;
public static final int QR4_TIMER_OUT = 105;
//图像识别方式
// 阈值识别方式
public static final int METHOD_THRESHOLD = 0;
// 过滤颜色识别方式
public static final int METHOD_FILTER = 1;
//识别指令前的提醒
public static final int NUMBER_DETECT_REMIND = 200;
public static final int DIRECTION_DETECT_REMIND = 201;
public static final int SHAPES_DETECT_REMIND = 202;
public static final int QR1_DETECT_REMIND = 203;
public static final int QR2_DETECT_REMIND = 204;
}

@ -19,7 +19,7 @@ public class CarLicense
public static class Result
{
boolean success = false;
boolean success;
byte[] chars = new byte[6];
public Result(String cpp_result)

@ -8,10 +8,13 @@ package com.uns.maincar.cpp_interface;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import com.googlecode.tesseract.android.TessBaseAPI;
import com.uns.maincar.R;
import java.io.File;
public class OCR
{
static
@ -29,7 +32,8 @@ public class OCR
public static String DecodeImage(Bitmap bitmap)
{
TessBaseAPI tessBaseApi = new TessBaseAPI();
tessBaseApi.init("/storage/emulated/0/MainCar/OCR/", "chi_sim");
String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "MainCar" + File.separator + "OCR" + File.separator;
tessBaseApi.init(path, "chi_sim");
tessBaseApi.setImage(ProcessImage(bitmap));
String extractedText = tessBaseApi.getUTF8Text();
tessBaseApi.end();

@ -5,10 +5,10 @@
package com.uns.maincar.cpp_interface;
import com.uns.maincar.constants.Flags.TrafficLightColors;
import android.graphics.Bitmap;
import com.uns.maincar.constants.Flags.TrafficLightColors;
public class TrafficLight
{
static
@ -16,11 +16,11 @@ public class TrafficLight
System.loadLibrary("traffic_light");
}
private static native int Recognize(Bitmap image, int offset);
private static native int Recognize(Bitmap image);
public static TrafficLightColors RecognizeTrafficLight(Bitmap image)
{
int res = Recognize(image, 58000);
int res = Recognize(image);
if (res == 0)
return TrafficLightColors.RED;
else if (res == 1)

@ -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();
}
}

@ -5,9 +5,6 @@
package com.uns.maincar.gui;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.DhcpInfo;
import android.net.wifi.WifiManager;
@ -17,15 +14,19 @@ import android.text.format.Formatter;
import android.view.MenuItem;
import android.widget.EditText;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import com.uns.maincar.R;
import com.uns.maincar.communication.DataTransferCore;
import com.uns.maincar.communication.SerialPortTransferCore;
import com.uns.maincar.communication.WifiTransferCore;
import com.uns.maincar.constants.Commands;
import com.uns.maincar.constants.Flags;
public class MovementController extends AppCompatActivity
{
private String IPCamera = "192.168.1.101:81";
//存储小车的IP
private String IPCar;
//通信客户端
@ -35,15 +36,21 @@ public class MovementController extends AppCompatActivity
//WIFI管理器
private WifiManager wifiManager;
//通信通道标志true为Wififalse为串口
private boolean CommunicationUsingWifi = true;
private final boolean CommunicationUsingWifi = true;
//串口通信的设备名
private final String SerialPortPath = "/dev/ttyS4";
//移动指令
private byte[] cmd_data = new byte[8];
private final byte[] cmd_data = new byte[8];
//编辑框——距离
EditText et_distance;
//编辑框——转向速度
EditText et_turn_speed;
//编辑框——循迹速度
EditText et_run_peed;
private int GetDistance()
{
String str = ((EditText)findViewById(R.id.num_distance)).getText().toString();
String str = et_distance.getText().toString();
try
{
return Integer.parseInt(str);
@ -56,7 +63,7 @@ public class MovementController extends AppCompatActivity
private int GetTurnSpeed()
{
String str = ((EditText)findViewById(R.id.num_turn_speed)).getText().toString();
String str = et_turn_speed.getText().toString();
try
{
return Integer.parseInt(str);
@ -69,7 +76,7 @@ public class MovementController extends AppCompatActivity
private int GetRunSpeed()
{
String str = ((EditText)findViewById(R.id.num_run_speed)).getText().toString();
String str = et_run_peed.getText().toString();
try
{
return Integer.parseInt(str);
@ -86,30 +93,36 @@ public class MovementController extends AppCompatActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movement_controller);
//设置标题栏
ActionBar actionBar = getSupportActionBar();
if(actionBar != null)
if (actionBar != null)
{
actionBar.setTitle("主/从车远端移动控制");
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
//获取控件对象
et_distance = findViewById(R.id.num_distance);
et_run_peed = findViewById(R.id.num_run_speed);
et_turn_speed = findViewById(R.id.num_turn_speed);
//获取主车IP地址
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
dhcpInfo = wifiManager.getDhcpInfo();
IPCar = Formatter.formatIpAddress(dhcpInfo.gateway);
//建立连接
if(CommunicationUsingWifi)
dtc_client = new WifiTransferCore(IPCar,60000, new Handler());
if (CommunicationUsingWifi)
dtc_client = new WifiTransferCore(IPCar, 60000, new Handler());
else
dtc_client = new SerialPortTransferCore(SerialPortPath, 115200, new Handler());
(new Thread(() -> dtc_client.Connect())).start();
// dtc_client.EnableAutoReconnect(); //启动自动重连
cmd_data[0] = Flags.CMD_PACKET_HEAD;
cmd_data[0] = Commands.FRAME_HEAD_0;
cmd_data[1] = Flags.CMD_PACKET_MAIN_CAR;
cmd_data[7] = Flags.CMD_PACKET_END;
cmd_data[7] = Commands.FRAME_END;
findViewById(R.id.rb_main_car).setOnClickListener(view -> cmd_data[1] = Flags.CMD_PACKET_MAIN_CAR);
@ -173,6 +186,7 @@ public class MovementController extends AppCompatActivity
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
//标题栏返回键
if (item.getItemId() == android.R.id.home)
{
finish();
@ -185,6 +199,7 @@ public class MovementController extends AppCompatActivity
protected void onDestroy()
{
super.onDestroy();
dtc_client.DisableAutoReconnect();
dtc_client.CloseConnection();
}
}

@ -28,13 +28,9 @@ public class ImageReleaser
private static class DrawableInfo
{
String filename;
private int res_id;
String storage_path;
public DrawableInfo()
{
}
private final int res_id;
private final String filename;
private final String storage_path;
public DrawableInfo(String filename, int res_id, String storage_path)
{
@ -42,36 +38,6 @@ public class ImageReleaser
this.res_id = res_id;
this.storage_path = storage_path;
}
public String getFilename()
{
return filename;
}
public void setFilename(String filename)
{
this.filename = filename;
}
public int getRes_id()
{
return res_id;
}
public void setRes_id(int res_id)
{
this.res_id = res_id;
}
public String getStorage_path()
{
return storage_path;
}
public void setStorage_path(String storage_path)
{
this.storage_path = storage_path;
}
}
public ImageReleaser(Context context)

@ -28,40 +28,14 @@ public class OCRDataReleaser
private static class FileData
{
private int res_id;
private String file_name;
public FileData()
{
res_id = -1;
file_name = "";
}
private final int res_id;
private final String file_name;
public FileData(int res_id, String file_name)
{
this.res_id = res_id;
this.file_name = file_name;
}
public int getResId()
{
return res_id;
}
public void setResId(int res_id)
{
this.res_id = res_id;
}
public String getFilename()
{
return file_name;
}
public void setFilename(String file_name)
{
this.file_name = file_name;
}
}
public OCRDataReleaser(Context context)

@ -11,7 +11,7 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 1735359724
"memoizedHashCode": 1273672783
},
{
"level_": 0,
@ -25,7 +25,7 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": -437508184
"memoizedHashCode": -899195125
},
{
"level_": 0,
@ -39,6 +39,6 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 608349172
"memoizedHashCode": 146662231
}
]

@ -11,7 +11,7 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 550802056
"memoizedHashCode": 89115115
},
{
"level_": 0,
@ -25,7 +25,7 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": -698413244
"memoizedHashCode": -1160100185
},
{
"level_": 0,
@ -39,6 +39,6 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 1477408402
"memoizedHashCode": 1015721461
}
]

@ -11,7 +11,7 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 861710202
"memoizedHashCode": 400023261
},
{
"level_": 0,
@ -25,7 +25,7 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 1807723122
"memoizedHashCode": 1346036181
},
{
"level_": 0,
@ -39,6 +39,6 @@
"fieldsDescending": {}
},
"memoizedSize": -1,
"memoizedHashCode": 524769837
"memoizedHashCode": 63082896
}
]
Loading…
Cancel
Save