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@38:c81bc5616e8e, 2015-12-03 (annotated)
- Committer:
- Xiaofei
- Date:
- Thu Dec 03 16:20:23 2015 +0000
- Revision:
- 38:c81bc5616e8e
- Parent:
- 37:8eba82309257
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 | 27:6bd26aff87e6 | 4 | //Serial pc(USBTX, USBRX); |
Xiaofei | 20:f7abfda12a41 | 5 | |
Xiaofei | 2:33462c1e9f45 | 6 | Xbee::Xbee(PinName tx, PinName rx , PinName rst):_xbee(tx,rx),_rst(rst) |
Xiaofei | 2:33462c1e9f45 | 7 | { |
Xiaofei | 16:cc598ae4ab52 | 8 | _xbee.baud(9600); |
Xiaofei | 16:cc598ae4ab52 | 9 | } |
Xiaofei | 16:cc598ae4ab52 | 10 | |
Xiaofei | 16:cc598ae4ab52 | 11 | void Xbee::Reset() |
Xiaofei | 16:cc598ae4ab52 | 12 | { |
Xiaofei | 2:33462c1e9f45 | 13 | _rst = 0; |
Xiaofei | 2:33462c1e9f45 | 14 | wait(0.01); |
Xiaofei | 2:33462c1e9f45 | 15 | _rst = 1; |
Xiaofei | 2:33462c1e9f45 | 16 | wait(0.01); |
Xiaofei | 5:d14636b861ff | 17 | |
Xiaofei | 2:33462c1e9f45 | 18 | } |
Xiaofei | 2:33462c1e9f45 | 19 | |
Xiaofei | 30:18ef9d8f1eea | 20 | void Xbee::Send(const char& buffer) |
Xiaofei | 0:633baa9653b0 | 21 | { |
Xiaofei | 28:8fdfd5bffe15 | 22 | while(1) |
Xiaofei | 3:fe623a260bf5 | 23 | { |
Xiaofei | 28:8fdfd5bffe15 | 24 | if(_xbee.writeable()) |
Xiaofei | 28:8fdfd5bffe15 | 25 | { |
Xiaofei | 31:84e27d1b86a6 | 26 | _xbee.putc('\0'); |
Xiaofei | 30:18ef9d8f1eea | 27 | _xbee.putc(buffer); |
Xiaofei | 28:8fdfd5bffe15 | 28 | } |
Xiaofei | 28:8fdfd5bffe15 | 29 | if(_xbee.readable()) |
Xiaofei | 28:8fdfd5bffe15 | 30 | { |
Xiaofei | 37:8eba82309257 | 31 | _xbee.getc(); |
Xiaofei | 28:8fdfd5bffe15 | 32 | break; |
Xiaofei | 28:8fdfd5bffe15 | 33 | } |
Xiaofei | 3:fe623a260bf5 | 34 | } |
Xiaofei | 0:633baa9653b0 | 35 | } |
Xiaofei | 0:633baa9653b0 | 36 | |
Xiaofei | 30:18ef9d8f1eea | 37 | void Xbee::Recv(char& buffer) |
Xiaofei | 0:633baa9653b0 | 38 | { |
Xiaofei | 28:8fdfd5bffe15 | 39 | while(1) |
Xiaofei | 38:c81bc5616e8e | 40 | { |
Xiaofei | 28:8fdfd5bffe15 | 41 | if(!_xbee.readable()) |
Xiaofei | 28:8fdfd5bffe15 | 42 | { |
Xiaofei | 30:18ef9d8f1eea | 43 | _xbee.putc('\0'); |
Xiaofei | 28:8fdfd5bffe15 | 44 | } |
Xiaofei | 28:8fdfd5bffe15 | 45 | else |
Xiaofei | 28:8fdfd5bffe15 | 46 | { |
Xiaofei | 31:84e27d1b86a6 | 47 | if(_xbee.getc()=='\0'); |
Xiaofei | 31:84e27d1b86a6 | 48 | { |
Xiaofei | 31:84e27d1b86a6 | 49 | buffer = _xbee.getc(); |
Xiaofei | 31:84e27d1b86a6 | 50 | } |
Xiaofei | 29:7b328499f9cf | 51 | break; |
Xiaofei | 28:8fdfd5bffe15 | 52 | } |
Xiaofei | 6:9f2db7a38f19 | 53 | } |
Xiaofei | 0:633baa9653b0 | 54 | } |