()
- labelData.realPaths.forEachIndexed { index, s ->
+ realPaths.forEachIndexed { index, s ->
val file = File(s)
val fileMultipart = MultipartBody.Part.createFormData(
"fileBuffer${index + 1}", file.name, file.asRequestBody("image/png".toMediaType())
diff --git a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
index 921448f..83cda4a 100644
--- a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
+++ b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
@@ -13,31 +13,32 @@
public class SerialPort {
private static final String TAG = "SerialPort";
- /**
- * .so 库名字。需要去掉生成时自带的lib前缀
- * */
static {
- System.loadLibrary("serial_port");
+ System.loadLibrary("serialPort");
}
/**
- * JNI
- *
- * 必须用 native 标识JNI方法
+ * 打开串口
*/
- private native static FileDescriptor open(String path, int baudRate, int flags);
-
- public native void close();
+ private native FileDescriptor open(String path, int baudRate, int flags);
/**
- * Do not remove or rename the field mFd: it is used by native method close();
+ * 关闭串口
*/
- private FileDescriptor mFd;
- private final FileInputStream mFileInputStream;
- private final FileOutputStream mFileOutputStream;
+ private native void close();
- public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
+ /**
+ * jfieldID fd_id = env->GetFieldID(serial_port_class, "fd", "Ljava/io/FileDescriptor;");
+ *
+ * fd不能随意修改,要改就一起改
+ *
+ * Do not remove or rename the field fd: it is used by native method close();
+ */
+ private final FileDescriptor fd;
+ private final FileInputStream inputStream;
+ private final FileOutputStream outputStream;
+ public SerialPort(File device, int baudRate, int flags) throws SecurityException, IOException {
if (!device.canRead() || !device.canWrite()) {
try {
Process su;
@@ -54,20 +55,24 @@
}
}
- mFd = open(device.getAbsolutePath(), baudrate, flags);
- if (mFd == null) {
+ fd = open(device.getAbsolutePath(), baudRate, flags);
+ if (fd == null) {
Log.e(TAG, "native open returns null");
throw new IOException();
}
- mFileInputStream = new FileInputStream(mFd);
- mFileOutputStream = new FileOutputStream(mFd);
+ inputStream = new FileInputStream(fd);
+ outputStream = new FileOutputStream(fd);
}
public InputStream getInputStream() {
- return mFileInputStream;
+ return inputStream;
}
public OutputStream getOutputStream() {
- return mFileOutputStream;
+ return outputStream;
+ }
+
+ public void closeSerialPort() {
+ close();
}
}
diff --git a/.gitignore b/.gitignore
index 10a1363..18c6ed4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,18 @@
*.iml
.gradle
/local.properties
-/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
-local.properties
/app/build
/app/src/androidTest
/app/src/test
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..f766fc3
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..167cf0c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..b007d28
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..4515aa3
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 623fc18..59fdbea 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,15 @@
apply plugin: 'org.greenrobot.greendao'
android {
+// signingConfigs {
+// release {
+// storeFile file('ElectricDetector.jks')
+// storePassword '123456789'
+// keyAlias 'key0'
+// keyPassword '123456789'
+// }
+// }
+
compileSdkVersion 33
defaultConfig {
@@ -13,12 +22,6 @@
targetSdkVersion 33
versionCode 5020
versionName "5.0.2"
-
- ndk {
- moduleName "serial_port"
- //"log"表示加入Android Logcat日志,需要导入 #include "android/log.h"
- ldLibs "log"
- }
}
buildTypes {
@@ -28,6 +31,13 @@
}
}
+ externalNativeBuild {
+ cmake {
+ path file('src/main/cpp/CMakeLists.txt')
+ version '3.22.1'
+ }
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -43,8 +53,8 @@
}
}
- viewBinding {
- enabled true
+ buildFeatures {
+ viewBinding true
}
applicationVariants.every { variant ->
@@ -66,10 +76,10 @@
}
dependencies {
+ //基础依赖库
+ implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.8'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
- //基础依赖库
- implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.5.3'
//Google官方授权框架
implementation 'pub.devrel:easypermissions:3.0.0'
//腾讯Android UI框架
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 92d80c5..ba718ef 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -63,15 +63,17 @@
+
+
-
-
-
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "android/log.h"
+
+#define LOG_TAG "SerialPortJNI"
+
+#define LOG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
+#define LOG_E(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)
+
+static speed_t get_baud_rate(jint baud_rate) {
+ switch (baud_rate) {
+ case 0:
+ return B0;
+ case 50:
+ return B50;
+ case 75:
+ return B75;
+ case 110:
+ return B110;
+ case 134:
+ return B134;
+ case 150:
+ return B150;
+ case 200:
+ return B200;
+ case 300:
+ return B300;
+ case 600:
+ return B600;
+ case 1200:
+ return B1200;
+ case 1800:
+ return B1800;
+ case 2400:
+ return B2400;
+ case 4800:
+ return B4800;
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ case 1000000:
+ return B1000000;
+ case 1152000:
+ return B1152000;
+ case 1500000:
+ return B1500000;
+ case 2000000:
+ return B2000000;
+ case 2500000:
+ return B2500000;
+ case 3000000:
+ return B3000000;
+ case 3500000:
+ return B3500000;
+ case 4000000:
+ return B4000000;
+ default:
+ return -1;
+ }
+}
+
+extern "C"
+JNIEXPORT jobject JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_open(JNIEnv *env, jobject thiz, jstring path,
+ jint baud_rate, jint flags) {
+ int fd;
+ speed_t speed;
+ jobject file_descriptor;
+
+ speed = get_baud_rate(baud_rate);
+ if (speed == -1) {
+ LOG_E("invalid baud_rate");
+ return nullptr;
+ }
+
+ jboolean is_copy;
+ const char *path_utf = env->GetStringUTFChars(path, &is_copy);
+ fd = open(path_utf, O_RDWR | flags);
+ LOG_D("open serial port %s with flags 0x%x", path_utf, O_RDWR | flags);
+ env->ReleaseStringUTFChars(path, path_utf);
+ if (fd == -1) {
+ LOG_E("can not open Port");
+ return nullptr;
+ }
+
+ struct termios cfg{};
+ LOG_D("configure serial port %d", fd);
+ if (tcgetattr(fd, &cfg)) {
+ LOG_E("tcgetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ cfmakeraw(&cfg);
+ cfsetispeed(&cfg, speed);
+ cfsetospeed(&cfg, speed);
+
+ if (tcsetattr(fd, TCSANOW, &cfg)) {
+ LOG_E("tcsetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ //获取句柄
+ jclass fd_class = env->FindClass("java/io/FileDescriptor");
+ jmethodID fd_method_id = env->GetMethodID(fd_class, "", "()V");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(fd_class, descriptor_buffer, "I");
+
+ file_descriptor = env->NewObject(fd_class, fd_method_id);
+ env->SetIntField(file_descriptor, descriptor_field_id, (jint) fd);
+
+ return file_descriptor;
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_close(JNIEnv *env, jobject thiz) {
+ jclass serial_port_class = env->GetObjectClass(thiz);
+ jclass file_descriptor_class = env->FindClass("java/io/FileDescriptor");
+
+ // fd 对应SerialPortKit里面的 fd
+ char fd_buffer[4] = {0};
+ strcat(fd_buffer, "fd");
+ jfieldID fd_field_id = env->GetFieldID(serial_port_class, fd_buffer,
+ "Ljava/io/FileDescriptor;");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(file_descriptor_class, descriptor_buffer, "I");
+
+ jobject fd_obj = env->GetObjectField(thiz, fd_field_id);
+ jint descriptor = env->GetIntField(fd_obj, descriptor_field_id);
+
+ LOG_D("close(fd = %d)", descriptor);
+ close(descriptor);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
index 0dbff79..1010ab7 100644
--- a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
@@ -48,10 +48,4 @@
fun getDaoSession(): DaoSession {
return daoSession
}
-
- fun closeSerialPort() {
- serialPorts?.forEach {
- it.close()
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
index f6e6574..69a3ddd 100644
--- a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
@@ -17,8 +17,8 @@
abstract class SerialPortActivity : AppCompatActivity() {
protected lateinit var binding: VB
-
- lateinit var out: OutputStream
+ private val serialPorts by lazy { BaseApplication.get().getSerialPorts() }
+ var out: OutputStream? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -30,18 +30,19 @@
initEvent()
try {
- val serialPorts = BaseApplication.get().getSerialPorts()
//读
lifecycleScope.launch(Dispatchers.IO) {
serialPorts?.apply {
- val stream = this[0].inputStream
+ val stream = first().inputStream
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -57,10 +58,12 @@
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -72,8 +75,10 @@
//写
serialPorts?.apply {
- out = this[0].outputStream
+ out = first().outputStream
}
+
+ "串口已打开!".show(this)
} catch (e: SecurityException) {
"您没有串口的读写权限!".show(this)
} catch (e: IOException) {
@@ -114,7 +119,9 @@
abstract fun onDataReceived(buffer: ByteArray)
override fun onDestroy() {
- BaseApplication.get().closeSerialPort()
+ serialPorts?.forEach {
+ it.closeSerialPort()
+ }
super.onDestroy()
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
deleted file mode 100644
index 64e7181..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.casic.electric.detector.callback;
-
-public interface IAddressListener {
- void onGetAddress(String address);
-}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
deleted file mode 100644
index 6f1bd03..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.casic.electric.detector.callback
-
-import com.amap.api.location.AMapLocation
-
-interface ILocationListener {
- fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
new file mode 100644
index 0000000..7a4e313
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
@@ -0,0 +1,5 @@
+package com.casic.electric.detector.callback;
+
+public interface OnGetAddressListener {
+ void onGetAddress(String address);
+}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
new file mode 100644
index 0000000..a8ec79e
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
@@ -0,0 +1,7 @@
+package com.casic.electric.detector.callback
+
+import com.amap.api.location.AMapLocation
+
+interface OnGetLocationListener {
+ fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
index c96c6f5..fba0059 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
@@ -3,24 +3,15 @@
import com.amap.api.location.AMapLocation
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
-import com.casic.electric.detector.model.CalculateResult
import kotlin.math.acos
/**
- * 计算两个经纬度之间连线的方位角,因为距离很近(一般是3米内),球面近似为平面
- * C B
- * |-------/
- * | /
- * | /
- * | /
- * | /
- * | /
- * | /
- * |/
- * A
+ * 计算两个经纬度之间连线的方位角,因为距离很近(一般是5米内),球面近似为平面
+ * A(探测仪所在位置),B(最近的标识器位置),C(辅助点位置)
+ * 手机坐标轴Y轴反置,所以右下角才是第一象限
* */
-fun AMapLocation.calculateAngle(target: LatLng): CalculateResult {
- //构造直角辅助点
+fun AMapLocation.calculateAngle(target: LatLng): Int {
+ //构造直角辅助点C
val auxiliaryPoint = LatLng(target.latitude, this.longitude)
//AB线段长度
@@ -30,10 +21,10 @@
//AC线段长度
val auxiliaryDistance = AMapUtils.calculateLineDistance(
- LatLng(auxiliaryPoint.latitude, auxiliaryPoint.longitude), target
+ auxiliaryPoint, target
)
- //求余弦值
+ //求∠A的余弦值
val cosine = auxiliaryDistance / distance
//反余弦得弧度
@@ -43,17 +34,18 @@
val angle = (radian * 180) / Math.PI
//判断方位
- val direction = if (target.latitude > this.latitude && target.longitude > this.longitude) {
+ val direction = if (this.longitude < target.longitude && this.latitude < target.latitude) {
//东北方
- "东偏北"
- } else if (target.latitude < this.latitude && target.longitude < this.longitude) {
- //西南方
- "西偏南"
- } else if (target.latitude > this.latitude && target.longitude < this.longitude) {
+ angle.toInt()
+ } else if (this.longitude > target.longitude && this.latitude < target.latitude) {
//西北方
- "西偏北"
+ (angle + 90).toInt()
+ } else if (this.longitude > target.longitude && this.latitude > target.latitude) {
+ //西南方
+ (angle + 180).toInt()
} else {
- "东偏南"
+ //东南方
+ (angle + 270).toInt()
}
- return CalculateResult(angle.toInt(), direction, distance.toInt())
+ return direction
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/String.kt b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
index 838d3ad..55136a6 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/String.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
@@ -43,6 +43,7 @@
val httpConfig = "http://${serverIp}:${serverPort}"
return when (type) {
FileType.APK -> "$httpConfig/ems/${this}"
+ FileType.EXCEL -> "$httpConfig/ems/xls/marker${this}.xls"
FileType.IMAGE -> "$httpConfig/ems${this}"
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt b/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
deleted file mode 100644
index 50682fd..0000000
--- a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.casic.electric.detector.extensions
-
-import java.net.ConnectException
-
-fun Throwable.convertChinese(): String {
- this.printStackTrace()
- return when (this) {
- is ConnectException -> "连接失败,请检查网络或者服务器"
- else -> "服务器异常,请联系管理员"
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt b/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
deleted file mode 100644
index 84c9cd9..0000000
--- a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.casic.electric.detector.model
-
-data class CalculateResult(val angle: Int, val direction: String, val distance: Int)
diff --git a/app/src/main/java/com/casic/electric/detector/model/EventModel.java b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
new file mode 100644
index 0000000..27a53e4
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
@@ -0,0 +1,76 @@
+package com.casic.electric.detector.model;
+
+public class EventModel {
+ private Long id;
+ private Long taskId;
+ private String description;
+ private String createTime;
+ private String imageName;
+ private Double latitude;
+ private Double longitude;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(Long taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getImageName() {
+ return imageName;
+ }
+
+ public void setImageName(String imageName) {
+ this.imageName = imageName;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/model/TaskModel.java b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
new file mode 100644
index 0000000..65f5ae7
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
@@ -0,0 +1,265 @@
+package com.casic.electric.detector.model;
+
+import java.util.List;
+
+public class TaskModel {
+
+ private String success;
+ private List message;
+
+ public String getSuccess() {
+ return success;
+ }
+
+ public void setSuccess(String success) {
+ this.success = success;
+ }
+
+ public List getMessage() {
+ return message;
+ }
+
+ public void setMessage(List message) {
+ this.message = message;
+ }
+
+ public static class MessageModel {
+ private int id;
+ private String taskCode;
+ private String description;
+ private String deployDate;
+ private Object beginDate;
+ private Object endDate;
+ private String status;
+ private String creatorId;
+ private String creatorName;
+ private String patrolerId;
+ private String patrolerName;
+ private int isValid;
+ private List taskDetailInfos;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDeployDate() {
+ return deployDate;
+ }
+
+ public void setDeployDate(String deployDate) {
+ this.deployDate = deployDate;
+ }
+
+ public Object getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Object beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Object getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Object endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorName() {
+ return creatorName;
+ }
+
+ public void setCreatorName(String creatorName) {
+ this.creatorName = creatorName;
+ }
+
+ public String getPatrolerId() {
+ return patrolerId;
+ }
+
+ public void setPatrolerId(String patrolerId) {
+ this.patrolerId = patrolerId;
+ }
+
+ public String getPatrolerName() {
+ return patrolerName;
+ }
+
+ public void setPatrolerName(String patrolerName) {
+ this.patrolerName = patrolerName;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ public List getTaskDetailInfos() {
+ return taskDetailInfos;
+ }
+
+ public void setTaskDetailInfos(List taskDetailInfos) {
+ this.taskDetailInfos = taskDetailInfos;
+ }
+
+ public static class TaskDetailInfosModel {
+ private int id;
+ private String taskId;
+ private String taskCode;
+ private Object markerName;
+ private int markerId;
+ private String markerIdReal;
+ private double longitude;
+ private double latitude;
+ private int isChecked;
+ private int isNormal;
+ private Object imagePath;
+ private Object description;
+ private Object finishTime;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public Object getMarkerName() {
+ return markerName;
+ }
+
+ public void setMarkerName(Object markerName) {
+ this.markerName = markerName;
+ }
+
+ public int getMarkerId() {
+ return markerId;
+ }
+
+ public void setMarkerId(int markerId) {
+ this.markerId = markerId;
+ }
+
+ public String getMarkerIdReal() {
+ return markerIdReal;
+ }
+
+ public void setMarkerIdReal(String markerIdReal) {
+ this.markerIdReal = markerIdReal;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public int getIsChecked() {
+ return isChecked;
+ }
+
+ public void setIsChecked(int isChecked) {
+ this.isChecked = isChecked;
+ }
+
+ public int getIsNormal() {
+ return isNormal;
+ }
+
+ public void setIsNormal(int isNormal) {
+ this.isNormal = isNormal;
+ }
+
+ public Object getImagePath() {
+ return imagePath;
+ }
+
+ public void setImagePath(Object imagePath) {
+ this.imagePath = imagePath;
+ }
+
+ public Object getDescription() {
+ return description;
+ }
+
+ public void setDescription(Object description) {
+ this.description = description;
+ }
+
+ public Object getFinishTime() {
+ return finishTime;
+ }
+
+ public void setFinishTime(Object finishTime) {
+ this.finishTime = finishTime;
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
index 7836b28..26a2bdd 100644
--- a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
@@ -1,7 +1,6 @@
package com.casic.electric.detector.retrofit
import com.casic.electric.detector.extensions.reformat
-import com.casic.electric.detector.utils.LabelDataClass
import com.casic.electric.detector.utils.LocaleConstant
import com.casic.electric.detector.utils.SmallLabelDataClass
import com.google.gson.JsonObject
@@ -75,52 +74,62 @@
* 安装新标识器
* Multipart上传图片,文件,带多参数上传
*/
- suspend fun installLabel(labelData: LabelDataClass): String {
+ suspend fun installLabel(
+ companyId: String,
+ recordType: String,
+ markerObjectType: String,
+ pipeMaterial: String,
+ pipeDiameter: String,
+ depth: String,
+ belowType: String,
+ belowMaterial: String,
+ belowDiameter: String,
+ belowDepth: String,
+ layStyle: String,
+ area: String,
+ line: String,
+ road: String,
+ constructTime: String,
+ ownerComp: String,
+ markerObjectId: String,
+ markerId: String,
+ markerType: String,
+ markerDepth: String,
+ creator: String,
+ createTime: String,
+ longitude: String,
+ latitude: String,
+ colorType: String,
+ memo: String,
+ realPaths: ArrayList
+ ): String {
val param = JsonObject()
- param.addProperty("companyId", labelData.companyId)
- param.addProperty("recordType", labelData.recordType)
- param.addProperty("markerObjectId", labelData.markerObjectId)
- param.addProperty("objectName", labelData.objectName)
- param.addProperty("pressLevel", labelData.pressLevel)
- param.addProperty("markerObjectType", labelData.markerObjectType)
- param.addProperty("inlineName", labelData.inlineName)
- param.addProperty("wellMaterial", labelData.wellMaterial)
- param.addProperty("capacity", labelData.capacity)
- param.addProperty("transformerSpec", labelData.transformerSpec)
- param.addProperty("size", labelData.size)
- param.addProperty("inlineCount", labelData.inlineCount)
- param.addProperty("outlineCount", labelData.outlineCount)
- param.addProperty("cabinetType", labelData.cabinetType)
- param.addProperty("bottomDepth", labelData.bottomDepth)
- param.addProperty("holeCount", labelData.holeCount)
- param.addProperty("coverDepth", labelData.coverDepth)
- param.addProperty("crossPipe", labelData.crossPipe)
- param.addProperty("leftHoleCount", labelData.leftHoleCount)
- param.addProperty("tieCable1", labelData.tieCable1)
- param.addProperty("tieCable2", labelData.tieCable2)
- param.addProperty("jointCount", labelData.jointCount)
- param.addProperty("bushingMaterial", labelData.bushingMaterial)
- param.addProperty("bushingSpec", labelData.bushingSpec)
- param.addProperty("height", labelData.height)
- param.addProperty("lineNo", labelData.lineNo)
- param.addProperty("constructTime", labelData.constructTime)
- param.addProperty("operComp", labelData.operComp)
- param.addProperty("area", labelData.area)
- param.addProperty("road", labelData.road)
- param.addProperty("memo1", labelData.memo1)
- param.addProperty("memo2", labelData.memo2)
- param.addProperty("memo3", labelData.memo3)
- param.addProperty("markerId", labelData.markerId)
- param.addProperty("markerType", labelData.markerType)
- param.addProperty("owner", labelData.owner)
- param.addProperty("markerDepth", labelData.markerDepth)
- param.addProperty("createTime", labelData.createTime)
- param.addProperty("longitude", labelData.longitude)
- param.addProperty("latitude", labelData.latitude)
- param.addProperty("eleTagCount", labelData.eleTagCount)
- param.addProperty("markerMemo1", labelData.markerMemo1)
- param.addProperty("markerMemo2", labelData.markerMemo2)
- param.addProperty("markerMemo3", labelData.markerMemo3)
+ param.addProperty("companyId", companyId)
+ param.addProperty("recordType", recordType)
+ param.addProperty("markerObjectType", markerObjectType)
+ param.addProperty("pipeMaterial", pipeMaterial)
+ param.addProperty("pipeDiameter", pipeDiameter)
+ param.addProperty("depth", depth)
+ param.addProperty("belowType", belowType)
+ param.addProperty("belowMaterial", belowMaterial)
+ param.addProperty("belowDiameter", belowDiameter)
+ param.addProperty("belowDepth", belowDepth)
+ param.addProperty("layStyle", layStyle)
+ param.addProperty("area", area)
+ param.addProperty("line", line)
+ param.addProperty("road", road)
+ param.addProperty("constructTime", constructTime)
+ param.addProperty("ownerComp", ownerComp)
+ param.addProperty("markerObjectId", markerObjectId)
+ param.addProperty("markerId", markerId)
+ param.addProperty("markerType", markerType)
+ param.addProperty("markerDepth", markerDepth)
+ param.addProperty("creator", creator)
+ param.addProperty("createTime", createTime)
+ param.addProperty("longitude", longitude)
+ param.addProperty("latitude", latitude)
+ param.addProperty("colorType", colorType)
+ param.addProperty("memo", memo)
val requestBody = param.toString().toRequestBody(
"application/json;charset=UTF-8".toMediaType()
)
@@ -128,7 +137,7 @@
res["jsonMarker"] = requestBody
val multiParts = ArrayList()
- labelData.realPaths.forEachIndexed { index, s ->
+ realPaths.forEachIndexed { index, s ->
val file = File(s)
val fileMultipart = MultipartBody.Part.createFormData(
"fileBuffer${index + 1}", file.name, file.asRequestBody("image/png".toMediaType())
diff --git a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
index 921448f..83cda4a 100644
--- a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
+++ b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
@@ -13,31 +13,32 @@
public class SerialPort {
private static final String TAG = "SerialPort";
- /**
- * .so 库名字。需要去掉生成时自带的lib前缀
- * */
static {
- System.loadLibrary("serial_port");
+ System.loadLibrary("serialPort");
}
/**
- * JNI
- *
- * 必须用 native 标识JNI方法
+ * 打开串口
*/
- private native static FileDescriptor open(String path, int baudRate, int flags);
-
- public native void close();
+ private native FileDescriptor open(String path, int baudRate, int flags);
/**
- * Do not remove or rename the field mFd: it is used by native method close();
+ * 关闭串口
*/
- private FileDescriptor mFd;
- private final FileInputStream mFileInputStream;
- private final FileOutputStream mFileOutputStream;
+ private native void close();
- public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
+ /**
+ * jfieldID fd_id = env->GetFieldID(serial_port_class, "fd", "Ljava/io/FileDescriptor;");
+ *
+ * fd不能随意修改,要改就一起改
+ *
+ * Do not remove or rename the field fd: it is used by native method close();
+ */
+ private final FileDescriptor fd;
+ private final FileInputStream inputStream;
+ private final FileOutputStream outputStream;
+ public SerialPort(File device, int baudRate, int flags) throws SecurityException, IOException {
if (!device.canRead() || !device.canWrite()) {
try {
Process su;
@@ -54,20 +55,24 @@
}
}
- mFd = open(device.getAbsolutePath(), baudrate, flags);
- if (mFd == null) {
+ fd = open(device.getAbsolutePath(), baudRate, flags);
+ if (fd == null) {
Log.e(TAG, "native open returns null");
throw new IOException();
}
- mFileInputStream = new FileInputStream(mFd);
- mFileOutputStream = new FileOutputStream(mFd);
+ inputStream = new FileInputStream(fd);
+ outputStream = new FileOutputStream(fd);
}
public InputStream getInputStream() {
- return mFileInputStream;
+ return inputStream;
}
public OutputStream getOutputStream() {
- return mFileOutputStream;
+ return outputStream;
+ }
+
+ public void closeSerialPort() {
+ close();
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
index 8f6caba..f9e5457 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
@@ -90,21 +90,27 @@
LocaleConstant.CONDITION_ARRAY[1] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerNumber, value)
}
+
LocaleConstant.CONDITION_ARRAY[2] -> {
return queryByProperty(LabelBeanDao.Properties.ObjectName, value)
}
+
LocaleConstant.CONDITION_ARRAY[3] -> {
return queryByProperty(LabelBeanDao.Properties.Area, value)
}
+
LocaleConstant.CONDITION_ARRAY[4] -> {
return queryByProperty(LabelBeanDao.Properties.Road, value)
}
+
LocaleConstant.CONDITION_ARRAY[5] -> {
return queryByProperty(LabelBeanDao.Properties.InspectionUnit, value)
}
+
LocaleConstant.CONDITION_ARRAY[6] -> {
return queryByProperty(LabelBeanDao.Properties.Owner, value)
}
+
LocaleConstant.CONDITION_ARRAY[8] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerId, value)
}
@@ -132,6 +138,15 @@
.where(LabelBeanDao.Properties.MarkerId.eq(markerId))
.list()
}
+
+ fun deleteTaskById(taskId: String?) {
+ if (taskId.isNullOrBlank()) {
+ return
+ }
+// queryTaskById(taskId).forEach {
+// taskBeanDao.delete(it)
+// }
+ }
/******************************* Lable *** End **********************************************/
/******************************* Small Lable *** Start **************************************/
diff --git a/.gitignore b/.gitignore
index 10a1363..18c6ed4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,18 @@
*.iml
.gradle
/local.properties
-/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
-local.properties
/app/build
/app/src/androidTest
/app/src/test
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..f766fc3
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..167cf0c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..b007d28
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..4515aa3
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 623fc18..59fdbea 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,15 @@
apply plugin: 'org.greenrobot.greendao'
android {
+// signingConfigs {
+// release {
+// storeFile file('ElectricDetector.jks')
+// storePassword '123456789'
+// keyAlias 'key0'
+// keyPassword '123456789'
+// }
+// }
+
compileSdkVersion 33
defaultConfig {
@@ -13,12 +22,6 @@
targetSdkVersion 33
versionCode 5020
versionName "5.0.2"
-
- ndk {
- moduleName "serial_port"
- //"log"表示加入Android Logcat日志,需要导入 #include "android/log.h"
- ldLibs "log"
- }
}
buildTypes {
@@ -28,6 +31,13 @@
}
}
+ externalNativeBuild {
+ cmake {
+ path file('src/main/cpp/CMakeLists.txt')
+ version '3.22.1'
+ }
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -43,8 +53,8 @@
}
}
- viewBinding {
- enabled true
+ buildFeatures {
+ viewBinding true
}
applicationVariants.every { variant ->
@@ -66,10 +76,10 @@
}
dependencies {
+ //基础依赖库
+ implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.8'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
- //基础依赖库
- implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.5.3'
//Google官方授权框架
implementation 'pub.devrel:easypermissions:3.0.0'
//腾讯Android UI框架
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 92d80c5..ba718ef 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -63,15 +63,17 @@
+
+
-
-
-
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "android/log.h"
+
+#define LOG_TAG "SerialPortJNI"
+
+#define LOG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
+#define LOG_E(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)
+
+static speed_t get_baud_rate(jint baud_rate) {
+ switch (baud_rate) {
+ case 0:
+ return B0;
+ case 50:
+ return B50;
+ case 75:
+ return B75;
+ case 110:
+ return B110;
+ case 134:
+ return B134;
+ case 150:
+ return B150;
+ case 200:
+ return B200;
+ case 300:
+ return B300;
+ case 600:
+ return B600;
+ case 1200:
+ return B1200;
+ case 1800:
+ return B1800;
+ case 2400:
+ return B2400;
+ case 4800:
+ return B4800;
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ case 1000000:
+ return B1000000;
+ case 1152000:
+ return B1152000;
+ case 1500000:
+ return B1500000;
+ case 2000000:
+ return B2000000;
+ case 2500000:
+ return B2500000;
+ case 3000000:
+ return B3000000;
+ case 3500000:
+ return B3500000;
+ case 4000000:
+ return B4000000;
+ default:
+ return -1;
+ }
+}
+
+extern "C"
+JNIEXPORT jobject JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_open(JNIEnv *env, jobject thiz, jstring path,
+ jint baud_rate, jint flags) {
+ int fd;
+ speed_t speed;
+ jobject file_descriptor;
+
+ speed = get_baud_rate(baud_rate);
+ if (speed == -1) {
+ LOG_E("invalid baud_rate");
+ return nullptr;
+ }
+
+ jboolean is_copy;
+ const char *path_utf = env->GetStringUTFChars(path, &is_copy);
+ fd = open(path_utf, O_RDWR | flags);
+ LOG_D("open serial port %s with flags 0x%x", path_utf, O_RDWR | flags);
+ env->ReleaseStringUTFChars(path, path_utf);
+ if (fd == -1) {
+ LOG_E("can not open Port");
+ return nullptr;
+ }
+
+ struct termios cfg{};
+ LOG_D("configure serial port %d", fd);
+ if (tcgetattr(fd, &cfg)) {
+ LOG_E("tcgetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ cfmakeraw(&cfg);
+ cfsetispeed(&cfg, speed);
+ cfsetospeed(&cfg, speed);
+
+ if (tcsetattr(fd, TCSANOW, &cfg)) {
+ LOG_E("tcsetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ //获取句柄
+ jclass fd_class = env->FindClass("java/io/FileDescriptor");
+ jmethodID fd_method_id = env->GetMethodID(fd_class, "", "()V");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(fd_class, descriptor_buffer, "I");
+
+ file_descriptor = env->NewObject(fd_class, fd_method_id);
+ env->SetIntField(file_descriptor, descriptor_field_id, (jint) fd);
+
+ return file_descriptor;
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_close(JNIEnv *env, jobject thiz) {
+ jclass serial_port_class = env->GetObjectClass(thiz);
+ jclass file_descriptor_class = env->FindClass("java/io/FileDescriptor");
+
+ // fd 对应SerialPortKit里面的 fd
+ char fd_buffer[4] = {0};
+ strcat(fd_buffer, "fd");
+ jfieldID fd_field_id = env->GetFieldID(serial_port_class, fd_buffer,
+ "Ljava/io/FileDescriptor;");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(file_descriptor_class, descriptor_buffer, "I");
+
+ jobject fd_obj = env->GetObjectField(thiz, fd_field_id);
+ jint descriptor = env->GetIntField(fd_obj, descriptor_field_id);
+
+ LOG_D("close(fd = %d)", descriptor);
+ close(descriptor);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
index 0dbff79..1010ab7 100644
--- a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
@@ -48,10 +48,4 @@
fun getDaoSession(): DaoSession {
return daoSession
}
-
- fun closeSerialPort() {
- serialPorts?.forEach {
- it.close()
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
index f6e6574..69a3ddd 100644
--- a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
@@ -17,8 +17,8 @@
abstract class SerialPortActivity : AppCompatActivity() {
protected lateinit var binding: VB
-
- lateinit var out: OutputStream
+ private val serialPorts by lazy { BaseApplication.get().getSerialPorts() }
+ var out: OutputStream? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -30,18 +30,19 @@
initEvent()
try {
- val serialPorts = BaseApplication.get().getSerialPorts()
//读
lifecycleScope.launch(Dispatchers.IO) {
serialPorts?.apply {
- val stream = this[0].inputStream
+ val stream = first().inputStream
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -57,10 +58,12 @@
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -72,8 +75,10 @@
//写
serialPorts?.apply {
- out = this[0].outputStream
+ out = first().outputStream
}
+
+ "串口已打开!".show(this)
} catch (e: SecurityException) {
"您没有串口的读写权限!".show(this)
} catch (e: IOException) {
@@ -114,7 +119,9 @@
abstract fun onDataReceived(buffer: ByteArray)
override fun onDestroy() {
- BaseApplication.get().closeSerialPort()
+ serialPorts?.forEach {
+ it.closeSerialPort()
+ }
super.onDestroy()
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
deleted file mode 100644
index 64e7181..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.casic.electric.detector.callback;
-
-public interface IAddressListener {
- void onGetAddress(String address);
-}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
deleted file mode 100644
index 6f1bd03..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.casic.electric.detector.callback
-
-import com.amap.api.location.AMapLocation
-
-interface ILocationListener {
- fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
new file mode 100644
index 0000000..7a4e313
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
@@ -0,0 +1,5 @@
+package com.casic.electric.detector.callback;
+
+public interface OnGetAddressListener {
+ void onGetAddress(String address);
+}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
new file mode 100644
index 0000000..a8ec79e
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
@@ -0,0 +1,7 @@
+package com.casic.electric.detector.callback
+
+import com.amap.api.location.AMapLocation
+
+interface OnGetLocationListener {
+ fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
index c96c6f5..fba0059 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
@@ -3,24 +3,15 @@
import com.amap.api.location.AMapLocation
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
-import com.casic.electric.detector.model.CalculateResult
import kotlin.math.acos
/**
- * 计算两个经纬度之间连线的方位角,因为距离很近(一般是3米内),球面近似为平面
- * C B
- * |-------/
- * | /
- * | /
- * | /
- * | /
- * | /
- * | /
- * |/
- * A
+ * 计算两个经纬度之间连线的方位角,因为距离很近(一般是5米内),球面近似为平面
+ * A(探测仪所在位置),B(最近的标识器位置),C(辅助点位置)
+ * 手机坐标轴Y轴反置,所以右下角才是第一象限
* */
-fun AMapLocation.calculateAngle(target: LatLng): CalculateResult {
- //构造直角辅助点
+fun AMapLocation.calculateAngle(target: LatLng): Int {
+ //构造直角辅助点C
val auxiliaryPoint = LatLng(target.latitude, this.longitude)
//AB线段长度
@@ -30,10 +21,10 @@
//AC线段长度
val auxiliaryDistance = AMapUtils.calculateLineDistance(
- LatLng(auxiliaryPoint.latitude, auxiliaryPoint.longitude), target
+ auxiliaryPoint, target
)
- //求余弦值
+ //求∠A的余弦值
val cosine = auxiliaryDistance / distance
//反余弦得弧度
@@ -43,17 +34,18 @@
val angle = (radian * 180) / Math.PI
//判断方位
- val direction = if (target.latitude > this.latitude && target.longitude > this.longitude) {
+ val direction = if (this.longitude < target.longitude && this.latitude < target.latitude) {
//东北方
- "东偏北"
- } else if (target.latitude < this.latitude && target.longitude < this.longitude) {
- //西南方
- "西偏南"
- } else if (target.latitude > this.latitude && target.longitude < this.longitude) {
+ angle.toInt()
+ } else if (this.longitude > target.longitude && this.latitude < target.latitude) {
//西北方
- "西偏北"
+ (angle + 90).toInt()
+ } else if (this.longitude > target.longitude && this.latitude > target.latitude) {
+ //西南方
+ (angle + 180).toInt()
} else {
- "东偏南"
+ //东南方
+ (angle + 270).toInt()
}
- return CalculateResult(angle.toInt(), direction, distance.toInt())
+ return direction
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/String.kt b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
index 838d3ad..55136a6 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/String.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
@@ -43,6 +43,7 @@
val httpConfig = "http://${serverIp}:${serverPort}"
return when (type) {
FileType.APK -> "$httpConfig/ems/${this}"
+ FileType.EXCEL -> "$httpConfig/ems/xls/marker${this}.xls"
FileType.IMAGE -> "$httpConfig/ems${this}"
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt b/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
deleted file mode 100644
index 50682fd..0000000
--- a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.casic.electric.detector.extensions
-
-import java.net.ConnectException
-
-fun Throwable.convertChinese(): String {
- this.printStackTrace()
- return when (this) {
- is ConnectException -> "连接失败,请检查网络或者服务器"
- else -> "服务器异常,请联系管理员"
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt b/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
deleted file mode 100644
index 84c9cd9..0000000
--- a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.casic.electric.detector.model
-
-data class CalculateResult(val angle: Int, val direction: String, val distance: Int)
diff --git a/app/src/main/java/com/casic/electric/detector/model/EventModel.java b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
new file mode 100644
index 0000000..27a53e4
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
@@ -0,0 +1,76 @@
+package com.casic.electric.detector.model;
+
+public class EventModel {
+ private Long id;
+ private Long taskId;
+ private String description;
+ private String createTime;
+ private String imageName;
+ private Double latitude;
+ private Double longitude;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(Long taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getImageName() {
+ return imageName;
+ }
+
+ public void setImageName(String imageName) {
+ this.imageName = imageName;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/model/TaskModel.java b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
new file mode 100644
index 0000000..65f5ae7
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
@@ -0,0 +1,265 @@
+package com.casic.electric.detector.model;
+
+import java.util.List;
+
+public class TaskModel {
+
+ private String success;
+ private List message;
+
+ public String getSuccess() {
+ return success;
+ }
+
+ public void setSuccess(String success) {
+ this.success = success;
+ }
+
+ public List getMessage() {
+ return message;
+ }
+
+ public void setMessage(List message) {
+ this.message = message;
+ }
+
+ public static class MessageModel {
+ private int id;
+ private String taskCode;
+ private String description;
+ private String deployDate;
+ private Object beginDate;
+ private Object endDate;
+ private String status;
+ private String creatorId;
+ private String creatorName;
+ private String patrolerId;
+ private String patrolerName;
+ private int isValid;
+ private List taskDetailInfos;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDeployDate() {
+ return deployDate;
+ }
+
+ public void setDeployDate(String deployDate) {
+ this.deployDate = deployDate;
+ }
+
+ public Object getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Object beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Object getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Object endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorName() {
+ return creatorName;
+ }
+
+ public void setCreatorName(String creatorName) {
+ this.creatorName = creatorName;
+ }
+
+ public String getPatrolerId() {
+ return patrolerId;
+ }
+
+ public void setPatrolerId(String patrolerId) {
+ this.patrolerId = patrolerId;
+ }
+
+ public String getPatrolerName() {
+ return patrolerName;
+ }
+
+ public void setPatrolerName(String patrolerName) {
+ this.patrolerName = patrolerName;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ public List getTaskDetailInfos() {
+ return taskDetailInfos;
+ }
+
+ public void setTaskDetailInfos(List taskDetailInfos) {
+ this.taskDetailInfos = taskDetailInfos;
+ }
+
+ public static class TaskDetailInfosModel {
+ private int id;
+ private String taskId;
+ private String taskCode;
+ private Object markerName;
+ private int markerId;
+ private String markerIdReal;
+ private double longitude;
+ private double latitude;
+ private int isChecked;
+ private int isNormal;
+ private Object imagePath;
+ private Object description;
+ private Object finishTime;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public Object getMarkerName() {
+ return markerName;
+ }
+
+ public void setMarkerName(Object markerName) {
+ this.markerName = markerName;
+ }
+
+ public int getMarkerId() {
+ return markerId;
+ }
+
+ public void setMarkerId(int markerId) {
+ this.markerId = markerId;
+ }
+
+ public String getMarkerIdReal() {
+ return markerIdReal;
+ }
+
+ public void setMarkerIdReal(String markerIdReal) {
+ this.markerIdReal = markerIdReal;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public int getIsChecked() {
+ return isChecked;
+ }
+
+ public void setIsChecked(int isChecked) {
+ this.isChecked = isChecked;
+ }
+
+ public int getIsNormal() {
+ return isNormal;
+ }
+
+ public void setIsNormal(int isNormal) {
+ this.isNormal = isNormal;
+ }
+
+ public Object getImagePath() {
+ return imagePath;
+ }
+
+ public void setImagePath(Object imagePath) {
+ this.imagePath = imagePath;
+ }
+
+ public Object getDescription() {
+ return description;
+ }
+
+ public void setDescription(Object description) {
+ this.description = description;
+ }
+
+ public Object getFinishTime() {
+ return finishTime;
+ }
+
+ public void setFinishTime(Object finishTime) {
+ this.finishTime = finishTime;
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
index 7836b28..26a2bdd 100644
--- a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
@@ -1,7 +1,6 @@
package com.casic.electric.detector.retrofit
import com.casic.electric.detector.extensions.reformat
-import com.casic.electric.detector.utils.LabelDataClass
import com.casic.electric.detector.utils.LocaleConstant
import com.casic.electric.detector.utils.SmallLabelDataClass
import com.google.gson.JsonObject
@@ -75,52 +74,62 @@
* 安装新标识器
* Multipart上传图片,文件,带多参数上传
*/
- suspend fun installLabel(labelData: LabelDataClass): String {
+ suspend fun installLabel(
+ companyId: String,
+ recordType: String,
+ markerObjectType: String,
+ pipeMaterial: String,
+ pipeDiameter: String,
+ depth: String,
+ belowType: String,
+ belowMaterial: String,
+ belowDiameter: String,
+ belowDepth: String,
+ layStyle: String,
+ area: String,
+ line: String,
+ road: String,
+ constructTime: String,
+ ownerComp: String,
+ markerObjectId: String,
+ markerId: String,
+ markerType: String,
+ markerDepth: String,
+ creator: String,
+ createTime: String,
+ longitude: String,
+ latitude: String,
+ colorType: String,
+ memo: String,
+ realPaths: ArrayList
+ ): String {
val param = JsonObject()
- param.addProperty("companyId", labelData.companyId)
- param.addProperty("recordType", labelData.recordType)
- param.addProperty("markerObjectId", labelData.markerObjectId)
- param.addProperty("objectName", labelData.objectName)
- param.addProperty("pressLevel", labelData.pressLevel)
- param.addProperty("markerObjectType", labelData.markerObjectType)
- param.addProperty("inlineName", labelData.inlineName)
- param.addProperty("wellMaterial", labelData.wellMaterial)
- param.addProperty("capacity", labelData.capacity)
- param.addProperty("transformerSpec", labelData.transformerSpec)
- param.addProperty("size", labelData.size)
- param.addProperty("inlineCount", labelData.inlineCount)
- param.addProperty("outlineCount", labelData.outlineCount)
- param.addProperty("cabinetType", labelData.cabinetType)
- param.addProperty("bottomDepth", labelData.bottomDepth)
- param.addProperty("holeCount", labelData.holeCount)
- param.addProperty("coverDepth", labelData.coverDepth)
- param.addProperty("crossPipe", labelData.crossPipe)
- param.addProperty("leftHoleCount", labelData.leftHoleCount)
- param.addProperty("tieCable1", labelData.tieCable1)
- param.addProperty("tieCable2", labelData.tieCable2)
- param.addProperty("jointCount", labelData.jointCount)
- param.addProperty("bushingMaterial", labelData.bushingMaterial)
- param.addProperty("bushingSpec", labelData.bushingSpec)
- param.addProperty("height", labelData.height)
- param.addProperty("lineNo", labelData.lineNo)
- param.addProperty("constructTime", labelData.constructTime)
- param.addProperty("operComp", labelData.operComp)
- param.addProperty("area", labelData.area)
- param.addProperty("road", labelData.road)
- param.addProperty("memo1", labelData.memo1)
- param.addProperty("memo2", labelData.memo2)
- param.addProperty("memo3", labelData.memo3)
- param.addProperty("markerId", labelData.markerId)
- param.addProperty("markerType", labelData.markerType)
- param.addProperty("owner", labelData.owner)
- param.addProperty("markerDepth", labelData.markerDepth)
- param.addProperty("createTime", labelData.createTime)
- param.addProperty("longitude", labelData.longitude)
- param.addProperty("latitude", labelData.latitude)
- param.addProperty("eleTagCount", labelData.eleTagCount)
- param.addProperty("markerMemo1", labelData.markerMemo1)
- param.addProperty("markerMemo2", labelData.markerMemo2)
- param.addProperty("markerMemo3", labelData.markerMemo3)
+ param.addProperty("companyId", companyId)
+ param.addProperty("recordType", recordType)
+ param.addProperty("markerObjectType", markerObjectType)
+ param.addProperty("pipeMaterial", pipeMaterial)
+ param.addProperty("pipeDiameter", pipeDiameter)
+ param.addProperty("depth", depth)
+ param.addProperty("belowType", belowType)
+ param.addProperty("belowMaterial", belowMaterial)
+ param.addProperty("belowDiameter", belowDiameter)
+ param.addProperty("belowDepth", belowDepth)
+ param.addProperty("layStyle", layStyle)
+ param.addProperty("area", area)
+ param.addProperty("line", line)
+ param.addProperty("road", road)
+ param.addProperty("constructTime", constructTime)
+ param.addProperty("ownerComp", ownerComp)
+ param.addProperty("markerObjectId", markerObjectId)
+ param.addProperty("markerId", markerId)
+ param.addProperty("markerType", markerType)
+ param.addProperty("markerDepth", markerDepth)
+ param.addProperty("creator", creator)
+ param.addProperty("createTime", createTime)
+ param.addProperty("longitude", longitude)
+ param.addProperty("latitude", latitude)
+ param.addProperty("colorType", colorType)
+ param.addProperty("memo", memo)
val requestBody = param.toString().toRequestBody(
"application/json;charset=UTF-8".toMediaType()
)
@@ -128,7 +137,7 @@
res["jsonMarker"] = requestBody
val multiParts = ArrayList()
- labelData.realPaths.forEachIndexed { index, s ->
+ realPaths.forEachIndexed { index, s ->
val file = File(s)
val fileMultipart = MultipartBody.Part.createFormData(
"fileBuffer${index + 1}", file.name, file.asRequestBody("image/png".toMediaType())
diff --git a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
index 921448f..83cda4a 100644
--- a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
+++ b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
@@ -13,31 +13,32 @@
public class SerialPort {
private static final String TAG = "SerialPort";
- /**
- * .so 库名字。需要去掉生成时自带的lib前缀
- * */
static {
- System.loadLibrary("serial_port");
+ System.loadLibrary("serialPort");
}
/**
- * JNI
- *
- * 必须用 native 标识JNI方法
+ * 打开串口
*/
- private native static FileDescriptor open(String path, int baudRate, int flags);
-
- public native void close();
+ private native FileDescriptor open(String path, int baudRate, int flags);
/**
- * Do not remove or rename the field mFd: it is used by native method close();
+ * 关闭串口
*/
- private FileDescriptor mFd;
- private final FileInputStream mFileInputStream;
- private final FileOutputStream mFileOutputStream;
+ private native void close();
- public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
+ /**
+ * jfieldID fd_id = env->GetFieldID(serial_port_class, "fd", "Ljava/io/FileDescriptor;");
+ *
+ * fd不能随意修改,要改就一起改
+ *
+ * Do not remove or rename the field fd: it is used by native method close();
+ */
+ private final FileDescriptor fd;
+ private final FileInputStream inputStream;
+ private final FileOutputStream outputStream;
+ public SerialPort(File device, int baudRate, int flags) throws SecurityException, IOException {
if (!device.canRead() || !device.canWrite()) {
try {
Process su;
@@ -54,20 +55,24 @@
}
}
- mFd = open(device.getAbsolutePath(), baudrate, flags);
- if (mFd == null) {
+ fd = open(device.getAbsolutePath(), baudRate, flags);
+ if (fd == null) {
Log.e(TAG, "native open returns null");
throw new IOException();
}
- mFileInputStream = new FileInputStream(mFd);
- mFileOutputStream = new FileOutputStream(mFd);
+ inputStream = new FileInputStream(fd);
+ outputStream = new FileOutputStream(fd);
}
public InputStream getInputStream() {
- return mFileInputStream;
+ return inputStream;
}
public OutputStream getOutputStream() {
- return mFileOutputStream;
+ return outputStream;
+ }
+
+ public void closeSerialPort() {
+ close();
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
index 8f6caba..f9e5457 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
@@ -90,21 +90,27 @@
LocaleConstant.CONDITION_ARRAY[1] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerNumber, value)
}
+
LocaleConstant.CONDITION_ARRAY[2] -> {
return queryByProperty(LabelBeanDao.Properties.ObjectName, value)
}
+
LocaleConstant.CONDITION_ARRAY[3] -> {
return queryByProperty(LabelBeanDao.Properties.Area, value)
}
+
LocaleConstant.CONDITION_ARRAY[4] -> {
return queryByProperty(LabelBeanDao.Properties.Road, value)
}
+
LocaleConstant.CONDITION_ARRAY[5] -> {
return queryByProperty(LabelBeanDao.Properties.InspectionUnit, value)
}
+
LocaleConstant.CONDITION_ARRAY[6] -> {
return queryByProperty(LabelBeanDao.Properties.Owner, value)
}
+
LocaleConstant.CONDITION_ARRAY[8] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerId, value)
}
@@ -132,6 +138,15 @@
.where(LabelBeanDao.Properties.MarkerId.eq(markerId))
.list()
}
+
+ fun deleteTaskById(taskId: String?) {
+ if (taskId.isNullOrBlank()) {
+ return
+ }
+// queryTaskById(taskId).forEach {
+// taskBeanDao.delete(it)
+// }
+ }
/******************************* Lable *** End **********************************************/
/******************************* Small Lable *** Start **************************************/
diff --git a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
index 362df50..67c666e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
@@ -3,5 +3,7 @@
sealed class FileType {
object APK : FileType()
+ object EXCEL : FileType()
+
object IMAGE : FileType()
}
diff --git a/.gitignore b/.gitignore
index 10a1363..18c6ed4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,18 @@
*.iml
.gradle
/local.properties
-/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
-local.properties
/app/build
/app/src/androidTest
/app/src/test
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..f766fc3
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..167cf0c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..b007d28
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..4515aa3
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 623fc18..59fdbea 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,15 @@
apply plugin: 'org.greenrobot.greendao'
android {
+// signingConfigs {
+// release {
+// storeFile file('ElectricDetector.jks')
+// storePassword '123456789'
+// keyAlias 'key0'
+// keyPassword '123456789'
+// }
+// }
+
compileSdkVersion 33
defaultConfig {
@@ -13,12 +22,6 @@
targetSdkVersion 33
versionCode 5020
versionName "5.0.2"
-
- ndk {
- moduleName "serial_port"
- //"log"表示加入Android Logcat日志,需要导入 #include "android/log.h"
- ldLibs "log"
- }
}
buildTypes {
@@ -28,6 +31,13 @@
}
}
+ externalNativeBuild {
+ cmake {
+ path file('src/main/cpp/CMakeLists.txt')
+ version '3.22.1'
+ }
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -43,8 +53,8 @@
}
}
- viewBinding {
- enabled true
+ buildFeatures {
+ viewBinding true
}
applicationVariants.every { variant ->
@@ -66,10 +76,10 @@
}
dependencies {
+ //基础依赖库
+ implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.8'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
- //基础依赖库
- implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.5.3'
//Google官方授权框架
implementation 'pub.devrel:easypermissions:3.0.0'
//腾讯Android UI框架
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 92d80c5..ba718ef 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -63,15 +63,17 @@
+
+
-
-
-
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "android/log.h"
+
+#define LOG_TAG "SerialPortJNI"
+
+#define LOG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
+#define LOG_E(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)
+
+static speed_t get_baud_rate(jint baud_rate) {
+ switch (baud_rate) {
+ case 0:
+ return B0;
+ case 50:
+ return B50;
+ case 75:
+ return B75;
+ case 110:
+ return B110;
+ case 134:
+ return B134;
+ case 150:
+ return B150;
+ case 200:
+ return B200;
+ case 300:
+ return B300;
+ case 600:
+ return B600;
+ case 1200:
+ return B1200;
+ case 1800:
+ return B1800;
+ case 2400:
+ return B2400;
+ case 4800:
+ return B4800;
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ case 1000000:
+ return B1000000;
+ case 1152000:
+ return B1152000;
+ case 1500000:
+ return B1500000;
+ case 2000000:
+ return B2000000;
+ case 2500000:
+ return B2500000;
+ case 3000000:
+ return B3000000;
+ case 3500000:
+ return B3500000;
+ case 4000000:
+ return B4000000;
+ default:
+ return -1;
+ }
+}
+
+extern "C"
+JNIEXPORT jobject JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_open(JNIEnv *env, jobject thiz, jstring path,
+ jint baud_rate, jint flags) {
+ int fd;
+ speed_t speed;
+ jobject file_descriptor;
+
+ speed = get_baud_rate(baud_rate);
+ if (speed == -1) {
+ LOG_E("invalid baud_rate");
+ return nullptr;
+ }
+
+ jboolean is_copy;
+ const char *path_utf = env->GetStringUTFChars(path, &is_copy);
+ fd = open(path_utf, O_RDWR | flags);
+ LOG_D("open serial port %s with flags 0x%x", path_utf, O_RDWR | flags);
+ env->ReleaseStringUTFChars(path, path_utf);
+ if (fd == -1) {
+ LOG_E("can not open Port");
+ return nullptr;
+ }
+
+ struct termios cfg{};
+ LOG_D("configure serial port %d", fd);
+ if (tcgetattr(fd, &cfg)) {
+ LOG_E("tcgetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ cfmakeraw(&cfg);
+ cfsetispeed(&cfg, speed);
+ cfsetospeed(&cfg, speed);
+
+ if (tcsetattr(fd, TCSANOW, &cfg)) {
+ LOG_E("tcsetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ //获取句柄
+ jclass fd_class = env->FindClass("java/io/FileDescriptor");
+ jmethodID fd_method_id = env->GetMethodID(fd_class, "", "()V");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(fd_class, descriptor_buffer, "I");
+
+ file_descriptor = env->NewObject(fd_class, fd_method_id);
+ env->SetIntField(file_descriptor, descriptor_field_id, (jint) fd);
+
+ return file_descriptor;
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_close(JNIEnv *env, jobject thiz) {
+ jclass serial_port_class = env->GetObjectClass(thiz);
+ jclass file_descriptor_class = env->FindClass("java/io/FileDescriptor");
+
+ // fd 对应SerialPortKit里面的 fd
+ char fd_buffer[4] = {0};
+ strcat(fd_buffer, "fd");
+ jfieldID fd_field_id = env->GetFieldID(serial_port_class, fd_buffer,
+ "Ljava/io/FileDescriptor;");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(file_descriptor_class, descriptor_buffer, "I");
+
+ jobject fd_obj = env->GetObjectField(thiz, fd_field_id);
+ jint descriptor = env->GetIntField(fd_obj, descriptor_field_id);
+
+ LOG_D("close(fd = %d)", descriptor);
+ close(descriptor);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
index 0dbff79..1010ab7 100644
--- a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
@@ -48,10 +48,4 @@
fun getDaoSession(): DaoSession {
return daoSession
}
-
- fun closeSerialPort() {
- serialPorts?.forEach {
- it.close()
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
index f6e6574..69a3ddd 100644
--- a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
@@ -17,8 +17,8 @@
abstract class SerialPortActivity : AppCompatActivity() {
protected lateinit var binding: VB
-
- lateinit var out: OutputStream
+ private val serialPorts by lazy { BaseApplication.get().getSerialPorts() }
+ var out: OutputStream? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -30,18 +30,19 @@
initEvent()
try {
- val serialPorts = BaseApplication.get().getSerialPorts()
//读
lifecycleScope.launch(Dispatchers.IO) {
serialPorts?.apply {
- val stream = this[0].inputStream
+ val stream = first().inputStream
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -57,10 +58,12 @@
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -72,8 +75,10 @@
//写
serialPorts?.apply {
- out = this[0].outputStream
+ out = first().outputStream
}
+
+ "串口已打开!".show(this)
} catch (e: SecurityException) {
"您没有串口的读写权限!".show(this)
} catch (e: IOException) {
@@ -114,7 +119,9 @@
abstract fun onDataReceived(buffer: ByteArray)
override fun onDestroy() {
- BaseApplication.get().closeSerialPort()
+ serialPorts?.forEach {
+ it.closeSerialPort()
+ }
super.onDestroy()
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
deleted file mode 100644
index 64e7181..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.casic.electric.detector.callback;
-
-public interface IAddressListener {
- void onGetAddress(String address);
-}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
deleted file mode 100644
index 6f1bd03..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.casic.electric.detector.callback
-
-import com.amap.api.location.AMapLocation
-
-interface ILocationListener {
- fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
new file mode 100644
index 0000000..7a4e313
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
@@ -0,0 +1,5 @@
+package com.casic.electric.detector.callback;
+
+public interface OnGetAddressListener {
+ void onGetAddress(String address);
+}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
new file mode 100644
index 0000000..a8ec79e
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
@@ -0,0 +1,7 @@
+package com.casic.electric.detector.callback
+
+import com.amap.api.location.AMapLocation
+
+interface OnGetLocationListener {
+ fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
index c96c6f5..fba0059 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
@@ -3,24 +3,15 @@
import com.amap.api.location.AMapLocation
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
-import com.casic.electric.detector.model.CalculateResult
import kotlin.math.acos
/**
- * 计算两个经纬度之间连线的方位角,因为距离很近(一般是3米内),球面近似为平面
- * C B
- * |-------/
- * | /
- * | /
- * | /
- * | /
- * | /
- * | /
- * |/
- * A
+ * 计算两个经纬度之间连线的方位角,因为距离很近(一般是5米内),球面近似为平面
+ * A(探测仪所在位置),B(最近的标识器位置),C(辅助点位置)
+ * 手机坐标轴Y轴反置,所以右下角才是第一象限
* */
-fun AMapLocation.calculateAngle(target: LatLng): CalculateResult {
- //构造直角辅助点
+fun AMapLocation.calculateAngle(target: LatLng): Int {
+ //构造直角辅助点C
val auxiliaryPoint = LatLng(target.latitude, this.longitude)
//AB线段长度
@@ -30,10 +21,10 @@
//AC线段长度
val auxiliaryDistance = AMapUtils.calculateLineDistance(
- LatLng(auxiliaryPoint.latitude, auxiliaryPoint.longitude), target
+ auxiliaryPoint, target
)
- //求余弦值
+ //求∠A的余弦值
val cosine = auxiliaryDistance / distance
//反余弦得弧度
@@ -43,17 +34,18 @@
val angle = (radian * 180) / Math.PI
//判断方位
- val direction = if (target.latitude > this.latitude && target.longitude > this.longitude) {
+ val direction = if (this.longitude < target.longitude && this.latitude < target.latitude) {
//东北方
- "东偏北"
- } else if (target.latitude < this.latitude && target.longitude < this.longitude) {
- //西南方
- "西偏南"
- } else if (target.latitude > this.latitude && target.longitude < this.longitude) {
+ angle.toInt()
+ } else if (this.longitude > target.longitude && this.latitude < target.latitude) {
//西北方
- "西偏北"
+ (angle + 90).toInt()
+ } else if (this.longitude > target.longitude && this.latitude > target.latitude) {
+ //西南方
+ (angle + 180).toInt()
} else {
- "东偏南"
+ //东南方
+ (angle + 270).toInt()
}
- return CalculateResult(angle.toInt(), direction, distance.toInt())
+ return direction
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/String.kt b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
index 838d3ad..55136a6 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/String.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
@@ -43,6 +43,7 @@
val httpConfig = "http://${serverIp}:${serverPort}"
return when (type) {
FileType.APK -> "$httpConfig/ems/${this}"
+ FileType.EXCEL -> "$httpConfig/ems/xls/marker${this}.xls"
FileType.IMAGE -> "$httpConfig/ems${this}"
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt b/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
deleted file mode 100644
index 50682fd..0000000
--- a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.casic.electric.detector.extensions
-
-import java.net.ConnectException
-
-fun Throwable.convertChinese(): String {
- this.printStackTrace()
- return when (this) {
- is ConnectException -> "连接失败,请检查网络或者服务器"
- else -> "服务器异常,请联系管理员"
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt b/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
deleted file mode 100644
index 84c9cd9..0000000
--- a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.casic.electric.detector.model
-
-data class CalculateResult(val angle: Int, val direction: String, val distance: Int)
diff --git a/app/src/main/java/com/casic/electric/detector/model/EventModel.java b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
new file mode 100644
index 0000000..27a53e4
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
@@ -0,0 +1,76 @@
+package com.casic.electric.detector.model;
+
+public class EventModel {
+ private Long id;
+ private Long taskId;
+ private String description;
+ private String createTime;
+ private String imageName;
+ private Double latitude;
+ private Double longitude;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(Long taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getImageName() {
+ return imageName;
+ }
+
+ public void setImageName(String imageName) {
+ this.imageName = imageName;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/model/TaskModel.java b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
new file mode 100644
index 0000000..65f5ae7
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
@@ -0,0 +1,265 @@
+package com.casic.electric.detector.model;
+
+import java.util.List;
+
+public class TaskModel {
+
+ private String success;
+ private List message;
+
+ public String getSuccess() {
+ return success;
+ }
+
+ public void setSuccess(String success) {
+ this.success = success;
+ }
+
+ public List getMessage() {
+ return message;
+ }
+
+ public void setMessage(List message) {
+ this.message = message;
+ }
+
+ public static class MessageModel {
+ private int id;
+ private String taskCode;
+ private String description;
+ private String deployDate;
+ private Object beginDate;
+ private Object endDate;
+ private String status;
+ private String creatorId;
+ private String creatorName;
+ private String patrolerId;
+ private String patrolerName;
+ private int isValid;
+ private List taskDetailInfos;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDeployDate() {
+ return deployDate;
+ }
+
+ public void setDeployDate(String deployDate) {
+ this.deployDate = deployDate;
+ }
+
+ public Object getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Object beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Object getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Object endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorName() {
+ return creatorName;
+ }
+
+ public void setCreatorName(String creatorName) {
+ this.creatorName = creatorName;
+ }
+
+ public String getPatrolerId() {
+ return patrolerId;
+ }
+
+ public void setPatrolerId(String patrolerId) {
+ this.patrolerId = patrolerId;
+ }
+
+ public String getPatrolerName() {
+ return patrolerName;
+ }
+
+ public void setPatrolerName(String patrolerName) {
+ this.patrolerName = patrolerName;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ public List getTaskDetailInfos() {
+ return taskDetailInfos;
+ }
+
+ public void setTaskDetailInfos(List taskDetailInfos) {
+ this.taskDetailInfos = taskDetailInfos;
+ }
+
+ public static class TaskDetailInfosModel {
+ private int id;
+ private String taskId;
+ private String taskCode;
+ private Object markerName;
+ private int markerId;
+ private String markerIdReal;
+ private double longitude;
+ private double latitude;
+ private int isChecked;
+ private int isNormal;
+ private Object imagePath;
+ private Object description;
+ private Object finishTime;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public Object getMarkerName() {
+ return markerName;
+ }
+
+ public void setMarkerName(Object markerName) {
+ this.markerName = markerName;
+ }
+
+ public int getMarkerId() {
+ return markerId;
+ }
+
+ public void setMarkerId(int markerId) {
+ this.markerId = markerId;
+ }
+
+ public String getMarkerIdReal() {
+ return markerIdReal;
+ }
+
+ public void setMarkerIdReal(String markerIdReal) {
+ this.markerIdReal = markerIdReal;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public int getIsChecked() {
+ return isChecked;
+ }
+
+ public void setIsChecked(int isChecked) {
+ this.isChecked = isChecked;
+ }
+
+ public int getIsNormal() {
+ return isNormal;
+ }
+
+ public void setIsNormal(int isNormal) {
+ this.isNormal = isNormal;
+ }
+
+ public Object getImagePath() {
+ return imagePath;
+ }
+
+ public void setImagePath(Object imagePath) {
+ this.imagePath = imagePath;
+ }
+
+ public Object getDescription() {
+ return description;
+ }
+
+ public void setDescription(Object description) {
+ this.description = description;
+ }
+
+ public Object getFinishTime() {
+ return finishTime;
+ }
+
+ public void setFinishTime(Object finishTime) {
+ this.finishTime = finishTime;
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
index 7836b28..26a2bdd 100644
--- a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
@@ -1,7 +1,6 @@
package com.casic.electric.detector.retrofit
import com.casic.electric.detector.extensions.reformat
-import com.casic.electric.detector.utils.LabelDataClass
import com.casic.electric.detector.utils.LocaleConstant
import com.casic.electric.detector.utils.SmallLabelDataClass
import com.google.gson.JsonObject
@@ -75,52 +74,62 @@
* 安装新标识器
* Multipart上传图片,文件,带多参数上传
*/
- suspend fun installLabel(labelData: LabelDataClass): String {
+ suspend fun installLabel(
+ companyId: String,
+ recordType: String,
+ markerObjectType: String,
+ pipeMaterial: String,
+ pipeDiameter: String,
+ depth: String,
+ belowType: String,
+ belowMaterial: String,
+ belowDiameter: String,
+ belowDepth: String,
+ layStyle: String,
+ area: String,
+ line: String,
+ road: String,
+ constructTime: String,
+ ownerComp: String,
+ markerObjectId: String,
+ markerId: String,
+ markerType: String,
+ markerDepth: String,
+ creator: String,
+ createTime: String,
+ longitude: String,
+ latitude: String,
+ colorType: String,
+ memo: String,
+ realPaths: ArrayList
+ ): String {
val param = JsonObject()
- param.addProperty("companyId", labelData.companyId)
- param.addProperty("recordType", labelData.recordType)
- param.addProperty("markerObjectId", labelData.markerObjectId)
- param.addProperty("objectName", labelData.objectName)
- param.addProperty("pressLevel", labelData.pressLevel)
- param.addProperty("markerObjectType", labelData.markerObjectType)
- param.addProperty("inlineName", labelData.inlineName)
- param.addProperty("wellMaterial", labelData.wellMaterial)
- param.addProperty("capacity", labelData.capacity)
- param.addProperty("transformerSpec", labelData.transformerSpec)
- param.addProperty("size", labelData.size)
- param.addProperty("inlineCount", labelData.inlineCount)
- param.addProperty("outlineCount", labelData.outlineCount)
- param.addProperty("cabinetType", labelData.cabinetType)
- param.addProperty("bottomDepth", labelData.bottomDepth)
- param.addProperty("holeCount", labelData.holeCount)
- param.addProperty("coverDepth", labelData.coverDepth)
- param.addProperty("crossPipe", labelData.crossPipe)
- param.addProperty("leftHoleCount", labelData.leftHoleCount)
- param.addProperty("tieCable1", labelData.tieCable1)
- param.addProperty("tieCable2", labelData.tieCable2)
- param.addProperty("jointCount", labelData.jointCount)
- param.addProperty("bushingMaterial", labelData.bushingMaterial)
- param.addProperty("bushingSpec", labelData.bushingSpec)
- param.addProperty("height", labelData.height)
- param.addProperty("lineNo", labelData.lineNo)
- param.addProperty("constructTime", labelData.constructTime)
- param.addProperty("operComp", labelData.operComp)
- param.addProperty("area", labelData.area)
- param.addProperty("road", labelData.road)
- param.addProperty("memo1", labelData.memo1)
- param.addProperty("memo2", labelData.memo2)
- param.addProperty("memo3", labelData.memo3)
- param.addProperty("markerId", labelData.markerId)
- param.addProperty("markerType", labelData.markerType)
- param.addProperty("owner", labelData.owner)
- param.addProperty("markerDepth", labelData.markerDepth)
- param.addProperty("createTime", labelData.createTime)
- param.addProperty("longitude", labelData.longitude)
- param.addProperty("latitude", labelData.latitude)
- param.addProperty("eleTagCount", labelData.eleTagCount)
- param.addProperty("markerMemo1", labelData.markerMemo1)
- param.addProperty("markerMemo2", labelData.markerMemo2)
- param.addProperty("markerMemo3", labelData.markerMemo3)
+ param.addProperty("companyId", companyId)
+ param.addProperty("recordType", recordType)
+ param.addProperty("markerObjectType", markerObjectType)
+ param.addProperty("pipeMaterial", pipeMaterial)
+ param.addProperty("pipeDiameter", pipeDiameter)
+ param.addProperty("depth", depth)
+ param.addProperty("belowType", belowType)
+ param.addProperty("belowMaterial", belowMaterial)
+ param.addProperty("belowDiameter", belowDiameter)
+ param.addProperty("belowDepth", belowDepth)
+ param.addProperty("layStyle", layStyle)
+ param.addProperty("area", area)
+ param.addProperty("line", line)
+ param.addProperty("road", road)
+ param.addProperty("constructTime", constructTime)
+ param.addProperty("ownerComp", ownerComp)
+ param.addProperty("markerObjectId", markerObjectId)
+ param.addProperty("markerId", markerId)
+ param.addProperty("markerType", markerType)
+ param.addProperty("markerDepth", markerDepth)
+ param.addProperty("creator", creator)
+ param.addProperty("createTime", createTime)
+ param.addProperty("longitude", longitude)
+ param.addProperty("latitude", latitude)
+ param.addProperty("colorType", colorType)
+ param.addProperty("memo", memo)
val requestBody = param.toString().toRequestBody(
"application/json;charset=UTF-8".toMediaType()
)
@@ -128,7 +137,7 @@
res["jsonMarker"] = requestBody
val multiParts = ArrayList()
- labelData.realPaths.forEachIndexed { index, s ->
+ realPaths.forEachIndexed { index, s ->
val file = File(s)
val fileMultipart = MultipartBody.Part.createFormData(
"fileBuffer${index + 1}", file.name, file.asRequestBody("image/png".toMediaType())
diff --git a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
index 921448f..83cda4a 100644
--- a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
+++ b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
@@ -13,31 +13,32 @@
public class SerialPort {
private static final String TAG = "SerialPort";
- /**
- * .so 库名字。需要去掉生成时自带的lib前缀
- * */
static {
- System.loadLibrary("serial_port");
+ System.loadLibrary("serialPort");
}
/**
- * JNI
- *
- * 必须用 native 标识JNI方法
+ * 打开串口
*/
- private native static FileDescriptor open(String path, int baudRate, int flags);
-
- public native void close();
+ private native FileDescriptor open(String path, int baudRate, int flags);
/**
- * Do not remove or rename the field mFd: it is used by native method close();
+ * 关闭串口
*/
- private FileDescriptor mFd;
- private final FileInputStream mFileInputStream;
- private final FileOutputStream mFileOutputStream;
+ private native void close();
- public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
+ /**
+ * jfieldID fd_id = env->GetFieldID(serial_port_class, "fd", "Ljava/io/FileDescriptor;");
+ *
+ * fd不能随意修改,要改就一起改
+ *
+ * Do not remove or rename the field fd: it is used by native method close();
+ */
+ private final FileDescriptor fd;
+ private final FileInputStream inputStream;
+ private final FileOutputStream outputStream;
+ public SerialPort(File device, int baudRate, int flags) throws SecurityException, IOException {
if (!device.canRead() || !device.canWrite()) {
try {
Process su;
@@ -54,20 +55,24 @@
}
}
- mFd = open(device.getAbsolutePath(), baudrate, flags);
- if (mFd == null) {
+ fd = open(device.getAbsolutePath(), baudRate, flags);
+ if (fd == null) {
Log.e(TAG, "native open returns null");
throw new IOException();
}
- mFileInputStream = new FileInputStream(mFd);
- mFileOutputStream = new FileOutputStream(mFd);
+ inputStream = new FileInputStream(fd);
+ outputStream = new FileOutputStream(fd);
}
public InputStream getInputStream() {
- return mFileInputStream;
+ return inputStream;
}
public OutputStream getOutputStream() {
- return mFileOutputStream;
+ return outputStream;
+ }
+
+ public void closeSerialPort() {
+ close();
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
index 8f6caba..f9e5457 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
@@ -90,21 +90,27 @@
LocaleConstant.CONDITION_ARRAY[1] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerNumber, value)
}
+
LocaleConstant.CONDITION_ARRAY[2] -> {
return queryByProperty(LabelBeanDao.Properties.ObjectName, value)
}
+
LocaleConstant.CONDITION_ARRAY[3] -> {
return queryByProperty(LabelBeanDao.Properties.Area, value)
}
+
LocaleConstant.CONDITION_ARRAY[4] -> {
return queryByProperty(LabelBeanDao.Properties.Road, value)
}
+
LocaleConstant.CONDITION_ARRAY[5] -> {
return queryByProperty(LabelBeanDao.Properties.InspectionUnit, value)
}
+
LocaleConstant.CONDITION_ARRAY[6] -> {
return queryByProperty(LabelBeanDao.Properties.Owner, value)
}
+
LocaleConstant.CONDITION_ARRAY[8] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerId, value)
}
@@ -132,6 +138,15 @@
.where(LabelBeanDao.Properties.MarkerId.eq(markerId))
.list()
}
+
+ fun deleteTaskById(taskId: String?) {
+ if (taskId.isNullOrBlank()) {
+ return
+ }
+// queryTaskById(taskId).forEach {
+// taskBeanDao.delete(it)
+// }
+ }
/******************************* Lable *** End **********************************************/
/******************************* Small Lable *** Start **************************************/
diff --git a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
index 362df50..67c666e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
@@ -3,5 +3,7 @@
sealed class FileType {
object APK : FileType()
+ object EXCEL : FileType()
+
object IMAGE : FileType()
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
index 9356f9a..566996e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
@@ -14,6 +14,7 @@
const val PERMISSIONS_CODE = 999
const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米
+ const val MAX_DISTANCE = 5.5f //表盘最大显示距离
const val AUTO_SAVE = "AUTO_SAVE"
const val USER_ACCOUNT = "USER_ACCOUNT"
diff --git a/.gitignore b/.gitignore
index 10a1363..18c6ed4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,18 @@
*.iml
.gradle
/local.properties
-/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
-local.properties
/app/build
/app/src/androidTest
/app/src/test
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..f766fc3
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..167cf0c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..b007d28
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..4515aa3
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 623fc18..59fdbea 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,15 @@
apply plugin: 'org.greenrobot.greendao'
android {
+// signingConfigs {
+// release {
+// storeFile file('ElectricDetector.jks')
+// storePassword '123456789'
+// keyAlias 'key0'
+// keyPassword '123456789'
+// }
+// }
+
compileSdkVersion 33
defaultConfig {
@@ -13,12 +22,6 @@
targetSdkVersion 33
versionCode 5020
versionName "5.0.2"
-
- ndk {
- moduleName "serial_port"
- //"log"表示加入Android Logcat日志,需要导入 #include "android/log.h"
- ldLibs "log"
- }
}
buildTypes {
@@ -28,6 +31,13 @@
}
}
+ externalNativeBuild {
+ cmake {
+ path file('src/main/cpp/CMakeLists.txt')
+ version '3.22.1'
+ }
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -43,8 +53,8 @@
}
}
- viewBinding {
- enabled true
+ buildFeatures {
+ viewBinding true
}
applicationVariants.every { variant ->
@@ -66,10 +76,10 @@
}
dependencies {
+ //基础依赖库
+ implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.8'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
- //基础依赖库
- implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.5.3'
//Google官方授权框架
implementation 'pub.devrel:easypermissions:3.0.0'
//腾讯Android UI框架
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 92d80c5..ba718ef 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -63,15 +63,17 @@
+
+
-
-
-
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "android/log.h"
+
+#define LOG_TAG "SerialPortJNI"
+
+#define LOG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
+#define LOG_E(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)
+
+static speed_t get_baud_rate(jint baud_rate) {
+ switch (baud_rate) {
+ case 0:
+ return B0;
+ case 50:
+ return B50;
+ case 75:
+ return B75;
+ case 110:
+ return B110;
+ case 134:
+ return B134;
+ case 150:
+ return B150;
+ case 200:
+ return B200;
+ case 300:
+ return B300;
+ case 600:
+ return B600;
+ case 1200:
+ return B1200;
+ case 1800:
+ return B1800;
+ case 2400:
+ return B2400;
+ case 4800:
+ return B4800;
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ case 1000000:
+ return B1000000;
+ case 1152000:
+ return B1152000;
+ case 1500000:
+ return B1500000;
+ case 2000000:
+ return B2000000;
+ case 2500000:
+ return B2500000;
+ case 3000000:
+ return B3000000;
+ case 3500000:
+ return B3500000;
+ case 4000000:
+ return B4000000;
+ default:
+ return -1;
+ }
+}
+
+extern "C"
+JNIEXPORT jobject JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_open(JNIEnv *env, jobject thiz, jstring path,
+ jint baud_rate, jint flags) {
+ int fd;
+ speed_t speed;
+ jobject file_descriptor;
+
+ speed = get_baud_rate(baud_rate);
+ if (speed == -1) {
+ LOG_E("invalid baud_rate");
+ return nullptr;
+ }
+
+ jboolean is_copy;
+ const char *path_utf = env->GetStringUTFChars(path, &is_copy);
+ fd = open(path_utf, O_RDWR | flags);
+ LOG_D("open serial port %s with flags 0x%x", path_utf, O_RDWR | flags);
+ env->ReleaseStringUTFChars(path, path_utf);
+ if (fd == -1) {
+ LOG_E("can not open Port");
+ return nullptr;
+ }
+
+ struct termios cfg{};
+ LOG_D("configure serial port %d", fd);
+ if (tcgetattr(fd, &cfg)) {
+ LOG_E("tcgetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ cfmakeraw(&cfg);
+ cfsetispeed(&cfg, speed);
+ cfsetospeed(&cfg, speed);
+
+ if (tcsetattr(fd, TCSANOW, &cfg)) {
+ LOG_E("tcsetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ //获取句柄
+ jclass fd_class = env->FindClass("java/io/FileDescriptor");
+ jmethodID fd_method_id = env->GetMethodID(fd_class, "", "()V");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(fd_class, descriptor_buffer, "I");
+
+ file_descriptor = env->NewObject(fd_class, fd_method_id);
+ env->SetIntField(file_descriptor, descriptor_field_id, (jint) fd);
+
+ return file_descriptor;
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_close(JNIEnv *env, jobject thiz) {
+ jclass serial_port_class = env->GetObjectClass(thiz);
+ jclass file_descriptor_class = env->FindClass("java/io/FileDescriptor");
+
+ // fd 对应SerialPortKit里面的 fd
+ char fd_buffer[4] = {0};
+ strcat(fd_buffer, "fd");
+ jfieldID fd_field_id = env->GetFieldID(serial_port_class, fd_buffer,
+ "Ljava/io/FileDescriptor;");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(file_descriptor_class, descriptor_buffer, "I");
+
+ jobject fd_obj = env->GetObjectField(thiz, fd_field_id);
+ jint descriptor = env->GetIntField(fd_obj, descriptor_field_id);
+
+ LOG_D("close(fd = %d)", descriptor);
+ close(descriptor);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
index 0dbff79..1010ab7 100644
--- a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
@@ -48,10 +48,4 @@
fun getDaoSession(): DaoSession {
return daoSession
}
-
- fun closeSerialPort() {
- serialPorts?.forEach {
- it.close()
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
index f6e6574..69a3ddd 100644
--- a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
@@ -17,8 +17,8 @@
abstract class SerialPortActivity : AppCompatActivity() {
protected lateinit var binding: VB
-
- lateinit var out: OutputStream
+ private val serialPorts by lazy { BaseApplication.get().getSerialPorts() }
+ var out: OutputStream? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -30,18 +30,19 @@
initEvent()
try {
- val serialPorts = BaseApplication.get().getSerialPorts()
//读
lifecycleScope.launch(Dispatchers.IO) {
serialPorts?.apply {
- val stream = this[0].inputStream
+ val stream = first().inputStream
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -57,10 +58,12 @@
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -72,8 +75,10 @@
//写
serialPorts?.apply {
- out = this[0].outputStream
+ out = first().outputStream
}
+
+ "串口已打开!".show(this)
} catch (e: SecurityException) {
"您没有串口的读写权限!".show(this)
} catch (e: IOException) {
@@ -114,7 +119,9 @@
abstract fun onDataReceived(buffer: ByteArray)
override fun onDestroy() {
- BaseApplication.get().closeSerialPort()
+ serialPorts?.forEach {
+ it.closeSerialPort()
+ }
super.onDestroy()
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
deleted file mode 100644
index 64e7181..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.casic.electric.detector.callback;
-
-public interface IAddressListener {
- void onGetAddress(String address);
-}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
deleted file mode 100644
index 6f1bd03..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.casic.electric.detector.callback
-
-import com.amap.api.location.AMapLocation
-
-interface ILocationListener {
- fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
new file mode 100644
index 0000000..7a4e313
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
@@ -0,0 +1,5 @@
+package com.casic.electric.detector.callback;
+
+public interface OnGetAddressListener {
+ void onGetAddress(String address);
+}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
new file mode 100644
index 0000000..a8ec79e
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
@@ -0,0 +1,7 @@
+package com.casic.electric.detector.callback
+
+import com.amap.api.location.AMapLocation
+
+interface OnGetLocationListener {
+ fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
index c96c6f5..fba0059 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
@@ -3,24 +3,15 @@
import com.amap.api.location.AMapLocation
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
-import com.casic.electric.detector.model.CalculateResult
import kotlin.math.acos
/**
- * 计算两个经纬度之间连线的方位角,因为距离很近(一般是3米内),球面近似为平面
- * C B
- * |-------/
- * | /
- * | /
- * | /
- * | /
- * | /
- * | /
- * |/
- * A
+ * 计算两个经纬度之间连线的方位角,因为距离很近(一般是5米内),球面近似为平面
+ * A(探测仪所在位置),B(最近的标识器位置),C(辅助点位置)
+ * 手机坐标轴Y轴反置,所以右下角才是第一象限
* */
-fun AMapLocation.calculateAngle(target: LatLng): CalculateResult {
- //构造直角辅助点
+fun AMapLocation.calculateAngle(target: LatLng): Int {
+ //构造直角辅助点C
val auxiliaryPoint = LatLng(target.latitude, this.longitude)
//AB线段长度
@@ -30,10 +21,10 @@
//AC线段长度
val auxiliaryDistance = AMapUtils.calculateLineDistance(
- LatLng(auxiliaryPoint.latitude, auxiliaryPoint.longitude), target
+ auxiliaryPoint, target
)
- //求余弦值
+ //求∠A的余弦值
val cosine = auxiliaryDistance / distance
//反余弦得弧度
@@ -43,17 +34,18 @@
val angle = (radian * 180) / Math.PI
//判断方位
- val direction = if (target.latitude > this.latitude && target.longitude > this.longitude) {
+ val direction = if (this.longitude < target.longitude && this.latitude < target.latitude) {
//东北方
- "东偏北"
- } else if (target.latitude < this.latitude && target.longitude < this.longitude) {
- //西南方
- "西偏南"
- } else if (target.latitude > this.latitude && target.longitude < this.longitude) {
+ angle.toInt()
+ } else if (this.longitude > target.longitude && this.latitude < target.latitude) {
//西北方
- "西偏北"
+ (angle + 90).toInt()
+ } else if (this.longitude > target.longitude && this.latitude > target.latitude) {
+ //西南方
+ (angle + 180).toInt()
} else {
- "东偏南"
+ //东南方
+ (angle + 270).toInt()
}
- return CalculateResult(angle.toInt(), direction, distance.toInt())
+ return direction
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/String.kt b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
index 838d3ad..55136a6 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/String.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
@@ -43,6 +43,7 @@
val httpConfig = "http://${serverIp}:${serverPort}"
return when (type) {
FileType.APK -> "$httpConfig/ems/${this}"
+ FileType.EXCEL -> "$httpConfig/ems/xls/marker${this}.xls"
FileType.IMAGE -> "$httpConfig/ems${this}"
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt b/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
deleted file mode 100644
index 50682fd..0000000
--- a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.casic.electric.detector.extensions
-
-import java.net.ConnectException
-
-fun Throwable.convertChinese(): String {
- this.printStackTrace()
- return when (this) {
- is ConnectException -> "连接失败,请检查网络或者服务器"
- else -> "服务器异常,请联系管理员"
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt b/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
deleted file mode 100644
index 84c9cd9..0000000
--- a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.casic.electric.detector.model
-
-data class CalculateResult(val angle: Int, val direction: String, val distance: Int)
diff --git a/app/src/main/java/com/casic/electric/detector/model/EventModel.java b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
new file mode 100644
index 0000000..27a53e4
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
@@ -0,0 +1,76 @@
+package com.casic.electric.detector.model;
+
+public class EventModel {
+ private Long id;
+ private Long taskId;
+ private String description;
+ private String createTime;
+ private String imageName;
+ private Double latitude;
+ private Double longitude;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(Long taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getImageName() {
+ return imageName;
+ }
+
+ public void setImageName(String imageName) {
+ this.imageName = imageName;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/model/TaskModel.java b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
new file mode 100644
index 0000000..65f5ae7
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
@@ -0,0 +1,265 @@
+package com.casic.electric.detector.model;
+
+import java.util.List;
+
+public class TaskModel {
+
+ private String success;
+ private List message;
+
+ public String getSuccess() {
+ return success;
+ }
+
+ public void setSuccess(String success) {
+ this.success = success;
+ }
+
+ public List getMessage() {
+ return message;
+ }
+
+ public void setMessage(List message) {
+ this.message = message;
+ }
+
+ public static class MessageModel {
+ private int id;
+ private String taskCode;
+ private String description;
+ private String deployDate;
+ private Object beginDate;
+ private Object endDate;
+ private String status;
+ private String creatorId;
+ private String creatorName;
+ private String patrolerId;
+ private String patrolerName;
+ private int isValid;
+ private List taskDetailInfos;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDeployDate() {
+ return deployDate;
+ }
+
+ public void setDeployDate(String deployDate) {
+ this.deployDate = deployDate;
+ }
+
+ public Object getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Object beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Object getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Object endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorName() {
+ return creatorName;
+ }
+
+ public void setCreatorName(String creatorName) {
+ this.creatorName = creatorName;
+ }
+
+ public String getPatrolerId() {
+ return patrolerId;
+ }
+
+ public void setPatrolerId(String patrolerId) {
+ this.patrolerId = patrolerId;
+ }
+
+ public String getPatrolerName() {
+ return patrolerName;
+ }
+
+ public void setPatrolerName(String patrolerName) {
+ this.patrolerName = patrolerName;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ public List getTaskDetailInfos() {
+ return taskDetailInfos;
+ }
+
+ public void setTaskDetailInfos(List taskDetailInfos) {
+ this.taskDetailInfos = taskDetailInfos;
+ }
+
+ public static class TaskDetailInfosModel {
+ private int id;
+ private String taskId;
+ private String taskCode;
+ private Object markerName;
+ private int markerId;
+ private String markerIdReal;
+ private double longitude;
+ private double latitude;
+ private int isChecked;
+ private int isNormal;
+ private Object imagePath;
+ private Object description;
+ private Object finishTime;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public Object getMarkerName() {
+ return markerName;
+ }
+
+ public void setMarkerName(Object markerName) {
+ this.markerName = markerName;
+ }
+
+ public int getMarkerId() {
+ return markerId;
+ }
+
+ public void setMarkerId(int markerId) {
+ this.markerId = markerId;
+ }
+
+ public String getMarkerIdReal() {
+ return markerIdReal;
+ }
+
+ public void setMarkerIdReal(String markerIdReal) {
+ this.markerIdReal = markerIdReal;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public int getIsChecked() {
+ return isChecked;
+ }
+
+ public void setIsChecked(int isChecked) {
+ this.isChecked = isChecked;
+ }
+
+ public int getIsNormal() {
+ return isNormal;
+ }
+
+ public void setIsNormal(int isNormal) {
+ this.isNormal = isNormal;
+ }
+
+ public Object getImagePath() {
+ return imagePath;
+ }
+
+ public void setImagePath(Object imagePath) {
+ this.imagePath = imagePath;
+ }
+
+ public Object getDescription() {
+ return description;
+ }
+
+ public void setDescription(Object description) {
+ this.description = description;
+ }
+
+ public Object getFinishTime() {
+ return finishTime;
+ }
+
+ public void setFinishTime(Object finishTime) {
+ this.finishTime = finishTime;
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
index 7836b28..26a2bdd 100644
--- a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
@@ -1,7 +1,6 @@
package com.casic.electric.detector.retrofit
import com.casic.electric.detector.extensions.reformat
-import com.casic.electric.detector.utils.LabelDataClass
import com.casic.electric.detector.utils.LocaleConstant
import com.casic.electric.detector.utils.SmallLabelDataClass
import com.google.gson.JsonObject
@@ -75,52 +74,62 @@
* 安装新标识器
* Multipart上传图片,文件,带多参数上传
*/
- suspend fun installLabel(labelData: LabelDataClass): String {
+ suspend fun installLabel(
+ companyId: String,
+ recordType: String,
+ markerObjectType: String,
+ pipeMaterial: String,
+ pipeDiameter: String,
+ depth: String,
+ belowType: String,
+ belowMaterial: String,
+ belowDiameter: String,
+ belowDepth: String,
+ layStyle: String,
+ area: String,
+ line: String,
+ road: String,
+ constructTime: String,
+ ownerComp: String,
+ markerObjectId: String,
+ markerId: String,
+ markerType: String,
+ markerDepth: String,
+ creator: String,
+ createTime: String,
+ longitude: String,
+ latitude: String,
+ colorType: String,
+ memo: String,
+ realPaths: ArrayList
+ ): String {
val param = JsonObject()
- param.addProperty("companyId", labelData.companyId)
- param.addProperty("recordType", labelData.recordType)
- param.addProperty("markerObjectId", labelData.markerObjectId)
- param.addProperty("objectName", labelData.objectName)
- param.addProperty("pressLevel", labelData.pressLevel)
- param.addProperty("markerObjectType", labelData.markerObjectType)
- param.addProperty("inlineName", labelData.inlineName)
- param.addProperty("wellMaterial", labelData.wellMaterial)
- param.addProperty("capacity", labelData.capacity)
- param.addProperty("transformerSpec", labelData.transformerSpec)
- param.addProperty("size", labelData.size)
- param.addProperty("inlineCount", labelData.inlineCount)
- param.addProperty("outlineCount", labelData.outlineCount)
- param.addProperty("cabinetType", labelData.cabinetType)
- param.addProperty("bottomDepth", labelData.bottomDepth)
- param.addProperty("holeCount", labelData.holeCount)
- param.addProperty("coverDepth", labelData.coverDepth)
- param.addProperty("crossPipe", labelData.crossPipe)
- param.addProperty("leftHoleCount", labelData.leftHoleCount)
- param.addProperty("tieCable1", labelData.tieCable1)
- param.addProperty("tieCable2", labelData.tieCable2)
- param.addProperty("jointCount", labelData.jointCount)
- param.addProperty("bushingMaterial", labelData.bushingMaterial)
- param.addProperty("bushingSpec", labelData.bushingSpec)
- param.addProperty("height", labelData.height)
- param.addProperty("lineNo", labelData.lineNo)
- param.addProperty("constructTime", labelData.constructTime)
- param.addProperty("operComp", labelData.operComp)
- param.addProperty("area", labelData.area)
- param.addProperty("road", labelData.road)
- param.addProperty("memo1", labelData.memo1)
- param.addProperty("memo2", labelData.memo2)
- param.addProperty("memo3", labelData.memo3)
- param.addProperty("markerId", labelData.markerId)
- param.addProperty("markerType", labelData.markerType)
- param.addProperty("owner", labelData.owner)
- param.addProperty("markerDepth", labelData.markerDepth)
- param.addProperty("createTime", labelData.createTime)
- param.addProperty("longitude", labelData.longitude)
- param.addProperty("latitude", labelData.latitude)
- param.addProperty("eleTagCount", labelData.eleTagCount)
- param.addProperty("markerMemo1", labelData.markerMemo1)
- param.addProperty("markerMemo2", labelData.markerMemo2)
- param.addProperty("markerMemo3", labelData.markerMemo3)
+ param.addProperty("companyId", companyId)
+ param.addProperty("recordType", recordType)
+ param.addProperty("markerObjectType", markerObjectType)
+ param.addProperty("pipeMaterial", pipeMaterial)
+ param.addProperty("pipeDiameter", pipeDiameter)
+ param.addProperty("depth", depth)
+ param.addProperty("belowType", belowType)
+ param.addProperty("belowMaterial", belowMaterial)
+ param.addProperty("belowDiameter", belowDiameter)
+ param.addProperty("belowDepth", belowDepth)
+ param.addProperty("layStyle", layStyle)
+ param.addProperty("area", area)
+ param.addProperty("line", line)
+ param.addProperty("road", road)
+ param.addProperty("constructTime", constructTime)
+ param.addProperty("ownerComp", ownerComp)
+ param.addProperty("markerObjectId", markerObjectId)
+ param.addProperty("markerId", markerId)
+ param.addProperty("markerType", markerType)
+ param.addProperty("markerDepth", markerDepth)
+ param.addProperty("creator", creator)
+ param.addProperty("createTime", createTime)
+ param.addProperty("longitude", longitude)
+ param.addProperty("latitude", latitude)
+ param.addProperty("colorType", colorType)
+ param.addProperty("memo", memo)
val requestBody = param.toString().toRequestBody(
"application/json;charset=UTF-8".toMediaType()
)
@@ -128,7 +137,7 @@
res["jsonMarker"] = requestBody
val multiParts = ArrayList()
- labelData.realPaths.forEachIndexed { index, s ->
+ realPaths.forEachIndexed { index, s ->
val file = File(s)
val fileMultipart = MultipartBody.Part.createFormData(
"fileBuffer${index + 1}", file.name, file.asRequestBody("image/png".toMediaType())
diff --git a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
index 921448f..83cda4a 100644
--- a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
+++ b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
@@ -13,31 +13,32 @@
public class SerialPort {
private static final String TAG = "SerialPort";
- /**
- * .so 库名字。需要去掉生成时自带的lib前缀
- * */
static {
- System.loadLibrary("serial_port");
+ System.loadLibrary("serialPort");
}
/**
- * JNI
- *
- * 必须用 native 标识JNI方法
+ * 打开串口
*/
- private native static FileDescriptor open(String path, int baudRate, int flags);
-
- public native void close();
+ private native FileDescriptor open(String path, int baudRate, int flags);
/**
- * Do not remove or rename the field mFd: it is used by native method close();
+ * 关闭串口
*/
- private FileDescriptor mFd;
- private final FileInputStream mFileInputStream;
- private final FileOutputStream mFileOutputStream;
+ private native void close();
- public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
+ /**
+ * jfieldID fd_id = env->GetFieldID(serial_port_class, "fd", "Ljava/io/FileDescriptor;");
+ *
+ * fd不能随意修改,要改就一起改
+ *
+ * Do not remove or rename the field fd: it is used by native method close();
+ */
+ private final FileDescriptor fd;
+ private final FileInputStream inputStream;
+ private final FileOutputStream outputStream;
+ public SerialPort(File device, int baudRate, int flags) throws SecurityException, IOException {
if (!device.canRead() || !device.canWrite()) {
try {
Process su;
@@ -54,20 +55,24 @@
}
}
- mFd = open(device.getAbsolutePath(), baudrate, flags);
- if (mFd == null) {
+ fd = open(device.getAbsolutePath(), baudRate, flags);
+ if (fd == null) {
Log.e(TAG, "native open returns null");
throw new IOException();
}
- mFileInputStream = new FileInputStream(mFd);
- mFileOutputStream = new FileOutputStream(mFd);
+ inputStream = new FileInputStream(fd);
+ outputStream = new FileOutputStream(fd);
}
public InputStream getInputStream() {
- return mFileInputStream;
+ return inputStream;
}
public OutputStream getOutputStream() {
- return mFileOutputStream;
+ return outputStream;
+ }
+
+ public void closeSerialPort() {
+ close();
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
index 8f6caba..f9e5457 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
@@ -90,21 +90,27 @@
LocaleConstant.CONDITION_ARRAY[1] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerNumber, value)
}
+
LocaleConstant.CONDITION_ARRAY[2] -> {
return queryByProperty(LabelBeanDao.Properties.ObjectName, value)
}
+
LocaleConstant.CONDITION_ARRAY[3] -> {
return queryByProperty(LabelBeanDao.Properties.Area, value)
}
+
LocaleConstant.CONDITION_ARRAY[4] -> {
return queryByProperty(LabelBeanDao.Properties.Road, value)
}
+
LocaleConstant.CONDITION_ARRAY[5] -> {
return queryByProperty(LabelBeanDao.Properties.InspectionUnit, value)
}
+
LocaleConstant.CONDITION_ARRAY[6] -> {
return queryByProperty(LabelBeanDao.Properties.Owner, value)
}
+
LocaleConstant.CONDITION_ARRAY[8] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerId, value)
}
@@ -132,6 +138,15 @@
.where(LabelBeanDao.Properties.MarkerId.eq(markerId))
.list()
}
+
+ fun deleteTaskById(taskId: String?) {
+ if (taskId.isNullOrBlank()) {
+ return
+ }
+// queryTaskById(taskId).forEach {
+// taskBeanDao.delete(it)
+// }
+ }
/******************************* Lable *** End **********************************************/
/******************************* Small Lable *** Start **************************************/
diff --git a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
index 362df50..67c666e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
@@ -3,5 +3,7 @@
sealed class FileType {
object APK : FileType()
+ object EXCEL : FileType()
+
object IMAGE : FileType()
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
index 9356f9a..566996e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
@@ -14,6 +14,7 @@
const val PERMISSIONS_CODE = 999
const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米
+ const val MAX_DISTANCE = 5.5f //表盘最大显示距离
const val AUTO_SAVE = "AUTO_SAVE"
const val USER_ACCOUNT = "USER_ACCOUNT"
diff --git a/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt b/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt
index 61e55f6..b726026 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt
@@ -11,8 +11,8 @@
import com.amap.api.services.geocoder.GeocodeSearch
import com.amap.api.services.geocoder.RegeocodeQuery
import com.amap.api.services.geocoder.RegeocodeResult
-import com.casic.electric.detector.callback.IAddressListener
-import com.casic.electric.detector.callback.ILocationListener
+import com.casic.electric.detector.callback.OnGetAddressListener
+import com.casic.electric.detector.callback.OnGetLocationListener
class LocationHub constructor(context: Context) {
@@ -20,10 +20,11 @@
private val locationClient by lazy { AMapLocationClient(context) }
private val codeSearch by lazy { GeocodeSearch(context) }
- fun getCurrentLocation(isOnceLocation: Boolean, listener: ILocationListener) {
+ fun getCurrentLocation(isOnceLocation: Boolean, listener: OnGetLocationListener) {
val locationOption = AMapLocationClientOption()
locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
locationOption.isOnceLocation = isOnceLocation
+ locationOption.isNeedAddress = false
locationClient.setLocationOption(locationOption)
locationClient.setLocationListener {
if (it.errorCode == 0) {
@@ -38,7 +39,7 @@
locationClient.startLocation()
}
- fun antiCodingLocation(location: Location, listener: IAddressListener) {
+ fun antiCodingLocation(location: Location, listener: OnGetAddressListener) {
try {
// 第一个参数表示一个LatLonPoint,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
val query = RegeocodeQuery(
diff --git a/.gitignore b/.gitignore
index 10a1363..18c6ed4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,18 @@
*.iml
.gradle
/local.properties
-/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
-local.properties
/app/build
/app/src/androidTest
/app/src/test
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..f766fc3
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..167cf0c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..b007d28
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..4515aa3
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 623fc18..59fdbea 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,15 @@
apply plugin: 'org.greenrobot.greendao'
android {
+// signingConfigs {
+// release {
+// storeFile file('ElectricDetector.jks')
+// storePassword '123456789'
+// keyAlias 'key0'
+// keyPassword '123456789'
+// }
+// }
+
compileSdkVersion 33
defaultConfig {
@@ -13,12 +22,6 @@
targetSdkVersion 33
versionCode 5020
versionName "5.0.2"
-
- ndk {
- moduleName "serial_port"
- //"log"表示加入Android Logcat日志,需要导入 #include "android/log.h"
- ldLibs "log"
- }
}
buildTypes {
@@ -28,6 +31,13 @@
}
}
+ externalNativeBuild {
+ cmake {
+ path file('src/main/cpp/CMakeLists.txt')
+ version '3.22.1'
+ }
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -43,8 +53,8 @@
}
}
- viewBinding {
- enabled true
+ buildFeatures {
+ viewBinding true
}
applicationVariants.every { variant ->
@@ -66,10 +76,10 @@
}
dependencies {
+ //基础依赖库
+ implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.8'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
- //基础依赖库
- implementation 'com.github.AndroidCoderPeng:Kotlin-lite-lib:1.0.5.3'
//Google官方授权框架
implementation 'pub.devrel:easypermissions:3.0.0'
//腾讯Android UI框架
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 92d80c5..ba718ef 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -63,15 +63,17 @@
+
+
-
-
-
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "android/log.h"
+
+#define LOG_TAG "SerialPortJNI"
+
+#define LOG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
+#define LOG_E(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)
+
+static speed_t get_baud_rate(jint baud_rate) {
+ switch (baud_rate) {
+ case 0:
+ return B0;
+ case 50:
+ return B50;
+ case 75:
+ return B75;
+ case 110:
+ return B110;
+ case 134:
+ return B134;
+ case 150:
+ return B150;
+ case 200:
+ return B200;
+ case 300:
+ return B300;
+ case 600:
+ return B600;
+ case 1200:
+ return B1200;
+ case 1800:
+ return B1800;
+ case 2400:
+ return B2400;
+ case 4800:
+ return B4800;
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ case 1000000:
+ return B1000000;
+ case 1152000:
+ return B1152000;
+ case 1500000:
+ return B1500000;
+ case 2000000:
+ return B2000000;
+ case 2500000:
+ return B2500000;
+ case 3000000:
+ return B3000000;
+ case 3500000:
+ return B3500000;
+ case 4000000:
+ return B4000000;
+ default:
+ return -1;
+ }
+}
+
+extern "C"
+JNIEXPORT jobject JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_open(JNIEnv *env, jobject thiz, jstring path,
+ jint baud_rate, jint flags) {
+ int fd;
+ speed_t speed;
+ jobject file_descriptor;
+
+ speed = get_baud_rate(baud_rate);
+ if (speed == -1) {
+ LOG_E("invalid baud_rate");
+ return nullptr;
+ }
+
+ jboolean is_copy;
+ const char *path_utf = env->GetStringUTFChars(path, &is_copy);
+ fd = open(path_utf, O_RDWR | flags);
+ LOG_D("open serial port %s with flags 0x%x", path_utf, O_RDWR | flags);
+ env->ReleaseStringUTFChars(path, path_utf);
+ if (fd == -1) {
+ LOG_E("can not open Port");
+ return nullptr;
+ }
+
+ struct termios cfg{};
+ LOG_D("configure serial port %d", fd);
+ if (tcgetattr(fd, &cfg)) {
+ LOG_E("tcgetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ cfmakeraw(&cfg);
+ cfsetispeed(&cfg, speed);
+ cfsetospeed(&cfg, speed);
+
+ if (tcsetattr(fd, TCSANOW, &cfg)) {
+ LOG_E("tcsetattr() failed");
+ close(fd);
+ return nullptr;
+ }
+
+ //获取句柄
+ jclass fd_class = env->FindClass("java/io/FileDescriptor");
+ jmethodID fd_method_id = env->GetMethodID(fd_class, "", "()V");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(fd_class, descriptor_buffer, "I");
+
+ file_descriptor = env->NewObject(fd_class, fd_method_id);
+ env->SetIntField(file_descriptor, descriptor_field_id, (jint) fd);
+
+ return file_descriptor;
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_casic_electric_detector_uart_SerialPort_close(JNIEnv *env, jobject thiz) {
+ jclass serial_port_class = env->GetObjectClass(thiz);
+ jclass file_descriptor_class = env->FindClass("java/io/FileDescriptor");
+
+ // fd 对应SerialPortKit里面的 fd
+ char fd_buffer[4] = {0};
+ strcat(fd_buffer, "fd");
+ jfieldID fd_field_id = env->GetFieldID(serial_port_class, fd_buffer,
+ "Ljava/io/FileDescriptor;");
+
+ char descriptor_buffer[16] = {0};
+ strcat(descriptor_buffer, "descriptor");
+ jfieldID descriptor_field_id = env->GetFieldID(file_descriptor_class, descriptor_buffer, "I");
+
+ jobject fd_obj = env->GetObjectField(thiz, fd_field_id);
+ jint descriptor = env->GetIntField(fd_obj, descriptor_field_id);
+
+ LOG_D("close(fd = %d)", descriptor);
+ close(descriptor);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
index 0dbff79..1010ab7 100644
--- a/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/BaseApplication.kt
@@ -48,10 +48,4 @@
fun getDaoSession(): DaoSession {
return daoSession
}
-
- fun closeSerialPort() {
- serialPorts?.forEach {
- it.close()
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
index f6e6574..69a3ddd 100644
--- a/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/electric/detector/base/SerialPortActivity.kt
@@ -17,8 +17,8 @@
abstract class SerialPortActivity : AppCompatActivity() {
protected lateinit var binding: VB
-
- lateinit var out: OutputStream
+ private val serialPorts by lazy { BaseApplication.get().getSerialPorts() }
+ var out: OutputStream? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -30,18 +30,19 @@
initEvent()
try {
- val serialPorts = BaseApplication.get().getSerialPorts()
//读
lifecycleScope.launch(Dispatchers.IO) {
serialPorts?.apply {
- val stream = this[0].inputStream
+ val stream = first().inputStream
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -57,10 +58,12 @@
while (isActive) {
try {
val buffer = ByteArray(64)
- val size = stream.read(buffer)
- if (size > 0) {
- withContext(Dispatchers.Main) {
- onDataReceived(buffer)
+ stream?.apply {
+ val size = read(buffer)
+ if (size > 0) {
+ withContext(Dispatchers.Main) {
+ onDataReceived(buffer)
+ }
}
}
} catch (e: IOException) {
@@ -72,8 +75,10 @@
//写
serialPorts?.apply {
- out = this[0].outputStream
+ out = first().outputStream
}
+
+ "串口已打开!".show(this)
} catch (e: SecurityException) {
"您没有串口的读写权限!".show(this)
} catch (e: IOException) {
@@ -114,7 +119,9 @@
abstract fun onDataReceived(buffer: ByteArray)
override fun onDestroy() {
- BaseApplication.get().closeSerialPort()
+ serialPorts?.forEach {
+ it.closeSerialPort()
+ }
super.onDestroy()
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
deleted file mode 100644
index 64e7181..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/IAddressListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.casic.electric.detector.callback;
-
-public interface IAddressListener {
- void onGetAddress(String address);
-}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
deleted file mode 100644
index 6f1bd03..0000000
--- a/app/src/main/java/com/casic/electric/detector/callback/ILocationListener.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.casic.electric.detector.callback
-
-import com.amap.api.location.AMapLocation
-
-interface ILocationListener {
- fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
new file mode 100644
index 0000000..7a4e313
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetAddressListener.java
@@ -0,0 +1,5 @@
+package com.casic.electric.detector.callback;
+
+public interface OnGetAddressListener {
+ void onGetAddress(String address);
+}
diff --git a/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
new file mode 100644
index 0000000..a8ec79e
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/callback/OnGetLocationListener.kt
@@ -0,0 +1,7 @@
+package com.casic.electric.detector.callback
+
+import com.amap.api.location.AMapLocation
+
+interface OnGetLocationListener {
+ fun onAMapLocationGet(location: AMapLocation?) //高德定位数据
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
index c96c6f5..fba0059 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/AMapLocation.kt
@@ -3,24 +3,15 @@
import com.amap.api.location.AMapLocation
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
-import com.casic.electric.detector.model.CalculateResult
import kotlin.math.acos
/**
- * 计算两个经纬度之间连线的方位角,因为距离很近(一般是3米内),球面近似为平面
- * C B
- * |-------/
- * | /
- * | /
- * | /
- * | /
- * | /
- * | /
- * |/
- * A
+ * 计算两个经纬度之间连线的方位角,因为距离很近(一般是5米内),球面近似为平面
+ * A(探测仪所在位置),B(最近的标识器位置),C(辅助点位置)
+ * 手机坐标轴Y轴反置,所以右下角才是第一象限
* */
-fun AMapLocation.calculateAngle(target: LatLng): CalculateResult {
- //构造直角辅助点
+fun AMapLocation.calculateAngle(target: LatLng): Int {
+ //构造直角辅助点C
val auxiliaryPoint = LatLng(target.latitude, this.longitude)
//AB线段长度
@@ -30,10 +21,10 @@
//AC线段长度
val auxiliaryDistance = AMapUtils.calculateLineDistance(
- LatLng(auxiliaryPoint.latitude, auxiliaryPoint.longitude), target
+ auxiliaryPoint, target
)
- //求余弦值
+ //求∠A的余弦值
val cosine = auxiliaryDistance / distance
//反余弦得弧度
@@ -43,17 +34,18 @@
val angle = (radian * 180) / Math.PI
//判断方位
- val direction = if (target.latitude > this.latitude && target.longitude > this.longitude) {
+ val direction = if (this.longitude < target.longitude && this.latitude < target.latitude) {
//东北方
- "东偏北"
- } else if (target.latitude < this.latitude && target.longitude < this.longitude) {
- //西南方
- "西偏南"
- } else if (target.latitude > this.latitude && target.longitude < this.longitude) {
+ angle.toInt()
+ } else if (this.longitude > target.longitude && this.latitude < target.latitude) {
//西北方
- "西偏北"
+ (angle + 90).toInt()
+ } else if (this.longitude > target.longitude && this.latitude > target.latitude) {
+ //西南方
+ (angle + 180).toInt()
} else {
- "东偏南"
+ //东南方
+ (angle + 270).toInt()
}
- return CalculateResult(angle.toInt(), direction, distance.toInt())
+ return direction
}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/String.kt b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
index 838d3ad..55136a6 100644
--- a/app/src/main/java/com/casic/electric/detector/extensions/String.kt
+++ b/app/src/main/java/com/casic/electric/detector/extensions/String.kt
@@ -43,6 +43,7 @@
val httpConfig = "http://${serverIp}:${serverPort}"
return when (type) {
FileType.APK -> "$httpConfig/ems/${this}"
+ FileType.EXCEL -> "$httpConfig/ems/xls/marker${this}.xls"
FileType.IMAGE -> "$httpConfig/ems${this}"
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt b/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
deleted file mode 100644
index 50682fd..0000000
--- a/app/src/main/java/com/casic/electric/detector/extensions/Throwable.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.casic.electric.detector.extensions
-
-import java.net.ConnectException
-
-fun Throwable.convertChinese(): String {
- this.printStackTrace()
- return when (this) {
- is ConnectException -> "连接失败,请检查网络或者服务器"
- else -> "服务器异常,请联系管理员"
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt b/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
deleted file mode 100644
index 84c9cd9..0000000
--- a/app/src/main/java/com/casic/electric/detector/model/CalculateResult.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.casic.electric.detector.model
-
-data class CalculateResult(val angle: Int, val direction: String, val distance: Int)
diff --git a/app/src/main/java/com/casic/electric/detector/model/EventModel.java b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
new file mode 100644
index 0000000..27a53e4
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/EventModel.java
@@ -0,0 +1,76 @@
+package com.casic.electric.detector.model;
+
+public class EventModel {
+ private Long id;
+ private Long taskId;
+ private String description;
+ private String createTime;
+ private String imageName;
+ private Double latitude;
+ private Double longitude;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(Long taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getImageName() {
+ return imageName;
+ }
+
+ public void setImageName(String imageName) {
+ this.imageName = imageName;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/model/TaskModel.java b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
new file mode 100644
index 0000000..65f5ae7
--- /dev/null
+++ b/app/src/main/java/com/casic/electric/detector/model/TaskModel.java
@@ -0,0 +1,265 @@
+package com.casic.electric.detector.model;
+
+import java.util.List;
+
+public class TaskModel {
+
+ private String success;
+ private List message;
+
+ public String getSuccess() {
+ return success;
+ }
+
+ public void setSuccess(String success) {
+ this.success = success;
+ }
+
+ public List getMessage() {
+ return message;
+ }
+
+ public void setMessage(List message) {
+ this.message = message;
+ }
+
+ public static class MessageModel {
+ private int id;
+ private String taskCode;
+ private String description;
+ private String deployDate;
+ private Object beginDate;
+ private Object endDate;
+ private String status;
+ private String creatorId;
+ private String creatorName;
+ private String patrolerId;
+ private String patrolerName;
+ private int isValid;
+ private List taskDetailInfos;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDeployDate() {
+ return deployDate;
+ }
+
+ public void setDeployDate(String deployDate) {
+ this.deployDate = deployDate;
+ }
+
+ public Object getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Object beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Object getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Object endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorName() {
+ return creatorName;
+ }
+
+ public void setCreatorName(String creatorName) {
+ this.creatorName = creatorName;
+ }
+
+ public String getPatrolerId() {
+ return patrolerId;
+ }
+
+ public void setPatrolerId(String patrolerId) {
+ this.patrolerId = patrolerId;
+ }
+
+ public String getPatrolerName() {
+ return patrolerName;
+ }
+
+ public void setPatrolerName(String patrolerName) {
+ this.patrolerName = patrolerName;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ public List getTaskDetailInfos() {
+ return taskDetailInfos;
+ }
+
+ public void setTaskDetailInfos(List taskDetailInfos) {
+ this.taskDetailInfos = taskDetailInfos;
+ }
+
+ public static class TaskDetailInfosModel {
+ private int id;
+ private String taskId;
+ private String taskCode;
+ private Object markerName;
+ private int markerId;
+ private String markerIdReal;
+ private double longitude;
+ private double latitude;
+ private int isChecked;
+ private int isNormal;
+ private Object imagePath;
+ private Object description;
+ private Object finishTime;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getTaskCode() {
+ return taskCode;
+ }
+
+ public void setTaskCode(String taskCode) {
+ this.taskCode = taskCode;
+ }
+
+ public Object getMarkerName() {
+ return markerName;
+ }
+
+ public void setMarkerName(Object markerName) {
+ this.markerName = markerName;
+ }
+
+ public int getMarkerId() {
+ return markerId;
+ }
+
+ public void setMarkerId(int markerId) {
+ this.markerId = markerId;
+ }
+
+ public String getMarkerIdReal() {
+ return markerIdReal;
+ }
+
+ public void setMarkerIdReal(String markerIdReal) {
+ this.markerIdReal = markerIdReal;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public int getIsChecked() {
+ return isChecked;
+ }
+
+ public void setIsChecked(int isChecked) {
+ this.isChecked = isChecked;
+ }
+
+ public int getIsNormal() {
+ return isNormal;
+ }
+
+ public void setIsNormal(int isNormal) {
+ this.isNormal = isNormal;
+ }
+
+ public Object getImagePath() {
+ return imagePath;
+ }
+
+ public void setImagePath(Object imagePath) {
+ this.imagePath = imagePath;
+ }
+
+ public Object getDescription() {
+ return description;
+ }
+
+ public void setDescription(Object description) {
+ this.description = description;
+ }
+
+ public Object getFinishTime() {
+ return finishTime;
+ }
+
+ public void setFinishTime(Object finishTime) {
+ this.finishTime = finishTime;
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
index 7836b28..26a2bdd 100644
--- a/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/retrofit/RetrofitServiceManager.kt
@@ -1,7 +1,6 @@
package com.casic.electric.detector.retrofit
import com.casic.electric.detector.extensions.reformat
-import com.casic.electric.detector.utils.LabelDataClass
import com.casic.electric.detector.utils.LocaleConstant
import com.casic.electric.detector.utils.SmallLabelDataClass
import com.google.gson.JsonObject
@@ -75,52 +74,62 @@
* 安装新标识器
* Multipart上传图片,文件,带多参数上传
*/
- suspend fun installLabel(labelData: LabelDataClass): String {
+ suspend fun installLabel(
+ companyId: String,
+ recordType: String,
+ markerObjectType: String,
+ pipeMaterial: String,
+ pipeDiameter: String,
+ depth: String,
+ belowType: String,
+ belowMaterial: String,
+ belowDiameter: String,
+ belowDepth: String,
+ layStyle: String,
+ area: String,
+ line: String,
+ road: String,
+ constructTime: String,
+ ownerComp: String,
+ markerObjectId: String,
+ markerId: String,
+ markerType: String,
+ markerDepth: String,
+ creator: String,
+ createTime: String,
+ longitude: String,
+ latitude: String,
+ colorType: String,
+ memo: String,
+ realPaths: ArrayList
+ ): String {
val param = JsonObject()
- param.addProperty("companyId", labelData.companyId)
- param.addProperty("recordType", labelData.recordType)
- param.addProperty("markerObjectId", labelData.markerObjectId)
- param.addProperty("objectName", labelData.objectName)
- param.addProperty("pressLevel", labelData.pressLevel)
- param.addProperty("markerObjectType", labelData.markerObjectType)
- param.addProperty("inlineName", labelData.inlineName)
- param.addProperty("wellMaterial", labelData.wellMaterial)
- param.addProperty("capacity", labelData.capacity)
- param.addProperty("transformerSpec", labelData.transformerSpec)
- param.addProperty("size", labelData.size)
- param.addProperty("inlineCount", labelData.inlineCount)
- param.addProperty("outlineCount", labelData.outlineCount)
- param.addProperty("cabinetType", labelData.cabinetType)
- param.addProperty("bottomDepth", labelData.bottomDepth)
- param.addProperty("holeCount", labelData.holeCount)
- param.addProperty("coverDepth", labelData.coverDepth)
- param.addProperty("crossPipe", labelData.crossPipe)
- param.addProperty("leftHoleCount", labelData.leftHoleCount)
- param.addProperty("tieCable1", labelData.tieCable1)
- param.addProperty("tieCable2", labelData.tieCable2)
- param.addProperty("jointCount", labelData.jointCount)
- param.addProperty("bushingMaterial", labelData.bushingMaterial)
- param.addProperty("bushingSpec", labelData.bushingSpec)
- param.addProperty("height", labelData.height)
- param.addProperty("lineNo", labelData.lineNo)
- param.addProperty("constructTime", labelData.constructTime)
- param.addProperty("operComp", labelData.operComp)
- param.addProperty("area", labelData.area)
- param.addProperty("road", labelData.road)
- param.addProperty("memo1", labelData.memo1)
- param.addProperty("memo2", labelData.memo2)
- param.addProperty("memo3", labelData.memo3)
- param.addProperty("markerId", labelData.markerId)
- param.addProperty("markerType", labelData.markerType)
- param.addProperty("owner", labelData.owner)
- param.addProperty("markerDepth", labelData.markerDepth)
- param.addProperty("createTime", labelData.createTime)
- param.addProperty("longitude", labelData.longitude)
- param.addProperty("latitude", labelData.latitude)
- param.addProperty("eleTagCount", labelData.eleTagCount)
- param.addProperty("markerMemo1", labelData.markerMemo1)
- param.addProperty("markerMemo2", labelData.markerMemo2)
- param.addProperty("markerMemo3", labelData.markerMemo3)
+ param.addProperty("companyId", companyId)
+ param.addProperty("recordType", recordType)
+ param.addProperty("markerObjectType", markerObjectType)
+ param.addProperty("pipeMaterial", pipeMaterial)
+ param.addProperty("pipeDiameter", pipeDiameter)
+ param.addProperty("depth", depth)
+ param.addProperty("belowType", belowType)
+ param.addProperty("belowMaterial", belowMaterial)
+ param.addProperty("belowDiameter", belowDiameter)
+ param.addProperty("belowDepth", belowDepth)
+ param.addProperty("layStyle", layStyle)
+ param.addProperty("area", area)
+ param.addProperty("line", line)
+ param.addProperty("road", road)
+ param.addProperty("constructTime", constructTime)
+ param.addProperty("ownerComp", ownerComp)
+ param.addProperty("markerObjectId", markerObjectId)
+ param.addProperty("markerId", markerId)
+ param.addProperty("markerType", markerType)
+ param.addProperty("markerDepth", markerDepth)
+ param.addProperty("creator", creator)
+ param.addProperty("createTime", createTime)
+ param.addProperty("longitude", longitude)
+ param.addProperty("latitude", latitude)
+ param.addProperty("colorType", colorType)
+ param.addProperty("memo", memo)
val requestBody = param.toString().toRequestBody(
"application/json;charset=UTF-8".toMediaType()
)
@@ -128,7 +137,7 @@
res["jsonMarker"] = requestBody
val multiParts = ArrayList()
- labelData.realPaths.forEachIndexed { index, s ->
+ realPaths.forEachIndexed { index, s ->
val file = File(s)
val fileMultipart = MultipartBody.Part.createFormData(
"fileBuffer${index + 1}", file.name, file.asRequestBody("image/png".toMediaType())
diff --git a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
index 921448f..83cda4a 100644
--- a/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
+++ b/app/src/main/java/com/casic/electric/detector/uart/SerialPort.java
@@ -13,31 +13,32 @@
public class SerialPort {
private static final String TAG = "SerialPort";
- /**
- * .so 库名字。需要去掉生成时自带的lib前缀
- * */
static {
- System.loadLibrary("serial_port");
+ System.loadLibrary("serialPort");
}
/**
- * JNI
- *
- * 必须用 native 标识JNI方法
+ * 打开串口
*/
- private native static FileDescriptor open(String path, int baudRate, int flags);
-
- public native void close();
+ private native FileDescriptor open(String path, int baudRate, int flags);
/**
- * Do not remove or rename the field mFd: it is used by native method close();
+ * 关闭串口
*/
- private FileDescriptor mFd;
- private final FileInputStream mFileInputStream;
- private final FileOutputStream mFileOutputStream;
+ private native void close();
- public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
+ /**
+ * jfieldID fd_id = env->GetFieldID(serial_port_class, "fd", "Ljava/io/FileDescriptor;");
+ *
+ * fd不能随意修改,要改就一起改
+ *
+ * Do not remove or rename the field fd: it is used by native method close();
+ */
+ private final FileDescriptor fd;
+ private final FileInputStream inputStream;
+ private final FileOutputStream outputStream;
+ public SerialPort(File device, int baudRate, int flags) throws SecurityException, IOException {
if (!device.canRead() || !device.canWrite()) {
try {
Process su;
@@ -54,20 +55,24 @@
}
}
- mFd = open(device.getAbsolutePath(), baudrate, flags);
- if (mFd == null) {
+ fd = open(device.getAbsolutePath(), baudRate, flags);
+ if (fd == null) {
Log.e(TAG, "native open returns null");
throw new IOException();
}
- mFileInputStream = new FileInputStream(mFd);
- mFileOutputStream = new FileOutputStream(mFd);
+ inputStream = new FileInputStream(fd);
+ outputStream = new FileOutputStream(fd);
}
public InputStream getInputStream() {
- return mFileInputStream;
+ return inputStream;
}
public OutputStream getOutputStream() {
- return mFileOutputStream;
+ return outputStream;
+ }
+
+ public void closeSerialPort() {
+ close();
}
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
index 8f6caba..f9e5457 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/DataBaseManager.kt
@@ -90,21 +90,27 @@
LocaleConstant.CONDITION_ARRAY[1] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerNumber, value)
}
+
LocaleConstant.CONDITION_ARRAY[2] -> {
return queryByProperty(LabelBeanDao.Properties.ObjectName, value)
}
+
LocaleConstant.CONDITION_ARRAY[3] -> {
return queryByProperty(LabelBeanDao.Properties.Area, value)
}
+
LocaleConstant.CONDITION_ARRAY[4] -> {
return queryByProperty(LabelBeanDao.Properties.Road, value)
}
+
LocaleConstant.CONDITION_ARRAY[5] -> {
return queryByProperty(LabelBeanDao.Properties.InspectionUnit, value)
}
+
LocaleConstant.CONDITION_ARRAY[6] -> {
return queryByProperty(LabelBeanDao.Properties.Owner, value)
}
+
LocaleConstant.CONDITION_ARRAY[8] -> {
return queryByProperty(LabelBeanDao.Properties.MarkerId, value)
}
@@ -132,6 +138,15 @@
.where(LabelBeanDao.Properties.MarkerId.eq(markerId))
.list()
}
+
+ fun deleteTaskById(taskId: String?) {
+ if (taskId.isNullOrBlank()) {
+ return
+ }
+// queryTaskById(taskId).forEach {
+// taskBeanDao.delete(it)
+// }
+ }
/******************************* Lable *** End **********************************************/
/******************************* Small Lable *** Start **************************************/
diff --git a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
index 362df50..67c666e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/FileType.kt
@@ -3,5 +3,7 @@
sealed class FileType {
object APK : FileType()
+ object EXCEL : FileType()
+
object IMAGE : FileType()
}
diff --git a/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
index 9356f9a..566996e 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/LocaleConstant.kt
@@ -14,6 +14,7 @@
const val PERMISSIONS_CODE = 999
const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米
+ const val MAX_DISTANCE = 5.5f //表盘最大显示距离
const val AUTO_SAVE = "AUTO_SAVE"
const val USER_ACCOUNT = "USER_ACCOUNT"
diff --git a/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt b/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt
index 61e55f6..b726026 100644
--- a/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt
+++ b/app/src/main/java/com/casic/electric/detector/utils/LocationHub.kt
@@ -11,8 +11,8 @@
import com.amap.api.services.geocoder.GeocodeSearch
import com.amap.api.services.geocoder.RegeocodeQuery
import com.amap.api.services.geocoder.RegeocodeResult
-import com.casic.electric.detector.callback.IAddressListener
-import com.casic.electric.detector.callback.ILocationListener
+import com.casic.electric.detector.callback.OnGetAddressListener
+import com.casic.electric.detector.callback.OnGetLocationListener
class LocationHub constructor(context: Context) {
@@ -20,10 +20,11 @@
private val locationClient by lazy { AMapLocationClient(context) }
private val codeSearch by lazy { GeocodeSearch(context) }
- fun getCurrentLocation(isOnceLocation: Boolean, listener: ILocationListener) {
+ fun getCurrentLocation(isOnceLocation: Boolean, listener: OnGetLocationListener) {
val locationOption = AMapLocationClientOption()
locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
locationOption.isOnceLocation = isOnceLocation
+ locationOption.isNeedAddress = false
locationClient.setLocationOption(locationOption)
locationClient.setLocationListener {
if (it.errorCode == 0) {
@@ -38,7 +39,7 @@
locationClient.startLocation()
}
- fun antiCodingLocation(location: Location, listener: IAddressListener) {
+ fun antiCodingLocation(location: Location, listener: OnGetAddressListener) {
try {
// 第一个参数表示一个LatLonPoint,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
val query = RegeocodeQuery(
diff --git a/app/src/main/java/com/casic/electric/detector/view/ElectricMarkerDetailActivity.kt b/app/src/main/java/com/casic/electric/detector/view/ElectricMarkerDetailActivity.kt
index d72edc5..33bf42d 100644
--- a/app/src/main/java/com/casic/electric/detector/view/ElectricMarkerDetailActivity.kt
+++ b/app/src/main/java/com/casic/electric/detector/view/ElectricMarkerDetailActivity.kt
@@ -16,6 +16,7 @@
import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.utils.Constant
+//TODO 改为Dialog
class ElectricMarkerDetailActivity : KotlinBaseActivity() {
private lateinit var smallLabel: SmallLabelBean
diff --git a/.gitignore b/.gitignore
index 10a1363..18c6ed4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,18 @@
*.iml
.gradle
/local.properties
-/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
-local.properties
/app/build
/app/src/androidTest
/app/src/test
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..f766fc3
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..167cf0c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+