[desc]:添加串口功能

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

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

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

@ -132,14 +132,20 @@ public class DemoActivity extends AppCompatActivity {
});
binding.mmkv.setOnClickListener(l -> {
MMKVUtils.INSTANCE.put("key", 100, "aa");
int value = MMKVUtils.INSTANCE.getInt("key", "bb");
Toast.makeText(DemoActivity.this, "" + value, Toast.LENGTH_SHORT).show();
// MMKVUtils.INSTANCE.put("key", 100, "aa");
// int value = MMKVUtils.INSTANCE.getInt("key", "bb");
// 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 -> {
SerialPortUtil serialPortUtil = new SerialPortUtil();
serialPortUtil = new SerialPortUtil();
serialPortUtil.openSerialPort();
});
}
private SerialPortUtil serialPortUtil = new SerialPortUtil();
}

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

@ -49,13 +49,6 @@ open class BaseObserve<T> {
return RequestManager.create(clazz)
}
/**
* 初始化服务类
*/
fun initService(clazz: Class<T>, interceptors: List<Interceptor>): T {
return RequestManager.create(clazz, interceptors)
}
/**
* 调用接口
* @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 异常

@ -6,4 +6,4 @@ package com.common.commonlib.serialport;
public interface Cmd {
String OPEN_DOOR = "010100000000FFFF";
}
}

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