Changeset 432 for EcnlProtoTool


Ignore:
Timestamp:
Jul 5, 2020, 6:30:00 PM (4 years ago)
Author:
coas-nagasima
Message:

ntshellのコードを整理

Location:
EcnlProtoTool/trunk/ntshell/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/ntshell/src/main.c

    r431 r432  
    7979char command[NTOPT_TEXT_MAXLEN];
    8080ntstdio_t ntstdio;
    81 ntshell_t ntshell;
    8281
    8382unsigned char ntstdio_xi(struct ntstdio_t *handle)
     
    118117
    119118struct main_obj_t {
     119        ntshell_t ntshell;
    120120        TMO timer;
    121121        enum main_state_t state;
     
    127127struct main_obj_t main_obj;
    128128
    129 static void netif_link_callback(T_IFNET *ether);
    130 static void main_initialize();
    131 static TMO main_get_timer();
    132 static void main_progress(TMO interval);
    133 static void main_timeout();
     129static void main_change_netif_link(T_IFNET *ether);
     130static void main_initialize(struct main_obj_t *obj);
     131static TMO main_get_timer(struct main_obj_t *obj);
     132static void main_progress(struct main_obj_t *obj, TMO elapse);
     133static void main_timeout(struct main_obj_t *obj);
    134134extern int execute_command(int wait);
    135135static int usrcmd_ntopt_callback(long *args, void *extobj);
     
    143143{
    144144        return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
    145 #if 0
    146         int result = cnt;
    147         ER ret;
    148         bool_t tmo = false;
    149 
    150         while (cnt > 0) {
    151                 /* タイムアウト処理 */
    152                 if (tmo) {
    153                         tmo = false;
    154                         main_timeout();
    155                 }
    156 
    157                 if (main_obj.rcvmsg.ptr == NULL) {
    158                         ER ret2;
    159                         TMO timer;
    160                         WS_FBS_ID msg;
    161 
    162                         main_obj.prev = main_obj.now;
    163 
    164                         timer = main_get_timer();
    165 
    166                         ret = trcv_dtq(MAIN_DATAQUEUE, (intptr_t *)&msg, timer);
    167                         if ((ret != E_OK) && (ret != E_TMOUT)) {
    168                                 syslog(LOG_ERROR, "trcv_dtq => %d", ret);
    169                                 ext_tsk();
    170                                 return 0;
    171                         }
    172 
    173                         ret2 = get_tim(&main_obj.now);
    174                         if (ret2 != E_OK) {
    175                                 syslog(LOG_ERROR, "get_tim");
    176                                 ext_tsk();
    177                                 return 0;
    178                         }
    179 
    180                         /* 時間経過 */
    181                         main_progress(main_obj.now - main_obj.prev);
    182 
    183                         if (ret == E_OK) {
    184                                 /* メッセージ受信処理 */
    185                                 if (main_obj.rcvmsg.ptr == NULL) {
    186                                         main_obj.rcvmsg = msg;
    187                                 }
    188                                 else {
    189                                         ws_fbs_enqueue(&main_obj.wbs_queue, msg.ptr);
    190                                 }
    191                         }
    192 
    193                         tmo = true;
    194                 }
    195                 else {
    196                         WS_FBS_SSIZE_T len, slen;
    197 
    198                         len = _ws_fbs_get_datalen(main_obj.rcvmsg);
    199                         if (len > cnt)
    200                                 len = cnt;
    201 
    202                         ret = _ws_fbs_get_data(main_obj.rcvmsg, buf, len, &slen);
    203                         if (ret != E_OK) {
    204                                 syslog(LOG_ERROR, "_ws_fbs_get_data msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);
    205                                 ext_tsk();
    206                         }
    207                         cnt -= slen;
    208 
    209                         /* データが空の場合 */
    210                         if (!_ws_fbs_exist_data(main_obj.rcvmsg)) {
    211                                 ret = _ws_fbs_del(main_obj.rcvmsg);
    212                                 if (ret != E_OK) {
    213                                         syslog(LOG_ERROR, "trcv_dtq msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);
    214                                         ext_tsk();
    215                                 }
    216 
    217                                 main_obj.rcvmsg.ptr = NULL;
    218 
    219                                 /* キューからデータを取得 */
    220                                 ret = ws_fbs_dequeue(&main_obj.wbs_queue, &main_obj.rcvmsg.ptr);
    221                         }
    222                 }
    223         }
    224 
    225         return result;
    226 #endif
    227145}
    228146
     
    230148{
    231149        return serial_wri_dat(SIO_PORTID, buf, cnt);
    232 #if 0
    233         int result = cnt;
    234         ER ret;
    235 
    236         while (cnt > 0) {
    237                 _ws_fbs_cre(cnt, &main_obj.sndmsg);
    238 
    239                 //((ID *)main_obj.sndmsg.ptr->_gap)[0] = wbsid;
    240                 _ws_fbs_add_data(main_obj.sndmsg, buf, cnt);
    241 
    242                 ret = psnd_dtq(WEBSOCKET_MBXID, (intptr_t)main_obj.sndmsg.ptr);
    243                 if (ret != E_OK) {
    244                         syslog(LOG_ERROR, "psnd_dtq(WEBSOCKET_MBXID) : result=%d", ret);
    245                         _ws_fbs_del(main_obj.sndmsg);
    246                         return ret;
    247                 }
    248         }
    249 
    250         return result;
    251 #endif
    252 }
    253 
    254 static int cmd_execute(const char *text, void *extobj)
     150}
     151
     152int cmd_execute(const char *text, void *extobj)
    255153{
    256154        if (text != NULL) {
     
    273171void main_task(intptr_t exinf)
    274172{
    275         main_initialize();
    276 
    277         ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);
    278         ntshell_set_prompt(&ntshell, "NTShell>");
    279         ntshell_execute(&ntshell);
     173        struct main_obj_t *obj = (struct main_obj_t *)&main_obj;
     174
     175        main_initialize(obj);
     176
     177        ntshell_init(&obj->ntshell, uart_read, uart_write, cmd_execute, obj);
     178        ntshell_set_prompt(&obj->ntshell, "NTShell>");
     179        ntshell_execute(&obj->ntshell);
    280180}
    281181
     
    283183 * 初期化
    284184 */
    285 static void main_initialize()
     185static void main_initialize(struct main_obj_t *obj)
    286186{
    287187        FILINFO fno;
     
    291191        fno.lfsize = _MAX_LFN + 1;
    292192#endif
    293         ER ret2;
     193        ER ret;
    294194
    295195        ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
    296196
    297         main_obj.timer = TMO_FEVR;
    298         main_obj.state = main_state_start;
     197        obj->timer = TMO_FEVR;
     198        obj->state = main_state_start;
    299199
    300200        gpio_t led_blue, led_green, led_red, sw;
     
    310210        gpio_write(&led_red, 0);
    311211
    312         ether_set_link_callback(netif_link_callback);
     212        ether_set_link_callback(main_change_netif_link);
    313213
    314214        /* 初期化 */
     
    336236        }
    337237
    338         ret2 = get_tim(&main_obj.now);
    339         if (ret2 != E_OK) {
     238        ret = get_tim(&obj->now);
     239        if (ret != E_OK) {
    340240                syslog(LOG_ERROR, "get_tim");
    341241                ext_tsk();
     
    347247 * タイマー取得
    348248 */
    349 static TMO main_get_timer()
    350 {
    351         TMO timer = main_obj.timer;
     249static TMO main_get_timer(struct main_obj_t *obj)
     250{
     251        TMO timer = obj->timer;
    352252
    353253        return timer;
     
    357257 * 時間経過
    358258 */
    359 static void main_progress(TMO interval)
    360 {
    361         if (main_obj.timer != TMO_FEVR) {
    362                 main_obj.timer -= interval;
    363                 if (main_obj.timer < 0) {
    364                         main_obj.timer = 0;
     259static void main_progress(struct main_obj_t *obj, TMO elapse)
     260{
     261        if (obj->timer != TMO_FEVR) {
     262                obj->timer -= elapse;
     263                if (obj->timer < 0) {
     264                        obj->timer = 0;
    365265                }
    366266        }
     
    370270 * タイムアウト処理
    371271 */
    372 static void main_timeout()
    373 {
    374         //if (main_obj.timer == 0) {
     272static void main_timeout(struct main_obj_t *obj)
     273{
     274        //if (obj->timer == 0) {
    375275        //}
    376276}
     
    382282}
    383283
    384 static void netif_link_callback(T_IFNET *ether)
     284static void main_change_netif_link(T_IFNET *ether)
    385285{
    386286        FLGPTN flgptn;
     
    406306        shellcmd_state = 2;
    407307}
    408 
    409 typedef struct
    410 {
    411         const cmd_table_t *table;
    412         int count;
    413 } cmd_table_info_t;
    414308
    415309static const cmd_table_t cmdlist[] = {
     
    429323{
    430324        const cmd_table_t *p = cmd_table_info.table;
     325        int result = 0;
     326        int found = 0;
     327
     328        if (*args == 0)
     329                return result;
     330
    431331        if (ntlibc_strcmp((const char *)args[1], "help") == 0) {
    432332                usrcmd_help(args[0], (char **)&args[1]);
  • EcnlProtoTool/trunk/ntshell/src/main.h

    r431 r432  
    5252 */
    5353
    54 #define MAIN_PRIORITY   5               /* メインタスクの優先度 */
     54#define MAIN_PRIORITY   5                       /* メインタスクの優先度 */
    5555#define SHELLCMD_PRIORITY       4               /* shellcmdタスクの優先度 */
    5656
     
    5858#define SHELLCMD_STACK_SIZE     0x00800000      /* shellcmdタスクのスタック領域のサイズ */
    5959
    60 #define NUM_MAIN_DATAQUEUE      1       /* メインタスクで待ち受けているデータキューのサイズ */
     60#define NUM_MAIN_DATAQUEUE      1               /* メインタスクで待ち受けているデータキューのサイズ */
    6161#define NUM_SHELLCMD_DATAQUEUE  1       /* shellcmdタスクで待ち受けているデータキューのサイズ */
    6262
     
    6666#ifndef TOPPERS_MACRO_ONLY
    6767
     68typedef struct
     69{
     70        const cmd_table_t *table;
     71        int count;
     72} cmd_table_info_t;
     73
    6874/* メインタスク */
    69 extern void main_task(intptr_t exinf);
     75void main_task(intptr_t exinf);
    7076
    7177/* shellcmdタスク */
    72 extern void shellcmd_task(intptr_t exinf);
     78void shellcmd_task(intptr_t exinf);
     79
     80/* コマンド実行 */
     81int cmd_execute(const char *text, void *extobj);
    7382
    7483/*
Note: See TracChangeset for help on using the changeset viewer.