升级Zigbee相关功能代码,编译通过,未测试

This commit is contained in:
Stone 2014-11-22 00:55:26 +00:00
parent dcf3321d4a
commit 3a7dd0feb2
2 changed files with 64 additions and 37 deletions

View File

@ -1,24 +1,65 @@
#include "Zigbee.h" #include "Zigbee.h"
Zigbee::Zigbee()
{
_port = NULL;
}
Zigbee::Zigbee(ITransport* port, Pin rst) Zigbee::Zigbee(ITransport* port, Pin rst)
{ {
assert_param(port); Init(port);
_port = port;
_rst = NULL;
if(rst != P0)
{
_rst = new OutputPort(rst);
Rest();
}
} }
Zigbee::~Zigbee() Zigbee::~Zigbee()
{ {
if(_port) delete _port; delete _port;
_port = NULL; _port = NULL;
if(_rst) delete _rst; /*if(_rst) delete _rst;
_rst = NULL; _rst = NULL;*/
}
void Zigbee::Init(ITransport* port, Pin rst)
{
assert_ptr(port);
_port = port;
//_rst = NULL;
if(rst != P0)
{
//_rst = new OutputPort(rst);
_rst.Set(rst);
Reset();
}
}
void Zigbee::Reset(void)
{
if(_rst.Empty()) return;
_rst = true;
Sys.Delay(100);
_rst = false;
Sys.Delay(100);
_rst = true;
}
// 注册回调函数
void Zigbee::Register(TransportHandler handler, void* param)
{
ITransport::Register(handler, param);
if(handler)
_port->Register(OnPortReceive, this);
else
_port->Register(NULL);
}
uint Zigbee::OnPortReceive(ITransport* sender, byte* buf, uint len, void* param)
{
assert_ptr(param);
Zigbee* zb = (Zigbee*)param;
return zb->OnReceive(buf, len);
} }

View File

@ -10,42 +10,28 @@
class Zigbee : public ITransport class Zigbee : public ITransport
{ {
private: private:
ITransport* _port; ITransport* _port;
OutputPort* _rst; OutputPort _rst;
public: public:
Zigbee();
Zigbee(ITransport* port, Pin rst = P0); Zigbee(ITransport* port, Pin rst = P0);
virtual ~Zigbee(); virtual ~Zigbee();
void Init(ITransport* port, Pin rst = P0);
// 注册回调函数 // 注册回调函数
virtual void Register(TransportHandler handler, void* param = NULL) virtual void Register(TransportHandler handler, void* param = NULL);
{
ITransport::Register(handler, param); virtual void Reset(void);
_port->Register(OnPortReceive, this);
}
virtual void Rest(void)
{
*_rst=true;
Sys.Delay(100);
*_rst=false;
Sys.Delay(100);
*_rst=true;
}
protected: protected:
virtual bool OnOpen() { return _port->Open(); } virtual bool OnOpen() { return _port->Open(); }
virtual void OnClose() { _port->Close(); } virtual void OnClose() { _port->Close(); }
virtual bool OnWrite(const byte* buf, uint len) { return _port->Write(buf, len); } virtual bool OnWrite(const byte* buf, uint len) { return _port->Write(buf, len); }
virtual uint OnRead(byte* buf, uint len) { return _port->Read(buf, len); } virtual uint OnRead(byte* buf, uint len) { return _port->Read(buf, len); }
static uint OnPortReceive(ITransport* sender, byte* buf, uint len, void* param) static uint OnPortReceive(ITransport* sender, byte* buf, uint len, void* param);
{
Zigbee* zb = (Zigbee*)param;
return zb->OnReceive(buf, len);
}
}; };
#endif #endif