Changeset 433 for EcnlProtoTool/trunk


Ignore:
Timestamp:
Jul 5, 2020, 9:26:49 PM (4 years ago)
Author:
coas-nagasima
Message:

dateコマンド追加
コードの整理

Location:
EcnlProtoTool/trunk/ntshell
Files:
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c

    r424 r433  
    789789}
    790790
     791int usrcmd_date(int argc, char **argv)
     792{
     793        int ret;
     794        struct timespec tp;
     795        char buf[30];
     796
     797        ret = shell_clock_gettime(CLOCK_REALTIME, &tp);
     798        if (ret != 0) {
     799                ntstdio_printf(&ntstdio, "clock_gettime error %d", ret);
     800                return 0;
     801        }
     802
     803        memset(buf, 0, sizeof(buf));
     804        if (ctime_r(&tp.tv_sec, buf) == NULL) {
     805                ntstdio_printf(&ntstdio, "ctime_r error");
     806                return 0;
     807        }
     808
     809        /* 改行コードの削除 */
     810        ret = ntlibc_strlen(buf);
     811        buf[ret - 1] = '\0';
     812
     813        ntstdio_printf(&ntstdio, "%s .%09ld\n", buf, tp.tv_nsec);
     814        return 0;
     815}
     816
    791817int usrcmd_info(int argc, char **argv)
    792818{
  • EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.h

    r331 r433  
    5050int usrcmd_mkdir(int argc, char **argv);
    5151int usrcmd_hexdump(int argc, char **argv);
     52int usrcmd_date(int argc, char **argv);
    5253
    5354int usrcmd_help(int argc, char **argv);
  • EcnlProtoTool/trunk/ntshell/ntshell/util/ntstdio.c

    r331 r433  
    186186                 */
    187187                value = (flag & FLAG_SIZE_LONG_INT) ? va_arg(arp, long)
    188                         : (flag & FLAG_SIZE_HALF_INT) ? ((d == 'D') ? (long)va_arg(arp, short) : (long)va_arg(arp, unsigned short))
     188                        : (flag & FLAG_SIZE_HALF_INT) ? ((d == 'D') ? (long)((short)va_arg(arp, int)) : (long)((unsigned short)va_arg(arp, unsigned int)))
    189189                                : ((d == 'D') ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int));
    190190                if ((d == 'D') && (value & 0x80000000)) {
     
    224224        handle->xi = xi;
    225225        handle->xo = xo;
    226         handle->outptr = 0;
    227         handle->len = 0;
    228226        handle->pos = 0;
    229227        handle->option = option;
     
    232230static void _putc(ntstdio_t *handle, char c)
    233231{
    234         if (handle->outptr) {
    235                 if ((handle->pos + 1) >= handle->len)
    236                         return;
    237                 handle->outptr[handle->pos] = (unsigned char)c;
    238                 handle->pos++;
    239                 return;
    240         }
    241 
    242232        if (handle->xo) {
    243233                handle->xo(handle, (unsigned char)c);
     
    291281}
    292282
     283struct put_buf_t {
     284        char *outptr;
     285        int len;
     286};
     287
     288static void put_buf(struct ntstdio_t *handle, unsigned char c)
     289{
     290        struct put_buf_t *put_buf = (struct put_buf_t *)handle->exinf;
     291        if ((handle->pos + 1) >= put_buf->len)
     292                return;
     293        put_buf->outptr[handle->pos] = (char)c;
     294        handle->pos++;
     295}
     296
    293297int ntstdio_snprintf(char *buf, int len, const char *fmt, ...)
    294298{
    295299        int result;
    296300        ntstdio_t handle;
     301        struct put_buf_t exinf;
    297302        va_list arp;
    298303        /* Switch destination for memory */
     304        handle.xo = put_buf;
    299305        handle.option = 0;
    300         handle.outptr = buf;
    301         handle.len = len;
    302306        handle.pos = 0;
     307        handle.exinf = &exinf;
     308        exinf.outptr = buf;
     309        exinf.len = len;
     310
    303311        va_start(arp, fmt);
    304312        result = xvprintf(&handle, fmt, arp);
     
    306314
    307315        /* Terminate output string with a \0 */
    308         handle.outptr[handle.pos] = '\0';
     316        buf[handle.pos] = '\0';
    309317        return result;
    310318}
  • EcnlProtoTool/trunk/ntshell/ntshell/util/ntstdio.h

    r331 r433  
    6767#define NTSTDIO_OPTION_LF_CR        (1 << 3)
    6868
     69struct ntstdio_t;
    6970typedef unsigned char (*NTSTDIO_XI)(struct ntstdio_t *handle);
    7071typedef void (*NTSTDIO_XO)(struct ntstdio_t *handle, unsigned char c);
     
    7374        NTSTDIO_XI xi;
    7475        NTSTDIO_XO xo;
    75         char *outptr;
    76         int len;
    7776        int pos;
    7877        unsigned int option;
     78        void *exinf;
    7979} ntstdio_t;
    8080
  • EcnlProtoTool/trunk/ntshell/src/fdtable.c

    r424 r433  
    5656//#include <ethernet_api.h>
    5757#include "ff.h"
    58 #include "socket_stub.h"
     58#include "fdtable.h"
    5959#include "kernel_cfg.h"
    6060//#include <string.h>
  • EcnlProtoTool/trunk/ntshell/src/io_stub.c

    r424 r433  
    5757#include <netinet/udp_var.h>
    5858//#include <ethernet_api.h>
    59 #include "socket_stub.h"
     59#include "fdtable.h"
    6060//#include <sys/stat.h>
    6161#include "util/ntstdio.h"
  • EcnlProtoTool/trunk/ntshell/src/main.c

    r432 r433  
    11/*
    2  *  TOPPERS ECHONET Lite Communication Middleware
     2 *  TOPPERS PROJECT Home Network Working Group Software
    33 *
    4  *  Copyright (C) 2014-2017 Cores Co., Ltd. Japan
     4 *  Copyright (C) 2014-2019 Cores Co., Ltd. Japan
    55 *
    66 *  上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
     
    4545#include <sil.h>
    4646#include <setjmp.h>
    47 //#include <string.h>
     47#include <string.h>
    4848#include "syssvc/serial.h"
    4949#include "syssvc/syslog.h"
     
    7070#include "usrcmd.h"
    7171#include "util/ntopt.h"
    72 #include "socket_stub.h"
     72#include "fdtable.h"
     73#include "target_syssvc.h"
    7374
    7475ID ws_api_mailboxid = MAIN_DATAQUEUE;
    7576ID ws_mempoolid = MPF_NET_BUF_256;
    76 
    77 #define SIO_PORTID 1
    7877
    7978char command[NTOPT_TEXT_MAXLEN];
     
    9897const struct utsname host_name = {
    9998        "TOPPERS/ASP3",
    100     "GR-PEACH",
    101     "3.1.0",
    102     "3.1.0",
    103     "GR-PEACH",
     99        TARGET_NAME,
     100        "3.5.0",
     101        "3.5.0",
     102        TARGET_NAME,
    104103    "toppers.jp"
    105104};
     
    315314        {"mkdir", "Make directory", usrcmd_mkdir},
    316315        {"hexdump", "Hex dump", usrcmd_hexdump},
     316        {"date", "print date and time", usrcmd_date},
    317317        {"info", "This is a description text string for info command.", usrcmd_info},
    318318        {"exit", "Exit Natural Tiny Shell", usrcmd_exit},
  • EcnlProtoTool/trunk/ntshell/src/main.h

    r432 r433  
    4040
    4141/*
    42  *              サンプルプログラム(1)のヘッダファイル
     42 *              ntshellタスクのヘッダファイル
    4343 */
    4444
     
    4747 */
    4848#include <kernel.h>
     49
     50#include "usrcmd.h"
     51#include "core/ntshell.h"
    4952
    5053/*
  • EcnlProtoTool/trunk/ntshell/src/socket_stub.c

    r424 r433  
    5757extern const ID tmax_tcp_cepid;
    5858#include "ff.h"
    59 #include "socket_stub.h"
     59#include "fdtable.h"
    6060
    6161#define SOCKET_TIMEOUT 2000000
Note: See TracChangeset for help on using the changeset viewer.