Matthew 4 months ago
commit bf91569905

@ -359,7 +359,7 @@ bool GpioControl::GetCamerastatus()
bool GpioControl::GetSelftestStatus(time_t wait_time) bool GpioControl::GetSelftestStatus(time_t wait_time)
{ {
int cmd; int cmd = 0;
#ifdef USING_N938 #ifdef USING_N938
cmd = CMD_SET_PIC1_POWER; cmd = CMD_SET_PIC1_POWER;
#endif #endif
@ -379,6 +379,28 @@ bool GpioControl::GetSelftestStatus(time_t wait_time)
} }
time_t GpioControl::GetSelfTestRemain(time_t wait_time)
{
int cmd = 0;
#ifdef USING_N938
cmd = CMD_SET_PIC1_POWER;
#endif
#ifdef USING_PLZ
cmd = CMD_SET_PTZ_PWR_ENABLE;
#endif
time_t now = time(NULL);
std::vector<ITEM>::iterator it;
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == cmd && it->openTime!=0 && (now - it->openTime <= wait_time))
{
time_t remaintime =wait_time - (now - it->openTime);
return remaintime;//自检完成
}
}
return 0;
}
void GpioControl::PowerControlThreadProc() void GpioControl::PowerControlThreadProc()
{ {
time_t ts = 0; time_t ts = 0;

@ -183,6 +183,7 @@ public:
static bool SetCamerastatus(int cmd, bool status); static bool SetCamerastatus(int cmd, bool status);
static bool GetCamerastatus(); static bool GetCamerastatus();
static bool GetSelftestStatus(time_t wait_time); static bool GetSelftestStatus(time_t wait_time);
static time_t GetSelfTestRemain(time_t wait_time);
static void PowerControlThreadProc(); static void PowerControlThreadProc();

@ -494,8 +494,6 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_signalLevel = 0; m_signalLevel = 0;
m_signalLevelUpdateTime = time(NULL); m_signalLevelUpdateTime = time(NULL);
mBuildTime = 0; mBuildTime = 0;
m_cameraStatus = false;
m_sensorsStatus = false;
m_lastTime = 0; m_lastTime = 0;
m_shouldStopWaiting = false; m_shouldStopWaiting = false;
m_collecting = false; m_collecting = false;
@ -1527,8 +1525,10 @@ bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
uint32_t waitTime = localPhotoInfo.selfTestingTime; uint32_t waitTime = localPhotoInfo.selfTestingTime;
if(!GpioControl::GetSelftestStatus(waitTime)) if(!GpioControl::GetSelftestStatus(waitTime))
{ {
m_isSelfTesting.store(true);
waitTime = (waitTime != 0) ? (waitTime * 1024) : 10240; waitTime = (waitTime != 0) ? (waitTime * 1024) : 10240;
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
m_isSelfTesting.store(false);
} }
XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power ON"); XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power ON");
@ -1950,9 +1950,12 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
uint32_t waitTime = localPhotoInfo.selfTestingTime; uint32_t waitTime = localPhotoInfo.selfTestingTime;
if(!GpioControl::GetSelftestStatus(waitTime)) if(!GpioControl::GetSelftestStatus(waitTime))
{ {
XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting, selfTestingtime=%u", waitTime); pThis->m_isSelfTesting.store(true);
waitTime = (waitTime != 0) ? (waitTime * 1024) : 10240; time_t remaintime = GpioControl::GetSelfTestRemain(waitTime);
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting,remaining selfTestingtime=%u", remaintime);
remaintime = (remaintime != 0) ? (remaintime * 1024) : 10240;
std::this_thread::sleep_for(std::chrono::milliseconds(remaintime));
pThis->m_isSelfTesting.store(false);
XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over"); XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over");
} }
@ -2054,25 +2057,20 @@ bool CPhoneDevice::OpenPTZSensors(uint32_t sec)
{ {
uint64_t wid = RequestWakelock(0); uint64_t wid = RequestWakelock(0);
unsigned long long time_now = GetMicroTimeStamp(); unsigned long long time_now = GetMicroTimeStamp();
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
if(time_now < localDelayTime-1000)
{
m_sensorsStatus = true;
m_cameraStatus = true;
OpenSensors(MAIN_POWER_OPEN); OpenSensors(MAIN_POWER_OPEN);
OpenSensors(CAMERA_SENSOR_OPEN); OpenSensors(CAMERA_SENSOR_OPEN);
}else if (!m_cameraStatus && !m_sensorsStatus)
if (m_isSelfTesting.load() || (GpioControl::GetCamerastatus() && GpioControl::GetSelftestStatus(sec)))
{ {
m_sensorsStatus = true; ReleaseWakelock(wid);
OpenSensors(MAIN_POWER_OPEN); return true;
OpenSensors(CAMERA_SENSOR_OPEN);
} }
}
if(m_sensorsStatus && !m_cameraStatus) if(GpioControl::GetCamerastatus() && !GpioControl::GetSelftestStatus(sec))
{ {
m_isSelfTesting.store(true);
XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting, selfTestingtime=%u", sec); XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting, selfTestingtime=%u", sec);
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
while (std::chrono::steady_clock::now() - start < std::chrono::seconds(sec)) while (std::chrono::steady_clock::now() - start < std::chrono::seconds(sec))
@ -2081,62 +2079,45 @@ bool CPhoneDevice::OpenPTZSensors(uint32_t sec)
{ {
CloseSensors(CAMERA_SENSOR_OPEN, 0); CloseSensors(CAMERA_SENSOR_OPEN, 0);
CloseSensors(MAIN_POWER_OPEN, 0); CloseSensors(MAIN_POWER_OPEN, 0);
m_cameraStatus = false;
m_sensorsStatus = false;
m_shouldStopWaiting.store(false); m_shouldStopWaiting.store(false);
m_isSelfTesting.store(false);
ReleaseWakelock(wid); ReleaseWakelock(wid);
return false; return false;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
} m_isSelfTesting.store(false);
m_shouldStopWaiting.store(false);
// if(m_sensorsStatus && !m_cameraStatus)
// std::this_thread::sleep_for(std::chrono::seconds(sec));
{
std::lock_guard<std::mutex> lock(m_cameraLocker);
// std::unique_lock<std::mutex> lock(m_cameraLocker);
if (!m_cameraStatus && m_sensorsStatus)
{
m_cameraStatus = true;
unsigned long long time_over = GetMicroTimeStamp(); unsigned long long time_over = GetMicroTimeStamp();
XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over, selfTestingtime=%u", (time_over - time_now)/1000); XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over, selfTestingtime=%u", (time_over - time_now)/1000);
} }
}
ReleaseWakelock(wid); ReleaseWakelock(wid);
return true;
return m_cameraStatus;
} }
bool CPhoneDevice::ClosePTZSensors(uint32_t delayedCloseTime) bool CPhoneDevice::ClosePTZSensors(uint32_t delayedCloseTime)
{ {
localDelayTime = GetMicroTimeStamp() + delayedCloseTime*1000; if(m_isSelfTesting.load())
if(m_sensorsStatus && !m_cameraStatus)
{ {
localDelayTime = GetMicroTimeStamp();
m_shouldStopWaiting.store(true); m_shouldStopWaiting.store(true);
} }else
else
{ {
std::lock_guard<std::mutex> lock(m_cameraLocker);
// std::unique_lock<std::mutex> lock(m_cameraLocker);
CloseSensors(CAMERA_SENSOR_OPEN, delayedCloseTime); CloseSensors(CAMERA_SENSOR_OPEN, delayedCloseTime);
CloseSensors(MAIN_POWER_OPEN, delayedCloseTime); CloseSensors(MAIN_POWER_OPEN, delayedCloseTime);
m_cameraStatus = false;
m_sensorsStatus = false;
} }
return true; return true;
} }
bool CPhoneDevice::GetPTZSensorsStatus() bool CPhoneDevice::GetPTZSensorsStatus(time_t waittime)
{ {
return m_sensorsStatus; return GpioControl::GetSelftestStatus(waittime);
} }
bool CPhoneDevice::GetCameraStatus() bool CPhoneDevice::GetCameraStatus()
{ {
return m_cameraStatus; return GpioControl::GetCamerastatus();
} }
bool CPhoneDevice::CloseCamera() bool CPhoneDevice::CloseCamera()
@ -3959,7 +3940,7 @@ void CPhoneDevice::ConvertDngToPng(const std::string& dngPath, const std::string
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) 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)
{ {
if(!(m_sensorsStatus && !m_cameraStatus) && GpioControl::GetCamerastatus()) { if(GpioControl::GetSelftestStatus(waitTime) && GpioControl::GetCamerastatus()) {
CPhoneDevice *pThis = this; CPhoneDevice *pThis = this;
string serfileStr(serfile); string serfileStr(serfile);
std::thread ctrlThread([pThis, waitTime, delayTime, cmdidx, channel, preset, serfileStr, baud, std::thread ctrlThread([pThis, waitTime, delayTime, cmdidx, channel, preset, serfileStr, baud,

@ -237,7 +237,7 @@ public:
virtual bool CloseSensors(int sensortype, uint32_t delayedCloseTime); virtual bool CloseSensors(int sensortype, uint32_t delayedCloseTime);
virtual bool OpenPTZSensors(uint32_t sec); virtual bool OpenPTZSensors(uint32_t sec);
virtual bool ClosePTZSensors(uint32_t delayedCloseTime); virtual bool ClosePTZSensors(uint32_t delayedCloseTime);
virtual bool GetPTZSensorsStatus(); virtual bool GetPTZSensorsStatus(time_t waittime);
virtual bool GetCameraStatus(); virtual bool GetCameraStatus();
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 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 int GetSerialPhoto(int devno, D_IMAGE_DEF *photo);
@ -406,10 +406,9 @@ protected:
std::string m_simcard; std::string m_simcard;
mutable std::mutex m_cameraLocker; mutable std::mutex m_cameraLocker;
bool m_cameraStatus;
bool m_sensorsStatus;
time_t m_lastTime; time_t m_lastTime;
std::atomic<bool> m_shouldStopWaiting; std::atomic<bool> m_shouldStopWaiting;
std::atomic<bool> m_isSelfTesting{false};
IDevice::ICE_TAIL m_tempData; IDevice::ICE_TAIL m_tempData;
mutable std::mutex m_dataLocker; mutable std::mutex m_dataLocker;

Loading…
Cancel
Save