|
@@ -82,6 +82,7 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
private boolean mToggle = true;
|
|
|
private boolean isDetached = false;
|
|
|
private byte[] mBytes = new byte[1024 * 8 + 32];
|
|
|
+ private String[] mVersionShow = new String[7];
|
|
|
private boolean isReceiverMessage = true;
|
|
|
private boolean isNeedFindDevice = true;
|
|
|
|
|
@@ -98,8 +99,7 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
|
|
|
public static List<Activity> activityList = new LinkedList();
|
|
|
|
|
|
- private Button bt_tcpstart, bt_tcpsend1;
|
|
|
- private EditText et_text, et_text1;
|
|
|
+ private Button bt_tcpstart;
|
|
|
private final static String TAG = "Main2Activity-------->";
|
|
|
private final static String addreeip = "192.168.3.80";
|
|
|
private final static int port = 5555;
|
|
@@ -111,7 +111,7 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
private OutputStream outputStream = null;
|
|
|
private InputStream inputStream = null;
|
|
|
|
|
|
- private byte[] SyncCmd = new byte[] {0x03, 0x00, 0x13, (byte)0x81, 0x4E, 0x00, 0x01};
|
|
|
+ private byte[] SyncCmd = new byte[] {0x03, 0x00, 0x0d, (byte)0x81, 0x4E, 0x00, 0x01};
|
|
|
|
|
|
Handler mHandler = new Handler() {
|
|
|
@Override
|
|
@@ -123,6 +123,57 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
//String avalue = "S818 is connected";
|
|
|
|
|
|
mShow.setText(R.string.connected);//????????
|
|
|
+
|
|
|
+ iicWrite((byte)0x12,(byte)0,(byte)0,0,57);
|
|
|
+
|
|
|
+ while(true) {
|
|
|
+ SystemClock.sleep(100);
|
|
|
+
|
|
|
+ iicRead((byte) 0x81, (byte) 0x4e, mBytes, 1);
|
|
|
+ if (mBytes[0] == (byte)0)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ iicWrite((byte) 0x0f, (byte) 0x81, (byte) 0x4e, 0, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ iicRead((byte) 0x81, (byte) 0x40, mBytes, 32);
|
|
|
+ int v = mBytes[5] & 0xFF;
|
|
|
+ String hv = Integer.toHexString(v);
|
|
|
+ if (hv.length() < 2){
|
|
|
+ hv = "0" + hv;
|
|
|
+ }
|
|
|
+ mVersionShow[0] = hv;
|
|
|
+
|
|
|
+ v = mBytes[6] & 0xFF;
|
|
|
+ hv = Integer.toHexString(v);
|
|
|
+ if (hv.length() < 2){
|
|
|
+ hv = "0" + hv;
|
|
|
+ }
|
|
|
+ mVersionShow[1] = hv;
|
|
|
+
|
|
|
+ v = mBytes[7] & 0xFF;
|
|
|
+ hv = Integer.toHexString(v);
|
|
|
+ if (hv.length() < 2){
|
|
|
+ hv = "0" + hv;
|
|
|
+ }
|
|
|
+ mVersionShow[2] = hv;
|
|
|
+
|
|
|
+ if (mBytes[0] == 0x39 && mBytes[1] == 0x31 && mBytes[2] == 0x31 && mBytes[3] == 0x32){
|
|
|
+ tvIPAddress.setText( "GT9110H_" + mVersionShow[1].toString() + mVersionShow[0].toString() );//输出显示
|
|
|
+ }
|
|
|
+ else if (mBytes[0] == 0x36 && mBytes[1] == 0x31 && mBytes[2] == 0x30 && mBytes[3] == 0x39){
|
|
|
+ tvIPAddress.setText( "GT6108H_" + mVersionShow[1].toString() + mVersionShow[0].toString() );//输出显示
|
|
|
+ }
|
|
|
+ else if (mBytes[0] == 0x37 && mBytes[1] == 0x32 && mBytes[2] == 0x38 && mBytes[3] == 0x38){
|
|
|
+ tvIPAddress.setText( "GT7288_" + mVersionShow[0].toString() + "." + mVersionShow[1].toString() + "." + mVersionShow[2].toString());//输出显示
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ tvIPAddress.setText( "Null" );//输出显示
|
|
|
+ }
|
|
|
+ //tvIPAddress.setText("IP Address : " + GetIPAddress());
|
|
|
+
|
|
|
break;
|
|
|
case CONNECTED_FAILED://??????????????????
|
|
|
//String bvalue = "S818 is disconnected";
|
|
@@ -229,16 +280,8 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
|
|
|
bt_tcpstart = findViewById(R.id.bt_tcpstart);
|
|
|
|
|
|
- bt_tcpsend1 = findViewById(R.id.bt_tcpsend1);
|
|
|
-
|
|
|
- et_text = findViewById(R.id.et_text);
|
|
|
-
|
|
|
- et_text1 = findViewById(R.id.et_text1);
|
|
|
-
|
|
|
bt_tcpstart.setOnClickListener(this);
|
|
|
|
|
|
- bt_tcpsend1.setOnClickListener(this);
|
|
|
-
|
|
|
init();//
|
|
|
}
|
|
|
|
|
@@ -376,7 +419,7 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
mShow = (TextView) findViewById(R.id.show);
|
|
|
tvIPAddress = (TextView) findViewById(R.id.ipaddressshow);
|
|
|
|
|
|
- tvIPAddress.setText("IP Address : " + GetIPAddress());
|
|
|
+ //tvIPAddress.setText("IP Address : " + GetIPAddress());
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
@@ -395,8 +438,6 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public void onClick(final View v) {
|
|
|
switch (v.getId()) {
|
|
@@ -456,7 +497,6 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
framelen = (headbytes[4] & 0xff) + (int) ((headbytes[5] & 0xff) * 256); //低位在前
|
|
|
frameid = (headbytes[6] & 0xff) + (int) ((headbytes[7] & 0xff) * 256);
|
|
|
|
|
|
-
|
|
|
int offset = 0;
|
|
|
|
|
|
do{
|
|
@@ -504,10 +544,8 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
System.out.println(sb);
|
|
|
*/
|
|
|
}
|
|
|
- // System.out.println("get message from client: " + sb);
|
|
|
|
|
|
//outputStream = socket.getOutputStream();
|
|
|
- //outputStream.write("Hello Client,I get the message.".getBytes("UTF-8"));
|
|
|
|
|
|
inputStream.close();
|
|
|
outputStream.close();
|
|
@@ -529,7 +567,6 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
//bt_tcpstart.setBackgroundColor(getResources().getColor(R.color.colorAccent2));
|
|
|
|
|
|
try {
|
|
|
- //socket.close();
|
|
|
//inputStream.close();
|
|
|
//outputStream.close();
|
|
|
//socket.close();
|
|
@@ -542,43 +579,11 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case R.id.bt_tcpsend1:
|
|
|
- tcp_start();
|
|
|
+ default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void tcp_start() {
|
|
|
-
|
|
|
- new Thread(new Runnable() {
|
|
|
-
|
|
|
- @Override
|
|
|
-
|
|
|
- public void run() {
|
|
|
- app_text = et_text.getText().toString().trim();
|
|
|
- try {
|
|
|
-
|
|
|
- if (app_text.equals("")) {
|
|
|
- Log.i(TAG, "输入不能为空");
|
|
|
- } else {
|
|
|
- //注意charset.forName 字符编码,utf-8中文。。。。。
|
|
|
- if(outputStream !=null){
|
|
|
- byte[] sendData = app_text.getBytes(Charset.forName("ASCII"));
|
|
|
- outputStream.write(sendData, 0, sendData.length);
|
|
|
- outputStream.flush();
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }).start();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* ???? , ??????????
|
|
|
*/
|
|
@@ -607,10 +612,12 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
for (UsbDevice usbDevice : deviceList.values()) {
|
|
|
int productId = usbDevice.getProductId();
|
|
|
int vendorId = usbDevice.getVendorId();
|
|
|
- if ((productId == 0x0818 && vendorId == 0x27C0)
|
|
|
+ if ((productId == 0x0616 && vendorId == 0x27C0)
|
|
|
+ ||(productId == 0x0818 && vendorId == 0x27C0)
|
|
|
||(productId == 0x0001 && vendorId == 0x222A)) //奕力的PID和VID
|
|
|
{
|
|
|
isS818Device = true;
|
|
|
+
|
|
|
if (mUsbManager.hasPermission(usbDevice)) {
|
|
|
initDevice();
|
|
|
}
|
|
@@ -657,7 +664,7 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
if (!values.isEmpty()) {
|
|
|
for (UsbDevice usbDevice : values) {
|
|
|
int productId = usbDevice.getProductId();
|
|
|
- if (productId == 0x0818 || productId == 0x0001 ) { //0x0001是奕力的PID
|
|
|
+ if (productId == 0x0818 || productId == 0x0001 || productId == 0x0616) { //0x0001是奕力的PID
|
|
|
|
|
|
if (mUsbManager.hasPermission(usbDevice)) {
|
|
|
|
|
@@ -932,6 +939,124 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ //发送命令,使得S818可以通过IIC向GT9的固定地址读取任意bytes的数据
|
|
|
+ private boolean iicRead(byte addressHigh,byte addressLow,byte[] wBuffer,int length) {
|
|
|
+
|
|
|
+ int i;
|
|
|
+ iicByteData[1] = 0x00; //read GT9 command
|
|
|
+ iicByteData[2] = 0x0f; //no command
|
|
|
+ iicByteData[3] = addressHigh;
|
|
|
+ iicByteData[4] = addressLow;
|
|
|
+ iicByteData[5] = 0x00;
|
|
|
+ iicByteData[6] = 63; //length 一次接收63个数据
|
|
|
+
|
|
|
+ for (int j = 7; j < 64; j++) {
|
|
|
+ iicWriteData[j] = 0x00;
|
|
|
+ }
|
|
|
+
|
|
|
+ int address1 = ((addressHigh&0xff)<<8);
|
|
|
+ int address2 = addressLow&0xff;
|
|
|
+ int address = address1|address2;
|
|
|
+
|
|
|
+ int sendTimes = length/63 + 1; //预计是向下取整,所以+1
|
|
|
+
|
|
|
+ for (int k = 0; k < sendTimes; k++) {
|
|
|
+ int finalOffset = k*63; //每次只能发57bytes数据
|
|
|
+ int offset = k*64;
|
|
|
+
|
|
|
+ if(length - (finalOffset ) < 63) {
|
|
|
+
|
|
|
+ iicByteData[6] = (byte) (length - (finalOffset)); //length
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iicByteData[6] = 63;
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送读取命令
|
|
|
+ i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicByteData, 0, 0x40, 100);
|
|
|
+ if (i != 0x40)
|
|
|
+ return false; //传输失败
|
|
|
+ // SystemClock.sleep(1);
|
|
|
+
|
|
|
+ //接收数据
|
|
|
+ i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 3000);
|
|
|
+
|
|
|
+ if (i != 0x40) {
|
|
|
+ //editname.setText("iicWrite Failed");
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ address = address + 63;
|
|
|
+ iicByteData[3] = (byte)(address>>8);
|
|
|
+ iicByteData[4] = (byte)address;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将report id从数组中去除
|
|
|
+ //byte[] temperBuffer =new byte[length];
|
|
|
+ if(true) {
|
|
|
+ int count1 = 0;
|
|
|
+ for (int k = 0; k < length; k++) {
|
|
|
+ if (k % 63 == 0) {
|
|
|
+ count1++;
|
|
|
+ }
|
|
|
+
|
|
|
+ wBuffer[k] = wBuffer[k + count1];
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送命令,使得S818可以通过IIC向GT9的固定地址写任意bytes的数据
|
|
|
+ private boolean iicWrite(byte command,byte addressHigh,byte addressLow,int offset,int length) {
|
|
|
+ int i;
|
|
|
+
|
|
|
+ iicWriteData[1] = 0x01; //write GT9PT command
|
|
|
+ iicWriteData[2] = command; //command
|
|
|
+ iicWriteData[3] = addressHigh;
|
|
|
+ iicWriteData[4] = addressLow;
|
|
|
+ iicWriteData[5] = 0x00;
|
|
|
+ iicWriteData[6] = 0x39; //length 57
|
|
|
+
|
|
|
+ int address1 = ((addressHigh&0xff)<<8);
|
|
|
+ int address2 = addressLow&0xff;
|
|
|
+ int address = address1|address2;
|
|
|
+
|
|
|
+ int sendTimes = length/57 + 1; //预计是向下取整,所以+1
|
|
|
+
|
|
|
+ for (int k = 0; k < sendTimes; k++) {
|
|
|
+ int finalOffset = offset + k*57; //每次只能发57bytes数据
|
|
|
+
|
|
|
+ if(length - (finalOffset -offset) < 57) {
|
|
|
+
|
|
|
+ iicWriteData[6] = (byte) (length - (finalOffset -offset)); //length
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iicWriteData[6] = 0x39;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int j = 7; j < 64; j++) {
|
|
|
+ iicWriteData[j] = 0;//wBuffer[finalOffset + j -7];
|
|
|
+ }
|
|
|
+ i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicWriteData, 0, 0x40, 100);
|
|
|
+
|
|
|
+ if (i != 0x40) {
|
|
|
+ //editname.setText("iicWrite Failed");
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ address = address + 57;
|
|
|
+ iicWriteData[3] = (byte)(address>>8);
|
|
|
+ iicWriteData[4] = (byte)address;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class OpenDevicesReceiver extends BroadcastReceiver {
|