[desc]:添加串口功能

[author]:wangyimiao
master
yimiao 3 years ago
parent 4704f48248
commit 266bfdf639

@ -23,9 +23,15 @@ android {
} }
buildTypes { buildTypes {
debug{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
release { release {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
} }
} }

@ -9,6 +9,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:extractNativeLibs="true"
android:theme="@style/Theme.CommonLibTest"> android:theme="@style/Theme.CommonLibTest">
<activity android:name="com.common.commonlibtest.DemoActivity"> <activity android:name="com.common.commonlibtest.DemoActivity">
<intent-filter> <intent-filter>

@ -132,14 +132,20 @@ public class DemoActivity extends AppCompatActivity {
}); });
binding.mmkv.setOnClickListener(l -> { binding.mmkv.setOnClickListener(l -> {
MMKVUtils.INSTANCE.put("key", 100, "aa"); // MMKVUtils.INSTANCE.put("key", 100, "aa");
int value = MMKVUtils.INSTANCE.getInt("key", "bb"); // int value = MMKVUtils.INSTANCE.getInt("key", "bb");
Toast.makeText(DemoActivity.this, "" + value, Toast.LENGTH_SHORT).show(); // Toast.makeText(DemoActivity.this, "" + value, Toast.LENGTH_SHORT).show();
serialPortUtil.sendSerialPort("AT+START_SCAN=1\r\n");
serialPortUtil.sendSerialPort("AT+SCAN_RES=0\r\n");
serialPortUtil.sendSerialPort("AT+CON_16=F9683387BAA1,0001\r\n");
}); });
binding.port.setOnClickListener(l -> { binding.port.setOnClickListener(l -> {
SerialPortUtil serialPortUtil = new SerialPortUtil(); serialPortUtil = new SerialPortUtil();
serialPortUtil.openSerialPort(); serialPortUtil.openSerialPort();
}); });
} }
private SerialPortUtil serialPortUtil = new SerialPortUtil();
} }

@ -1,6 +1,6 @@
project.ext { project.ext {
sign = [ sign = [
keystore_path : "../innovationapp.jks", keystore_path : "../signature/innovationapp.jks",
keystore_pwd : "123456", keystore_pwd : "123456",
keystore_alias: "yinuo" keystore_alias: "yinuo"
] ]

@ -49,13 +49,6 @@ open class BaseObserve<T> {
return RequestManager.create(clazz) return RequestManager.create(clazz)
} }
/**
* 初始化服务类
*/
fun initService(clazz: Class<T>, interceptors: List<Interceptor>): T {
return RequestManager.create(clazz, interceptors)
}
/** /**
* 调用接口 * 调用接口
* @param observable 可订阅 * @param observable 可订阅
@ -89,6 +82,13 @@ open class BaseObserve<T> {
}) })
} }
/**
* 初始化服务类
*/
fun initService(clazz: Class<T>, interceptors: List<Interceptor>): T {
return RequestManager.create(clazz, interceptors)
}
/** /**
* 处理错误 * 处理错误
* @param e 异常 * @param e 异常

@ -8,13 +8,22 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/** /**
* @author by AllenJ on 2018/4/20. * @author by AllenJ on 2018/4/20.
* * <p>
* *
*/ */
public class SerialPortUtil { public class SerialPortUtil {
/**
*
*/
private static final String DEVICE_PATH = "/dev/ttyMSM1";
/**
*
*/
private static final int DEVICE_BIT_RATE = 115200;
private SerialPort serialPort = null; private SerialPort serialPort = null;
private InputStream inputStream = null; private InputStream inputStream = null;
private OutputStream outputStream = null; private OutputStream outputStream = null;
@ -28,13 +37,12 @@ public class SerialPortUtil {
public void openSerialPort() { public void openSerialPort() {
try { try {
// 设置当前设备SU命令的位置 // 设置当前设备SU命令的位置
SerialPort.setSuPath("/system/xbin/su"); // SerialPort.setSuPath("/system/xbin/su");
serialPort = new SerialPort(new File("/dev/ttyS0"), 9600, 0); serialPort = new SerialPort(new File(DEVICE_PATH), DEVICE_BIT_RATE, 0);
//调用对象SerialPort方法获取串口中"读和写"的数据流 //调用对象SerialPort方法获取串口中"读和写"的数据流
inputStream = serialPort.getInputStream(); inputStream = serialPort.getInputStream();
outputStream = serialPort.getOutputStream(); outputStream = serialPort.getOutputStream();
isStart = true; isStart = true;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -58,7 +66,6 @@ public class SerialPortUtil {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
@ -69,7 +76,7 @@ public class SerialPortUtil {
*/ */
public void sendSerialPort(String data) { public void sendSerialPort(String data) {
try { try {
byte[] sendData = DataUtils.HexToByteArr(data); byte[] sendData = data.getBytes(StandardCharsets.US_ASCII);
outputStream.write(sendData); outputStream.write(sendData);
outputStream.flush(); outputStream.flush();
} catch (IOException e) { } catch (IOException e) {
@ -100,10 +107,9 @@ public class SerialPortUtil {
try { try {
int size = inputStream.read(readData); int size = inputStream.read(readData);
if (size > 0) { if (size > 0) {
String readString = DataUtils.ByteArrToHex(readData, 0, size); String readString = new String(readData, 0, size, StandardCharsets.US_ASCII);
// EventBus.getDefault().post(readString); Log.d("wangym", "got msg = "+ readString);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

Binary file not shown.

@ -0,0 +1,9 @@
#!/bin/sh
# 转换平台签名命令
./keytool-importkeypair -k innovationapp.jks -p 123456 -pk8 platform.pk8 -cert platform.x509.pem -alias yinuo
# innovationapp.jks : 签名文件
# 123456 : 签名文件密码
# platform.pk8、platform.x509.pem : 系统签名文件
# yinuo : 签名文件别名
Loading…
Cancel
Save