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.
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed
application/main.cpp@3:998f7fb862af, 2016-12-09 (annotated)
- Committer:
- micbio
- Date:
- Fri Dec 09 11:22:47 2016 +0000
- Revision:
- 3:998f7fb862af
dupa
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| micbio | 3:998f7fb862af | 1 | #include "mbed.h" |
| micbio | 3:998f7fb862af | 2 | #include "EthernetInterface.h" |
| micbio | 3:998f7fb862af | 3 | #include "SDFileSystem.h" |
| micbio | 3:998f7fb862af | 4 | #include "cli.hpp" |
| micbio | 3:998f7fb862af | 5 | #include "file_manager.hpp" |
| micbio | 3:998f7fb862af | 6 | |
| micbio | 3:998f7fb862af | 7 | #define SD 1 |
| micbio | 3:998f7fb862af | 8 | #define MII 0 |
| micbio | 3:998f7fb862af | 9 | |
| micbio | 3:998f7fb862af | 10 | #if SD + MII == 2 |
| micbio | 3:998f7fb862af | 11 | #error "Wybierz tylko jeden przyklad." |
| micbio | 3:998f7fb862af | 12 | #endif |
| micbio | 3:998f7fb862af | 13 | |
| micbio | 3:998f7fb862af | 14 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
| micbio | 3:998f7fb862af | 15 | Serial pc(USBTX, USBRX); |
| micbio | 3:998f7fb862af | 16 | DigitalOut led(LED1); |
| micbio | 3:998f7fb862af | 17 | EthernetInterface eth; |
| micbio | 3:998f7fb862af | 18 | |
| micbio | 3:998f7fb862af | 19 | int main() { |
| micbio | 3:998f7fb862af | 20 | #if MII |
| micbio | 3:998f7fb862af | 21 | pc.printf("Ethernet example\r\n"); |
| micbio | 3:998f7fb862af | 22 | eth.init(); //Use DHCP |
| micbio | 3:998f7fb862af | 23 | eth.connect(); |
| micbio | 3:998f7fb862af | 24 | pc.printf("IP Address is %s\n", eth.getIPAddress()); |
| micbio | 3:998f7fb862af | 25 | |
| micbio | 3:998f7fb862af | 26 | TCPSocketConnection sock; |
| micbio | 3:998f7fb862af | 27 | sock.connect("mbed.org", 80); |
| micbio | 3:998f7fb862af | 28 | |
| micbio | 3:998f7fb862af | 29 | char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; |
| micbio | 3:998f7fb862af | 30 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
| micbio | 3:998f7fb862af | 31 | |
| micbio | 3:998f7fb862af | 32 | char buffer[300]; |
| micbio | 3:998f7fb862af | 33 | int ret; |
| micbio | 3:998f7fb862af | 34 | while (true) { |
| micbio | 3:998f7fb862af | 35 | ret = sock.receive(buffer, sizeof(buffer)-1); |
| micbio | 3:998f7fb862af | 36 | if (ret <= 0) |
| micbio | 3:998f7fb862af | 37 | break; |
| micbio | 3:998f7fb862af | 38 | buffer[ret] = '\0'; |
| micbio | 3:998f7fb862af | 39 | pc.printf("Received %d chars from server:\n%s\n", ret, buffer); |
| micbio | 3:998f7fb862af | 40 | } |
| micbio | 3:998f7fb862af | 41 | |
| micbio | 3:998f7fb862af | 42 | sock.close(); |
| micbio | 3:998f7fb862af | 43 | |
| micbio | 3:998f7fb862af | 44 | eth.disconnect(); |
| micbio | 3:998f7fb862af | 45 | |
| micbio | 3:998f7fb862af | 46 | while(1) {} |
| micbio | 3:998f7fb862af | 47 | #elif SD |
| micbio | 3:998f7fb862af | 48 | cli_sd cli; |
| micbio | 3:998f7fb862af | 49 | file_manager fm; |
| micbio | 3:998f7fb862af | 50 | char cmd; |
| micbio | 3:998f7fb862af | 51 | |
| micbio | 3:998f7fb862af | 52 | cli.welcome(); |
| micbio | 3:998f7fb862af | 53 | cli.print_help(); |
| micbio | 3:998f7fb862af | 54 | |
| micbio | 3:998f7fb862af | 55 | while(1) |
| micbio | 3:998f7fb862af | 56 | { |
| micbio | 3:998f7fb862af | 57 | cmd = cli.get_cmd(); |
| micbio | 3:998f7fb862af | 58 | |
| micbio | 3:998f7fb862af | 59 | switch(cmd) |
| micbio | 3:998f7fb862af | 60 | { |
| micbio | 3:998f7fb862af | 61 | // case 'm': |
| micbio | 3:998f7fb862af | 62 | // break; |
| micbio | 3:998f7fb862af | 63 | case 'p': |
| micbio | 3:998f7fb862af | 64 | fm.set_path(); |
| micbio | 3:998f7fb862af | 65 | break; |
| micbio | 3:998f7fb862af | 66 | case 'w': |
| micbio | 3:998f7fb862af | 67 | fm.write_to_file(); |
| micbio | 3:998f7fb862af | 68 | break; |
| micbio | 3:998f7fb862af | 69 | // case 'a': |
| micbio | 3:998f7fb862af | 70 | // fm.append_to_file(); |
| micbio | 3:998f7fb862af | 71 | // break; |
| micbio | 3:998f7fb862af | 72 | case 'r': |
| micbio | 3:998f7fb862af | 73 | fm.read_file(); |
| micbio | 3:998f7fb862af | 74 | break; |
| micbio | 3:998f7fb862af | 75 | case 'h': |
| micbio | 3:998f7fb862af | 76 | cli.print_help(); |
| micbio | 3:998f7fb862af | 77 | break; |
| micbio | 3:998f7fb862af | 78 | default: |
| micbio | 3:998f7fb862af | 79 | pc.printf("Error.\r\n"); // should never enter this |
| micbio | 3:998f7fb862af | 80 | break; |
| micbio | 3:998f7fb862af | 81 | } |
| micbio | 3:998f7fb862af | 82 | } |
| micbio | 3:998f7fb862af | 83 | #endif |
| micbio | 3:998f7fb862af | 84 | } |