编译通过,是否支持电源管理,由各个设备负责

This commit is contained in:
nnhy 2015-11-08 02:33:50 +00:00
parent 6bdc22cb90
commit ae229272df
8 changed files with 34 additions and 32 deletions

View File

@ -266,7 +266,7 @@ void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power)
// 初始化前必须先关闭电源。因为系统可能是重启,而模块并没有重启,还保留着上一次的参数
//!!! 重大突破当前版本程序烧写后无法触发IRQ中断但是重新上电以后可以中断而Reset也不能触发。并且发现只要模块带电寄存器参数不会改变。
SetPower(false);*/
SetPowerMode(false);*/
}
NRF24L01::~NRF24L01()
@ -279,7 +279,7 @@ NRF24L01::~NRF24L01()
Register(NULL);
// 关闭电源
SetPower(false);
SetPowerMode(false);
delete _spi;
_spi = NULL;
@ -439,7 +439,7 @@ bool NRF24L01::Config()
#endif
//ShowStatus();
SetPower(false);
SetPowerMode(false);
_CE = false;
SetAddress(true);
@ -497,7 +497,7 @@ bool NRF24L01::Config()
// 清除中断标志
ClearStatus(true, true);
if(!SetPower(true)) return false;
if(!SetPowerMode(true)) return false;
_CE = true;
@ -558,7 +558,7 @@ bool NRF24L01::GetPower()
}
// 获取/设置当前电源状态
bool NRF24L01::SetPower(bool on)
bool NRF24L01::SetPowerMode(bool on)
{
byte mode = ReadReg(CONFIG);
RF_CONFIG config;
@ -566,7 +566,7 @@ bool NRF24L01::SetPower(bool on)
if(!(on ^ config.PWR_UP)) return true;
debug_printf("NRF24L01::SetPower %s电源\r\n", on ? "打开" : "关闭");
debug_printf("NRF24L01::SetPowerMode %s电源\r\n", on ? "打开" : "关闭");
config.PWR_UP = on ? 1 : 0;
@ -584,7 +584,7 @@ bool NRF24L01::SetPower(bool on)
config.Init(ReadReg(CONFIG));
if(!config.PWR_UP)
{
debug_printf("NRF24L01::SetPower 无法打开电源!\r\n");
debug_printf("NRF24L01::SetPowerMode 无法打开电源!\r\n");
return false;
}
}
@ -592,6 +592,20 @@ bool NRF24L01::SetPower(bool on)
return true;
}
void NRF24L01::ChangePower(int level)
{
if(level == 1)
{
// 芯片内部关闭电源
SetPowerMode(false);
}
else if(level > 1)
{
// 整个模块断电
Power = false;
}
}
// 获取当前模式是否接收模式
bool NRF24L01::GetMode()
{
@ -812,7 +826,7 @@ void NRF24L01::OnClose()
{
if(_tidRecv) Sys.SetTask(_tidRecv, false);
SetPower(false);
SetPowerMode(false);
_spi->Close();
_CE.Close();

View File

@ -74,8 +74,6 @@ void ShunCom::ChangePower(int level)
Power = false;
Sleep = false;
Config = false;
PackPort::ChangePower(level);
}
bool ShunCom::OnWrite(const ByteArray& bs)

View File

@ -3,12 +3,13 @@
#include "Sys.h"
#include "Port.h"
#include "Power.h"
#include "Net\ITransport.h"
#include "Message\DataStore.h"
// 上海顺舟Zigbee协议
// 主站发送所有从站收到,从站发送只有主站收到
class ShunCom : public PackPort
class ShunCom : public PackPort, public Power
{
private:

View File

@ -6,10 +6,11 @@
#include "Net\ITransport.h"
#include "Timer.h"
#include "Thread.h"
#include "Power.h"
#include "Message\DataStore.h"
// NRF24L01类
class NRF24L01 : public ITransport
class NRF24L01 : public ITransport, public Power
{
private:
byte WriteBuf(byte reg, const byte *pBuf, byte bytes);
@ -58,7 +59,7 @@ public:
bool Check();
bool Config(); // 完成基础参数设定,默认初始化为发送模式
bool GetPower(); // 获取当前电源状态
bool SetPower(bool on); // 设置当前电源状态。返回是否成功
bool SetPowerMode(bool on); // 设置当前电源状态。返回是否成功
bool GetMode(); // 获取当前模式是否接收模式
bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定
void SetAddress(bool full); // 设置地址。参数指定是否设置0通道地址以外的完整地址
@ -66,6 +67,9 @@ public:
void ClearFIFO(bool rx);
void ClearStatus(bool tx, bool rx);
// 电源等级变更(如进入低功耗模式)时调用
virtual void ChangePower(int level);
IDataPort* Led; // 数据灯
byte Status;

View File

@ -35,13 +35,6 @@ bool ITransport::Open()
Opened = OnOpen();
Opening = false;
/*// 设置电源管理
if(Opened)
{
Power* pwr = dynamic_cast<Power*>(this);
if(pwr) pwr->SetPower();
}*/
return Opened;
}
@ -136,9 +129,3 @@ uint PackPort::OnPortReceive(ITransport* sender, ByteArray& bs, void* param, voi
PackPort* pp = dynamic_cast<PackPort*>((PackPort*)param);
return pp->OnReceive(bs, param2);
}
void PackPort::ChangePower(int level)
{
Power* pwr = dynamic_cast<Power*>(Port);
if(pwr) pwr->ChangePower(level);
}

View File

@ -2,7 +2,6 @@
#define __ITransport_H__
#include "Sys.h"
#include "Power.h"
class ITransport;
@ -74,9 +73,6 @@ public:
virtual void Set(ITransport* port);
// 电源等级变更(如进入低功耗模式)时调用
virtual void ChangePower(int level);
virtual string ToString() { return "PackPort"; }
protected:

View File

@ -11,7 +11,7 @@
#define SERIAL_BAUDRATE 1024000
// 串口类
class SerialPort : public ITransport
class SerialPort : public ITransport, public Power
{
private:
byte _index;

View File

@ -85,7 +85,9 @@ ITransport* CreateShunCom(COM_Def index, int baudRate, Pin rst, Pin power, Pin s
zb->Sleep.Init(slp, true);
zb->Config.Init(cfg, true);
zb->Init(&sp, rst);
zb->Init(sp, rst);
sp->SetPower();
zb->SetPower();
/*zb.Register(OnZig, &zb);