Changeset 603:fa52efd1e870

Show
Ignore:
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:
3 modified

Legend:

Unmodified
Added
Removed
  • nxos/systems/tag-route/main.h

    r600 r603  
    1111 
    1212#include "base/types.h" 
     13#include "base/lib/fs/fs.h" 
    1314 
    1415#define ROUTE_FILE "tag.data" 
     
    1718void replay(char *filename); 
    1819void usb_recv(void); 
     20void usb_recv_to(fs_fd_t fd); 
    1921 
    2022#endif /* __NXOS_TAG_ROUTE_MAIN_H__ */ 
  • nxos/systems/tag-route/record.c

    r600 r603  
    1515#include "main.h" 
    1616 
    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  
    2017void record(char *filename) { 
    2118  fs_fd_t fd; 
    2219  fs_err_t err; 
    23   size_t i; 
    2420 
    2521  nx_display_clear(); 
     
    4743  } 
    4844 
    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); 
    6148 
    6249  nx_display_uint(nx_fs_get_filesize(fd)); 
    63   nx_display_string("/"); 
    64   nx_display_uint(DATA_SIZE); 
    6550  nx_display_string("B written.\n"); 
    6651  nx_fs_close(fd); 
  • nxos/systems/tag-route/usb.c

    r600 r603  
    1010#include "base/display.h" 
    1111#include "base/util.h" 
     12#include "base/drivers/systick.h" 
    1213#include "base/drivers/usb.h" 
     14#include "base/lib/fs/fs.h" 
    1315#include "base/lib/rcmd/rcmd.h" 
    1416 
    1517#include "main.h" 
    1618 
    17 static void usb_readline(char *buf) { 
    18   int i=0; 
     19static void usb_readline(U8 *buf) { 
     20  size_t len; 
     21  int i = 0; 
    1922 
    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  } 
    2338} 
    2439 
    2540void usb_recv(void) { 
    26   char buf[RCMD_BUF_LEN]; 
     41  U8 buf[RCMD_BUF_LEN]; 
    2742 
    2843  nx_display_clear(); 
    29   nx_display_string("Waiting...\n"); 
     44  nx_display_string("<< "); 
    3045 
    3146  do { 
    3247    memset(buf, 0, RCMD_BUF_LEN); 
    3348    usb_readline(buf); 
    34     nx_display_string(buf); 
    35   } while (!streq(buf, "end")); 
    3649 
     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 
     63void 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")); 
    3783} 
    3884