Changeset 331 for EcnlProtoTool/trunk/ntshell/src/main.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/src/main.c
r321 r331 40 40 */ 41 41 42 #include "shellif.h" 42 43 #include <kernel.h> 43 #include <t_syslog.h>44 44 #include <t_stdlib.h> 45 45 #include <sil.h> 46 #include <s tdlib.h>46 #include <setjmp.h> 47 47 #include <string.h> 48 #include <stdio.h>49 #include <setjmp.h>50 48 #include "syssvc/serial.h" 51 49 #include "syssvc/syslog.h" … … 64 62 #include <net/if_var.h> 65 63 #include <netinet/udp_var.h> 66 #include <ethernet_api.h>67 64 #include "ffarch.h" 68 #include "gpio_api.h"69 65 #include "ff.h" 70 66 #include "websocket_fbs.h" 71 #include "ntshell.h" 72 #include "ntstdio.h" 67 #include "core/ntshell.h" 68 #include "core/ntlibc.h" 69 #include "util/ntstdio.h" 73 70 #include "usrcmd.h" 74 #include "ntopt.h" 75 76 #ifndef _MSC_VER 77 void strcpy_s(char *dst, int size, const char *src); 78 #endif 71 #include "util/ntopt.h" 72 #include "socket_stub.h" 79 73 80 74 ID ws_api_mailboxid = MAIN_DATAQUEUE; … … 86 80 ntstdio_t ntstdio; 87 81 88 const uint8_t mac_addr[6] = {0x00, 0x30, 0x13, 0x06, 0x62, 0xC0}; 89 const char host_name[] = "GR-PEACH"; 82 const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}; 83 const struct utsname host_name = { 84 "TOPPERS/ASP3", 85 "GR-PEACH", 86 "3.1.0", 87 "3.1.0", 88 "GR-PEACH", 89 "toppers.jp" 90 }; 90 91 91 92 static void netif_link_callback(T_IFNET *ether); … … 228 229 char buf[1]; 229 230 if(serial_rea_dat(SIO_PORTID, buf, 1) != 1) 230 return - 1;231 return -EIO; 231 232 return buf[0]; 232 233 } … … 305 306 306 307 if (exec) { 307 strcpy_s(command, sizeof(command), "mruby -b 1:/upload/main.mrb");308 ntlibc_strlcpy(command, "mruby -b 1:/upload/main.mrb", sizeof(command)); 308 309 309 310 execute_command(1); … … 371 372 } 372 373 373 int gethostname(char *name, size_t len)374 { 375 return strlcpy(name, host_name, len);376 } 377 378 static int usrcmd_ntopt_callback( int argc, char **argv, void *extobj);374 int shell_uname(struct utsname *uts) 375 { 376 return memcpy(uts, &host_name, sizeof(host_name)); 377 } 378 379 static int usrcmd_ntopt_callback(long *args, void *extobj); 379 380 int mruby_exit_code; 380 381 volatile int mruby_state; 381 typedef void (*PowerOn_Reset_t)( int argc, char **argv);382 typedef void (*PowerOn_Reset_t)(long *args); 382 383 jmp_buf process_exit; 383 384 … … 392 393 } 393 394 394 static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj) 395 { 395 typedef struct 396 { 397 const cmd_table_t *table; 398 int count; 399 } cmd_table_info_t; 400 401 static const cmd_table_t cmdlist[] = { 402 {"cd", "change directory", usrcmd_cd }, 403 {"ls", "list files", usrcmd_ls }, 404 {"cp", "copy file", usrcmd_cp }, 405 {"rm", "remove file", usrcmd_rm }, 406 {"mv", "move file", usrcmd_mv }, 407 {"mkdir", "Make directory", usrcmd_mkdir}, 408 {"hexdump", "Hex dump", usrcmd_hexdump}, 409 {"info", "This is a description text string for info command.", usrcmd_info}, 410 {"exit", "Exit Natural Tyny Shell", usrcmd_exit}, 411 }; 412 cmd_table_info_t cmd_table_info = { cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) }; 413 414 static int usrcmd_ntopt_callback(long *args, void *extobj) 415 { 416 const cmd_table_t *p = cmd_table_info.table; 417 if (ntlibc_strcmp((const char *)args[1], "help") == 0) { 418 usrcmd_help(args[0], (char **)&args[1]); 419 } 420 else for (int i = 0; i < cmd_table_info.count; i++) { 421 if (ntlibc_strcmp((const char *)args[1], p->cmd) == 0) { 422 return p->func(args[0], (char **)&args[1]); 423 } 424 p++; 425 } 396 426 if (setjmp(process_exit) == 0) { 397 (*((PowerOn_Reset_t *)0x18200000))(arg c, argv);427 (*((PowerOn_Reset_t *)0x18200000))(args); 398 428 } 399 429 clean_fd(); 430 return 0; 431 } 432 433 int usrcmd_help(int argc, char **argv) 434 { 435 const cmd_table_t *p = cmd_table_info.table; 436 for (int i = 0; i < cmd_table_info.count; i++) { 437 ntstdio_puts(&ntstdio, p->cmd); 438 ntstdio_puts(&ntstdio, "\t:"); 439 ntstdio_puts(&ntstdio, p->desc); 440 ntstdio_puts(&ntstdio, "\n"); 441 p++; 442 } 400 443 return 0; 401 444 } … … 422 465 423 466 void shell_exit(int exitcd) 467 { 468 mruby_exit_code = exitcd; 469 longjmp(process_exit, 1); 470 } 471 472 void shell_exit_group(int exitcd) 424 473 { 425 474 mruby_exit_code = exitcd; … … 458 507 static int cmd_execute(const char *text, void *extobj) 459 508 { 460 strlcpy(command, text, sizeof(command));509 ntlibc_strlcpy(command, text, sizeof(command)); 461 510 return execute_command(1); 462 511 } … … 464 513 int stdio_close(struct _IO_FILE *fp) 465 514 { 466 return - 1;515 return -EPERM; 467 516 } 468 517 469 518 size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len) 470 519 { 471 return - 1;520 return -EPERM; 472 521 } 473 522 474 523 size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len) 475 524 { 476 return - 1;525 return -EPERM; 477 526 } 478 527 … … 507 556 int sio_close(struct _IO_FILE *fp) 508 557 { 509 return - 1;558 return -EPERM; 510 559 } 511 560 512 561 size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len) 513 562 { 514 return - 1;563 return -EPERM; 515 564 } 516 565 517 566 size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len) 518 567 { 519 return -1; 520 } 568 return -EPERM; 569 } 570 571 off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org) 572 { 573 return -EPERM; 574 } 575 576 int sio_ioctl(struct _IO_FILE *fp, int request, void *arg) 577 { 578 switch (request) { 579 case TIOCGWINSZ: 580 return 0; 581 case TCGETS: 582 return sio_tcgetattr(fp->fd, (struct termios *)arg); 583 case TCSETS + TCSANOW: 584 case TCSETS + TCSADRAIN: 585 case TCSETS + TCSAFLUSH: 586 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg); 587 } 588 589 return -EINVAL; 590 } 591 592 int shell_clock_getres(clockid_t clk_id, struct timespec *res) 593 { 594 if (clk_id != CLOCK_REALTIME) 595 return -EINVAL; 596 597 memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec)); 598 res->tv_nsec = 0; 599 600 return 0; 601 } 602 603 int shell_clock_gettime(clockid_t clk_id, struct timespec *tp) 604 { 605 SYSTIM now = 0; 606 607 if (clk_id != CLOCK_REALTIME) 608 return -EINVAL; 609 610 get_tim(&now); 611 tp->tv_sec = now / 1000000; 612 tp->tv_nsec = (now % 1000000) * 1000; 613 614 return 0; 615 } 616 617 int shell_clock_settime(clockid_t clk_id, const struct timespec *tp) 618 { 619 if (clk_id != CLOCK_REALTIME) 620 return -EINVAL; 621 622 rtc_write(tp->tv_sec); 623 624 return 0; 625 } 626 627 sigset_t g_sigmask; 628 629 int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) 630 { 631 if (old != NULL) 632 memcpy(old, &g_sigmask, sizeof(sigset_t)); 633 634 switch (how) { 635 case SIG_BLOCK: 636 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) { 637 g_sigmask.__bits[i] |= set->__bits[i]; 638 } 639 break; 640 case SIG_UNBLOCK: 641 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) { 642 g_sigmask.__bits[i] &= ~set->__bits[i]; 643 } 644 break; 645 case SIG_SETMASK: 646 memcpy(&g_sigmask, set, sizeof(sigset_t)); 647 break; 648 default: 649 return -EINVAL; 650 } 651 652 return 0; 653 } 654 655 struct sigaction sigtable[6]; 656 657 int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) 658 { 659 struct sigaction *sat; 660 661 switch(sig){ 662 case SIGALRM: 663 sat = &sigtable[0]; 664 break; 665 case SIGFPE: 666 sat = &sigtable[1]; 667 break; 668 case SIGILL: 669 sat = &sigtable[2]; 670 break; 671 case SIGSEGV: 672 sat = &sigtable[3]; 673 break; 674 case SIGBUS: 675 sat = &sigtable[4]; 676 break; 677 case SIGABRT: 678 sat = &sigtable[5]; 679 break; 680 default: 681 return -EINVAL; 682 } 683 684 if (old != NULL) 685 memcpy(old, sat, sizeof(struct sigaction)); 686 687 memcpy(sat, sa, sizeof(struct sigaction)); 688 689 return 0; 690 } 691 692 int shell_madvise(void *a, size_t b, int c) 693 { 694 return 0; 695 } 696
Note:
See TracChangeset
for help on using the changeset viewer.