|
|
|
@ -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,...},
|
|
|
|
|
//并将1,2,4,8,16,32位置变为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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|