Ignore:
Timestamp:
Feb 1, 2019, 9:57:09 PM (5 years ago)
Author:
coas-nagasima
Message:

TINETとSocket APIなどを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.c

    r359 r364  
    4545#include <sil.h>
    4646#include <setjmp.h>
     47#include <stdlib.h>
    4748#include <string.h>
    4849#include "syssvc/serial.h"
     
    8081
    8182ID ws_api_mailboxid = MAIN_DATAQUEUE;
     83#ifndef NOUSE_MPF_NET_BUF
    8284ID ws_mempoolid = MPF_NET_BUF_256;
     85#endif
    8386
    8487#if defined(IF_ETHER_BTUSB) || defined(IF_ETHER_ENBT)
     
    114117static void main_timeout();
    115118
     119extern int ntshell_exit;
     120
    116121int uart_read(char *buf, int cnt, void *extobj)
    117122{
    118         return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
     123        struct main_t *obj = (struct main_t *)extobj;
     124        int result;
     125        ER ret;
     126        int timer;
     127
     128        obj->prev = obj->now;
     129
     130        /* タイマー取得 */
     131        timer = main_get_timer();
     132
     133        /* 待ち */
     134        ret = serial_trea_dat(SIO_PORTID, buf, cnt, timer);
     135        if ((ret < 0) && (ret != E_OK) && (ret != E_TMOUT)) {
     136                syslog(LOG_NOTICE, "tslp_tsk ret: %s %d", itron_strerror(ret), timer);
     137                ntshell_exit = 1;
     138                return -1;
     139        }
     140        result = (int)ret;
     141
     142        ret = get_tim(&obj->now);
     143        if (ret != E_OK) {
     144                syslog(LOG_NOTICE, "get_tim ret: %s", itron_strerror(ret));
     145                ntshell_exit = 1;
     146                return -1;
     147        }
     148
     149                        /* 時間経過 */
     150        int elapse = obj->now - obj->prev;
     151        main_progress(elapse);
     152
     153        /* タイムアウト処理 */
     154        main_timeout();
     155
     156        return result;
    119157}
    120158
     
    122160{
    123161        return serial_wri_dat(SIO_PORTID, buf, cnt);
    124 }
    125 
    126 unsigned char ntstdio_xi(struct ntstdio_t *handle)
    127 {
    128         char buf[1];
    129         if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
    130                 return -EIO;
    131         return buf[0];
    132 }
    133 
    134 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
    135 {
    136         char buf[1];
    137         buf[0] = c;
    138         serial_wri_dat(SIO_PORTID, buf, 1);
    139162}
    140163
     
    156179        main_initialize();
    157180
    158         ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);
     181        ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, &main_obj);
    159182        ntshell_set_prompt(&ntshell, "NTShell>");
    160183        ntshell_execute(&ntshell);
     
    176199        ER ret;
    177200
     201#ifdef TOPPERS_OMIT_TECS
     202        serial_opn_por(SIO_PORTID);
     203#endif
     204        serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
     205
    178206        //wolfSSL_Debugging_ON();
    179207
    180         ntshell_task_init();
     208        ntshell_task_init(uart_read, uart_write, &main_obj);
    181209
    182210        main_obj.timer = TMO_FEVR;
     
    313341}
    314342
     343int cmd_creid(int argc, char **argv)
     344{
     345        if (argc != 2) {
     346                printf("creid {client_id}\n");
     347                return 0;
     348        }
     349
     350        client_set_client_id(argv[1]);
     351
     352        return 0;
     353}
     354
     355int cmd_secret(int argc, char **argv)
     356{
     357        if (argc != 2) {
     358                printf("secret {client_secret}\n");
     359                return 0;
     360        }
     361
     362        client_set_client_secret(argv[1]);
     363
     364        return 0;
     365}
     366
    315367int cmd_logupload(int argc, char **argv)
    316368{
    317         client_task(0);
    318         return 0;
     369        return client_upload_file(argc, argv);
    319370}
    320371
     
    335386        {"dnsc", "DNS client", usrcmd_dnsc },
    336387        {"ntpc", "NTP client", usrcmd_ntpc },
     388        {"creid", "Regster device", cmd_creid},
     389        {"secret", "Regster device", cmd_secret},
     390        {"gdi", "get_device_id", client_get_device_id},
     391        {"gat", "get_access_token", client_get_access_token},
     392        {"uat", "update_access_token", client_update_access_token},
     393        {"rd", "revoke device", client_revoke},
     394        {"uf", "upload_file", client_upload_file},
    337395        {"logupload", "Upload log to server", cmd_logupload},
    338396        {"info", "This is a description text string for info command.", usrcmd_info},
Note: See TracChangeset for help on using the changeset viewer.