source: UsbWattMeter/trunk/asp_dcre/library/log_output.c@ 164

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

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 5.0 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
6 * Toyohashi Univ. of Technology, JAPAN
7 * Copyright (C) 2004-2011 by Embedded and Real-Time Systems Laboratory
8 * Graduate School of Information Science, Nagoya Univ., JAPAN
9 *
10 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
11 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
12 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
13 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
14 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
15 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
16 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
17 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
18ƒƒ“ƒgi—˜—p
19 * ŽÒƒ}ƒjƒ…
20ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
21 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
22 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
23 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
24 * ‚ƁD
25 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
26ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
27ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
28 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
29 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
30 * •ñ‚·‚邱‚ƁD
31 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
32 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
33 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
34 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
35 * –Ɛӂ·‚邱‚ƁD
36 *
37 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
38 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
39 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
40 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
41 * ‚̐ӔC‚𕉂í‚È‚¢D
42 *
43 * @(#) $Id: log_output.c 164 2016-03-07 11:33:50Z coas-nagasima $
44 */
45
46/*
47 * ƒVƒXƒeƒ€ƒƒO‚̃tƒH[ƒ}ƒbƒgo—Í
48 */
49
50#include <t_stddef.h>
51#include <t_syslog.h>
52#include <log_output.h>
53
54/*
55 * ”’l‚𕶎š—ñ‚É•ÏŠ·
56 */
57#define CONVERT_BUFLEN ((sizeof(uintptr_t) * CHAR_BIT + 2) / 3)
58 /* uintptr_tŒ^‚̐”’l‚̍ő啶Žš” */
59static void
60convert(uintptr_t val, uint_t radix, const char *radchar,
61 uint_t width, bool_t minus, bool_t padzero, void (*putc)(char))
62{
63 char buf[CONVERT_BUFLEN];
64 uint_t i, j;
65
66 i = 0U;
67 do {
68 buf[i++] = radchar[val % radix];
69 val /= radix;
70 } while (i < CONVERT_BUFLEN && val != 0);
71
72 if (minus && width > 0) {
73 width -= 1;
74 }
75 if (minus && padzero) {
76 (*putc)('-');
77 }
78 for (j = i; j < width; j++) {
79 (*putc)(padzero ? '0' : ' ');
80 }
81 if (minus && !padzero) {
82 (*putc)('-');
83 }
84 while (i > 0U) {
85 (*putc)(buf[--i]);
86 }
87}
88
89/*
90 * •¶Žš—ñ®Œ`o—Í
91 */
92static const char raddec[] = "0123456789";
93static const char radhex[] = "0123456789abcdef";
94static const char radHEX[] = "0123456789ABCDEF";
95
96void
97syslog_printf(const char *format, const intptr_t *p_args, void (*putc)(char))
98{
99 char c;
100 uint_t width;
101 bool_t padzero;
102 intptr_t val;
103 const char *str;
104
105 while ((c = *format++) != '\0') {
106 if (c != '%') {
107 (*putc)(c);
108 continue;
109 }
110
111 width = 0U;
112 padzero = false;
113 if ((c = *format++) == '0') {
114 padzero = true;
115 c = *format++;
116 }
117 while ('0' <= c && c <= '9') {
118 width = width * 10U + c - '0';
119 c = *format++;
120 }
121 if (c == 'l') {
122 c = *format++;
123 }
124 switch (c) {
125 case 'd':
126 val = (intptr_t)(*p_args++);
127 if (val >= 0) {
128 convert((uintptr_t) val, 10U, raddec,
129 width, false, padzero, putc);
130 }
131 else {
132 convert((uintptr_t)(-val), 10U, raddec,
133 width, true, padzero, putc);
134 }
135 break;
136 case 'u':
137 val = (intptr_t)(*p_args++);
138 convert((uintptr_t) val, 10U, raddec, width, false, padzero, putc);
139 break;
140 case 'x':
141 case 'p':
142 val = (intptr_t)(*p_args++);
143 convert((uintptr_t) val, 16U, radhex, width, false, padzero, putc);
144 break;
145 case 'X':
146 val = (intptr_t)(*p_args++);
147 convert((uintptr_t) val, 16U, radHEX, width, false, padzero, putc);
148 break;
149 case 'c':
150 (*putc)((char)(intptr_t)(*p_args++));
151 break;
152 case 's':
153 str = (const char *)(*p_args++);
154 while ((c = *str++) != '\0') {
155 (*putc)(c);
156 }
157 break;
158 case '%':
159 (*putc)('%');
160 break;
161 case '\0':
162 format--;
163 break;
164 default:
165 break;
166 }
167 }
168}
169
170/*
171 * ƒƒOî•ñ‚̏o—Í
172 */
173void
174syslog_print(const SYSLOG *p_syslog, void (*putc)(char))
175{
176 switch (p_syslog->logtype) {
177 case LOG_TYPE_COMMENT:
178 syslog_printf((const char *)(p_syslog->loginfo[0]),
179 &(p_syslog->loginfo[1]), putc);
180 break;
181 case LOG_TYPE_ASSERT:
182 syslog_printf("%s:%u: Assertion `%s' failed.",
183 &(p_syslog->loginfo[0]), putc);
184 break;
185 default:
186 /*
187 * ‘¼‚ÌŽí•Ê‚̃ƒOî•ñ‚ɂ͑Ήž‚µ‚Ä‚¢‚È‚¢D
188 */
189 break;
190 }
191}
192
193/*
194 * ƒƒOî•ñ‘rŽ¸ƒƒbƒZ[ƒW‚̏o—Í
195 */
196void
197syslog_lostmsg(uint_t lostlog, void (*putc)(char))
198{
199 intptr_t lostinfo[1];
200
201 lostinfo[0] = (intptr_t) lostlog;
202 syslog_printf("%d messages are lost.", lostinfo, putc);
203 (*putc)('\n');
204}
Note: See TracBrowser for help on using the repository browser.