by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp@0:94cb0f736f64, 2013-06-16 (annotated)
- Committer:
- robt
- Date:
- Sun Jun 16 15:32:03 2013 +0000
- Revision:
- 0:94cb0f736f64
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robt | 0:94cb0f736f64 | 1 | /* Program Example 12.8: Ethernet read |
robt | 0:94cb0f736f64 | 2 | */ |
robt | 0:94cb0f736f64 | 3 | #include "mbed.h" |
robt | 0:94cb0f736f64 | 4 | Ethernet eth; // Ethernet object |
robt | 0:94cb0f736f64 | 5 | Serial pc(USBTX, USBRX); // tx, rx for host terminal coms |
robt | 0:94cb0f736f64 | 6 | char buf[0xFF]; // create a large buffer to store data |
robt | 0:94cb0f736f64 | 7 | int main() { |
robt | 0:94cb0f736f64 | 8 | pc.printf("Ethernet data read and display\n\r"); |
robt | 0:94cb0f736f64 | 9 | while (1) { |
robt | 0:94cb0f736f64 | 10 | int size = eth.receive(); // get size of incoming data packet |
robt | 0:94cb0f736f64 | 11 | if (size > 0) { // if packet received |
robt | 0:94cb0f736f64 | 12 | eth.read(buf, size); // read packet to data buffer |
robt | 0:94cb0f736f64 | 13 | pc.printf("size = %d data = ",size); // print to screen |
robt | 0:94cb0f736f64 | 14 | for (int i=0;i<size;i++) { // loop for each data byte |
robt | 0:94cb0f736f64 | 15 | pc.printf("%02X ",buf[i]); // print data to screen |
robt | 0:94cb0f736f64 | 16 | } |
robt | 0:94cb0f736f64 | 17 | pc.printf("\n\r"); |
robt | 0:94cb0f736f64 | 18 | } |
robt | 0:94cb0f736f64 | 19 | } |
robt | 0:94cb0f736f64 | 20 | } |
robt | 0:94cb0f736f64 | 21 |