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

TINETとSocket APIなどを更新

Location:
asp3_tinet_ecnl_arm/trunk/ntshell
Files:
4 added
28 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet.c

    r352 r364  
    5656
    5757/*
     58 * インスタンスリスト通知の送信
     59 */
     60ER ecn_ntf_inl()
     61{
     62        return _ecn_tsk_ntf_inl();
     63}
     64
     65/*
    5866 * ECHONETオブジェクト参照
    5967 * 引数
     
    393401                return E_PAR;
    394402
    395         a_ret = trcv_dtq(ecn_api_mailboxid, (intptr_t *)&p_msg, fa_tmout);
     403        a_ret = trcv_dtq(ecn_api_dataqueueid, (intptr_t *)&p_msg, fa_tmout);
    396404        if (a_ret != E_OK) {
    397405                *ppk_esv = NULL;
     
    425433        a_ret = _ecn_fbs_del(a_fbs);
    426434        return a_ret;
     435}
     436
     437/*
     438 * 応答電文の送信元ノードを取得する
     439 */
     440ID ecn_get_enod(T_EDATA *pk_esv)
     441{
     442        const EOBJCB    *p_snod;
     443        const EOBJINIB  *p_sobj = NULL;
     444
     445        p_snod = _ecn_eno_fnd(((T_ECN_FST_BLK *)pk_esv)->hdr.sender.id);
     446        if (p_snod != NULL) {
     447                p_sobj = p_snod->profile;
     448        }
     449
     450        if (p_sobj == NULL)
     451                return EOBJ_NULL;
     452#ifdef ECHONET_CONTROLLER_EXTENTION
     453        if (p_sobj->eprpcnt == 0)
     454                return ecn_agent_get_eobj(p_sobj);
     455#endif
     456        return 1 + (((intptr_t)p_sobj - (intptr_t)eobjinib_table) / sizeof(EOBJINIB));
    427457}
    428458
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet.h

    r352 r364  
    6767typedef enum _echonet_enod_id
    6868{
    69         ENOD_NOT_MATCH_ID       = -1,
     69        ENOD_NOT_MATCH_ID       = -1,                   /* アドレスID登録なし */
    7070        ENOD_MULTICAST_ID       = 0,                    /* マルチキャストアドレスID */
    7171        ENOD_LOCAL_ID           = 1,                    /* 自ノードアドレスID */
     
    279279extern const ID ecn_svc_taskid;
    280280extern const ID ecn_udp_taskid;
    281 extern const ID ecn_api_mailboxid;
    282 extern const ID ecn_svc_mailboxid;
    283 extern const ID ecn_udp_mailboxid;
     281extern const ID ecn_api_dataqueueid;
     282extern const ID ecn_svc_dataqueueid;
     283extern const ID ecn_udp_dataqueueid;
    284284#ifndef ECHONET_USE_MALLOC
    285285extern const ID ecn_mempoolid;
     
    309309
    310310/*
     311 * インスタンスリスト通知の送信
     312 */
     313ER ecn_ntf_inl();
     314
     315/*
    311316 * ECHONETオブジェクト参照
    312317 */
     
    392397 */
    393398ER ecn_rel_esv(T_EDATA *pk_esv);
     399
     400/*
     401 * 応答電文の送信元ノードを取得する
     402 */
     403ID ecn_get_enod(T_EDATA *pk_esv);
    394404
    395405/*
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet.trb

    r352 r364  
    634634const ID _echonet_ecn_svc_taskid = ECHONET_SVC_TASK;
    635635const ID _echonet_ecn_udp_taskid = ECHONET_UDP_TASK;
    636 const ID _echonet_ecn_api_mailboxid = ECHONET_API_MAILBOX;
    637 const ID _echonet_ecn_svc_mailboxid = ECHONET_SVC_MAILBOX;
    638 const ID _echonet_ecn_udp_mailboxid = ECHONET_UDP_MAILBOX;
     636const ID _echonet_ecn_api_dataqueueid = ECHONET_API_DATAQUEUE;
     637const ID _echonet_ecn_svc_dataqueueid = ECHONET_SVC_DATAQUEUE;
     638const ID _echonet_ecn_udp_dataqueueid = ECHONET_UDP_DATAQUEUE;
    639639#ifndef ECHONET_USE_MALLOC
    640640const ID _echonet_ecn_mempoolid = ECHONET_MEMPOOL;
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_asp.cfg

    r352 r364  
    5151
    5252/*
    53  * ECHONET Lite API用メールボックス
     53 * ECHONET Lite API用データキュー
    5454 */
    55 CRE_DTQ(ECHONET_API_MAILBOX, { TA_TFIFO, 1, NULL });
     55CRE_DTQ(ECHONET_API_DATAQUEUE, { TA_TFIFO, ECHONET_API_DATAQUEUE_COUNT, NULL });
    5656
    5757/*
    58  * ECHONET Lite サービス処理タスク用メールボックス
     58 * ECHONET Lite サービス処理タスク用データキュー
    5959 */
    60 CRE_DTQ(ECHONET_SVC_MAILBOX, { TA_TFIFO, 1, NULL });
     60CRE_DTQ(ECHONET_SVC_DATAQUEUE, { TA_TFIFO, ECHONET_SVC_DATAQUEUE_COUNT, NULL });
    6161
    6262/*
     
    6666
    6767/*
    68  * ECHONET Lite UDP通信処理用メールボックス
     68 * ECHONET Lite UDP通信処理用データキュー
    6969 */
    70 CRE_DTQ(ECHONET_UDP_MAILBOX, { TA_TFIFO, 1, NULL });
     70CRE_DTQ(ECHONET_UDP_DATAQUEUE, { TA_TFIFO, ECHONET_UDP_DATAQUEUE_COUNT, NULL });
    7171
    7272/*
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_rename.h

    r352 r364  
    4747#define ecn_svc_taskid          _echonet_ecn_svc_taskid
    4848#define ecn_udp_taskid          _echonet_ecn_udp_taskid
    49 #define ecn_api_mailboxid       _echonet_ecn_api_mailboxid
    50 #define ecn_svc_mailboxid       _echonet_ecn_svc_mailboxid
    51 #define ecn_udp_mailboxid       _echonet_ecn_udp_mailboxid
     49#define ecn_api_dataqueueid     _echonet_ecn_api_dataqueueid
     50#define ecn_svc_dataqueueid     _echonet_ecn_svc_dataqueueid
     51#define ecn_udp_dataqueueid     _echonet_ecn_udp_dataqueueid
    5252#define ecn_mempoolid           _echonet_ecn_mempoolid
    5353#define ecn_udp_cepid           _echonet_ecn_udp_cepid
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_task.c

    r352 r364  
    7777static bool_t g_release_esv;
    7878
    79 ER _ecn_tsk_ntf_inl(intptr_t fa_exinf);
    80 
    8179ER _ecn_tsk_snd_dtq(ECN_FBS_ID fa_rsp_fbs, bool_t from_app)
    8280{
    8381        ER      a_ret;
    8482        T_MSG *msg = (T_MSG *)fa_rsp_fbs.ptr;
    85         ID dtqid = ecn_udp_mailboxid;
     83        ID dtqid = ecn_udp_dataqueueid;
    8684        int i;
    8785#ifdef ECN_DBG_PUT_ENA
     
    9088        if (from_app && (((T_EDATA *)fa_rsp_fbs.ptr)->hdr.edata.esv == ESV_INFC)) {
    9189                g_api_tid = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
    92                 dtqid = ecn_svc_mailboxid;
     90                dtqid = ecn_svc_dataqueueid;
    9391        }
    9492        else {
     
    9896                                g_api_tid = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
    9997
    100                         dtqid = ecn_udp_mailboxid;
     98                        dtqid = ecn_udp_dataqueueid;
    10199                        break;
    102100                case ENOD_LOCAL_ID:
    103101                        if (from_app)
    104                                 dtqid = ecn_svc_mailboxid;
     102                                dtqid = ecn_svc_dataqueueid;
    105103                        else
    106                                 dtqid = ecn_api_mailboxid;
     104                                dtqid = ecn_api_dataqueueid;
    107105                        break;
    108106                case ENOD_API_ID:
    109                         dtqid = ecn_api_mailboxid;
     107                        dtqid = ecn_api_dataqueueid;
    110108                        break;
    111109                default:
     
    121119                                switch (eobjcb_table[i].profile->eobjatr) {
    122120                                case EOBJ_SYNC_REMOTE_NODE:
    123                                         dtqid = ecn_udp_mailboxid;
     121                                        dtqid = ecn_udp_dataqueueid;
    124122                                        break;
    125123                                case EOBJ_ASYNC_REMOTE_NODE:
    126                                         dtqid = ecn_svc_mailboxid;
     124                                        dtqid = ecn_svc_dataqueueid;
    127125                                        break;
    128126                                default:
     
    131129                        }
    132130                        else {
    133                                 dtqid = ecn_udp_mailboxid;
     131                                dtqid = ecn_udp_dataqueueid;
    134132                        }
    135133                        break;
     
    242240#endif
    243241
    244                 a_ret = trcv_dtq(ecn_svc_mailboxid, (intptr_t *)&a_mdt.p_msg, a_timer);
     242                a_ret = trcv_dtq(ecn_svc_dataqueueid, (intptr_t *)&a_mdt.p_msg, a_timer);
    245243                if ((a_ret != E_OK) && (a_ret != E_TMOUT)) {
    246244                        ECN_DBG_PUT_2("trcv_dtq() result = %d:%s", a_ret, itron_strerror(a_ret));
     
    867865                g_release_esv = false;
    868866
    869                 ECN_CAP_PUT_1("redirect ecn_svc_mailboxid → ecn_api_mailboxid (esv:0x%02X)",
     867                ECN_CAP_PUT_1("redirect ecn_svc_dataqueueid → ecn_api_dataqueueid (esv:0x%02X)",
    870868                        p_esv->edata.esv);
    871869                fa_fbs_id.ptr->hdr.target.id = ENOD_API_ID;
    872                 a_ret = snd_dtq(ecn_api_mailboxid, (intptr_t)fa_fbs_id.ptr);
     870                a_ret = snd_dtq(ecn_api_dataqueueid, (intptr_t)fa_fbs_id.ptr);
    873871                if (a_ret != E_OK) {
    874872                        syslog(LOG_WARNING, "_ecn_tsk_ecn_msg() : snd_dtq() result = %d:%s", a_ret, itron_strerror(a_ret));
     
    20242022        req.ptr->hdr.type = ECN_MSG_INTERNAL;
    20252023        req.ptr->hdr.sender.dtqid = sender;
    2026         req.ptr->hdr.target.dtqid = ecn_svc_mailboxid;
     2024        req.ptr->hdr.target.dtqid = ecn_svc_dataqueueid;
    20272025        req.ptr->hdr.reply.dtqid = sender;
    20282026
     
    20522050
    20532051        res.ptr->hdr.type = ECN_MSG_INTERNAL;
    2054         res.ptr->hdr.sender.dtqid = ecn_svc_mailboxid;
     2052        res.ptr->hdr.sender.dtqid = ecn_svc_dataqueueid;
    20552053        res.ptr->hdr.target.dtqid = req.ptr->hdr.reply.dtqid;
    2056         res.ptr->hdr.reply.dtqid = ecn_svc_mailboxid;
     2054        res.ptr->hdr.reply.dtqid = ecn_svc_dataqueueid;
    20572055
    20582056        *pk_res = res;
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_task.h

    r352 r364  
    110110} T_ECN_INTERNAL_MSG;
    111111
     112/*
     113 * インスタンスリスト通知の送信
     114 */
     115ER _ecn_tsk_ntf_inl();
    112116/*
    113117 * 要求電文作成
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_udp6_task.c

    r352 r364  
    151151
    152152        /* echonet_taskに送る */
    153         a_ret = snd_dtq(ecn_svc_mailboxid, (intptr_t)a_fbs_id.ptr);
    154         if (a_ret != E_OK) {
    155                 ECN_DBG_PUT_2("[UDP ECHO SRV] snd_dtq(ecn_svc_mailboxid) result = %d:%s", a_ret, itron_strerror(a_ret));
     153        a_ret = snd_dtq(ecn_svc_dataqueueid, (intptr_t)a_fbs_id.ptr);
     154        if (a_ret != E_OK) {
     155                ECN_DBG_PUT_2("[UDP ECHO SRV] snd_dtq(ecn_svc_dataqueueid) result = %d:%s", a_ret, itron_strerror(a_ret));
    156156                goto lb_except;
    157157        }
     
    201201                a_timer = ECHONET_UDP_TASK_GET_TIMER;
    202202
    203                 a_ret = trcv_dtq(ecn_udp_mailboxid, (intptr_t *)&a_mdt.p_msg, a_timer);
     203                a_ret = trcv_dtq(ecn_udp_dataqueueid, (intptr_t *)&a_mdt.p_msg, a_timer);
    204204                if ((a_ret != E_OK) && (a_ret != E_TMOUT)) {
    205205                        ECN_DBG_PUT_2("trcv_dtq() result = %d:%s", a_ret, itron_strerror(a_ret));
     
    261261        req.ptr->hdr.type = ECN_MSG_INTERNAL;
    262262        req.ptr->hdr.sender.dtqid = sender;
    263         req.ptr->hdr.target.dtqid = ecn_udp_mailboxid;
     263        req.ptr->hdr.target.dtqid = ecn_udp_dataqueueid;
    264264        req.ptr->hdr.reply.dtqid = sender;
    265265
     
    289289
    290290        res.ptr->hdr.type = ECN_MSG_INTERNAL;
    291         res.ptr->hdr.sender.dtqid = ecn_udp_mailboxid;
     291        res.ptr->hdr.sender.dtqid = ecn_udp_dataqueueid;
    292292        res.ptr->hdr.target.dtqid = req.ptr->hdr.reply.dtqid;
    293         res.ptr->hdr.reply.dtqid = ecn_udp_mailboxid;
     293        res.ptr->hdr.reply.dtqid = ecn_udp_dataqueueid;
    294294
    295295        *pk_res = res;
     
    416416                else if (memcmp(&a_dst.ipaddr, &locl, sizeof(a_dst.ipaddr)) == 0) {
    417417                        /* 送信先が127.0.0.1 → dtqに転送 */
    418                         ECN_DBG_PUT_1("redirect ecn_udp_mailboxid → ecn_svc_mailboxid (esv:0x%02X)",
     418                        ECN_DBG_PUT_1("redirect ecn_udp_dataqueueid → ecn_svc_dataqueueid (esv:0x%02X)",
    419419                                ((T_EDATA *)fbs_id.ptr)->hdr.edata.esv);
    420420
     
    462462
    463463        switch (fncd) {
    464         case TFN_UDP_CRE_CEP:
     464        case TEV_UDP_RCV_DAT:
    465465        case TFN_UDP_RCV_DAT:
    466466                /* ECN_CAP_PUT("[UDP ECHO SRV] callback_nblk_udp() recv: %u", *(int *)p_parblk); */
     
    488488                return E_OK;
    489489
     490        case TFN_UDP_CRE_CEP:
    490491        case TFN_UDP_SND_DAT:
    491492                break;
    492493        default:
    493494                ECN_CAP_PUT_2("[UDP ECHO SRV] fncd:0x%04X(%s)", -fncd,
     495                        (fncd == TEV_UDP_RCV_DAT ? "TEV_UDP_RCV_DAT" :
    494496                        (fncd == TFN_UDP_CRE_CEP ? "TFN_UDP_CRE_CEP" :
    495497                        (fncd == TFN_UDP_RCV_DAT ? "TFN_UDP_RCV_DAT" :
    496                         (fncd == TFN_UDP_SND_DAT ? "TFN_UDP_SND_DAT" : "undef"))));
     498                        (fncd == TFN_UDP_SND_DAT ? "TFN_UDP_SND_DAT" : "undef")))));
    497499
    498500                error = E_PAR;
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_udp6_task.h

    r352 r364  
    7171#endif /* ECHONET_UDP_TASK_STACK_SIZE */
    7272
    73 #ifndef NUM_ECHONET_UDP_MAILBOX
    74 #define NUM_ECHONET_UDP_MAILBOX 10
    75 #endif /* NUM_ECHONET_UDP_MAILBOX */
     73#ifndef NUM_ECHONET_UDP_DATAQUEUE
     74#define NUM_ECHONET_UDP_DATAQUEUE       10
     75#endif /* NUM_ECHONET_UDP_DATAQUEUE */
    7676
    7777/*
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_udp_task.c

    r352 r364  
    146146
    147147        /* echonet_taskに送る */
    148         a_ret = snd_dtq(ecn_svc_mailboxid, (intptr_t)a_fbs_id.ptr);
    149         if (a_ret != E_OK) {
    150                 ECN_DBG_PUT_2("[UDP ECHO SRV] snd_dtq(ecn_svc_mailboxid) result = %d:%s", a_ret, itron_strerror(a_ret));
     148        a_ret = snd_dtq(ecn_svc_dataqueueid, (intptr_t)a_fbs_id.ptr);
     149        if (a_ret != E_OK) {
     150                ECN_DBG_PUT_2("[UDP ECHO SRV] snd_dtq(ecn_svc_dataqueueid) result = %d:%s", a_ret, itron_strerror(a_ret));
    151151                goto lb_except;
    152152        }
     
    206206                a_timer = ECHONET_UDP_TASK_GET_TIMER;
    207207
    208                 a_ret = trcv_dtq(ecn_udp_mailboxid, (intptr_t *)&a_mdt.p_msg, a_timer);
     208                a_ret = trcv_dtq(ecn_udp_dataqueueid, (intptr_t *)&a_mdt.p_msg, a_timer);
    209209                if ((a_ret != E_OK) && (a_ret != E_TMOUT)) {
    210210                        ECN_DBG_PUT_2("trcv_dtq() result = %d:%s", a_ret, itron_strerror(a_ret));
     
    266266        req.ptr->hdr.type = ECN_MSG_INTERNAL;
    267267        req.ptr->hdr.sender.dtqid = sender;
    268         req.ptr->hdr.target.dtqid = ecn_udp_mailboxid;
     268        req.ptr->hdr.target.dtqid = ecn_udp_dataqueueid;
    269269        req.ptr->hdr.reply.dtqid = sender;
    270270
     
    294294
    295295        res.ptr->hdr.type = ECN_MSG_INTERNAL;
    296         res.ptr->hdr.sender.dtqid = ecn_udp_mailboxid;
     296        res.ptr->hdr.sender.dtqid = ecn_udp_dataqueueid;
    297297        res.ptr->hdr.target.dtqid = req.ptr->hdr.reply.dtqid;
    298         res.ptr->hdr.reply.dtqid = ecn_udp_mailboxid;
     298        res.ptr->hdr.reply.dtqid = ecn_udp_dataqueueid;
    299299
    300300        *pk_res = res;
     
    420420                else if (a_dst.ipaddr == MAKE_IPV4_ADDR(127,0,0,1)) {
    421421                        /* 送信先が127.0.0.1 → dtqに転送 */
    422                         ECN_DBG_PUT_1("redirect ecn_udp_mailboxid → ecn_svc_mailboxid (esv:0x%02X)",
     422                        ECN_DBG_PUT_1("redirect ecn_udp_dataqueueid → ecn_svc_dataqueueid (esv:0x%02X)",
    423423                                ((T_EDATA *)fbs_id.ptr)->hdr.edata.esv);
    424424
     
    466466
    467467        switch (fncd) {
    468         case TFN_UDP_CRE_CEP:
     468        case TEV_UDP_RCV_DAT:
    469469        case TFN_UDP_RCV_DAT:
    470470                /* ECN_CAP_PUT("[UDP ECHO SRV] callback_nblk_udp() recv: %u", *(int *)p_parblk); */
     
    492492                return E_OK;
    493493
     494        case TFN_UDP_CRE_CEP:
    494495        case TFN_UDP_SND_DAT:
    495496                break;
    496497        default:
    497498                ECN_CAP_PUT_2("[UDP ECHO SRV] fncd:0x%04X(%s)", -fncd,
     499                        (fncd == TEV_UDP_RCV_DAT ? "TEV_UDP_RCV_DAT" :
    498500                        (fncd == TFN_UDP_CRE_CEP ? "TFN_UDP_CRE_CEP" :
    499501                        (fncd == TFN_UDP_RCV_DAT ? "TFN_UDP_RCV_DAT" :
    500                         (fncd == TFN_UDP_SND_DAT ? "TFN_UDP_SND_DAT" : "undef"))));
     502                        (fncd == TFN_UDP_SND_DAT ? "TFN_UDP_SND_DAT" : "undef")))));
    501503
    502504                error = E_PAR;
  • asp3_tinet_ecnl_arm/trunk/ntshell/echonet/echonet_udp_task.h

    r352 r364  
    7171#endif /* ECHONET_UDP_TASK_STACK_SIZE */
    7272
    73 #ifndef NUM_ECHONET_UDP_MAILBOX
    74 #define NUM_ECHONET_UDP_MAILBOX 10
    75 #endif /* NUM_ECHONET_UDP_MAILBOX */
     73#ifndef NUM_ECHONET_UDP_DATAQUEUE
     74#define NUM_ECHONET_UDP_DATAQUEUE       10
     75#endif /* NUM_ECHONET_UDP_DATAQUEUE */
    7676
    7777/*
  • asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.h

    r359 r364  
    4141#define FFARCH_STACK_SIZE               512
    4242
    43 void ffarch_init();
     43void ffarch_init(void);
    4444void ffarch_task(intptr_t exinf);
    45 int ffarch_get_timer();
     45int ffarch_get_timer(void);
    4646void ffarch_progress(int elapse);
    47 void ffarch_timeout();
     47void ffarch_timeout(void);
    4848
    4949void sdfs_cychdr(intptr_t exinf);
  • asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c

    r352 r364  
    11/*
    22 *  TOPPERS ECHONET Lite Communication Middleware
    3  * 
     3 *
    44 *  Copyright (C) 2018 Cores Co., Ltd. Japan
    5  * 
     5 *
    66 *  上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
    77 *  ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
     
    2626 *      由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
    2727 *      免責すること.
    28  * 
     28 *
    2929 *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
    3030 *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
     
    3232 *  アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
    3333 *  の責任を負わない.
    34  * 
     34 *
    3535 *  @(#) $Id$
    3636 */
     
    4141#include <string.h>
    4242#include <target_syssvc.h>
     43#ifndef ADAFRUIT_SSD1306
    4344#include "adafruit_st7735.h"
     45#else
     46#include "adafruit_ssd1306.h"
     47#endif
    4448#include "draw_font.h"
    45 #include "misaki_font.h"
    46 
    47 void get_bitmap_font(char *string, unsigned char *bitmap_data, unsigned long *use_chars)
    48 {
    49         unsigned long len, code;
    50         unsigned char i,j,k;
    51         unsigned long totalj, totalk;
     49
     50void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars)
     51{
     52        uint32_t len, code;
     53        uint8_t i, j, k;
     54        uint32_t totalj, totalk;
    5255
    5356        *use_chars = 0;
    5457        len = 0;
    55         if      ((string[0] & 0x80) ==    0) { len = 1; }
     58        if ((string[0] & 0x80) == 0) { len = 1; }
    5659        else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
    5760        else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
    5861        else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
    59         else { return;  }
     62        else { return; }
    6063
    6164        j = k = totalj = totalk = 0;
    6265
    63         if( len == 1 ) {
     66        if (len == 1) {
    6467                code = string[0];
    65                 memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], 8 );
     68                memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8);
    6669                *use_chars = 1;
    6770                return;
    6871        }
    6972
    70         if( len == 2 ) {
     73        if (len == 2) {
    7174                code = string[0];
    7275                // 1バイト目サーチ
    73                 for(i = 0; i < UTF8_CODE_2B_1_NUM; i++ ) {
    74                         if ( Utf8CodeTable_2B_1st[i][0] == code ) {
     76                for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {
     77                        if (Utf8CodeTable_2B_1st[i][0] == code) {
    7578                                code = string[1];
    76                                 for( j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++ ) {
    77                                         if ( UTF8_2B_CODE_BITMAP[totalk].code == code ) {
    78                                                 memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, 8 );
     79                                for (j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) {
     80                                        if (UTF8_2B_CODE_BITMAP[totalk].code == code) {
     81                                                memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
    7982                                                *use_chars = 2;
    8083                                                return;
     
    9093        }
    9194
    92         if( len == 3 ) {
     95        if (len == 3) {
    9396                code = string[0];
    9497                // 1バイト目サーチ
    95                 for(i = 0; i < UTF8_CODE_3B_1_NUM; i++ ) {
    96                         if ( Utf8CodeTable_3B_1st[i][0] == code ) {
     98                for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {
     99                        if (Utf8CodeTable_3B_1st[i][0] == code) {
    97100                                code = string[1];
    98101                                // 2バイト目サーチ
    99                                 for( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++ ){
    100                                         if ( Utf8CodeTable_3B_2nd[totalj][0] == code ) {
     102                                for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
     103                                        if (Utf8CodeTable_3B_2nd[totalj][0] == code) {
    101104                                                code = string[2];
    102105                                                // 3バイト目サーチ
    103                                                 for( k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
     106                                                for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
    104107                                                        if (UTF8_3B_CODE_BITMAP[totalk].code == code) {
    105                                                                 memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, 8 );
     108                                                                memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
    106109                                                                *use_chars = 3;
    107110                                                                return;
     
    111114                                                return;
    112115                                        }
    113                                         else{/*読み飛ばすbitmap個数を蓄積*/
     116                                        else {/*読み飛ばすbitmap個数を蓄積*/
    114117                                                totalk += Utf8CodeTable_3B_2nd[totalj][1];
    115118                                        }
     
    118121                        }
    119122                        else {/*読み飛ばすbitmap個数を蓄積*/
    120                                 for( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++ ) {
     123                                for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
    121124                                        totalk += Utf8CodeTable_3B_2nd[totalj][1];
    122125                                        totalj++;
     
    128131}
    129132
    130 void lcd_drawFont(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color)
    131 {
    132         int i, j;
    133 
    134         for(i = 0; i < 8; i++ ) {
    135                 for(j = 0; j < 8; j++ ) {
    136                         if (((bitmap_data[i] >> j) & 0x01) == 1){
    137                                 lcd_drawPixel(hlcd, x - j, y + i, color);
     133void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
     134{
     135        int i, j, b;
     136        uint8_t *bitmap = bitmap_data;
     137
     138        b = 0x80;
     139        for (i = 0; i < FONT_HEIGHT; i++) {
     140                for (j = 0; j < FONT_WIDTH; j++) {
     141                        if ((*bitmap & b) != 0) {
     142                                lcd_drawPixel(hlcd, x + j, y + i, color);
    138143                        }
    139144                        else {
    140                                 lcd_drawPixel(hlcd, x - j, y + i, back_color);
    141                         }
    142                 }
    143         }
    144 }
    145 
    146 void lcd_drawFontHalf(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color)
    147 {
    148         int i, j;
    149 
    150         for(i = 0; i < 8; i++ ) {
    151                 for(j = 4; j < 8; j++ ) {
    152                         if (((bitmap_data[i] >> j) & 0x01) == 1){
    153                                 lcd_drawPixel(hlcd, x - j, y + i, color);
     145                                lcd_drawPixel(hlcd, x + j, y + i, back_color);
     146                        }
     147                        b >>= 1;
     148                        if (b == 0) {
     149                                b = 0x80;
     150                                bitmap++;
     151                        }
     152                }
     153        }
     154}
     155
     156void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
     157{
     158        int i, j, b;
     159        uint8_t *bitmap = bitmap_data;
     160
     161        b = 0x80;
     162        for (i = 0; i < FONT_HEIGHT; i++) {
     163                for (j = 0; j < FONT_HALF_WIDTH; j++) {
     164                        if ((*bitmap & b) != 0) {
     165                                lcd_drawPixel(hlcd, x + j, y + i, color);
    154166                        }
    155167                        else {
    156                                 lcd_drawPixel(hlcd, x - j, y + i, back_color);
    157                         }
    158                 }
    159         }
    160 }
    161 
    162 void lcd_drawString(LCD_Handler_t *hlcd, char *string, int x, int y, unsigned short color, unsigned short back_color )
    163 {
    164         unsigned long current_top, use_chars, for_3B_hankaku_code;
    165         unsigned char bitmap_data[8], ctrl_code;
    166         int local_x, local_y;
     168                                lcd_drawPixel(hlcd, x + j, y + i, back_color);
     169                        }
     170                        b >>= 1;
     171                        if (b == 0) {
     172                                b = 0x80;
     173                                bitmap++;
     174                        }
     175                }
     176        }
     177}
     178
     179void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color)
     180{
     181        uint32_t current_top, use_chars, for_3B_hankaku_code;
     182        uint8_t bitmap_data[FONT_WIDTH * FONT_HEIGHT / 8], ctrl_code;
     183        int local_x, local_y, len = strlen(string);
     184        const uint8_t *code = (const uint8_t *)string;
    167185
    168186        local_x = x;
     
    170188
    171189        current_top = 0;
    172         while( current_top < strlen(string) )
    173         {
    174                 memset(bitmap_data,0x0,8);
    175                 ctrl_code = string[current_top];
    176                 get_bitmap_font(&string[current_top], bitmap_data, &use_chars);
    177                 if(use_chars == 0)
     190        while (current_top < len) {
     191                memset(bitmap_data, 0x0, FONT_WIDTH * FONT_HEIGHT / 8);
     192                ctrl_code = code[current_top];
     193                get_bitmap_font(&code[current_top], bitmap_data, &use_chars);
     194                if (use_chars == 0)
    178195                        return;
    179196
    180197                //3バイトコード半角文字用
    181                 if(use_chars == 3) {
     198                if (use_chars == 3) {
    182199                        for_3B_hankaku_code = 0;
    183                         for_3B_hankaku_code = ( (string[current_top]  << 16) |
    184                                                                     (string[current_top+1] << 8) |
    185                                                                     (string[current_top+2]      )   );
     200                        for_3B_hankaku_code = ((code[current_top] << 16) |
     201                                (code[current_top + 1] << 8) |
     202                                (code[current_top + 2]));
    186203                }
    187204
     
    189206
    190207                //1バイトコード半角文字
    191                 if ( use_chars == 1 ) {
    192                         if(ctrl_code == 0x0D) { // CR
     208                if (use_chars == 1) {
     209                        if (ctrl_code == 0x0D) { // CR
    193210                                local_x = X_LINE_TO_PIX(hlcd, 0);
    194211                                continue;
    195212                        }
    196                         if(ctrl_code == 0x0A) { // LF
    197                                 local_y = local_y + 8;
     213                        if (ctrl_code == 0x0A) { // LF
     214                                local_y = local_y + FONT_HEIGHT;
    198215                                continue;
    199216                        }
    200217
    201                         if ( local_x >= hlcd->_width + 4 ) {
     218                        if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
    202219                                local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
    203                                 local_y = local_y + 8;
     220                                local_y = local_y + FONT_HEIGHT;
    204221                        }
    205222                        lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
    206                         local_x += 4;
     223                        local_x += FONT_HALF_WIDTH;
    207224                        continue;
    208225                }
    209226
    210227                //3バイトコード半角文字
    211                 if( use_chars == 3 ) {
    212                         if (    ( (0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF) ) ||
    213                                         ( (0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F) )      ) {
     228                if (use_chars == 3) {
     229                        if (((0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) ||
     230                                ((0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F))) {
    214231                                //3バイトコード半角文字
    215                                 if ( local_x >= hlcd->_width + 4 ) {
     232                                if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
    216233                                        local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
    217                                         local_y = local_y + 8;
     234                                        local_y = local_y + FONT_HEIGHT;
    218235                                }
    219236                                lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
    220                                 local_x += 4;
     237                                local_x += FONT_HALF_WIDTH;
    221238                                continue;
    222239                        }
     
    224241
    225242                //全角文字
    226                 if ( local_x >= hlcd->_width + 8 ) {
     243                if (local_x + FONT_WIDTH > hlcd->_width) {
    227244                        local_x = X_LINE_TO_PIX(hlcd, 0);
    228                         local_y = local_y + 8;
     245                        local_y = local_y + FONT_HEIGHT;
    229246                }
    230247                lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color);
    231                 local_x += 8;
    232         }
    233 }
    234 
     248                local_x += FONT_WIDTH;
     249        }
     250}
     251
  • asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.h

    r352 r364  
    3939#define DRAW_FONT_H
    4040
     41#if defined(SHNM16_FONT)
     42#include "shnm16_font.h"
     43#elif defined(SHNM12_FONT)
     44#include "shnm12_font.h"
     45#else
     46#include "misaki_font.h"
     47#endif
     48
    4149#define DISP_X_ADJ      0
    4250#define DISP_Y_ADJ      0
    43 #define X_ZENKAKU_CHARACTERS(hlcd)      ((hlcd)->_width / 8)
    44 #define X_HANKAKU_CHARACTERS(hlcd)      ((hlcd)->_width / 4)
    45 #define Y_CHARACTERS(hlcd)                      ((hlcd)->_height / 8)
    46 #define X_LINE_TO_PIX(hlcd, x)          ((8*(x))-DISP_X_ADJ)
    47 #define X_LINE_HALF_TO_PIX(hlcd, x)     ((4*(x))-DISP_X_ADJ)
    48 #define Y_ROW_TO_PIX(hlcd, y)           ((8*(y))-DISP_Y_ADJ)
     51#define X_ZENKAKU_CHARACTERS(hlcd)      ((hlcd)->_width / FONT_WIDTH)
     52#define X_HANKAKU_CHARACTERS(hlcd)      ((hlcd)->_width / FONT_HALF_WIDTH)
     53#define Y_CHARACTERS(hlcd)                      ((hlcd)->_height / FONT_HEIGHT)
     54#define X_LINE_TO_PIX(hlcd, x)          ((FONT_WIDTH*(x))-DISP_X_ADJ)
     55#define X_LINE_HALF_TO_PIX(hlcd, x)     ((FONT_HALF_WIDTH*(x))-DISP_X_ADJ)
     56#define Y_ROW_TO_PIX(hlcd, y)           ((FONT_HEIGHT*(y))-DISP_Y_ADJ)
    4957
    5058#ifdef __cplusplus
     
    5260#endif
    5361
    54 void get_bitmap_font(char *string, unsigned char *bitmap_data, unsigned long *use_chars);
    55 void lcd_drawFont(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color);
    56 void lcd_drawFontHalf(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color);
    57 void lcd_drawString(LCD_Handler_t *hlcd, char *string, int x, int y, unsigned short color, unsigned short back_color );
     62void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars);
     63void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color);
     64void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color);
     65void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color );
    5866
    5967#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/ntshell/lcd/misaki_font.c

    r352 r364  
    4646
    4747// 1バイトコード
    48 unsigned char UTF8_1B_CODE_BITMAP[UTF8_1B_CODE_BITMAP_NUM][8] = {
    49         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    50         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    51         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    52         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    53         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    54         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    55         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    56         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    57         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    58         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    59         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    60         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    61         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    62         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    63         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    64         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    65         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    66         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    67         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    68         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    69         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    70         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    71         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    72         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    73         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    74         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    75         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    76         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    77         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    78         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    79         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    80         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    81         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    82         {0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x00, 0x00},
    83         {0xA0, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    84         {0xA0, 0xE0, 0xA0, 0xA0, 0xE0, 0xA0, 0x00, 0x00},
    85         {0x40, 0xE0, 0xC0, 0x60, 0xE0, 0x40, 0x00, 0x00},
    86         {0x00, 0x80, 0x20, 0x40, 0x80, 0x20, 0x00, 0x00},
    87         {0x40, 0xA0, 0x40, 0x60, 0xC0, 0xE0, 0x00, 0x00},
    88         {0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    89         {0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x00},
    90         {0x80, 0x40, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00},
    91         {0x40, 0xE0, 0x40, 0xA0, 0x00, 0x00, 0x00, 0x00},
    92         {0x00, 0x40, 0x40, 0xE0, 0x40, 0x40, 0x00, 0x00},
    93         {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00},
    94         {0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00},
    95         {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00},
    96         {0x00, 0x00, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00},
    97         {0x00, 0x40, 0xA0, 0xE0, 0xA0, 0x40, 0x00, 0x00},
    98         {0x00, 0x40, 0xC0, 0x40, 0x40, 0xE0, 0x00, 0x00},
    99         {0x00, 0xC0, 0x20, 0x40, 0x80, 0xE0, 0x00, 0x00},
    100         {0x00, 0xC0, 0x20, 0x40, 0x20, 0xC0, 0x00, 0x00},
    101         {0x00, 0x20, 0x60, 0xA0, 0xE0, 0x20, 0x00, 0x00},
    102         {0x00, 0xE0, 0x80, 0xC0, 0x20, 0xC0, 0x00, 0x00},
    103         {0x00, 0x60, 0x80, 0xC0, 0xA0, 0x40, 0x00, 0x00},
    104         {0x00, 0xE0, 0x20, 0x40, 0x40, 0x40, 0x00, 0x00},
    105         {0x00, 0x40, 0xA0, 0x40, 0xA0, 0x40, 0x00, 0x00},
    106         {0x00, 0x40, 0xA0, 0x60, 0x20, 0xC0, 0x00, 0x00},
    107         {0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x00, 0x00},
    108         {0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x80, 0x00},
    109         {0x00, 0x20, 0x40, 0x80, 0x40, 0x20, 0x00, 0x00},
    110         {0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0x00},
    111         {0x00, 0x80, 0x40, 0x20, 0x40, 0x80, 0x00, 0x00},
    112         {0x40, 0xA0, 0x20, 0x40, 0x00, 0x40, 0x00, 0x00},
    113         {0x40, 0xA0, 0x20, 0x60, 0xA0, 0x40, 0x00, 0x00},
    114         {0x40, 0xA0, 0xA0, 0xE0, 0xA0, 0xA0, 0x00, 0x00},
    115         {0xC0, 0xA0, 0xC0, 0xA0, 0xA0, 0xC0, 0x00, 0x00},
    116         {0x60, 0x80, 0x80, 0x80, 0x80, 0x60, 0x00, 0x00},
    117         {0xC0, 0xA0, 0xA0, 0xA0, 0xA0, 0xC0, 0x00, 0x00},
    118         {0xE0, 0x80, 0xC0, 0x80, 0x80, 0xE0, 0x00, 0x00},
    119         {0xE0, 0x80, 0xC0, 0x80, 0x80, 0x80, 0x00, 0x00},
    120         {0x60, 0x80, 0x80, 0xA0, 0xA0, 0x60, 0x00, 0x00},
    121         {0xA0, 0xA0, 0xA0, 0xE0, 0xA0, 0xA0, 0x00, 0x00},
    122         {0xE0, 0x40, 0x40, 0x40, 0x40, 0xE0, 0x00, 0x00},
    123         {0x20, 0x20, 0x20, 0x20, 0xA0, 0x40, 0x00, 0x00},
    124         {0xA0, 0xA0, 0xC0, 0xA0, 0xA0, 0xA0, 0x00, 0x00},
    125         {0x80, 0x80, 0x80, 0x80, 0x80, 0xE0, 0x00, 0x00},
    126         {0xA0, 0xE0, 0xE0, 0xA0, 0xA0, 0xA0, 0x00, 0x00},
    127         {0xC0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0x00, 0x00},
    128         {0x40, 0xA0, 0xA0, 0xA0, 0xA0, 0x40, 0x00, 0x00},
    129         {0xC0, 0xA0, 0xA0, 0xC0, 0x80, 0x80, 0x00, 0x00},
    130         {0x40, 0xA0, 0xA0, 0xA0, 0xA0, 0x40, 0x20, 0x00},
    131         {0xC0, 0xA0, 0xA0, 0xC0, 0xA0, 0xA0, 0x00, 0x00},
    132         {0x60, 0x80, 0x40, 0x20, 0x20, 0xC0, 0x00, 0x00},
    133         {0xE0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
    134         {0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xE0, 0x00, 0x00},
    135         {0xA0, 0xA0, 0xA0, 0xA0, 0xC0, 0x80, 0x00, 0x00},
    136         {0xA0, 0xA0, 0xA0, 0xE0, 0xE0, 0xA0, 0x00, 0x00},
    137         {0xA0, 0xA0, 0x40, 0x40, 0xA0, 0xA0, 0x00, 0x00},
    138         {0xA0, 0xA0, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
    139         {0xE0, 0x20, 0x40, 0x40, 0x80, 0xE0, 0x00, 0x00},
    140         {0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x00},
    141         {0xA0, 0x40, 0xE0, 0x40, 0xE0, 0x40, 0x00, 0x00},
    142         {0xC0, 0x40, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x00},
    143         {0x40, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    144         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00},
    145         {0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    146         {0x00, 0x00, 0x60, 0xA0, 0xA0, 0x60, 0x00, 0x00},
    147         {0x80, 0x80, 0xC0, 0xA0, 0xA0, 0xC0, 0x00, 0x00},
    148         {0x00, 0x00, 0x60, 0x80, 0x80, 0x60, 0x00, 0x00},
    149         {0x20, 0x20, 0x60, 0xA0, 0xA0, 0x60, 0x00, 0x00},
    150         {0x00, 0x00, 0x60, 0xE0, 0x80, 0x60, 0x00, 0x00},
    151         {0x60, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x00, 0x00},
    152         {0x00, 0x00, 0x60, 0xA0, 0x60, 0x20, 0xC0, 0x00},
    153         {0x80, 0x80, 0xC0, 0xA0, 0xA0, 0xA0, 0x00, 0x00},
    154         {0x40, 0x00, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
    155         {0x40, 0x00, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00},
    156         {0x80, 0x80, 0xA0, 0xC0, 0xA0, 0xA0, 0x00, 0x00},
    157         {0xC0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
    158         {0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xA0, 0x00, 0x00},
    159         {0x00, 0x00, 0xC0, 0xA0, 0xA0, 0xA0, 0x00, 0x00},
    160         {0x00, 0x00, 0x40, 0xA0, 0xA0, 0x40, 0x00, 0x00},
    161         {0x00, 0x00, 0xC0, 0xA0, 0xA0, 0xC0, 0x80, 0x00},
    162         {0x00, 0x00, 0x60, 0xA0, 0xA0, 0x60, 0x20, 0x00},
    163         {0x00, 0x00, 0xA0, 0xC0, 0x80, 0x80, 0x00, 0x00},
    164         {0x00, 0x00, 0x60, 0xC0, 0x60, 0xC0, 0x00, 0x00},
    165         {0x00, 0x40, 0xE0, 0x40, 0x40, 0x60, 0x00, 0x00},
    166         {0x00, 0x00, 0xA0, 0xA0, 0xA0, 0xE0, 0x00, 0x00},
    167         {0x00, 0x00, 0xA0, 0xA0, 0xC0, 0x80, 0x00, 0x00},
    168         {0x00, 0x00, 0xA0, 0xA0, 0xE0, 0xE0, 0x00, 0x00},
    169         {0x00, 0x00, 0xA0, 0x40, 0x40, 0xA0, 0x00, 0x00},
    170         {0x00, 0x00, 0xA0, 0xA0, 0x60, 0x20, 0xC0, 0x00},
    171         {0x00, 0x00, 0xE0, 0x20, 0x40, 0xE0, 0x00, 0x00},
    172         {0x20, 0x40, 0x40, 0x80, 0x40, 0x40, 0x20, 0x00},
    173         {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00},
    174         {0x80, 0x40, 0x40, 0x20, 0x40, 0x40, 0x80, 0x00},
    175         {0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    176         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
     48const uint8_t UTF8_1B_CODE_BITMAP[UTF8_1B_CODE_BITMAP_NUM][FONT_HALF_WIDTH * FONT_HEIGHT / 8] = {
     49        {0x00, 0x00, 0x00, 0x00},
     50        {0x00, 0x00, 0x00, 0x00},
     51        {0x00, 0x00, 0x00, 0x00},
     52        {0x00, 0x00, 0x00, 0x00},
     53        {0x00, 0x00, 0x00, 0x00},
     54        {0x00, 0x00, 0x00, 0x00},
     55        {0x00, 0x00, 0x00, 0x00},
     56        {0x00, 0x00, 0x00, 0x00},
     57        {0x00, 0x00, 0x00, 0x00},
     58        {0x00, 0x00, 0x00, 0x00},
     59        {0x00, 0x00, 0x00, 0x00},
     60        {0x00, 0x00, 0x00, 0x00},
     61        {0x00, 0x00, 0x00, 0x00},
     62        {0x00, 0x00, 0x00, 0x00},
     63        {0x00, 0x00, 0x00, 0x00},
     64        {0x00, 0x00, 0x00, 0x00},
     65        {0x00, 0x00, 0x00, 0x00},
     66        {0x00, 0x00, 0x00, 0x00},
     67        {0x00, 0x00, 0x00, 0x00},
     68        {0x00, 0x00, 0x00, 0x00},
     69        {0x00, 0x00, 0x00, 0x00},
     70        {0x00, 0x00, 0x00, 0x00},
     71        {0x00, 0x00, 0x00, 0x00},
     72        {0x00, 0x00, 0x00, 0x00},
     73        {0x00, 0x00, 0x00, 0x00},
     74        {0x00, 0x00, 0x00, 0x00},
     75        {0x00, 0x00, 0x00, 0x00},
     76        {0x00, 0x00, 0x00, 0x00},
     77        {0x00, 0x00, 0x00, 0x00},
     78        {0x00, 0x00, 0x00, 0x00},
     79        {0x00, 0x00, 0x00, 0x00},
     80        {0x00, 0x00, 0x00, 0x00},
     81        {0x00, 0x00, 0x00, 0x00},
     82        {0x44, 0x44, 0x04, 0x00},
     83        {0xAA, 0x00, 0x00, 0x00},
     84        {0xAE, 0xAA, 0xEA, 0x00},
     85        {0x4E, 0xC6, 0xE4, 0x00},
     86        {0x08, 0x24, 0x82, 0x00},
     87        {0x4A, 0x46, 0xCE, 0x00},
     88        {0x48, 0x00, 0x00, 0x00},
     89        {0x24, 0x44, 0x44, 0x20},
     90        {0x84, 0x44, 0x44, 0x80},
     91        {0x4E, 0x4A, 0x00, 0x00},
     92        {0x04, 0x4E, 0x44, 0x00},
     93        {0x00, 0x00, 0x04, 0x80},
     94        {0x00, 0x0E, 0x00, 0x00},
     95        {0x00, 0x00, 0x04, 0x00},
     96        {0x00, 0x24, 0x80, 0x00},
     97        {0x04, 0xAE, 0xA4, 0x00},
     98        {0x04, 0xC4, 0x4E, 0x00},
     99        {0x0C, 0x24, 0x8E, 0x00},
     100        {0x0C, 0x24, 0x2C, 0x00},
     101        {0x02, 0x6A, 0xE2, 0x00},
     102        {0x0E, 0x8C, 0x2C, 0x00},
     103        {0x06, 0x8C, 0xA4, 0x00},
     104        {0x0E, 0x24, 0x44, 0x00},
     105        {0x04, 0xA4, 0xA4, 0x00},
     106        {0x04, 0xA6, 0x2C, 0x00},
     107        {0x00, 0x40, 0x04, 0x00},
     108        {0x00, 0x40, 0x04, 0x80},
     109        {0x02, 0x48, 0x42, 0x00},
     110        {0x00, 0xE0, 0xE0, 0x00},
     111        {0x08, 0x42, 0x48, 0x00},
     112        {0x4A, 0x24, 0x04, 0x00},
     113        {0x4A, 0x26, 0xA4, 0x00},
     114        {0x4A, 0xAE, 0xAA, 0x00},
     115        {0xCA, 0xCA, 0xAC, 0x00},
     116        {0x68, 0x88, 0x86, 0x00},
     117        {0xCA, 0xAA, 0xAC, 0x00},
     118        {0xE8, 0xC8, 0x8E, 0x00},
     119        {0xE8, 0xC8, 0x88, 0x00},
     120        {0x68, 0x8A, 0xA6, 0x00},
     121        {0xAA, 0xAE, 0xAA, 0x00},
     122        {0xE4, 0x44, 0x4E, 0x00},
     123        {0x22, 0x22, 0xA4, 0x00},
     124        {0xAA, 0xCA, 0xAA, 0x00},
     125        {0x88, 0x88, 0x8E, 0x00},
     126        {0xAE, 0xEA, 0xAA, 0x00},
     127        {0xCA, 0xAA, 0xAA, 0x00},
     128        {0x4A, 0xAA, 0xA4, 0x00},
     129        {0xCA, 0xAC, 0x88, 0x00},
     130        {0x4A, 0xAA, 0xA4, 0x20},
     131        {0xCA, 0xAC, 0xAA, 0x00},
     132        {0x68, 0x42, 0x2C, 0x00},
     133        {0xE4, 0x44, 0x44, 0x00},
     134        {0xAA, 0xAA, 0xAE, 0x00},
     135        {0xAA, 0xAA, 0xC8, 0x00},
     136        {0xAA, 0xAE, 0xEA, 0x00},
     137        {0xAA, 0x44, 0xAA, 0x00},
     138        {0xAA, 0x44, 0x44, 0x00},
     139        {0xE2, 0x44, 0x8E, 0x00},
     140        {0x64, 0x44, 0x44, 0x60},
     141        {0xA4, 0xE4, 0xE4, 0x00},
     142        {0xC4, 0x44, 0x44, 0xC0},
     143        {0x4A, 0x00, 0x00, 0x00},
     144        {0x00, 0x00, 0x00, 0xE0},
     145        {0x42, 0x00, 0x00, 0x00},
     146        {0x00, 0x6A, 0xA6, 0x00},
     147        {0x88, 0xCA, 0xAC, 0x00},
     148        {0x00, 0x68, 0x86, 0x00},
     149        {0x22, 0x6A, 0xA6, 0x00},
     150        {0x00, 0x6E, 0x86, 0x00},
     151        {0x64, 0xE4, 0x44, 0x00},
     152        {0x00, 0x6A, 0x62, 0xC0},
     153        {0x88, 0xCA, 0xAA, 0x00},
     154        {0x40, 0x44, 0x44, 0x00},
     155        {0x40, 0x44, 0x44, 0x80},
     156        {0x88, 0xAC, 0xAA, 0x00},
     157        {0xC4, 0x44, 0x44, 0x00},
     158        {0x00, 0xCE, 0xEA, 0x00},
     159        {0x00, 0xCA, 0xAA, 0x00},
     160        {0x00, 0x4A, 0xA4, 0x00},
     161        {0x00, 0xCA, 0xAC, 0x80},
     162        {0x00, 0x6A, 0xA6, 0x20},
     163        {0x00, 0xAC, 0x88, 0x00},
     164        {0x00, 0x6C, 0x6C, 0x00},
     165        {0x04, 0xE4, 0x46, 0x00},
     166        {0x00, 0xAA, 0xAE, 0x00},
     167        {0x00, 0xAA, 0xC8, 0x00},
     168        {0x00, 0xAA, 0xEE, 0x00},
     169        {0x00, 0xA4, 0x4A, 0x00},
     170        {0x00, 0xAA, 0x62, 0xC0},
     171        {0x00, 0xE2, 0x4E, 0x00},
     172        {0x24, 0x48, 0x44, 0x20},
     173        {0x44, 0x44, 0x44, 0x40},
     174        {0x84, 0x42, 0x44, 0x80},
     175        {0xE0, 0x00, 0x00, 0x00},
     176        {0x00, 0x00, 0x00, 0x00}
    177177};
    178178
    179179// 2バイトコード 1バイト目
    180 unsigned char Utf8CodeTable_2B_1st[UTF8_CODE_2B_1_NUM][2] = {
     180const uint8_t Utf8CodeTable_2B_1st[UTF8_CODE_2B_1_NUM][2] = {
    181181        {0xC2,  0x06},
    182182        {0xC3,  0x02},
     
    187187};
    188188// 2バイトコード 2バイト目 bitmapデータ
    189 struct utf8_code_bitmap UTF8_2B_CODE_BITMAP[UTF8_2B_CODE_BITMAP_NUM] = {
     189const struct utf8_code_bitmap UTF8_2B_CODE_BITMAP[UTF8_2B_CODE_BITMAP_NUM] = {
    190190        {0xA7,  {0x1C, 0x20, 0x18, 0x24, 0x18, 0x04, 0x38, 0x00}},
    191191        {0xA8,  {0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
     
    313313
    314314// 3バイトコード 1バイト目
    315 unsigned char Utf8CodeTable_3B_1st[UTF8_CODE_3B_1_NUM][2] = {
     315const uint8_t Utf8CodeTable_3B_1st[UTF8_CODE_3B_1_NUM][2] = {
    316316        {0xE2,  0x0E},
    317317        {0xE3,  0x04},
     
    325325};
    326326// 3バイトコード 2バイト目
    327 unsigned char Utf8CodeTable_3B_2nd[UTF8_CODE_3B_2_NUM][2] = {
     327const uint8_t Utf8CodeTable_3B_2nd[UTF8_CODE_3B_2_NUM][2] = {
    328328        {0x80,  0x0F},
    329329        {0x84,  0x02},
     
    673673
    674674// 3バイトコード 3バイト目 bitmapデータ
    675 struct utf8_code_bitmap UTF8_3B_CODE_BITMAP[UTF8_3B_CODE_BITMAP_NUM] = {
     675const struct utf8_code_bitmap UTF8_3B_CODE_BITMAP[UTF8_3B_CODE_BITMAP_NUM] = {
    676676        { 0x90 ,{0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00}},
    677677        { 0x95 ,{0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00}},
  • asp3_tinet_ecnl_arm/trunk/ntshell/lcd/misaki_font.h

    r352 r364  
    3939#define MISAKI_FONT_H
    4040
     41#include <stdint.h>
     42
     43#define FONT_HALF_WIDTH                 4
     44#define FONT_WIDTH                              8
     45#define FONT_HEIGHT                             8
     46
    4147struct utf8_code_bitmap {
    42         unsigned char code;
    43         unsigned char bitmap[8];
     48        const uint8_t code;
     49        const uint8_t bitmap[FONT_WIDTH * FONT_HEIGHT / 8];
    4450};
    4551
     
    4854#define UTF8_CODE_3B_2_NUM              (343+1)         /*半角追加2/2*/
    4955
    50 #define UTF8_CODE_BITMAP_NUM    6879                                                                                            /*トータル*/
    5156#define UTF8_1B_CODE_BITMAP_NUM 128
    5257#define UTF8_2B_CODE_BITMAP_NUM 122                                                                                                     /*"¬","\","¢""£"移動)*/
     
    5459
    5560// 1バイトコード
    56 extern unsigned char UTF8_1B_CODE_BITMAP[UTF8_1B_CODE_BITMAP_NUM][8];
     61extern const uint8_t UTF8_1B_CODE_BITMAP[UTF8_1B_CODE_BITMAP_NUM][FONT_HALF_WIDTH * FONT_HEIGHT / 8];
    5762
    5863// 2バイトコード 1バイト目
    59 extern unsigned char Utf8CodeTable_2B_1st[UTF8_CODE_2B_1_NUM][2];
     64extern const uint8_t Utf8CodeTable_2B_1st[UTF8_CODE_2B_1_NUM][2];
    6065// 2バイトコード 2バイト目 bitmapデータ
    61 extern struct utf8_code_bitmap UTF8_2B_CODE_BITMAP[UTF8_2B_CODE_BITMAP_NUM];
     66extern const struct utf8_code_bitmap UTF8_2B_CODE_BITMAP[UTF8_2B_CODE_BITMAP_NUM];
    6267
    6368// 3バイトコード 1バイト目
    64 extern unsigned char Utf8CodeTable_3B_1st[UTF8_CODE_3B_1_NUM][2];
     69extern const uint8_t Utf8CodeTable_3B_1st[UTF8_CODE_3B_1_NUM][2];
    6570// 3バイトコード 2バイト目
    66 extern unsigned char Utf8CodeTable_3B_2nd[UTF8_CODE_3B_2_NUM][2];
     71extern const uint8_t Utf8CodeTable_3B_2nd[UTF8_CODE_3B_2_NUM][2];
    6772
    6873// 3バイトコード 3バイト目 bitmapデータ
    69 extern struct utf8_code_bitmap UTF8_3B_CODE_BITMAP[UTF8_3B_CODE_BITMAP_NUM];
     74extern const struct utf8_code_bitmap UTF8_3B_CODE_BITMAP[UTF8_3B_CODE_BITMAP_NUM];
    7075
    7176#endif /* MISAKI_FONT_H */
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/echonet_app_config.h

    r352 r364  
    4040
    4141#define ECHONET_TASK_STACK_SIZE 1024    /* ECNL UDPタスク用スタック領域のサイズ */
     42
     43#define ECHONET_API_DATAQUEUE_COUNT 5           /* ECHONET Lite API用データキュー */
     44#define ECHONET_SVC_DATAQUEUE_COUNT 5           /* ECHONET Lite サービス処理タスク用データキュー */
     45#define ECHONET_UDP_DATAQUEUE_COUNT 5           /* ECHONET Lite UDP通信処理用データキュー */
    4246
    4347/*
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c

    r359 r364  
    4545#include "target_syssvc.h"
    4646#ifndef NTSHELL_NO_SOCKET
     47#include <tinet_defs.h>
    4748#include <tinet_config.h>
     49#include <net/net.h>
     50#include <net/net_endian.h>
    4851#include <netinet/in.h>
    4952#include <netinet/in_itron.h>
     
    5558#include <net/net.h>
    5659#include <net/if_var.h>
     60#include <netinet/udp.h>
    5761#include <netinet/udp_var.h>
    5862#include <netinet/tcp.h>
    5963#include <netinet/tcp_var.h>
     64#include <net/net_buf.h>
    6065#endif
    6166#include "ff.h"
     
    6974#define IO_TYPE_DIR             3
    7075#define IO_TYPE_TCP             4
    71 #define IO_TYPE_UDP             5
     76#define IO_TYPE_UDP     5
    7277
    7378static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = {
     
    8590                        continue;
    8691
     92                memset(fp, 0, sizeof(struct _IO_FILE));
    8793                fp->fd = fd;
    8894                fp->type = type;
     
    280286#endif
    281287
     288void memor(void *dst, void *src, size_t len)
     289{
     290        uint8_t *d = (uint8_t *)dst;
     291        uint8_t *s = (uint8_t *)src;
     292        uint8_t *e = &s[len];
     293
     294        while (s < e) {
     295                *d++ |= *s++;
     296        }
     297}
     298
    282299struct fd_events {
    283300        int count;
     
    304321        }
    305322
    306         memcpy(&evts.readfds, rfds, sizeof(fd_set));
    307         memcpy(&evts.writefds, wfds, sizeof(fd_set));
    308         memcpy(&evts.errorfds, efds, sizeof(fd_set));
     323        if (rfds != NULL)
     324                memcpy(&evts.readfds, rfds, sizeof(fd_set));
     325        else
     326                memset(&evts.readfds, 0, sizeof(fd_set));
     327        if (wfds != NULL)
     328                memcpy(&evts.writefds, wfds, sizeof(fd_set));
     329        else
     330                memset(&evts.writefds, 0, sizeof(fd_set));
     331        if (efds != NULL)
     332                memcpy(&evts.errorfds, efds, sizeof(fd_set));
     333        else
     334                memset(&evts.errorfds, 0, sizeof(fd_set));
    309335        evts.count = 0;
    310336
    311337        ret = shell_get_evts(&evts, tmout);
     338        if (rfds != NULL)
     339                memset(rfds, 0, sizeof(fd_set));
     340        if (wfds != NULL)
     341                memset(wfds, 0, sizeof(fd_set));
     342        if (efds != NULL)
     343                memset(efds, 0, sizeof(fd_set));
    312344        if (ret == E_OK) {
    313                 memcpy(rfds, &evts.readfds, sizeof(fd_set));
    314                 memcpy(wfds, &evts.writefds, sizeof(fd_set));
    315                 memcpy(efds, &evts.errorfds, sizeof(fd_set));
     345                if (rfds != NULL)
     346                        memor(rfds, &evts.readfds, sizeof(fd_set));
     347                if (wfds != NULL)
     348                        memor(wfds, &evts.writefds, sizeof(fd_set));
     349                if (efds != NULL)
     350                        memor(efds, &evts.errorfds, sizeof(fd_set));
    316351                return evts.count;
    317352        }
    318353        if (ret == E_TMOUT) {
    319                 memset(rfds, 0, sizeof(fd_set));
    320                 memset(wfds, 0, sizeof(fd_set));
    321                 memset(efds, 0, sizeof(fd_set));
    322354                return 0;
    323355        }
     
    441473        struct _IO_FILE *fp = tcpid_to_fd(cepid);
    442474        FLGPTN flgptn = 0;
     475        ER ret;
     476        int len;
    443477
    444478        if (fp == NULL)
     
    449483
    450484        switch (fncd) {
     485        case TFN_TCP_RCV_BUF:
     486                len = *(int *)p_parblk;
     487                if (len <= 0)
     488                        return E_OK;
     489
     490                ret = wai_sem(SEM_FILEDESC);
     491                if (ret < 0) {
     492                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     493                }
     494                fp->psock->len += len;
     495                ret = sig_sem(SEM_FILEDESC);
     496                if (ret < 0) {
     497                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     498                }
     499
     500                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     501
     502                set_flg(FLG_SELECT_WAIT, flgptn);
     503                return E_OK;
     504
    451505        case TFN_TCP_RCV_DAT:
     506                len = *(int *)p_parblk;
     507                if (len <= 0)
     508                        return E_OK;
     509
     510                ret = wai_sem(SEM_FILEDESC);
     511                if (ret < 0) {
     512                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     513                }
     514                fp->psock->len += len;
     515                ret = sig_sem(SEM_FILEDESC);
     516                if (ret < 0) {
     517                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     518                }
     519
    452520                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
    453521
     
    484552        struct _IO_FILE *fp = udpid_to_fd(cepid);
    485553        FLGPTN flgptn = 0;
     554        int len;
    486555
    487556        if (fp == NULL)
     
    492561
    493562        switch (fncd) {
     563        case TEV_UDP_RCV_DAT:
     564        {
     565                T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
     566                len = udppara->len;
     567                if (len <= 0)
     568                        return E_OK;
     569
     570                ER ret = wai_sem(SEM_FILEDESC);
     571                if (ret < 0) {
     572                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     573                }
     574                fp->psock->len = len;
     575                if (fp->psock->input != NULL) {
     576                        ret = rel_net_buf(fp->psock->input);
     577                        if (ret < 0) {
     578                                syslog(LOG_ERROR, "rel_net_buf => %d", ret);
     579                        }
     580                }
     581                fp->psock->input = udppara->input;
     582                fp->psock->buf = GET_UDP_SDU(udppara->input, udppara->off);
     583                memset(&fp->psock->raddr4, 0, sizeof(fp->psock->raddr4));
     584                fp->psock->raddr4.sin_family = AF_INET;
     585                fp->psock->raddr4.sin_port = htons(udppara->rep4.portno);
     586                fp->psock->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
     587                udppara->input->flags |= NB_FLG_NOREL_IFOUT;
     588                ret = sig_sem(SEM_FILEDESC);
     589                if (ret < 0) {
     590                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     591                }
     592
     593                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     594
     595                set_flg(FLG_SELECT_WAIT, flgptn);
     596                return E_OK;
     597        }
    494598        case TFN_UDP_CRE_CEP:
     599                return E_OK;
     600
    495601        case TFN_UDP_RCV_DAT:
     602                len = *(int *)p_parblk;
     603                if (len <= 0)
     604                        return E_OK;
     605
    496606                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
    497607
     
    524634ER shell_get_evts(struct fd_events *evts, TMO tmout)
    525635{
    526         ER ret;
    527         FLGPTN waitptn, flgptn = 0, readfds = 0, writefds = 0;
    528         struct _IO_FILE *fp = NULL;
    529636        int count = 0;
    530 
    531         stdio_update_evts();
     637        SYSTIM prev, now;
     638
     639        get_tim(&prev);
     640
     641        for (;;) {
     642                ER ret;
     643                FLGPTN waitptn, flgptn, readfds = 0, writefds = 0;
     644                struct _IO_FILE *fp = NULL;
     645
     646                stdio_update_evts();
    532647
    533648#ifndef NTSHELL_NO_SOCKET
    534         waitptn = *((FLGPTN *)&evts->errorfds);
     649                waitptn = *((FLGPTN *)&evts->errorfds);
    535650#else
    536         waitptn = *((FLGPTN *)&evts->readfds) | *((FLGPTN *)&evts->errorfds);
     651                waitptn = *((FLGPTN *)&evts->readfds) | *((FLGPTN *)&evts->errorfds);
    537652#endif
    538         for (int fd = 0; fd < fd_table_count; fd++) {
    539                 fp = &fd_table[fd];
     653                for (int fd = 0; fd < fd_table_count; fd++) {
     654                        fp = &fd_table[fd];
    540655
    541656#ifndef NTSHELL_NO_SOCKET
    542                 if (FD_ISSET(fd, &evts->readfds)) {
    543                         if ((fp->type == IO_TYPE_TCP)
    544                                 && (GET_TCP_CEP(fp->psock->cepid)->rwbuf_count > 0)) {
    545                                 FD_SET(fd, (fd_set *)&readfds);
    546                                 count++;
    547                                 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
     657                        if (FD_ISSET(fd, &evts->readfds)) {
     658                                if ((fp->type == IO_TYPE_TCP) && (fp->psock->cepid != 0)) {
     659                                        if (fp->psock->len == 0) {
     660                                                ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_NBLK);
     661                                                if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
     662                                                        syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
     663                                                        //return ret;
     664                                                }
     665                                                if (ret > 0) {
     666                                                        ret = wai_sem(SEM_FILEDESC);
     667                                                        if (ret < 0) {
     668                                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     669                                                        }
     670                                                        fp->psock->len += ret;
     671                                                        ret = sig_sem(SEM_FILEDESC);
     672                                                        if (ret < 0) {
     673                                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     674                                                        }
     675                                                }
     676                                        }
     677                                        else ret = 1;
     678                                        if (ret > 0) {
     679                                                FD_SET(fd, (fd_set *)&readfds);
     680                                                count++;
     681                                                if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
     682                                        }
     683                                }
     684                                else if ((fp->type == IO_TYPE_UDP) && (fp->psock->cepid != 0)) {
     685                                        if (fp->psock->input != NULL) {
     686                                                FD_SET(fd, (fd_set *)&readfds);
     687                                                count++;
     688                                                if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
     689                                        }
     690                                }
     691                                else {
     692                                        FD_SET(fd, (fd_set *)&waitptn);
     693                                }
    548694                        }
    549                         else {
    550                                 FD_SET(fd, (fd_set *)&waitptn);
     695#endif
     696                        if (FD_ISSET(fd, &evts->writefds)) {
     697                                if (fp->writeevt_w == fp->writeevt_r) {
     698                                        FD_SET(fd, (fd_set *)&writefds);
     699                                        count++;
     700                                        if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_r--;
     701                                }
     702                                else {
     703                                        FD_SET(fd, (fd_set *)&waitptn);
     704                                }
    551705                        }
    552706                }
    553 #endif
    554                 if (FD_ISSET(fd, &evts->writefds)) {
    555                         if (fp->writable) {
    556                                 FD_SET(fd, (fd_set *)&writefds);
     707                memset(evts, 0, sizeof(*evts));
     708
     709                if (waitptn == 0) {
     710                        memcpy(&evts->readfds, &readfds, sizeof(evts->readfds));
     711                        memcpy(&evts->writefds, &writefds, sizeof(evts->writefds));
     712                        evts->count = count;
     713                        return E_OK;
     714                }
     715                else if ((readfds | writefds) != 0) {
     716                        set_flg(FLG_SELECT_WAIT, (readfds | writefds));
     717                }
     718
     719                /* イベント待ち */
     720                flgptn = 0;
     721                ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, tmout);
     722                if (ret != E_OK) {
     723                        if (ret != E_TMOUT) {
     724                                syslog(LOG_ERROR, "twai_flg => %d", ret);
     725                                return ret;
     726                        }
     727
     728                        stdio_flgptn(&flgptn);
     729
     730                        if (flgptn == 0)
     731                                return E_TMOUT;
     732                }
     733                flgptn &= waitptn;
     734
     735                /* 受け取ったフラグのみクリア */
     736                ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
     737                if (ret != E_OK) {
     738                        syslog(LOG_ERROR, "clr_flg => %d", ret);
     739                }
     740
     741                count = 0;
     742                for (int fd = 0; fd < fd_table_count; fd++) {
     743                        if (!FD_ISSET(fd, (fd_set *)&waitptn))
     744                                continue;
     745
     746                        fp = &fd_table[fd];
     747
     748                        if (fp->readevt_w != fp->readevt_r) {
     749                                fp->readevt_r++;
     750                                FD_SET(fd, &evts->readfds);
    557751                                count++;
    558752                        }
    559                         else {
    560                                 FD_SET(fd, (fd_set *)&waitptn);
     753                        if (fp->writeevt_w != fp->writeevt_r) {
     754                                fp->writeevt_r++;
     755                                fp->writable = 1;
    561756                        }
    562                 }
    563         }
    564         memset(evts, 0, sizeof(*evts));
    565 
    566         if (waitptn == 0) {
    567                 memcpy(&evts->readfds, &readfds, sizeof(evts->readfds));
    568                 memcpy(&evts->writefds, &writefds, sizeof(evts->writefds));
    569                 evts->count = count;
    570                 return E_OK;
    571         }
    572         else if ((readfds | writefds) != 0){
    573                 set_flg(FLG_SELECT_WAIT, (readfds | writefds));
    574         }
    575 
    576         /* イベント待ち */
    577         ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, tmout);
    578         if (ret != E_OK) {
    579                 if (ret != E_TMOUT) {
    580                         syslog(LOG_ERROR, "twai_flg => %d", ret);
    581                         return ret;
    582                 }
    583 
    584                 stdio_flgptn(&flgptn);
    585 
    586                 if (flgptn == 0)
     757                        if (fp->writable) {
     758                                FD_SET(fd, &evts->writefds);
     759                                count++;
     760                        }
     761                        if (fp->errorevt_w != fp->errorevt_r) {
     762                                fp->errorevt_r++;
     763                                FD_SET(fd, &evts->errorfds);
     764                                count++;
     765                        }
     766                }
     767
     768                if (count > 0)
     769                        break;
     770
     771                get_tim(&now);
     772
     773                SYSTIM elapse = now - prev;
     774                if (elapse > tmout)
    587775                        return E_TMOUT;
    588         }
    589         flgptn &= waitptn;
    590 
    591         /* 受け取ったフラグのみクリア */
    592         ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
    593         if (ret != E_OK) {
    594                 syslog(LOG_ERROR, "clr_flg => %d", ret);
    595         }
    596 
    597         count = 0;
    598         for (int fd = 0; fd < fd_table_count; fd++) {
    599                 if (!FD_ISSET(fd, (fd_set *)&waitptn))
    600                         continue;
    601 
    602                 fp = &fd_table[fd];
    603 
    604                 if (fp->readevt_w != fp->readevt_r) {
    605                         fp->readevt_r++;
    606                         FD_SET(fd, &evts->readfds);
    607                         count++;
    608                 }
    609                 if (fp->writeevt_w != fp->writeevt_r) {
    610                         fp->writeevt_r++;
    611                         fp->writable = 1;
    612                 }
    613                 if (fp->writable) {
    614                         FD_SET(fd, &evts->writefds);
    615                         count++;
    616                 }
    617                 if (fp->errorevt_w != fp->errorevt_r) {
    618                         fp->errorevt_r++;
    619                         FD_SET(fd, &evts->errorfds);
    620                         count++;
    621                 }
    622         }
     776
     777                prev = now;
     778                tmout -= elapse;
     779        }
     780
    623781        evts->count = count;
    624782
     
    676834}
    677835
    678 ssize_t shell_send(int fd, const void *buf, size_t len, int flags)
    679 {
    680         return -ENOMEM;
    681 }
    682 
    683836ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
    684837{
     
    691844}
    692845
    693 ssize_t shell_recv(int fd, void *buf, size_t len, int flags)
    694 {
    695         return -ENOMEM;
    696 }
    697 
    698 ssize_t shell_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
     846ssize_t shell_recvfrom(int fd, void *__restrict buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
    699847{
    700848        return -ENOMEM;
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.h

    r352 r364  
    4141/* スタックサイズ */
    4242
    43 #define NET_MISC_STACK_SIZE     1024            /* NTP クライアントタスク(IPv4)のスタックサイズ  */
     43#define NET_MISC_STACK_SIZE     2048            /* NTP クライアントタスク(IPv4)のスタックサイズ  */
    4444
    4545/* 優先度 */
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c

    r352 r364  
    239239int usrcmd_ping(int argc, char **argv)
    240240{
    241         int     tmo, size;
    242         char    apip = DEFAULT_API_PROTO;
     241        int tmo = 3, size = 64;
     242        char apip = DEFAULT_API_PROTO;
    243243        char *line = argv[1];
    244244#if defined(SUPPORT_INET6)
     
    262262
    263263#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
     264        if (argc <= 2)
     265                return 0;
     266
    264267        if ('0' <= *line && *line <= '9') {
    265268                if (*line == '6')
     
    269272                line++;
    270273        }
     274
     275        line = argv[2];
     276#else
     277        if (argc <= 1)
     278                return 0;
    271279#endif  /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
    272280
     
    276284        }
    277285
    278         line = argv[2];
    279         if ('0' <= *line && *line <= '9')
    280                 line = get_int(&tmo, line);
    281         else
    282                 tmo = 3;
    283 
    284         line = argv[3];
    285         if ('0' <= *line && *line <= '9')
    286                 line = get_int(&size, line);
    287         else
    288                 size = 64;
     286        if (argc > 2) {
     287                line = argv[2];
     288                if ('0' <= *line && *line <= '9')
     289                        line = get_int(&tmo, line);
     290
     291                if (argc > 3) {
     292                        line = argv[3];
     293                        if ('0' <= *line && *line <= '9')
     294                                line = get_int(&size, line);
     295                }
     296        }
    289297
    290298#if defined(SUPPORT_INET6)
     
    337345{
    338346        ER ret;
     347
     348        if (argc < 2)
     349                return 0;
     350
    339351        if (ntlibc_strcmp(argv[1], "rel") == 0) {
    340352                ret = dhcp4c_rel_info();
     
    348360                dhcp4c_info();
    349361        }
     362
    350363        return 0;
    351364}
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c

    r359 r364  
    265265
    266266        nc->buf[0] = '\0';
    267 #ifndef _MSC_VER
     267#ifdef __NEED_struct_timespec
    268268        if (ctime_r(&tp.tv_sec, nc->buf) != NULL)
    269269#else
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c

    r352 r364  
    6969const struct utsname host_name = {
    7070        "TOPPERS/ASP3",
    71     TARGET_NAME,
    72     "3.2.0",
    73     "3.2.0",
    74     TARGET_NAME,
    75     "toppers.jp"
     71        TARGET_NAME,
     72        "3.2.0",
     73        "3.2.0",
     74        TARGET_NAME,
     75        "toppers.jp"
    7676};
    7777
     
    8888jmp_buf process_exit;
    8989void sys_init(void);
    90 
    91 void ntshell_task_init()
    92 {
     90NTSHELL_SERIAL_READ ntshell_serial_read = 0;
     91NTSHELL_SERIAL_WRITE ntshell_serial_write = 0;
     92void *ntshell_serial_extobj;
     93
     94unsigned char ntstdio_xi(struct ntstdio_t *handle)
     95{
     96        unsigned char buf[1];
     97        ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj);
     98        return buf[0];
     99}
     100
     101void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
     102{
     103        char buf[1];
     104        buf[0] = c;
     105        ntshell_serial_write(buf, 1, ntshell_serial_extobj);
     106}
     107
     108void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
     109        NTSHELL_SERIAL_WRITE func_write, void *extobj)
     110{
     111        ntshell_serial_read = func_read;
     112        ntshell_serial_write = func_write;
     113        ntshell_serial_extobj = extobj;
     114
    93115        sys_init();
    94116
     
    126148        int result = 0;
    127149        int found = 0;
     150
     151        if (*args == 0)
     152                return result;
    128153
    129154        if (strcmp((const char *)args[1], "help") == 0) {
     
    295320int shell_clock_getres(clockid_t clk_id, struct timespec *res)
    296321{
    297         if (clk_id != CLOCK_REALTIME)
     322        if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))
    298323                return -EINVAL;
    299324
     
    308333        SYSTIM now = 0;
    309334
    310         if (clk_id != CLOCK_REALTIME)
     335        if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))
    311336                return -EINVAL;
    312337
     
    320345int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)
    321346{
    322         if (clk_id != CLOCK_REALTIME)
     347        if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))
    323348                return -EINVAL;
    324349
    325         rtc_write(tp->tv_sec);
     350        SYSTIM time;
     351        ER ret;
     352
     353        time = (tp->tv_sec * 1000000ll) + (tp->tv_nsec / 1000ll);
     354
     355        ret = set_tim(time);
     356        if (ret != E_OK) {
     357                return -EPERM;
     358        }
    326359
    327360        return 0;
     
    356389}
    357390
    358 struct sigaction sigtable[6];
     391struct sigaction sigtable[7];
    359392
    360393int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
     
    381414                sat = &sigtable[5];
    382415                break;
     416        case SIGPIPE:
     417                sat = &sigtable[6];
     418                break;
    383419        default:
    384420                return -EINVAL;
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg

    r352 r364  
    4343CRE_TSK(NTSHELL_TASK, { TA_NULL, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
    4444CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
     45CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 });
    4546CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 });
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h

    r352 r364  
    4949
    5050#include "usrcmd.h"
     51#include "core/ntshell.h"
    5152
    5253/*
     
    5455 */
    5556
    56 #define NTSHELL_PRIORITY        4               /* ntshellタスクの優先度 */
     57#define NTSHELL_PRIORITY        8               /* ntshellタスクの優先度 */
    5758
    5859#define NTSHELL_STACK_SIZE      8192    /* ntshellタスクのスタック領域のサイズ */
     
    7576extern PRI main_task_priority;
    7677
    77 struct ntstdio_t;
    78 unsigned char ntstdio_xi(struct ntstdio_t *handle);
    79 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c);
    80 
    8178/* ntshellタスク初期化 */
    82 void ntshell_task_init();
     79void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
     80        NTSHELL_SERIAL_WRITE func_write, void *extobj);
    8381
    8482/* ntshellタスク */
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h

    r352 r364  
    3939
    4040#ifdef _MSC_VER
    41 #define _CRT_NO_TIME_T
    42 #define tm msc_tm
    43 #include <time.h>
    44 #include <errno.h>
    45 #include <limits.h>
    46 #include <stdlib.h>
    47 #undef tm
    4841#undef NULL
    4942#endif
     
    133126#endif
    134127
     128#ifdef __cplusplus
     129extern "C" {
     130#endif
     131
    135132// time.h
    136133#define CLOCK_REALTIME 0
     
    179176int shell_access(const char *path, int mode);
    180177// signal.h
    181 int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old);
    182 int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old);
     178int shell_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict old);
     179int shell_sigaction(int sig, const struct sigaction *__restrict sa, struct sigaction *__restrict old);
    183180// socket.h
    184181int shell_socket(int, int, int);
    185182int shell_connect(int, const struct sockaddr *, socklen_t);
    186 ssize_t shell_send(int, const void *, size_t, int);
    187183ssize_t shell_sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
    188184ssize_t shell_sendmsg(int, const struct msghdr *, int);
     
    190186int shell_listen(int, int);
    191187int shell_accept(int, struct sockaddr *__restrict, socklen_t *__restrict);
    192 ssize_t shell_recv(int, void *, size_t, int);
    193188ssize_t shell_recvfrom(int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
    194189ssize_t shell_recvmsg(int, struct msghdr *, int);
     
    263258int shell_pipe2(int [2], int);
    264259int shell_ppoll(struct pollfd *, nfds_t, const struct timespec *,const sigset_t *);
    265 int shell_pselect6(int, fd_set *restrict, fd_set *restrict,
    266         fd_set *restrict, const struct timespec *restrict, const sigset_t *restrict);
     260int shell_pselect6(int, fd_set *__restrict, fd_set *__restrict,
     261        fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict);
    267262int shell_setpgid(pid_t, pid_t);
    268263int shell_setsid();
     
    314309void free(void *ptr);
    315310
     311#ifdef __cplusplus
     312}
     313#endif
     314
    316315#endif /* SHELLIF_H */
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c

    r352 r364  
    4242#include <sil.h>
    4343#include "syssvc/syslog.h"
     44#include <tinet_defs.h>
    4445#include <tinet_config.h>
     46#include <net/net.h>
     47#include <net/net_endian.h>
    4548#include <netinet/in.h>
    4649#include <netinet/in_itron.h>
     
    5356#include <net/if_var.h>
    5457#include <netinet/udp_var.h>
     58#include <net/net_buf.h>
    5559//#include <netinet/tcp_var.h>
    5660#include <netapp/resolver.h>
     
    5862#include "ff.h"
    5963#include "socket_stub.h"
     64#include "kernel_cfg.h"
    6065
    6166#define SOCKET_TIMEOUT 2000000
     
    181186                        fp->psock->buf_size = 512 + 512;
    182187                        fp->psock->buf = malloc(fp->psock->buf_size);
     188#ifdef _DEBUG
     189                        memset(fp->psock->buf, 0, fp->psock->buf_size);
     190#endif
    183191                        T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
    184192                        ret = tcp_cre_cep(cepid, &ccep);
     
    279287                        fp->psock->buf_size = 512 + 512;
    280288                        fp->psock->buf = malloc(fp->psock->buf_size);
     289#ifdef _DEBUG
     290                        memset(fp->psock->buf, 0, fp->psock->buf_size);
     291#endif
    281292                        T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
    282293                        ret = tcp_cre_cep(cepid, &ccep);
     
    298309                        return -EHOSTUNREACH;
    299310                }
    300                 fp->writable = 1;
    301311                break;
    302312        }
     
    322332        }
    323333
    324         memcpy(&fp->psock, &lfp->psock, sizeof(fp->psock));
     334        memcpy(fp->psock, lfp->psock, offsetof(socket_t, buf_size));
    325335
    326336        ER ret;
     
    335345                        fp->psock->buf_size = 512 + 512;
    336346                        fp->psock->buf = malloc(fp->psock->buf_size);
     347#ifdef _DEBUG
     348                        memset(fp->psock->buf, 0, fp->psock->buf_size);
     349#endif
    337350                        T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
    338351                        ret = tcp_cre_cep(cepid, &ccep);
     
    346359                else {
    347360                        cepid = lfp->psock->cepid;
     361                        fp->handle = cepid;
    348362                        lfp->handle = tmax_tcp_cepid + lfp->psock->repid;
    349363                        lfp->psock->cepid = 0;
     
    356370                        return -ENOMEM;
    357371                }
    358                 fp->writable = 1;
    359372                struct sockaddr_in *raddr = &fp->psock->raddr4;
    360373                memset(raddr, 0, sizeof(*raddr));
     
    384397}
    385398
    386 ssize_t shell_send(int fd, const void *buf, size_t len, int flags)
     399ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
    387400{
    388401        SOCKET *fp = fd_to_fp(fd);
     
    396409                switch (fp->psock->type) {
    397410                case SOCK_STREAM: {
    398                         fp->writable = 0;
     411                        if ((addr != NULL) || (alen != 0)) {
     412                                return -EISCONN;
     413                        }
     414
    399415                        if (flags & MSG_OOB) {
    400416                                ret = tcp_snd_oob(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     
    404420                        }
    405421                        else {
    406                                 ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    407                                 if (ret < 0) {
    408                                         return -ECOMM;
    409                                 }
    410                         }
    411                         break;
    412                 }
    413                 case SOCK_DGRAM: {
    414                         return -EINVAL;
    415                 }
    416                 }
    417                 break;
    418         }
    419         case AF_INET6: {
    420                 return -EAFNOSUPPORT;
    421         }
    422         }
    423 
    424         return ret;
    425 }
    426 
    427 ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
    428 {
    429         SOCKET *fp = fd_to_fp(fd);
    430         if (fp == NULL) {
    431                 return -EBADF;
    432         }
    433 
    434         int ret = 0;
    435         switch (fp->psock->family) {
    436         case AF_INET: {
    437                 switch (fp->psock->type) {
    438                 case SOCK_STREAM: {
    439                         if ((addr != NULL) && (alen != 0)) {
    440                                 return -EINVAL;
    441                         }
    442 
    443                         fp->writable = 0;
    444                         if (flags & MSG_OOB) {
    445                                 ret = tcp_snd_oob(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    446                                 if (ret < 0) {
    447                                         return -ECOMM;
    448                                 }
    449                         }
    450                         else {
    451                                 ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    452                                 if (ret < 0) {
    453                                         return -ECOMM;
    454                                 }
     422                                for (;;) {
     423                                        ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     424                                        if (ret < 0) {
     425                                                if (ret == E_TMOUT)
     426                                                        return -ETIME;
     427                                                return -ECOMM;
     428                                        }
     429                                        len -= ret;
     430                                        if (len <= 0)
     431                                                break;
     432                                        buf = (const void *)&((uint8_t *)buf)[ret];
     433                                }
    455434                        }
    456435                        break;
     
    458437                case SOCK_DGRAM: {
    459438                        int sz = alen;
    460                         if (sz < 8) {
     439                        if ((addr == NULL) || (sz < 8)) {
    461440                                return -EINVAL;
    462441                        }
     
    465444                        memcpy(raddr, addr, sz);
    466445                        T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
    467                         fp->writable = 0;
    468446                        ret = udp_snd_dat(fp->psock->cepid, &rep, (void *)buf, len,
    469                                 (fp->psock->flags & O_NONBLOCK) ? 0 : SOCKET_TIMEOUT);
     447                                (fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
    470448                        if (ret < 0) {
    471                                 return -ECOMM;
     449                                return (ret == E_TMOUT) ? -ETIME : -ECOMM;
    472450                        }
    473451                        break;
     
    490468}
    491469
    492 ssize_t shell_recv(int fd, void *buf, size_t len, int flags)
     470ssize_t shell_recvfrom(int fd, void *__restrict buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
    493471{
    494472        SOCKET *fp = fd_to_fp(fd);
     
    505483                                ret = tcp_rcv_oob(fp->psock->cepid, buf, len);
    506484                                if (ret < 0) {
     485                                        syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret);
    507486                                        return -ECOMM;
    508487                                }
    509488                        }
    510489                        else {
    511                                 ret = tcp_rcv_dat(fp->psock->cepid, buf, len, TMO_FEVR);
     490                                int rsz, tmp;
     491                                if (fp->psock->input == NULL) {
     492                                        ret = wai_sem(SEM_FILEDESC);
     493                                        if (ret < 0) {
     494                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     495                                        }
     496                                        fp->psock->len = 0;
     497                                        ret = sig_sem(SEM_FILEDESC);
     498                                        if (ret < 0) {
     499                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     500                                        }
     501                                        ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_FEVR);
     502                                        if (ret < 0) {
     503                                                syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
     504                                                return -ECOMM;
     505                                        }
     506                                        rsz = ret;
     507                                }
     508                                else
     509                                        rsz = fp->psock->len;
     510                                tmp = rsz;
     511                                if (rsz > len)
     512                                        rsz = len;
     513                                if (rsz >= 0) {
     514                                        memcpy(buf, fp->psock->input, rsz);
     515                                        ret = wai_sem(SEM_FILEDESC);
     516                                        if (ret < 0) {
     517                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     518                                        }
     519                                        fp->psock->len = tmp - rsz;
     520                                        ret = sig_sem(SEM_FILEDESC);
     521                                        if (ret < 0) {
     522                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     523                                        }
     524                                        if (tmp - rsz == 0) {
     525                                                fp->psock->input = NULL;
     526                                        }
     527                                        else
     528                                                fp->psock->input = (void *)&((uint8_t *)fp->psock->input)[rsz];
     529                                        ret = tcp_rel_buf(fp->psock->cepid, rsz);
     530                                        if ((ret != E_OBJ) && (ret < 0)) {
     531                                                syslog(LOG_ERROR, "tcp_rel_buf => %d", ret);
     532                                                //return -ECOMM;
     533                                        }
     534                                }
     535                                ret = rsz;
     536                        }
     537                        break;
     538                }
     539                case SOCK_DGRAM: {
     540                        struct sockaddr_in *raddr = &fp->psock->raddr4;
     541                        int rsz;
     542                        ret = wai_sem(SEM_FILEDESC);
     543                        if (ret < 0) {
     544                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     545                        }
     546                        T_NET_BUF *input = fp->psock->input;
     547                        if (input == NULL) {
     548                                ret = sig_sem(SEM_FILEDESC);
    512549                                if (ret < 0) {
    513                                         return -ECOMM;
    514                                 }
    515                         }
    516                         break;
    517                 }
    518                 case SOCK_DGRAM: {
    519                         T_IPV4EP rep = { 0, 0 };
    520                         ret = udp_rcv_dat(fp->psock->cepid, &rep, buf, len, (fp->psock->flags & O_NONBLOCK) ? 0 : TMO_FEVR);
    521                         if (ret < 0) {
    522                                 return -ECOMM;
    523                         }
    524                 }
    525                 }
    526                 break;
    527         }
    528         case AF_INET6: {
    529                 return -EAFNOSUPPORT;
    530         }
    531         }
    532 
    533         return ret;
    534 }
    535 
    536 ssize_t shell_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
    537 {
    538         SOCKET *fp = fd_to_fp(fd);
    539         if (fp == NULL) {
    540                 return -EBADF;
    541         }
    542 
    543         int ret = 0;
    544         switch (fp->psock->family) {
    545         case AF_INET: {
    546                 switch (fp->psock->type) {
    547                 case SOCK_STREAM: {
    548                         if (flags & MSG_OOB) {
    549                                 ret = tcp_rcv_oob(fp->psock->cepid, buf, len);
     550                                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     551                                }
     552
     553                                T_IPV4EP rep = { 0, 0 };
     554                                ret = udp_rcv_dat(fp->psock->cepid, &rep, buf, len,
     555                                        (fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
    550556                                if (ret < 0) {
    551                                         return -ECOMM;
     557                                        syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
     558                                        return (ret == E_TMOUT) ? -ETIME : -ECOMM;
     559                                }
     560                                rsz = ret;
     561                                if ((addr != NULL) && (alen != NULL)) {
     562                                        ret = wai_sem(SEM_FILEDESC);
     563                                        if (ret < 0) {
     564                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     565                                        }
     566                                        int sz = *alen;
     567                                        memset(raddr, 0, sizeof(fp->psock->raddr4));
     568                                        raddr->sin_family = AF_INET;
     569                                        raddr->sin_port = htons(rep.portno);
     570                                        raddr->sin_addr.s_addr = htonl(rep.ipaddr);
     571                                        if (sz > sizeof(fp->psock->raddr4))
     572                                                sz = sizeof(fp->psock->raddr4);
     573                                        memcpy(addr, raddr, sz);
     574                                        *alen = sz;
     575                                        ret = sig_sem(SEM_FILEDESC);
     576                                        if (ret < 0) {
     577                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     578                                        }
    552579                                }
    553580                        }
    554581                        else {
    555                                 ret = tcp_rcv_dat(fp->psock->cepid, buf, len, TMO_FEVR);
     582                                rsz = fp->psock->len;
     583                                void *pbuf = fp->psock->buf;
     584                                fp->psock->input = NULL;
     585                                fp->psock->len = 0;
     586                                fp->psock->buf = NULL;
     587                                if ((addr != NULL) && (alen != NULL)) {
     588                                        int sz = *alen;
     589                                        if (sz > sizeof(fp->psock->raddr4))
     590                                                sz = sizeof(fp->psock->raddr4);
     591                                        memcpy(addr, raddr, sz);
     592                                        *alen = sz;
     593                                }
     594                                ret = sig_sem(SEM_FILEDESC);
    556595                                if (ret < 0) {
    557                                         return -ECOMM;
    558                                 }
    559                         }
    560                         break;
    561                 }
    562                 case SOCK_DGRAM: {
    563                         T_IPV4EP rep = { 0, 0 };
    564                         ret = udp_rcv_dat(fp->psock->cepid, &rep, buf, len, TMO_FEVR);
    565                         if (ret < 0) {
    566                                 return -ECOMM;
    567                         }
    568                         int sz = *alen;
    569                         struct sockaddr_in raddr;
    570                         memset(&raddr, 0, sizeof(raddr));
    571                         raddr.sin_family = AF_INET;
    572                         raddr.sin_port = htons(rep.portno);
    573                         raddr.sin_addr.s_addr = htonl(rep.ipaddr);
    574                         if (sz > sizeof(raddr))
    575                                 sz = sizeof(raddr);
    576                         memcpy(addr, &raddr, sz);
     596                                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     597                                }
     598                                if (rsz > len)
     599                                        rsz = len;
     600                                memcpy(buf, pbuf, rsz);
     601                                ret = rel_net_buf(input);
     602                                if (ret < 0) {
     603                                        syslog(LOG_ERROR, "rel_net_buf => %d", ret);
     604                                        //return -ECOMM;
     605                                }
     606                        }
     607                        ret = rsz;
    577608                }
    578609                }
     
    830861int tcp_fd_close(struct _IO_FILE *fp)
    831862{
    832         ER ret;
    833 
    834         free(fp->psock->buf);
    835         fp->psock->buf = NULL;
     863        ER ret, ret2;
    836864
    837865        switch (fp->psock->family) {
     
    844872                        }
    845873                        ret = tcp_cls_cep(cepid, (fp->psock->repid != 0) ? 0 : SOCKET_TIMEOUT);
    846                         if (ret < 0) {
    847                                 //return -1;
    848                         }
    849                         ret = tcp_del_cep(cepid);
     874                        ret2 = tcp_del_cep(cepid);
     875                        free(fp->psock->buf);
     876                        fp->psock->buf = NULL;
    850877                        delete_tcp_fd(cepid);
    851878                        delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    852                         if (ret < 0) {
    853                                 return -EINVAL;
     879                        if ((ret < 0) || (ret2 < 0)) {
     880                                return (ret == E_TMOUT) ? -ETIME : -EINVAL;
    854881                        }
    855882                }
     
    857884                        ID repid = fp->psock->repid;
    858885                        ret = tcp_del_rep(repid);
     886                        free(fp->psock->buf);
     887                        fp->psock->buf = NULL;
    859888                        delete_tcp_fd(tmax_tcp_cepid + repid);
    860889                        delete_id(tcp_repid_table, tcp_repid_table_count, repid);
     
    864893                }
    865894                else {
     895                        free(fp->psock->buf);
     896                        fp->psock->buf = NULL;
    866897                        return -EINVAL;
    867898                }
     
    878909size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
    879910{
    880         return shell_recv(fp->fd, dst, dstsz, 0);
     911        return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
    881912}
    882913
    883914size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
    884915{
    885         return shell_send(fp->fd, src, srcsz, 0);
     916        return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
    886917}
    887918
     
    901932        ID cepid;
    902933
    903         free(fp->psock->buf);
    904         fp->psock->buf = NULL;
    905 
    906934        switch (fp->psock->family) {
    907935        case AF_INET: {
    908936                cepid = fp->psock->cepid;
    909937                ret = udp_del_cep(cepid);
     938                //free(fp->psock->buf);
     939                //fp->psock->buf = NULL;
    910940                delete_udp_fd(cepid);
    911941                delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
     
    925955size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
    926956{
    927         return shell_recv(fp->fd, dst, dstsz, 0);
     957        return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
    928958}
    929959
    930960size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
    931961{
    932         return shell_send(fp->fd, src, srcsz, 0);
     962        return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
    933963}
    934964
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h

    r352 r364  
    9999        int buf_size;
    100100        unsigned char *buf;
     101        void *input;
     102        int len;
    101103} socket_t;
    102104
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c

    r352 r364  
    201201
    202202long SYS_futex() {
     203        int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
    203204        return no_implement("futex\n");
    204205}
     
    309310
    310311long SYS_recv(long a, long b, long c, long d) {
    311         return shell_recv((int)a, (void *)b, (size_t)c, (int)d);
     312        return shell_recvfrom((int)a, (void *)b, (size_t)c, (int)d, NULL, NULL);
    312313}
    313314
    314315long SYS_recvfrom(long a, long b, long c, long d, long e, long f) {
    315         if (a == 0)
    316                 return shell_recv(a, (void *)b, (size_t)c, (int)d);
    317         else
    318                 return shell_recvfrom(a, (void *)b, (size_t)c, (int)d, (struct sockaddr *)e, (socklen_t *)f);
     316        return shell_recvfrom(a, (void *)b, (size_t)c, (int)d, (struct sockaddr *)e, (socklen_t *)f);
    319317}
    320318
     
    344342
    345343long SYS_send(long a, long b, long c, long d) {
    346         return shell_send((int)a, (const void *)b, (size_t)c, (int)d);
     344        return shell_sendto((int)a, (const void *)b, (size_t)c, (int)d, NULL, 0);
    347345}
    348346
     
    352350
    353351long SYS_sendto(long a, long b, long c, long d, long e, long f) {
    354         if (a == 0)
    355                 return shell_send(a, (const void *)b, (size_t)c, (int)d);
    356         else
    357                 return shell_sendto(a, (const void *)b, (size_t)c, (int)d, (const struct sockaddr *)e, (socklen_t)f);
     352        return shell_sendto(a, (const void *)b, (size_t)c, (int)d, (const struct sockaddr *)e, (socklen_t)f);
    358353}
    359354
     
    422417}
    423418
     419long SYS_dup()
     420{
     421        return no_implement("dup\n");
     422}
     423
     424long SYS_dup2()
     425{
     426        return no_implement("dup2\n");
     427}
     428
     429long SYS_pipe()
     430{
     431        return no_implement("pipe\n");
     432}
     433
     434long SYS_readlink()
     435{
     436        return no_implement("readlink\n");
     437}
     438
     439long SYS_symlink()
     440{
     441        return no_implement("symlink\n");
     442}
     443
     444long SYS_umask()
     445{
     446        return no_implement("umask\n");
     447}
     448
     449long SYS_execve()
     450{
     451        return no_implement("execve\n");
     452}
     453
     454long SYS_fork()
     455{
     456        return no_implement("fork\n");
     457}
     458
     459long SYS_wait4()
     460{
     461        return no_implement("wait4\n");
     462}
     463
     464long SYS_socketpair()
     465{
     466        return no_implement("socketpair\n");
     467}
     468
     469long SYS_flock()
     470{
     471        return no_implement("flock\n");
     472}
     473
    424474long ARM_SYS_cacheflush() {
    425475        flash_access_cache_control();
Note: See TracChangeset for help on using the changeset viewer.