source: azure_iot_hub/trunk/asp3_dcre/tinet/netapp/lcd.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 10.0 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者
8は,以下の (1)~(4) の条件か,Free Software Foundation
9 * によってå…
10¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
11 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
12 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
13å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
14 * 利用と呼ぶ)することを無償で許諾する.
15 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
16 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * スコード中に含まれていること.
18 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
19 * 用できる形で再é…
20å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
21å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
22 * 者
23マニュアルなど)に,上記の著作権表示,この利用条件および下記
24 * の無保証規定を掲載すること.
25 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
26 * 用できない形で再é…
27å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®æ¡ä»¶ã‚’満たすこと.
28 * (a) 再é…
29å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
30マニュアルなど)に,上記の著
31 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
32 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
33 * 害からも,上記著作権者
34およびTOPPERSプロジェクトをå…
35è²¬ã™ã‚‹ã“と.
36 *
37 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
38お
39 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
40 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
41 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
42 *
43 * @(#) $Id: lcd.c 388 2019-05-22 11:25:18Z coas-nagasima $
44 */
45
46#include <stdarg.h>
47#include <string.h>
48
49#ifdef TARGET_KERNEL_ASP
50
51#include <sil.h>
52#include "target_syssvc.h"
53#include "target_lcd.h"
54#include <kernel.h>
55#include <t_syslog.h>
56
57#endif /* of #ifdef TARGET_KERNEL_ASP */
58
59#ifdef TARGET_KERNEL_JSP
60
61#include <s_services.h>
62#include <t_services.h>
63#include "hw_lcd.h"
64#include "kernel_id.h"
65
66#endif /* of #ifdef TARGET_KERNEL_JSP */
67
68#include <netinet/in.h>
69#include <netinet/in_itron.h>
70
71#include <netapp/lcd.h>
72
73/*
74 * 局所変数の定義
75 */
76
77static bool_t newline = false;
78static int_t col = 0;
79static int8_t line[LCD_COLUMN_SIZE + 1] = { " " };
80
81/*
82 * lcd_cls -- LCD 表示クリア
83 */
84
85void
86lcd_cls (void)
87{
88 target_lcd_cls();
89 col = 0;
90 newline = false;
91 }
92
93/*
94 * lcd_newline -- LCD の表示を改行する。
95 */
96
97static void
98lcd_newline (void)
99{
100 target_lcd_newline(line, col);
101 col = 0;
102 newline = false;
103 }
104
105/*
106 * lcd_initialize -- LCD 初期化
107 */
108
109void
110lcd_initialize (intptr_t exinf)
111{
112 target_lcd_initialize();
113 lcd_cls();
114 }
115
116/*
117 * lcd_putc -- LCD 出力
118 */
119
120void
121lcd_putc (ID portid, int8_t data)
122{
123 if (data == '\n')
124 newline = true;
125 else {
126 if (newline)
127 lcd_newline();
128 target_lcd_data_putc(data);
129 line[col ++] = data;
130 if (col >= LCD_COLUMN_SIZE)
131 newline = true;
132 }
133 }
134
135/*
136 * lcd_puts -- LCD への文字列の出力
137 */
138
139void
140lcd_puts (ID portid, const char *str)
141{
142 while (*str != '\0')
143 lcd_putc(portid, *str ++);
144 }
145
146/*
147 * LCD への書式付文字列出力ライブラリ
148 */
149
150/*
151 * 数値変換のための変換表
152 */
153
154static const char radhex[] = "0123456789abcdef";
155static const char radHEX[] = "0123456789ABCDEF";
156
157/*
158 * もっとも長い整数型 (LONGEST) と符号なし整数型 (ULONGEST)
159 */
160
161#ifdef _int64_
162
163typedef _int64_ LONGEST;
164typedef unsigned _int64_ ULONGEST;
165
166#else /* of #ifdef _int64_ */
167
168#ifdef _int32_
169
170typedef _int32_ LONGEST;
171typedef unsigned _int32_ ULONGEST;
172
173#else /* of #ifdef _int32_ */
174
175typedef int_t LONGEST;
176typedef uint_t ULONGEST;
177
178#endif /* of #ifdef _int32_ */
179
180#endif /* of #ifdef _int64_ */
181
182/*
183 * convert -- lcd_printf の数値変換
184 */
185
186static int_t
187convert (ID portid, ULONGEST val, int_t radix,
188 const char *radchar, int_t width, bool_t minus, char padchar)
189{
190 char digits[24];
191 int_t ix, pad, pchars;
192 bool_t left;
193
194 if (width < 0) {
195 width = -width;
196 left = true;
197 }
198 else
199 left = false;
200
201 ix = 0;
202 do {
203 digits[ix ++] = radchar[val % radix];
204 val /= radix;
205 } while (val != 0);
206
207 if (minus)
208 digits[ix ++] = '-';
209
210 if (width > ix)
211 pchars = width;
212 else
213 pchars = ix;
214
215 pad = ix;
216 if (!left) /* 右詰め */
217 for ( ; pad < width; pad ++)
218 lcd_putc(portid, padchar);
219
220 while (ix -- > 0)
221 lcd_putc(portid, digits[ix]);
222
223 if (left) /* 左詰め */
224 for ( ; pad < width; pad ++)
225 lcd_putc(portid, padchar);
226
227 return pchars;
228 }
229
230#if defined(SUPPORT_INET4)
231
232/*
233 * ipv4addr -- IPv4 アドレス出力
234 */
235
236static void
237put_ipv4addr (ID portid, T_IN4_ADDR *addr, int_t width)
238{
239 int_t len = 3; /* 3 は '.' の文字数 */
240
241 len += convert(portid, (*addr >> 24) & 0xff, 10, radhex, 0, false, ' ');
242 lcd_putc(portid, '.');
243 len += convert(portid, (*addr >> 16) & 0xff, 10, radhex, 0, false, ' ');
244 lcd_putc(portid, '.');
245 len += convert(portid, (*addr >> 8) & 0xff, 10, radhex, 0, false, ' ');
246 lcd_putc(portid, '.');
247 len += convert(portid, *addr & 0xff, 10, radhex, 0, false, ' ');
248
249 for ( ; len < width; len ++)
250 lcd_putc(portid, ' ');
251 }
252
253#endif /* of #if defined(SUPPORT_INET4) */
254
255#if defined(SUPPORT_INET6)
256
257/*
258 * ipv6addr -- IPv6 アドレス出力
259 */
260
261static void
262put_ipv6addr (ID portid, const T_IN6_ADDR *addr, int_t width)
263{
264 int_t len = 0, ix;
265 bool_t omit = false, zero = false;
266
267 if (addr == NULL || IN6_IS_ADDR_UNSPECIFIED(addr)) {
268 lcd_putc(portid, ':');
269 lcd_putc(portid, ':');
270 }
271 else {
272 for (ix = 0; ix < sizeof(T_IN6_ADDR) / 2; ix ++) {
273 if (omit) {
274 if (ix < 7) {
275 lcd_putc(portid, ':');
276 len ++;
277 }
278 }
279 else if (ix > 0 && ix < 7 && addr->s6_addr16[ix] == 0)
280 zero = true;
281 else {
282 if (zero) {
283 omit = true;
284 lcd_putc(portid, ':');
285 len ++;
286 }
287 if (ix < 7) {
288 lcd_putc(portid, ':');
289 len ++;
290 }
291 }
292 }
293
294 for ( ; len < width; len ++)
295 lcd_putc(portid, ' ');
296 }
297 }
298
299#endif /* of #if defined(SUPPORT_INET6) */
300
301/*
302 * macaddr -- MAC アドレス出力
303 */
304
305static void
306macaddr (ID portid, uint8_t *mac, int_t width)
307{
308 int_t oct, len;
309
310 for (oct = 5; oct -- > 0; ) {
311 convert(portid, *mac ++, 16, radhex, 2, false, '0');
312 lcd_putc(portid, ':');
313 }
314 convert(portid, *mac, 16, radhex, 2, false, '0');
315
316 for (len = 17; len < width; len ++)
317 lcd_putc(portid, ' ');
318 }
319
320/*
321 * 引数を取り出すためのマクロ
322 */
323
324#ifdef _int32_
325
326#define GET_ARG(ap,lf) (lf ? va_arg(ap, _int32_) : va_arg(ap, int_t))
327
328#else /* of #ifdef _int32_ */
329
330#define GET_ARG(ap,lf) (va_arg(ap, int_t))
331
332#endif /* of #ifdef _int32_ */
333
334/*
335 * lcd_printf -- シリアルポートへの書式付文字列出力
336 */
337
338void
339lcd_printf (ID portid, const char *fmt, ...)
340{
341 va_list ap;
342 LONGEST val;
343 char padchar, *str;
344 int_t ch, width, longflag, shortflag, left;
345
346#if defined(SUPPORT_INET4)
347 T_IN4_ADDR *addr;
348#endif /* of #if defined(SUPPORT_INET4) */
349
350 va_start(ap, fmt);
351 while ((ch = *fmt ++) != '\0') {
352 if (ch != '%') { /* 書式指定以外 */
353 lcd_putc(portid, (char)ch);
354 continue;
355 }
356
357 width = longflag = shortflag = 0;
358 padchar = ' ';
359
360 if (ch == '-') { /* 左詰め */
361 fmt ++;
362 left = -1;
363 }
364 else
365 left = 1;
366
367 if ((ch = *fmt ++) == '0') { /* 上位桁の 0 */
368 padchar = '0';
369 ch = *fmt ++;
370 }
371
372 while ('0' <= ch && ch <= '9') { /* 出力幅
373 */
374 width = width * 10 + ch - '0';
375 ch = *fmt ++;
376 }
377
378 while (ch == 'l') { /* long (long) の指定 */
379 longflag ++;
380 ch = *fmt ++;
381 }
382
383 while (ch == 'h') { /* short の指定 */
384 shortflag ++;
385 ch = *fmt ++;
386 }
387
388 switch (ch) {
389 case 'd':
390 val = GET_ARG(ap, longflag);
391 if (val >= 0)
392 convert(portid, val, 10, radhex, width * left, false, padchar);
393 else
394 convert(portid, -val, 10, radhex, width * left, true, padchar);
395 break;
396
397 case 'u':
398 val = GET_ARG(ap, longflag);
399 convert(portid, val, 10, radhex, width * left, false, padchar);
400 break;
401
402 case 'x':
403 val = GET_ARG(ap, longflag);
404 convert(portid, val, 16, radhex, width * left, false, padchar);
405 break;
406
407 case 'X':
408 val = GET_ARG(ap, longflag);
409 convert(portid, val, 16, radHEX, width * left, false, padchar);
410 break;
411
412 case 'c':
413 ch = va_arg(ap, int_t);
414 lcd_putc(portid, (char)ch);
415 break;
416
417 case 's':
418 str = va_arg(ap, char*);
419 while ((ch = *str ++) != '\0')
420 lcd_putc(portid, (char)ch);
421 break;
422
423 case 'I':
424
425 if (longflag) {
426
427#if defined(SUPPORT_INET6)
428
429 str = va_arg(ap, char*);
430 put_ipv6addr(portid, (T_IN6_ADDR *)str, width);
431
432#else /* of #if defined(SUPPORT_INET6) */
433
434 addr = va_arg(ap, T_IN4_ADDR *);
435 put_ipv4addr(portid, addr, width);
436
437#endif /* of #if defined(SUPPORT_INET6) */
438
439 }
440 else if (shortflag) {
441
442#if defined(SUPPORT_INET4)
443
444 addr = va_arg(ap, T_IN4_ADDR *);
445 put_ipv4addr(portid, addr, width);
446
447#else /* of #if defined(SUPPORT_INET4) */
448
449 str = va_arg(ap, char*);
450 put_ipv6addr(portid, (T_IN6_ADDR *)str, width);
451
452#endif /* of #if defined(SUPPORT_INET4) */
453
454 }
455 else {
456
457#if defined(SUPPORT_INET6)
458
459 str = va_arg(ap, char*);
460 put_ipv6addr(portid, (T_IN6_ADDR *)str, width);
461
462#else /* of #if defined(SUPPORT_INET6) */
463
464#if defined(SUPPORT_INET4)
465
466 addr = va_arg(ap, T_IN4_ADDR *);
467 put_ipv4addr(portid, addr, width);
468
469#endif /* of #if defined(SUPPORT_INET4) */
470
471#endif /* of #if defined(SUPPORT_INET6) */
472
473 }
474 break;
475
476 case 'M':
477 str = va_arg(ap, char*);
478 macaddr(portid, str, width);
479 break;
480
481 case '%':
482 lcd_putc(portid, '%');
483 break;
484
485 case '0':
486 fmt --;
487 break;
488
489 default:
490 break;
491 }
492
493 }
494 va_end(ap);
495 }
Note: See TracBrowser for help on using the repository browser.