From e06b9178bfbb41b7d942e6d3a13ed3cbc01a4d56 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 25 Nov 2024 11:39:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E6=91=84=E5=83=8F=E5=A4=B4?= =?UTF-8?q?=E6=8B=8D=E7=85=A7=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/GPIOControl.cpp | 4 +- app/src/main/cpp/MicroPhoto.cpp | 27 +++- app/src/main/cpp/PhoneDevice.cpp | 105 ++++++++++---- app/src/main/cpp/PhoneDevice.h | 10 +- app/src/main/cpp/SensorsProtocol.cpp | 9 +- app/src/main/cpp/netcamera/httpclient.cpp | 128 ++++++++++++++---- app/src/main/cpp/netcamera/httpclient.h | 6 +- app/src/main/cpp/netcamera/netcamera.h | 19 ++- .../com/xypower/mpapp/MicroPhotoService.java | 43 +++++- 9 files changed, 270 insertions(+), 81 deletions(-) diff --git a/app/src/main/cpp/GPIOControl.cpp b/app/src/main/cpp/GPIOControl.cpp index b20d939c..f90d6838 100644 --- a/app/src/main/cpp/GPIOControl.cpp +++ b/app/src/main/cpp/GPIOControl.cpp @@ -48,7 +48,7 @@ int GpioControl::turnOnImpl(const IOT_PARAM& param) } if (it == m_references.end()) { - m_references.push_back(std::pair(cmd, references)); + m_references.push_back(std::pair(param.cmd, references)); } } @@ -111,7 +111,7 @@ void GpioControl::setInt(int cmd, int value) } } -static void GpioControl::setInt(const std::vector& cmds, int value) +void GpioControl::setInt(const std::vector& cmds, int value) { IOT_PARAM param = { 0, value, 0 }; // param.cmd = cmd; diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 74038974..114d527f 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -292,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); @@ -1390,4 +1383,24 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile( #else 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(handle); + if (pTerminal == NULL) + { + return JNI_FALSE; + } + + CPhoneDevice* device = (CPhoneDevice*)pTerminal->GetDevice(); + if (device != NULL) + { + device->UpdateEthernet(static_cast(networkHandle), available != JNI_FALSE); + } + + return JNI_TRUE; } \ No newline at end of file diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 91de8126..5ce32271 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -257,7 +257,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) { } @@ -391,7 +390,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), m_network(NULL) +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; @@ -1418,17 +1418,6 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< mPath = path; mOsds = osds; -#ifdef USING_N938 - if (photoInfo.mediaType == 0) { - // CameraPhotoCmd(time(NULL), channel, MOVE_PRESETNO, 0, type); - // std::this_thread::sleep_for(std::chrono::seconds(2)); - time_t ts = time(NULL); - CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0); - TakePTZPhotoCb(3, photoInfo); - } - return true; -#else - bool res = false; if (photoInfo.cameraType == CAM_TYPE_USB || photoInfo.cameraType == CAM_TYPE_NET) @@ -1519,18 +1508,64 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< { pThis->SetStaticIp(); - std::this_thread::sleep_for(std::chrono::milliseconds(128)); + 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; + } + } + } - NET_PHOTO_INFO netPhotoInfo = { 0 }; + if (netHandle == 0) + { + // timeout + XYLOG(XYLOG_SEVERITY_ERROR, "Ethernet not existing CH=%u PR=%X PHOTOID=%u", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.preset, photoInfo.photoId); + pThis->TakePhotoCb(0, localPhotoInfo, "", 0); + return; + } + + 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)photoInfo.channel, (unsigned int)photoInfo.preset, photoInfo.photoId); + pThis->TakePhotoCb(0, localPhotoInfo, "", 0); + return; + } struct in_addr addr; addr.s_addr = localPhotoInfo.ip; strcpy(netPhotoInfo.ip, inet_ntoa(addr)); - strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi"); strcpy(netPhotoInfo.outputPath, path.c_str()); + // strcpy(netPhotoInfo.interface, "eth0"); + std::vector img; - bool res = nc_hy::requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img); + bool res = requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img); if (res) { @@ -1552,7 +1587,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< cv::Mat rgb = cv::imdecode(cv::Mat(img), cv::IMREAD_COLOR); #ifdef _DEBUG - cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb); + // cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb); #endif res = pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", rgb); @@ -1567,7 +1602,13 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< } else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_SERIAL)) { - + // if (photoInfo.mediaType == 0) { + // CameraPhotoCmd(time(NULL), channel, MOVE_PRESETNO, 0, type); + // std::this_thread::sleep_for(std::chrono::seconds(2)); + time_t ts = time(NULL); + CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0); + TakePTZPhotoCb(3, photoInfo); + res = true; } else if (mPhotoInfo.usingSysCamera == 1) { @@ -1648,7 +1689,6 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< } return res; -#endif } bool CPhoneDevice::CloseCamera() @@ -3260,6 +3300,23 @@ 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(); +} + +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; @@ -3276,10 +3333,10 @@ void CPhoneDevice::SetStaticIp(const std::string& iface, const std::string& ip, 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); + // env->DeleteLocalRef(jgw); + // env->DeleteLocalRef(jnetmask); + // env->DeleteLocalRef(jip); + // env->DeleteLocalRef(jiface); if (didAttachThread) { diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 9b938b9e..a05da140 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -27,6 +27,8 @@ #include #include +#include + #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "error", __VA_ARGS__)) #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "debug", __VA_ARGS__)) @@ -248,6 +250,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); @@ -324,7 +329,7 @@ protected: protected: - std::mutex m_devLocker; + mutable std::mutex m_devLocker; JavaVM* m_vm; jobject m_javaService; @@ -332,7 +337,8 @@ protected: std::string m_tfCardPath; std::string m_nativeLibraryDir; - NETWORK* m_network; + NETWORK* m_network; + net_handle_t m_netHandle; jmethodID mRegisterHeartbeatMid; jmethodID mUpdateCaptureScheduleMid; diff --git a/app/src/main/cpp/SensorsProtocol.cpp b/app/src/main/cpp/SensorsProtocol.cpp index 63297bb7..9b2eac68 100644 --- a/app/src/main/cpp/SensorsProtocol.cpp +++ b/app/src/main/cpp/SensorsProtocol.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/app/src/main/cpp/netcamera/httpclient.cpp b/app/src/main/cpp/netcamera/httpclient.cpp index 30410b1b..1d2deaef 100644 --- a/app/src/main/cpp/netcamera/httpclient.cpp +++ b/app/src/main/cpp/netcamera/httpclient.cpp @@ -1,6 +1,8 @@ #include "httpclient.h" #include "netcamera.h" +#include + static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid) { std::vector* data = (std::vector*)lpVoid; @@ -14,8 +16,20 @@ static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid) return nmemb; } +static int SockOptCallback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) +{ + net_handle_t netHandle = *((net_handle_t *)clientp); -int DoGetRequest(const char* url, const char* userName, const char* password, const char* interface, std::vector& data) + 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& data) { CURLcode nRet; std::string auth; @@ -33,7 +47,13 @@ int DoGetRequest(const char* url, const char* userName, const char* password, co 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); @@ -48,10 +68,6 @@ int DoGetRequest(const char* url, const char* userName, const char* password, co // 连接超时,这个数值如果设置太短可能导致数据请求不到就断开了 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); - if (interface != NULL && strlen(interface) > 0) - { - curl_easy_setopt(curl, CURLOPT_INTERFACE , interface); - } nRet = curl_easy_perform(curl); if (CURLE_OK != nRet) { @@ -62,7 +78,7 @@ int DoGetRequest(const char* url, const char* userName, const char* password, co return (0 == nRet) ? 0 : 1; } -int DoPutRequest(const char* url, const char* userName, const char* password, const char* interface, const char* contents, std::vector& data) +int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data) { std::string auth; @@ -78,7 +94,13 @@ int DoPutRequest(const char* url, const char* userName, const char* password, co // 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); @@ -89,10 +111,6 @@ int DoPutRequest(const char* url, const char* userName, const char* password, co // 连接超时,这个数值如果设置太短可能导致数据请求不到就断开了 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); - if (interface != NULL && strlen(interface) > 0) - { - curl_easy_setopt(curl, CURLOPT_INTERFACE , interface); - } CURLcode nRet = curl_easy_perform(curl); if (CURLE_OK != nRet) { @@ -103,12 +121,64 @@ int DoPutRequest(const char* url, const char* userName, const char* password, co return (0 == nRet) ? 0 : 1; } -namespace nc_hy +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) + bool res = false; + std::vector 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& 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& img) { bool res = false; - std::vector data; const char* userName = NULL; const char* password = NULL; if (photoInfo.authType != 0) @@ -116,30 +186,30 @@ namespace nc_hy userName = photoInfo.userName; password = photoInfo.password; } - const char* interface = photoInfo.interface; std::string url = "http://"; url += photoInfo.ip; url += photoInfo.url; - int nRet = DoGetRequest(url.c_str(), userName, password, interface, data); + int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img); +#ifdef _DEBUG if (0 == nRet) { - if (!data.empty()) + FILE *fp = fopen("/sdcard/com.xypower.mpapp/tmp/netimg.jpg", "wb"); + if (fp != NULL) { - FILE *fp = fopen(photoInfo.outputPath, "wb"); - if (fp != NULL) - { - fwrite(&data[0], data.size(), 1, fp); - fclose(fp); - res = true; - } + fwrite(&img[0], img.size(), 1, fp); + fclose(fp); } } - - return res; +#endif + return (0 == nRet); } +} + +namespace nc_ys +{ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector& img) { bool res = false; @@ -155,7 +225,7 @@ namespace nc_hy url += photoInfo.ip; url += photoInfo.url; - int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.interface, img); + int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img); #ifdef _DEBUG if (0 == nRet) { @@ -169,4 +239,4 @@ namespace nc_hy #endif return (0 == nRet); } -} +} \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/httpclient.h b/app/src/main/cpp/netcamera/httpclient.h index d09d4dbf..e1cc05d9 100644 --- a/app/src/main/cpp/netcamera/httpclient.h +++ b/app/src/main/cpp/netcamera/httpclient.h @@ -9,12 +9,14 @@ #include #include +#include + #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, const char* interface, std::vector& data); -int DoPutRequest(const char* url, const char* userName, const char* password, const char* interface, const char* contents, std::vector& data); +int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector& data); +int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data); #endif // __HTTP_CLIENT__ \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/netcamera.h b/app/src/main/cpp/netcamera/netcamera.h index c15812c6..c5326734 100644 --- a/app/src/main/cpp/netcamera/netcamera.h +++ b/app/src/main/cpp/netcamera/netcamera.h @@ -1,5 +1,6 @@ #include #include +#include #ifndef __NET_CAMERA__ #define __NET_CAMERA__ @@ -7,14 +8,14 @@ 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 interface[16]; char url[128]; char outputPath[128]; - unsigned char authType; // 0, 1 - unsigned char reserved[7]; // for memory alignment }; /* @@ -31,15 +32,19 @@ struct NET_PHOTO_INFO }; */ -namespace nc_hy + +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& img); + +namespace nc_hk { - 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& img); } -namespace nc_hk + +namespace nc_ys { - bool requestCapture(uint8_t channel); + bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector& img); } #endif // __NET_CAMERA__ \ No newline at end of file diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index d0c66e33..386f3c68 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -161,6 +161,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() { @@ -1440,6 +1443,38 @@ public class MicroPhotoService extends Service { 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) { + Log.d(TAG, "Network Lost " + network.toString()); + updateEhernet(mNativeHandle, network.getNetworkHandle(), false); + } + @Override + public void onAvailable(final Network network) { + Log.d(TAG, "Network Available " + network.toString()); + 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); @@ -1449,8 +1484,8 @@ public class MicroPhotoService extends Service { if (!TextUtils.isEmpty(gateway)) { intent.putExtra("gateway", gateway); } - // nn.putExtra("dns1", "8.8.8.8"); - // nn.putExtra("dns2", "192.168.1.1"); + // intent.putExtra("dns1", "8.8.8.8"); + // intent.putExtra("dns2", "192.168.19.1"); sendBroadcast(getApplicationContext(), intent); } @@ -1482,10 +1517,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); @@ -1508,8 +1545,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;