UART通信を用いた組み込みデバッグ用途向けメモリモニタ
Revision | 08c148c686dec0cbc8d8a6a66845d45f4aaf717d (tree) |
---|---|
Time | 2018-05-08 23:09:50 |
Author | Yasushi Tanaka <tanaka_yasushi2008@yaho...> |
Commiter | Yasushi Tanaka |
ログを実装
@@ -84,7 +84,7 @@ | ||
84 | 84 | <ClInclude Include="src\framework\bdlist.h" /> |
85 | 85 | <ClInclude Include="src\framework\cons.h" /> |
86 | 86 | <ClInclude Include="src\framework\header.h" /> |
87 | - <ClInclude Include="src\framework\listbox.h" /> | |
87 | + <ClInclude Include="src\framework\logwin.h" /> | |
88 | 88 | <ClInclude Include="src\framework\monitor.h" /> |
89 | 89 | <ClInclude Include="src\framework\screen.h" /> |
90 | 90 | <ClInclude Include="src\framework\winmain.h" /> |
@@ -93,7 +93,7 @@ | ||
93 | 93 | <ClCompile Include="src\comm\comm.c" /> |
94 | 94 | <ClCompile Include="src\framework\bdlist.c" /> |
95 | 95 | <ClCompile Include="src\framework\cons.c" /> |
96 | - <ClCompile Include="src\framework\listbox.c" /> | |
96 | + <ClCompile Include="src\framework\logwin.c" /> | |
97 | 97 | <ClCompile Include="src\framework\monitor.c" /> |
98 | 98 | <ClCompile Include="src\framework\screen.c" /> |
99 | 99 | <ClCompile Include="src\framework\winmain.c" /> |
@@ -33,9 +33,6 @@ | ||
33 | 33 | <ClInclude Include="src\framework\header.h"> |
34 | 34 | <Filter>ヘッダー ファイル\framework</Filter> |
35 | 35 | </ClInclude> |
36 | - <ClInclude Include="src\framework\listbox.h"> | |
37 | - <Filter>ヘッダー ファイル\framework</Filter> | |
38 | - </ClInclude> | |
39 | 36 | <ClInclude Include="src\framework\monitor.h"> |
40 | 37 | <Filter>ヘッダー ファイル\framework</Filter> |
41 | 38 | </ClInclude> |
@@ -48,6 +45,9 @@ | ||
48 | 45 | <ClInclude Include="src\framework\cons.h"> |
49 | 46 | <Filter>ヘッダー ファイル\framework</Filter> |
50 | 47 | </ClInclude> |
48 | + <ClInclude Include="src\framework\logwin.h"> | |
49 | + <Filter>ヘッダー ファイル\framework</Filter> | |
50 | + </ClInclude> | |
51 | 51 | </ItemGroup> |
52 | 52 | <ItemGroup> |
53 | 53 | <ClCompile Include="src\framework\winmain.c"> |
@@ -56,9 +56,6 @@ | ||
56 | 56 | <ClCompile Include="src\framework\screen.c"> |
57 | 57 | <Filter>ソース ファイル\framework</Filter> |
58 | 58 | </ClCompile> |
59 | - <ClCompile Include="src\framework\listbox.c"> | |
60 | - <Filter>ソース ファイル\framework</Filter> | |
61 | - </ClCompile> | |
62 | 59 | <ClCompile Include="src\framework\monitor.c"> |
63 | 60 | <Filter>ソース ファイル\framework</Filter> |
64 | 61 | </ClCompile> |
@@ -71,5 +68,8 @@ | ||
71 | 68 | <ClCompile Include="src\framework\cons.c"> |
72 | 69 | <Filter>ソース ファイル\framework</Filter> |
73 | 70 | </ClCompile> |
71 | + <ClCompile Include="src\framework\logwin.c"> | |
72 | + <Filter>ソース ファイル\framework</Filter> | |
73 | + </ClCompile> | |
74 | 74 | </ItemGroup> |
75 | 75 | </Project> |
\ No newline at end of file |
@@ -23,16 +23,12 @@ | ||
23 | 23 | /* スクリーンオブジェクト */ |
24 | 24 | static SCREEN_OBJECT g_cons_screen; |
25 | 25 | |
26 | -static DWORD g_dwTime; | |
27 | - | |
28 | 26 | /* |
29 | 27 | * コンソール |
30 | 28 | * 初期化 |
31 | 29 | */ |
32 | 30 | BOOL cons_init(HWND parent, int x, int y, int width, int height) |
33 | 31 | { |
34 | - g_dwTime = timeGetTime(); | |
35 | - | |
36 | 32 | /* スクリーンオブジェクトを初期化 */ |
37 | 33 | memset(&g_cons_screen, 0, sizeof(g_cons_screen)); |
38 | 34 |
@@ -73,19 +69,6 @@ void cons_resize(int x, int y, int width, int height) | ||
73 | 69 | */ |
74 | 70 | void cons_idle(void) |
75 | 71 | { |
76 | - DWORD dwDiff; | |
77 | - | |
78 | - dwDiff = (DWORD)(timeGetTime() - g_dwTime); | |
79 | - if (dwDiff < 200) | |
80 | - { | |
81 | - return; | |
82 | - } | |
83 | - g_dwTime += 200; | |
84 | - | |
85 | - if (g_cons_screen.virt.lines < 60) | |
86 | - { | |
87 | - cons_printf("Lines = %02d, g_dwTime = %d", g_cons_screen.virt.lines, g_dwTime); | |
88 | - } | |
89 | 72 | } |
90 | 73 | |
91 | 74 | /* |
@@ -0,0 +1,289 @@ | ||
1 | +/* | |
2 | + * Debug Monitor Framework | |
3 | + * Author: Yasushi Tanaka | |
4 | + * | |
5 | + * [ Windowsログ ] | |
6 | + */ | |
7 | + | |
8 | +#include "header.h" | |
9 | +#include "screen.h" | |
10 | +#include "logwin.h" | |
11 | + | |
12 | +/* | |
13 | + * 定数 | |
14 | + */ | |
15 | + | |
16 | +/* ウィンドウキャプション */ | |
17 | +#define LOGWIN_WINDOW_NAME L"Windowsログ" | |
18 | + | |
19 | +/* | |
20 | + * static変数 | |
21 | + */ | |
22 | + | |
23 | +/* スクリーンオブジェクト */ | |
24 | +static SCREEN_OBJECT g_logwin_screen; | |
25 | + | |
26 | +/* ファイルハンドル */ | |
27 | +static FILE *g_logwin_file; | |
28 | + | |
29 | +/* ログ番号 */ | |
30 | +static UINT g_logwin_num; | |
31 | + | |
32 | +/* | |
33 | + * Windowsログ | |
34 | + * 終了 | |
35 | + */ | |
36 | +static void logwin_on_ncdestroy(void) | |
37 | +{ | |
38 | + /* ファイルハンドルを閉じる */ | |
39 | + if (NULL != g_logwin_file) | |
40 | + { | |
41 | + fclose(g_logwin_file); | |
42 | + g_logwin_file = NULL; | |
43 | + } | |
44 | +} | |
45 | + | |
46 | +/* | |
47 | + * Windowsログ | |
48 | + * ファイルオープン | |
49 | + */ | |
50 | +BOOL logwin_file_open(void) | |
51 | +{ | |
52 | + wchar_t buf[0x8000]; | |
53 | + wchar_t dir[0x8000]; | |
54 | + DWORD len; | |
55 | + DWORD attr; | |
56 | + BOOL result; | |
57 | + SYSTEMTIME st; | |
58 | + errno_t err; | |
59 | + | |
60 | + /* bufには十分大きなバッファを用意すること(250キャラクタを超える長いファイルネームに対応) */ | |
61 | + len = GetModuleFileName(NULL, buf, _countof(buf)); | |
62 | + assert((0 != len) && (ERROR_INSUFFICIENT_BUFFER != len)); | |
63 | + if ((0 == len) || (ERROR_INSUFFICIENT_BUFFER == len)) | |
64 | + { | |
65 | + return FALSE; | |
66 | + } | |
67 | + | |
68 | + /* len-1から走査して、最初に区切り文字が出てきたところを見つける */ | |
69 | + len--; | |
70 | + while (len > 0) | |
71 | + { | |
72 | + if (L'\\' == buf[len]) | |
73 | + { | |
74 | + /* この次で切る */ | |
75 | + buf[len + 1] = L'\0'; | |
76 | + break; | |
77 | + } | |
78 | + len--; | |
79 | + } | |
80 | + if (0 == len) | |
81 | + { | |
82 | + return FALSE; | |
83 | + } | |
84 | + | |
85 | + /* 先頭は\\?\*/ | |
86 | + wcscpy_s(dir, _countof(dir), L"\\\\?\\"); | |
87 | + | |
88 | + /* パス本体 */ | |
89 | + wcscat_s(dir, _countof(dir), buf); | |
90 | + | |
91 | + /* logを追加 */ | |
92 | + wcscat_s(dir, _countof(dir), L"log"); | |
93 | + | |
94 | + /* ファイルまたはディレクトリが存在すると仮定して、属性を得る */ | |
95 | + attr = GetFileAttributes(dir); | |
96 | + if (INVALID_FILE_ATTRIBUTES == attr) | |
97 | + { | |
98 | + /* ファイルまたはディレクトリは存在しない */ | |
99 | + attr = 0; | |
100 | + } | |
101 | + else | |
102 | + { | |
103 | + /* ディレクトリ属性のみをマスク */ | |
104 | + attr &= FILE_ATTRIBUTE_DIRECTORY; | |
105 | + } | |
106 | + | |
107 | + /* ディレクトリ属性か */ | |
108 | + if (0 == attr) | |
109 | + { | |
110 | + /* ディレクトリ属性でないので、作成を試みる */ | |
111 | + result = CreateDirectory(dir, NULL); | |
112 | + if (FALSE == result) | |
113 | + { | |
114 | + /* ディレクトリの作成に失敗 */ | |
115 | + return FALSE; | |
116 | + } | |
117 | + } | |
118 | + | |
119 | + /* ローカル時刻を取得 */ | |
120 | + memset(&st, 0, sizeof(st)); | |
121 | + GetLocalTime(&st); | |
122 | + | |
123 | + /* dirからbufへ逆にフォーマット */ | |
124 | + wcscat_s(dir, _countof(dir), L"\\"); | |
125 | + swprintf_s( | |
126 | + buf, | |
127 | + _countof(buf), | |
128 | + L"%s%04d%02d%02d_%02d%02d%02d.log", | |
129 | + dir, | |
130 | + st.wYear, | |
131 | + st.wMonth, | |
132 | + st.wDay, | |
133 | + st.wHour, | |
134 | + st.wMinute, | |
135 | + st.wSecond); | |
136 | + | |
137 | + /* ファイルを作成 */ | |
138 | + err = _wfopen_s(&g_logwin_file, buf, L"a+t"); | |
139 | + if ((0 != err) || (NULL == g_logwin_file)) | |
140 | + { | |
141 | + return FALSE; | |
142 | + } | |
143 | + | |
144 | + /* 成功 */ | |
145 | + return TRUE; | |
146 | +} | |
147 | + | |
148 | +/* | |
149 | + * Windowsログ | |
150 | + * 初期化 | |
151 | + */ | |
152 | +BOOL logwin_init(HWND parent, int x, int y, int width, int height) | |
153 | +{ | |
154 | + BOOL result; | |
155 | + | |
156 | + /* ファイルハンドルを初期化 */ | |
157 | + g_logwin_file = NULL; | |
158 | + | |
159 | + /* ログ番号を初期化 */ | |
160 | + g_logwin_num = 0; | |
161 | + | |
162 | + /* ファイルオープン */ | |
163 | + result = logwin_file_open(); | |
164 | + if (FALSE == result) | |
165 | + { | |
166 | + return FALSE; | |
167 | + } | |
168 | + | |
169 | + /* スクリーンオブジェクトを初期化 */ | |
170 | + memset(&g_logwin_screen, 0, sizeof(g_logwin_screen)); | |
171 | + | |
172 | + /* パラメータをセット */ | |
173 | + g_logwin_screen.name = LOGWIN_WINDOW_NAME; | |
174 | + g_logwin_screen.parent = parent; | |
175 | + g_logwin_screen.x = x; | |
176 | + g_logwin_screen.y = y; | |
177 | + g_logwin_screen.width = width; | |
178 | + g_logwin_screen.height = height; | |
179 | + g_logwin_screen.fore_def = GetSysColor(COLOR_WINDOWTEXT); | |
180 | + g_logwin_screen.back_def = GetSysColor(COLOR_WINDOW); | |
181 | + g_logwin_screen.vscroll = TRUE; | |
182 | + g_logwin_screen.on_ncdestroy = logwin_on_ncdestroy; | |
183 | + | |
184 | + /* スクリーンを作成 */ | |
185 | + return screen_create(&g_logwin_screen); | |
186 | +} | |
187 | + | |
188 | +/* | |
189 | + * Windowsログ | |
190 | + * リサイズ | |
191 | + */ | |
192 | +void logwin_resize(int x, int y, int width, int height) | |
193 | +{ | |
194 | + /* パラメータをセット */ | |
195 | + g_logwin_screen.x = x; | |
196 | + g_logwin_screen.y = y; | |
197 | + g_logwin_screen.width = width; | |
198 | + g_logwin_screen.height = height; | |
199 | + | |
200 | + /* スクリーンをリサイズ */ | |
201 | + screen_resize(&g_logwin_screen); | |
202 | +} | |
203 | + | |
204 | +/* | |
205 | + * Windowsログ | |
206 | + * ログ出力 | |
207 | + */ | |
208 | +void logwin_out(const char *log) | |
209 | +{ | |
210 | + char buf[0x400]; | |
211 | + wchar_t wide[0x400]; | |
212 | + SYSTEMTIME st; | |
213 | + UINT loop; | |
214 | + | |
215 | + assert(NULL != log); | |
216 | + | |
217 | + /* ローカル時刻を取得 */ | |
218 | + memset(&st, 0, sizeof(st)); | |
219 | + GetLocalTime(&st); | |
220 | + | |
221 | + /* bufへフォーマット */ | |
222 | + sprintf_s( | |
223 | + buf, | |
224 | + _countof(buf), | |
225 | + "%07d,%02d:%02d:%02d.%03d,%s", | |
226 | + g_logwin_num, | |
227 | + st.wHour, | |
228 | + st.wMinute, | |
229 | + st.wSecond, | |
230 | + st.wMilliseconds, | |
231 | + log | |
232 | + ); | |
233 | + buf[_countof(buf) - 1] = L'\0'; | |
234 | + | |
235 | + /* ログ番号を進める */ | |
236 | + g_logwin_num++; | |
237 | + | |
238 | + /* \nが現れたら、そこで打ち切る */ | |
239 | + for (loop = 0; loop < _countof(buf); loop++) | |
240 | + { | |
241 | + if ('\0' == buf[loop]) | |
242 | + { | |
243 | + break; | |
244 | + } | |
245 | + if ('\n' == buf[loop]) | |
246 | + { | |
247 | + buf[loop] = '\0'; | |
248 | + break; | |
249 | + } | |
250 | + } | |
251 | + | |
252 | + /* ファイルへ追加 */ | |
253 | + assert(NULL != g_logwin_file); | |
254 | + fprintf_s(g_logwin_file, "%s\n", buf); | |
255 | + | |
256 | + /* ワイド文字へ変換 */ | |
257 | + MultiByteToWideChar( | |
258 | + CP_ACP, | |
259 | + MB_PRECOMPOSED, | |
260 | + buf, | |
261 | + -1, | |
262 | + wide, | |
263 | + _countof(wide)); | |
264 | + wide[_countof(wide) - 1] = L'\0'; | |
265 | + | |
266 | + /* 表示スクリーンへ追加 */ | |
267 | + screen_add(&g_logwin_screen, wide); | |
268 | +} | |
269 | + | |
270 | +/* | |
271 | + * Windowsログ | |
272 | + * 書式つき出力 | |
273 | + */ | |
274 | +void logwin_printf(const char *format, ...) | |
275 | +{ | |
276 | + char multibyte[0x400]; | |
277 | + va_list ap; | |
278 | + | |
279 | + assert(NULL != format); | |
280 | + | |
281 | + /* フォーマット */ | |
282 | + va_start(ap, format); | |
283 | + vsprintf_s(multibyte, _countof(multibyte), format, ap); | |
284 | + multibyte[_countof(multibyte) - 1] = '\0'; | |
285 | + va_end(ap); | |
286 | + | |
287 | + /* ログ出力 */ | |
288 | + logwin_out(multibyte); | |
289 | +} |
@@ -0,0 +1,24 @@ | ||
1 | +/* | |
2 | + * Debug Monitor Framework | |
3 | + * Author: Yasushi Tanaka | |
4 | + * | |
5 | + * [ Windowsログ ] | |
6 | + */ | |
7 | + | |
8 | +#pragma once | |
9 | + | |
10 | +/* | |
11 | + * グローバル関数 | |
12 | + */ | |
13 | + | |
14 | +/* 初期化 */ | |
15 | +BOOL logwin_init(HWND parent, int x, int y, int width, int height); | |
16 | + | |
17 | +/* リサイズ */ | |
18 | +void logwin_resize(int x, int y, int width, int height); | |
19 | + | |
20 | +/* ログ追加 */ | |
21 | +void logwin_out(const char *log); | |
22 | + | |
23 | +/* 書式つき出力 */ | |
24 | +void logwin_printf(const char *format, ...); |
@@ -1467,6 +1467,12 @@ static void screen_on_ncdestroy(HWND hWnd) | ||
1467 | 1467 | |
1468 | 1468 | /* スクリーンオブジェクトを破棄する */ |
1469 | 1469 | screen_destroy_object(object); |
1470 | + | |
1471 | + /* コールバック関数が登録されていれば呼び出す */ | |
1472 | + if (NULL != object->on_ncdestroy) | |
1473 | + { | |
1474 | + object->on_ncdestroy(); | |
1475 | + } | |
1470 | 1476 | } |
1471 | 1477 | |
1472 | 1478 | /* |
@@ -165,6 +165,9 @@ typedef struct _SCREEN_OBJECT | ||
165 | 165 | /* デフ4ォルトのバックグラウンドカラー */ |
166 | 166 | COLORREF back_def; |
167 | 167 | |
168 | + /* ウィンドウ破棄時に呼び出されるコールバック関数 */ | |
169 | + void (*on_ncdestroy)(void); | |
170 | + | |
168 | 171 | /* |
169 | 172 | * スクリーン側が管理する領域 |
170 | 173 | */ |
@@ -9,7 +9,7 @@ | ||
9 | 9 | #include "screen.h" |
10 | 10 | #include "cons.h" |
11 | 11 | #include "monitor.h" |
12 | -#include "listbox.h" | |
12 | +#include "logwin.h" | |
13 | 13 | #include "comm.h" |
14 | 14 | #include "winmain.h" |
15 | 15 |
@@ -66,9 +66,6 @@ typedef struct _CHILD_RECTS { | ||
66 | 66 | |
67 | 67 | /* ログ(Windows)領域 */ |
68 | 68 | RECT rcLogWin; |
69 | - | |
70 | - /* ログ(ターゲット)領域 */ | |
71 | - RECT rcLogTarget; | |
72 | 69 | } CHILD_RECTS; |
73 | 70 | |
74 | 71 | /* |
@@ -121,7 +118,7 @@ static void CalcChilldRects(HWND hWnd) | ||
121 | 118 | } |
122 | 119 | } |
123 | 120 | |
124 | - /* 高さの60%をスクリーン、40%をログに割り当てる */ | |
121 | + /* 指定高さ比率をスクリーン、残りをログに割り当てる */ | |
125 | 122 | if (FALSE == bSuccess) |
126 | 123 | { |
127 | 124 | /* 仮のスクリーン高さを算出 */ |
@@ -193,7 +190,7 @@ static BOOL OnCreateFont(HWND hWnd) | ||
193 | 190 | } |
194 | 191 | |
195 | 192 | /* ゼロクリア */ |
196 | - ZeroMemory(&lf, sizeof(lf)); | |
193 | + memset(&lf, 0, sizeof(lf)); | |
197 | 194 | |
198 | 195 | /* フォント高さ */ |
199 | 196 | lf.lfHeight = -MulDiv(WINDOW_FONT_POINT, GetDeviceCaps(hDC, LOGPIXELSY), 72); |
@@ -350,14 +347,14 @@ static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs) | ||
350 | 347 | return FALSE; |
351 | 348 | } |
352 | 349 | |
353 | - /* リストボックスを作成 */ | |
350 | + /* Windowsログを作成 */ | |
354 | 351 | x = g_rcChilds.rcLogWin.left; |
355 | 352 | y = g_rcChilds.rcLogWin.top; |
356 | 353 | width = g_rcChilds.rcLogWin.right - g_rcChilds.rcLogWin.left; |
357 | 354 | assert(0 <= width); |
358 | 355 | height = g_rcChilds.rcLogWin.bottom - g_rcChilds.rcLogWin.top; |
359 | 356 | assert(0 <= height); |
360 | - bResult = listbox_init(hWnd, x, y, width, height); | |
357 | + bResult = logwin_init(hWnd, x, y, width, height); | |
361 | 358 | assert(FALSE != bResult); |
362 | 359 | if (FALSE == bResult) |
363 | 360 | { |
@@ -421,14 +418,16 @@ static void OnSize(HWND hWnd) | ||
421 | 418 | assert(0 <= height); |
422 | 419 | monitor_resize(x, y, width, height); |
423 | 420 | |
424 | - /* リストボックスのリサイズを要求 */ | |
421 | + /* Windowsログのリサイズを要求 */ | |
425 | 422 | x = g_rcChilds.rcLogWin.left; |
426 | 423 | y = g_rcChilds.rcLogWin.top; |
427 | 424 | width = g_rcChilds.rcLogWin.right - g_rcChilds.rcLogWin.left; |
428 | 425 | assert(0 <= width); |
429 | 426 | height = g_rcChilds.rcLogWin.bottom - g_rcChilds.rcLogWin.top; |
430 | 427 | assert(0 <= height); |
431 | - listbox_resize(x, y, width, height); | |
428 | + logwin_resize(x, y, width, height); | |
429 | + | |
430 | + logwin_printf("リサイズ width=%d height=%d", width, height); | |
432 | 431 | } |
433 | 432 | |
434 | 433 | /* |
@@ -492,7 +491,7 @@ static BOOL RegisterWindowClass(void) | ||
492 | 491 | WNDCLASSEX wcex; |
493 | 492 | |
494 | 493 | /* ゼロクリア */ |
495 | - ZeroMemory(&wcex, sizeof(wcex)); | |
494 | + memset(&wcex, 0, sizeof(wcex)); | |
496 | 495 | |
497 | 496 | /* 構造体サイズ */ |
498 | 497 | wcex.cbSize = sizeof(wcex); |