|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
#include "TerminalDevice.h"
|
|
|
|
|
|
|
|
|
|
#include <AndroidHelper.h>
|
|
|
|
|
#include "PhoneDevice.h"
|
|
|
|
|
#include <AndroidHelper.h>
|
|
|
|
|
#include <SpecData_JSON.h>
|
|
|
|
|
#include <Client/Terminal.h>
|
|
|
|
|
#include <Utils.h>
|
|
|
|
|
#include <LogThread.h>
|
|
|
|
@ -289,6 +288,119 @@ bool CPhoneDevice::BindNetwork(int sock)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::SelfTest(std::string& result)
|
|
|
|
|
{
|
|
|
|
|
result.clear();
|
|
|
|
|
|
|
|
|
|
unsigned int numberOfChannels = 0;
|
|
|
|
|
|
|
|
|
|
result += "自检。Version:" + GetVersion() + "\r\n";
|
|
|
|
|
|
|
|
|
|
Json::Value appConfig = Json::objectValue;
|
|
|
|
|
std::vector<unsigned char> content;
|
|
|
|
|
std::string filePath = m_appPath + (APP_DATA_DIR DIR_SEP_STR APP_FILE_NAME_APP_CONF);
|
|
|
|
|
if (!readFile(filePath, content))
|
|
|
|
|
{
|
|
|
|
|
result += "读取系统配置文件App.json失败\r\n";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Json::CharReaderBuilder builder;
|
|
|
|
|
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
|
|
|
|
|
|
|
|
const char* doc = (const char*)&(content[0]);
|
|
|
|
|
if (reader->parse(doc, doc + content.size(), &appConfig, NULL))
|
|
|
|
|
{
|
|
|
|
|
unsigned int val = 0;
|
|
|
|
|
if (GetJSONUInt32Value(appConfig, "channels", val) && (val > 0 && val <= 255))
|
|
|
|
|
{
|
|
|
|
|
numberOfChannels = val;
|
|
|
|
|
result += "通道数:" + std::to_string(numberOfChannels) + "\r\n";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result += "通道数未定义或者无效\r\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result += "解析系统配置文件App.json失败\r\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned int channel = 1; channel <= numberOfChannels; channel++)
|
|
|
|
|
{
|
|
|
|
|
std::string path = m_appPath + (APP_PATH_CHANNELS DIR_SEP_STR);
|
|
|
|
|
|
|
|
|
|
unsigned char cameraId = 0;
|
|
|
|
|
Json::Value channelCfg = Json::objectValue;
|
|
|
|
|
content.clear();
|
|
|
|
|
filePath = m_appPath + (APP_DATA_DIR DIR_SEP_STR APP_FILE_NAME_APP_CONF);
|
|
|
|
|
if (!readFile(filePath, content))
|
|
|
|
|
{
|
|
|
|
|
result += "读取通道" + std::to_string(channel) + "配置文件失败\r\n";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Json::CharReaderBuilder builder;
|
|
|
|
|
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
|
|
|
|
|
|
|
|
const char* doc = (const char*)&(content[0]);
|
|
|
|
|
if (reader->parse(doc, doc + content.size(), &channelCfg, NULL))
|
|
|
|
|
{
|
|
|
|
|
unsigned char val = 0;
|
|
|
|
|
if (GetJSONUInt8Value(channelCfg, "cameraId", cameraId))
|
|
|
|
|
{
|
|
|
|
|
result += "通道" + std::to_string(channel) + " Camera ID为 " + std::to_string(cameraId) + "\r\n";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cameraId = channel - 1;
|
|
|
|
|
result += "通道" + std::to_string(channel) + "未定义Camera ID, 使用默认值 " + std::to_string(cameraId) + "\r\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result += "解析通道" + std::to_string(channel) + "配置文件App.json失败\r\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t width = 0;
|
|
|
|
|
int32_t height = 0;
|
|
|
|
|
NdkCamera::CAMERA_PARAMS params = { 0 };
|
|
|
|
|
NdkCamera camera(width, height, params);
|
|
|
|
|
int res = camera.selfTest(std::to_string(cameraId), width, height);
|
|
|
|
|
if (res == 0)
|
|
|
|
|
{
|
|
|
|
|
result += "通道" + std::to_string(channel) + "正常:最大分辨率:" + std::to_string(width) + "x" + std::to_string(height) + "\r\n";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result += "通道" + std::to_string(channel) + " 异常 err=" + std::to_string(res) + "\r\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int bv = QueryBatteryVoltage(DEFAULT_BATTERY_QUERY_RETRIES);
|
|
|
|
|
if (bv > 0)
|
|
|
|
|
{
|
|
|
|
|
bv -= bv % 100;
|
|
|
|
|
result += "电池电压:" + std::to_string((float)bv / 1000) + "\r\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs::space_info si = fs::space("/data");
|
|
|
|
|
double fr = ((double)si.available * 100.0f) / ((double)si.capacity);
|
|
|
|
|
result += "存储剩余:";
|
|
|
|
|
result += std::to_string((int)fr);
|
|
|
|
|
result += "%\r\n";
|
|
|
|
|
|
|
|
|
|
long fm = android_os_Process_getFreeMemory();
|
|
|
|
|
long tm = android_os_Process_getTotalMemory();
|
|
|
|
|
double fmp = ((double)fm * 100.0f) / ((double)tm);
|
|
|
|
|
result += std::string("可用内存:") + std::to_string((int)fmp) + std::string("%\r\n");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::UpdateTime(time_t ts)
|
|
|
|
|
{
|
|
|
|
|
JNIEnv* env = NULL;
|
|
|
|
@ -329,6 +441,22 @@ bool CPhoneDevice::UpdateSchedules()
|
|
|
|
|
return (ret == JNI_TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CPhoneDevice::QueryBatteryVoltage(int retries)
|
|
|
|
|
{
|
|
|
|
|
int val = -1; // // BatVol
|
|
|
|
|
for (int idx = 0; idx < retries; idx++)
|
|
|
|
|
{
|
|
|
|
|
val = GpioControl::getBatteryBusVoltage(); // // BatVol
|
|
|
|
|
if (val >= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& properties)
|
|
|
|
|
{
|
|
|
|
|
char value[PROP_VALUE_MAX] = { 0 };
|
|
|
|
@ -368,11 +496,7 @@ bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& pro
|
|
|
|
|
else if (it->first == (PROP_VERSION_ABBR))
|
|
|
|
|
{
|
|
|
|
|
// FOR OSD
|
|
|
|
|
string version = std::to_string(mVersionCode / 100000);
|
|
|
|
|
version += ".";
|
|
|
|
|
version += std::to_string((mVersionCode % 100000) / 1000);
|
|
|
|
|
version += ".";
|
|
|
|
|
version += std::to_string(mVersionCode % 1000);
|
|
|
|
|
string version = GetVersion();
|
|
|
|
|
#if 0
|
|
|
|
|
version += " " + FormatLocalTime(mBuildTime);
|
|
|
|
|
#endif
|
|
|
|
@ -481,17 +605,7 @@ bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& pro
|
|
|
|
|
}
|
|
|
|
|
else if (it->first == (PROP_BATTERY_BUS_VOL) || it->first == (PROP_BATTERY_VOLTAGE))
|
|
|
|
|
{
|
|
|
|
|
int val = -1; // // BatVol
|
|
|
|
|
for (int idx = 0; idx < DEFAULT_BATTERY_QUERY_RETRIES; idx++)
|
|
|
|
|
{
|
|
|
|
|
val = GpioControl::getBatteryBusVoltage(); // // BatVol
|
|
|
|
|
if (val >= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int val = QueryBatteryVoltage(DEFAULT_BATTERY_QUERY_RETRIES); // // BatVol
|
|
|
|
|
if (val > 0)
|
|
|
|
|
{
|
|
|
|
|
bv = val;
|
|
|
|
@ -529,15 +643,7 @@ bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& pro
|
|
|
|
|
{
|
|
|
|
|
if (bv == -1)
|
|
|
|
|
{
|
|
|
|
|
for (int idx = 0; idx < DEFAULT_BATTERY_QUERY_RETRIES; idx++)
|
|
|
|
|
{
|
|
|
|
|
bv = GpioControl::getBatteryBusVoltage(); // // BatVol
|
|
|
|
|
if (bv >= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
}
|
|
|
|
|
bv = QueryBatteryVoltage(DEFAULT_BATTERY_QUERY_RETRIES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bv > 0)
|
|
|
|
@ -1498,6 +1604,18 @@ std::string CPhoneDevice::GetFileName() const
|
|
|
|
|
return mPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string CPhoneDevice::GetVersion() const
|
|
|
|
|
{
|
|
|
|
|
// FOR OSD
|
|
|
|
|
string version = std::to_string(mVersionCode / 100000);
|
|
|
|
|
version += ".";
|
|
|
|
|
version += std::to_string((mVersionCode % 100000) / 1000);
|
|
|
|
|
version += ".";
|
|
|
|
|
version += std::to_string(mVersionCode % 1000);
|
|
|
|
|
|
|
|
|
|
return version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPhoneDevice::UpdatePosition(double lon, double lat, double radius, time_t ts)
|
|
|
|
|
{
|
|
|
|
|
if (m_listener != NULL)
|
|
|
|
|