网络摄像头拍照的实现

hdrplus
Matthew 7 months ago
parent 83dfd4fb7c
commit e06b9178bf

@ -48,7 +48,7 @@ int GpioControl::turnOnImpl(const IOT_PARAM& param)
} }
if (it == m_references.end()) 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));
} }
} }
@ -111,7 +111,7 @@ void GpioControl::setInt(int cmd, int value)
} }
} }
static void GpioControl::setInt(const std::vector<int>& cmds, int value) void GpioControl::setInt(const std::vector<int>& cmds, int value)
{ {
IOT_PARAM param = { 0, value, 0 }; IOT_PARAM param = { 0, value, 0 };
// param.cmd = cmd; // param.cmd = cmd;

@ -292,13 +292,6 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
NULL, true, -1); NULL, true, -1);
*/ */
if (netHandle != NETID_UNSET) {
net_handle_t nh = (net_handle_t)netHandle;
android_setprocnetwork(nh);
}
char model[PROP_VALUE_MAX] = { 0 }; char model[PROP_VALUE_MAX] = { 0 };
__system_property_get("ro.product.model", model); __system_property_get("ro.product.model", model);
@ -1391,3 +1384,23 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
return JNI_FALSE; return JNI_FALSE;
#endif #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;
}

@ -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) 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::mCameraPowerCount = 0;
long CPhoneDevice::mOtgCount = 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; mCamera = NULL;
m_listener = NULL; m_listener = NULL;
@ -1418,17 +1418,6 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
mPath = path; mPath = path;
mOsds = osds; 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; bool res = false;
if (photoInfo.cameraType == CAM_TYPE_USB || photoInfo.cameraType == CAM_TYPE_NET) 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(); pThis->SetStaticIp();
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)); std::this_thread::sleep_for(std::chrono::milliseconds(128));
netHandle = pThis->GetNetHandle();
NET_PHOTO_INFO netPhotoInfo = { 0 }; if (netHandle != 0)
{
break;
}
}
}
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; struct in_addr addr;
addr.s_addr = localPhotoInfo.ip; addr.s_addr = localPhotoInfo.ip;
strcpy(netPhotoInfo.ip, inet_ntoa(addr)); strcpy(netPhotoInfo.ip, inet_ntoa(addr));
strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi");
strcpy(netPhotoInfo.outputPath, path.c_str()); strcpy(netPhotoInfo.outputPath, path.c_str());
// strcpy(netPhotoInfo.interface, "eth0");
std::vector<uint8_t> img; std::vector<uint8_t> img;
bool res = nc_hy::requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img); bool res = requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img);
if (res) 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); cv::Mat rgb = cv::imdecode(cv::Mat(img), cv::IMREAD_COLOR);
#ifdef _DEBUG #ifdef _DEBUG
cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb); // cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb);
#endif #endif
res = pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", rgb); 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)) 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) else if (mPhotoInfo.usingSysCamera == 1)
{ {
@ -1648,7 +1689,6 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
} }
return res; return res;
#endif
} }
bool CPhoneDevice::CloseCamera() bool CPhoneDevice::CloseCamera()
@ -3260,6 +3300,23 @@ void CPhoneDevice::UpdateSimcard(const std::string& simcard)
m_simcard = 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) void CPhoneDevice::SetStaticIp(const std::string& iface, const std::string& ip, const std::string& netmask, const std::string& gateway)
{ {
JNIEnv* env = NULL; 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 jnetmask = env->NewStringUTF(netmask.c_str());
jstring jgw = env->NewStringUTF(gateway.c_str()); jstring jgw = env->NewStringUTF(gateway.c_str());
env->CallVoidMethod(m_javaService, mSetStaticIpMid, jiface, jip, jnetmask, jgw); env->CallVoidMethod(m_javaService, mSetStaticIpMid, jiface, jip, jnetmask, jgw);
env->DeleteLocalRef(jgw); // env->DeleteLocalRef(jgw);
env->DeleteLocalRef(jnetmask); // env->DeleteLocalRef(jnetmask);
env->DeleteLocalRef(jip); // env->DeleteLocalRef(jip);
env->DeleteLocalRef(jiface); // env->DeleteLocalRef(jiface);
if (didAttachThread) if (didAttachThread)
{ {

@ -27,6 +27,8 @@
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <android/bitmap.h> #include <android/bitmap.h>
#include <android/multinetwork.h>
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "error", __VA_ARGS__)) #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "error", __VA_ARGS__))
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "debug", __VA_ARGS__)) #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "debug", __VA_ARGS__))
@ -248,6 +250,9 @@ public:
mBuildTime = buildTime; mBuildTime = buildTime;
} }
void UpdateSimcard(const std::string& simcard); 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 TurnOnCameraPower(JNIEnv* env);
static void TurnOffCameraPower(JNIEnv* env); static void TurnOffCameraPower(JNIEnv* env);
@ -324,7 +329,7 @@ protected:
protected: protected:
std::mutex m_devLocker; mutable std::mutex m_devLocker;
JavaVM* m_vm; JavaVM* m_vm;
jobject m_javaService; jobject m_javaService;
@ -333,6 +338,7 @@ protected:
std::string m_nativeLibraryDir; std::string m_nativeLibraryDir;
NETWORK* m_network; NETWORK* m_network;
net_handle_t m_netHandle;
jmethodID mRegisterHeartbeatMid; jmethodID mRegisterHeartbeatMid;
jmethodID mUpdateCaptureScheduleMid; jmethodID mUpdateCaptureScheduleMid;

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

@ -1,6 +1,8 @@
#include "httpclient.h" #include "httpclient.h"
#include "netcamera.h" #include "netcamera.h"
#include <errno.h>
static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid) static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid)
{ {
std::vector<uint8_t>* data = (std::vector<uint8_t>*)lpVoid; std::vector<uint8_t>* data = (std::vector<uint8_t>*)lpVoid;
@ -14,8 +16,20 @@ static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid)
return nmemb; 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<uint8_t>& 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<uint8_t>& data)
{ {
CURLcode nRet; CURLcode nRet;
std::string auth; 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); 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_WRITEFUNCTION, OnWriteData);
// 设置回调函数的参数,获取反馈信息 // 设置回调函数的参数,获取反馈信息
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data); 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); 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); nRet = curl_easy_perform(curl);
if (CURLE_OK != nRet) 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; return (0 == nRet) ? 0 : 1;
} }
int DoPutRequest(const char* url, const char* userName, const char* password, const char* interface, const char* contents, 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)
{ {
std::string auth; std::string auth;
@ -78,7 +94,13 @@ int DoPutRequest(const char* url, const char* userName, const char* password, co
// DIGEST Auth // DIGEST Auth
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 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_WRITEFUNCTION, OnWriteData);
// 设置回调函数的参数,获取反馈信息 // 设置回调函数的参数,获取反馈信息
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data); 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); 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); CURLcode nRet = curl_easy_perform(curl);
if (CURLE_OK != nRet) if (CURLE_OK != nRet)
{ {
@ -103,10 +121,8 @@ int DoPutRequest(const char* url, const char* userName, const char* password, co
return (0 == nRet) ? 0 : 1; 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; bool res = false;
std::vector<uint8_t> data; std::vector<uint8_t> data;
const char* userName = NULL; const char* userName = NULL;
@ -116,13 +132,12 @@ namespace nc_hy
userName = photoInfo.userName; userName = photoInfo.userName;
password = photoInfo.password; password = photoInfo.password;
} }
const char* interface = photoInfo.interface;
std::string url = "http://"; std::string url = "http://";
url += photoInfo.ip; url += photoInfo.ip;
url += photoInfo.url; url += photoInfo.url;
int nRet = DoGetRequest(url.c_str(), userName, password, interface, data); int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, data);
if (0 == nRet) if (0 == nRet)
{ {
if (!data.empty()) if (!data.empty())
@ -138,8 +153,63 @@ namespace nc_hy
} }
return res; 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 requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photoInfo, std::vector<uint8_t>& img)
{ {
bool res = false; bool res = false;
@ -155,7 +225,7 @@ namespace nc_hy
url += photoInfo.ip; url += photoInfo.ip;
url += photoInfo.url; 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 #ifdef _DEBUG
if (0 == nRet) if (0 == nRet)
{ {

@ -9,12 +9,14 @@
#include <net/if.h> #include <net/if.h>
#include <bits/ioctl.h> #include <bits/ioctl.h>
#include <android/multinetwork.h>
#ifndef __HTTP_CLIENT__ #ifndef __HTTP_CLIENT__
#define __HTTP_CLIENT__ #define __HTTP_CLIENT__
bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr); 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<uint8_t>& data); 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, const char* interface, const char* contents, 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__ #endif // __HTTP_CLIENT__

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

@ -161,6 +161,9 @@ public class MicroPhotoService extends Service {
FileOutputStream mAppRunningFile; FileOutputStream mAppRunningFile;
FileLock mAppLock; FileLock mAppLock;
private ConnectivityManager mConnectivityManager = null;
private ConnectivityManager.NetworkCallback mNetworkCallback = null;
private Runnable delayedSleep = new Runnable() { private Runnable delayedSleep = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1440,6 +1443,38 @@ public class MicroPhotoService extends Service {
public void setStaticNetwork(String iface, String ip, String netmask, String gateway) 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 intent = new Intent();
intent.putExtra("cmd", "setnet"); intent.putExtra("cmd", "setnet");
intent.putExtra("staticip", true); intent.putExtra("staticip", true);
@ -1449,8 +1484,8 @@ public class MicroPhotoService extends Service {
if (!TextUtils.isEmpty(gateway)) { if (!TextUtils.isEmpty(gateway)) {
intent.putExtra("gateway", gateway); intent.putExtra("gateway", gateway);
} }
// nn.putExtra("dns1", "8.8.8.8"); // intent.putExtra("dns1", "8.8.8.8");
// nn.putExtra("dns2", "192.168.1.1"); // intent.putExtra("dns2", "192.168.19.1");
sendBroadcast(getApplicationContext(), intent); sendBroadcast(getApplicationContext(), intent);
} }
@ -1482,10 +1517,12 @@ cellSignalStrengthGsm.getDbm();
protected native boolean sendHeartbeat(long handler, int signalLevel); protected native boolean sendHeartbeat(long handler, int signalLevel);
protected native boolean reloadConfigs(long handler); protected native boolean reloadConfigs(long handler);
protected native void updatePosition(long handler, double lon, double lat, double radius, long ts); 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 boolean uninit(long handler);
protected native void recordingFinished(long handler, boolean photoOrVideo, boolean result, String path, long videoId); 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 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); 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 long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path);
public static native void releaseDeviceHandle(long deviceHandle); public static native void releaseDeviceHandle(long deviceHandle);
public static native boolean sendExternalPhoto(long deviceHandle, String path, long photoInfo); 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 exportPublicKeyFile(int index, String outputPath);
public static native boolean exportPrivateFile(int index, String outputPath); public static native boolean exportPrivateFile(int index, String outputPath);
////////////////////////GPS//////////////////// ////////////////////////GPS////////////////////
// private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER; // private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
private LocationManager mLocationManager; private LocationManager mLocationManager;

Loading…
Cancel
Save