A small lib for switch xbee from transperant mode to api
Revision 0:31b3aca13b85, committed 2017-01-30
- Comitter:
- gert_lauritsen
- Date:
- Mon Jan 30 16:22:53 2017 +0000
- Commit message:
- Libery to switch a xbee from transperant mode to api and zb mode
Changed in this revision
XbeeConfig.cpp | Show annotated file Show diff for this revision Revisions of this file |
XbeeConfig.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 31b3aca13b85 XbeeConfig.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XbeeConfig.cpp Mon Jan 30 16:22:53 2017 +0000 @@ -0,0 +1,101 @@ +/* + * XbeeConfig.cpp + * + * Created on: 29/01/2017 + * Author: gert + */ + +#include <XbeeConfig/XbeeConfig.h> + +XbeeConfig::XbeeConfig(PinName tx, PinName rx, PinName Rst): _com(tx,rx), rst(Rst){ + _com.baud(9600); + Reset(); +} + +XbeeConfig::~XbeeConfig() { + +} + +void XbeeConfig::Reset() +{ + rst = 0; + wait_ms(10); + rst = 1; + wait_ms(1); +} + +int XbeeConfig::SetZB() +{ + wait_ms(5); + _com.printf("ATZS2\r"); + Wait4OK(); + return 1; +} + +int XbeeConfig::ResetSetAPI() +{ + wait_ms(5); + _com.printf("ATAP0\r"); + Wait4OK(); + return 1; +} + + +int XbeeConfig::SetAPI() +{ + wait_ms(5); + _com.printf("ATAP1\r"); + Wait4OK(); + return 1; +} + + +int XbeeConfig::ExitConfigMode() +{ + wait_ms(5); + _com.printf("ATWR \r"); + Wait4OK(); + + _com.printf("ATCN \r"); + Wait4OK(); + return 1; +} + +int XbeeConfig::Wait4OK(){ + int a=0; + while (a != 75) { //Wait for OK + if (_com.readable()) { + a = _com.getc(); + } + } + return 1; +} + +int XbeeConfig::ConfigMode() +{ + wait(2); + _com.printf("+++"); + Wait4OK(); + wait(1); + return 1; +} + +int XbeeConfig::Switch2Transperantmode() { + if (ConfigMode()) { + ResetSetAPI(); + ExitConfigMode(); + return 1; + } + else return 0; +} + + +int XbeeConfig::Switch2APImode() { + if (ConfigMode()) { + SetAPI(); + SetZB(); + ExitConfigMode(); + return 1; + } + else return 0; +}
diff -r 000000000000 -r 31b3aca13b85 XbeeConfig.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XbeeConfig.h Mon Jan 30 16:22:53 2017 +0000 @@ -0,0 +1,30 @@ +/* + * XbeeConfig.h + * + * Created on: 29/01/2017 + * Author: gert + */ + +#ifndef XBEECONFIG_XBEECONFIG_H_ +#define XBEECONFIG_XBEECONFIG_H_ +#include "mbed.h" + +class XbeeConfig { +private: + RawSerial _com; + DigitalOut rst; + int ConfigMode(); + int ExitConfigMode(); + int SetAPI(); + void Reset(); + int Wait4OK(); + int SetZB(); + int ResetSetAPI(); +public: + XbeeConfig(PinName tx, PinName rx, PinName Rst); + virtual ~XbeeConfig(); + int Switch2APImode(); + int Switch2Transperantmode(); +}; + +#endif /* XBEECONFIG_XBEECONFIG_H_ */ \ No newline at end of file