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@19:4bc3e2e68495, 2015-11-28 (annotated)
- Committer:
- Xiaofei
- Date:
- Sat Nov 28 04:14:05 2015 +0000
- Revision:
- 19:4bc3e2e68495
- Parent:
- 18:1604f829e859
- Child:
- 20:f7abfda12a41
c
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 | 16:cc598ae4ab52 | 6 | _xbee.baud(9600); |
Xiaofei | 16:cc598ae4ab52 | 7 | } |
Xiaofei | 16:cc598ae4ab52 | 8 | |
Xiaofei | 16:cc598ae4ab52 | 9 | void Xbee::Reset() |
Xiaofei | 16:cc598ae4ab52 | 10 | { |
Xiaofei | 2:33462c1e9f45 | 11 | _rst = 0; |
Xiaofei | 2:33462c1e9f45 | 12 | wait(0.01); |
Xiaofei | 2:33462c1e9f45 | 13 | _rst = 1; |
Xiaofei | 2:33462c1e9f45 | 14 | wait(0.01); |
Xiaofei | 5:d14636b861ff | 15 | |
Xiaofei | 2:33462c1e9f45 | 16 | } |
Xiaofei | 2:33462c1e9f45 | 17 | |
Xiaofei | 17:2271d7a273e7 | 18 | void Xbee::Send(const char& buffer) |
Xiaofei | 0:633baa9653b0 | 19 | { |
Xiaofei | 9:c0955550ca13 | 20 | while(1) |
Xiaofei | 3:fe623a260bf5 | 21 | { |
Xiaofei | 13:01e5b1744921 | 22 | _xbee.putc('.'); |
Xiaofei | 19:4bc3e2e68495 | 23 | _xbee.putc(buffer); |
Xiaofei | 8:6fd7091e1478 | 24 | if(_xbee.getc() == '.') |
Xiaofei | 8:6fd7091e1478 | 25 | { |
Xiaofei | 8:6fd7091e1478 | 26 | break; |
Xiaofei | 8:6fd7091e1478 | 27 | } |
Xiaofei | 3:fe623a260bf5 | 28 | } |
Xiaofei | 0:633baa9653b0 | 29 | } |
Xiaofei | 0:633baa9653b0 | 30 | |
Xiaofei | 19:4bc3e2e68495 | 31 | void Xbee::Recv(char& buffer) |
Xiaofei | 0:633baa9653b0 | 32 | { |
Xiaofei | 11:4e806bf0fb3d | 33 | while(1) |
Xiaofei | 6:9f2db7a38f19 | 34 | { |
Xiaofei | 11:4e806bf0fb3d | 35 | if(_xbee.readable()) |
Xiaofei | 7:922bf2a611b1 | 36 | { |
Xiaofei | 12:8410a1f1df58 | 37 | if(_xbee.getc()=='.') |
Xiaofei | 19:4bc3e2e68495 | 38 | buffer = _xbee.getc(); |
Xiaofei | 10:c6100f1f2265 | 39 | _xbee.putc('.'); |
Xiaofei | 10:c6100f1f2265 | 40 | break; |
Xiaofei | 7:922bf2a611b1 | 41 | } |
Xiaofei | 6:9f2db7a38f19 | 42 | } |
Xiaofei | 0:633baa9653b0 | 43 | } |