diff --git a/app/build.gradle b/app/build.gradle
index ef944099..9caeb55b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,7 +5,7 @@ plugins {
// 10,00,000 major-minor-build
def AppMajorVersion = 1
def AppMinorVersion = 0
-def AppBuildNumber = 150
+def AppBuildNumber = 152
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber
@@ -119,6 +119,8 @@ dependencies {
// implementation 'com.tencent:mmkv-static:1.3.0'
// implementation project(path: ':opencv')
implementation files('libs/devapi.aar')
+ debugImplementation files('libs/rtmp-client-debug.aar')
+ releaseImplementation files('libs/rtmp-client.aar')
implementation project(':gpuv')
// implementation group: 'io.netty', name: 'netty-all', version: '4.1.96.Final'
diff --git a/app/libs/rtmp-client-debug.aar b/app/libs/rtmp-client-debug.aar
new file mode 100644
index 00000000..a2c6ed39
Binary files /dev/null and b/app/libs/rtmp-client-debug.aar differ
diff --git a/app/libs/rtmp-client.aar b/app/libs/rtmp-client.aar
new file mode 100644
index 00000000..74992ed8
Binary files /dev/null and b/app/libs/rtmp-client.aar differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8ecf3ef2..c44fcf96 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -54,6 +54,7 @@
+
diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt
index 72dfad43..6b3b11b3 100644
--- a/app/src/main/cpp/CMakeLists.txt
+++ b/app/src/main/cpp/CMakeLists.txt
@@ -305,6 +305,8 @@ add_library( # Sets the name of the library.
ncnn/yolov5ncnn.cpp
+ serial/WeatherComm.cpp
+
# camera2/OpenCVFont.cpp
${CAMERA2_SOURCES}
diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp
index 7077c5cd..ac458a7c 100644
--- a/app/src/main/cpp/MicroPhoto.cpp
+++ b/app/src/main/cpp/MicroPhoto.cpp
@@ -12,6 +12,8 @@
#include
+#define NRSEC_PATH "/dev/spidev0.0"
+
#ifdef USING_BREAK_PAD
#include "client/linux/handler/exception_handler.h"
#include "client/linux/handler/minidump_descriptor.h"
@@ -710,35 +712,39 @@ Java_com_xypower_mpapp_MicroPhotoService_getSerialNumber(
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_importPublicKeyFile(
- JNIEnv* env, jclass cls, jint index, jstring path, jstring md5) {
+ JNIEnv* env, jclass cls, jint index, jstring outputPath, jstring md5) {
#ifdef USING_NRSEC
- NrsecPort nrsec;
-
// NrsecSpiPort spi("/dev/mtkgpioctrl");
// NrsecSpiPort spi("/dev/spidevSE");
// const char *port = "/dev/mtkgpioctrl";
- const char *port = "/dev/spidev0.0";
- if (!nrsec.Open(port))
+ if (env->GetStringUTFLength(outputPath) <=0)
+ {
+ return JNI_FALSE;
+ }
+
+ NrsecPort nrsec;
+ const char *path = NRSEC_PATH;
+ if (!nrsec.Open(path))
{
return JNI_FALSE;
}
- const char *pathStr = env->GetStringUTFChars(path, 0);
+ const char *outputPathStr = env->GetStringUTFChars(outputPath, 0);
const char *md5Str = env->GetStringUTFChars(md5, 0);
bool res = false;
std::vector data;
- if (readFile(pathStr, data) && !data.empty())
+ if (readFile(outputPathStr, data) && !data.empty())
{
- res = nrsec.SM2ImportPublicKey(1, &data[0]);
+ res = nrsec.SM2ImportPublicKey(index, &data[0]) == 0;
}
nrsec.Close();
- env->ReleaseStringUTFChars(path, pathStr);
+ env->ReleaseStringUTFChars(outputPath, outputPathStr);
env->ReleaseStringUTFChars(md5, md5Str);
return res ? JNI_TRUE : JNI_FALSE;
@@ -751,28 +757,22 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
#ifdef USING_NRSEC
- NrsecPort nrsec;
- // const char *port = "/dev/mtkgpioctrl";
- const char *port = "/dev/spidev0.0";
int byteCertLen = env->GetArrayLength(cert);
if (byteCertLen <= 0)
{
return JNI_FALSE;
}
- if (!nrsec.Open(port))
+ NrsecPort nrsec;
+ const char *path = NRSEC_PATH;
+ if (!nrsec.Open(path))
{
return JNI_FALSE;
}
- std::string version = nrsec.Version();
-
- char buf[128] = { 0 };
- strcpy(buf, version.c_str());
-
jbyte* byteCert = env->GetByteArrayElements(cert, 0);
- bool res = nrsec.SM2ImportPublicKey(index, (const uint8_t*)byteCert);
+ bool res = nrsec.SM2ImportPublicKey(index, (const uint8_t*)byteCert) == 0;
nrsec.Close();
@@ -788,32 +788,214 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
jclass cls, jint index) {
#ifdef USING_NRSEC
-
// GpioControl::setRS485Enable(true);
- GpioControl::setSpiMode(SPI_MODE_3);
- GpioControl::setSpiBitsPerWord(8);
- GpioControl::setSpiMaxSpeedHz(33000000);
+ //GpioControl::setSpiMode(SPI_MODE_3);
+ //GpioControl::setSpiBitsPerWord(8);
+ //GpioControl::setSpiMaxSpeedHz(33000000);
- const char *port = "/dev/mtkgpioctrl";
- // const char *port = "/dev/spidevSE";
+ const char *path = NRSEC_PATH;
NrsecPort nrsec;
- if (!nrsec.Open(port))
+ if (!nrsec.Open(path))
{
return JNI_FALSE;
}
+ bool res = nrsec.SM2keypair(index) == 0;
+
+ nrsec.Close();
+
+ return res ? JNI_TRUE : JNI_FALSE;
+#endif
+
+}
+
+extern "C" JNIEXPORT jstring JNICALL
+Java_com_xypower_mpapp_MicroPhotoService_querySecVersion(
+ JNIEnv* env,
+ jclass cls) {
+#ifdef USING_NRSEC
+
+ const char *path = NRSEC_PATH;
+
+ NrsecPort nrsec;
+ if (!nrsec.Open(path))
+ {
+ return NULL;
+ }
+
std::string version = nrsec.Version();
+ nrsec.Close();
- char buf[128] = { 0 };
- strcpy(buf, version.c_str());
+ return env->NewStringUTF(version.c_str());
+#endif
+}
- bool res = nrsec.SM2keypair(index) == 0;
+extern "C" JNIEXPORT jboolean JNICALL
+Java_com_xypower_mpapp_MicroPhotoService_genCertRequest(
+ JNIEnv* env, jclass cls, jint index, jint type, jstring subject, jstring outputPath) {
+
+#ifdef USING_NRSEC
+ if (env->GetStringUTFLength(subject) <=0 || env->GetStringUTFLength(outputPath) <=0)
+ {
+ return JNI_FALSE;
+ }
+ const char *path = NRSEC_PATH;
+ NrsecPort nrsec;
+ if (!nrsec.Open(path))
+ {
+ return JNI_FALSE;
+ }
+
+ uint8_t output[1024] = { 0 };
+ uint16_t len = 0;
+ const char* subjectStr = env->GetStringUTFChars(subject, 0);
+
+ bool res = nrsec.SM2cert(type, index, MakeString(subjectStr), output, &len) == 0;
nrsec.Close();
+ env->ReleaseStringUTFChars(subject, subjectStr);
+ if (!res)
+ {
+ return JNI_FALSE;
+ }
+
+ const char* outputPathStr = env->GetStringUTFChars(outputPath, 0);
+ FILE* file = fopen(outputPathStr, "wb");
+ env->ReleaseStringUTFChars(outputPath, outputPathStr);
+ if (file == NULL)
+ {
+ return JNI_FALSE;
+ }
+
+ int bytes = fwrite(output, sizeof(unsigned char), len, file);
+ fclose(file);
+
+ return bytes == len ? JNI_TRUE : JNI_FALSE;
+#endif
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_com_xypower_mpapp_MicroPhotoService_importPrivateKeyFile(
+ JNIEnv* env, jclass cls, jint index, jstring outputPath, jstring md5) {
+
+#ifdef USING_NRSEC
+
+ if (env->GetStringUTFLength(outputPath)<=0)
+ {
+ return JNI_FALSE;
+ }
+ const char *path = NRSEC_PATH;
+
+ NrsecPort nrsec;
+ if (!nrsec.Open(path))
+ {
+ return JNI_FALSE;
+ }
+
+ const char *outputPathStr = env->GetStringUTFChars(outputPath, 0);
+ const char *md5Str = env->GetStringUTFChars(md5, 0);
+
+ bool res = false;
+ std::vector data;
+ if (readFile(outputPathStr, data) && !data.empty())
+ {
+ res = nrsec.SM2ImportPrivateKey(index, &data[0]) == 0;
+ }
+
+ nrsec.Close();
+
+ env->ReleaseStringUTFChars(outputPath, outputPathStr);
+ env->ReleaseStringUTFChars(md5, md5Str);
return res ? JNI_TRUE : JNI_FALSE;
+
+#endif
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
+ JNIEnv* env, jclass cls, jint index, jstring outputPath) {
+
+#ifdef USING_NRSEC
+
+ if (env->GetStringUTFLength(outputPath) <= 0)
+ {
+ return JNI_FALSE;
+ }
+
+ const char *path = NRSEC_PATH;
+ NrsecPort nrsec;
+ if (!nrsec.Open(path))
+ {
+ return JNI_FALSE;
+ }
+
+ bool res = false;
+ std::vector data(64, 0);
+ uint8_t len = 0;
+ res = nrsec.SM2ExportPublicKey(index, &data[0], &len) == 0;
+ nrsec.Close();
+ if (!res)
+ {
+ return JNI_FALSE;
+ }
+
+ const char* outputPathStr = env->GetStringUTFChars(outputPath, 0);
+ FILE* file = fopen(outputPathStr, "wb");
+ env->ReleaseStringUTFChars(outputPath, outputPathStr);
+ if (file == NULL)
+ {
+ return JNI_FALSE;
+ }
+
+ int bytes = fwrite(&data[0], sizeof(unsigned char), len, file);
+
+ fclose(file);
+ return bytes == len ? JNI_TRUE : JNI_FALSE;
#endif
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
+ JNIEnv* env, jclass cls, jint index, jstring outputPath) {
+
+#ifdef USING_NRSEC
+
+ if (env->GetStringUTFLength(outputPath)<=0)
+ {
+ return JNI_FALSE;
+ }
+
+ const char *path = NRSEC_PATH;
+ NrsecPort nrsec;
+ if (!nrsec.Open(path))
+ {
+ return JNI_FALSE;
+ }
+
+ bool res = false;
+ std::vector data(64,0);
+ uint8_t len = 0;
+ res = nrsec.SM2ExportPrivateKey(index, &data[0], &len) == 0;
+ nrsec.Close();
+ if (!res)
+ {
+ return JNI_FALSE;
+ }
-}
\ No newline at end of file
+ const char* outputPathStr = env->GetStringUTFChars(outputPath, 0);
+ FILE* file = fopen(outputPathStr, "wb");
+ env->ReleaseStringUTFChars(outputPath, outputPathStr);
+ if (file == NULL)
+ {
+ return JNI_FALSE;
+ }
+
+ int bytes = fwrite(&data[0], sizeof(unsigned char), len, file);
+
+ fclose(file);
+ return bytes == len ? JNI_TRUE : JNI_FALSE;
+#endif
+}
diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp
index 1f879b97..51c13b02 100644
--- a/app/src/main/cpp/PhoneDevice.cpp
+++ b/app/src/main/cpp/PhoneDevice.cpp
@@ -527,6 +527,10 @@ bool CPhoneDevice::QuerySystemProperties(std::map& pro
#endif
it->second = version;
}
+ else if (it->first == PROP_BUILD_TIME)
+ {
+ it->second = FormatLocalDateTime(mBuildTime);
+ }
else if (it->first == PROP_PROD_DATE)
{
__system_property_get("ro.build.date.utc", value);
diff --git a/app/src/main/cpp/serial/WeatherComm.cpp b/app/src/main/cpp/serial/WeatherComm.cpp
new file mode 100644
index 00000000..01da9869
--- /dev/null
+++ b/app/src/main/cpp/serial/WeatherComm.cpp
@@ -0,0 +1,534 @@
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "GPIOControl.h"
+#include "WeatherComm.h"
+
+SIO_PARAM_SERIAL_DEF serialport;
+float weatherpntmsg[10];
+
+static void set_baudrate (struct termios *opt, unsigned int baudrate)
+{
+ cfsetispeed(opt, baudrate);
+ cfsetospeed(opt, baudrate);
+}
+
+static void set_data_bit (struct termios *opt, unsigned int databit)
+{
+ opt->c_cflag &= ~CSIZE;
+ switch (databit)
+ {
+ case 8:
+ opt->c_cflag |= CS8;
+ break;
+ case 7:
+ opt->c_cflag |= CS7;
+ break;
+ case 6:
+ opt->c_cflag |= CS6;
+ break;
+ case 5:
+ opt->c_cflag |= CS5;
+ break;
+ default:
+ opt->c_cflag |= CS8;
+ break;
+ }
+}
+
+static void set_parity (struct termios *opt, char parity)
+{
+ switch (parity)
+ {
+ case'N':/* 无校验 */
+ case 'n':
+ opt->c_cflag &= ~PARENB;
+ break;
+ case'E':/*偶校验*/
+ case 'e':
+ opt->c_cflag |= PARENB;
+ opt->c_cflag &= ~PARODD;
+ break;
+ case'O':/* 奇校验 */
+ case 'o':
+ opt->c_cflag |= PARENB;
+ opt->c_cflag |= ~PARODD;
+ break;
+ default: /*其它选择为无校验 */
+ opt->c_cflag &= ~PARENB;
+ break;
+ }
+}
+
+static void set_stopbit (struct termios *opt, const char *stopbit)
+{
+ if (strcmp(stopbit, "1") == 0)
+ {
+ opt->c_cflag &= ~CSTOPB;/*1 位停止位 t */
+ }
+ else if(0 == strcmp(stopbit, "1.5"))
+ {
+ opt->c_cflag &= ~CSTOPB;/*1.5 位停止位 */
+ }
+ else if(0 == strcmp (stopbit,"2"))
+ {
+ opt->c_cflag |= CSTOPB; /*2 位停止位 */
+ }
+ else
+ {
+ opt->c_cflag &= ~CSTOPB; /*1 位停止位 */
+ }
+}
+
+int set_port_attr (int fd, int baudrate, int databit, const char *stopbit, char parity, int vtime, int vmin )
+{
+ struct termios opt;
+ tcgetattr(fd, &opt);
+ set_baudrate(&opt, baudrate);
+ //opt.c_cflag |= CLOCAL|CREAD; /*|CRTSCTS */
+ opt.c_lflag &= ~(ICANON | ECHO |ECHOE |ISIG);
+ set_data_bit(&opt, databit);
+ set_parity(&opt, parity);
+ set_stopbit(&opt, stopbit);
+ opt.c_oflag = 0;
+ //opt.c_lflag |= 0;
+ opt.c_oflag &= ~OPOST;
+ opt.c_cc[VTIME] = vtime;
+ opt.c_cc[VMIN] = vmin;
+ tcflush (fd, TCIFLUSH);
+ return (tcsetattr (fd, TCSANOW, &opt));
+}
+
+static void setInt(int cmd, int value)
+{
+ int fd = open("/dev/mtkgpioctrl", O_RDONLY);
+ IOT_PARAM param;
+ param.cmd = cmd;
+ param.value = value;
+ // LOGE("set_int fd=%d,cmd=%d,value=%d\r\n",fd, cmd, value);
+ if( fd > 0 )
+ {
+ int res = ioctl(fd, IOT_PARAM_WRITE, ¶m);
+ // LOGE("set_int22 cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
+ close(fd);
+ }
+ return;
+}
+static void setRS485Enable(bool z) {
+ setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
+}
+
+static void set485WriteMode() {
+ setInt(CMD_SET_485_STATE, 1);
+}
+
+static void set485ReadMode() {
+ setInt(CMD_SET_485_STATE, 0);
+}
+static void set12VEnable(bool z) {
+ setInt(CMD_SET_12V_EN_STATE, z ? 1 : 0);
+}
+
+static void setCam3V3Enable(bool enabled)
+{
+ setInt(CMD_SET_CAM_3V3_EN_STATE, enabled ? 1 : 0);
+}
+
+
+/*********************************************************************************
+* 气象数据处理 *
+**********************************************************************************/
+void PortDataProcess( void )
+{
+ float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/;
+ //WORD uDevAddr;
+ unsigned char cmdidx;
+ int i, j, aipnt, datanum;
+ SIO_PARAM_SERIAL_DEF *pPortParam;
+ char szbuf[64];
+
+ pPortParam = &serialport;
+ //取出装置地址,开始处理地址+++
+ if(0x02 == pPortParam->m_au8RecvBuf[5])
+ {
+ //pPortParam->devaddr = pPortParam->m_au8RecvBuf[4];
+ return;
+ }
+ cmdidx = pPortParam->m_au8RecvBuf[5];
+#if 0
+ aipnt = pPortParam->SameTypeDevIdx;
+ uDevAddr = serialport->m_au8RecvBuf[4];
+ if(0 == srdt.IsReadWireTem)
+ {
+ if(uDevAddr != pPortParam->devaddr)
+ return;
+ }
+#endif
+ fvalua = &fvalue;
+ datanum = pPortParam->m_au8RecvBuf[6];
+ if((0x08 != cmdidx) && (0x09 != cmdidx))
+ return;
+
+ for(i = 0, j=7; (im_au8RecvBuf[1]); i++, j+=5 )
+ {
+ if(0x08 == cmdidx)
+ fvalue = (pPortParam->m_au8RecvBuf[j+1]<<24)+(pPortParam->m_au8RecvBuf[j+2]<<16)
+ +(pPortParam->m_au8RecvBuf[j+3]<<8)+pPortParam->m_au8RecvBuf[j+4];
+ else
+ {
+ *(u_char *)fvalua = pPortParam->m_au8RecvBuf[j+4];
+ *((u_char *)fvalua+1) = pPortParam->m_au8RecvBuf[j+3];
+ *((u_char *)fvalua+2) = pPortParam->m_au8RecvBuf[j+2];
+ *((u_char *)fvalua+3) = pPortParam->m_au8RecvBuf[j+1];
+ }
+ switch(pPortParam->m_au8RecvBuf[j])
+ {
+ case 1: /*温度*/
+ weatherpntmsg[0] = fvalue;
+ LOGE("温度:%0.3f ", fvalue);
+ break;
+ case 2: /*气压*/
+ weatherpntmsg[5] = fvalue;
+ LOGE("气压:%0.3f ", fvalue);
+ break;
+ case 3: /*湿度*/
+ weatherpntmsg[1] = fvalue;
+ LOGE("湿度:%0.3f ", fvalue);
+ break;
+ case 4: /*雨量*/
+ break;
+ case 5: /*日照*/
+ break;
+ case 6: /*风速*/
+ weatherpntmsg[2] = fvalue;
+ LOGE("风速:%0.3f ", fvalue);
+ break;
+ case 7: /*风向*/
+ weatherpntmsg[3] = fvalue;
+ LOGE("风向:%0.3f ", fvalue);
+ break;
+ case 8: /*拉力*/
+ case 9: /*倾角传感器X轴倾角*/
+ case 10: /*倾角传感器Y轴倾角*/
+ case 11: /*测温球导线温度*/
+ case 12: /*测温球内部温度*/
+ break;
+ case 13: /*测温球导线X轴倾角*/
+ break;
+ case 14: /*测温球导线Y轴倾角*/
+ break;
+ case 15: /*测温球导线电流*/
+ break;
+ case 16: /*测温球电池电压*/
+ break;
+ case 17: /*A相泄漏电流平均值;*/
+ break;
+ case 18: /*A相泄漏电流最大值;*/
+ break;
+ case 19: /*A相超过3mA的脉冲频次*/
+ break;
+ case 20: /*A相超过10mA的脉冲频次*/
+ break;
+ case 21: /*B相泄漏电流平均值;*/
+ break;
+ case 22: /*B相泄漏电流最大值;*/
+ break;
+ case 23: /*B相超过3mA的脉冲频次*/
+ break;
+ case 24: /*B相超过10mA的脉冲频次*/
+ case 25: /*C相泄漏电流平均值;*/
+ case 26: /*C相泄漏电流最大值;*/
+ case 27: /*C相超过3mA的脉冲频次*/
+ case 28: /*C相超过10mA的脉冲频次*/
+ break;
+ }
+ }
+}
+
+//***************************************************************
+//* 按照协议格式化接收数据 *
+//***************************************************************
+static void RecvData(u_char *buf, int len)// 规约读数据处理
+{
+ int i, ictime;
+ //WORD crc, check;
+ SIO_PARAM_SERIAL_DEF *pPortParam;
+
+ pPortParam = &serialport;
+ ictime = (int)time(NULL);
+
+ if(pPortParam->m_iRecvLen == 0)
+ {
+ pPortParam->iRecvTime = ictime;
+ }
+ else
+ {
+ if((ictime-pPortParam->iRecvTime > 6) || (ictime - pPortParam->iRecvTime < 0))
+ pPortParam->iRecvTime = ictime;
+ else if(ictime - pPortParam->iRecvTime > 2)
+ {
+ pPortParam->m_iRecvLen = 0;
+ pPortParam->m_iRevStatus = 0;
+ }
+ }
+
+ for(i=0; im_iRevStatus)
+ {
+ case 0: // 0x68
+ pPortParam->m_iRecvLen = 0;
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ if(0x68 == buf[i])
+ pPortParam->m_iRevStatus++;
+ else
+ pPortParam->m_iRevStatus = 18;
+ break;
+ case 1: // len1
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ pPortParam->m_iRevStatus++;
+ break;
+ case 2: // len2
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ if(buf[i] == pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen-2])
+ {
+ pPortParam->m_iRevStatus++;
+ pPortParam->m_iNeedRevLength = buf[i]+5;
+ }
+ else
+ pPortParam->m_iRevStatus = 18;
+ break;
+ case 3: // 0x68
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ pPortParam->m_iNeedRevLength--;
+ if(0x68 == buf[i])
+ pPortParam->m_iRevStatus++;
+ else
+ pPortParam->m_iRevStatus = 18;
+ break;
+ case 4: // 正确接收数据
+ pPortParam->m_iNeedRevLength--;
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ if(pPortParam->m_iNeedRevLength > 0)
+ break;
+ if(buf[i] != 0x16)
+ {
+ pPortParam->m_iRevStatus=18;
+ break;
+ }
+
+ //if(CheckLpcError(serialport->m_au8RecvBuf, pPortParam->m_iRecvLen) == TRUE)
+ {
+ PortDataProcess();
+ pPortParam->m_iRevStatus = 0;
+ pPortParam->RevCmdFlag = 1;
+ }
+ pPortParam->m_iRecvLen = 0;
+ break;
+ case 255:// 错误接收数据
+ default:
+ if(buf[i] == 0x68)
+ {
+ pPortParam->m_iRevStatus = 1;
+ pPortParam->m_iRecvLen = 1;
+ pPortParam->m_au8RecvBuf[0] = buf[i];
+ }
+ else if(buf[i] == 0x16)
+ {
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ pPortParam->m_iRevStatus = 0;
+ pPortParam->m_iRecvLen = 0;
+ }
+ else
+ {
+ pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i];
+ if(pPortParam->m_iRecvLen > 200)
+ {
+ pPortParam->m_iRecvLen = 0;
+ }
+ }
+ break;
+ }
+ }
+}
+
+//int inum =0;
+//int itimecnt=0;
+static int weather_comm(SERIAL_PARAM weatherport)
+{
+ int fd = -1;
+ int len, i,ret, ictime, iruntime, isendtime, irecvtime, icnt=0;
+ unsigned char sendbuf[] = {0x68,0x00,0x00,0x68,0x01,0x09,0x0a,0x16};
+ char recvbuf[256], szbuf[512];
+ //char serial_description[] = "/dev/ttyS0";
+
+#if 0
+ DIR *dir = opendir("/dev");
+ if (dir == NULL) {
+ LOGE("_test_ opendir");
+ return -1;
+ }
+
+ // 读取目录项
+ struct dirent *entry;
+ while ((entry = readdir(dir)) != NULL) {
+ // 过滤出串口设备,通常以"ttyS"或"ttyUSB"开头
+ if ((strncmp(entry->d_name, "ttyS2", 5) == 0) ||
+ (strncmp(entry->d_name, "ttyS0", 5) == 0)) {
+ LOGE("_test_ Found serial port: %s\n", entry->d_name);
+ }
+ }
+
+ // 关闭目录
+ closedir(dir);
+#endif
+ serialport.RevCmdFlag = 1;
+ serialport.m_iRecvLen = 0;
+ serialport.m_iRevStatus = 0;
+
+ set12VEnable(true);
+ setCam3V3Enable(true);
+ setRS485Enable(true);
+
+ ictime = (int)time(NULL);
+ for(;;)
+ {
+ if(fd < 0)
+ {
+ fd = open(weatherport.pathname, O_RDWR | O_NDELAY);
+ //fd = open(weatherport.pathname, O_RDWR | O_NOCTTY);
+ if(fd < 0)
+ {
+ LOGE("_test_ open serial error \n");
+ perror(weatherport.pathname);
+ return -1;
+ }
+
+ ret= set_port_attr (fd, weatherport.baudrate,weatherport.databit,weatherport.stopbit,weatherport.parity,0,0 );/*9600 8n1 */
+ if(ret < 0)
+ {
+ LOGE("_test_ set uart arrt faile \n");
+ return -1;
+ }
+ }
+
+ usleep(10000);
+ iruntime = (int)time(NULL);
+ if((iruntime - ictime > 120) || (iruntime - ictime < 0))
+ ictime = iruntime;
+ if(iruntime - ictime > 19)
+ {
+ memset(szbuf, 0, sizeof(szbuf));
+ sprintf(szbuf, "气象采样时间=%d,停止采样!", iruntime-ictime);
+ LOGE("%s", szbuf);
+ break;
+ }
+
+ if(1 == serialport.RevCmdFlag)
+ {
+ set485WriteMode();
+
+ len = write(fd, sendbuf, sizeof(sendbuf));/* 向串囗发送字符串 */
+ serialport.RevCmdFlag = 0;
+ isendtime = time(NULL);
+ if (len < 0) {
+ LOGE("write data error \n");
+ return -1;
+ } else {
+ memset(szbuf, 0, sizeof(szbuf));
+ sprintf(szbuf, "Send:");
+ for (i = 0; i < len; i++) {
+ sprintf(szbuf, "%s %02X", szbuf, sendbuf[i]);
+ }
+ LOGE("%s", szbuf);
+ //icnt = 0;
+ //inum++;
+ }
+ tcdrain(fd);
+ //usleep(50000);
+ }
+ else
+ {
+ irecvtime = time(NULL);
+ if((irecvtime-isendtime > 6) ||(irecvtime - isendtime < 0))
+ isendtime = irecvtime;
+ if (irecvtime-isendtime > 1)
+ {
+ LOGE("传感器超过%d秒未应答", irecvtime-isendtime);
+ serialport.RevCmdFlag = 1;
+ serialport.m_iRecvLen = 0;
+ serialport.m_iRevStatus = 0;
+ close(fd);
+ //set12VEnable(false);
+ //setCam3V3Enable(false);
+ //setRS485Enable(false);
+ fd = -1;
+ continue;
+ }
+ }
+ set485ReadMode();
+ memset(recvbuf, 0, sizeof(recvbuf));
+ len = read(fd, recvbuf, sizeof(recvbuf));/* 在串口读取字符串 */
+ if (len < 0) {
+ LOGE("serial read error \n");
+ continue;
+ }
+ if(0 == len)
+ {
+ //icnt++;
+ continue;
+ }
+
+ memset(szbuf, 0, sizeof(szbuf));
+ sprintf(szbuf, "Recv:");
+ for (i = 0; i < len; i++) {
+ sprintf(szbuf, "%s %02X", szbuf, recvbuf[i]);
+ }
+ __android_log_print(ANDROID_LOG_INFO, "serial", "%s", szbuf);
+ RecvData((u_char*)recvbuf, len);
+ //LOGE("一周期空循环次数%d, 读取次数%d, 时间:%d %d", icnt, inum, (int)time(NULL), itimecnt);
+ icnt = 0;
+ //serialport.RevCmdFlag =1;
+ }
+
+ close(fd);
+ set12VEnable(false);
+ setCam3V3Enable(false);
+ setRS485Enable(false);
+
+ //exit(-1);
+ return(0);
+}
+
+int serial_port_comm()
+{
+ SERIAL_PARAM portparm;
+#if 1
+ memset(portparm.pathname, 0, sizeof(portparm.pathname));
+ sprintf(portparm.pathname, "/dev/ttyS0");
+ portparm.parity = 'N';
+ portparm.databit = 8;
+ portparm.baudrate = B9600;
+ memset(portparm.stopbit, 0, sizeof(portparm.stopbit));
+ sprintf(portparm.stopbit, "1");
+#endif
+ //itimecnt = (int)time(NULL);
+
+ for(;;)
+ weather_comm(portparm);
+ return 0;
+}
+
diff --git a/app/src/main/cpp/serial/WeatherComm.h b/app/src/main/cpp/serial/WeatherComm.h
new file mode 100644
index 00000000..80c47f98
--- /dev/null
+++ b/app/src/main/cpp/serial/WeatherComm.h
@@ -0,0 +1,51 @@
+//
+// Created by hyz on 2024/6/5.
+//
+
+#ifndef WEATHERCOMM_H
+#define WEATHERCOMM_H
+
+#include
+#include "GPIOControl.h"
+
+#define MAX_STRING_LEN 32
+#define IOT_PARAM_WRITE 0xAE
+#define IOT_PARAM_READ 0xAF
+
+#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, "serial_port_comm", fmt, ##args)
+
+// 串口参数
+typedef struct
+{
+ int baudrate; /* 波特率*/
+ int databit; /* 数据位*/
+ char stopbit[8]; /* 停止位*/
+ char parity; /* 校验位*/
+ char pathname[128];/* 串口文件名及路径*/
+} SERIAL_PARAM;
+
+typedef struct
+{
+ int m_iRevStatus; /* */
+ int m_iRecvLen; /* */
+ int m_iNeedRevLength; /* */
+ int iRecvTime; /* */
+ int RevCmdFlag;
+ unsigned char m_au8RecvBuf[128];/* */
+} SIO_PARAM_SERIAL_DEF;
+
+typedef struct
+{
+ int cmd;
+ int value;
+ int result;
+ long value2;
+ char str[MAX_STRING_LEN];
+}IOT_PARAM;
+
+void PortDataProcess( void );
+int serial_port_comm();
+static int weather_comm(SERIAL_PARAM weatherport);
+int set_port_attr (int fd, int baudrate, int databit, const char *stopbit, char parity, int vtime, int vmin );
+
+#endif //WEATHERCOMM_H
diff --git a/app/src/main/java/com/xypower/mpapp/CertActivity.java b/app/src/main/java/com/xypower/mpapp/CertActivity.java
index c6acdcc3..8b46e1f9 100644
--- a/app/src/main/java/com/xypower/mpapp/CertActivity.java
+++ b/app/src/main/java/com/xypower/mpapp/CertActivity.java
@@ -53,8 +53,11 @@ public class CertActivity extends AppCompatActivity {
int index = intent.getIntExtra("index", 0);
MicroPhotoService.genKeys(index);
} else if (TextUtils.equals(action, ACTION_CERT_REQ)) {
- // int index = intent.getIntExtra("index", 0);
- // MicroPhotoService.genKeys(index);
+ int index = intent.getIntExtra("index", 0);
+ int type = intent.getIntExtra("type", 0);
+ String subject = intent.getStringExtra("subject");
+ String path = intent.getStringExtra("path");
+ MicroPhotoService.genCertRequest(index, type, subject, path);
}
}
diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java
index 9460b2d4..8332f9b5 100644
--- a/app/src/main/java/com/xypower/mpapp/MainActivity.java
+++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java
@@ -1,6 +1,8 @@
package com.xypower.mpapp;
import android.Manifest;
+import android.app.Activity;
+import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java
index 9275c2d3..1f89b02e 100644
--- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java
+++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java
@@ -1140,10 +1140,17 @@ cellSignalStrengthGsm.getDbm();
public static native void setOtgState(boolean enabled);
public static native void setCam3V3Enable(boolean enabled);
public static native String getSerialNumber();
- public static native boolean importPublicKeyFile(int index, String path, String md5);
+ public static native boolean importPublicKeyFile(int index, String outputPath, String md5);
public static native boolean importPublicKey(int index, byte cert[]);
public static native boolean genKeys(int index);
+ public static native String querySecVersion();
+ public static native boolean genCertRequest(int index, int type, String subject, String outputPath);
+ public static native boolean importPrivateKeyFile(int index, String outputPath, String md5);
+ public static native boolean exportPublicKeyFile(int index, String outputPath);
+ public static native boolean exportPrivateFile(int index, String outputPath);
+
+
////////////////////////GPS////////////////////
// private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
private LocationManager mLocationManager;
diff --git a/app/src/main/java/com/xypower/mpapp/v2/AspectRatioFrameLayout.java b/app/src/main/java/com/xypower/mpapp/v2/AspectRatioFrameLayout.java
index b281c90b..203edd77 100644
--- a/app/src/main/java/com/xypower/mpapp/v2/AspectRatioFrameLayout.java
+++ b/app/src/main/java/com/xypower/mpapp/v2/AspectRatioFrameLayout.java
@@ -70,6 +70,16 @@ public final class AspectRatioFrameLayout extends FrameLayout {
private float videoAspectRatio;
private int resizeMode;
+ public static interface OnSizeChangeListener {
+ void onSizeChanged(int width, int height);
+ }
+
+ private OnSizeChangeListener mOnSizeChangedListener = null;
+
+ public void setOnSizeChangedListener(OnSizeChangeListener sizeChangedListener) {
+ mOnSizeChangedListener = sizeChangedListener;
+ }
+
public AspectRatioFrameLayout(Context context) {
this(context, null);
}
@@ -144,6 +154,17 @@ public final class AspectRatioFrameLayout extends FrameLayout {
}
break;
}
+
+ if (mOnSizeChangedListener != null) {
+ final int fw = width;
+ final int fh = height;
+ this.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mOnSizeChangedListener.onSizeChanged(fw, fh);
+ }
+ }, 0);
+ }
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
diff --git a/app/src/main/java/com/xypower/mpapp/v2/AutoFitGLView.java b/app/src/main/java/com/xypower/mpapp/v2/AutoFitGLView.java
index 4d2e2cb6..4c59abb0 100644
--- a/app/src/main/java/com/xypower/mpapp/v2/AutoFitGLView.java
+++ b/app/src/main/java/com/xypower/mpapp/v2/AutoFitGLView.java
@@ -8,7 +8,8 @@ import android.view.View;
public class AutoFitGLView extends GLSurfaceView implements View.OnTouchListener {
- private float mAspectRatio;
+ private int mRatioWidth = 0;
+ private int mRatioHeight = 0;
public AutoFitGLView(Context context) {
this(context, null);
@@ -21,12 +22,24 @@ public class AutoFitGLView extends GLSurfaceView implements View.OnTouchListener
private TouchListener touchListener;
- public void setAspectRatio(int width, int height){
- mAspectRatio = (float)width / height;
- getHolder().setFixedSize(width, height);
- requestLayout();
+ /**
+ * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
+ * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
+ * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
+ *
+ * @param width Relative horizontal size
+ * @param height Relative vertical size
+ */
+ public void setAspectRatio(int width, int height) {
+ if (width < 0 || height < 0) {
+ throw new IllegalArgumentException("Size cannot be negative.");
+ }
+ mRatioWidth = width;
+ mRatioHeight = height;
+ post(() -> requestLayout());
}
+
@Override
public boolean onTouch(View v, MotionEvent event) {
final int actionMasked = event.getActionMasked();
@@ -53,26 +66,14 @@ public class AutoFitGLView extends GLSurfaceView implements View.OnTouchListener
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
- if (mAspectRatio == 0) {
+ if (0 == mRatioWidth || 0 == mRatioHeight) {
setMeasuredDimension(width, height);
- }else {
- int newW,newH;
- float actualRatio;
- if (width > height) {
- actualRatio = mAspectRatio;
- }else {
- actualRatio = 1 / mAspectRatio;
+ } else {
+ if (width < height * mRatioWidth / mRatioHeight) {
+ setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
+ } else {
+ setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
}
-
- if (width < height * actualRatio){
- newH = height;
- newW = (int) (height * actualRatio);
- }else {
- newW = width;
- newH = (int) (width / actualRatio);
- }
- setMeasuredDimension(newW, newH);
-
}
}
}
diff --git a/app/src/main/java/com/xypower/mpapp/v2/Camera2VideoActivity.java b/app/src/main/java/com/xypower/mpapp/v2/Camera2VideoActivity.java
index 394e4443..ea8c82bc 100644
--- a/app/src/main/java/com/xypower/mpapp/v2/Camera2VideoActivity.java
+++ b/app/src/main/java/com/xypower/mpapp/v2/Camera2VideoActivity.java
@@ -22,12 +22,15 @@ import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.View;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowMetrics;
import android.widget.FrameLayout;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@@ -176,7 +179,20 @@ public class Camera2VideoActivity extends AppCompatActivity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
Window win = getWindow();
- win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ int flags = /*WindowManager.LayoutParams.FLAG_FULLSCREEN
+ | */WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
+ int mask = /*WindowManager.LayoutParams.FLAG_FULLSCREEN |
+ | */WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
+ win.setFlags(flags, mask);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
+ setShowWhenLocked(true);
+ }
setContentView(R.layout.activity_camera2_video);
@@ -241,6 +257,14 @@ public class Camera2VideoActivity extends AppCompatActivity {
mCameraHeight = mVideoHeight;
AspectRatioFrameLayout frameLayout = (AspectRatioFrameLayout)findViewById(R.id.wrap_view);
+
+ frameLayout.setOnSizeChangedListener(new AspectRatioFrameLayout.OnSizeChangeListener() {
+ @Override
+ public void onSizeChanged(int width, int height) {
+ Log.i("OSD", "width=" + Integer.toString(width));
+ }
+ });
+
frameLayout.setAspectRatio((float)mVideoWidth / (float)mVideoHeight);
mTimeMask = 0;
@@ -292,12 +316,6 @@ public class Camera2VideoActivity extends AppCompatActivity {
mHandler = new Handler();
- // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@@ -307,18 +325,39 @@ public class Camera2VideoActivity extends AppCompatActivity {
@Override
public void run() {
mNextVideoAbsolutePath = getVideoFilePath();
- mGPUCameraRecorder.start(mNextVideoAbsolutePath);
+ if (mGPUCameraRecorder != null) {
+ mGPUCameraRecorder.start(mNextVideoAbsolutePath);
+ } else {
+ int aa = 0;
+ }
}
}, 0);
}
}, 100);
+ // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Log.i("OSD", "onResume");
+
}
@Override
protected void onStop() {
super.onStop();
+
+ Log.i("OSD", "onStop");
+
+ }
+
+ @Override
+ protected void onDestroy() {
+ Log.i("OSD", "onDestroy");
releaseCamera();
+ super.onDestroy();
}
private void initOSD(Bitmap bm, long ts) {
@@ -514,7 +553,7 @@ public class Camera2VideoActivity extends AppCompatActivity {
int statusHeight = mStatusBarHeight;
Canvas canvas = new Canvas(bm);
- boolean aa = canvas.isHardwareAccelerated();
+ // boolean aa = canvas.isHardwareAccelerated();
Rect textBounds = new Rect();
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
@@ -590,6 +629,7 @@ public class Camera2VideoActivity extends AppCompatActivity {
mGPUCameraRecorder.stop();
mGPUCameraRecorder.release();
mGPUCameraRecorder = null;
+ Log.i("OSD", "mGPUCameraRecorder destroyed");
}
if (mPreviewView != null) {
@@ -602,7 +642,7 @@ public class Camera2VideoActivity extends AppCompatActivity {
runOnUiThread(() -> {
- AspectRatioFrameLayout frameLayout = (AspectRatioFrameLayout)findViewById(R.id.wrap_view);
+ final AspectRatioFrameLayout frameLayout = (AspectRatioFrameLayout)findViewById(R.id.wrap_view);
frameLayout.removeAllViews();
mPreviewView = null;
@@ -612,40 +652,77 @@ public class Camera2VideoActivity extends AppCompatActivity {
mGPUCameraRecorder.changeManualFocusPoint(event.getX(), event.getY(), width, height);
});
- frameLayout.addView(mPreviewView);
+ mPreviewView.getHolder().addCallback(new SurfaceHolder.Callback() {
+ @Override
+ public void surfaceCreated(@NonNull SurfaceHolder holder) {
- if (!TextUtils.isEmpty(mOSDLeftTop) || !TextUtils.isEmpty(mOSDLeftTop) || !TextUtils.isEmpty(mOSDLeftTop) || !TextUtils.isEmpty(mOSDLeftTop)) {
- mPreviewWidth = frameLayout.getMeasuredWidth();
- mPreviewHeight = frameLayout.getMeasuredHeight();
+ }
- mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- mPaint.setStyle(Paint.Style.FILL);
- mPaint.setColor(Color.WHITE);
- int fontSize = DEFAULT_FONT_SIZE * mPreviewHeight / 1024;
- float strokeWidth = DEFAULT_STROKE_WIDTH * mPreviewHeight / 1024;
- mPaint.setTextSize(fontSize);
+ @Override
+ public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
+ if (width > 0 && height > 0) {
- mPaintStroker = new Paint(Paint.ANTI_ALIAS_FLAG);
- mPaintStroker.setStyle(Paint.Style.STROKE);
- mPaintStroker.setColor(Color.BLACK);
- mPaintStroker.setTextSize(fontSize);
- mPaintStroker.setStrokeWidth(strokeWidth);
+ }
+ }
- Bitmap bm = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(bm);
- canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
+ @Override
+ public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
- long ts = System.currentTimeMillis();
- long zeroTs = ts - (ts % 1000);
- initOSD(bm, zeroTs);
- mOSDFilter = new GlWatermarkFilter(bm);
+ }
+ });
+
+ frameLayout.addView(mPreviewView);
+
+ frameLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
+
+ int width = right - left;
+ int height = bottom - top;
+
+ if (width <= 0 || height <= 0) {
+ return;
+ }
+ frameLayout.removeOnLayoutChangeListener(this);
+
+ if (!TextUtils.isEmpty(mOSDLeftTop) || !TextUtils.isEmpty(mOSDLeftTop) || !TextUtils.isEmpty(mOSDLeftTop) || !TextUtils.isEmpty(mOSDLeftTop)) {
+ mPreviewWidth = frameLayout.getMeasuredWidth();
+ mPreviewHeight = frameLayout.getMeasuredHeight();
+
+ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mPaint.setStyle(Paint.Style.FILL);
+ mPaint.setColor(Color.WHITE);
+ int fontSize = DEFAULT_FONT_SIZE * mPreviewHeight / 1024;
+ float strokeWidth = DEFAULT_STROKE_WIDTH * mPreviewHeight / 1024;
+ mPaint.setTextSize(fontSize);
+
+ mPaintStroker = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mPaintStroker.setStyle(Paint.Style.STROKE);
+ mPaintStroker.setColor(Color.BLACK);
+ mPaintStroker.setTextSize(fontSize);
+ mPaintStroker.setStrokeWidth(strokeWidth);
+
+ Bitmap bm = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bm);
+ canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
+
+ long ts = System.currentTimeMillis();
+ long zeroTs = ts - (ts % 1000);
+ initOSD(bm, zeroTs);
+ mOSDFilter = new GlWatermarkFilter(bm);
+
+ if (mGPUCameraRecorder != null) {
+ mGPUCameraRecorder.setFilter(mOSDFilter);
+ }
+
+ mOsdThread.start();
+ }
- if (mGPUCameraRecorder != null) {
- mGPUCameraRecorder.setFilter(mOSDFilter);
}
+ });
+
+
- mOsdThread.start();
- }
});
}
@@ -661,13 +738,11 @@ public class Camera2VideoActivity extends AppCompatActivity {
.cameraRecordListener(new CameraRecordListener() {
@Override
public void onGetFlashSupport(boolean flashSupport) {
-
}
@Override
public void onRecordComplete() {
// mHandler.removeCallbacks(mTimerRunnable);
-
}
@Override
@@ -682,7 +757,6 @@ public class Camera2VideoActivity extends AppCompatActivity {
int aa = 0;
}
}, 1200L + mDuration * 1000);
-
}
@Override
@@ -711,7 +785,6 @@ public class Camera2VideoActivity extends AppCompatActivity {
@Override
public void onDurationArrived() {
-
}
})
.videoSize(mVideoWidth, mVideoHeight)
@@ -721,6 +794,7 @@ public class Camera2VideoActivity extends AppCompatActivity {
.duration(mDuration * 1000)
.build();
+ Log.i("OSD", "mGPUCameraRecorder created");
if (mOSDFilter != null) {
mGPUCameraRecorder.setFilter(mOSDFilter);
}
diff --git a/app/src/main/res/layout/activity_camera2_video.xml b/app/src/main/res/layout/activity_camera2_video.xml
index 7c58cc11..945a0eba 100644
--- a/app/src/main/res/layout/activity_camera2_video.xml
+++ b/app/src/main/res/layout/activity_camera2_video.xml
@@ -1,9 +1,11 @@
0) && (startedCount <= 0)) {
- mediaMuxer.stop();
- mediaMuxer.release();
+ try {
+ mediaMuxer.stop();
+ mediaMuxer.release();
+ } catch (Exception ex) {
+ }
isStarted = false;
Log.v(TAG, "MediaMuxer stopped:");
}
diff --git a/mpmaster/build.gradle b/mpmaster/build.gradle
index ae189d36..ec252529 100644
--- a/mpmaster/build.gradle
+++ b/mpmaster/build.gradle
@@ -4,7 +4,7 @@ plugins {
def AppMajorVersion = 1
def AppMinorVersion = 0
-def AppBuildNumber = 38
+def AppBuildNumber = 39
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java
index 98d0d6b9..5ee17218 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java
@@ -111,13 +111,17 @@ public class AppMaster {
return (System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000) / 1000;
}
- private void selectSimCard(int number) {
- TelephonyManager telephonyManager = (TelephonyManager)mService.getSystemService(Context.TELEPHONY_SERVICE);
- }
-
public void start() {
new Thread(new Runnable() {
+
+ void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (Exception ex) {
+ }
+ }
+
@Override
public void run() {
@@ -125,30 +129,24 @@ public class AppMaster {
if (separateNetwork) {
try {
+ ConnectivityManager connectivityManager = (ConnectivityManager) mService.getSystemService(Context.CONNECTIVITY_SERVICE);
+ Network previousNetwork = connectivityManager.getActiveNetwork();
+ String previousNetworkStr = previousNetwork.toString();
+
+ mService.logger.info("Switch to Simcard 2");
SysApi.selectSimCard4Data(mService.getApplicationContext(), 2);
- Thread.sleep(100);
+ sleep(100);
boolean connected = false;
- ConnectivityManager connectivityManager = (ConnectivityManager) mService.getSystemService(Context.CONNECTIVITY_SERVICE);
for (int idx = 0; idx < 8; idx++) {
- Network[] networks = connectivityManager.getAllNetworks();
- if (networks != null && networks.length > 0) {
- for (Network nw : networks) {
- NetworkInfo ni = connectivityManager.getNetworkInfo(nw);
-
- if (ni.getType() == 0) {
- connected = true;
- break;
- }
- }
- }
-
- if (connected) {
+ Network network = connectivityManager.getActiveNetwork();
+ if (!network.equals(previousNetwork)) {
+ mService.logger.info("Network Changed from " + previousNetworkStr + " to " + network.toString());
break;
}
- Thread.sleep(1000);
+ sleep(1000);
}
try {
@@ -158,6 +156,7 @@ public class AppMaster {
} finally {
try {
if (!mService.isMntnMode()) {
+ mService.logger.info("Switch to Simcard 1");
SysApi.selectSimCard4Data(mService.getApplicationContext(), 1);
}
} catch (Exception ex) {
@@ -166,6 +165,15 @@ public class AppMaster {
}
} catch (Exception ex) {
ex.printStackTrace();
+ } finally {
+ try {
+ if (!mService.isMntnMode()) {
+ mService.logger.info("Switch to Simcard 1");
+ SysApi.selectSimCard4Data(mService.getApplicationContext(), 1);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
} else {
try {
@@ -225,13 +233,17 @@ public class AppMaster {
postParams.add(new Pair("firmware", MpMasterService.getSystemProperty("ro.custom.ota.version")));
+ postParams.add(new Pair("signalLevel1", Integer.toString(MpMasterService.getSignalLevel(1))));
+ postParams.add(new Pair("signalLevel2", Integer.toString(MpMasterService.getSignalLevel(2))));
+
// SysApi.
postParams.add(new Pair("simcard1", mService.getIccid(1)));
// if (mService.isSeparateNetwork()) {
- postParams.add(new Pair("simcard2", mService.getIccid(2)));
+ postParams.add(new Pair("simcard2", mService.getIccid(2)));
// }
postParams.add(new Pair("freeROM", getFreeROM()));
+
buildStats(startTime, postParams);
try {
@@ -361,7 +373,11 @@ public class AppMaster {
}
private String getFreeROM() {
- // return SysApi.get
+ long[] flashInfo = SysApi.getFlashInfo();
+ if (flashInfo != null && flashInfo.length > 1) {
+ double fd = (double)(flashInfo[1] * 100) / (double)flashInfo[0];
+ return Integer.toString((int)fd) + "%";
+ }
return "";
}
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
index e5eb7fd2..b651c8ba 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
@@ -430,7 +430,7 @@ public class MpMasterService extends Service {
MicroPhotoContext.saveMasterConfig(getApplicationContext(), masterConfig);
logger.warning("MNTN Mode Changed from " + convertSwitch(oldMntnMode) + " to " + convertSwitch(mntnMode)
- + " Quick Heartbeat from" + convertSwitch(oldQuickHbMode) + " to " + convertSwitch(quickHbMode));
+ + " Quick Heartbeat from " + convertSwitch(oldQuickHbMode) + " to " + convertSwitch(quickHbMode));
}
if (oldQuickHbMode != quickHbMode) {
@@ -496,6 +496,7 @@ public class MpMasterService extends Service {
mService.restartApp(context, context.getPackageName());
} else {
mService.loadConfig();
+ mService.registerHeartbeatTimer();
}
} else if (TextUtils.equals(ACTION_UPD_OTA, action)) {
@@ -548,8 +549,10 @@ public class MpMasterService extends Service {
private void registerHeartbeatTimer() {
long timeout = mHeartbeatDuration;
- if (mMntnMode && mQuickHbMode) {
- timeout = mQuickHeartbeatDuration;
+ if (mMntnMode) {
+ if (mQuickHbMode) {
+ timeout = mQuickHeartbeatDuration;
+ }
registerHeartbeatTimer(System.currentTimeMillis() + timeout * 1000);
} else {
long closestTime = -1;
@@ -644,7 +647,7 @@ public class MpMasterService extends Service {
mCmdid = cmdid;
}
- Log.i(TAG, "AppPath=" + appPath + " cmdid=" + cmdid);
+ logger.info("AppPath=" + appPath + " cmdid=" + cmdid);
// startMaster(false);
mHander.postDelayed(new Runnable() {
@@ -654,6 +657,10 @@ public class MpMasterService extends Service {
}
}, 5000);
+ // Reset Data Network
+ // logger.info("Switch to Simcard 1");
+ // SysApi.selectSimCard4Data(getApplicationContext(), 1);
+
registerHeartbeatTimer();
startMaster(false);
@@ -801,6 +808,36 @@ public class MpMasterService extends Service {
return true;
}
+ public static int getSignalLevel(int num) {
+ String result = getSystemProperty("vendor.ril.nw.signalstrength.lte." + Integer.toString(num));
+ if (TextUtils.isEmpty(result)) {
+ return 0;
+ }
+ String[] items = result.split(",");
+ int rsrp = -140;
+
+ if (items != null && items.length > 0) {
+ try {
+ rsrp = Integer.parseInt(items[0]);
+ } catch (Exception ex) {
+ }
+ }
+ int signalLevel = 0;
+ if (rsrp >= -97) {
+ signalLevel = 4;
+ } else if (rsrp >= -107) {
+ signalLevel = 3;
+ } else if (rsrp >= -117) {
+ signalLevel = 2;
+ } else if (rsrp >= -125) {
+ signalLevel = 1;
+ } else if (rsrp >= -140) {
+ signalLevel = 0;
+ }
+
+ return signalLevel;
+ }
+
public void downloadAndInstall(final String url) {
final Context context = getApplicationContext();