Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Xbee.cpp@8:6fd7091e1478, 2015-11-22 (annotated)
- Committer:
- Xiaofei
- Date:
- Sun Nov 22 02:39:01 2015 +0000
- Revision:
- 8:6fd7091e1478
- Parent:
- 7:922bf2a611b1
- Child:
- 9:c0955550ca13
cc
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Xiaofei | 0:633baa9653b0 | 1 | #pragma once | 
| Xiaofei | 0:633baa9653b0 | 2 | #include "Xbee.h" | 
| Xiaofei | 0:633baa9653b0 | 3 | |
| Xiaofei | 2:33462c1e9f45 | 4 | Xbee::Xbee(PinName tx, PinName rx , PinName rst):_xbee(tx,rx),_rst(rst) | 
| Xiaofei | 2:33462c1e9f45 | 5 | { | 
| Xiaofei | 2:33462c1e9f45 | 6 | _rst = 0; | 
| Xiaofei | 2:33462c1e9f45 | 7 | wait(0.01); | 
| Xiaofei | 2:33462c1e9f45 | 8 | _rst = 1; | 
| Xiaofei | 2:33462c1e9f45 | 9 | wait(0.01); | 
| Xiaofei | 5:d14636b861ff | 10 | |
| Xiaofei | 5:d14636b861ff | 11 | _xbee.baud(9600); | 
| Xiaofei | 2:33462c1e9f45 | 12 | } | 
| Xiaofei | 2:33462c1e9f45 | 13 | |
| Xiaofei | 2:33462c1e9f45 | 14 | |
| Xiaofei | 0:633baa9653b0 | 15 | void Xbee::Send(const char* buffer) | 
| Xiaofei | 0:633baa9653b0 | 16 | { | 
| Xiaofei | 3:fe623a260bf5 | 17 | while(!_xbee.readable()) | 
| Xiaofei | 3:fe623a260bf5 | 18 | { | 
| Xiaofei | 8:6fd7091e1478 | 19 | if(_xbee.getc() == '.') | 
| Xiaofei | 8:6fd7091e1478 | 20 | { | 
| Xiaofei | 8:6fd7091e1478 | 21 | break; | 
| Xiaofei | 8:6fd7091e1478 | 22 | } | 
| Xiaofei | 3:fe623a260bf5 | 23 | _xbee.puts(buffer); | 
| Xiaofei | 4:58f5ff5eb15b | 24 | wait(0.05); | 
| Xiaofei | 3:fe623a260bf5 | 25 | } | 
| Xiaofei | 0:633baa9653b0 | 26 | } | 
| Xiaofei | 0:633baa9653b0 | 27 | |
| Xiaofei | 0:633baa9653b0 | 28 | void Xbee::Recv(char* buffer, const size_t& sz) | 
| Xiaofei | 0:633baa9653b0 | 29 | { | 
| Xiaofei | 6:9f2db7a38f19 | 30 | while(_xbee.readable()) | 
| Xiaofei | 6:9f2db7a38f19 | 31 | { | 
| Xiaofei | 7:922bf2a611b1 | 32 | if(_xbee.getc() == '.') | 
| Xiaofei | 7:922bf2a611b1 | 33 | { | 
| Xiaofei | 7:922bf2a611b1 | 34 | _xbee.gets(buffer,sz); | 
| Xiaofei | 7:922bf2a611b1 | 35 | } | 
| Xiaofei | 6:9f2db7a38f19 | 36 | _xbee.putc('.'); | 
| Xiaofei | 6:9f2db7a38f19 | 37 | } | 
| Xiaofei | 6:9f2db7a38f19 | 38 | |
| Xiaofei | 0:633baa9653b0 | 39 | } |