Matthew 7 months ago
commit 02037ac34f

@ -441,6 +441,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_cameraStatus = false; m_cameraStatus = false;
m_sensorsStatus = false; m_sensorsStatus = false;
m_lastTime = 0; m_lastTime = 0;
m_shouldStopWaiting = false;
RegisterHandlerForSignal(SIGUSR2); 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)) else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_SERIAL))
{ {
// if (photoInfo.mediaType == 0) { if (photoInfo.preset != 0 && photoInfo.preset != 0xFF)
// CameraPhotoCmd(time(NULL), channel, MOVE_PRESETNO, 0, type); {
// std::this_thread::sleep_for(std::chrono::seconds(2)); CameraPhotoCmd(time(NULL), photoInfo.channel, MOVE_PRESETNO, 0, photoInfo.preset);
std::this_thread::sleep_for(std::chrono::seconds(2));
}
time_t ts = time(NULL); time_t ts = time(NULL);
CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0); CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0);
TakePTZPhotoCb(3, photoInfo); TakePTZPhotoCb(3, photoInfo);
@ -1783,7 +1786,9 @@ bool CPhoneDevice::OpenPTZSensors(int sec)
{ {
{ {
std::lock_guard<std::mutex> lock(m_cameraLocker); std::lock_guard<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && !m_sensorsStatus) { // std::unique_lock<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && !m_sensorsStatus)
{
m_sensorsStatus = true; m_sensorsStatus = true;
OpenSensors(MAIN_POWER_OPEN); OpenSensors(MAIN_POWER_OPEN);
OpenSensors(CAMERA_SENSOR_OPEN); OpenSensors(CAMERA_SENSOR_OPEN);
@ -1792,25 +1797,55 @@ bool CPhoneDevice::OpenPTZSensors(int sec)
} }
if(m_sensorsStatus && !m_cameraStatus) 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(200));
}
}
// if(m_sensorsStatus && !m_cameraStatus)
// std::this_thread::sleep_for(std::chrono::seconds(sec));
{ {
std::lock_guard<std::mutex> lock(m_cameraLocker); std::lock_guard<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && m_sensorsStatus) { // std::unique_lock<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && m_sensorsStatus)
{
m_cameraStatus = true; m_cameraStatus = true;
} }
} }
return m_cameraStatus; return m_cameraStatus;
} }
bool CPhoneDevice::ClosePTZSensors() bool CPhoneDevice::ClosePTZSensors()
{ {
if(m_sensorsStatus && !m_cameraStatus)
{
m_shouldStopWaiting.store(true);
}
else
{
std::lock_guard<std::mutex> lock(m_cameraLocker); std::lock_guard<std::mutex> lock(m_cameraLocker);
// std::unique_lock<std::mutex> lock(m_cameraLocker);
CloseSensors(CAMERA_SENSOR_OPEN); CloseSensors(CAMERA_SENSOR_OPEN);
CloseSensors(MAIN_POWER_OPEN); CloseSensors(MAIN_POWER_OPEN);
m_cameraStatus = false; m_cameraStatus = false;
m_sensorsStatus = false; m_sensorsStatus = false;
}
return true; return true;
} }
@ -3444,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) 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 Collect_sensor_data(); //15s
Data_DEF airt; Data_DEF airt;
//++等值覆冰厚度, 综合悬挂载荷, 不均衡张力差 置0 //++等值覆冰厚度, 综合悬挂载荷, 不均衡张力差 置0
@ -3458,45 +3498,124 @@ int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceT
if(sensorParam[num].SensorsType == RALLY_PROTOCOL) if(sensorParam[num].SensorsType == RALLY_PROTOCOL)
{ {
GetPullValue(num, &airt); GetPullValue(num, &airt);
if(airt.AiState == 2)
iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue; iceInfo->t_sensor_data[pullno].original_tension = airt.EuValue;
pullno++; pullno++;
} else if(sensorParam[num].SensorsType == SLANT_PROTOCOL) } else if(sensorParam[num].SensorsType == SLANT_PROTOCOL)
{ {
GetAngleValue(num, &airt, 0); GetAngleValue(num, &airt, 0);
if(airt.AiState == 2)
iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue; iceInfo->t_sensor_data[angleno].deflection_angle = airt.EuValue;
GetAngleValue(num, &airt, 1); GetAngleValue(num, &airt, 1);
if(airt.AiState == 2)
iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue; iceInfo->t_sensor_data[angleno].windage_yaw_angle = airt.EuValue;
angleno++; angleno++;
} }
} }
{
std::lock_guard<std::mutex> lock(m_dataLocker);
GetWindSpeedData(&airt); GetWindSpeedData(&airt);
if(airt.AiState == 2)
{
iceTail->instantaneous_windspeed = airt.EuValue; 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); GetWindDirectionData(&airt);
iceTail->instantaneous_winddirection = airt.EuValue;//需求无符号整数给出浮点数 if(airt.AiState == 2)
{
iceTail->instantaneous_winddirection = airt.EuValue;
m_tempData.instantaneous_winddirection = iceTail->instantaneous_winddirection;
} else
{
iceTail->instantaneous_winddirection = m_tempData.instantaneous_winddirection;
m_tempData.instantaneous_winddirection = 0;
}
GetAirTempData(&airt); GetAirTempData(&airt);
if(airt.AiState == 2) {
iceTail->air_temperature = airt.EuValue; 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); GetHumidityData(&airt);
iceTail->humidity = airt.EuValue;//需求无符号整数给出浮点数 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; return true;
} }
int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo) 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 Collect_sensor_data(); //15s
Data_DEF airt; Data_DEF airt;
GetWeatherData(&airt, 0); {
weatherInfo->air_temperature = airt.EuValue; std::lock_guard<std::mutex> lock(m_dataLocker);
GetWeatherData(&airt, 1);
weatherInfo->humidity = airt.EuValue;
GetWeatherData(&airt, 2); GetWeatherData(&airt, 2);
if(airt.AiState == 2)
{
weatherInfo->avg_windspeed_10min = airt.EuValue; weatherInfo->avg_windspeed_10min = airt.EuValue;
weatherInfo->extreme_windspeed = airt.EuValue; weatherInfo->extreme_windspeed = airt.EuValue;
weatherInfo->standard_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); GetWeatherData(&airt, 3);
if(airt.AiState == 2)
{
weatherInfo->avg_winddirection_10min = airt.EuValue; 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); GetWeatherData(&airt, 4);
if(airt.AiState == 2) if(airt.AiState == 2)
weatherInfo->precipitation = airt.EuValue; weatherInfo->precipitation = airt.EuValue;
@ -3506,6 +3625,8 @@ int CPhoneDevice::GetWData(IDevice::WEATHER_INFO *weatherInfo)
GetWeatherData(&airt, 6); GetWeatherData(&airt, 6);
if(airt.AiState == 2) if(airt.AiState == 2)
weatherInfo->radiation_intensity = airt.EuValue; weatherInfo->radiation_intensity = airt.EuValue;
}
return true; return true;
} }

@ -396,6 +396,10 @@ protected:
bool m_cameraStatus; bool m_cameraStatus;
bool m_sensorsStatus; bool m_sensorsStatus;
time_t m_lastTime; time_t m_lastTime;
std::atomic<bool> m_shouldStopWaiting;
IDevice::ICE_TAIL m_tempData;
mutable std::mutex m_dataLocker;
}; };

Loading…
Cancel
Save