package com.basic.security.utils.socket;
|
|
import android.os.SystemClock;
|
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.manager.BaseSettingManager;
|
import com.jaredrummler.android.shell.CommandResult;
|
import com.jaredrummler.android.shell.Shell;
|
|
import java.util.LinkedList;
|
|
public class RelayServerUtil2 {
|
public static LinkedList<String> openDoorThreadQueue = new LinkedList<>();
|
public static long lastOpenDoorThread = System.currentTimeMillis();
|
|
public static void startOpenDoorThread() {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
while (true) {
|
try {
|
// FireflyApi fireflyApi = BaseApplication.getApplication().activity.getFireflyApi();
|
synchronized (openDoorThreadQueue) {
|
if (openDoorThreadQueue.size() > 0) {
|
openDoorThreadQueue.clear();
|
lastOpenDoorThread = System.currentTimeMillis();
|
{
|
CommandResult commandResult = Shell.SU.run("cd /sys/class/gpio/",
|
"echo 12 > /sys/class/gpio/export",
|
"echo out > /sys/class/gpio/gpio12/direction ",
|
"echo 0 > /sys/class/gpio/gpio12/value "
|
);
|
System1.out.println(commandResult);
|
}
|
{
|
CommandResult commandResult = Shell.SU.run("cd /sys/class/gpio/",
|
"echo 157 > /sys/class/gpio/export",
|
"echo out > /sys/class/gpio/gpio157/direction ",
|
"echo 1 > /sys/class/gpio/gpio157/value "
|
);
|
System1.out.println(commandResult);
|
}
|
// System1.out.println("RelayServerUtil2.run 开门");
|
}
|
}
|
if (System.currentTimeMillis() - lastOpenDoorThread > BaseSettingManager.getOpenDoorDurationSeconds() * 1000) {
|
{
|
CommandResult commandResult = Shell.SU.run("cd /sys/class/gpio/",
|
"echo 12 > /sys/class/gpio/export",
|
"echo out > /sys/class/gpio/gpio12/direction ",
|
"echo 1 > /sys/class/gpio/gpio12/value "
|
);
|
}
|
{
|
CommandResult commandResult = Shell.SU.run("cd /sys/class/gpio/",
|
"echo 157 > /sys/class/gpio/export",
|
"echo out > /sys/class/gpio/gpio157/direction ",
|
"echo 0 > /sys/class/gpio/gpio157/value "
|
);
|
}
|
// System1.out.println("RelayServerUtil2.run 关门");
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
SystemClock.sleep(1000);
|
}
|
});
|
}
|
|
public static boolean open() {
|
// if (Constants.useAlf) {
|
synchronized (openDoorThreadQueue) {
|
openDoorThreadQueue.add(System.currentTimeMillis() + "");
|
}
|
// System1.out.println("RelayServerUtil2.open");
|
// IOUtil.initIOUtil().openUNLOCK();
|
return true;
|
// } else {
|
// return true;
|
// }
|
// boolean success = false;
|
// BufferedInputStream inputStream = null;
|
// BufferedOutputStream outputStream = null;
|
// Socket socket = null;
|
// ByteArrayOutputStream byteArray = null;
|
// try {
|
// socket = new Socket("192.168.1.100", 6722);
|
// socket.setSoTimeout(1000);
|
// inputStream = new BufferedInputStream(socket.getInputStream());
|
// outputStream = new BufferedOutputStream(socket.getOutputStream());
|
// outputStream.write("00".getBytes()); // 查询
|
//// outputStream.write("21".getBytes()); // ch1 释放 返回00011000
|
//// outputStream.write("11".getBytes()); // ch1 吸合 返回10011000
|
//// outputStream.write("11:2".getBytes()); // CH1 吸合,30 秒后自动释放 返回10011000
|
// outputStream.flush();
|
// byte[] buff = new byte[256];
|
// int len = 0;
|
// String ret = "";
|
// while ((len = inputStream.read(buff)) != -1) {
|
// ret = new String(buff, "UTF-8");
|
// System1.out.println(ret);
|
// Log.e("test111", ret);
|
// break;
|
// }
|
// if ("1".equals(ret.charAt(0) + "")) {
|
// outputStream.write("21".getBytes()); // ch1 释放 返回00011000
|
// } else {
|
// outputStream.write("11".getBytes()); // ch1 吸合 返回10011000
|
// }
|
// outputStream.flush();
|
// while ((len = inputStream.read(buff)) != -1) {
|
// ret = new String(buff, "ISO8859-1");
|
//// System1.out.println(ret);
|
// Log.e("test222", ret);
|
// break;
|
// }
|
// } catch (Exception e) {
|
//// e.printStackTrace();
|
//// System1.out.println("RelayServerUtil2.open " + e.getMessage());
|
// } finally {
|
// try {
|
// if (outputStream != null) {
|
// outputStream.close();
|
// }
|
// if (inputStream != null) {
|
// inputStream.close();
|
// }
|
// if (socket != null) {
|
// socket.close();
|
// }
|
// if (byteArray != null) {
|
// byteArray.close();
|
// }
|
// } catch (IOException e) {
|
// }
|
// }
|
// return success;
|
}
|
}
|