|
@@ -38,6 +38,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
int getBaudRate() {
|
|
int getBaudRate() {
|
|
|
|
+// return 9600;
|
|
return 115200;
|
|
return 115200;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,7 +75,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
case 0x0A://电控锁
|
|
case 0x0A://电控锁
|
|
|
|
|
|
break;
|
|
break;
|
|
- case 0x0C://距离/温度
|
|
|
|
|
|
+ case 0x01://距离/温度
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -133,7 +134,6 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
SPUtils.getInstance().put("RunningState",1);
|
|
SPUtils.getInstance().put("RunningState",1);
|
|
MainViewModel.SendSmsResponse("其他设备未检测到");
|
|
MainViewModel.SendSmsResponse("其他设备未检测到");
|
|
-
|
|
|
|
Log.e(TAG,"读取门磁错误",e);
|
|
Log.e(TAG,"读取门磁错误",e);
|
|
return 3;
|
|
return 3;
|
|
}
|
|
}
|
|
@@ -205,10 +205,28 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /*
|
|
|
|
+ * 设置电流阈值
|
|
|
|
+ * */
|
|
public void setPower(){
|
|
public void setPower(){
|
|
try {
|
|
try {
|
|
|
|
+// byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x60, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
+ byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x44, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
+
|
|
|
|
+ port.write(setPower, 500);
|
|
|
|
+ byte[] response = new byte[12];
|
|
|
|
+ port.read(response,500);
|
|
|
|
+ Log.i(TAG,ByteUtil.bytesToString(response)+"设置电流");
|
|
|
|
+ }catch(Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setPowerBigger(){
|
|
|
|
+ try {
|
|
|
|
+// byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x60, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x03, 0x60, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x03, 0x60, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
+
|
|
port.write(setPower, 500);
|
|
port.write(setPower, 500);
|
|
byte[] response = new byte[12];
|
|
byte[] response = new byte[12];
|
|
port.read(response,500);
|
|
port.read(response,500);
|
|
@@ -216,8 +234,21 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
}catch(Exception e){
|
|
}catch(Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ public void queryPower(){
|
|
|
|
|
|
|
|
+ try{
|
|
|
|
+ byte[] readPushOrderBytes=new byte[]{(byte)0xAA, (byte) 0xBB,0x0A, 0x01, 0x55 ,0x01 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
+ port.write(readPushOrderBytes, 100);
|
|
|
|
+ byte[] responseRead = new byte[ 12];
|
|
|
|
+ port.read(responseRead,200);
|
|
|
|
+ System.out.println("Read response:"+ByteUtil.bytesToString(responseRead));
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 伸杆关门
|
|
* 伸杆关门
|
|
*/
|
|
*/
|
|
@@ -228,7 +259,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
try {
|
|
try {
|
|
SPUtils.getInstance().put("RodSwitch","0");
|
|
SPUtils.getInstance().put("RodSwitch","0");
|
|
//门 66后面 01 表示杆 01表示伸杆 1c表示多少秒 02 1c 表示电流
|
|
//门 66后面 01 表示杆 01表示伸杆 1c表示多少秒 02 1c 表示电流
|
|
- System.out.println("------------push rod------------------------");
|
|
|
|
|
|
+// System.out.println("------------push rod------------------------");
|
|
SPUtils.getInstance().put("queryInfraredError",0);
|
|
SPUtils.getInstance().put("queryInfraredError",0);
|
|
// byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x1C, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
// byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x1C, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
// port.write(setPower, 100);
|
|
// port.write(setPower, 100);
|
|
@@ -240,14 +271,24 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
getRodOpenNumber();
|
|
getRodOpenNumber();
|
|
byte[] response = new byte[ 12];
|
|
byte[] response = new byte[ 12];
|
|
port.read(response,200);
|
|
port.read(response,200);
|
|
- byte[] readPushOrderBytes=new byte[]{(byte)0xAA, (byte) 0xBB,0x0A, 0x01, 0x55 ,0x01 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
- port.write(readPushOrderBytes, 100);
|
|
|
|
- byte[] responseRead = new byte[ 12];
|
|
|
|
- port.read(responseRead,200);
|
|
|
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ byte[] readPushOrderBytes=new byte[]{(byte)0xAA, (byte) 0xBB,0x0A, 0x01, 0x55 ,0x01 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
+ try {
|
|
|
|
+ port.write(readPushOrderBytes, 100);
|
|
|
|
+ byte[] responseRead = new byte[ 12];
|
|
|
|
+ port.read(responseRead,200);
|
|
|
|
+ System.out.println("pushRead response:"+ByteUtil.bytesToString(responseRead));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },1000);
|
|
|
|
+
|
|
System.out.println("push response:"+ByteUtil.bytesToString(response));
|
|
System.out.println("push response:"+ByteUtil.bytesToString(response));
|
|
- System.out.println("pushRead response:"+ByteUtil.bytesToString(responseRead));
|
|
|
|
|
|
|
|
-// SPUtils.getInstance().getInt("infraredNum1",0);
|
|
|
|
|
|
+ SPUtils.getInstance().getInt("infraredNum1",0);
|
|
long curr=System.currentTimeMillis();
|
|
long curr=System.currentTimeMillis();
|
|
Thread.sleep(500);
|
|
Thread.sleep(500);
|
|
while (System.currentTimeMillis() - curr < 6000) {
|
|
while (System.currentTimeMillis() - curr < 6000) {
|
|
@@ -259,8 +300,12 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
}
|
|
}
|
|
if (infrared == 1) {//有障碍物
|
|
if (infrared == 1) {//有障碍物
|
|
//停止关门
|
|
//停止关门
|
|
- Log.i(TAG, "停止关门");
|
|
|
|
|
|
+ Log.i(TAG, "有障碍物,停止关门");
|
|
port.write(new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x01, 0x03, (byte) 0x05, (byte) 0xff, (byte) 0xff, (byte) 0xCC, (byte) 0xDD}, 200);
|
|
port.write(new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x01, 0x03, (byte) 0x05, (byte) 0xff, (byte) 0xff, (byte) 0xCC, (byte) 0xDD}, 200);
|
|
|
|
+ byte[] response3 = new byte[ 12];
|
|
|
|
+ port.read(response3,200);
|
|
|
|
+ Log.i("停止关门",response3+"");
|
|
|
|
+
|
|
int num=SPUtils.getInstance().getInt("infraredNum1",0)+1;
|
|
int num=SPUtils.getInstance().getInt("infraredNum1",0)+1;
|
|
SPUtils.getInstance().put("infraredNum1",num);
|
|
SPUtils.getInstance().put("infraredNum1",num);
|
|
if(num<3){
|
|
if(num<3){
|
|
@@ -313,12 +358,22 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
System.out.println("pullRod "+writeLen);
|
|
System.out.println("pullRod "+writeLen);
|
|
byte[] response = new byte[12];
|
|
byte[] response = new byte[12];
|
|
port.read(response,200);
|
|
port.read(response,200);
|
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ byte[] readPullOrderBytes=new byte[]{(byte)0xAA, (byte) 0xBB,0x0A, 0x01, 0x55 ,0x01 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
+ try {
|
|
|
|
+ port.write(readPullOrderBytes, 100);
|
|
|
|
+ byte[] responseRead = new byte[ 12];
|
|
|
|
+ port.read(responseRead,200);
|
|
|
|
+ System.out.println("pullRead response:"+ByteUtil.bytesToString(responseRead));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ },1000);
|
|
|
|
|
|
- byte[] readPullOrderBytes=new byte[]{(byte)0xAA, (byte) 0xBB,0x0A, 0x01, 0x55 ,0x01 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
|
- port.write(readPullOrderBytes, 100);
|
|
|
|
- byte[] responseRead = new byte[ 12];
|
|
|
|
- port.read(responseRead,200);
|
|
|
|
- System.out.println("pullRead response:"+ByteUtil.bytesToString(responseRead));
|
|
|
|
System.out.println("response:"+ByteUtil.bytesToString(response));
|
|
System.out.println("response:"+ByteUtil.bytesToString(response));
|
|
}catch ( Exception e ){
|
|
}catch ( Exception e ){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -334,7 +389,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
/**
|
|
/**
|
|
* 运收门开锁
|
|
* 运收门开锁
|
|
*/
|
|
*/
|
|
- public Integer openLock(){
|
|
|
|
|
|
+ public Integer openLock(){//AA BB 0A 01 66 02 01 07 FF FF CC DD
|
|
try {
|
|
try {
|
|
// byte[] openLockOrderBytes = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x02, 0x01,0x03, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
// byte[] openLockOrderBytes = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x02, 0x01,0x03, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
byte[] openLockOrderBytes = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x02, 0x01,0x07, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
byte[] openLockOrderBytes = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x02, 0x01,0x07, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
@@ -344,7 +399,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
getLockOpenNumber();
|
|
getLockOpenNumber();
|
|
Log.i(TAG,ByteUtil.bytesToString(response)+"开收运门");
|
|
Log.i(TAG,ByteUtil.bytesToString(response)+"开收运门");
|
|
if(response[4]==102&&response[5]==2&&response[6]==1){
|
|
if(response[4]==102&&response[5]==2&&response[6]==1){
|
|
- return 0;
|
|
|
|
|
|
+ return 1;
|
|
}else {
|
|
}else {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -385,69 +440,76 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
* 距离
|
|
* 距离
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Integer getDistance(){
|
|
|
|
- try {
|
|
|
|
- byte[] bytes = new byte[]{(byte)0xAA ,(byte)0xBB ,(byte)0x0C ,(byte)0x01 ,(byte)0x55 ,(byte)0x01 ,(byte)0xFF ,(byte)0xFF,(byte)0xFF ,(byte)0xFF ,(byte)0xCC ,(byte)0xDD};
|
|
|
|
- port.write(bytes,200);
|
|
|
|
- byte[] response = new byte[12];
|
|
|
|
- int len = port.read(response,200);
|
|
|
|
- Log.i(TAG,ByteUtil.bytesToString(response)+len+"距离");
|
|
|
|
- byte[] disBytes = new byte[4];
|
|
|
|
- disBytes[2] = response[6];
|
|
|
|
- disBytes[3] = response[7];
|
|
|
|
- Log.i(TAG,ByteUtil.bytesToString(disBytes)+"juli");
|
|
|
|
- int disInt = ByteUtil.bytes2Int(disBytes);
|
|
|
|
- if(response[4]==85&&response[5]==1){
|
|
|
|
- return disInt;
|
|
|
|
- }else {
|
|
|
|
- SPUtils.getInstance().put("RunningState",5);
|
|
|
|
- MainViewModel.SendSmsResponse("温度超声波失灵");
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }catch ( Exception e ){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- SPUtils.getInstance().put("RunningState",1);
|
|
|
|
- MainViewModel.SendSmsResponse("其他设备未检测到");
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 温度
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Integer geTemperature(){//获取温度
|
|
|
|
- try{
|
|
|
|
- byte[] bytes = new byte[]{(byte)0xAA ,(byte)0xBB ,(byte)0x0C ,(byte)0x01 ,(byte)0x55 ,(byte)0x02 ,(byte)0xFF ,(byte)0xFF,(byte)0xFF ,(byte)0xFF ,(byte)0xCC ,(byte)0xDD};
|
|
|
|
- port.write(bytes,200);
|
|
|
|
- byte[] response=new byte[12];
|
|
|
|
- int len=port.read(response,200);
|
|
|
|
- Log.i(TAG,ByteUtil.bytesToString(response)+len+"温度"+response[4]+response[5]);
|
|
|
|
- byte[] temBytes=new byte[4];
|
|
|
|
-// temBytes[2]=response[5];
|
|
|
|
- temBytes[3]=response[6];
|
|
|
|
- Integer temInt=ByteUtil.bytes2Int(temBytes);
|
|
|
|
-// double temDouble=0;
|
|
|
|
-// if(temInt<65536){
|
|
|
|
-// temDouble=temInt/10;
|
|
|
|
-// return temDouble;
|
|
|
|
|
|
+// public Integer getDistance(){
|
|
|
|
+// try {
|
|
|
|
+//// byte[] bytes = new byte[]{(byte)0xAA ,(byte)0xBB ,(byte)0x0C ,(byte)0x01 ,(byte)0x55 ,(byte)0x01 ,(byte)0xFF ,(byte)0xFF,(byte)0xFF ,(byte)0xFF ,(byte)0xCC ,(byte)0xDD};
|
|
|
|
+// //新超声波 01 03 01 02 00 01 24 36
|
|
|
|
+// byte[] bytes = new byte[]{(byte)0xAA ,(byte)0xBB ,(byte)0x01 ,(byte)0x03 ,(byte)0x01 ,(byte)0x02 ,(byte)0x00 ,(byte)0x01,(byte)0x24 ,(byte)0x36 ,(byte)0xCC ,(byte)0xDD};
|
|
|
|
+//// byte[] bytes = new byte[]{(byte)0x01 ,(byte)0x03 ,(byte)0x01 ,(byte)0x02 ,(byte)0x00 ,(byte)0x01 ,(byte)0x24 ,(byte)0x36};
|
|
|
|
+// port.write(bytes,100);
|
|
|
|
+// byte[] response = new byte[12];
|
|
|
|
+// int len = port.read(response,100);
|
|
|
|
+// Log.i(TAG,ByteUtil.bytesToString(response)+len+"距离");
|
|
|
|
+// for (int i:response) {
|
|
|
|
+// Log.i("超声波", ""+response[i]);
|
|
// }
|
|
// }
|
|
-// temDouble=-(temInt-65536)/10;
|
|
|
|
-// return temDouble;
|
|
|
|
- if(response[4]==85&&response[5]==2){
|
|
|
|
- return temInt;
|
|
|
|
- }else {
|
|
|
|
- SPUtils.getInstance().put("RunningState",5);
|
|
|
|
- MainViewModel.SendSmsResponse("温度超声波失灵");
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }catch ( Exception e ){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- SPUtils.getInstance().put("RunningState",1);
|
|
|
|
- MainViewModel.SendSmsResponse("其他设备未检测到");
|
|
|
|
- Log.i(TAG,"测温度失败");
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// Log.i("超声波", ""+response.toString());
|
|
|
|
+// byte[] disBytes = new byte[4];
|
|
|
|
+// disBytes[2] = response[3];
|
|
|
|
+// disBytes[3] = response[4];
|
|
|
|
+// Log.i(TAG,ByteUtil.bytesToString(disBytes)+"juli");
|
|
|
|
+// int disInt = ByteUtil.bytes2Int(disBytes);
|
|
|
|
+// if(response[4]==85&&response[5]==1){
|
|
|
|
+// return disInt;
|
|
|
|
+// }else {
|
|
|
|
+// SPUtils.getInstance().put("RunningState",5);
|
|
|
|
+// MainViewModel.SendSmsResponse("温度超声波失灵");
|
|
|
|
+// return 0;
|
|
|
|
+// }
|
|
|
|
+// }catch ( Exception e ){
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// SPUtils.getInstance().put("RunningState",1);
|
|
|
|
+// MainViewModel.SendSmsResponse("其他设备未检测到");
|
|
|
|
+// return 0;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// /**
|
|
|
|
+// * 温度
|
|
|
|
+// * @return
|
|
|
|
+// */
|
|
|
|
+// public Integer geTemperature(){//获取温度
|
|
|
|
+// try{
|
|
|
|
+// byte[] bytes = new byte[]{(byte)0xAA ,(byte)0xBB ,(byte)0x0C ,(byte)0x01 ,(byte)0x55 ,(byte)0x02 ,(byte)0xFF ,(byte)0xFF,(byte)0xFF ,(byte)0xFF ,(byte)0xCC ,(byte)0xDD};
|
|
|
|
+// port.write(bytes,200);
|
|
|
|
+// byte[] response=new byte[12];
|
|
|
|
+// int len=port.read(response,200);
|
|
|
|
+// Log.i(TAG,ByteUtil.bytesToString(response)+len+"温度"+response[4]+response[5]);
|
|
|
|
+// byte[] temBytes=new byte[4];
|
|
|
|
+//// temBytes[2]=response[5];
|
|
|
|
+// temBytes[3]=response[6];
|
|
|
|
+// Integer temInt=ByteUtil.bytes2Int(temBytes);
|
|
|
|
+//// double temDouble=0;
|
|
|
|
+//// if(temInt<65536){
|
|
|
|
+//// temDouble=temInt/10;
|
|
|
|
+//// return temDouble;
|
|
|
|
+//// }
|
|
|
|
+//// temDouble=-(temInt-65536)/10;
|
|
|
|
+//// return temDouble;
|
|
|
|
+// if(response[4]==85&&response[5]==2){
|
|
|
|
+// return temInt;
|
|
|
|
+// }else {
|
|
|
|
+// SPUtils.getInstance().put("RunningState",5);
|
|
|
|
+// MainViewModel.SendSmsResponse("温度超声波失灵");
|
|
|
|
+// return 0;
|
|
|
|
+// }
|
|
|
|
+// }catch ( Exception e ){
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// SPUtils.getInstance().put("RunningState",1);
|
|
|
|
+// MainViewModel.SendSmsResponse("其他设备未检测到");
|
|
|
|
+// Log.i(TAG,"测温度失败");
|
|
|
|
+// return 0;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
/*
|
|
/*
|
|
* 开灯关灯
|
|
* 开灯关灯
|
|
* */
|
|
* */
|