From c6eee571158bf79e5d07f1f2a15ea9d85f0d1d93 Mon Sep 17 00:00:00 2001 From: "XI.CHEN" Date: Tue, 26 Nov 2024 17:31:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8B=8D=E7=85=A7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E9=A2=84=E7=BD=AE=E4=BD=8D=EF=BC=8C=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E5=85=B3=E7=94=B5=E6=BA=90=E4=B8=8D=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E8=87=AA=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 57 ++++++++++++++++++++++++++------ app/src/main/cpp/PhoneDevice.h | 1 + 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index a5351aa0..cf8c3e3f 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -441,6 +441,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa m_cameraStatus = false; m_sensorsStatus = false; m_lastTime = 0; + m_shouldStopWaiting = false; RegisterHandlerForSignal(SIGUSR2); @@ -1690,9 +1691,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< } else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_SERIAL)) { - // if (photoInfo.mediaType == 0) { - // CameraPhotoCmd(time(NULL), channel, MOVE_PRESETNO, 0, type); - // std::this_thread::sleep_for(std::chrono::seconds(2)); + if (photoInfo.preset != 0 && photoInfo.preset != 0xFF) + { + CameraPhotoCmd(time(NULL), photoInfo.channel, MOVE_PRESETNO, 0, photoInfo.preset); + std::this_thread::sleep_for(std::chrono::seconds(2)); + } time_t ts = time(NULL); CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0); TakePTZPhotoCb(3, photoInfo); @@ -1783,7 +1786,9 @@ bool CPhoneDevice::OpenPTZSensors(int sec) { { std::lock_guard lock(m_cameraLocker); - if (!m_cameraStatus && !m_sensorsStatus) { +// std::unique_lock lock(m_cameraLocker); + if (!m_cameraStatus && !m_sensorsStatus) + { m_sensorsStatus = true; OpenSensors(MAIN_POWER_OPEN); OpenSensors(CAMERA_SENSOR_OPEN); @@ -1792,25 +1797,55 @@ bool CPhoneDevice::OpenPTZSensors(int sec) } if(m_sensorsStatus && !m_cameraStatus) - std::this_thread::sleep_for(std::chrono::seconds(sec)); + { + auto start = std::chrono::steady_clock::now(); + while (std::chrono::steady_clock::now() - start < std::chrono::seconds(sec)) + { + if (m_shouldStopWaiting.load()) + { + CloseSensors(CAMERA_SENSOR_OPEN); + CloseSensors(MAIN_POWER_OPEN); + m_cameraStatus = false; + m_sensorsStatus = false; + m_shouldStopWaiting.store(false); + return false; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + } + +// if(m_sensorsStatus && !m_cameraStatus) +// std::this_thread::sleep_for(std::chrono::seconds(sec)); { std::lock_guard lock(m_cameraLocker); - if (!m_cameraStatus && m_sensorsStatus) { +// std::unique_lock lock(m_cameraLocker); + if (!m_cameraStatus && m_sensorsStatus) + { m_cameraStatus = true; } } return m_cameraStatus; + + } bool CPhoneDevice::ClosePTZSensors() { - std::lock_guard lock(m_cameraLocker); - CloseSensors(CAMERA_SENSOR_OPEN); - CloseSensors(MAIN_POWER_OPEN); - m_cameraStatus = false; - m_sensorsStatus = false; + if(m_sensorsStatus && !m_cameraStatus) + { + m_shouldStopWaiting.store(true); + } + else + { + std::lock_guard lock(m_cameraLocker); +// std::unique_lock lock(m_cameraLocker); + CloseSensors(CAMERA_SENSOR_OPEN); + CloseSensors(MAIN_POWER_OPEN); + m_cameraStatus = false; + m_sensorsStatus = false; + } return true; } diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index f24ca7f1..367a24fc 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -396,6 +396,7 @@ protected: bool m_cameraStatus; bool m_sensorsStatus; time_t m_lastTime; + std::atomic m_shouldStopWaiting; }; From fefa90b01f31e334806e3c56fd75e31b96abfeac Mon Sep 17 00:00:00 2001 From: "XI.CHEN" Date: Wed, 27 Nov 2024 10:31:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=87=8F=E5=B0=91=E7=94=B5=E6=BA=90?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index cf8c3e3f..81161013 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1810,7 +1810,7 @@ bool CPhoneDevice::OpenPTZSensors(int sec) m_shouldStopWaiting.store(false); return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); } } From e7da756eec574d0f7cb0be9e864687d321989646 Mon Sep 17 00:00:00 2001 From: "XI.CHEN" Date: Wed, 27 Nov 2024 17:01:08 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B0=94=E8=B1=A1?= =?UTF-8?q?=E8=A6=86=E5=86=B0=E5=86=85=E5=AD=98=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 146 ++++++++++++++++++++++++------- app/src/main/cpp/PhoneDevice.h | 3 + 2 files changed, 119 insertions(+), 30 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 81161013..6aeba2be 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -3479,6 +3479,11 @@ void CPhoneDevice::SetStaticIp(const std::string& iface, const std::string& ip, int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceTail, SENSOR_PARAM *sensorParam) { + m_tempData.instantaneous_windspeed = 0; + m_tempData.air_temperature = 0; + m_tempData.instantaneous_winddirection = 0; + m_tempData.humidity = 0; + Collect_sensor_data(); //15s Data_DEF airt; //++等值覆冰厚度, 综合悬挂载荷, 不均衡张力差 置0 @@ -3493,54 +3498,135 @@ int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceT if(sensorParam[num].SensorsType == RALLY_PROTOCOL) { GetPullValue(num, &airt); - iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue; + if(airt.AiState == 2) + iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue; pullno++; } else if(sensorParam[num].SensorsType == SLANT_PROTOCOL) { GetAngleValue(num, &airt, 0); - iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue; + if(airt.AiState == 2) + iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue; GetAngleValue(num, &airt, 1); - iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue; + if(airt.AiState == 2) + iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue; angleno++; } } - GetWindSpeedData(&airt); - iceTail->instantaneous_windspeed = airt.EuValue; - GetWindDirectionData(&airt); - iceTail->instantaneous_winddirection = airt.EuValue;//需求无符号整数给出浮点数 - GetAirTempData(&airt); - iceTail->air_temperature = airt.EuValue; - GetHumidityData(&airt); - iceTail->humidity = airt.EuValue;//需求无符号整数给出浮点数 + { + std::lock_guard lock(m_dataLocker); + GetWindSpeedData(&airt); + if(airt.AiState == 2) + { + iceTail->instantaneous_windspeed = airt.EuValue; + m_tempData.instantaneous_windspeed = iceTail->instantaneous_windspeed; + } else + { + iceTail->instantaneous_windspeed = m_tempData.instantaneous_windspeed; + m_tempData.instantaneous_windspeed = 0; + } + GetWindDirectionData(&airt); + if(airt.AiState == 2) + { + iceTail->instantaneous_winddirection = airt.EuValue; + m_tempData.instantaneous_winddirection = iceTail->instantaneous_winddirection; + } else + { + iceTail->instantaneous_winddirection = m_tempData.instantaneous_winddirection; + m_tempData.instantaneous_winddirection = 0; + } + GetAirTempData(&airt); + if(airt.AiState == 2) { + iceTail->air_temperature = airt.EuValue; + m_tempData.air_temperature = iceTail->air_temperature; + } else + { + iceTail->air_temperature = m_tempData.air_temperature; + m_tempData.air_temperature = 0; + } + GetHumidityData(&airt); + if(airt.AiState == 2) + { + iceTail->humidity = airt.EuValue; + m_tempData.humidity = iceTail->humidity; + } else + { + iceTail->humidity = m_tempData.humidity; + m_tempData.humidity = 0; + } + + } return true; } int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo) { + m_tempData.instantaneous_windspeed = 0; + m_tempData.air_temperature = 0; + m_tempData.instantaneous_winddirection = 0; + m_tempData.humidity = 0; + Collect_sensor_data(); //15s Data_DEF airt; - GetWeatherData(&airt, 0); - weatherInfo->air_temperature = airt.EuValue; - GetWeatherData(&airt, 1); - weatherInfo->humidity = airt.EuValue; - GetWeatherData(&airt, 2); - weatherInfo->avg_windspeed_10min = airt.EuValue; - weatherInfo->extreme_windspeed = airt.EuValue; - weatherInfo->standard_windspeed = airt.EuValue; - GetWeatherData(&airt, 3); - weatherInfo->avg_winddirection_10min = airt.EuValue; - GetWeatherData(&airt, 4); - if(airt.AiState == 2) - weatherInfo->precipitation = airt.EuValue; - GetWeatherData(&airt, 5); - if(airt.AiState == 2) - weatherInfo->air_pressure = airt.EuValue; - GetWeatherData(&airt, 6); - if(airt.AiState == 2) - weatherInfo->radiation_intensity = airt.EuValue; + { + std::lock_guard lock(m_dataLocker); + GetWeatherData(&airt, 2); + if(airt.AiState == 2) + { + weatherInfo->avg_windspeed_10min = airt.EuValue; + weatherInfo->extreme_windspeed = airt.EuValue; + weatherInfo->standard_windspeed = airt.EuValue; + m_tempData.instantaneous_windspeed = weatherInfo->avg_windspeed_10min; + } else + { + weatherInfo->avg_windspeed_10min = m_tempData.instantaneous_windspeed; + weatherInfo->extreme_windspeed = m_tempData.instantaneous_windspeed; + weatherInfo->standard_windspeed = m_tempData.instantaneous_windspeed; + m_tempData.instantaneous_windspeed = 0; + } + GetWeatherData(&airt, 3); + if(airt.AiState == 2) + { + weatherInfo->avg_winddirection_10min = airt.EuValue; + m_tempData.instantaneous_winddirection = weatherInfo->avg_winddirection_10min; + } else + { + weatherInfo->avg_winddirection_10min = m_tempData.instantaneous_winddirection; + m_tempData.instantaneous_winddirection = 0; + } + GetWeatherData(&airt, 0); + if(airt.AiState == 2) + { + weatherInfo->air_temperature = airt.EuValue; + m_tempData.air_temperature = weatherInfo->air_temperature; + } else + { + weatherInfo->air_temperature = m_tempData.air_temperature; + m_tempData.air_temperature = 0; + } + GetWeatherData(&airt, 1); + if(airt.AiState == 2) + { + weatherInfo->humidity = airt.EuValue; + m_tempData.humidity = weatherInfo->humidity; + } else + { + weatherInfo->humidity = m_tempData.humidity; + m_tempData.humidity = 0; + } + GetWeatherData(&airt, 4); + if(airt.AiState == 2) + weatherInfo->precipitation = airt.EuValue; + GetWeatherData(&airt, 5); + if(airt.AiState == 2) + weatherInfo->air_pressure = airt.EuValue; + GetWeatherData(&airt, 6); + if(airt.AiState == 2) + weatherInfo->radiation_intensity = airt.EuValue; + } + return true; } diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 367a24fc..bdb0d603 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -398,6 +398,9 @@ protected: time_t m_lastTime; std::atomic m_shouldStopWaiting; + IDevice::ICE_TAIL m_tempData; + mutable std::mutex m_dataLocker; + };