jxjajs 7 months ago
commit 1728e08f7a

@ -5,7 +5,7 @@ plugins {
// 10,00,000 major-minor-build
def AppMajorVersion = 1
def AppMinorVersion = 1
def AppBuildNumber = 5
def AppBuildNumber = 9
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber

@ -39,6 +39,7 @@ add_definitions(-DUSING_NRSEC_VPN)
# add_definitions(-DOUTPUT_CAMERA_DBG_INFO)
add_definitions(-DALIGN_HB_TIMER_TO_PHOTO)
add_definitions(-DENABLE_3V3_ALWAYS)
add_definitions(-DCURL_STATICLIB)
add_definitions(-DUSING_HDRPLUS)
add_definitions(-DUSING_EXEC_HDRP=1)
@ -390,6 +391,8 @@ add_library( # Sets the name of the library.
ncnn/yolov5ncnn.cpp
netcamera/httpclient.cpp
#serial/WeatherComm.cpp
# camera2/OpenCVFont.cpp
@ -468,7 +471,7 @@ target_link_libraries( # Specifies the target library.
# included in the NDK.
${log-lib}
android camera2ndk mediandk z
android camera2ndk mediandk z curl
ncnn ${OpenCV_LIBS} sqlite3 ${HDRPLUS_LIBS_EMBED}

@ -371,7 +371,7 @@ namespace cv {
delete userData;
#if defined(USING_HB)
hb_buffer_destroy(hb_buffer);
#endif 0
#endif // 0
}
// https://freetype.org/freetype2/docs/tutorial/example2.cpp
@ -630,7 +630,7 @@ namespace cv {
#if defined(USING_HB)
hb_buffer_destroy(hb_buffer);
#endif 0
#endif // 0
}
Size FreeType2Impl::getTextSize(

@ -20,47 +20,26 @@
#define IOT_PARAM_WRITE 0xAE
#define IOT_PARAM_READ 0xAF
#define MAX_STRING_LEN 32
typedef struct
{
int cmd;
int value;
int result;
long value2;
char str[MAX_STRING_LEN];
}IOT_PARAM;
std::mutex GpioControl::m_locker;
std::vector<std::pair<int, uint32_t>> GpioControl::m_references;
void GpioControl::setInt(int cmd, int value)
int GpioControl::turnOnImpl(const IOT_PARAM& param)
{
int fd = -1;
IOT_PARAM param = { cmd, value, 0 };
// param.cmd = cmd;
// param.value = value;
int res = 0;
uint32_t references = (value != 0) ? 1 : 0;
uint32_t references = 1;
std::vector<std::pair<int, uint32_t> >::iterator it;
int res = 0;
int fd = -1;
if (value)
{
m_locker.lock();
fd = open(GPIO_NODE_MP, O_RDONLY);
if( fd > 0 )
{
res = ioctl(fd, IOT_PARAM_WRITE, &param);
#ifdef _DEBUG
ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
#endif
close(fd);
// check res???
for (it = m_references.begin(); it != m_references.end(); ++it)
{
if (it->first == cmd)
if (it->first == param.cmd)
{
it->second++;
references = it->second;
@ -69,17 +48,23 @@ void GpioControl::setInt(int cmd, int value)
}
if (it == m_references.end())
{
m_references.push_back(std::pair<int, uint32_t >(cmd, references));
m_references.push_back(std::pair<int, uint32_t >(param.cmd, references));
}
}
m_locker.unlock();
return references;
}
else
int GpioControl::turnOffImpl(const IOT_PARAM& param)
{
m_locker.lock();
uint32_t references = 0;
std::vector<std::pair<int, uint32_t> >::iterator it;
int res = 0;
int fd = -1;
for (it = m_references.begin(); it != m_references.end(); ++it)
{
if (it->first == cmd)
if (it->first == param.cmd)
{
if (it->second > 0)
{
@ -93,7 +78,8 @@ void GpioControl::setInt(int cmd, int value)
if (references == 0)
{
fd = open(GPIO_NODE_MP, O_RDONLY);
if (fd > 0) {
if (fd > 0)
{
res = ioctl(fd, IOT_PARAM_WRITE, &param);
#ifdef _DEBUG
ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
@ -101,6 +87,56 @@ void GpioControl::setInt(int cmd, int value)
close(fd);
}
}
return references;
}
void GpioControl::setInt(int cmd, int value)
{
IOT_PARAM param = { cmd, value, 0 };
// param.cmd = cmd;
// param.value = value;
if (value)
{
m_locker.lock();
turnOnImpl(param);
m_locker.unlock();
}
else
{
m_locker.lock();
turnOffImpl(param);
m_locker.unlock();
}
}
void GpioControl::setInt(const std::vector<int>& cmds, int value)
{
IOT_PARAM param = { 0, value, 0 };
// param.cmd = cmd;
// param.value = value;
std::vector<int>::const_iterator it;
if (value)
{
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOnImpl(param);
}
m_locker.unlock();
}
else
{
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOffImpl(param);
}
m_locker.unlock();
}
}

@ -108,6 +108,10 @@
#define CMD_SPI2SERIAL_POWER_EN 368
#define CMD_RS485_3V3_EN 369
// Others
#define CMD_SET_485_EN_STATE 131
#define CMD_SET_OTG_STATE 107
#endif // USING_N938
@ -119,15 +123,30 @@
>>>>>>> 1b0d0f421fe8db524af9afc327dce98899a13e6d
#define GPIO_NODE_MP "/dev/mtkgpioctrl"
#define MAX_STRING_LEN 32
typedef struct
{
int cmd;
int value;
int result;
long value2;
char str[MAX_STRING_LEN];
}IOT_PARAM;
class GpioControl
{
private:
static std::mutex m_locker;
static std::vector<std::pair<int, uint32_t>> m_references;
public:
protected:
static int turnOnImpl(const IOT_PARAM& param);
static int turnOffImpl(const IOT_PARAM& param);
public:
static void setInt(int cmd, int value);
static void setInt(const std::vector<int>& cmds, int value);
static int getInt(int cmd);
static void setLong(int cmd, long value);
static long getLong(int cmd);

@ -44,6 +44,7 @@ bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
#include <Client/NrsecPort.h>
#endif
#include <curl/curl.h>
static jmethodID mRegisterTimerMid = 0;
static jmethodID mRegisterHeartbeatMid = 0;
@ -225,6 +226,8 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
env->DeleteLocalRef(clazz);
#endif
curl_global_init(CURL_GLOBAL_ALL);
return result;
}
@ -289,13 +292,6 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
NULL, true, -1);
*/
if (netHandle != NETID_UNSET) {
net_handle_t nh = (net_handle_t)netHandle;
android_setprocnetwork(nh);
}
char model[PROP_VALUE_MAX] = { 0 };
__system_property_get("ro.product.model", model);
@ -1388,3 +1384,23 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
return JNI_FALSE;
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_updateEhernet(
JNIEnv* env, jobject pThis, jlong handle, jlong networkHandle, jboolean available) {
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handle);
if (pTerminal == NULL)
{
return JNI_FALSE;
}
CPhoneDevice* device = (CPhoneDevice*)pTerminal->GetDevice();
if (device != NULL)
{
device->UpdateEthernet(static_cast<net_handle_t>(networkHandle), available != JNI_FALSE);
}
return JNI_TRUE;
}

@ -24,12 +24,15 @@
#include <sys/system_properties.h>
#include <media/NdkImage.h>
#include <mat.h>
#include <string.h>
#ifdef USING_HDRPLUS
#include <hdrplus/hdrplus_pipeline.h>
#include <hdrplus2/include/HDRPlus.h>
#endif
#include "netcamera/netcamera.h"
#include <fcntl.h>
#include <filesystem>
#include <cstdio>
@ -192,6 +195,37 @@ static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
return 0xff000000 | (nR << 16) | (nG << 8) | nB;
}
class AutoEnv
{
public:
AutoEnv(JavaVM* vm)
{
didAttachThread = false;
env = NULL;
m_vm = vm;
jboolean ret = JNI_FALSE;
bool res = GetJniEnv(m_vm, &env, didAttachThread);
if (!res)
{
ALOGE("Failed to get JNI Env");
}
}
~AutoEnv()
{
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
}
private:
JavaVM* m_vm;
JNIEnv* env;
bool didAttachThread;
};
CPhoneDevice::CPhoneCamera::CPhoneCamera(CPhoneDevice* dev, int32_t width, int32_t height, const NdkCamera::CAMERA_PARAMS& params) : NdkCamera(width, height, params), m_dev(dev)
{
}
@ -254,7 +288,6 @@ void CPhoneDevice::CPhoneCamera::onDisconnected(ACameraDevice* device)
}
}
CPhoneDevice::CJpegCamera::CJpegCamera(CPhoneDevice* dev, int32_t width, int32_t height, const std::string& path, const NdkCamera::CAMERA_PARAMS& params) : CPhoneDevice::CPhoneCamera(dev, width, height, params), m_path(path)
{
}
@ -388,7 +421,8 @@ std::mutex CPhoneDevice::m_powerLocker;
long CPhoneDevice::mCameraPowerCount = 0;
long CPhoneDevice::mOtgCount = 0;
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir) : mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir)
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir)
: mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir), m_network(NULL), m_netHandle(NETWORK_UNSPECIFIED)
{
mCamera = NULL;
m_listener = NULL;
@ -404,9 +438,15 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_signalLevel = 0;
m_signalLevelUpdateTime = time(NULL);
mBuildTime = 0;
m_cameraStatus = false;
m_sensorsStatus = false;
m_lastTime = 0;
m_shouldStopWaiting = false;
RegisterHandlerForSignal(SIGUSR2);
LoadNetworkInfo();
m_vm = vm;
JNIEnv* env = NULL;
bool didAttachThread = false;
@ -436,6 +476,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
mExecHdrplusMid = env->GetMethodID(classService, "execHdrplus", "(IILjava/lang/String;Ljava/lang/String;)I");
mSetStaticIpMid = env->GetMethodID(classService, "setStaticNetwork", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
mCallSysCameraMid = env->GetMethodID(classService, "callSystemCamera", "(IJ)V");
env->DeleteLocalRef(classService);
@ -489,6 +531,12 @@ CPhoneDevice::~CPhoneDevice()
}
m_pRecognizationCfg = NULL;
}
if (m_network != NULL)
{
delete m_network;
m_network = NULL;
}
}
void CPhoneDevice::SetListener(IListener* listener)
@ -1167,6 +1215,9 @@ bool CPhoneDevice::RegisterHandlerForSignal(int sig)
void CPhoneDevice::handleTimer(union sigval v)
{
#ifdef _DEBUG
setThreadName("bztimer");
#endif
TIMER_CONTEXT* context = (TIMER_CONTEXT*)(v.sival_ptr);
context->device->handleTimerImpl(context);
}
@ -1402,6 +1453,25 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
mPath = path;
mOsds = osds;
bool res = false;
if (photoInfo.cameraType == CAM_TYPE_USB || photoInfo.cameraType == CAM_TYPE_NET)
{
TurnOnOtg(NULL);
}
if (photoInfo.cameraType == CAM_TYPE_NET)
{
GpioControl::set12VEnable(true);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 1);
GpioControl::setInt(CMD_SET_485_EN_STATE, 1);
#endif
}
TurnOnCameraPower(NULL);
res = true;
if ((mPhotoInfo.mediaType == 0) && ((mPhotoInfo.cameraType == CAM_TYPE_MIPI) || (mPhotoInfo.cameraType == CAM_TYPE_USB)))
{
NdkCamera::CAMERA_PARAMS params;
memset(&params, 0, sizeof(params));
@ -1437,17 +1507,6 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
}
#endif
bool res = false;
if (photoInfo.usbCamera)
{
TurnOnOtg(NULL);
}
TurnOnCameraPower(NULL);
res = true;
if (mPhotoInfo.mediaType == 0 && mPhotoInfo.usingSysCamera == 0)
{
mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params);
// mCamera = new CJpegCamera(this, photoInfo.width, photoInfo.height, mPath, params);
if (mCamera->open(to_string(mPhotoInfo.cameraId)) == 0)
@ -1475,6 +1534,176 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
}
}
}
else if ((mPhotoInfo.mediaType == 0) && (mPhotoInfo.cameraType == CAM_TYPE_NET))
{
XYLOG(XYLOG_SEVERITY_INFO, "Start TP on NET Camera CH=%u PR=%X PHOTOID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.preset, mPhotoInfo.photoId);
// Start Thread
CPhoneDevice* pThis = this;
vector<IDevice::OSD_INFO> osds;
osds.swap(mOsds);
IDevice::PHOTO_INFO localPhotoInfo = mPhotoInfo;
pThis->SetStaticIp();
std::thread t([localPhotoInfo, path, pThis, osds]() mutable
{
// AutoEnv autoEnv(pThis->m_vm);
std::this_thread::sleep_for(std::chrono::milliseconds(10240));
net_handle_t netHandle = pThis->GetNetHandle();
if (netHandle == 0)
{
// Wait about 10s
for (int idx = 0; idx < 84; idx++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(128));
netHandle = pThis->GetNetHandle();
if (netHandle != 0)
{
break;
}
}
}
if (netHandle == 0)
{
// timeout
XYLOG(XYLOG_SEVERITY_ERROR, "Ethernet not existing CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
TurnOffOtg(NULL);
GpioControl::set12VEnable(false);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
#endif
return;
}
else
{
XYLOG(XYLOG_SEVERITY_INFO, "Ethernet is Available CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
}
NET_PHOTO_INFO netPhotoInfo = { netHandle, 0 };
if (localPhotoInfo.vendor == 1)
{
// Hai Kang
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/%u/picture", (uint32_t)localPhotoInfo.channel);
}
else if (localPhotoInfo.vendor == 2)
{
// Hang Yu
strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi");
}
else if (localPhotoInfo.vendor == 3)
{
// Yu Shi
int streamSid = 0; // should put into config
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/LAPI/V1.0/Channels/%u/Media/Video/Streams/%d/Snapshot", (uint32_t)localPhotoInfo.channel, streamSid);
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.vendor, (uint32_t)localPhotoInfo.channel, (unsigned int)localPhotoInfo.preset, localPhotoInfo.photoId);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
TurnOffOtg(NULL);
GpioControl::set12VEnable(false);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
#endif
return;
}
struct in_addr addr;
addr.s_addr = localPhotoInfo.ip;
strcpy(netPhotoInfo.ip, inet_ntoa(addr));
strcpy(netPhotoInfo.outputPath, path.c_str());
if (!localPhotoInfo.userName.empty())
{
size_t len = std::min<size_t>(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size());
strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len);
}
if (!localPhotoInfo.password.empty())
{
size_t len = std::min<size_t>(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size());
strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len);
}
// strcpy(netPhotoInfo.interface, "eth0");
std::vector<uint8_t> img;
bool netCaptureResult = false;
for (int idx = 0; idx < 3; idx++)
{
netHandle = pThis->GetNetHandle();
netPhotoInfo.netHandle = netHandle;
XYLOG(XYLOG_SEVERITY_INFO, "NetCapture %d NetHandle=%lld PHOTOID=%u", idx, netHandle, localPhotoInfo.photoId);
netCaptureResult = requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img);
if (netCaptureResult)
{
break;
}
}
TurnOffOtg(NULL);
GpioControl::set12VEnable(false);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
#endif
if (netCaptureResult)
{
time_t takingTime = time(NULL);
if (localPhotoInfo.remedy != 0)
{
if ((takingTime - localPhotoInfo.scheduleTime) > 30)
{
takingTime = localPhotoInfo.scheduleTime + localPhotoInfo.channel * 2;
}
}
localPhotoInfo.photoTime = takingTime;
// Notify to take next photo
pThis->TakePhotoCb(1, localPhotoInfo, "", takingTime);
cv::Mat rgb = cv::imdecode(cv::Mat(img), cv::IMREAD_COLOR);
#ifdef _DEBUG
// cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb);
#endif
netCaptureResult = pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", rgb);
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Faile to TP on NET Camera CH=%u PR=%X PHOTOID=%u URL=http://%s%s", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset,
localPhotoInfo.photoId, netPhotoInfo.ip, netPhotoInfo.url);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
}
});
t.detach();
}
else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_SERIAL))
{
if (photoInfo.preset != 0 && photoInfo.preset != 0xFF)
{
CameraPhotoCmd(time(NULL), photoInfo.channel, MOVE_PRESETNO, 0, photoInfo.preset);
std::this_thread::sleep_for(std::chrono::seconds(2));
}
time_t ts = time(NULL);
if(!GetPTZSensorsStatus() && !GetCameraStatus())
{
OpenPTZSensors(120);
}
CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0);
res = TakePTZPhotoCb(3, photoInfo);
}
else if (mPhotoInfo.usingSysCamera == 1)
{
JNIEnv* env = NULL;
@ -1556,6 +1785,84 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
return res;
}
bool CPhoneDevice::OpenPTZSensors(int sec)
{
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
// std::unique_lock<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && !m_sensorsStatus)
{
m_sensorsStatus = true;
OpenSensors(MAIN_POWER_OPEN);
OpenSensors(CAMERA_SENSOR_OPEN);
}
}
if(m_sensorsStatus && !m_cameraStatus)
{
auto start = std::chrono::steady_clock::now();
while (std::chrono::steady_clock::now() - start < std::chrono::seconds(sec))
{
if (m_shouldStopWaiting.load())
{
CloseSensors(CAMERA_SENSOR_OPEN);
CloseSensors(MAIN_POWER_OPEN);
m_cameraStatus = false;
m_sensorsStatus = false;
m_shouldStopWaiting.store(false);
return false;
}
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
}
// if(m_sensorsStatus && !m_cameraStatus)
// std::this_thread::sleep_for(std::chrono::seconds(sec));
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
// std::unique_lock<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && m_sensorsStatus)
{
m_cameraStatus = true;
}
}
return m_cameraStatus;
}
bool CPhoneDevice::ClosePTZSensors()
{
if(m_sensorsStatus && !m_cameraStatus)
{
m_shouldStopWaiting.store(true);
}
else if(m_sensorsStatus && m_cameraStatus)
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
// std::unique_lock<std::mutex> lock(m_cameraLocker);
CloseSensors(CAMERA_SENSOR_OPEN);
CloseSensors(MAIN_POWER_OPEN);
m_cameraStatus = false;
m_sensorsStatus = false;
}
return true;
}
bool CPhoneDevice::GetPTZSensorsStatus()
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
return m_sensorsStatus;
}
bool CPhoneDevice::GetCameraStatus()
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
return m_cameraStatus;
}
bool CPhoneDevice::CloseCamera()
{
if (mCamera != NULL)
@ -1569,7 +1876,7 @@ bool CPhoneDevice::CloseCamera()
return true;
}
void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera, unsigned int photoId, bool turnOffOtg)
void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera, unsigned int photoId, unsigned char cameraType)
{
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: Start CloseCamera PHOTOID=%u", photoId);
// std::this_thread::sleep_for(std::chrono::milliseconds(16));
@ -1580,11 +1887,16 @@ void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera, unsigned int
}
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: Will Turn Off Power PHOTOID=%u", photoId);
if (turnOffOtg)
if (cameraType == CAM_TYPE_NET)
{
TurnOffOtg(NULL);
GpioControl::set12VEnable(false);
}
TurnOffCameraPower(NULL);
if (cameraType == CAM_TYPE_USB || cameraType == CAM_TYPE_NET)
{
GpioControl::setOtgState(false);
}
GpioControl::setCam3V3Enable(false);
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: End Turn Off Power PHOTOID=%u", photoId);
XYLOG(XYLOG_SEVERITY_DEBUG, "TP: CloseCamera PHOTOID=%u", photoId);
@ -1665,7 +1977,7 @@ bool CPhoneDevice::onOneCapture(std::shared_ptr<ACameraMetadata> characteristics
media_status_t mstatus;
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, photoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, photoInfo.photoId, photoInfo.cameraType);
m_threadClose.swap(closeThread);
if (closeThread.joinable())
{
@ -1777,7 +2089,7 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
CPhoneCamera* pCamera = mCamera;
mCamera = NULL;
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, photoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, photoInfo.photoId, photoInfo.cameraType);
m_threadClose.swap(closeThread);
if (closeThread.joinable())
{
@ -2118,7 +2430,7 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
int32_t planeCount = 0;
mstatus = AImage_getNumberOfPlanes(spImage.get(), &planeCount);
AASSERT(status == AMEDIA_OK && planeCount == 1, "Error: getNumberOfPlanes() planeCount = %d", planeCount);
AASSERT(mstatus == AMEDIA_OK && planeCount == 1, "Error: getNumberOfPlanes() planeCount = %d", planeCount);
uint8_t *planeData = NULL;
int planeDataLen = 0;
@ -2220,7 +2532,7 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
frames.clear();
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, photoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, photoInfo.photoId, mPhotoInfo.cameraType);
m_threadClose.swap(closeThread);
if (closeThread.joinable())
{
@ -2963,7 +3275,7 @@ bool CPhoneDevice::OnCaptureReady(bool photoOrVideo, bool result, cv::Mat& mat,
mCamera = NULL;
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType);
m_threadClose.swap(closeThread);
if (closeThread.joinable())
{
@ -2991,7 +3303,7 @@ bool CPhoneDevice::OnVideoReady(bool photoOrVideo, bool result, const char* path
TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, time(NULL), objs);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType);
m_threadClose.swap(closeThread);
}
else
@ -3008,7 +3320,7 @@ bool CPhoneDevice::OnVideoReady(bool photoOrVideo, bool result, const char* path
TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, time(NULL), objs);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType);
m_threadClose.swap(closeThread);
}
@ -3030,7 +3342,7 @@ void CPhoneDevice::onError(const std::string& msg)
TakePhotoCb(0, mPhotoInfo, mPath, 0);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType);
// closeThread.detach();
m_threadClose.swap(closeThread);
}
@ -3049,7 +3361,7 @@ void CPhoneDevice::onDisconnected(ACameraDevice* device)
TakePhotoCb(0, mPhotoInfo, mPath, 0);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType);
// closeThread.detach();
m_threadClose.swap(closeThread);
}
@ -3086,67 +3398,29 @@ void CPhoneDevice::UpdatePosition(double lon, double lat, double radius, time_t
void CPhoneDevice::TurnOnCameraPower(JNIEnv* env)
{
m_powerLocker.lock();
if (mCameraPowerCount == 0)
{
GpioControl::setCam3V3Enable(true);
}
mCameraPowerCount++;
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOffCameraPower(JNIEnv* env)
{
bool turnedOff = false;
m_powerLocker.lock();
if (mCameraPowerCount > 0)
{
mCameraPowerCount--;
if (mCameraPowerCount == 0)
{
GpioControl::setCam3V3Enable(false);
turnedOff = true;
}
}
m_powerLocker.unlock();
if (turnedOff)
{
XYLOG(XYLOG_SEVERITY_INFO, "CAM PWR Turned Off");
}
}
void CPhoneDevice::TurnOnOtg(JNIEnv* env)
{
m_powerLocker.lock();
if (mOtgCount == 0)
{
ALOGD("setOtgState 1");
GpioControl::setOtgState(true);
}
mOtgCount++;
GpioControl::setInt(CMD_SET_OTG_STATE, 1);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOffOtg(JNIEnv* env)
{
bool turnedOff = false;
m_powerLocker.lock();
if (mOtgCount > 0)
{
mOtgCount--;
if (mOtgCount == 0)
{
// ALOGD("setOtgState 0");
GpioControl::setOtgState(false);
turnedOff = true;
}
}
GpioControl::setInt(CMD_SET_OTG_STATE, 0);
m_powerLocker.unlock();
if (turnedOff)
{
XYLOG(XYLOG_SEVERITY_INFO, "OTG PWR Turned Off");
}
}
void CPhoneDevice::UpdateSignalLevel(int signalLevel)
@ -3160,14 +3434,65 @@ void CPhoneDevice::UpdateSimcard(const std::string& simcard)
m_simcard = simcard;
}
void CPhoneDevice::UpdateEthernet(net_handle_t nethandle, bool available)
{
m_devLocker.lock();
m_netHandle = available ? nethandle : NETWORK_UNSPECIFIED;
m_devLocker.unlock();
XYLOG(XYLOG_SEVERITY_WARNING, "NET Handle: %lld", available ? (uint64_t)nethandle : 0);
}
net_handle_t CPhoneDevice::GetNetHandle() const
{
net_handle_t nethandle = NETWORK_UNSPECIFIED;
m_devLocker.lock();
nethandle = m_netHandle;
m_devLocker.unlock();
return nethandle;
}
void CPhoneDevice::SetStaticIp(const std::string& iface, const std::string& ip, const std::string& netmask, const std::string& gateway)
{
JNIEnv* env = NULL;
jboolean ret = JNI_FALSE;
bool didAttachThread = false;
bool res = GetJniEnv(m_vm, &env, didAttachThread);
if (!res)
{
ALOGE("Failed to get JNI Env");
}
jstring jiface = env->NewStringUTF(iface.c_str());
jstring jip = env->NewStringUTF(ip.c_str());
jstring jnetmask = env->NewStringUTF(netmask.c_str());
jstring jgw = env->NewStringUTF(gateway.c_str());
env->CallVoidMethod(m_javaService, mSetStaticIpMid, jiface, jip, jnetmask, jgw);
// env->DeleteLocalRef(jgw);
// env->DeleteLocalRef(jnetmask);
// env->DeleteLocalRef(jip);
// env->DeleteLocalRef(jiface);
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
}
int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceTail, SENSOR_PARAM *sensorParam)
{
m_tempData.instantaneous_windspeed = 0xff;
m_tempData.air_temperature = 0xff;
m_tempData.instantaneous_winddirection = 0xff;
m_tempData.humidity = 0xff;
Collect_sensor_data(); //15s
Data_DEF airt;
//++等值覆冰厚度, 综合悬挂载荷, 不均衡张力差 置0
iceInfo->equal_icethickness = 0;
iceInfo->tension = 0;
iceInfo->tension_difference = 0;
iceInfo->equal_icethickness = 0xff;
iceInfo->tension = 0xff;
iceInfo->tension_difference = 0xff;
int pullno = 0;
int angleno = 0;
@ -3176,47 +3501,130 @@ int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceT
if(sensorParam[num].SensorsType == RALLY_PROTOCOL)
{
GetPullValue(num, &airt);
if(airt.AiState == 2)
iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue;
else
iceInfo->t_sensor_data[pullno].original_tension = 0xff;
pullno++;
} else if(sensorParam[num].SensorsType == SLANT_PROTOCOL)
{
GetAngleValue(num, &airt, 0);
if(airt.AiState == 2)
iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue;
else
iceInfo->t_sensor_data[angleno].deflection_angle = 0xff;
GetAngleValue(num, &airt, 1);
if(airt.AiState == 2)
iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue;
else
iceInfo->t_sensor_data[angleno].windage_yaw_angle =0xff;
angleno++;
}
}
{
std::lock_guard<std::mutex> lock(m_dataLocker);
GetWindSpeedData(&airt);
if(airt.AiState == 2)
{
iceTail->instantaneous_windspeed = airt.EuValue;
m_tempData.instantaneous_windspeed = iceTail->instantaneous_windspeed;
} else
{
iceTail->instantaneous_windspeed = m_tempData.instantaneous_windspeed;
m_tempData.instantaneous_windspeed = 0xff;
}
GetWindDirectionData(&airt);
iceTail->instantaneous_winddirection = airt.EuValue;//需求无符号整数给出浮点数
if(airt.AiState == 2)
{
iceTail->instantaneous_winddirection = airt.EuValue;
m_tempData.instantaneous_winddirection = iceTail->instantaneous_winddirection;
} else
{
iceTail->instantaneous_winddirection = m_tempData.instantaneous_winddirection;
m_tempData.instantaneous_winddirection = 0xff;
}
GetAirTempData(&airt);
if(airt.AiState == 2) {
iceTail->air_temperature = airt.EuValue;
m_tempData.air_temperature = iceTail->air_temperature;
} else
{
iceTail->air_temperature = m_tempData.air_temperature;
m_tempData.air_temperature = 0xff;
}
GetHumidityData(&airt);
iceTail->humidity = airt.EuValue;//需求无符号整数给出浮点数
return true;
if(airt.AiState == 2)
{
iceTail->humidity = airt.EuValue;
m_tempData.humidity = iceTail->humidity;
} else
{
iceTail->humidity = m_tempData.humidity;
m_tempData.humidity = 0xff;
}
}
return true;
}
int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo)
{
m_tempData.instantaneous_windspeed = 0xff;
m_tempData.air_temperature = 0xff;
m_tempData.instantaneous_winddirection = 0xff;
m_tempData.humidity = 0xff;
Collect_sensor_data(); //15s
Data_DEF airt;
GetWeatherData(&airt, 0);
weatherInfo->air_temperature = airt.EuValue;
GetWeatherData(&airt, 1);
weatherInfo->humidity = airt.EuValue;
{
std::lock_guard<std::mutex> lock(m_dataLocker);
GetWeatherData(&airt, 2);
if(airt.AiState == 2)
{
weatherInfo->avg_windspeed_10min = airt.EuValue;
weatherInfo->extreme_windspeed = airt.EuValue;
weatherInfo->standard_windspeed = airt.EuValue;
m_tempData.instantaneous_windspeed = weatherInfo->avg_windspeed_10min;
} else
{
weatherInfo->avg_windspeed_10min = m_tempData.instantaneous_windspeed;
weatherInfo->extreme_windspeed = m_tempData.instantaneous_windspeed;
weatherInfo->standard_windspeed = m_tempData.instantaneous_windspeed;
m_tempData.instantaneous_windspeed = 0xff;
}
GetWeatherData(&airt, 3);
if(airt.AiState == 2)
{
weatherInfo->avg_winddirection_10min = airt.EuValue;
m_tempData.instantaneous_winddirection = weatherInfo->avg_winddirection_10min;
} else
{
weatherInfo->avg_winddirection_10min = m_tempData.instantaneous_winddirection;
m_tempData.instantaneous_winddirection = 0xff;
}
GetWeatherData(&airt, 0);
if(airt.AiState == 2)
{
weatherInfo->air_temperature = airt.EuValue;
m_tempData.air_temperature = weatherInfo->air_temperature;
} else
{
weatherInfo->air_temperature = m_tempData.air_temperature;
m_tempData.air_temperature = 0xff;
}
GetWeatherData(&airt, 1);
if(airt.AiState == 2)
{
weatherInfo->humidity = airt.EuValue;
m_tempData.humidity = weatherInfo->humidity;
} else
{
weatherInfo->humidity = m_tempData.humidity;
m_tempData.humidity = 0xff;
}
GetWeatherData(&airt, 4);
if(airt.AiState == 2)
weatherInfo->precipitation = airt.EuValue;
@ -3226,6 +3634,8 @@ int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo)
GetWeatherData(&airt, 6);
if(airt.AiState == 2)
weatherInfo->radiation_intensity = airt.EuValue;
}
return true;
}
@ -3236,41 +3646,59 @@ bool CPhoneDevice::OpenSensors(int sensortype)
GpioControl::set12VEnable(true);
GpioControl::setCam3V3Enable(true);
GpioControl::setRS485Enable(true);
GpioControl::setInt(CMD_SET_SPI_POWER, 1);
// GpioControl::setInt(CMD_SET_485_EN_STATE, 1); // 打开RS485电源
#ifndef USING_N938
#ifndef USING_PLZ
GpioControl::setInt(CMD_SET_485_EN_STATE, 1);
#else
GpioControl::setInt(CMD_SET_485_ENABLE, 1);
#endif
#else
GpioControl::setInt(CMD_SPI2SERIAL_POWER_EN, 1);
GpioControl::setInt(CMD_RS485_3V3_EN, 1);
#endif
GpioControl::setInt(CMD_SET_SPI_POWER, 1);
}
if(sensortype == CAMERA_SENSOR_OPEN)
{
#ifndef USING_N938
#ifndef USING_PLZ
#else
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 1);
#endif
#else
GpioControl::setInt(CMD_SET_PIC1_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN4, 1);
#endif
// GpioControl::setInt(CMD_SET_CAM_3V3_EN_STATE, 1); // 打开3.3V电压
// GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 1);
#ifndef USING_N938
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 1);
#endif
}
if(sensortype == WEATHER_SENSOR_OPEN || sensortype == ICETHICK_SENSOR_OPEN)
if(sensortype == WEATHER_SENSOR_OPEN)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_WTH_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN3, 1);
#endif
}
if(sensortype == ICETHICK_SENSOR_OPEN)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_PULL_POWER, 1);
GpioControl::setInt(CMD_SET_ANGLE_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN1, 1);
GpioControl::setInt(CMD_SET_485_EN0, 1);
#endif
}
if(sensortype == OTHER_SENSOR)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_OTHER_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN2, 1);
#endif
}
return 0;
}
@ -3285,7 +3713,11 @@ bool CPhoneDevice::CloseSensors(int sensortype)
GpioControl::setRS485Enable(false);
// GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
#ifndef USING_N938
#ifndef USING_PLZ
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
#else
GpioControl::setInt(CMD_SET_485_ENABLE, 0);
#endif
#else
GpioControl::setInt(CMD_SPI2SERIAL_POWER_EN, 0);
GpioControl::setInt(CMD_RS485_3V3_EN, 0);
@ -3294,30 +3726,84 @@ bool CPhoneDevice::CloseSensors(int sensortype)
}
if(sensortype == CAMERA_SENSOR_OPEN)
{
#ifdef USING_N938
GpioControl::setInt(CMD_SET_PIC1_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN4, 0);
// GpioControl::setInt(CMD_SET_CAM_3V3_EN_STATE, 0);
#endif
#ifndef USING_N938
GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 0);
// GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 0);
#ifndef USING_PLZ
#else
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 0);
#endif
#endif
}
if(sensortype == WEATHER_SENSOR_OPEN || sensortype == ICETHICK_SENSOR_OPEN)
if(sensortype == WEATHER_SENSOR_OPEN )
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_WTH_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN3, 0);
#endif
}
if(sensortype == ICETHICK_SENSOR_OPEN)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_PULL_POWER, 0);
GpioControl::setInt(CMD_SET_ANGLE_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN1, 0);
GpioControl::setInt(CMD_SET_485_EN0, 0);
#endif
}
if(sensortype == OTHER_SENSOR)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_OTHER_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN2, 0);
#endif
}
return 0;
}
bool CPhoneDevice::LoadNetworkInfo()
{
std::vector<uint8_t> content;
if (!readFile(m_appPath + (APP_PATH_NETWORK), content) && !content.empty())
{
return false;
}
Json::CharReaderBuilder builder;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value jsonVal;
const char* doc = (const char*)&(content[0]);
std::string errMsg;
if (!reader->parse(doc, doc + content.size(), &jsonVal, &errMsg))
{
return false;
}
if (m_network == NULL)
{
m_network = new NETWORK();
}
GetJSONValue(jsonVal, "iface", m_network->iface);
GetJSONValue(jsonVal, "ip", m_network->ip);
GetJSONValue(jsonVal, "netmask", m_network->netmask);
GetJSONValue(jsonVal, "gateway", m_network->gateway);
return true;
}
void CPhoneDevice::SetStaticIp()
{
if (m_network != NULL)
{
SetStaticIp(m_network->iface, m_network->ip, m_network->netmask, m_network->gateway);
}
}

@ -27,6 +27,8 @@
#include <opencv2/opencv.hpp>
#include <android/bitmap.h>
#include <android/multinetwork.h>
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "error", __VA_ARGS__))
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "debug", __VA_ARGS__))
@ -153,6 +155,14 @@ class CPhoneDevice : public IDevice
{
public:
struct NETWORK
{
std::string iface;
std::string ip;
std::string netmask;
std::string gateway;
};
class CPhoneCamera : public NdkCamera
{
public:
@ -221,7 +231,12 @@ public:
virtual int GetIceData(ICE_INFO *iceInfo, ICE_TAIL *icetail, SENSOR_PARAM *sensorParam);
virtual bool OpenSensors(int sensortype);
virtual bool CloseSensors(int sensortype);
virtual bool OpenPTZSensors(int sec);
virtual bool ClosePTZSensors();
virtual bool GetPTZSensorsStatus();
virtual bool GetCameraStatus();
bool LoadNetworkInfo();
bool GetNextScheduleItem(uint32_t tsBasedZero, uint32_t scheduleTime, vector<uint32_t>& items);
void UpdatePosition(double lon, double lat, double radius, time_t ts);
@ -238,6 +253,9 @@ public:
mBuildTime = buildTime;
}
void UpdateSimcard(const std::string& simcard);
void UpdateEthernet(net_handle_t nethandle, bool available);
net_handle_t GetNetHandle() const;
static void TurnOnCameraPower(JNIEnv* env);
static void TurnOffCameraPower(JNIEnv* env);
@ -274,6 +292,17 @@ protected:
return false;
}
inline bool TakePTZPhotoCb(int result, const IDevice::PHOTO_INFO& photoInfo) const
{
if (m_listener != NULL)
{
std::vector<IDevice::RECOG_OBJECT> objects;
return m_listener->OnPTZPhotoTaken(result, photoInfo);
}
return false;
}
void QueryPowerInfo(std::map<std::string, std::string>& powerInfo);
std::string QueryCpuTemperature();
@ -284,7 +313,7 @@ protected:
void onError(const std::string& msg);
void onDisconnected(ACameraDevice* device);
void CloseCamera2(CPhoneCamera* camera, unsigned int photoId, bool turnOffOtg);
void CloseCamera2(CPhoneCamera* camera, unsigned int photoId, unsigned char cameraType);
static void handleSignal(int sig, siginfo_t *si, void *uc);
bool RegisterHandlerForSignal(int sig);
@ -298,9 +327,12 @@ protected:
int CallExecv(int rotation, int frontCamera, const std::string& outputPath, const std::vector<std::string>& images);
void SetStaticIp(const std::string& iface, const std::string& ip, const std::string& netmask, const std::string& gateway);
void SetStaticIp();
protected:
std::mutex m_devLocker;
mutable std::mutex m_devLocker;
JavaVM* m_vm;
jobject m_javaService;
@ -308,6 +340,9 @@ protected:
std::string m_tfCardPath;
std::string m_nativeLibraryDir;
NETWORK* m_network;
net_handle_t m_netHandle;
jmethodID mRegisterHeartbeatMid;
jmethodID mUpdateCaptureScheduleMid;
jmethodID mUpdateTimeMid;
@ -323,6 +358,7 @@ protected:
jmethodID mEnableGpsMid;
jmethodID mRequestPositionMid;
jmethodID mExecHdrplusMid;
jmethodID mSetStaticIpMid;
jmethodID mCallSysCameraMid;
@ -356,6 +392,15 @@ protected:
std::string m_simcard;
mutable std::mutex m_cameraLocker;
bool m_cameraStatus;
bool m_sensorsStatus;
time_t m_lastTime;
std::atomic<bool> m_shouldStopWaiting;
IDevice::ICE_TAIL m_tempData;
mutable std::mutex m_dataLocker;
};

@ -1,6 +1,7 @@
#include <jni.h>
#include <string>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
@ -37,7 +38,7 @@ AI_DEF slantpntmsg[6][SLANTANGLE_DATA_NUM];
static void setInt(int cmd, int value)
{
int fd = open("/dev/mtkgpioctrl", O_RDONLY);
int fd = ::open("/dev/mtkgpioctrl", O_RDONLY);
IOT_PARAM param;
param.cmd = cmd;
param.value = value;
@ -53,7 +54,7 @@ static void setInt(int cmd, int value)
int getInt(int cmd)
{
int fd = open("/dev/mtkgpioctrl", O_RDONLY);
int fd = ::open("/dev/mtkgpioctrl", O_RDONLY);
// LOGE("get_int fd=%d,cmd=%d\r\n",fd, cmd);
if (fd > 0)
{
@ -713,7 +714,7 @@ void BytestreamLOG(int commid, char* describe, u_char* buf, int len, char flag)
strncpy(szbuf, describe, strlen(describe));
for (i = 0; i < len; i++)
{
sprintf(szbuf, "%s %02X", szbuf, buf[i]);
::sprintf(szbuf, "%s %02X", szbuf, buf[i]);
}
SaveLogTofile(commid, szbuf);
switch (flag)
@ -750,7 +751,7 @@ void Gm_OpenSerialPort(int devidx)
memset(szbuf, 0, sizeof(szbuf));
if (serialport[devparam[devidx].commid].fd <= 0)
{
fd = open(devparam[devidx].pathname, O_RDWR | O_NDELAY);
fd = ::open(devparam[devidx].pathname, O_RDWR | O_NDELAY);
if (fd < 0)
{
sprintf(szbuf, "装置%d 打开串口%d失败fd=%d", devidx + 1, devparam[devidx].commid + 1, fd);

@ -2328,6 +2328,8 @@ bool NdkCamera::convertAImageToNv21(AImage* image, uint8_t** nv21, int32_t& widt
}
}
return true;
}
void NdkCamera::EnumCameraResult(ACameraMetadata* result, CAPTURE_RESULT& captureResult)

@ -0,0 +1,242 @@
#include "httpclient.h"
#include "netcamera.h"
#include <errno.h>
static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid)
{
std::vector<uint8_t>* data = (std::vector<uint8_t>*)lpVoid;
if( NULL == data || NULL == buffer )
{
return -1;
}
uint8_t* begin = (uint8_t *)buffer;
uint8_t* end = begin + size * nmemb;
data->insert(data->end(), begin, end);
return nmemb;
}
static int SockOptCallback(void *clientp, curl_socket_t curlfd, curlsocktype purpose)
{
net_handle_t netHandle = *((net_handle_t *)clientp);
int res = android_setsocknetwork(netHandle, curlfd);
if (res == -1)
{
int errcode = errno;
printf("android_setsocknetwork errno=%d", errcode);
}
return res == 0 ? CURL_SOCKOPT_OK : CURL_SOCKOPT_ERROR;
}
int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data)
{
CURLcode nRet;
std::string auth;
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, url);
if (userName != NULL && password != NULL && strlen(userName) > 0)
{
auth = userName;
auth += ":";
auth += password;
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
// DIGEST Auth
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}
if (netHandle != NETWORK_UNSPECIFIED)
{
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, SockOptCallback);
curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &netHandle);
}
//
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
// 设置回调函数的参数,获取反馈信息
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
// 接收数据时超时设置如果5秒内数据未接收完直接退出
#ifndef NDEBUG
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
#else
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
#endif
// 设置重定向次数,防止重定向次数太多
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 4);
// 连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
nRet = curl_easy_perform(curl);
if (CURLE_OK != nRet)
{
printf("GET err=%d", nRet);
}
curl_easy_cleanup(curl);
return (0 == nRet) ? 0 : 1;
}
int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data)
{
std::string auth;
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_URL, url);
if (userName != NULL && password != NULL && strlen(userName) > 0)
{
auth = userName;
auth += ":";
auth += password;
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
// DIGEST Auth
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}
if (netHandle != NETWORK_UNSPECIFIED)
{
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, SockOptCallback);
curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &netHandle);
}
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
// 设置回调函数的参数,获取反馈信息
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
// 接收数据时超时设置如果5秒内数据未接收完直接退出
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
// 设置重定向次数,防止重定向次数太多
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 4);
// 连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
CURLcode nRet = curl_easy_perform(curl);
if (CURLE_OK != nRet)
{
printf("GET err=%d", nRet);
}
curl_easy_cleanup(curl);
return (0 == nRet) ? 0 : 1;
}
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo)
{
bool res = false;
std::vector<uint8_t> data;
const char* userName = NULL;
const char* password = NULL;
if (photoInfo.authType != 0)
{
userName = photoInfo.userName;
password = photoInfo.password;
}
std::string url = "http://";
url += photoInfo.ip;
url += photoInfo.url;
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, data);
if (0 == nRet)
{
if (!data.empty())
{
FILE *fp = fopen(photoInfo.outputPath, "wb");
if (fp != NULL)
{
fwrite(&data[0], data.size(), 1, fp);
fclose(fp);
res = true;
}
}
}
return res;
}
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img)
{
bool res = false;
const char* userName = NULL;
const char* password = NULL;
if (photoInfo.authType != 0)
{
userName = photoInfo.userName;
password = photoInfo.password;
}
std::string url = "http://";
url += photoInfo.ip;
url += photoInfo.url;
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img);
return (0 == nRet);
}
namespace nc_hk
{
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img)
{
bool res = false;
const char* userName = NULL;
const char* password = NULL;
if (photoInfo.authType != 0)
{
userName = photoInfo.userName;
password = photoInfo.password;
}
std::string url = "http://";
url += photoInfo.ip;
url += photoInfo.url;
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img);
#ifdef _DEBUG
if (0 == nRet)
{
FILE *fp = fopen("/sdcard/com.xypower.mpapp/tmp/netimg.jpg", "wb");
if (fp != NULL)
{
fwrite(&img[0], img.size(), 1, fp);
fclose(fp);
}
}
#endif
return (0 == nRet);
}
}
namespace nc_ys
{
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img)
{
bool res = false;
const char* userName = NULL;
const char* password = NULL;
if (photoInfo.authType != 0)
{
userName = photoInfo.userName;
password = photoInfo.password;
}
std::string url = "http://";
url += photoInfo.ip;
url += photoInfo.url;
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img);
#ifdef _DEBUG
if (0 == nRet)
{
FILE *fp = fopen("/sdcard/com.xypower.mpapp/tmp/netimg.jpg", "wb");
if (fp != NULL)
{
fwrite(&img[0], img.size(), 1, fp);
fclose(fp);
}
}
#endif
return (0 == nRet);
}
}

@ -0,0 +1,22 @@
#include <string>
#include <vector>
#include <curl/curl.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <bits/ioctl.h>
#include <android/multinetwork.h>
#ifndef __HTTP_CLIENT__
#define __HTTP_CLIENT__
bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr);
int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data);
int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data);
#endif // __HTTP_CLIENT__

@ -0,0 +1,50 @@
#include <stdint.h>
#include <vector>
#include <android/multinetwork.h>
#ifndef __NET_CAMERA__
#define __NET_CAMERA__
struct NET_PHOTO_INFO
{
net_handle_t netHandle;
unsigned char authType; // 0, 1
unsigned char reserved[7]; // for memory alignment
char ip[24];
char userName[8];
char password[16];
char url[128];
char outputPath[128];
};
/*
struct NET_PHOTO_INFO
{
std::string ip;
std::string userName;
std::string password;
std::string interface;
std::string url;
std::string outputPath;
unsigned char authType; // 0, 1
unsigned char reserved[7]; // for memory alignment
};
*/
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo);
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img);
namespace nc_hk
{
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img);
}
namespace nc_ys
{
bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img);
}
#endif // __NET_CAMERA__

@ -25,6 +25,8 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
@ -161,6 +163,9 @@ public class MicroPhotoService extends Service {
FileOutputStream mAppRunningFile;
FileLock mAppLock;
private ConnectivityManager mConnectivityManager = null;
private ConnectivityManager.NetworkCallback mNetworkCallback = null;
private Runnable delayedSleep = new Runnable() {
@Override
public void run() {
@ -1438,6 +1443,79 @@ public class MicroPhotoService extends Service {
return exitCode;
}
public void setStaticNetwork(String iface, String ip, String netmask, String gateway)
{
if (mConnectivityManager == null || mNetworkCallback == null) {
mConnectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onLost(Network network) {
infoLog("Network Lost " + network.toString());
updateEhernet(mNativeHandle, network.getNetworkHandle(), false);
}
@Override
public void onAvailable(final Network network) {
String ip = "";
try {
NetworkInfo ni = mConnectivityManager.getNetworkInfo(network);
LinkProperties lp = mConnectivityManager.getLinkProperties(network);
if (lp != null) {
List<LinkAddress> addresses = lp.getLinkAddresses();
if (addresses != null && addresses.size() > 0) {
InetAddress inetAddress = addresses.get(0).getAddress();
if (inetAddress != null) {
ip = inetAddress.getHostAddress();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
infoLog("Network Available " + network.toString() + " IP=" + ip);
updateEhernet(mNativeHandle, network.getNetworkHandle(), true);
}
};
NetworkRequest request = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
.build();
mConnectivityManager.registerNetworkCallback(request, mNetworkCallback);
Network[] nws = mConnectivityManager.getAllNetworks();
for (Network nw : nws) {
NetworkInfo ni = mConnectivityManager.getNetworkInfo(nw);
if (ni.getType() == ConnectivityManager.TYPE_ETHERNET) {
updateEhernet(mNativeHandle, nw.getNetworkHandle(), true);
}
}
}
Intent intent = new Intent();
intent.putExtra("cmd", "setnet");
intent.putExtra("staticip", true);
intent.putExtra("iface", iface);
intent.putExtra("ip", ip);
intent.putExtra("netmask", netmask);
if (!TextUtils.isEmpty(gateway)) {
intent.putExtra("gateway", gateway);
}
// intent.putExtra("dns1", "8.8.8.8");
// intent.putExtra("dns2", "192.168.19.1");
sendBroadcast(getApplicationContext(), intent);
}
public static void sendBroadcast(Context context, Intent intent)
{
intent.setAction("com.xy.xsetting.action");
intent.setPackage("com.android.systemui");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
context.sendBroadcast(intent);
}
/*
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
// for example value of first element
@ -1458,10 +1536,12 @@ cellSignalStrengthGsm.getDbm();
protected native boolean sendHeartbeat(long handler, int signalLevel);
protected native boolean reloadConfigs(long handler);
protected native void updatePosition(long handler, double lon, double lat, double radius, long ts);
protected native boolean updateEhernet(long handler, long nativeNetworkHandle, boolean available);
protected native boolean uninit(long handler);
protected native void recordingFinished(long handler, boolean photoOrVideo, boolean result, String path, long videoId);
protected native void captureFinished(long handler, boolean photoOrVideo, boolean result, Bitmap bm, long videoId);
protected native void burstCaptureFinished(long handler, boolean result, int numberOfCaptures, String pathsJoinedByTab, boolean frontCamera, int rotation, long photoId);
public static native long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path);
public static native void releaseDeviceHandle(long deviceHandle);
public static native boolean sendExternalPhoto(long deviceHandle, String path, long photoInfo);
@ -1484,8 +1564,6 @@ cellSignalStrengthGsm.getDbm();
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;

Loading…
Cancel
Save