diff --git a/app/build.gradle b/app/build.gradle index 76089345..0549a4c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 1 -def AppBuildNumber = 20 +def AppBuildNumber = 41 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber @@ -86,12 +86,14 @@ android { variant.outputs.all { output -> if (outputFileName.endsWith('.apk')) { def buildTypeFlag = "dbg" + def prevFileName = "mpapp" if(variant.buildType.name.equals('release')) { buildTypeFlag = "rel" } def abi = output.getFilter(com.android.build.OutputFile.ABI) if (abi == null) abi = "all" - def fileName = "mpapp_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}_${abi}.apk" + if (abi.contains("v7a")) prevFileName = "N938" + def fileName = "${prevFileName}_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}_${abi}.apk" outputFileName = fileName } } diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index cb99ef6f..736422ad 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -47,7 +47,7 @@ add_definitions(-DUSING_EXEC_HDRP=1) set(USING_EXEC_HDRP 1) -add_definitions(-DUSING_PLZ) +# add_definitions(-DUSING_PLZ) if(ANDROID_ABI STREQUAL "armeabi-v7a") add_definitions(-DUSING_N938) diff --git a/app/src/main/cpp/GPIOControl.cpp b/app/src/main/cpp/GPIOControl.cpp index e17bd754..5e9f1893 100644 --- a/app/src/main/cpp/GPIOControl.cpp +++ b/app/src/main/cpp/GPIOControl.cpp @@ -27,6 +27,7 @@ CSemaphore GpioControl::m_semaphore; std::vector GpioControl::m_items; std::thread GpioControl::m_thread; bool GpioControl::m_exitSignal = false; +bool GpioControl::m_cameraPowerStatus = false; size_t GpioControl::turnOnImpl(const IOT_PARAM& param) { @@ -48,6 +49,7 @@ size_t GpioControl::turnOnImpl(const IOT_PARAM& param) it->references++; it->closeTime = 0; references = it->references; + SetCamerastatus(it->cmd, true); break; } } @@ -198,6 +200,30 @@ size_t GpioControl::TurnOn(const std::vector& cmds) return 0; } +size_t GpioControl::TurnOffImmediately(int cmd) +{ + time_t ts = time(NULL); + size_t ref = 0; + std::vector::iterator it; + m_locker.lock(); + for (it = m_items.begin(); it != m_items.end(); ++it) + { + if (it->cmd == cmd) + { + ref = it->references; + it->closeCmds++; + it->closeTime = ts; + break; + } + } + m_locker.unlock(); + m_semaphore.release(); +#ifdef _DEBUG + ALOGI("PWR TurnOffNow cmd=%d ref=%u", cmd, (uint32_t)ref); +#endif + return 0; +} + size_t GpioControl::TurnOff(int cmd, uint32_t delayedCloseTime/* = 0*/) { time_t ts = 0; @@ -274,6 +300,7 @@ size_t GpioControl::TurnOff(const std::vector >& cmds) { if (it->cmd == itCmd->first) { + it->closeCmds++; if (itCmd->second != 0) { @@ -292,6 +319,22 @@ size_t GpioControl::TurnOff(const std::vector >& cmds) return 0; } +bool GpioControl::SetCamerastatus(int cmd, bool status) +{ +#ifdef USING_N938 + if(cmd == CMD_SET_PIC1_POWER) + m_cameraPowerStatus = status; +#endif +#ifdef USING_PLZ + if(cmd == CMD_SET_PTZ_PWR_ENABLE) + m_cameraPowerStatus = status; +#endif + return true; +} +bool GpioControl::GetCamerastatus() +{ + return m_cameraPowerStatus; +} void GpioControl::PowerControlThreadProc() { @@ -302,6 +345,7 @@ void GpioControl::PowerControlThreadProc() time_t delayTime = 0; int fd = -1; int res = -1; + m_cameraPowerStatus = 0; while(1) { @@ -330,6 +374,8 @@ void GpioControl::PowerControlThreadProc() else { it->references -= it->closeCmds; + if(it->references < 0) + it->references = 0; } it->closeCmds = 0; } @@ -345,6 +391,7 @@ void GpioControl::PowerControlThreadProc() #ifdef _DEBUG ALOGI("PWR TH DO TurnOff cmd=%d", it->cmd); #endif + SetCamerastatus(it->cmd, false); } else { diff --git a/app/src/main/cpp/GPIOControl.h b/app/src/main/cpp/GPIOControl.h index 8083e095..49c9d5e9 100644 --- a/app/src/main/cpp/GPIOControl.h +++ b/app/src/main/cpp/GPIOControl.h @@ -164,6 +164,7 @@ private: static std::vector m_items; static bool m_exitSignal; static std::thread m_thread; + static bool m_cameraPowerStatus; protected: static size_t turnOnImpl(const IOT_PARAM& param); @@ -177,6 +178,9 @@ public: static size_t TurnOff(int cmd, uint32_t delayedCloseTime = 0); static size_t TurnOff(const std::vector& cmds, uint32_t delayedCloseTime = 0); static size_t TurnOff(const std::vector >& cmds); + static size_t TurnOffImmediately(int cmd); + static bool SetCamerastatus(int cmd, bool status); + static bool GetCamerastatus(); static void PowerControlThreadProc(); @@ -513,7 +517,24 @@ public: PowerControl(CMD_SET_OTG_STATE, CMD_SET_NETWORK_POWER_EN, CMD_SET_PIC1_POWER, CMD_SET_485_EN_STATE, closeDelayTime) #else // USING_N938 #ifdef USING_PLZ - PowerControl(CMD_SET_PTZ_PWR_ENABLE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime) + PowerControl(CMD_SET_OTG_STATE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime) +#else // USING_PLZ + PowerControl(CMD_SET_OTG_STATE, CMD_SET_12V_EN_STATE, closeDelayTime) +#endif // USING_PLZ +#endif // USING_N938 + { + } +}; + +class PlzCameraPowerCtrl : public PowerControl +{ +public: + PlzCameraPowerCtrl(uint32_t closeDelayTime) : +#ifdef USING_N938 + PowerControl(CMD_SET_OTG_STATE, CMD_SET_NETWORK_POWER_EN, CMD_SET_PIC1_POWER, CMD_SET_485_EN_STATE, closeDelayTime) +#else // USING_N938 +#ifdef USING_PLZ + PowerControl(CMD_SET_OTG_STATE, CMD_SET_PTZ_PWR_ENABLE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime) #else // USING_PLZ PowerControl(CMD_SET_OTG_STATE, CMD_SET_12V_EN_STATE, closeDelayTime) #endif // USING_PLZ @@ -532,7 +553,24 @@ public: #ifdef USING_PLZ PowerControl(CMD_SET_PTZ_PWR_ENABLE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime) #else // USING_PLZ - PowerControl(CMD_SET_OTG_STATE, CMD_SET_12V_EN_STATE, closeDelayTime) + PowerControl(CMD_SET_OTG_STATE, CMD_SET_12V_EN_STATE, closeDelayTime) +#endif // USING_PLZ +#endif // USING_N938 + { + } +}; + +class SerialCameraPowerCtrl : public PowerControl +{ +public: + SerialCameraPowerCtrl(uint32_t closeDelayTime) : +#ifdef USING_N938 + PowerControl(CMD_SET_SPI_POWER, CMD_SPI2SERIAL_POWER_EN, CMD_RS485_3V3_EN, CMD_SET_PIC1_POWER, CMD_SET_485_EN4, closeDelayTime) +#else // USING_N938 +#ifdef USING_PLZ + PowerControl(CMD_SET_12V_EN_STATE, CMD_SET_485_ENABLE, CMD_SET_3V3_PWR_EN, CMD_SET_SPI_POWER, CMD_SET_PTZ_PWR_ENABLE, closeDelayTime) +#else // USING_PLZ + PowerControl(CMD_SET_12V_EN_STATE, CMD_SET_3V3_PWR_EN, CMD_SET_SPI_POWER, CMD_SET_485_EN_STATE, closeDelayTime) #endif // USING_PLZ #endif // USING_N938 { diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 2306bcfd..a5b03ead 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -154,9 +154,9 @@ void posix_signal_handler(int sig, siginfo_t *siginfo, void *context) class Runner { public: - static void RequestCapture(CTerminal* pTerminal, unsigned int channel, unsigned int preset, unsigned int type, unsigned long scheduleTime); + static void RequestCapture(CTerminal* pTerminal, unsigned int channel, unsigned int preset, unsigned int type, uint64_t scheduleTime); }; -void Runner::RequestCapture(CTerminal* pTerminal, unsigned int channel, unsigned int preset, unsigned int type, unsigned long scheduleTime) +void Runner::RequestCapture(CTerminal* pTerminal, unsigned int channel, unsigned int preset, unsigned int type, uint64_t scheduleTime) { pTerminal->RequestCapture(channel, preset, type, scheduleTime); } @@ -358,7 +358,7 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto( JNIEnv* env, jobject pThis, jlong handler, jint channel, jint preset, jlong scheduleTime, jboolean photoOrVideo) { - if (channel < 1 || channel > 0xFF) + if (channel < 0 || channel > 0xFFFF) { return JNI_FALSE; } @@ -369,9 +369,18 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto( } unsigned char type = photoOrVideo ? 0 : 1; - // std::thread th(&Runner::RequestCapture, pTerminal, (unsigned int)channel, (unsigned int)preset, type, (unsigned long)scheduleTime, 0, true); + // std::thread th(&Runner::RequestCapture, pTerminal, (unsigned int)channel, (unsigned int)preset, type, (uint64_t)scheduleTime, 0, true); // th.detach(); - pTerminal->RequestCapture((unsigned int)channel, (unsigned int)preset, type, (unsigned long)scheduleTime, 0, true); + if (channel < 0x100) + { + pTerminal->RequestCapture((uint32_t)channel, (unsigned int)preset, type, (uint64_t)scheduleTime, 0, true); + } + else + { + uint32_t packetType = channel; + packetType &= 0xFF; + pTerminal->RequestSampling(packetType, (uint64_t)scheduleTime, 0); + } return JNI_TRUE; } @@ -501,6 +510,7 @@ Java_com_xypower_mpapp_MicroPhotoService_uninit( return JNI_FALSE; } + XYLOG(XYLOG_SEVERITY_WARNING, "Will uninit service"); IDevice* dev = pTerminal->GetDevice(); if (dev != NULL) { @@ -559,7 +569,7 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData2( vector dataArray; dataArray.reserve(numberOfData); - unsigned long val = 0; + uint64_t val = 0; jint channel = 0; for (map>::const_iterator it = photoTime.cbegin(); it != photoTime.cend(); ++it) { @@ -576,11 +586,11 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData2( for (vector::const_iterator it2 = it->second.cbegin(); it2 != it->second.cend(); ++it2) { // time - val = ((unsigned long)((*it2) & 0xFFFFFF00)) << 24; + val = ((uint64_t)((*it2) & 0xFFFFFF00)) << 24; // channel - val |= ((unsigned long)channel) << 16; + val |= ((uint64_t)channel) << 16; // preset - val |= ((unsigned long)((*it2) & 0xFF)) << 8; + val |= ((uint64_t)((*it2) & 0xFF)) << 8; dataArray.push_back((jlong)val); } @@ -612,7 +622,7 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData( unsigned int scheduleTime = 0; time_t zeroPointTime = 0; - std::vector > channelsAndPresets; + std::vector > channelsAndPresets; if (!pTerminal->GetAndRefreshLatestScheduleTime(startTime, zeroPointTime, scheduleTime, channelsAndPresets)) { return NULL; @@ -630,14 +640,14 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData( dataArray.push_back((jlong)scheduleTime); dataArray.push_back((jlong)channelsAndPresets.size()); - unsigned long val = 0; - for (std::vector >::const_iterator it = channelsAndPresets.cbegin(); it != channelsAndPresets.cend(); ++it) + uint64_t val = 0; + for (std::vector >::const_iterator it = channelsAndPresets.cbegin(); it != channelsAndPresets.cend(); ++it) { - val = (unsigned long)scheduleTime << 24; + val = (((uint64_t)scheduleTime) << 28); // channel - val |= ((unsigned long)(it->first)) << 16; + val |= (((uint64_t)(it->first)) << 12); // preset - val |= ((unsigned long)(it->second)) << 8; + val |= (((uint64_t)(it->second)) << 4); dataArray.push_back((jlong)val); } @@ -735,75 +745,6 @@ Java_com_xypower_mpapp_MicroPhotoService_recoganizePicture( return data; } - -/* -extern "C" JNIEXPORT jlongArray JNICALL -Java_com_xypower_mpapp_MicroPhotoService_getNextScheduleItem( - JNIEnv* env, - jobject pThis, jlong handler) { - - CTerminal* pTerminal = reinterpret_cast(handler); - if (pTerminal == NULL) - { - return NULL; - } - - map> photoTime; - if (!pTerminal->GetPhotoTime(photoTime) || photoTime.empty()) - { - return NULL; - } - - size_t numberOfData = photoTime.size() * photoTime.begin()->second.size(); - if (numberOfData == 0) - { - return NULL; - } - - vector dataArray; - dataArray.reserve(numberOfData); - - unsigned long val = 0; - jint channel = 0; - for (map>::const_iterator it = photoTime.cbegin(); it != photoTime.cend(); ++it) - { - if (it->second.empty()) - { - continue; - } - - channel = (jint)((unsigned short)it->first); - // dataArray.push_back(channel); - - // val = (jint)it->second.size(); - // dataArray.push_back(val); - for (vector::const_iterator it2 = it->second.cbegin(); it2 != it->second.cend(); ++it2) - { - // time - val = ((unsigned long)((*it2) & 0xFFFFFF00)) << 24; - // channel - val |= ((unsigned long)channel) << 16; - // preset - val |= ((unsigned long)((*it2) & 0xFF)) << 8; - - dataArray.push_back((jlong)val); - } - } - - std::sort(dataArray.begin(), dataArray.end()); - - jlongArray data = env->NewLongArray(dataArray.size()); - if (data == NULL) { - return NULL; - } - - env->SetLongArrayRegion(data, 0, dataArray.size(), &dataArray[0]); - - return data; -} - */ - - extern "C" JNIEXPORT void JNICALL Java_com_xypower_mpapp_MicroPhotoService_captureFinished( JNIEnv* env, @@ -821,7 +762,7 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished( if (result == JNI_FALSE || bitmap == NULL) { cv::Mat mat; - ((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId); + ((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (uint64_t)photoId); return; } AndroidBitmapInfo info = { 0 }; @@ -845,7 +786,7 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished( cv::cvtColor(mat, mat, cv::COLOR_RGB2BGR); - ((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId); + ((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (uint64_t)photoId); #endif // 0 } else { @@ -862,7 +803,7 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished( AndroidBitmap_unlockPixels(env, bitmap); - ((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (unsigned long)photoId); + ((CPhoneDevice *)dev)->OnCaptureReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, mat, (uint64_t)photoId); } } } @@ -890,7 +831,7 @@ Java_com_xypower_mpapp_MicroPhotoService_burstCaptureFinished( if (result == JNI_FALSE) { cv::Mat mat; - ((CPhoneDevice *)dev)->OnCaptureReady(true, false, mat, (unsigned long)photoId); + ((CPhoneDevice *)dev)->OnCaptureReady(true, false, mat, (uint64_t)photoId); return; } @@ -923,7 +864,7 @@ Java_com_xypower_mpapp_MicroPhotoService_recordingFinished( } // camera->Open(pathStr, fileNameStr); - unsigned long photoId = videoId; + uint64_t photoId = videoId; ((CPhoneDevice *)dev)->OnVideoReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, pathStr, photoId); if (path != NULL) { diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 99c828ae..6af7fc80 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -552,8 +552,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa } m_timerUidFeed = time(NULL) * 1000; - m_wakelockIdFeed = (unsigned long)m_timerUidFeed; - m_uniqueIdFeed = (unsigned long)m_timerUidFeed; + m_wakelockIdFeed = (uint64_t)m_timerUidFeed; + m_uniqueIdFeed = (uint64_t)m_timerUidFeed; #ifdef USING_NRSEC GpioControl::setCam3V3Enable(true); @@ -831,7 +831,7 @@ bool CPhoneDevice::UpdateSchedules() { ALOGE("Failed to get JNI Env"); } - time_t ts = time(NULL); + jlong ts = time(NULL); ret = env->CallBooleanMethod(m_javaService, mUpdateCaptureScheduleMid, ts); if (didAttachThread) { @@ -1167,7 +1167,7 @@ void CPhoneDevice::RestartApp(int resetType, long timeout, const std::string& re { jreason = env->NewStringUTF(reason.c_str()); } - env->CallVoidMethod(m_javaService, mRebootMid, resetType, timeout, jreason); + env->CallVoidMethod(m_javaService, mRebootMid, resetType, (jlong)timeout, jreason); if (didAttachThread) { m_vm->DetachCurrentThread(); @@ -1321,7 +1321,7 @@ void CPhoneDevice::handleRebootTimer(union sigval v) // { // } -IDevice::timer_uid_t CPhoneDevice::RegisterTimer(unsigned int timerType, unsigned int timeout, void* data, unsigned long times/* = 0*/) +IDevice::timer_uid_t CPhoneDevice::RegisterTimer(unsigned int timerType, unsigned int timeout, void* data, uint64_t times/* = 0*/) { struct sigevent evp = { 0 }; struct itimerspec ts = { 0 }; @@ -1351,7 +1351,7 @@ IDevice::timer_uid_t CPhoneDevice::RegisterTimer(unsigned int timerType, unsigne return INVALID_TIMER_UID; } - context->uid = (unsigned long)timer; + context->uid = (uint64_t)timer; ts.it_value.tv_sec = (timeout / 1000); ts.it_value.tv_nsec = (timeout % 1000) * 1000; if (times != 1) @@ -1393,9 +1393,9 @@ bool CPhoneDevice::UnregisterTimer(IDevice::timer_uid_t uid) return false; } -unsigned long CPhoneDevice::RequestWakelock(unsigned long timeout) +uint64_t CPhoneDevice::RequestWakelock(uint64_t timeout) { - unsigned long wakelockId = m_wakelockIdFeed.fetch_add(1); + uint64_t wakelockId = m_wakelockIdFeed.fetch_add(1); std::string name = WAKELOCK_NAME; name += to_string(wakelockId); @@ -1425,7 +1425,7 @@ unsigned long CPhoneDevice::RequestWakelock(unsigned long timeout) return wakelockId; } -bool CPhoneDevice::ReleaseWakelock(unsigned long wakelock) +bool CPhoneDevice::ReleaseWakelock(uint64_t wakelock) { // ALOGI("ReleaseWakelock=%lld", wakelock); std::string name = WAKELOCK_NAME; @@ -1482,6 +1482,147 @@ IDevice::timer_uid_t CPhoneDevice::RegisterHeartbeat(unsigned int timerType, uns return uid; } +bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector& osds, std::shared_ptr powerCtrlPtr) +{ + // AutoEnv autoEnv(pThis->m_vm); + time_t ts = time(NULL); + uint32_t waitTime = localPhotoInfo.selfTestingTime; + waitTime = (waitTime!= 0) ? (waitTime * 1024) : 10240; + std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); + + SetStaticIp(); + std::this_thread::sleep_for(std::chrono::milliseconds(256)); + + net_handle_t netHandle = GetNetHandle(); + + if (netHandle == 0) + { + // Wait about 10s + for (int idx = 0; idx < 84; idx++) + { + std::this_thread::sleep_for(std::chrono::milliseconds(128)); + netHandle = 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); + TakePhotoCb(0, localPhotoInfo, "", 0); + return false; + } + 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 + netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; + 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 + netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; + 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 if (localPhotoInfo.vendor == 5) + { + // Hang Yu - New + netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC; + // http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080 + // http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg + // http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg + snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)localPhotoInfo.channel); + } + 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); + TakePhotoCb(0, localPhotoInfo, "", 0); + return false; + } + + 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(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size()); + strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len); + } + if (!localPhotoInfo.password.empty()) + { + size_t len = std::min(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size()); + strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len); + } + // strcpy(netPhotoInfo.interface, "eth0"); + + std::vector img; + + bool netCaptureResult = false; + for (int idx = 0; idx < 3; idx++) + { + netHandle = 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; + } + } + + if (netCaptureResult) + { + time_t takingTime = ts; + if(localPhotoInfo.scheduleTime != 0) + takingTime = localPhotoInfo.scheduleTime; + if (localPhotoInfo.remedy != 0) + { + if ((takingTime - localPhotoInfo.scheduleTime) > 30) + { + takingTime = localPhotoInfo.scheduleTime + localPhotoInfo.channel * 2; + } + } + + localPhotoInfo.photoTime = takingTime; + + // Notify to take next photo + 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 = 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); + TakePhotoCb(0, localPhotoInfo, "", 0); + } + + return true; +} + bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector& osds, const std::string& path) { if (photoInfo.width == 0 || photoInfo.height == 0) @@ -1542,7 +1683,17 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< } else if (photoInfo.cameraType == CAM_TYPE_NET) { - powerCtrlPtr = std::shared_ptr(new NetCameraPowerCtrl(mPhotoInfo.closeDelayTime)); + if(mPhotoInfo.scheduleTime == 0) + powerCtrlPtr = std::shared_ptr(new NetCameraPowerCtrl(mPhotoInfo.closeDelayTime)); + else + powerCtrlPtr = std::shared_ptr(new NetCameraPowerCtrl(2)); + } + else if (photoInfo.cameraType == CAM_TYPE_PLZ) + { + if(mPhotoInfo.scheduleTime == 0) + powerCtrlPtr = std::shared_ptr(new PlzCameraPowerCtrl(mPhotoInfo.closeDelayTime)); + else + powerCtrlPtr = std::shared_ptr(new PlzCameraPowerCtrl(2)); } res = true; @@ -1638,161 +1789,105 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< std::thread t([localPhotoInfo, path, pThis, osds, powerCtrlPtr]() mutable { - // AutoEnv autoEnv(pThis->m_vm); - uint32_t waitTime = localPhotoInfo.selfTestingTime; - waitTime = (waitTime!= 0) ? (waitTime * 1024) : 10240; - std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); - - pThis->SetStaticIp(); - std::this_thread::sleep_for(std::chrono::milliseconds(256)); - - 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); - 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); - 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(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size()); - strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len); - } - if (!localPhotoInfo.password.empty()) - { - size_t len = std::min(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size()); - strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len); - } - // strcpy(netPhotoInfo.interface, "eth0"); - - std::vector 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; - } - } - - 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); - } + pThis->TakePhotoWithNetCamera(localPhotoInfo, path, osds, powerCtrlPtr); }); t.detach(); } else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_SERIAL)) { - unsigned long wid_serial = RequestWakelock(0); + uint64_t wid_serial = RequestWakelock(0); CPhoneDevice* pThis = this; IDevice::PHOTO_INFO localPhotoInfo = mPhotoInfo; IDevice::SerialsPhotoParam param = { "", 0, 0 }; GetPhotoSerialsParamCb(param); + vector osds; + osds.swap(mOsds); - std::thread t([localPhotoInfo, param, pThis,wid_serial]() mutable + std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial]() mutable { + time_t ts = time(NULL); + if(localPhotoInfo.scheduleTime != 0) + ts = localPhotoInfo.scheduleTime; + pThis->OpenPTZSensors(localPhotoInfo.selfTestingTime); + if (localPhotoInfo.preset != 0 && localPhotoInfo.preset != 0xFF) { + XYLOG(XYLOG_SEVERITY_INFO,"Recv CameraCtrl Command, action= MOVE_PRESETNO, preset = %u", localPhotoInfo.preset); CameraPhotoCmd(time(NULL), localPhotoInfo.channel, MOVE_PRESETNO, 0, localPhotoInfo.preset, param.serfile, param.baud, param.addr); - std::this_thread::sleep_for(std::chrono::seconds(3)); + std::this_thread::sleep_for(std::chrono::seconds(5)); } - time_t ts = time(NULL); - if(!pThis->GetPTZSensorsStatus() && !pThis->GetCameraStatus()) + + CameraPhotoCmd(ts, localPhotoInfo.channel, 0, localPhotoInfo.resolution, localPhotoInfo.preset, param.serfile, param.baud, param.addr); + XYLOG(XYLOG_SEVERITY_INFO, "Taking photo over"); + + if(localPhotoInfo.scheduleTime == 0) { + pThis->ClosePTZSensors(localPhotoInfo.closeDelayTime); + } + else { + pThis->ClosePTZSensors(2); + } + + + time_t takingTime = ts; + if (localPhotoInfo.remedy != 0) { - pThis->OpenPTZSensors(localPhotoInfo.selfTestingTime); + if ((takingTime - localPhotoInfo.scheduleTime) > 30) + { + takingTime = localPhotoInfo.scheduleTime + localPhotoInfo.channel * 2; + } } - CameraPhotoCmd(ts, localPhotoInfo.channel, 0, localPhotoInfo.resolution, 0, param.serfile, param.baud, param.addr); - XYLOG(XYLOG_SEVERITY_INFO, "Taking photo over"); - pThis->TakePTZPhotoCb(3, localPhotoInfo); - pThis->ClosePTZSensors(localPhotoInfo.closeDelayTime); - GpioControl::setCam3V3Enable(false, localPhotoInfo.closeDelayTime); + IMAGE_DEF photo = { 0 }; + std::vector objects; + GetImage(0, &photo); + if(photo.state == 5) + { + XYLOG(XYLOG_SEVERITY_INFO,"Get Serials Photo, PhotoID = %s", photo.photoname); + localPhotoInfo.photoTime = takingTime; + cv::Mat img = cv::imread(photo.photoname, cv::IMREAD_COLOR); + if (!img.empty()) + { + int result = std::remove(photo.photoname); + pThis->TakePhotoCb(1, localPhotoInfo, "", takingTime, objects); + pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", img); + } + + }else + { + XYLOG(XYLOG_SEVERITY_WARNING,"Get Serials Photo Failed"); + pThis->TakePhotoCb(0, localPhotoInfo, path, takingTime, objects); + } +// pThis->TakePTZPhotoCb(3, localPhotoInfo); pThis->ReleaseWakelock(wid_serial); }); t.detach(); } + else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_PLZ)) + { + uint64_t wid_serial = RequestWakelock(0); + CPhoneDevice* pThis = this; + IDevice::PHOTO_INFO localPhotoInfo = mPhotoInfo; + IDevice::SerialsPhotoParam param = { "", 0, 0 }; + GetPhotoSerialsParamCb(param); + vector osds; + osds.swap(mOsds); + + std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial, powerCtrlPtr]() mutable + { + if (localPhotoInfo.preset != 0 && localPhotoInfo.preset != 0xFF) + { + XYLOG(XYLOG_SEVERITY_INFO,"Recv CameraCtrl Command, action= MOVE_PRESETNO, preset = %u", localPhotoInfo.preset); + CameraPhotoCmd(time(NULL), localPhotoInfo.channel, MOVE_PRESETNO, 0, localPhotoInfo.preset, param.serfile, param.baud, param.addr); + std::this_thread::sleep_for(std::chrono::seconds(5)); + } + + pThis->TakePhotoWithNetCamera(localPhotoInfo, path, osds, powerCtrlPtr); + pThis->ReleaseWakelock(wid_serial); + }); + + t.detach(); + } else if (mPhotoInfo.usingSysCamera == 1) { JNIEnv* env = NULL; @@ -1856,7 +1951,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< int orientation = mPhotoInfo.orientation == 0 ? -1 : (mPhotoInfo.orientation - 1) * 90; jboolean photoOrVideo = mPhotoInfo.mediaType == 0 ? JNI_TRUE : JNI_FALSE; - env->CallVoidMethod(m_javaService, mStartRecordingMid, photoOrVideo, mPhotoInfo.cameraId, (unsigned long)mPhotoInfo.photoId, + env->CallVoidMethod(m_javaService, mStartRecordingMid, photoOrVideo, mPhotoInfo.cameraId, (uint64_t)mPhotoInfo.photoId, mPhotoInfo.duration, mPhotoInfo.width, mPhotoInfo.height, mPhotoInfo.duration, orientation, leftTopOSD, rightTopOSD, rightBottomOSD, leftBottomOSD); @@ -1876,20 +1971,17 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< bool CPhoneDevice::OpenPTZSensors(uint32_t sec) { - unsigned long wid = RequestWakelock(0); + uint64_t wid = RequestWakelock(0); unsigned long long time_now = GetMicroTimeStamp(); - if(time_now < localDelayTime-1000) { std::lock_guard lock(m_cameraLocker); - m_sensorsStatus = true; - m_cameraStatus = true; - OpenSensors(MAIN_POWER_OPEN); - OpenSensors(CAMERA_SENSOR_OPEN); - } - { - std::lock_guard lock(m_cameraLocker); -// std::unique_lock lock(m_cameraLocker); - if (!m_cameraStatus && !m_sensorsStatus) + if(time_now < localDelayTime-1000) + { + m_sensorsStatus = true; + m_cameraStatus = true; + OpenSensors(MAIN_POWER_OPEN); + OpenSensors(CAMERA_SENSOR_OPEN); + }else if (!m_cameraStatus && !m_sensorsStatus) { m_sensorsStatus = true; OpenSensors(MAIN_POWER_OPEN); @@ -1911,6 +2003,7 @@ bool CPhoneDevice::OpenPTZSensors(uint32_t sec) m_cameraStatus = false; m_sensorsStatus = false; m_shouldStopWaiting.store(false); + ReleaseWakelock(wid); return false; } std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -1933,8 +2026,6 @@ bool CPhoneDevice::OpenPTZSensors(uint32_t sec) ReleaseWakelock(wid); return m_cameraStatus; - - } bool CPhoneDevice::ClosePTZSensors(uint32_t delayedCloseTime) @@ -1943,9 +2034,10 @@ bool CPhoneDevice::ClosePTZSensors(uint32_t delayedCloseTime) if(m_sensorsStatus && !m_cameraStatus) { + localDelayTime = GetMicroTimeStamp(); m_shouldStopWaiting.store(true); } - else if(m_sensorsStatus && m_cameraStatus) + else { std::lock_guard lock(m_cameraLocker); // std::unique_lock lock(m_cameraLocker); @@ -1959,12 +2051,10 @@ bool CPhoneDevice::ClosePTZSensors(uint32_t delayedCloseTime) bool CPhoneDevice::GetPTZSensorsStatus() { - std::lock_guard lock(m_cameraLocker); return m_sensorsStatus; } bool CPhoneDevice::GetCameraStatus() { - std::lock_guard lock(m_cameraLocker); return m_cameraStatus; } @@ -3648,66 +3738,21 @@ void CPhoneDevice::ConvertDngToPng(const std::string& dngPath, const std::string } } -void CPhoneDevice::CameraCtrl(unsigned char waitTime, unsigned char delayTime, unsigned char channel, int cmdidx, unsigned char preset, const char *serfile, unsigned int baud, int addr) +void CPhoneDevice::CameraCtrl(unsigned short waitTime, unsigned short delayTime, unsigned char channel, int cmdidx, unsigned char preset, const char *serfile, unsigned int baud, int addr) { - switch (cmdidx) { - case 2:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(time(NULL), channel, MOVE_PRESETNO, 0, preset, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 3:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(0, channel, MOVE_UP, 0, 0, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 4:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(0, channel, MOVE_DOWN, 0, 0, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 5:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(0, channel, MOVE_LEFT, 0, 0, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 6:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(0, channel, MOVE_RIGHT, 0, 0, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 7:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(0, channel, ZOOM_WIDE, 0, 0, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 8:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(0, channel, ZOOM_TELE, 0, 0, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - case 9:{ -// if(GetCameraStatus()) - OpenPTZSensors(waitTime); - CameraPhotoCmd(time(NULL), channel, SAVE_PRESETNO, 0, preset, serfile, baud, addr); - ClosePTZSensors(delayTime); - break; - } - + if(!(m_sensorsStatus && !m_cameraStatus) && GpioControl::GetCamerastatus()) { + CPhoneDevice *pThis = this; + string serfileStr(serfile); + std::thread ctrlThread([pThis, waitTime, delayTime, cmdidx, channel, preset, serfileStr, baud, + addr]() mutable { + uint64_t wid = pThis->RequestWakelock(0); + pThis->OpenPTZSensors(waitTime); + CameraPhotoCmd(time(NULL), channel, cmdidx, 0, preset, serfileStr.c_str(), baud, + addr); + pThis->ClosePTZSensors(delayTime); + pThis->ReleaseWakelock(wid); + }); + ctrlThread.detach(); } } @@ -3753,69 +3798,99 @@ int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceT int angleno = 0; for(int num = 0; num < MAX_SERIAL_DEV_NUM; num++) { - if(sensorParam[num].SensorsType == RALLY_PROTOCOL && sensorParam[num].IsNoInsta == 1) + if(sensorParam[num].SensorsType == RALLY_PROTOCOL) { - GetPullValue(num, &airt); - if(airt.AiState == 255 || airt.AiState == -1) + if(sensorParam[num].IsNoInsta == 0) { iceInfo->t_sensor_data[pullno].original_tension = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,拉力未接传感器", - sensorParam[num].devaddr, airt.AiState); + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,拉力传感器未启用", + sensorParam[num].devaddr); }else { - iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue; - XYLOG(XYLOG_SEVERITY_INFO,"地址%d,采样状态 = %d,拉力 = %f", sensorParam[num].devaddr, airt.AiState, iceInfo->t_sensor_data[pullno].original_tension); - if(airt.AiState != 2 && iceInfo->t_sensor_data[pullno].original_tension == 0) + GetPullValue(num, &airt); + if(airt.AiState == 255 || airt.AiState == -1) { - XYLOG(XYLOG_SEVERITY_INFO,"地址%d,采样状态 = %d,拉力未采集到数据,重新采样", sensorParam[num].devaddr, airt.AiState); - status = 0; + iceInfo->t_sensor_data[pullno].original_tension = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,拉力未接传感器", + sensorParam[num].devaddr, airt.AiState); }else { - if(iceInfo->tension == 0xff) - iceInfo->tension =0; - iceInfo->tension = iceInfo->tension + iceInfo->t_sensor_data[pullno].original_tension; + iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue; + XYLOG(XYLOG_SEVERITY_INFO,"地址%d,采样状态 = %d,拉力 = %f", sensorParam[num].devaddr, airt.AiState, iceInfo->t_sensor_data[pullno].original_tension); + if(airt.AiState != 2 && iceInfo->t_sensor_data[pullno].original_tension == 0) + { + XYLOG(XYLOG_SEVERITY_INFO,"地址%d,采样状态 = %d,拉力未采集到数据,重新采样", sensorParam[num].devaddr, airt.AiState); + status = 0; + }else + { + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceInfo->t_sensor_data[pullno].original_tension = iceInfo->t_sensor_data[pullno].original_tension * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceInfo->t_sensor_data[pullno].original_tension = iceInfo->t_sensor_data[pullno].original_tension + sensorParam[num].offset; + if(iceInfo->tension == 0xff) + iceInfo->tension =0; + iceInfo->tension = iceInfo->tension + iceInfo->t_sensor_data[pullno].original_tension; + } } } pullno++; - } else if(sensorParam[num].SensorsType == SLANT_PROTOCOL && sensorParam[num].IsNoInsta == 1) + } else if(sensorParam[num].SensorsType == SLANT_PROTOCOL) { - GetAngleValue(num, &airt, 0); - if(airt.AiState == 255 || airt.AiState == -1) + if(sensorParam[num].IsNoInsta == 0) { iceInfo->t_sensor_data[angleno].deflection_angle = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,倾角x未接传感器", - sensorParam[num].devaddr, airt.AiState); + iceInfo->t_sensor_data[angleno].windage_yaw_angle = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,倾角传感器未启用", + sensorParam[num].devaddr); }else { - iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue; - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,x = %f", sensorParam[num].devaddr, - airt.AiState, iceInfo->t_sensor_data[angleno].deflection_angle); - if (airt.AiState != 2 && iceInfo->t_sensor_data[angleno].deflection_angle == 0) - { - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,倾角x未采集到数据,重新采样", + GetAngleValue(num, &airt, 0); + if (airt.AiState == 255 || airt.AiState == -1) { + iceInfo->t_sensor_data[angleno].deflection_angle = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,倾角x未接传感器", sensorParam[num].devaddr, airt.AiState); - status = 0; + } else { + iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,x = %f", + sensorParam[num].devaddr, + airt.AiState, iceInfo->t_sensor_data[angleno].deflection_angle); + if (airt.AiState != 2 && iceInfo->t_sensor_data[angleno].deflection_angle == 0) + { + XYLOG(XYLOG_SEVERITY_INFO, + "地址%d,采样状态 = %d,倾角x未采集到数据,重新采样", + sensorParam[num].devaddr, airt.AiState); + status = 0; + } else{ + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceInfo->t_sensor_data[angleno].deflection_angle = iceInfo->t_sensor_data[angleno].deflection_angle * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceInfo->t_sensor_data[angleno].deflection_angle = iceInfo->t_sensor_data[angleno].deflection_angle + sensorParam[num].offset; + } } - } - GetAngleValue(num, &airt, 1); - if(airt.AiState == 255 || airt.AiState == -1) - { - iceInfo->t_sensor_data[angleno].windage_yaw_angle =0xff; - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,倾角y未接传感器", - sensorParam[num].devaddr, airt.AiState); - }else - { - iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue; - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,y = %f", sensorParam[num].devaddr, - airt.AiState, iceInfo->t_sensor_data[angleno].windage_yaw_angle); - if (airt.AiState != 2 && iceInfo->t_sensor_data[angleno].windage_yaw_angle == 0) - { - XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,倾角y未采集到数据,重新采样", + GetAngleValue(num, &airt, 1); + if (airt.AiState == 255 || airt.AiState == -1) { + iceInfo->t_sensor_data[angleno].windage_yaw_angle = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,倾角y未接传感器", sensorParam[num].devaddr, airt.AiState); - status = 0; + } else { + iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,采样状态 = %d,y = %f", + sensorParam[num].devaddr, + airt.AiState, iceInfo->t_sensor_data[angleno].windage_yaw_angle); + if (airt.AiState != 2 && + iceInfo->t_sensor_data[angleno].windage_yaw_angle == 0) { + XYLOG(XYLOG_SEVERITY_INFO, + "地址%d,采样状态 = %d,倾角y未采集到数据,重新采样", + sensorParam[num].devaddr, airt.AiState); + status = 0; + }else{ + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceInfo->t_sensor_data[angleno].windage_yaw_angle = iceInfo->t_sensor_data[angleno].windage_yaw_angle * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceInfo->t_sensor_data[angleno].windage_yaw_angle = iceInfo->t_sensor_data[angleno].windage_yaw_angle + sensorParam[num].offset; + } } } - angleno++; } } @@ -3828,98 +3903,138 @@ int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceT { std::lock_guard lock(m_dataLocker); - GetWindSpeedData(&airt); - if(airt.AiState == 255 || airt.AiState == -1) - { - iceTail->instantaneous_windspeed = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风速未接传感器", - airt.AiState); - }else - { - iceTail->instantaneous_windspeed = airt.EuValue; - if (airt.AiState != 2 && iceTail->instantaneous_windspeed == 0 && m_tempData.instantaneous_windspeed == 0xff) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风速未采集到数据,重新采样", airt.AiState); - status = 0; - } else if (airt.AiState == 2 && m_tempData.instantaneous_windspeed == 0xff) - { - m_tempData.instantaneous_windspeed = iceTail->instantaneous_windspeed; - } else if (iceTail->instantaneous_windspeed == 0 && m_tempData.instantaneous_windspeed != 0xff) - { - iceTail->instantaneous_windspeed = m_tempData.instantaneous_windspeed; - } - } + for (int num = 0; num < MAX_SERIAL_DEV_NUM; num++) { + if (sensorParam[num].SensorsType == WIND_PROTOCOL && sensorParam[num].IsNoInsta == 0) { + iceTail->instantaneous_windspeed = 0xff; + iceTail->instantaneous_winddirection = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,风速风向传感器未启用", + sensorParam[num].devaddr); + continue; + } else if ((sensorParam[num].SensorsType == WIND_PROTOCOL || sensorParam[num].SensorsType == MUTIWEATHER_PROTOCOL) && + sensorParam[num].IsNoInsta == 1) { + GetWindSpeedData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) { + iceTail->instantaneous_windspeed = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风速未接传感器", + airt.AiState); + } else { + iceTail->instantaneous_windspeed = airt.EuValue; + if (airt.AiState != 2 && iceTail->instantaneous_windspeed == 0 && + m_tempData.instantaneous_windspeed == 0xff) + { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风速未采集到数据,重新采样", + airt.AiState); + status = 0; + } else + { + if (airt.AiState == 2 && m_tempData.instantaneous_windspeed == 0xff) + { + m_tempData.instantaneous_windspeed = iceTail->instantaneous_windspeed; + } else if (iceTail->instantaneous_windspeed == 0 && m_tempData.instantaneous_windspeed != 0xff) + { + iceTail->instantaneous_windspeed = m_tempData.instantaneous_windspeed; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceTail->instantaneous_windspeed = iceTail->instantaneous_windspeed * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceTail->instantaneous_windspeed = iceTail->instantaneous_windspeed + sensorParam[num].offset; + } + } - GetWindDirectionData(&airt); - if(airt.AiState == 255 || airt.AiState == -1) - { - iceTail->instantaneous_winddirection = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风向未接传感器", - airt.AiState); - }else - { - iceTail->instantaneous_winddirection = airt.EuValue; - if (airt.AiState != 2 && iceTail->instantaneous_winddirection == 0 && - m_tempData.instantaneous_winddirection == 0xff) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风向未采集到数据,重新采样", airt.AiState); - status = 0; - } else if (airt.AiState == 2 && m_tempData.instantaneous_winddirection == 0xff) - { - m_tempData.instantaneous_winddirection = iceTail->instantaneous_winddirection; - } else if (iceTail->instantaneous_winddirection == 0 && m_tempData.instantaneous_winddirection != 0xff) - { - iceTail->instantaneous_winddirection = m_tempData.instantaneous_winddirection; + GetWindDirectionData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) { + iceTail->instantaneous_winddirection = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风向未接传感器", + airt.AiState); + } else { + iceTail->instantaneous_winddirection = airt.EuValue; + if (airt.AiState != 2 && iceTail->instantaneous_winddirection == 0 && + m_tempData.instantaneous_winddirection == 0xff) { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰风向未采集到数据,重新采样", + airt.AiState); + status = 0; + } else { + if (airt.AiState == 2 && m_tempData.instantaneous_winddirection == 0xff) + { + m_tempData.instantaneous_winddirection = iceTail->instantaneous_winddirection; + } else if (iceTail->instantaneous_winddirection == 0 && m_tempData.instantaneous_winddirection != 0xff) + { + iceTail->instantaneous_winddirection = m_tempData.instantaneous_winddirection; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceTail->instantaneous_winddirection = iceTail->instantaneous_winddirection * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceTail->instantaneous_winddirection = iceTail->instantaneous_winddirection + sensorParam[num].offset; + } + } + break; } } - GetAirTempData(&airt); - if(airt.AiState == 255 || airt.AiState == -1) - { - iceTail->air_temperature = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰温度未接传感器", - airt.AiState); - }else - { - iceTail->air_temperature = airt.EuValue; - if (airt.AiState != 2 && iceTail->air_temperature == 0 && - m_tempData.air_temperature == 0xff) + for (int num = 0; num < MAX_SERIAL_DEV_NUM; num++) { + if (sensorParam[num].SensorsType == WEATHER_PROTOCOL && sensorParam[num].IsNoInsta == 0) { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰温度未采集到数据,重新采样", - airt.AiState); - status = 0; - } else if (airt.AiState == 2 && m_tempData.air_temperature == 0xff) - { - m_tempData.air_temperature = iceTail->air_temperature; - } else if (iceTail->air_temperature == 0 && m_tempData.air_temperature != 0xff) - { - iceTail->air_temperature = m_tempData.air_temperature; - } - } + iceTail->air_temperature = 0xff; + iceTail->humidity = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,温湿度传感器未启用", + sensorParam[num].devaddr); + continue; + } else if ((sensorParam[num].SensorsType == WEATHER_PROTOCOL || sensorParam[num].SensorsType == MUTIWEATHER_PROTOCOL) && sensorParam[num].IsNoInsta == 1) { + GetAirTempData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) { + iceTail->air_temperature = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰温度未接传感器", + airt.AiState); + } else { + iceTail->air_temperature = airt.EuValue; + if (airt.AiState != 2 && iceTail->air_temperature == 0 && + m_tempData.air_temperature == 0xff) { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰温度未采集到数据,重新采样", + airt.AiState); + status = 0; + } else { + if (airt.AiState == 2 && m_tempData.air_temperature == 0xff) + { + m_tempData.air_temperature = iceTail->air_temperature; + } else if (iceTail->air_temperature == 0 && + m_tempData.air_temperature != 0xff) + { + iceTail->air_temperature = m_tempData.air_temperature; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceTail->air_temperature = iceTail->air_temperature * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceTail->air_temperature = iceTail->air_temperature + sensorParam[num].offset; + } + } - GetHumidityData(&airt); - if(airt.AiState == 255 || airt.AiState == -1) - { - iceTail->humidity = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰湿度未接传感器", - airt.AiState); - }else - { - iceTail->humidity = airt.EuValue; - if (airt.AiState != 2 && iceTail->humidity == 0 && m_tempData.humidity == 0xff) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰湿度未采集到数据,重新采样", - airt.AiState); - status = 0; - } else if (airt.AiState == 2 && m_tempData.humidity == 0xff) - { - m_tempData.humidity = iceTail->humidity; - } else if (iceTail->humidity == 0 && m_tempData.humidity != 0xff) - { - iceTail->humidity = m_tempData.humidity; + GetHumidityData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) { + iceTail->humidity = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰湿度未接传感器", + airt.AiState); + } else { + iceTail->humidity = airt.EuValue; + if (airt.AiState != 2 && iceTail->humidity == 0 && + m_tempData.humidity == 0xff) { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,覆冰湿度未采集到数据,重新采样", + airt.AiState); + status = 0; + } else { + if (airt.AiState == 2 && m_tempData.humidity == 0xff) { + m_tempData.humidity = iceTail->humidity; + } else if (iceTail->humidity == 0 && m_tempData.humidity != 0xff) { + iceTail->humidity = m_tempData.humidity; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + iceTail->humidity = iceTail->humidity * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + iceTail->humidity = iceTail->humidity + sensorParam[num].offset; + } + } + break; } } - } if(status) @@ -3928,7 +4043,7 @@ int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceT return false; } -int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo) +int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo, D_SENSOR_PARAM *sensorParam) { m_tempData.instantaneous_windspeed = 0xff; m_tempData.air_temperature = 0xff; @@ -3953,137 +4068,220 @@ int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo) Data_DEF airt; { std::lock_guard lock(m_dataLocker); - GetWeatherData(&airt, 2); - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->avg_windspeed_10min = 0xff; - weatherInfo->extreme_windspeed = 0xff; - weatherInfo->standard_windspeed = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风速未接传感器", airt.AiState); - }else + for (int num = 0; num < MAX_SERIAL_DEV_NUM; num++) { - weatherInfo->avg_windspeed_10min = airt.EuValue; - weatherInfo->extreme_windspeed = airt.EuValue; - weatherInfo->standard_windspeed = airt.EuValue; - if (airt.AiState != 2 && weatherInfo->avg_windspeed_10min == 0 && - m_tempData.instantaneous_windspeed == 0xff) + if (sensorParam[num].SensorsType == WIND_PROTOCOL && sensorParam[num].IsNoInsta == 0) { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风速未采集到数据,重新采样", - airt.AiState); - status = 0; - } else if (airt.AiState == 2 && m_tempData.instantaneous_windspeed == 0xff) - { - m_tempData.instantaneous_windspeed = weatherInfo->avg_windspeed_10min; - } else if (weatherInfo->avg_windspeed_10min == 0 && - m_tempData.instantaneous_windspeed != 0xff) + weatherInfo->avg_windspeed_10min = 0xff; + weatherInfo->extreme_windspeed = 0xff; + weatherInfo->standard_windspeed = 0xff; + weatherInfo->avg_winddirection_10min = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,风速风向传感器未启用", + sensorParam[num].devaddr); + continue; + } else if ((sensorParam[num].SensorsType == WIND_PROTOCOL || sensorParam[num].SensorsType == MUTIWEATHER_PROTOCOL) && sensorParam[num].IsNoInsta == 1) { - weatherInfo->avg_windspeed_10min = m_tempData.instantaneous_windspeed; - weatherInfo->extreme_windspeed = m_tempData.instantaneous_windspeed; - weatherInfo->standard_windspeed = m_tempData.instantaneous_windspeed; - } - } + GetWindSpeedData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->avg_windspeed_10min = 0xff; + weatherInfo->extreme_windspeed = 0xff; + weatherInfo->standard_windspeed = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风速未接传感器", airt.AiState); + } else + { + weatherInfo->avg_windspeed_10min = airt.EuValue; + weatherInfo->extreme_windspeed = airt.EuValue; + weatherInfo->standard_windspeed = airt.EuValue; + if (airt.AiState != 2 && weatherInfo->avg_windspeed_10min == 0 && m_tempData.instantaneous_windspeed == 0xff) + { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风速未采集到数据,重新采样", + airt.AiState); + status = 0; + } else { + if (airt.AiState == 2 && m_tempData.instantaneous_windspeed == 0xff) + { + m_tempData.instantaneous_windspeed = weatherInfo->avg_windspeed_10min; + } else if (weatherInfo->avg_windspeed_10min == 0 && + m_tempData.instantaneous_windspeed != 0xff) + { + weatherInfo->avg_windspeed_10min = m_tempData.instantaneous_windspeed; + weatherInfo->extreme_windspeed = m_tempData.instantaneous_windspeed; + weatherInfo->standard_windspeed = m_tempData.instantaneous_windspeed; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + { + weatherInfo->avg_windspeed_10min = weatherInfo->avg_windspeed_10min * sensorParam[num].multiple; + weatherInfo->extreme_windspeed = weatherInfo->avg_windspeed_10min; + weatherInfo->standard_windspeed = weatherInfo->avg_windspeed_10min; + } + if(sensorParam[num].offset != 0) + { + weatherInfo->avg_windspeed_10min = weatherInfo->avg_windspeed_10min + sensorParam[num].offset; + weatherInfo->extreme_windspeed = weatherInfo->avg_windspeed_10min; + weatherInfo->standard_windspeed = weatherInfo->avg_windspeed_10min; + } + } + } - GetWeatherData(&airt, 3); - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->avg_winddirection_10min = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风向未接传感器", airt.AiState); - }else - { - weatherInfo->avg_winddirection_10min = airt.EuValue; - if (airt.AiState != 2 && weatherInfo->avg_winddirection_10min == 0 && - m_tempData.instantaneous_winddirection == 0xff) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风向未采集到数据,重新采样", airt.AiState); - status = 0; - } else if(airt.AiState == 2 && m_tempData.instantaneous_winddirection == 0xff) - { - m_tempData.instantaneous_winddirection = weatherInfo->avg_winddirection_10min; - }else if(weatherInfo->winddirection == 0 && m_tempData.instantaneous_winddirection != 0xff) - { - weatherInfo->winddirection = m_tempData.instantaneous_winddirection; - } - } - GetWeatherData(&airt, 0); - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->air_temperature = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象温度未接传感器", airt.AiState); - }else - { - weatherInfo->air_temperature = airt.EuValue; - if (airt.AiState != 2 && weatherInfo->air_temperature == 0 && - m_tempData.air_temperature == 0xff) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象温度未采集到数据,重新采样", - airt.AiState); - status = 0; - } else if (airt.AiState == 2 && m_tempData.air_temperature == 0xff) - { - m_tempData.air_temperature = weatherInfo->air_temperature; - } else if (weatherInfo->air_temperature == 0 && m_tempData.air_temperature != 0xff) - { - weatherInfo->air_temperature = m_tempData.air_temperature; + GetWindDirectionData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->avg_winddirection_10min = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风向未接传感器", airt.AiState); + } else + { + weatherInfo->avg_winddirection_10min = airt.EuValue; + if (airt.AiState != 2 && weatherInfo->avg_winddirection_10min == 0 && m_tempData.instantaneous_winddirection == 0xff) + { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象风向未采集到数据,重新采样", airt.AiState); + status = 0; + } else { + if (airt.AiState == 2 && m_tempData.instantaneous_winddirection == 0xff) { + m_tempData.instantaneous_winddirection = weatherInfo->avg_winddirection_10min; + } else if (weatherInfo->winddirection == 0 && m_tempData.instantaneous_winddirection != 0xff) { + weatherInfo->avg_winddirection_10min = m_tempData.instantaneous_winddirection; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + weatherInfo->avg_winddirection_10min = weatherInfo->avg_winddirection_10min * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + weatherInfo->avg_winddirection_10min = weatherInfo->avg_winddirection_10min + sensorParam[num].offset; + } + } + + GetRainfallData(&airt); + weatherInfo->precipitation = airt.EuValue; + if(airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->precipitation = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,降雨量未接传感器", airt.AiState); + }else if (airt.AiState != 2 && weatherInfo->precipitation == 0) + { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,降雨量未采集到数据,重新采样", + weatherInfo->precipitation, airt.AiState); + status = 0; + } else + { + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + weatherInfo->precipitation = weatherInfo->precipitation * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + weatherInfo->precipitation = weatherInfo->precipitation + sensorParam[num].offset; + } + + GetAtmosData(&airt); + weatherInfo->air_pressure = airt.EuValue; + if(airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->air_pressure = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气压未接传感器", airt.AiState); + }else if (airt.AiState != 2 && weatherInfo->air_pressure == 0) { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气压未采集到数据,重新采样", + weatherInfo->air_pressure, airt.AiState); + status = 0; + } else + { + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + weatherInfo->air_pressure = weatherInfo->air_pressure * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + weatherInfo->air_pressure = weatherInfo->air_pressure + sensorParam[num].offset; + } + + GetOpticalRadiationData(&airt); + weatherInfo->radiation_intensity = airt.EuValue; + if(airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->radiation_intensity = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,光照强度未接传感器", airt.AiState); + }else if (airt.AiState != 2 && weatherInfo->radiation_intensity == 0) { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,光照强度未采集到数据,重新采样", + weatherInfo->radiation_intensity, airt.AiState); + status = 0; + } else + { + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + weatherInfo->radiation_intensity = weatherInfo->radiation_intensity * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + weatherInfo->radiation_intensity = weatherInfo->radiation_intensity + sensorParam[num].offset; + } + break; } } - GetWeatherData(&airt, 1); - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->humidity = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象湿度未接传感器", airt.AiState); - }else - { - weatherInfo->humidity = airt.EuValue; - if (airt.AiState != 2 && weatherInfo->humidity == 0 && m_tempData.humidity == 0xff) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象湿度未采集到数据,重新采样", airt.AiState); - status = 0; - } else if(airt.AiState == 2 && m_tempData.humidity == 0xff) + + for (int num = 0; num < MAX_SERIAL_DEV_NUM; num++) { + if (sensorParam[num].SensorsType == WEATHER_PROTOCOL && sensorParam[num].IsNoInsta == 0) { - m_tempData.humidity = weatherInfo->humidity; - }else if(weatherInfo->humidity == 0 && m_tempData.humidity != 0xff) + weatherInfo->air_temperature = 0xff; + weatherInfo->humidity = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "地址%d,温湿度传感器未启用", + sensorParam[num].devaddr); + continue; + } else if ((sensorParam[num].SensorsType == WEATHER_PROTOCOL || sensorParam[num].SensorsType == MUTIWEATHER_PROTOCOL) && + sensorParam[num].IsNoInsta == 1) { - weatherInfo->humidity = m_tempData.humidity; - } - } - - GetWeatherData(&airt, 4); - weatherInfo->precipitation = airt.EuValue; - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->precipitation = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,降雨量未接传感器", airt.AiState); - }else if (airt.AiState != 2 && weatherInfo->precipitation == 0) - { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,降雨量未采集到数据,重新采样", - weatherInfo->precipitation, airt.AiState); - status = 0; - } + GetAirTempData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->air_temperature = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象温度未接传感器", airt.AiState); + } else + { + weatherInfo->air_temperature = airt.EuValue; + if (airt.AiState != 2 && weatherInfo->air_temperature == 0 && + m_tempData.air_temperature == 0xff) + { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象温度未采集到数据,重新采样", + airt.AiState); + status = 0; + } else + { + if (airt.AiState == 2 && m_tempData.air_temperature == 0xff) + { + m_tempData.air_temperature = weatherInfo->air_temperature; + } else if (weatherInfo->air_temperature == 0 && m_tempData.air_temperature != 0xff) + { + weatherInfo->air_temperature = m_tempData.air_temperature; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + weatherInfo->air_temperature = weatherInfo->air_temperature * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + weatherInfo->air_temperature = weatherInfo->air_temperature + sensorParam[num].offset; + } + } - GetWeatherData(&airt, 5); - weatherInfo->air_pressure = airt.EuValue; - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->air_pressure = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气压未接传感器", airt.AiState); - }else if (airt.AiState != 2 && weatherInfo->air_pressure == 0) { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气压未采集到数据,重新采样", - weatherInfo->air_pressure, airt.AiState); - status = 0; + GetHumidityData(&airt); + if (airt.AiState == 255 || airt.AiState == -1) + { + weatherInfo->humidity = 0xff; + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象湿度未接传感器", airt.AiState); + } else + { + weatherInfo->humidity = airt.EuValue; + if (airt.AiState != 2 && weatherInfo->humidity == 0 && + m_tempData.humidity == 0xff) + { + XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,气象湿度未采集到数据,重新采样", + airt.AiState); + status = 0; + } else + { + if (airt.AiState == 2 && m_tempData.humidity == 0xff) + { + m_tempData.humidity = weatherInfo->humidity; + } else if (weatherInfo->humidity == 0 && m_tempData.humidity != 0xff) + { + weatherInfo->humidity = m_tempData.humidity; + } + if(sensorParam[num].multiple != 1 && sensorParam[num].multiple != 0) + weatherInfo->humidity = weatherInfo->humidity * sensorParam[num].multiple; + if(sensorParam[num].offset != 0) + weatherInfo->humidity = weatherInfo->humidity + sensorParam[num].offset; + } + } + break; + } } - GetWeatherData(&airt, 6); - weatherInfo->radiation_intensity = airt.EuValue; - if(airt.AiState == 255 || airt.AiState == -1) - { - weatherInfo->radiation_intensity = 0xff; - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,光照强度未接传感器", airt.AiState); - }else if (airt.AiState != 2 && weatherInfo->radiation_intensity == 0) { - XYLOG(XYLOG_SEVERITY_INFO, "采样状态 = %d,光照强度未采集到数据,重新采样", - weatherInfo->radiation_intensity, airt.AiState); - status = 0; - } if (status) return true; else @@ -4177,19 +4375,36 @@ bool CPhoneDevice::CloseSensors(int sensortype, uint32_t delayedCloseTime) } if(sensortype == CAMERA_SENSOR_OPEN) { + if(delayedCloseTime ==0) + { +#ifdef USING_N938 + GpioControl::TurnOffImmediately(CMD_SET_PIC1_POWER); + GpioControl::TurnOffImmediately(CMD_SET_485_EN4); +#endif + +#ifndef USING_N938 + // GpioControl::TurnOff(CMD_SET_3V3_PWR_ENABLE); +#ifndef USING_PLZ +#else + GpioControl::TurnOffImmediately(CMD_SET_PTZ_PWR_ENABLE); +#endif +#endif + }else + { #ifdef USING_N938 - GpioControl::TurnOff(CMD_SET_PIC1_POWER, delayedCloseTime); - GpioControl::TurnOff(CMD_SET_485_EN4, delayedCloseTime); + GpioControl::TurnOff(CMD_SET_PIC1_POWER, delayedCloseTime); + GpioControl::TurnOff(CMD_SET_485_EN4, delayedCloseTime); // GpioControl::TurnOff(CMD_SET_CAM_3V3_EN_STATE); #endif #ifndef USING_N938 - // GpioControl::TurnOff(CMD_SET_3V3_PWR_ENABLE); - #ifndef USING_PLZ - #else - GpioControl::TurnOff(CMD_SET_PTZ_PWR_ENABLE, delayedCloseTime); - #endif + // GpioControl::TurnOff(CMD_SET_3V3_PWR_ENABLE); +#ifndef USING_PLZ +#else + GpioControl::TurnOff(CMD_SET_PTZ_PWR_ENABLE, delayedCloseTime); #endif +#endif + } } if(sensortype == WEATHER_SENSOR_OPEN ) { diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index ee444c0d..e20bf433 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -202,10 +202,10 @@ public: { CPhoneDevice* device; unsigned int timerType; - unsigned long times; + uint64_t times; void* data; - unsigned long expectedTimes; - unsigned long uid; + uint64_t expectedTimes; + uint64_t uid; }; CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir); @@ -226,12 +226,12 @@ public: virtual timer_uid_t RegisterHeartbeat(unsigned int timerType, unsigned int timeout, time_t tsForNextPhoto); virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector& osds, const std::string& path); virtual bool CloseCamera(); - virtual timer_uid_t RegisterTimer(unsigned int timerType, unsigned int timeout, void* data, unsigned long times = 0); + virtual timer_uid_t RegisterTimer(unsigned int timerType, unsigned int timeout, void* data, uint64_t times = 0); virtual bool UnregisterTimer(timer_uid_t uid); - virtual unsigned long RequestWakelock(unsigned long timeout); - virtual bool ReleaseWakelock(unsigned long wakelock); + virtual uint64_t RequestWakelock(uint64_t timeout); + virtual bool ReleaseWakelock(uint64_t wakelock); - virtual int GetWData(WEATHER_INFO *weatherInfo); + virtual int GetWData(WEATHER_INFO *weatherInfo, D_SENSOR_PARAM *sensorParam); virtual int GetIceData(ICE_INFO *iceInfo, ICE_TAIL *icetail, D_SENSOR_PARAM *sensorParam); virtual bool OpenSensors(int sensortype); virtual bool CloseSensors(int sensortype, uint32_t delayedCloseTime); @@ -239,7 +239,7 @@ public: virtual bool ClosePTZSensors(uint32_t delayedCloseTime); virtual bool GetPTZSensorsStatus(); virtual bool GetCameraStatus(); - virtual void CameraCtrl(unsigned char waitTime, unsigned char delayTime, unsigned char channel, int cmdidx, unsigned char presetno, const char *serfile, unsigned int baud, int addr); + virtual void CameraCtrl(unsigned short waitTime, unsigned short delayTime, unsigned char channel, int cmdidx, unsigned char presetno, const char *serfile, unsigned int baud, int addr); virtual int GetSerialPhoto(int devno, D_IMAGE_DEF *photo); virtual void InitSerialComm(D_SENSOR_PARAM *sensorParam, char *filedir); @@ -272,6 +272,7 @@ protected: bool SendBroadcastMessage(std::string action, int value); // bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_, + bool TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector& osds, std::shared_ptr powerCtrlPtr); bool PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector& osds, const std::string& path, const std::string& cameraInfo, cv::Mat& mat); inline bool TakePhotoCb(int res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime, const std::vector& objects) const { @@ -386,9 +387,9 @@ protected: unsigned int mVersionCode; time_t mBuildTime; - atomic_ulong m_timerUidFeed; - atomic_ulong m_wakelockIdFeed; - atomic_ulong m_uniqueIdFeed; + atomic_ullong m_timerUidFeed; + atomic_ullong m_wakelockIdFeed; + atomic_ullong m_uniqueIdFeed; std::map mTimers; mutable CPhoneCamera* mCamera; diff --git a/app/src/main/cpp/SensorsProtocol.cpp b/app/src/main/cpp/SensorsProtocol.cpp index a7ed0966..7c0c97b7 100644 --- a/app/src/main/cpp/SensorsProtocol.cpp +++ b/app/src/main/cpp/SensorsProtocol.cpp @@ -692,7 +692,7 @@ void Gm_OpenSerialPort(int devidx) fd = ::open(devparam[devidx].pathname, O_RDWR | O_NDELAY); if (fd < 0) { - sprintf(szbuf, "装置%d 打开串口%d %s失败!fd=%d", devidx+1, devparam[devidx].pathname, devparam[devidx].commid+1, fd); + sprintf(szbuf, "装置%d 打开串口%d %s失败!fd=%d", devidx+1, devparam[devidx].commid+1, devparam[devidx].pathname, fd); DebugLog(devparam[devidx].commid, szbuf, 'E'); return; } @@ -1020,6 +1020,9 @@ void Gm_InitSerialComm(SENSOR_PARAM *sensorParam, char *filedir) case RESERVE5_PROTOCOL: sprintf(szbuf, "传感器%d接的是加密芯片", i + 1); break; + case MUTIWEATHER_PROTOCOL: + sprintf(szbuf, "传感器%d接的是多合一气象传感器", i + 1); + break; default: sprintf(szbuf, "传感器%d没有接!", i + 1); break; @@ -1180,6 +1183,7 @@ void FindDevUseSerialCommNo() { case WEATHER_PROTOCOL: case WIND_PROTOCOL: + case MUTIWEATHER_PROTOCOL: //memset(devparam[i].pathname, 0, sizeof(devparam[i].pathname)); /* 目前还不确定具体串口分配,暂时默认使用串口1*/ //sprintf(devparam[i].pathname, "/dev/swk3"); @@ -1271,6 +1275,7 @@ void GM_StartSerialComm() switch (devparam[i].ProtocolIdx) { case WEATHER_PROTOCOL: // 气象 + case MUTIWEATHER_PROTOCOL: memset(weatherpntmsg, 0, sizeof(AI_DEF)*WEATHER_DATA_NUM); memset(szbuf, 0, sizeof(szbuf)); sprintf(szbuf, "%s", "气象"); @@ -1433,6 +1438,7 @@ void Gm_FindAllSensorsCommand() case RALLY_PROTOCOL: /* 拉力*/ case WIND_PROTOCOL: /* 风速风向*/ case SLANT_PROTOCOL: /* 倾角*/ + case MUTIWEATHER_PROTOCOL: flag = FindNextShxyProtocolCommand(curidx); break; case RESERVE2_PROTOCOL: @@ -1480,6 +1486,7 @@ void GM_IsCloseSensors() case RALLY_PROTOCOL: /* 拉力*/ case WIND_PROTOCOL: /* 风速风向*/ case SLANT_PROTOCOL: /* 倾角*/ + case MUTIWEATHER_PROTOCOL: if ((lctime - srdt.ms_dev[i].FirstCmdTimeCnt > 50 * 1000) || (lctime - srdt.ms_dev[i].FirstCmdTimeCnt < 0)) { srdt.ms_dev[i].FirstCmdTimeCnt = lctime; @@ -1498,7 +1505,7 @@ void GM_IsCloseSensors() else if (SER_SAMPLE == srdt.ms_dev[i].aiValue[j].AiState) srdt.ms_dev[i].aiValue[j].AiState = SAMPLINGSUCCESS; } - if((devparam[i].ProtocolIdx == WIND_PROTOCOL) || (WEATHER_PROTOCOL == devparam[i].ProtocolIdx)) + if((devparam[i].ProtocolIdx == WIND_PROTOCOL) || (WEATHER_PROTOCOL == devparam[i].ProtocolIdx)|| (MUTIWEATHER_PROTOCOL == devparam[i].ProtocolIdx)) { for (j = 0; j < WEATHER_DATA_NUM; j++) { @@ -1606,6 +1613,7 @@ void SerialDataProcess(int devidx, u_char *buf, int len) case RALLY_PROTOCOL: /* 拉力*/ case WIND_PROTOCOL: /* 风速风向*/ case SLANT_PROTOCOL: /* 倾角*/ + case MUTIWEATHER_PROTOCOL: ShxyProtocolRecvData(devidx, buf, len); break; case RESERVE2_PROTOCOL: /* 意科电池电量读取协议*/ @@ -2961,7 +2969,7 @@ void ShxyProtocolDataProcess(int devno) int i, j, aipnt, datanum; SERIAL_DEV_DEF *pPortParam; SIO_PARAM_SERIAL_DEF *curserial; - char szbuf[64]; + char szbuf[128]; pPortParam = &srdt.ms_dev[devno]; curserial = &serialport[devparam[devno].commid]; @@ -3093,8 +3101,8 @@ void ShxyProtocolDataProcess(int devno) //g_SelfTest.SensorsFault |= (0x10); //if ((gDisSunRain & 0x80) == 0x80) { - sprintf(szbuf, "气压:%0.3f ", fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + sprintf(szbuf, "%s气压:%0.3f ", szbuf, fvalue); + //DebugLog(devparam[devno].commid, szbuf, 'V'); } break; case 3: /*湿度*/ @@ -3115,12 +3123,50 @@ void ShxyProtocolDataProcess(int devno) //if ((gDisSunRain & 0x80) == 0x80) { sprintf(szbuf, "%s湿度:%0.3f ", szbuf, fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + if(datanum < 6) + DebugLog(devparam[devno].commid, szbuf, 'V'); } break; case 4: /*雨量*/ + if ((fvalue < 0) || (fvalue > 10000)) + { + frnb = (GeneratingRandomNumber() % 41 - 20) / 1000.0; + pPortParam->aiValue[RainfallNo].EuValue *= (1 + frnb); + weatherpntmsg[RainfallNo].EuValue *= (1 + frnb); + } + else + { + pPortParam->aiValue[RainfallNo].EuValue = fvalue;/*pPortParam->aiValue[1].AiParam.fFactor + pPortParam->aiValue[1].AiParam.EuValueDelta;*/ + weatherpntmsg[RainfallNo].EuValue = fvalue;/*weatherpntmsg[HumidityNo].AiParam.fFactor + weatherpntmsg[HumidityNo].AiParam.EuValueDelta;*/ + } + pPortParam->aiValue[RainfallNo].AiState = SER_SAMPLE; + weatherpntmsg[RainfallNo].AiState = SER_SAMPLE; + //g_SelfTest.SensorsFault |= (0x02); + //if ((gDisSunRain & 0x80) == 0x80) + { + sprintf(szbuf, "%s雨量:%0.3f ", szbuf, fvalue); + if(datanum < 7) + DebugLog(devparam[devno].commid, szbuf, 'V'); + } break; case 5: /*日照*/ + if ((fvalue < 0) || (fvalue > 10000)) + { + frnb = (GeneratingRandomNumber() % 41 - 20) / 1000.0; + pPortParam->aiValue[OpticalRadiationNo].EuValue *= (1 + frnb); + weatherpntmsg[OpticalRadiationNo].EuValue *= (1 + frnb); + } + else + { + pPortParam->aiValue[OpticalRadiationNo].EuValue = fvalue;/*pPortParam->aiValue[1].AiParam.fFactor + pPortParam->aiValue[1].AiParam.EuValueDelta;*/ + weatherpntmsg[OpticalRadiationNo].EuValue = fvalue;/*weatherpntmsg[HumidityNo].AiParam.fFactor + weatherpntmsg[HumidityNo].AiParam.EuValueDelta;*/ + } + pPortParam->aiValue[OpticalRadiationNo].AiState = SER_SAMPLE; + weatherpntmsg[OpticalRadiationNo].AiState = SER_SAMPLE; + { + sprintf(szbuf, "%s日照:%0.3f ", szbuf, fvalue); + DebugLog(devparam[devno].commid, szbuf, 'V'); + } break; case 6: /*风速*/ if ((fvalue < 0) || (fvalue > 80)) diff --git a/app/src/main/cpp/SensorsProtocol.h b/app/src/main/cpp/SensorsProtocol.h index a7f45c93..4618dcca 100644 --- a/app/src/main/cpp/SensorsProtocol.h +++ b/app/src/main/cpp/SensorsProtocol.h @@ -38,6 +38,7 @@ #define PELCO_P_PROTOCOL 5 /* 摄像机Pelco_P协议序号*/ #define PELCO_D_PROTOCOL 6 /* 摄像机Pelco_D协议序号*/ #define SERIALCAMERA_PROTOCOL 8 /* 串口摄像机协议序号*/ +#define MUTIWEATHER_PROTOCOL 9 /*多合一气象*/ #define RESERVE2_PROTOCOL 17 /* 备用2协议序号*/ #define RESERVE4_PROTOCOL 19 /* 备用4协议序号*/ #define RESERVE5_PROTOCOL 20 /* 备用5协议序号*/ @@ -193,6 +194,8 @@ typedef struct SENSOR_PARAM uint8_t IsNoInsta; /* 装置没有安装或者已经坏了(1:正常, 0:无效,坏了或没有安装)*/ uint8_t CameraChannel; /* 像机的通道号*/ uint8_t Phase; /* 传感器所安装相别,指拉力和倾角11表示A1....*/ + float multiple; /*系数*/ + float offset; /*偏移值*/ } SENSOR_PARAM; // 需要配置的串口装置参数 diff --git a/app/src/main/cpp/netcamera/httpclient.cpp b/app/src/main/cpp/netcamera/httpclient.cpp index b5d256c9..2f16d3b3 100644 --- a/app/src/main/cpp/netcamera/httpclient.cpp +++ b/app/src/main/cpp/netcamera/httpclient.cpp @@ -29,7 +29,7 @@ static int SockOptCallback(void *clientp, curl_socket_t curlfd, curlsocktype pur 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) +int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector& data) { CURLcode nRet; std::string auth; @@ -37,14 +37,24 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne 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) + if (authType != HTTP_AUTH_TYPE_NONE) { - 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 (userName != NULL && password != NULL && strlen(userName) > 0) + { + auth = userName; + auth += ":"; + auth += password; + curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str()); + // DIGEST Auth + if (authType == HTTP_AUTH_TYPE_BASIC) + { + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + } + else if (authType == HTTP_AUTH_TYPE_DIGEST) + { + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + } + } } if (netHandle != NETWORK_UNSPECIFIED) @@ -69,30 +79,56 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); nRet = curl_easy_perform(curl); - if (CURLE_OK != nRet) + + long responseCode = 0; + if (CURLE_OK == nRet) + { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode); + if (responseCode != 200) + { +#ifdef _DEBUG + char * log = new char[data.size() + 1]; + log[data.size()] = 0; + memcpy(log, &data[0], data.size()); + printf(log); + delete[] log; +#endif + } + } + else { printf("GET err=%d", nRet); } curl_easy_cleanup(curl); - return (0 == nRet) ? 0 : 1; + return ((0 == nRet) && (responseCode == 200)) ? 0 : 1; } -int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data) +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& 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) + if (authType != HTTP_AUTH_TYPE_NONE) { - 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 (userName != NULL && password != NULL && strlen(userName) > 0) + { + auth = userName; + auth += ":"; + auth += password; + curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str()); + // DIGEST Auth + if (authType == HTTP_AUTH_TYPE_BASIC) + { + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + } + else if (authType == HTTP_AUTH_TYPE_DIGEST) + { + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + } + } } if (netHandle != NETWORK_UNSPECIFIED) @@ -137,7 +173,7 @@ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photo url += photoInfo.ip; url += photoInfo.url; - int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, data); + int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, data); if (0 == nRet) { if (!data.empty()) @@ -170,7 +206,7 @@ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photo url += photoInfo.ip; url += photoInfo.url; - int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img); + int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, img); return (0 == nRet); } @@ -191,7 +227,7 @@ namespace nc_hk url += photoInfo.ip; url += photoInfo.url; - int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img); + int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, img); #ifdef _DEBUG if (0 == nRet) { @@ -225,7 +261,7 @@ namespace nc_ys url += photoInfo.ip; url += photoInfo.url; - int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img); + int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, img); #ifdef _DEBUG if (0 == nRet) { diff --git a/app/src/main/cpp/netcamera/httpclient.h b/app/src/main/cpp/netcamera/httpclient.h index e1cc05d9..71af1a76 100644 --- a/app/src/main/cpp/netcamera/httpclient.h +++ b/app/src/main/cpp/netcamera/httpclient.h @@ -16,7 +16,7 @@ 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& data); -int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data); +int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector& data); +int DoPutRequest(const char* url, int authType, 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 c5326734..9f0ab52e 100644 --- a/app/src/main/cpp/netcamera/netcamera.h +++ b/app/src/main/cpp/netcamera/netcamera.h @@ -5,6 +5,9 @@ #ifndef __NET_CAMERA__ #define __NET_CAMERA__ +#define HTTP_AUTH_TYPE_NONE 0 +#define HTTP_AUTH_TYPE_BASIC 1 +#define HTTP_AUTH_TYPE_DIGEST 2 struct NET_PHOTO_INFO { diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 7de2ceaf..7f2ac1ef 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -86,6 +86,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; public class MicroPhotoService extends Service { public static final String TAG = "MPLOG"; @@ -101,6 +102,10 @@ public class MicroPhotoService extends Service { public final static int MSG_WHAT_MAX = 1000; + public final static int BROADCAST_REQUEST_CODE_HEARTBEAT = 1; + public final static int BROADCAST_REQUEST_CODE_TAKING_PHOTO = 2; + public final static int BROADCAST_REQUEST_CODE_GPS = 2; + public static final int NOTIFICATION_ID_FOREGROUND_SERVICE = 8466503; public static final String ACTION_MSG_BROADCAST = "ACT_MSG_BROADCAST"; @@ -157,6 +162,8 @@ public class MicroPhotoService extends Service { private ServiceHandler mHander = null; private Messenger mMessenger = null; + private static AtomicInteger mPendingIntentFeed = new AtomicInteger(); + private String mModelName = null; public static boolean isRunning = false; @@ -199,7 +206,7 @@ public class MicroPhotoService extends Service { @Override public void onTrimMemory(int level) { - Log.w(TAG, "onTrimMemory level=" + level); + infoLog("Event onTrimMemory level=" + level); if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) { // Clear the caches. Note all pending requests will be removed too. final Context context = getApplicationContext(); @@ -318,6 +325,7 @@ public class MicroPhotoService extends Service { getApplicationContext().registerReceiver(mNetworkChangedReceiver, filter); } + /* AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(ALARM_SERVICE); while (true) { @@ -327,6 +335,8 @@ public class MicroPhotoService extends Service { } } + */ + enableGps(true); requestPosition(); } @@ -416,17 +426,24 @@ public class MicroPhotoService extends Service { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (TextUtils.equals(ACTION_HEARTBEAT, action)) { - Log.i(TAG, "HB Timer Fired ACTION=" + action); + long ts = System.currentTimeMillis(); + long expectedHbTime = intent.getLongExtra("HeartbeatTime", ts); + + infoLog("HB Timer Fired ACTION=" + action + " ExpTS=" + Long.toString(expectedHbTime)); Runnable runnable = new Runnable() { public void run() { mService.sendHeartbeat(mService.mNativeHandle, mService.getSignalLevel()); } }; - Thread th = new Thread(runnable); th.start(); - - mService.registerHeartbeatTimer(mService.mHeartbeatDuration); + + long nextHbTime = expectedHbTime + mService.mHeartbeatDuration; + while (nextHbTime <= ts) { + nextHbTime += mService.mHeartbeatDuration; + } + long timeout = (expectedHbTime != 0) ? (nextHbTime - System.currentTimeMillis()) : mService.mHeartbeatDuration; + mService.registerHeartbeatTimer(timeout); try { @@ -449,11 +466,18 @@ public class MicroPhotoService extends Service { for (int idx = 0; idx < cnt; idx++) { long val = intent.getLongExtra(EXTRA_PARAM_SCHEDULE + idx, 0); - int channel = (int) ((val & 0xFF0000L) >> 16); - int preset = (int) ((val & 0xFF00L) >> 8); - boolean photoOrVideo = ((val & 0xFFL) == 0); + int channel = (int) ((val & 0xFFFF000L) >> 12); + int preset = (int) ((val & 0xFF0L) >> 4); + boolean photoOrVideo = ((val & 0xFL) == 0); - Log.i(TAG, "PhotoTimer Fired: CH=" + channel + " PR=" + preset); + if (channel >= 256) + { + infoLog("SERIAL Timer Fired: CH=" + (channel - 256) + " PR=" + preset); + } + else + { + infoLog("IMG Timer Fired: CH=" + channel + " PR=" + preset); + } mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo); } } @@ -626,7 +650,7 @@ public class MicroPhotoService extends Service { nextPhotoTime *= 1000; if (nextPhotoTime > ts) { mHeartbeatDuration = duration; - registerHeartbeatTimer((int) ((nextPhotoTime - ts) % duration) + 999); + registerHeartbeatTimer((int) ((nextPhotoTime - ts) % duration)); } else { mHeartbeatDuration = duration; @@ -638,15 +662,20 @@ public class MicroPhotoService extends Service { } } - private void registerHeartbeatTimer(long timeout) { + private void registerHeartbeatTimer(long timeoutMs) { // 创建延迟意图 - long triggerTime = System.currentTimeMillis() + timeout; + long triggerTime = System.currentTimeMillis() + timeoutMs; + triggerTime -= (triggerTime % 1000); Intent alarmIntent = new Intent(); alarmIntent.setAction(ACTION_HEARTBEAT); alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration); alarmIntent.putExtra("HeartbeatTime", triggerTime); - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_HEARTBEAT, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); + + Date date = new Date(triggerTime); + String dateStr = (String) DateFormat.format("kk:mm:ss", date); + infoLog( "HB Reg " + Long.toString(triggerTime) + " at " + dateStr); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent); @@ -661,10 +690,20 @@ public class MicroPhotoService extends Service { intent.putExtra(EXTRA_PARAM_SCHEDULES, cnt); StringBuilder channelStr = new StringBuilder(); long val = 0; + long channel = 0; for (int idx = 0; idx < cnt; idx++) { val = schedules.get(idx).longValue(); + channel = ((val & 0XFFFF000) >> 12); intent.putExtra(EXTRA_PARAM_SCHEDULE + idx, schedules.get(idx).longValue()); - channelStr.append("(" + ((val & 0XFF0000) >> 16) + "-" + Long.toString (((val & 0XFF00) >> 8), 16).toUpperCase() + ") "); + if (channel > 0xFF) + { + channel &= 0xFF; + channelStr.append("(" + channel + "-" + Long.toString (((val & 0XFF0) >> 4), 16).toUpperCase() + "/SERIAL) "); + } + else + { + channelStr.append("(" + channel + "-" + Long.toString (((val & 0XFF0) >> 4), 16).toUpperCase() + "/IMG) "); + } } intent.putExtra(EXTRA_PARAM_TIME, scheduleTime); @@ -675,7 +714,7 @@ public class MicroPhotoService extends Service { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); localBroadcastManager.sendBroadcast(intent); } else { - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, BROADCAST_REQUEST_CODE_TAKING_PHOTO, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); try { @@ -684,12 +723,12 @@ public class MicroPhotoService extends Service { ex.printStackTrace(); } + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent); + long currentTimeMillis = System.currentTimeMillis(); Date date = new Date(currentTimeMillis + timeout); String dateStr = (String) DateFormat.format("MM-dd kk:mm:ss", date); - Log.d(TAG, "PhotoTimer Reg: " + dateStr + " currentTimeMillis=" + currentTimeMillis + " timeout=" + timeout + " CH-PR=" + channelStr.toString()); - - alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent); + infoLog( "Timer Reg: " + dateStr + " TS=" + currentTimeMillis + " Timeout=" + timeout + " " + channelStr.toString()); } } @@ -982,7 +1021,7 @@ public class MicroPhotoService extends Service { alarmIntent.setPackage(context.getPackageName()); alarmIntent.setAction(ACTION_STOP); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, alarmIntent, 0); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), mPendingIntentFeed.getAndIncrement(), alarmIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getApplicationContext().getSystemService(ALARM_SERVICE); alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 100, pendingIntent); @@ -1384,7 +1423,7 @@ public class MicroPhotoService extends Service { Intent intent = new Intent(); intent.setAction(ACTION_GPS_TIMEOUT); - mPreviousGpsTimer = PendingIntent.getBroadcast(this, 0, intent, 0); + mPreviousGpsTimer = PendingIntent.getBroadcast(this, mPendingIntentFeed.getAndIncrement(), intent, 0); alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mGpsTimeout, mPreviousGpsTimer); } catch (Exception ex) { diff --git a/mpmaster/build.gradle b/mpmaster/build.gradle index 362a334d..68de669a 100644 --- a/mpmaster/build.gradle +++ b/mpmaster/build.gradle @@ -4,7 +4,7 @@ plugins { def AppMajorVersion = 1 def AppMinorVersion = 0 -def AppBuildNumber = 88 +def AppBuildNumber = 90 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index 1030a698..0b9219f2 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -390,6 +390,9 @@ public class MpMasterService extends Service { public boolean shouldSyncTime() { return mSyncTime; } public void startMpApp() { + if (true) { + return; + } try { final Context context = getApplicationContext(); long ts = System.currentTimeMillis(); @@ -417,7 +420,10 @@ public class MpMasterService extends Service { ex.printStackTrace(); } - if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) { + long tempduration = mMpHeartbeatDuration; + if(mMpHeartbeatDuration < 600000) + tempduration = 300000; + if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > tempduration * 2) { // MpApp is not running if (ts - mTimeToStartMpApp >= 1800000) { MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection"); @@ -440,9 +446,10 @@ public class MpMasterService extends Service { final long modifiedTimeOfPhoto = getFileModificationTime(appPath + "data/alive/taking"); final long modifiedTimeOfUpload = getFileModificationTime(appPath + "data/alive/upload"); - if (((ts - modifiedTimeOfHb) > mTimeOfMpAppAlive) || - ((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) || - ((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4)) { + if (((ts - modifiedTimeOfHb) > mTimeOfMpAppAlive) //|| +// ((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) || +// ((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4) + ) { if (ts - mTimeToStartMpApp >= 1800000) { String msg = "Restart MpAPP as it is NOT Running hb=" + Long.toString(ts - modifiedTimeOfHb) + @@ -811,9 +818,8 @@ public class MpMasterService extends Service { if (keepAlive) { alarmIntent.putExtra("keepAlive", keepAlive); } - int uniqueReqCode = reqCode.getAndIncrement(); - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); -// PendingIntent pendingIntent = PendingIntent.getBroadcast(this, keepAlive ? 0 : 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); +// PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, keepAlive ? 0 : 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); Date dt = new Date(triggerTime);