liuguijing 6 months ago
commit 8dabf9aecc

@ -5,7 +5,7 @@ plugins {
// 10,00,000 major-minor-build // 10,00,000 major-minor-build
def AppMajorVersion = 1 def AppMajorVersion = 1
def AppMinorVersion = 1 def AppMinorVersion = 1
def AppBuildNumber = 20 def AppBuildNumber = 41
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber
@ -86,12 +86,14 @@ android {
variant.outputs.all { output -> variant.outputs.all { output ->
if (outputFileName.endsWith('.apk')) { if (outputFileName.endsWith('.apk')) {
def buildTypeFlag = "dbg" def buildTypeFlag = "dbg"
def prevFileName = "mpapp"
if(variant.buildType.name.equals('release')) { if(variant.buildType.name.equals('release')) {
buildTypeFlag = "rel" buildTypeFlag = "rel"
} }
def abi = output.getFilter(com.android.build.OutputFile.ABI) def abi = output.getFilter(com.android.build.OutputFile.ABI)
if (abi == null) abi = "all" 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 outputFileName = fileName
} }
} }

@ -47,7 +47,7 @@ add_definitions(-DUSING_EXEC_HDRP=1)
set(USING_EXEC_HDRP 1) set(USING_EXEC_HDRP 1)
add_definitions(-DUSING_PLZ) # add_definitions(-DUSING_PLZ)
if(ANDROID_ABI STREQUAL "armeabi-v7a") if(ANDROID_ABI STREQUAL "armeabi-v7a")
add_definitions(-DUSING_N938) add_definitions(-DUSING_N938)

@ -27,6 +27,7 @@ CSemaphore GpioControl::m_semaphore;
std::vector<GpioControl::ITEM> GpioControl::m_items; std::vector<GpioControl::ITEM> GpioControl::m_items;
std::thread GpioControl::m_thread; std::thread GpioControl::m_thread;
bool GpioControl::m_exitSignal = false; bool GpioControl::m_exitSignal = false;
bool GpioControl::m_cameraPowerStatus = false;
size_t GpioControl::turnOnImpl(const IOT_PARAM& param) size_t GpioControl::turnOnImpl(const IOT_PARAM& param)
{ {
@ -48,6 +49,7 @@ size_t GpioControl::turnOnImpl(const IOT_PARAM& param)
it->references++; it->references++;
it->closeTime = 0; it->closeTime = 0;
references = it->references; references = it->references;
SetCamerastatus(it->cmd, true);
break; break;
} }
} }
@ -198,6 +200,30 @@ size_t GpioControl::TurnOn(const std::vector<int>& cmds)
return 0; return 0;
} }
size_t GpioControl::TurnOffImmediately(int cmd)
{
time_t ts = time(NULL);
size_t ref = 0;
std::vector<ITEM>::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*/) size_t GpioControl::TurnOff(int cmd, uint32_t delayedCloseTime/* = 0*/)
{ {
time_t ts = 0; time_t ts = 0;
@ -274,6 +300,7 @@ size_t GpioControl::TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds)
{ {
if (it->cmd == itCmd->first) if (it->cmd == itCmd->first)
{ {
it->closeCmds++; it->closeCmds++;
if (itCmd->second != 0) if (itCmd->second != 0)
{ {
@ -292,6 +319,22 @@ size_t GpioControl::TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds)
return 0; 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() void GpioControl::PowerControlThreadProc()
{ {
@ -302,6 +345,7 @@ void GpioControl::PowerControlThreadProc()
time_t delayTime = 0; time_t delayTime = 0;
int fd = -1; int fd = -1;
int res = -1; int res = -1;
m_cameraPowerStatus = 0;
while(1) while(1)
{ {
@ -330,6 +374,8 @@ void GpioControl::PowerControlThreadProc()
else else
{ {
it->references -= it->closeCmds; it->references -= it->closeCmds;
if(it->references < 0)
it->references = 0;
} }
it->closeCmds = 0; it->closeCmds = 0;
} }
@ -345,6 +391,7 @@ void GpioControl::PowerControlThreadProc()
#ifdef _DEBUG #ifdef _DEBUG
ALOGI("PWR TH DO TurnOff cmd=%d", it->cmd); ALOGI("PWR TH DO TurnOff cmd=%d", it->cmd);
#endif #endif
SetCamerastatus(it->cmd, false);
} }
else else
{ {

@ -164,6 +164,7 @@ private:
static std::vector<ITEM> m_items; static std::vector<ITEM> m_items;
static bool m_exitSignal; static bool m_exitSignal;
static std::thread m_thread; static std::thread m_thread;
static bool m_cameraPowerStatus;
protected: protected:
static size_t turnOnImpl(const IOT_PARAM& param); 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(int cmd, uint32_t delayedCloseTime = 0);
static size_t TurnOff(const std::vector<int>& cmds, uint32_t delayedCloseTime = 0); static size_t TurnOff(const std::vector<int>& cmds, uint32_t delayedCloseTime = 0);
static size_t TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds); static size_t TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds);
static size_t TurnOffImmediately(int cmd);
static bool SetCamerastatus(int cmd, bool status);
static bool GetCamerastatus();
static void PowerControlThreadProc(); 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) PowerControl(CMD_SET_OTG_STATE, CMD_SET_NETWORK_POWER_EN, CMD_SET_PIC1_POWER, CMD_SET_485_EN_STATE, closeDelayTime)
#else // USING_N938 #else // USING_N938
#ifdef USING_PLZ #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 #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_PLZ
@ -539,6 +560,23 @@ public:
} }
}; };
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
{
}
};

@ -154,9 +154,9 @@ void posix_signal_handler(int sig, siginfo_t *siginfo, void *context)
class Runner class Runner
{ {
public: 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); pTerminal->RequestCapture(channel, preset, type, scheduleTime);
} }
@ -358,7 +358,7 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto(
JNIEnv* env, JNIEnv* env,
jobject pThis, jlong handler, jint channel, jint preset, jlong scheduleTime, jboolean photoOrVideo) { 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; return JNI_FALSE;
} }
@ -369,9 +369,18 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto(
} }
unsigned char type = photoOrVideo ? 0 : 1; 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(); // 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; return JNI_TRUE;
} }
@ -501,6 +510,7 @@ Java_com_xypower_mpapp_MicroPhotoService_uninit(
return JNI_FALSE; return JNI_FALSE;
} }
XYLOG(XYLOG_SEVERITY_WARNING, "Will uninit service");
IDevice* dev = pTerminal->GetDevice(); IDevice* dev = pTerminal->GetDevice();
if (dev != NULL) if (dev != NULL)
{ {
@ -559,7 +569,7 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData2(
vector<jlong> dataArray; vector<jlong> dataArray;
dataArray.reserve(numberOfData); dataArray.reserve(numberOfData);
unsigned long val = 0; uint64_t val = 0;
jint channel = 0; jint channel = 0;
for (map<unsigned char, vector<unsigned int>>::const_iterator it = photoTime.cbegin(); it != photoTime.cend(); ++it) for (map<unsigned char, vector<unsigned int>>::const_iterator it = photoTime.cbegin(); it != photoTime.cend(); ++it)
{ {
@ -576,11 +586,11 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData2(
for (vector<unsigned int>::const_iterator it2 = it->second.cbegin(); it2 != it->second.cend(); ++it2) for (vector<unsigned int>::const_iterator it2 = it->second.cbegin(); it2 != it->second.cend(); ++it2)
{ {
// time // time
val = ((unsigned long)((*it2) & 0xFFFFFF00)) << 24; val = ((uint64_t)((*it2) & 0xFFFFFF00)) << 24;
// channel // channel
val |= ((unsigned long)channel) << 16; val |= ((uint64_t)channel) << 16;
// preset // preset
val |= ((unsigned long)((*it2) & 0xFF)) << 8; val |= ((uint64_t)((*it2) & 0xFF)) << 8;
dataArray.push_back((jlong)val); dataArray.push_back((jlong)val);
} }
@ -612,7 +622,7 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData(
unsigned int scheduleTime = 0; unsigned int scheduleTime = 0;
time_t zeroPointTime = 0; time_t zeroPointTime = 0;
std::vector<std::pair<unsigned char, unsigned char> > channelsAndPresets; std::vector<std::pair<uint16_t, uint8_t> > channelsAndPresets;
if (!pTerminal->GetAndRefreshLatestScheduleTime(startTime, zeroPointTime, scheduleTime, channelsAndPresets)) if (!pTerminal->GetAndRefreshLatestScheduleTime(startTime, zeroPointTime, scheduleTime, channelsAndPresets))
{ {
return NULL; return NULL;
@ -630,14 +640,14 @@ Java_com_xypower_mpapp_MicroPhotoService_getPhotoTimeData(
dataArray.push_back((jlong)scheduleTime); dataArray.push_back((jlong)scheduleTime);
dataArray.push_back((jlong)channelsAndPresets.size()); dataArray.push_back((jlong)channelsAndPresets.size());
unsigned long val = 0; uint64_t val = 0;
for (std::vector<std::pair<unsigned char, unsigned char> >::const_iterator it = channelsAndPresets.cbegin(); it != channelsAndPresets.cend(); ++it) for (std::vector<std::pair<uint16_t, uint8_t> >::const_iterator it = channelsAndPresets.cbegin(); it != channelsAndPresets.cend(); ++it)
{ {
val = (unsigned long)scheduleTime << 24; val = (((uint64_t)scheduleTime) << 28);
// channel // channel
val |= ((unsigned long)(it->first)) << 16; val |= (((uint64_t)(it->first)) << 12);
// preset // preset
val |= ((unsigned long)(it->second)) << 8; val |= (((uint64_t)(it->second)) << 4);
dataArray.push_back((jlong)val); dataArray.push_back((jlong)val);
} }
@ -735,75 +745,6 @@ Java_com_xypower_mpapp_MicroPhotoService_recoganizePicture(
return data; return data;
} }
/*
extern "C" JNIEXPORT jlongArray JNICALL
Java_com_xypower_mpapp_MicroPhotoService_getNextScheduleItem(
JNIEnv* env,
jobject pThis, jlong handler) {
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
if (pTerminal == NULL)
{
return NULL;
}
map<unsigned char, vector<unsigned int>> photoTime;
if (!pTerminal->GetPhotoTime(photoTime) || photoTime.empty())
{
return NULL;
}
size_t numberOfData = photoTime.size() * photoTime.begin()->second.size();
if (numberOfData == 0)
{
return NULL;
}
vector<jlong> dataArray;
dataArray.reserve(numberOfData);
unsigned long val = 0;
jint channel = 0;
for (map<unsigned char, vector<unsigned int>>::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<unsigned int>::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 extern "C" JNIEXPORT void JNICALL
Java_com_xypower_mpapp_MicroPhotoService_captureFinished( Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
JNIEnv* env, JNIEnv* env,
@ -821,7 +762,7 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
if (result == JNI_FALSE || bitmap == NULL) if (result == JNI_FALSE || bitmap == NULL)
{ {
cv::Mat mat; 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; return;
} }
AndroidBitmapInfo info = { 0 }; AndroidBitmapInfo info = { 0 };
@ -845,7 +786,7 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
cv::cvtColor(mat, mat, cv::COLOR_RGB2BGR); 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 #endif // 0
} else } else
{ {
@ -862,7 +803,7 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished(
AndroidBitmap_unlockPixels(env, bitmap); 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) if (result == JNI_FALSE)
{ {
cv::Mat mat; cv::Mat mat;
((CPhoneDevice *)dev)->OnCaptureReady(true, false, mat, (unsigned long)photoId); ((CPhoneDevice *)dev)->OnCaptureReady(true, false, mat, (uint64_t)photoId);
return; return;
} }
@ -923,7 +864,7 @@ Java_com_xypower_mpapp_MicroPhotoService_recordingFinished(
} }
// camera->Open(pathStr, fileNameStr); // camera->Open(pathStr, fileNameStr);
unsigned long photoId = videoId; uint64_t photoId = videoId;
((CPhoneDevice *)dev)->OnVideoReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, pathStr, photoId); ((CPhoneDevice *)dev)->OnVideoReady(photoOrVideo != JNI_FALSE, result != JNI_FALSE, pathStr, photoId);
if (path != NULL) if (path != NULL)
{ {

File diff suppressed because it is too large Load Diff

@ -202,10 +202,10 @@ public:
{ {
CPhoneDevice* device; CPhoneDevice* device;
unsigned int timerType; unsigned int timerType;
unsigned long times; uint64_t times;
void* data; void* data;
unsigned long expectedTimes; uint64_t expectedTimes;
unsigned long uid; uint64_t uid;
}; };
CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir); 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 timer_uid_t RegisterHeartbeat(unsigned int timerType, unsigned int timeout, time_t tsForNextPhoto);
virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path); virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path);
virtual bool CloseCamera(); 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 bool UnregisterTimer(timer_uid_t uid);
virtual unsigned long RequestWakelock(unsigned long timeout); virtual uint64_t RequestWakelock(uint64_t timeout);
virtual bool ReleaseWakelock(unsigned long wakelock); 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 int GetIceData(ICE_INFO *iceInfo, ICE_TAIL *icetail, D_SENSOR_PARAM *sensorParam);
virtual bool OpenSensors(int sensortype); virtual bool OpenSensors(int sensortype);
virtual bool CloseSensors(int sensortype, uint32_t delayedCloseTime); virtual bool CloseSensors(int sensortype, uint32_t delayedCloseTime);
@ -239,7 +239,7 @@ public:
virtual bool ClosePTZSensors(uint32_t delayedCloseTime); virtual bool ClosePTZSensors(uint32_t delayedCloseTime);
virtual bool GetPTZSensorsStatus(); virtual bool GetPTZSensorsStatus();
virtual bool GetCameraStatus(); 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 int GetSerialPhoto(int devno, D_IMAGE_DEF *photo);
virtual void InitSerialComm(D_SENSOR_PARAM *sensorParam, char *filedir); virtual void InitSerialComm(D_SENSOR_PARAM *sensorParam, char *filedir);
@ -272,6 +272,7 @@ protected:
bool SendBroadcastMessage(std::string action, int value); bool SendBroadcastMessage(std::string action, int value);
// bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_, // 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<IDevice::OSD_INFO>& osds, std::shared_ptr<PowerControl> powerCtrlPtr);
bool PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<IDevice::OSD_INFO>& osds, const std::string& path, const std::string& cameraInfo, cv::Mat& mat); bool PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<IDevice::OSD_INFO>& 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<IDevice::RECOG_OBJECT>& objects) const inline bool TakePhotoCb(int res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime, const std::vector<IDevice::RECOG_OBJECT>& objects) const
{ {
@ -386,9 +387,9 @@ protected:
unsigned int mVersionCode; unsigned int mVersionCode;
time_t mBuildTime; time_t mBuildTime;
atomic_ulong m_timerUidFeed; atomic_ullong m_timerUidFeed;
atomic_ulong m_wakelockIdFeed; atomic_ullong m_wakelockIdFeed;
atomic_ulong m_uniqueIdFeed; atomic_ullong m_uniqueIdFeed;
std::map<IDevice::timer_uid_t, TIMER_CONTEXT*> mTimers; std::map<IDevice::timer_uid_t, TIMER_CONTEXT*> mTimers;
mutable CPhoneCamera* mCamera; mutable CPhoneCamera* mCamera;

@ -692,7 +692,7 @@ void Gm_OpenSerialPort(int devidx)
fd = ::open(devparam[devidx].pathname, O_RDWR | O_NDELAY); fd = ::open(devparam[devidx].pathname, O_RDWR | O_NDELAY);
if (fd < 0) if (fd < 0)
{ {
sprintf(szbuf, "装置%d 打开串口%d %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'); DebugLog(devparam[devidx].commid, szbuf, 'E');
return; return;
} }
@ -1020,6 +1020,9 @@ void Gm_InitSerialComm(SENSOR_PARAM *sensorParam, char *filedir)
case RESERVE5_PROTOCOL: case RESERVE5_PROTOCOL:
sprintf(szbuf, "传感器%d接的是加密芯片", i + 1); sprintf(szbuf, "传感器%d接的是加密芯片", i + 1);
break; break;
case MUTIWEATHER_PROTOCOL:
sprintf(szbuf, "传感器%d接的是多合一气象传感器", i + 1);
break;
default: default:
sprintf(szbuf, "传感器%d没有接!", i + 1); sprintf(szbuf, "传感器%d没有接!", i + 1);
break; break;
@ -1180,6 +1183,7 @@ void FindDevUseSerialCommNo()
{ {
case WEATHER_PROTOCOL: case WEATHER_PROTOCOL:
case WIND_PROTOCOL: case WIND_PROTOCOL:
case MUTIWEATHER_PROTOCOL:
//memset(devparam[i].pathname, 0, sizeof(devparam[i].pathname)); //memset(devparam[i].pathname, 0, sizeof(devparam[i].pathname));
/* 目前还不确定具体串口分配暂时默认使用串口1</dev/ttyS0>*/ /* 目前还不确定具体串口分配暂时默认使用串口1</dev/ttyS0>*/
//sprintf(devparam[i].pathname, "/dev/swk3"); //sprintf(devparam[i].pathname, "/dev/swk3");
@ -1271,6 +1275,7 @@ void GM_StartSerialComm()
switch (devparam[i].ProtocolIdx) switch (devparam[i].ProtocolIdx)
{ {
case WEATHER_PROTOCOL: // 气象 case WEATHER_PROTOCOL: // 气象
case MUTIWEATHER_PROTOCOL:
memset(weatherpntmsg, 0, sizeof(AI_DEF)*WEATHER_DATA_NUM); memset(weatherpntmsg, 0, sizeof(AI_DEF)*WEATHER_DATA_NUM);
memset(szbuf, 0, sizeof(szbuf)); memset(szbuf, 0, sizeof(szbuf));
sprintf(szbuf, "%s", "气象"); sprintf(szbuf, "%s", "气象");
@ -1433,6 +1438,7 @@ void Gm_FindAllSensorsCommand()
case RALLY_PROTOCOL: /* 拉力*/ case RALLY_PROTOCOL: /* 拉力*/
case WIND_PROTOCOL: /* 风速风向*/ case WIND_PROTOCOL: /* 风速风向*/
case SLANT_PROTOCOL: /* 倾角*/ case SLANT_PROTOCOL: /* 倾角*/
case MUTIWEATHER_PROTOCOL:
flag = FindNextShxyProtocolCommand(curidx); flag = FindNextShxyProtocolCommand(curidx);
break; break;
case RESERVE2_PROTOCOL: case RESERVE2_PROTOCOL:
@ -1480,6 +1486,7 @@ void GM_IsCloseSensors()
case RALLY_PROTOCOL: /* 拉力*/ case RALLY_PROTOCOL: /* 拉力*/
case WIND_PROTOCOL: /* 风速风向*/ case WIND_PROTOCOL: /* 风速风向*/
case SLANT_PROTOCOL: /* 倾角*/ case SLANT_PROTOCOL: /* 倾角*/
case MUTIWEATHER_PROTOCOL:
if ((lctime - srdt.ms_dev[i].FirstCmdTimeCnt > 50 * 1000) || (lctime - srdt.ms_dev[i].FirstCmdTimeCnt < 0)) if ((lctime - srdt.ms_dev[i].FirstCmdTimeCnt > 50 * 1000) || (lctime - srdt.ms_dev[i].FirstCmdTimeCnt < 0))
{ {
srdt.ms_dev[i].FirstCmdTimeCnt = lctime; srdt.ms_dev[i].FirstCmdTimeCnt = lctime;
@ -1498,7 +1505,7 @@ void GM_IsCloseSensors()
else if (SER_SAMPLE == srdt.ms_dev[i].aiValue[j].AiState) else if (SER_SAMPLE == srdt.ms_dev[i].aiValue[j].AiState)
srdt.ms_dev[i].aiValue[j].AiState = SAMPLINGSUCCESS; 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++) 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 RALLY_PROTOCOL: /* 拉力*/
case WIND_PROTOCOL: /* 风速风向*/ case WIND_PROTOCOL: /* 风速风向*/
case SLANT_PROTOCOL: /* 倾角*/ case SLANT_PROTOCOL: /* 倾角*/
case MUTIWEATHER_PROTOCOL:
ShxyProtocolRecvData(devidx, buf, len); ShxyProtocolRecvData(devidx, buf, len);
break; break;
case RESERVE2_PROTOCOL: /* 意科电池电量读取协议*/ case RESERVE2_PROTOCOL: /* 意科电池电量读取协议*/
@ -2961,7 +2969,7 @@ void ShxyProtocolDataProcess(int devno)
int i, j, aipnt, datanum; int i, j, aipnt, datanum;
SERIAL_DEV_DEF *pPortParam; SERIAL_DEV_DEF *pPortParam;
SIO_PARAM_SERIAL_DEF *curserial; SIO_PARAM_SERIAL_DEF *curserial;
char szbuf[64]; char szbuf[128];
pPortParam = &srdt.ms_dev[devno]; pPortParam = &srdt.ms_dev[devno];
curserial = &serialport[devparam[devno].commid]; curserial = &serialport[devparam[devno].commid];
@ -3093,8 +3101,8 @@ void ShxyProtocolDataProcess(int devno)
//g_SelfTest.SensorsFault |= (0x10); //g_SelfTest.SensorsFault |= (0x10);
//if ((gDisSunRain & 0x80) == 0x80) //if ((gDisSunRain & 0x80) == 0x80)
{ {
sprintf(szbuf, "气压:%0.3f ", fvalue); sprintf(szbuf, "%s气压:%0.3f ", szbuf, fvalue);
DebugLog(devparam[devno].commid, szbuf, 'V'); //DebugLog(devparam[devno].commid, szbuf, 'V');
} }
break; break;
case 3: /*湿度*/ case 3: /*湿度*/
@ -3115,12 +3123,50 @@ void ShxyProtocolDataProcess(int devno)
//if ((gDisSunRain & 0x80) == 0x80) //if ((gDisSunRain & 0x80) == 0x80)
{ {
sprintf(szbuf, "%s湿度:%0.3f ", szbuf, fvalue); sprintf(szbuf, "%s湿度:%0.3f ", szbuf, fvalue);
if(datanum < 6)
DebugLog(devparam[devno].commid, szbuf, 'V'); DebugLog(devparam[devno].commid, szbuf, 'V');
} }
break; break;
case 4: /*雨量*/ 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; break;
case 5: /*日照*/ 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; break;
case 6: /*风速*/ case 6: /*风速*/
if ((fvalue < 0) || (fvalue > 80)) if ((fvalue < 0) || (fvalue > 80))

@ -38,6 +38,7 @@
#define PELCO_P_PROTOCOL 5 /* 摄像机Pelco_P协议序号*/ #define PELCO_P_PROTOCOL 5 /* 摄像机Pelco_P协议序号*/
#define PELCO_D_PROTOCOL 6 /* 摄像机Pelco_D协议序号*/ #define PELCO_D_PROTOCOL 6 /* 摄像机Pelco_D协议序号*/
#define SERIALCAMERA_PROTOCOL 8 /* 串口摄像机协议序号*/ #define SERIALCAMERA_PROTOCOL 8 /* 串口摄像机协议序号*/
#define MUTIWEATHER_PROTOCOL 9 /*多合一气象*/
#define RESERVE2_PROTOCOL 17 /* 备用2协议序号*/ #define RESERVE2_PROTOCOL 17 /* 备用2协议序号*/
#define RESERVE4_PROTOCOL 19 /* 备用4协议序号*/ #define RESERVE4_PROTOCOL 19 /* 备用4协议序号*/
#define RESERVE5_PROTOCOL 20 /* 备用5协议序号*/ #define RESERVE5_PROTOCOL 20 /* 备用5协议序号*/
@ -193,6 +194,8 @@ typedef struct SENSOR_PARAM
uint8_t IsNoInsta; /* 装置没有安装或者已经坏了(1:正常, 0:无效,坏了或没有安装)*/ uint8_t IsNoInsta; /* 装置没有安装或者已经坏了(1:正常, 0:无效,坏了或没有安装)*/
uint8_t CameraChannel; /* 像机的通道号*/ uint8_t CameraChannel; /* 像机的通道号*/
uint8_t Phase; /* 传感器所安装相别指拉力和倾角11表示A1....*/ uint8_t Phase; /* 传感器所安装相别指拉力和倾角11表示A1....*/
float multiple; /*系数*/
float offset; /*偏移值*/
} SENSOR_PARAM; } SENSOR_PARAM;
// 需要配置的串口装置参数 // 需要配置的串口装置参数

@ -29,7 +29,7 @@ static int SockOptCallback(void *clientp, curl_socket_t curlfd, curlsocktype pur
return res == 0 ? CURL_SOCKOPT_OK : CURL_SOCKOPT_ERROR; return res == 0 ? CURL_SOCKOPT_OK : CURL_SOCKOPT_ERROR;
} }
int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data) int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data)
{ {
CURLcode nRet; CURLcode nRet;
std::string auth; std::string auth;
@ -37,6 +37,8 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
if (authType != HTTP_AUTH_TYPE_NONE)
{
if (userName != NULL && password != NULL && strlen(userName) > 0) if (userName != NULL && password != NULL && strlen(userName) > 0)
{ {
auth = userName; auth = userName;
@ -44,8 +46,16 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
auth += password; auth += password;
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str()); curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
// DIGEST Auth // 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); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
} }
}
}
if (netHandle != NETWORK_UNSPECIFIED) if (netHandle != NETWORK_UNSPECIFIED)
{ {
@ -69,22 +79,40 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
nRet = curl_easy_perform(curl); 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); printf("GET err=%d", nRet);
} }
curl_easy_cleanup(curl); 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<uint8_t>& data) int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data)
{ {
std::string auth; std::string auth;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
if (authType != HTTP_AUTH_TYPE_NONE)
{
if (userName != NULL && password != NULL && strlen(userName) > 0) if (userName != NULL && password != NULL && strlen(userName) > 0)
{ {
auth = userName; auth = userName;
@ -92,8 +120,16 @@ int DoPutRequest(const char* url, const char* userName, const char* password, ne
auth += password; auth += password;
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str()); curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
// DIGEST Auth // 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); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
} }
}
}
if (netHandle != NETWORK_UNSPECIFIED) 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.ip;
url += photoInfo.url; 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 (0 == nRet)
{ {
if (!data.empty()) 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.ip;
url += photoInfo.url; 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); return (0 == nRet);
} }
@ -191,7 +227,7 @@ namespace nc_hk
url += photoInfo.ip; url += photoInfo.ip;
url += photoInfo.url; 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 #ifdef _DEBUG
if (0 == nRet) if (0 == nRet)
{ {
@ -225,7 +261,7 @@ namespace nc_ys
url += photoInfo.ip; url += photoInfo.ip;
url += photoInfo.url; 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 #ifdef _DEBUG
if (0 == nRet) if (0 == nRet)
{ {

@ -16,7 +16,7 @@
bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr); bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr);
int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data); int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data);
int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data); int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data);
#endif // __HTTP_CLIENT__ #endif // __HTTP_CLIENT__

@ -5,6 +5,9 @@
#ifndef __NET_CAMERA__ #ifndef __NET_CAMERA__
#define __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 struct NET_PHOTO_INFO
{ {

@ -86,6 +86,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class MicroPhotoService extends Service { public class MicroPhotoService extends Service {
public static final String TAG = "MPLOG"; 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 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 int NOTIFICATION_ID_FOREGROUND_SERVICE = 8466503;
public static final String ACTION_MSG_BROADCAST = "ACT_MSG_BROADCAST"; public static final String ACTION_MSG_BROADCAST = "ACT_MSG_BROADCAST";
@ -157,6 +162,8 @@ public class MicroPhotoService extends Service {
private ServiceHandler mHander = null; private ServiceHandler mHander = null;
private Messenger mMessenger = null; private Messenger mMessenger = null;
private static AtomicInteger mPendingIntentFeed = new AtomicInteger();
private String mModelName = null; private String mModelName = null;
public static boolean isRunning = false; public static boolean isRunning = false;
@ -199,7 +206,7 @@ public class MicroPhotoService extends Service {
@Override @Override
public void onTrimMemory(int level) { public void onTrimMemory(int level) {
Log.w(TAG, "onTrimMemory level=" + level); infoLog("Event onTrimMemory level=" + level);
if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) { if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
// Clear the caches. Note all pending requests will be removed too. // Clear the caches. Note all pending requests will be removed too.
final Context context = getApplicationContext(); final Context context = getApplicationContext();
@ -318,6 +325,7 @@ public class MicroPhotoService extends Service {
getApplicationContext().registerReceiver(mNetworkChangedReceiver, filter); getApplicationContext().registerReceiver(mNetworkChangedReceiver, filter);
} }
/*
AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(ALARM_SERVICE);
while (true) { while (true) {
@ -327,6 +335,8 @@ public class MicroPhotoService extends Service {
} }
} }
*/
enableGps(true); enableGps(true);
requestPosition(); requestPosition();
} }
@ -416,17 +426,24 @@ public class MicroPhotoService extends Service {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (TextUtils.equals(ACTION_HEARTBEAT, action)) { 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() { Runnable runnable = new Runnable() {
public void run() { public void run() {
mService.sendHeartbeat(mService.mNativeHandle, mService.getSignalLevel()); mService.sendHeartbeat(mService.mNativeHandle, mService.getSignalLevel());
} }
}; };
Thread th = new Thread(runnable); Thread th = new Thread(runnable);
th.start(); 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 { try {
@ -449,11 +466,18 @@ public class MicroPhotoService extends Service {
for (int idx = 0; idx < cnt; idx++) { for (int idx = 0; idx < cnt; idx++) {
long val = intent.getLongExtra(EXTRA_PARAM_SCHEDULE + idx, 0); long val = intent.getLongExtra(EXTRA_PARAM_SCHEDULE + idx, 0);
int channel = (int) ((val & 0xFF0000L) >> 16); int channel = (int) ((val & 0xFFFF000L) >> 12);
int preset = (int) ((val & 0xFF00L) >> 8); int preset = (int) ((val & 0xFF0L) >> 4);
boolean photoOrVideo = ((val & 0xFFL) == 0); 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); mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo);
} }
} }
@ -626,7 +650,7 @@ public class MicroPhotoService extends Service {
nextPhotoTime *= 1000; nextPhotoTime *= 1000;
if (nextPhotoTime > ts) { if (nextPhotoTime > ts) {
mHeartbeatDuration = duration; mHeartbeatDuration = duration;
registerHeartbeatTimer((int) ((nextPhotoTime - ts) % duration) + 999); registerHeartbeatTimer((int) ((nextPhotoTime - ts) % duration));
} else { } else {
mHeartbeatDuration = duration; 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(); Intent alarmIntent = new Intent();
alarmIntent.setAction(ACTION_HEARTBEAT); alarmIntent.setAction(ACTION_HEARTBEAT);
alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration); alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration);
alarmIntent.putExtra("HeartbeatTime", triggerTime); 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 alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent); alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
@ -661,10 +690,20 @@ public class MicroPhotoService extends Service {
intent.putExtra(EXTRA_PARAM_SCHEDULES, cnt); intent.putExtra(EXTRA_PARAM_SCHEDULES, cnt);
StringBuilder channelStr = new StringBuilder(); StringBuilder channelStr = new StringBuilder();
long val = 0; long val = 0;
long channel = 0;
for (int idx = 0; idx < cnt; idx++) { for (int idx = 0; idx < cnt; idx++) {
val = schedules.get(idx).longValue(); val = schedules.get(idx).longValue();
channel = ((val & 0XFFFF000) >> 12);
intent.putExtra(EXTRA_PARAM_SCHEDULE + idx, schedules.get(idx).longValue()); 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); intent.putExtra(EXTRA_PARAM_TIME, scheduleTime);
@ -675,7 +714,7 @@ public class MicroPhotoService extends Service {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
localBroadcastManager.sendBroadcast(intent); localBroadcastManager.sendBroadcast(intent);
} else { } 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); AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
try { try {
@ -684,12 +723,12 @@ public class MicroPhotoService extends Service {
ex.printStackTrace(); ex.printStackTrace();
} }
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
Date date = new Date(currentTimeMillis + timeout); Date date = new Date(currentTimeMillis + timeout);
String dateStr = (String) DateFormat.format("MM-dd kk:mm:ss", date); 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()); infoLog( "Timer Reg: " + dateStr + " TS=" + currentTimeMillis + " Timeout=" + timeout + " " + channelStr.toString());
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
} }
} }
@ -982,7 +1021,7 @@ public class MicroPhotoService extends Service {
alarmIntent.setPackage(context.getPackageName()); alarmIntent.setPackage(context.getPackageName());
alarmIntent.setAction(ACTION_STOP); 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 alarmManager = (AlarmManager) context.getApplicationContext().getSystemService(ALARM_SERVICE);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 100, pendingIntent); alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 100, pendingIntent);
@ -1384,7 +1423,7 @@ public class MicroPhotoService extends Service {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(ACTION_GPS_TIMEOUT); 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); alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mGpsTimeout, mPreviousGpsTimer);
} catch (Exception ex) { } catch (Exception ex) {

@ -4,7 +4,7 @@ plugins {
def AppMajorVersion = 1 def AppMajorVersion = 1
def AppMinorVersion = 0 def AppMinorVersion = 0
def AppBuildNumber = 88 def AppBuildNumber = 90
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber

@ -390,6 +390,9 @@ public class MpMasterService extends Service {
public boolean shouldSyncTime() { return mSyncTime; } public boolean shouldSyncTime() { return mSyncTime; }
public void startMpApp() { public void startMpApp() {
if (true) {
return;
}
try { try {
final Context context = getApplicationContext(); final Context context = getApplicationContext();
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
@ -417,7 +420,10 @@ public class MpMasterService extends Service {
ex.printStackTrace(); 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 // MpApp is not running
if (ts - mTimeToStartMpApp >= 1800000) { if (ts - mTimeToStartMpApp >= 1800000) {
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection"); 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 modifiedTimeOfPhoto = getFileModificationTime(appPath + "data/alive/taking");
final long modifiedTimeOfUpload = getFileModificationTime(appPath + "data/alive/upload"); final long modifiedTimeOfUpload = getFileModificationTime(appPath + "data/alive/upload");
if (((ts - modifiedTimeOfHb) > mTimeOfMpAppAlive) || if (((ts - modifiedTimeOfHb) > mTimeOfMpAppAlive) //||
((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) || // ((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) ||
((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4)) { // ((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4)
) {
if (ts - mTimeToStartMpApp >= 1800000) { if (ts - mTimeToStartMpApp >= 1800000) {
String msg = "Restart MpAPP as it is NOT Running hb=" + Long.toString(ts - modifiedTimeOfHb) + 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) { if (keepAlive) {
alarmIntent.putExtra("keepAlive", 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, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, keepAlive ? 0 : 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// PendingIntent pendingIntent = PendingIntent.getBroadcast(this, keepAlive ? 0 : 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Date dt = new Date(triggerTime); Date dt = new Date(triggerTime);

Loading…
Cancel
Save