优化电源控制机制

hdrplus
Matthew 7 months ago
parent eb13dea4fa
commit 36d2188ce9

@ -11,6 +11,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#include <climits>
#include "GPIOControl.h" #include "GPIOControl.h"
@ -22,12 +23,15 @@
#define IOT_PARAM_READ 0xAF #define IOT_PARAM_READ 0xAF
std::mutex GpioControl::m_locker; std::mutex GpioControl::m_locker;
std::vector<std::pair<int, uint32_t>> GpioControl::m_references; CSemaphore GpioControl::m_semaphore;
std::vector<GpioControl::ITEM> GpioControl::m_items;
std::thread GpioControl::m_thread;
bool GpioControl::m_exitSignal = false;
int GpioControl::turnOnImpl(const IOT_PARAM& param) size_t GpioControl::turnOnImpl(const IOT_PARAM& param)
{ {
uint32_t references = 1; size_t references = 1;
std::vector<std::pair<int, uint32_t> >::iterator it; std::vector<ITEM>::iterator it;
int res = 0; int res = 0;
int fd = -1; int fd = -1;
@ -37,108 +41,41 @@ int GpioControl::turnOnImpl(const IOT_PARAM& param)
res = ioctl(fd, IOT_PARAM_WRITE, &param); res = ioctl(fd, IOT_PARAM_WRITE, &param);
close(fd); close(fd);
// check res??? // check res???
for (it = m_references.begin(); it != m_references.end(); ++it) for (it = m_items.begin(); it != m_items.end(); ++it)
{ {
if (it->first == param.cmd) if (it->cmd == param.cmd)
{ {
it->second++; it->references++;
references = it->second; it->closeTime = 0;
references = it->references;
break; break;
} }
} }
if (it == m_references.end()) if (it == m_items.end())
{ {
m_references.push_back(std::pair<int, uint32_t >(param.cmd, references)); ITEM item = {param.cmd, references, 0, 0};
m_items.push_back(item);
} }
} }
return references; return references;
} }
int GpioControl::turnOffImpl(const IOT_PARAM& param) void GpioControl::setInt(int cmd, int value)
{ {
uint32_t references = 0; IOT_PARAM param = { cmd, value, 0 };
std::vector<std::pair<int, uint32_t> >::iterator it; // param.cmd = cmd;
int res = 0; // param.value = value;
int fd = -1;
for (it = m_references.begin(); it != m_references.end(); ++it)
{
if (it->first == param.cmd)
{
if (it->second > 0)
{
it->second--;
}
references = it->second;
break;
}
}
if (references == 0) int fd = open(GPIO_NODE_MP, O_RDONLY);
{
fd = open(GPIO_NODE_MP, O_RDONLY);
if (fd > 0) if (fd > 0)
{ {
res = ioctl(fd, IOT_PARAM_WRITE, &param); int res = ioctl(fd, IOT_PARAM_WRITE, &param);
#ifdef _DEBUG #ifdef _DEBUG
ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result); ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
#endif #endif
close(fd); close(fd);
} }
}
return references;
}
void GpioControl::setInt(int cmd, int value)
{
IOT_PARAM param = { cmd, value, 0 };
// param.cmd = cmd;
// param.value = value;
if (value)
{
m_locker.lock();
turnOnImpl(param);
m_locker.unlock();
}
else
{
m_locker.lock();
turnOffImpl(param);
m_locker.unlock();
}
}
void GpioControl::setInt(const std::vector<int>& cmds, int value)
{
IOT_PARAM param = { 0, value, 0 };
// param.cmd = cmd;
// param.value = value;
std::vector<int>::const_iterator it;
if (value)
{
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOnImpl(param);
}
m_locker.unlock();
}
else
{
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOffImpl(param);
}
m_locker.unlock();
}
} }
int GpioControl::getInt(int cmd) int GpioControl::getInt(int cmd)
@ -226,3 +163,214 @@ std::string GpioControl::getString(int cmd)
return ""; return "";
} }
/////////////////////////// Power Control /////////////////////////////////
size_t GpioControl::TurnOn(int cmd)
{
IOT_PARAM param = { cmd, 1, 0 };
// param.cmd = cmd;
// param.value = value;
m_locker.lock();
size_t ref = turnOnImpl(param);
m_locker.unlock();
return ref;
}
size_t GpioControl::TurnOn(const std::vector<int>& cmds)
{
IOT_PARAM param = { 0, 1, 0 };
// param.cmd = cmd;
// param.value = value;
std::vector<int>::const_iterator it;
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOnImpl(param);
}
m_locker.unlock();
return 0;
}
size_t GpioControl::TurnOff(int cmd, uint32_t delayedCloseTime/* = 0*/)
{
time_t ts = 0;
if (delayedCloseTime > 0)
{
ts = time(NULL) + delayedCloseTime;
}
std::vector<ITEM>::iterator it;
m_locker.lock();
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == cmd)
{
it->closeCmds++;
if (ts > it->closeTime)
{
it->closeTime = ts;
}
break;
}
}
m_locker.unlock();
return 0;
}
size_t GpioControl::TurnOff(const std::vector<int>& cmds, uint32_t delayedCloseTime/* = 0*/)
{
time_t ts = 0;
if (delayedCloseTime > 0)
{
ts = time(NULL) + delayedCloseTime;
}
std::vector<ITEM>::iterator it;
std::vector<int>::const_iterator itCmd;
m_locker.lock();
// turnOnImpl(param);
for (itCmd = cmds.cbegin(); itCmd != cmds.end(); ++itCmd)
{
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == *itCmd)
{
it->closeCmds++;
if (ts > it->closeTime)
{
it->closeTime = ts;
}
break;
}
}
}
return 0;
}
size_t GpioControl::TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds)
{
time_t ts = time(NULL);
time_t ts2;
std::vector<ITEM>::iterator it;
std::vector<std::pair<int, uint32_t> >::const_iterator itCmd;
m_locker.lock();
for (itCmd = cmds.cbegin(); itCmd != cmds.end(); ++itCmd)
{
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == itCmd->first)
{
it->closeCmds++;
if (itCmd->second != 0)
{
ts2 = itCmd->second + ts;
if (ts2 > it->closeTime)
{
it->closeTime = ts2;
}
}
break;
}
}
}
return 0;
}
void GpioControl::PowerControlThreadProc()
{
time_t ts = 0;
std::vector<ITEM>::iterator it;
std::vector<int> items;
time_t minDelayTime = 0;
time_t delayTime = 0;
int fd = -1;
int res = -1;
while(1)
{
// Check if there is close cmd
ts = time(NULL);
minDelayTime = std::numeric_limits<time_t>::max();
m_locker.lock();
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->references == 0 && it->closeCmds == 0 && it->closeTime == 0)
{
continue;
}
if (it->closeCmds > 0)
{
if (it->references <= it->closeCmds)
{
it->references = 0;
}
else
{
it->references -= it->closeCmds;
}
it->closeCmds = 0;
}
if (it->references == 0)
{
// Should turn off the power
if ((it->closeTime == 0) || (it->closeTime <= ts))
{
// close it directly
setInt(it->cmd, 0);
it->closeTime = 0;
}
else
{
// Check Time
delayTime = ts - it->closeTime;
if (delayTime < minDelayTime)
{
minDelayTime = delayTime;
}
}
}
}
m_locker.unlock();
if (minDelayTime < std::numeric_limits<time_t>::max())
{
m_semaphore.try_acquire_for(std::chrono::seconds(1));
}
else
{
m_semaphore.acquire();
}
if (m_exitSignal)
{
break;
}
}
}
bool GpioControl::Startup()
{
// if (m_thread.)
m_exitSignal = false;
m_thread = std::thread(PowerControlThreadProc);
return true;
}
void GpioControl::Stop()
{
// Notify
m_exitSignal = true;
m_semaphore.release();
m_thread.detach();
}

@ -12,7 +12,7 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <SemaphoreEx.h>
#ifndef USING_N938 #ifndef USING_N938
@ -129,18 +129,42 @@ typedef struct
class GpioControl class GpioControl
{ {
public:
struct ITEM
{
int cmd;
size_t references;
size_t closeCmds;
time_t closeTime;
};
private: private:
static std::mutex m_locker; static std::mutex m_locker;
static std::vector<std::pair<int, uint32_t>> m_references; static CSemaphore m_semaphore;
static std::vector<ITEM> m_items;
static bool m_exitSignal;
static std::thread m_thread;
protected: protected:
static int turnOnImpl(const IOT_PARAM& param); static size_t turnOnImpl(const IOT_PARAM& param);
static int turnOffImpl(const IOT_PARAM& param); static size_t turnOffImpl(const IOT_PARAM& param);
public: public:
static void setInt(int cmd, int value); // Power
static void setInt(const std::vector<int>& cmds, int value); static size_t TurnOn(int cmd);
static size_t TurnOn(const std::vector<int>& cmds);
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<std::pair<int, uint32_t> >& cmds);
static void PowerControlThreadProc();
static bool Startup();
static void Stop();
public:
static void setInt(int cmd, int value);
static int getInt(int cmd); static int getInt(int cmd);
static void setLong(int cmd, long value); static void setLong(int cmd, long value);
static long getLong(int cmd); static long getLong(int cmd);
@ -150,7 +174,7 @@ public:
static void setOtgState(bool on) static void setOtgState(bool on)
{ {
#ifndef USING_N938 #ifndef USING_N938
setInt(CMD_SET_OTG_STATE, on ? 1 : 0); on ? TurnOn(CMD_SET_OTG_STATE) : TurnOff(CMD_SET_OTG_STATE);
#endif #endif
} }
@ -165,10 +189,42 @@ public:
static void setCam3V3Enable(bool enabled) static void setCam3V3Enable(bool enabled)
{ {
#ifdef ENABLE_3V3_ALWAYS enabled ? TurnOn(CMD_SET_CAM_3V3_EN_STATE) : TurnOff(CMD_SET_CAM_3V3_EN_STATE);
setInt(CMD_SET_CAM_3V3_EN_STATE, 1); }
#else
setInt(CMD_SET_CAM_3V3_EN_STATE, enabled ? 1 : 0);
static void setBeeOn(bool z)
{
#ifndef USING_N938
setInt(CMD_SET_PWM_BEE_STATE, z ? 1 : 0);
#endif
}
static void setJidianqiState(bool z) {
#ifndef USING_N938
setInt(CMD_SET_ALM_MODE, z ? 1 : 0);
#endif
}
static void setSpiPower(bool on) {
setInt(CMD_SET_SPI_POWER, on ? 1 : 0);
if (on)
{
std::this_thread::sleep_for(std::chrono::milliseconds(40));
}
}
static void setRS485Enable(bool z)
{
#ifndef USING_N938
setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
#endif
}
static void set12VEnable(bool z)
{
#ifndef USING_N938
z ? TurnOn(CMD_SET_12V_EN_STATE) : TurnOff(CMD_SET_12V_EN_STATE);
#endif #endif
} }
@ -305,39 +361,6 @@ public:
#endif #endif
} }
static void setBeeOn(bool z) {
#ifndef USING_N938
setInt(CMD_SET_PWM_BEE_STATE, z ? 1 : 0);
#endif
}
static void setJidianqiState(bool z) {
#ifndef USING_N938
setInt(CMD_SET_ALM_MODE, z ? 1 : 0);
#endif
}
static void setSpiPower(bool on) {
setInt(CMD_SET_SPI_POWER, on ? 1 : 0);
if (on)
{
std::this_thread::sleep_for(std::chrono::milliseconds(40));
}
}
static void setRS485Enable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
#endif
}
static void set12VEnable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_12V_EN_STATE, z ? 1 : 0);
#endif
}
}; };

@ -401,9 +401,9 @@ Java_com_xypower_mpapp_MicroPhotoService_takePhoto(
if (photoInfo.usbCamera) if (photoInfo.usbCamera)
{ {
CPhoneDevice::TurnOnOtg(NULL); GpioControl::setOtgState(true);
} }
CPhoneDevice::TurnOnCameraPower(NULL); GpioControl::setCam3V3Enable(true);
std::vector<IDevice::OSD_INFO> osds; std::vector<IDevice::OSD_INFO> osds;
osds.resize(4); osds.resize(4);
@ -1045,8 +1045,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKeyFile(
const char *md5Str = env->GetStringUTFChars(md5, 0); const char *md5Str = env->GetStringUTFChars(md5, 0);
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
NrsecPort nrsec; NrsecPort nrsec;
@ -1059,7 +1058,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKeyFile(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
env->ReleaseStringUTFChars(md5, md5Str); env->ReleaseStringUTFChars(md5, md5Str);
@ -1081,8 +1080,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
return JNI_FALSE; return JNI_FALSE;
} }
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
NrsecPort nrsec; NrsecPort nrsec;
@ -1097,7 +1095,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
return res ? JNI_TRUE : JNI_FALSE; return res ? JNI_TRUE : JNI_FALSE;
#else #else
@ -1118,8 +1116,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKey(
return JNI_FALSE; return JNI_FALSE;
} }
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
NrsecPort nrsec; NrsecPort nrsec;
@ -1134,7 +1131,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKey(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
return res ? JNI_TRUE : JNI_FALSE; return res ? JNI_TRUE : JNI_FALSE;
#else #else
@ -1157,8 +1154,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
#ifdef USING_NRSEC #ifdef USING_NRSEC
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
const char *path = NRSEC_PATH; const char *path = NRSEC_PATH;
@ -1172,7 +1168,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
return res ? JNI_TRUE : JNI_FALSE; return res ? JNI_TRUE : JNI_FALSE;
#else #else
@ -1187,8 +1183,7 @@ Java_com_xypower_mpapp_MicroPhotoService_querySecVersion(
std::string version; std::string version;
#ifdef USING_NRSEC #ifdef USING_NRSEC
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
const char *path = NRSEC_PATH; const char *path = NRSEC_PATH;
@ -1202,7 +1197,7 @@ Java_com_xypower_mpapp_MicroPhotoService_querySecVersion(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
#endif #endif
return env->NewStringUTF(version.c_str()); return env->NewStringUTF(version.c_str());
} }
@ -1218,8 +1213,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genCertRequest(
} }
const char *path = NRSEC_PATH; const char *path = NRSEC_PATH;
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
uint8_t output[1024] = { 0 }; uint8_t output[1024] = { 0 };
@ -1237,7 +1231,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genCertRequest(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
if (res) if (res)
{ {
@ -1276,8 +1270,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKeyFile(
const char *path = NRSEC_PATH; const char *path = NRSEC_PATH;
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
NrsecPort nrsec; NrsecPort nrsec;
@ -1289,7 +1282,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKeyFile(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
// const char *md5Str = env->GetStringUTFChars(md5, 0); // const char *md5Str = env->GetStringUTFChars(md5, 0);
// env->ReleaseStringUTFChars(md5, md5Str); // env->ReleaseStringUTFChars(md5, md5Str);
@ -1316,8 +1309,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
uint8_t len = 0; uint8_t len = 0;
std::vector<unsigned char> data(64, 0); std::vector<unsigned char> data(64, 0);
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
NrsecPort nrsec; NrsecPort nrsec;
@ -1329,7 +1321,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
} }
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
if (res) if (res)
{ {
@ -1355,8 +1347,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
const char *path = NRSEC_PATH; const char *path = NRSEC_PATH;
GpioControl::setSpiPower(false); GpioControl::setCam3V3Enable(true);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
NrsecPort nrsec; NrsecPort nrsec;
@ -1371,7 +1362,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
nrsec.Close(); nrsec.Close();
GpioControl::setSpiPower(false); GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
if (res) { if (res) {
const char *outputPathStr = env->GetStringUTFChars(outputPath, 0); const char *outputPathStr = env->GetStringUTFChars(outputPath, 0);

@ -417,10 +417,6 @@ int32_t CPhoneDevice::CJpegCamera::getOutputFormat() const
return AIMAGE_FORMAT_JPEG; return AIMAGE_FORMAT_JPEG;
} }
std::mutex CPhoneDevice::m_powerLocker;
long CPhoneDevice::mCameraPowerCount = 0;
long CPhoneDevice::mOtgCount = 0;
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir) CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir)
: mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir), m_network(NULL), m_netHandle(NETWORK_UNSPECIFIED) : mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir), m_network(NULL), m_netHandle(NETWORK_UNSPECIFIED)
{ {
@ -493,7 +489,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_uniqueIdFeed = (unsigned long)m_timerUidFeed; m_uniqueIdFeed = (unsigned long)m_timerUidFeed;
#ifdef USING_NRSEC #ifdef USING_NRSEC
TurnOnCameraPower(env); GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true); GpioControl::setSpiPower(true);
#endif #endif
} }
@ -671,16 +667,16 @@ bool CPhoneDevice::SelfTest(std::string& result)
params.burstCaptures = 1; params.burstCaptures = 1;
if (usbCamera) if (usbCamera)
{ {
TurnOnOtg(NULL); GpioControl::setOtgState(true);
} }
TurnOnCameraPower(NULL); GpioControl::setCam3V3Enable(true);
NdkCamera camera(width, height, params); NdkCamera camera(width, height, params);
int res = camera.selfTest(std::to_string(cameraId), width, height); int res = camera.selfTest(std::to_string(cameraId), width, height);
TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
if (usbCamera) if (usbCamera)
{ {
TurnOffOtg(NULL); GpioControl::setOtgState(false);
} }
if (res == 0) if (res == 0)
{ {
@ -1457,17 +1453,17 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
if (photoInfo.cameraType == CAM_TYPE_USB || photoInfo.cameraType == CAM_TYPE_NET) if (photoInfo.cameraType == CAM_TYPE_USB || photoInfo.cameraType == CAM_TYPE_NET)
{ {
TurnOnOtg(NULL); GpioControl::setOtgState(true);
} }
if (photoInfo.cameraType == CAM_TYPE_NET) if (photoInfo.cameraType == CAM_TYPE_NET)
{ {
GpioControl::set12VEnable(true); GpioControl::set12VEnable(true);
#ifdef USING_N938 #ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 1); GpioControl::TurnOn(CMD_SET_NETWORK_POWER_EN);
GpioControl::setInt(CMD_SET_485_EN_STATE, 1); GpioControl::TurnOn(CMD_SET_485_EN_STATE);
#endif #endif
} }
TurnOnCameraPower(NULL); GpioControl::setCam3V3Enable(true);
res = true; res = true;
if ((mPhotoInfo.mediaType == 0) && ((mPhotoInfo.cameraType == CAM_TYPE_MIPI) || (mPhotoInfo.cameraType == CAM_TYPE_USB))) if ((mPhotoInfo.mediaType == 0) && ((mPhotoInfo.cameraType == CAM_TYPE_MIPI) || (mPhotoInfo.cameraType == CAM_TYPE_USB)))
@ -1521,10 +1517,10 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
mCamera = NULL; mCamera = NULL;
res = false; res = false;
TurnOffCameraPower(NULL); GpioControl::setCam3V3Enable(false);
if (photoInfo.usbCamera) if (photoInfo.usbCamera)
{ {
TurnOffOtg(NULL); GpioControl::setOtgState(false);
} }
if (hasFatalError) if (hasFatalError)
@ -1575,11 +1571,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
XYLOG(XYLOG_SEVERITY_ERROR, "Ethernet not existing CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId); 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); pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
TurnOffOtg(NULL); GpioControl::setOtgState(false);
GpioControl::set12VEnable(false); GpioControl::set12VEnable(false);
#ifdef USING_N938 #ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0); GpioControl::TurnOff(CMD_SET_NETWORK_POWER_EN);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0); GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#endif #endif
return; return;
} }
@ -1609,11 +1605,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
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); 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); pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
TurnOffOtg(NULL); GpioControl::setOtgState(false);
GpioControl::set12VEnable(false); GpioControl::set12VEnable(false);
#ifdef USING_N938 #ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0); GpioControl::TurnOff(CMD_SET_NETWORK_POWER_EN);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0); GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#endif #endif
return; return;
} }
@ -1651,11 +1647,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
} }
} }
TurnOffOtg(NULL); GpioControl::setOtgState(false);
GpioControl::set12VEnable(false); GpioControl::set12VEnable(false);
#ifdef USING_N938 #ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0); GpioControl::TurnOff(CMD_SET_NETWORK_POWER_EN);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0); GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#endif #endif
if (netCaptureResult) if (netCaptureResult)
{ {
@ -3395,34 +3391,6 @@ void CPhoneDevice::UpdatePosition(double lon, double lat, double radius, time_t
} }
} }
void CPhoneDevice::TurnOnCameraPower(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setCam3V3Enable(true);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOffCameraPower(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setCam3V3Enable(false);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOnOtg(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setInt(CMD_SET_OTG_STATE, 1);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOffOtg(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setInt(CMD_SET_OTG_STATE, 0);
m_powerLocker.unlock();
}
void CPhoneDevice::UpdateSignalLevel(int signalLevel) void CPhoneDevice::UpdateSignalLevel(int signalLevel)
{ {
m_signalLevel = signalLevel; m_signalLevel = signalLevel;
@ -3646,18 +3614,18 @@ bool CPhoneDevice::OpenSensors(int sensortype)
GpioControl::set12VEnable(true); GpioControl::set12VEnable(true);
GpioControl::setCam3V3Enable(true); GpioControl::setCam3V3Enable(true);
GpioControl::setRS485Enable(true); GpioControl::setRS485Enable(true);
GpioControl::setInt(CMD_SET_SPI_POWER, 1); GpioControl::TurnOn(CMD_SET_SPI_POWER);
// GpioControl::setInt(CMD_SET_485_EN_STATE, 1); // 打开RS485电源 // GpioControl::TurnOn(CMD_SET_485_EN_STATE); // 打开RS485电源
#ifndef USING_N938 #ifndef USING_N938
#ifndef USING_PLZ #ifndef USING_PLZ
GpioControl::setInt(CMD_SET_485_EN_STATE, 1); GpioControl::TurnOn(CMD_SET_485_EN_STATE);
#else #else
GpioControl::setInt(CMD_SET_485_ENABLE, 1); GpioControl::TurnOn(CMD_SET_485_ENABLE);
#endif #endif
#else #else
GpioControl::setInt(CMD_SPI2SERIAL_POWER_EN, 1); GpioControl::TurnOn(CMD_SPI2SERIAL_POWER_EN);
GpioControl::setInt(CMD_RS485_3V3_EN, 1); GpioControl::TurnOn(CMD_RS485_3V3_EN);
#endif #endif
} }
if(sensortype == CAMERA_SENSOR_OPEN) if(sensortype == CAMERA_SENSOR_OPEN)
@ -3665,39 +3633,39 @@ bool CPhoneDevice::OpenSensors(int sensortype)
#ifndef USING_N938 #ifndef USING_N938
#ifndef USING_PLZ #ifndef USING_PLZ
#else #else
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 1); GpioControl::TurnOn(CMD_SET_PTZ_PWR_ENABLE);
#endif #endif
#else #else
GpioControl::setInt(CMD_SET_PIC1_POWER, 1); GpioControl::TurnOn(CMD_SET_PIC1_POWER);
GpioControl::setInt(CMD_SET_485_EN4, 1); GpioControl::TurnOn(CMD_SET_485_EN4);
#endif #endif
// GpioControl::setInt(CMD_SET_CAM_3V3_EN_STATE, 1); // 打开3.3V电压 // GpioControl::TurnOn(CMD_SET_CAM_3V3_EN_STATE); // 打开3.3V电压
// GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 1); // GpioControl::TurnOn(CMD_SET_3V3_PWR_ENABLE);
} }
if(sensortype == WEATHER_SENSOR_OPEN) if(sensortype == WEATHER_SENSOR_OPEN)
{ {
#ifndef USING_N938 #ifndef USING_N938
#else #else
GpioControl::setInt(CMD_SET_WTH_POWER, 1); GpioControl::TurnOn(CMD_SET_WTH_POWER);
GpioControl::setInt(CMD_SET_485_EN3, 1); GpioControl::TurnOn(CMD_SET_485_EN3);
#endif #endif
} }
if(sensortype == ICETHICK_SENSOR_OPEN) if(sensortype == ICETHICK_SENSOR_OPEN)
{ {
#ifndef USING_N938 #ifndef USING_N938
#else #else
GpioControl::setInt(CMD_SET_PULL_POWER, 1); GpioControl::TurnOn(CMD_SET_PULL_POWER, 0);
GpioControl::setInt(CMD_SET_ANGLE_POWER, 1); GpioControl::TurnOn(CMD_SET_ANGLE_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN1, 1); GpioControl::TurnOn(CMD_SET_485_EN1, 0);
GpioControl::setInt(CMD_SET_485_EN0, 1); GpioControl::TurnOn(CMD_SET_485_EN0, 0);
#endif #endif
} }
if(sensortype == OTHER_SENSOR) if(sensortype == OTHER_SENSOR)
{ {
#ifndef USING_N938 #ifndef USING_N938
#else #else
GpioControl::setInt(CMD_SET_OTHER_POWER, 1); GpioControl::TurnOn(CMD_SET_OTHER_POWER);
GpioControl::setInt(CMD_SET_485_EN2, 1); GpioControl::TurnOn(CMD_SET_485_EN2);
#endif #endif
} }
return 0; return 0;
@ -3707,36 +3675,36 @@ bool CPhoneDevice::CloseSensors(int sensortype)
{ {
if(sensortype == MAIN_POWER_OPEN) if(sensortype == MAIN_POWER_OPEN)
{ {
GpioControl::setInt(CMD_SET_SPI_POWER, 0); GpioControl::TurnOff(CMD_SET_SPI_POWER);
GpioControl::set12VEnable(false); GpioControl::set12VEnable(false);
GpioControl::setCam3V3Enable(false); GpioControl::setCam3V3Enable(false);
GpioControl::setRS485Enable(false); GpioControl::setRS485Enable(false);
// GpioControl::setInt(CMD_SET_485_EN_STATE, 0); // GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#ifndef USING_N938 #ifndef USING_N938
#ifndef USING_PLZ #ifndef USING_PLZ
GpioControl::setInt(CMD_SET_485_EN_STATE, 0); GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#else #else
GpioControl::setInt(CMD_SET_485_ENABLE, 0); GpioControl::TurnOff(CMD_SET_485_ENABLE);
#endif #endif
#else #else
GpioControl::setInt(CMD_SPI2SERIAL_POWER_EN, 0); GpioControl::TurnOff(CMD_SPI2SERIAL_POWER_EN);
GpioControl::setInt(CMD_RS485_3V3_EN, 0); GpioControl::TurnOff(CMD_RS485_3V3_EN);
#endif #endif
} }
if(sensortype == CAMERA_SENSOR_OPEN) if(sensortype == CAMERA_SENSOR_OPEN)
{ {
#ifdef USING_N938 #ifdef USING_N938
GpioControl::setInt(CMD_SET_PIC1_POWER, 0); GpioControl::TurnOff(CMD_SET_PIC1_POWER);
GpioControl::setInt(CMD_SET_485_EN4, 0); GpioControl::TurnOff(CMD_SET_485_EN4);
// GpioControl::setInt(CMD_SET_CAM_3V3_EN_STATE, 0); // GpioControl::TurnOff(CMD_SET_CAM_3V3_EN_STATE);
#endif #endif
#ifndef USING_N938 #ifndef USING_N938
// GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 0); // GpioControl::TurnOff(CMD_SET_3V3_PWR_ENABLE);
#ifndef USING_PLZ #ifndef USING_PLZ
#else #else
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 0); GpioControl::TurnOff(CMD_SET_PTZ_PWR_ENABLE);
#endif #endif
#endif #endif
} }
@ -3744,26 +3712,26 @@ bool CPhoneDevice::CloseSensors(int sensortype)
{ {
#ifndef USING_N938 #ifndef USING_N938
#else #else
GpioControl::setInt(CMD_SET_WTH_POWER, 0); GpioControl::TurnOff(CMD_SET_WTH_POWER);
GpioControl::setInt(CMD_SET_485_EN3, 0); GpioControl::TurnOff(CMD_SET_485_EN3);
#endif #endif
} }
if(sensortype == ICETHICK_SENSOR_OPEN) if(sensortype == ICETHICK_SENSOR_OPEN)
{ {
#ifndef USING_N938 #ifndef USING_N938
#else #else
GpioControl::setInt(CMD_SET_PULL_POWER, 0); GpioControl::TurnOff(CMD_SET_PULL_POWER);
GpioControl::setInt(CMD_SET_ANGLE_POWER, 0); GpioControl::TurnOff(CMD_SET_ANGLE_POWER);
GpioControl::setInt(CMD_SET_485_EN1, 0); GpioControl::TurnOff(CMD_SET_485_EN1);
GpioControl::setInt(CMD_SET_485_EN0, 0); GpioControl::TurnOff(CMD_SET_485_EN0);
#endif #endif
} }
if(sensortype == OTHER_SENSOR) if(sensortype == OTHER_SENSOR)
{ {
#ifndef USING_N938 #ifndef USING_N938
#else #else
GpioControl::setInt(CMD_SET_OTHER_POWER, 0); GpioControl::TurnOff(CMD_SET_OTHER_POWER);
GpioControl::setInt(CMD_SET_485_EN2, 0); GpioControl::TurnOff(CMD_SET_485_EN2);
#endif #endif
} }
return 0; return 0;
@ -3805,7 +3773,8 @@ void CPhoneDevice::SetStaticIp()
if (m_network != NULL) if (m_network != NULL)
{ {
SetStaticIp(m_network->iface, m_network->ip, m_network->netmask, m_network->gateway); SetStaticIp(m_network->iface, m_network->ip, m_network->netmask, m_network->gateway);
XYLOG(XYLOG_SEVERITY_INFO, "Set Static IP on %s: %s", m_network->iface.c_str(), m_network->ip.c_str()); XYLOG(XYLOG_SEVERITY_INFO, "Set Static IP on %s: %s", m_network->iface.c_str(),
m_network->ip.c_str());
} }
else else
{ {

@ -257,12 +257,6 @@ public:
net_handle_t GetNetHandle() const; net_handle_t GetNetHandle() const;
static void TurnOnCameraPower(JNIEnv* env);
static void TurnOffCameraPower(JNIEnv* env);
static void TurnOnOtg(JNIEnv* env);
static void TurnOffOtg(JNIEnv* env);
protected: protected:
std::string GetFileName() const; std::string GetFileName() const;
@ -382,9 +376,6 @@ protected:
time_t mHeartbeatStartTime; time_t mHeartbeatStartTime;
unsigned int mHeartbeatDuration; unsigned int mHeartbeatDuration;
static std::mutex m_powerLocker;
static long mCameraPowerCount;
static long mOtgCount;
std::thread m_threadClose; std::thread m_threadClose;
int m_signalLevel; int m_signalLevel;

@ -36,72 +36,6 @@ AI_DEF weatherpntmsg[WEATHER_DATA_NUM];
AI_DEF rallypntmsg[6][RALLY_DATA_NUM]; AI_DEF rallypntmsg[6][RALLY_DATA_NUM];
AI_DEF slantpntmsg[6][SLANTANGLE_DATA_NUM]; AI_DEF slantpntmsg[6][SLANTANGLE_DATA_NUM];
static void setInt(int cmd, int value)
{
int fd = ::open("/dev/mtkgpioctrl", O_RDONLY);
IOT_PARAM param;
param.cmd = cmd;
param.value = value;
// LOGE("set_int fd=%d,cmd=%d,value=%d\r\n",fd, cmd, value);
if (fd > 0)
{
ioctl(fd, IOT_PARAM_WRITE, &param);
// LOGE("set_int22 cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
close(fd);
}
//return;
}
int getInt(int cmd)
{
int fd = ::open("/dev/mtkgpioctrl", O_RDONLY);
// LOGE("get_int fd=%d,cmd=%d\r\n",fd, cmd);
if (fd > 0)
{
IOT_PARAM param;
param.cmd = cmd;
ioctl(fd, IOT_PARAM_READ, &param);
#ifdef _DEBUG
//ALOGI("getInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
#endif
close(fd);
return param.value;
}
return -1;
}
static void setRS485Enable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
#endif
}
static void set485WriteMode() {
#ifndef USING_N938
setInt(CMD_SET_485_STATE, 1);
#endif
}
static void set485ReadMode() {
#ifndef USING_N938
setInt(CMD_SET_485_STATE, 0);
#endif
}
static void set12VEnable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_12V_EN_STATE, z ? 1 : 0);
#endif
}
static void setCam3V3Enable(bool enabled)
{
#ifdef ENABLE_3V3_ALWAYS
setInt(CMD_SET_CAM_3V3_EN_STATE, 1);
#else
setInt(CMD_SET_CAM_3V3_EN_STATE, enabled ? 1 : 0);
#endif
}
#if 0 #if 0
/********************************************************************************* /*********************************************************************************
* * * *

Loading…
Cancel
Save