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_rx/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;
    83 
     85#endif
    8486#ifdef IF_ETHER_BTUSB
    8587extern int bt_bnep_mode;
    8688/* PANU向けリモートアドレス */
    8789bd_addr_t remote_addr = {0x00,0x1B,0xDC,0x09,0x27,0x26};
     90bool_t dhcp_enable = false;
     91#else
     92bool_t dhcp_enable = true;
    8893#endif
    8994
    9095uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0x01};
    91 bool_t dhcp_enable = true;
    9296PRI main_task_priority = MAIN_PRIORITY + 1;
    9397
     
    112116static void main_timeout();
    113117
     118extern int ntshell_exit;
     119
    114120int uart_read(char *buf, int cnt, void *extobj)
    115121{
    116         return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
     122        struct main_t *obj = (struct main_t *)extobj;
     123        int result;
     124        ER ret;
     125        int timer;
     126
     127        obj->prev = obj->now;
     128
     129        /* タイマー取得 */
     130        timer = main_get_timer();
     131
     132        /* 待ち */
     133        ret = serial_trea_dat(SIO_PORTID, buf, cnt, timer);
     134        if ((ret < 0) && (ret != E_OK) && (ret != E_TMOUT)) {
     135                syslog(LOG_NOTICE, "tslp_tsk ret: %s %d", itron_strerror(ret), timer);
     136                ntshell_exit = 1;
     137                return -1;
     138        }
     139        result = (int)ret;
     140
     141        ret = get_tim(&obj->now);
     142        if (ret != E_OK) {
     143                syslog(LOG_NOTICE, "get_tim ret: %s", itron_strerror(ret));
     144                ntshell_exit = 1;
     145                return -1;
     146        }
     147
     148                        /* 時間経過 */
     149        int elapse = obj->now - obj->prev;
     150        main_progress(elapse);
     151
     152        /* タイムアウト処理 */
     153        main_timeout();
     154
     155        return result;
    117156}
    118157
     
    120159{
    121160        return serial_wri_dat(SIO_PORTID, buf, cnt);
    122 }
    123 
    124 unsigned char ntstdio_xi(struct ntstdio_t *handle)
    125 {
    126         char buf[1];
    127         if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
    128                 return -EIO;
    129         return buf[0];
    130 }
    131 
    132 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
    133 {
    134         char buf[1];
    135         buf[0] = c;
    136         serial_wri_dat(SIO_PORTID, buf, 1);
    137161}
    138162
     
    151175        main_initialize();
    152176
    153         ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);
     177        ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, &main_obj);
    154178        ntshell_set_prompt(&ntshell, "NTShell>");
    155179        ntshell_execute(&ntshell);
     
    171195        ER ret;
    172196
     197#ifdef TOPPERS_OMIT_TECS
     198        serial_opn_por(SIO_PORTID);
     199#endif
     200        serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
     201
    173202        //wolfSSL_Debugging_ON();
    174203
    175         ntshell_task_init();
     204        ntshell_task_init(uart_read, uart_write, &main_obj);
    176205
    177206        main_obj.timer = TMO_FEVR;
     
    308337}
    309338
     339int cmd_creid(int argc, char **argv)
     340{
     341        if (argc != 2) {
     342                printf("creid {client_id}\n");
     343                return 0;
     344        }
     345
     346        client_set_client_id(argv[1]);
     347
     348        return 0;
     349}
     350
     351int cmd_secret(int argc, char **argv)
     352{
     353        if (argc != 2) {
     354                printf("secret {client_secret}\n");
     355                return 0;
     356        }
     357
     358        client_set_client_secret(argv[1]);
     359
     360        return 0;
     361}
     362
    310363int cmd_logupload(int argc, char **argv)
    311364{
    312         client_task(0);
    313         return 0;
     365        return client_upload_file(argc, argv);
    314366}
    315367
     
    330382        {"dnsc", "DNS client", usrcmd_dnsc },
    331383        {"ntpc", "NTP client", usrcmd_ntpc },
     384        {"creid", "Regster device", cmd_creid},
     385        {"secret", "Regster device", cmd_secret},
     386        {"gdi", "get_device_id", client_get_device_id},
     387        {"gat", "get_access_token", client_get_access_token},
     388        {"uat", "update_access_token", client_update_access_token},
     389        {"rd", "revoke device", client_revoke},
     390        {"uf", "upload_file", client_upload_file},
    332391        {"logupload", "Upload log to server", cmd_logupload},
    333392        {"info", "This is a description text string for info command.", usrcmd_info},
Note: See TracChangeset for help on using the changeset viewer.