Changeset 603:fa52efd1e870
- Timestamp:
- 06/11/08 11:24:18 (7 months ago)
- Author:
- Maxime Petazzoni <maxime.petazzoni@…>
- Branch:
- default
- Message:
-
Record commands from the RCMD console to the file. Also add
a direct command execution mode.
- Location:
- nxos/systems/tag-route
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r600
|
r603
|
|
| 11 | 11 | |
| 12 | 12 | #include "base/types.h" |
| | 13 | #include "base/lib/fs/fs.h" |
| 13 | 14 | |
| 14 | 15 | #define ROUTE_FILE "tag.data" |
| … |
… |
|
| 17 | 18 | void replay(char *filename); |
| 18 | 19 | void usb_recv(void); |
| | 20 | void usb_recv_to(fs_fd_t fd); |
| 19 | 21 | |
| 20 | 22 | #endif /* __NXOS_TAG_ROUTE_MAIN_H__ */ |
-
|
r600
|
r603
|
|
| 15 | 15 | #include "main.h" |
| 16 | 16 | |
| 17 | | #define TEST_DATA "print hello world\nmove A,B 100 1500\nwait 2000\nplay 1500 1000 sync\nprint done" |
| 18 | | #define DATA_SIZE strlen(TEST_DATA) |
| 19 | | |
| 20 | 17 | void record(char *filename) { |
| 21 | 18 | fs_fd_t fd; |
| 22 | 19 | fs_err_t err; |
| 23 | | size_t i; |
| 24 | 20 | |
| 25 | 21 | nx_display_clear(); |
| … |
… |
|
| 47 | 43 | } |
| 48 | 44 | |
| 49 | | nx_display_string("File opened.\n\n"); |
| 50 | | nx_display_string("Writing...\n"); |
| 51 | | |
| 52 | | for (i=0; i<DATA_SIZE; i++) { |
| 53 | | err = nx_fs_write(fd, (U8)TEST_DATA[i]); |
| 54 | | |
| 55 | | if (err != FS_ERR_NO_ERROR) { |
| 56 | | nx_display_string("Err: "); |
| 57 | | nx_display_uint(err); |
| 58 | | nx_display_end_line(); |
| 59 | | } |
| 60 | | } |
| | 45 | nx_display_string("File opened.\n"); |
| | 46 | nx_display_string("Waiting...\n"); |
| | 47 | usb_recv_to(fd); |
| 61 | 48 | |
| 62 | 49 | nx_display_uint(nx_fs_get_filesize(fd)); |
| 63 | | nx_display_string("/"); |
| 64 | | nx_display_uint(DATA_SIZE); |
| 65 | 50 | nx_display_string("B written.\n"); |
| 66 | 51 | nx_fs_close(fd); |
-
|
r600
|
r603
|
|
| 10 | 10 | #include "base/display.h" |
| 11 | 11 | #include "base/util.h" |
| | 12 | #include "base/drivers/systick.h" |
| 12 | 13 | #include "base/drivers/usb.h" |
| | 14 | #include "base/lib/fs/fs.h" |
| 13 | 15 | #include "base/lib/rcmd/rcmd.h" |
| 14 | 16 | |
| 15 | 17 | #include "main.h" |
| 16 | 18 | |
| 17 | | static void usb_readline(char *buf) { |
| 18 | | int i=0; |
| | 19 | static void usb_readline(U8 *buf) { |
| | 20 | size_t len; |
| | 21 | int i = 0; |
| 19 | 22 | |
| 20 | | do { |
| 21 | | nx_usb_read((U8 *)(buf+i), 1); |
| 22 | | } while (buf[i] != '\0' || buf[i] != '\n'); |
| | 23 | nx_usb_read(buf, RCMD_BUF_LEN*sizeof(char)); |
| | 24 | for (i=0; i<10 && !nx_usb_data_read(); i++) { |
| | 25 | nx_systick_wait_ms(200); |
| | 26 | } |
| | 27 | |
| | 28 | if (i >= 10) { |
| | 29 | return; |
| | 30 | } |
| | 31 | |
| | 32 | len = nx_usb_data_read(); |
| | 33 | if (len+1 < RCMD_BUF_LEN) { |
| | 34 | buf[len+1] = '\0'; |
| | 35 | } else { |
| | 36 | buf[RCMD_BUF_LEN-1] = '\0'; |
| | 37 | } |
| 23 | 38 | } |
| 24 | 39 | |
| 25 | 40 | void usb_recv(void) { |
| 26 | | char buf[RCMD_BUF_LEN]; |
| | 41 | U8 buf[RCMD_BUF_LEN]; |
| 27 | 42 | |
| 28 | 43 | nx_display_clear(); |
| 29 | | nx_display_string("Waiting...\n"); |
| | 44 | nx_display_string("<< "); |
| 30 | 45 | |
| 31 | 46 | do { |
| 32 | 47 | memset(buf, 0, RCMD_BUF_LEN); |
| 33 | 48 | usb_readline(buf); |
| 34 | | nx_display_string(buf); |
| 35 | | } while (!streq(buf, "end")); |
| 36 | 49 | |
| | 50 | if (!*buf) { |
| | 51 | continue; |
| | 52 | } |
| | 53 | |
| | 54 | nx_display_string((char *)buf); |
| | 55 | nx_display_end_line(); |
| | 56 | |
| | 57 | nx_rcmd_do((char *)buf); |
| | 58 | nx_systick_wait_ms(50); |
| | 59 | nx_display_string("<< "); |
| | 60 | } while (!streq((char *)buf, "end")); |
| | 61 | } |
| | 62 | |
| | 63 | void usb_recv_to(fs_fd_t fd) { |
| | 64 | U8 buf[RCMD_BUF_LEN]; |
| | 65 | size_t i; |
| | 66 | |
| | 67 | do { |
| | 68 | memset(buf, 0, RCMD_BUF_LEN); |
| | 69 | usb_readline(buf); |
| | 70 | |
| | 71 | if (!*buf) { |
| | 72 | continue; |
| | 73 | } |
| | 74 | |
| | 75 | for (i=0; i<strlen((char *)buf); i++) { |
| | 76 | nx_fs_write(fd, buf[i]); |
| | 77 | } |
| | 78 | nx_fs_write(fd, (U8)'\n'); |
| | 79 | |
| | 80 | nx_rcmd_do((char *)buf); |
| | 81 | nx_systick_wait_ms(50); |
| | 82 | } while (!streq((char *)buf, "end")); |
| 37 | 83 | } |
| 38 | 84 | |