• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

UART通信を用いた組み込みデバッグ用途向けメモリモニタ


Commit MetaInfo

Revisão8d5b11694e92ef11e0b1b3e8f602b236557e91f0 (tree)
Hora2018-05-09 22:46:51
AutorYasushi Tanaka <tanaka_yasushi2008@yaho...>
CommiterYasushi Tanaka

Mensagem de Log

ユーザ・アプリケーションを追加

Mudança Sumário

Diff

--- a/DebugMonitor/DebugMonitor.vcxproj
+++ b/DebugMonitor/DebugMonitor.vcxproj
@@ -53,7 +53,7 @@
5353 <Optimization>Disabled</Optimization>
5454 <PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
5555 <SDLCheck>true</SDLCheck>
56- <AdditionalIncludeDirectories>$(ProjectDir)src\framework;$(ProjectDir)src\comm;$(ProjectDir)src\user;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
56+ <AdditionalIncludeDirectories>$(ProjectDir)src\framework;$(ProjectDir)src\comm;$(ProjectDir)src\app;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
5757 </ClCompile>
5858 <Link>
5959 <SubSystem>Windows</SubSystem>
@@ -80,6 +80,7 @@
8080 </Link>
8181 </ItemDefinitionGroup>
8282 <ItemGroup>
83+ <ClInclude Include="src\app\app.h" />
8384 <ClInclude Include="src\comm\comm.h" />
8485 <ClInclude Include="src\framework\bdlist.h" />
8586 <ClInclude Include="src\framework\cons.h" />
@@ -90,6 +91,7 @@
9091 <ClInclude Include="src\framework\winmain.h" />
9192 </ItemGroup>
9293 <ItemGroup>
94+ <ClCompile Include="src\app\app.c" />
9395 <ClCompile Include="src\comm\comm.c" />
9496 <ClCompile Include="src\framework\bdlist.c" />
9597 <ClCompile Include="src\framework\cons.c" />
--- a/DebugMonitor/DebugMonitor.vcxproj.filters
+++ b/DebugMonitor/DebugMonitor.vcxproj.filters
@@ -22,6 +22,15 @@
2222 <Filter Include="ヘッダー ファイル\comm">
2323 <UniqueIdentifier>{dcfe82fa-6677-4e75-a349-855d11d4cd3e}</UniqueIdentifier>
2424 </Filter>
25+ <Filter Include="ヘッダー ファイル\app">
26+ <UniqueIdentifier>{7bc461d1-4990-4c9a-ae0e-8c40eec7bb6d}</UniqueIdentifier>
27+ </Filter>
28+ <Filter Include="ソース ファイル\comm">
29+ <UniqueIdentifier>{8cb68c7d-dbc1-4cc4-b781-83399b23163e}</UniqueIdentifier>
30+ </Filter>
31+ <Filter Include="ソース ファイル\app">
32+ <UniqueIdentifier>{7f74ed15-8047-46a8-b2bf-3cd283e0275c}</UniqueIdentifier>
33+ </Filter>
2534 </ItemGroup>
2635 <ItemGroup>
2736 <ClInclude Include="src\framework\screen.h">
@@ -48,6 +57,9 @@
4857 <ClInclude Include="src\framework\logwin.h">
4958 <Filter>ヘッダー ファイル\framework</Filter>
5059 </ClInclude>
60+ <ClInclude Include="src\app\app.h">
61+ <Filter>ヘッダー ファイル\app</Filter>
62+ </ClInclude>
5163 </ItemGroup>
5264 <ItemGroup>
5365 <ClCompile Include="src\framework\winmain.c">
@@ -62,14 +74,17 @@
6274 <ClCompile Include="src\framework\bdlist.c">
6375 <Filter>ソース ファイル\framework</Filter>
6476 </ClCompile>
65- <ClCompile Include="src\comm\comm.c">
66- <Filter>ヘッダー ファイル\comm</Filter>
67- </ClCompile>
6877 <ClCompile Include="src\framework\cons.c">
6978 <Filter>ソース ファイル\framework</Filter>
7079 </ClCompile>
7180 <ClCompile Include="src\framework\logwin.c">
7281 <Filter>ソース ファイル\framework</Filter>
7382 </ClCompile>
83+ <ClCompile Include="src\comm\comm.c">
84+ <Filter>ソース ファイル\comm</Filter>
85+ </ClCompile>
86+ <ClCompile Include="src\app\app.c">
87+ <Filter>ソース ファイル\app</Filter>
88+ </ClCompile>
7489 </ItemGroup>
7590 </Project>
\ No newline at end of file
--- /dev/null
+++ b/DebugMonitor/src/app/app.c
@@ -0,0 +1,28 @@
1+/*
2+ * Debug Monitor Framework
3+ * Author: Yasushi Tanaka
4+ *
5+ * [ アプリケーション ]
6+ */
7+
8+#include "header.h"
9+#include "winmain.h"
10+#include "logwin.h"
11+#include "comm.h"
12+#include "app.h"
13+
14+/*
15+ * アプリケーション
16+ * 実行
17+ */
18+void app_run(void)
19+{
20+ UINT count;
21+
22+ count = 0;
23+
24+ while (TRUE == do_events(1000))
25+ {
26+ comm_enum();
27+ }
28+}
--- /dev/null
+++ b/DebugMonitor/src/app/app.h
@@ -0,0 +1,15 @@
1+/*
2+ * Debug Monitor Framework
3+ * Author: Yasushi Tanaka
4+ *
5+ * [ アプリケーション ]
6+ */
7+
8+#pragma once
9+
10+/*
11+ * グローバル関数
12+ */
13+
14+/* アプリケーション実行 */
15+void app_run(void);
--- a/DebugMonitor/src/comm/comm.c
+++ b/DebugMonitor/src/comm/comm.c
@@ -6,6 +6,7 @@
66 */
77
88 #include "header.h"
9+#include "logwin.h"
910 #include "comm.h"
1011
1112 /*
@@ -15,6 +16,9 @@
1516 /* 最初の通信ポート */
1617 static COMM_PORT *g_comm_port_head;
1718
19+/* 検出された通信ポート数 */
20+static UINT g_comm_port_num;
21+
1822 /*
1923 * 通信ポート
2024 * ポートの初期化
@@ -403,12 +407,73 @@ static void comm_allport_destroy(void)
403407
404408 /*
405409 * 通信ポート
410+ * すべての通信ポートのオープンチェック
411+ */
412+static BOOL comm_allport_isopen(void)
413+{
414+ COMM_PORT *port;
415+
416+ /* 初期化 */
417+ port = g_comm_port_head;
418+
419+ /* ポートが有効である限り回る */
420+ while (NULL != port)
421+ {
422+ /* ポートがオープンされていればTRUEを返す */
423+ if (INVALID_HANDLE_VALUE != port->file_handle)
424+ {
425+ /* オープンされている */
426+ return TRUE;
427+ }
428+
429+ /* 次へ */
430+ port = (COMM_PORT*)port->bdlist.bdlist_next;
431+ }
432+
433+ /* すべてオープンされていない */
434+ return FALSE;
435+}
436+
437+/*
438+ * 通信ポート
439+ * すべての通信ポートの個数取得
440+ */
441+static UINT comm_allport_getnum(void)
442+{
443+ COMM_PORT *port;
444+ UINT num;
445+
446+ /* 個数を初期化 */
447+ num = 0;
448+
449+ /* 初期化 */
450+ port = g_comm_port_head;
451+
452+ /* ポートが有効である限り回る */
453+ while (NULL != port)
454+ {
455+ /* 個数を+1 */
456+ num++;
457+
458+ /* 次へ */
459+ port = (COMM_PORT*)port->bdlist.bdlist_next;
460+ }
461+
462+ /* 個数を返す */
463+ return num;
464+}
465+
466+/*
467+ * 通信ポート
406468 * 初期化
407469 */
408470 void comm_init(void)
409471 {
410472 /* 通信ポートなし */
411473 g_comm_port_head = NULL;
474+
475+ /* ポート数を最大値に初期化 */
476+ g_comm_port_num = 0xFFFFFFFF;
412477 }
413478
414479 /*
@@ -431,6 +496,15 @@ void comm_enum(void)
431496 GUID guid;
432497 DWORD required;
433498 HDEVINFO hDevInfo;
499+ UINT num;
500+ COMM_PORT *port;
501+
502+ /* ポートがオープンされていれば何もしない */
503+ result = comm_allport_isopen();
504+ if (FALSE != result)
505+ {
506+ return;
507+ }
434508
435509 /* すべての通信ポートの破棄 */
436510 comm_allport_destroy();
@@ -458,4 +532,33 @@ void comm_enum(void)
458532
459533 /* デバイス情報セットの使用を終了 */
460534 SetupDiDestroyDeviceInfoList(hDevInfo);
535+
536+ /* 個数が変更ない場合は何もしない */
537+ num = comm_allport_getnum();
538+ if (g_comm_port_num == num)
539+ {
540+ return;
541+ }
542+
543+ /* ポート個数を更新 */
544+ g_comm_port_num = num;
545+
546+ /* ポートがない場合 */
547+ if (0 == num)
548+ {
549+ logwin_printf("COMポートが見つかりません");
550+ return;
551+ }
552+ else
553+ {
554+ logwin_printf("COMポートが%uポート見つかりました", num);
555+
556+ /* ポートループ */
557+ port = g_comm_port_head;
558+ while (NULL != port)
559+ {
560+ logwin_printfw(port->friendly_name);
561+ port = (COMM_PORT*)port->bdlist.bdlist_next;
562+ }
563+ }
461564 }
--- a/DebugMonitor/src/framework/logwin.c
+++ b/DebugMonitor/src/framework/logwin.c
@@ -203,7 +203,7 @@ void logwin_resize(int x, int y, int width, int height)
203203
204204 /*
205205 * Windowsログ
206- * ログ出力
206+ * ログ出力(char)
207207 */
208208 void logwin_out(const char *log)
209209 {
@@ -269,7 +269,7 @@ void logwin_out(const char *log)
269269
270270 /*
271271 * Windowsログ
272- * 書式つき出力
272+ * 書式つき出力(char)
273273 */
274274 void logwin_printf(const char *format, ...)
275275 {
@@ -287,3 +287,41 @@ void logwin_printf(const char *format, ...)
287287 /* ログ出力 */
288288 logwin_out(multibyte);
289289 }
290+
291+/*
292+ * Windowsログ
293+ * 書式つき出力(wchar_t)
294+ */
295+void logwin_printfw(const wchar_t *format, ...)
296+{
297+ wchar_t wide[0x400];
298+ char multibyte[0x400];
299+ va_list ap;
300+ int result;
301+
302+ assert(NULL != format);
303+
304+ /* フォーマット */
305+ va_start(ap, format);
306+ vswprintf_s(wide, _countof(wide), format, ap);
307+ wide[_countof(wide) - 1] = '\0';
308+ va_end(ap);
309+
310+ /* マルチバイト文字へ変換 */
311+ result = WideCharToMultiByte(
312+ CP_ACP,
313+ 0,
314+ wide,
315+ -1,
316+ multibyte,
317+ _countof(multibyte),
318+ NULL,
319+ NULL);
320+ if (0 == result)
321+ {
322+ return;
323+ }
324+
325+ /* ログ出力 */
326+ logwin_out(multibyte);
327+}
--- a/DebugMonitor/src/framework/logwin.h
+++ b/DebugMonitor/src/framework/logwin.h
@@ -17,8 +17,11 @@ BOOL logwin_init(HWND parent, int x, int y, int width, int height);
1717 /* リサイズ */
1818 void logwin_resize(int x, int y, int width, int height);
1919
20-/* ログ追加 */
20+/* ログ追加(char) */
2121 void logwin_out(const char *log);
2222
23-/* 書式つき出力 */
23+/* 書式つき出力(char) */
2424 void logwin_printf(const char *format, ...);
25+
26+/* 書式つき出力(wchar_t) */
27+void logwin_printfw(const wchar_t *format, ...);
--- a/DebugMonitor/src/framework/winmain.c
+++ b/DebugMonitor/src/framework/winmain.c
@@ -11,6 +11,7 @@
1111 #include "monitor.h"
1212 #include "logwin.h"
1313 #include "comm.h"
14+#include "app.h"
1415 #include "winmain.h"
1516
1617 /*
@@ -54,6 +55,15 @@ TEXTMETRIC g_tm;
5455 /* フォントの高さ(マージン含む) */
5556 LONG g_tmAllHeight;
5657
58+/* WM_USERメッセージをポストした */
59+BOOL g_bUserPost;
60+
61+/* WM_CLOSEメッセージを受けた */
62+BOOL g_bCloseReq;
63+
64+/* ユーザアプリケーションが終了した */
65+BOOL g_bUserQuit;
66+
5767 /*
5868 * 構造体定義
5969 */
@@ -306,7 +316,6 @@ static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs)
306316
307317 /* ポートを初期化 */
308318 comm_init();
309- comm_enum();
310319
311320 /* チャイルドウィンドウのサイズを決定 */
312321 CalcChilldRects(hWnd);
@@ -426,8 +435,68 @@ static void OnSize(HWND hWnd)
426435 height = g_rcChilds.rcLogWin.bottom - g_rcChilds.rcLogWin.top;
427436 assert(0 <= height);
428437 logwin_resize(x, y, width, height);
438+}
439+
440+/*
441+ * WinMain
442+ * WM_ACTIVATEメッセージハンドラ
443+ */
444+static void OnActivate(HWND hWnd)
445+{
446+ assert(NULL != hWnd);
447+
448+ /* WM_USERをポストしていない場合 */
449+ if (FALSE == g_bUserPost)
450+ {
451+ /* WM_USERポスト済みとして */
452+ g_bUserPost = TRUE;
429453
430- logwin_printf("リサイズ width=%d height=%d", width, height);
454+ /* WM_USERをポストする */
455+ PostMessage(hWnd, WM_USER, 0, 0);
456+ }
457+}
458+
459+/*
460+ * WinMain
461+ * WM_CLOSEメッセージハンドラ
462+ */
463+static void OnClose(HWND hWnd)
464+{
465+ assert(NULL != hWnd);
466+
467+ /* クローズ要求有り */
468+ g_bCloseReq = TRUE;
469+
470+ /* アプリケーションが終了していれば、DestroyWindowを即座に発行 */
471+ if (FALSE != g_bUserQuit)
472+ {
473+ DestroyWindow(hWnd);
474+ }
475+}
476+
477+/*
478+ * WinMain
479+ * WM_USERメッセージハンドラ
480+ */
481+static void OnUser(HWND hWnd)
482+{
483+ assert(NULL != hWnd);
484+
485+ /* ユーザアプリは終了していない */
486+ g_bUserQuit = FALSE;
487+
488+ /* アプリケーション呼び出し */
489+ app_run();
490+
491+ /* ユーザアプリは終了した */
492+ logwin_printf("アプリケーションは終了しました");
493+ g_bUserQuit = TRUE;
494+
495+ /* 終了要求が出ていれば、ここでDestroyWindowを発行 */
496+ if (FALSE != g_bCloseReq)
497+ {
498+ DestroyWindow(hWnd);
499+ }
431500 }
432501
433502 /*
@@ -473,6 +542,24 @@ static LRESULT CALLBACK FrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
473542 OnSize(hWnd);
474543 return 0;
475544
545+ /* ウィンドウが表示された */
546+ case WM_ACTIVATE:
547+ /* ハンドラを呼び出す */
548+ OnActivate(hWnd);
549+ return 0;
550+
551+ /* ウィンドウが終了要求された */
552+ case WM_CLOSE:
553+ /* ハンドラを呼び出す */
554+ OnClose(hWnd);
555+ return 0;
556+
557+ /* ユーザメッセージ */
558+ case WM_USER:
559+ /* ハンドラを呼び出す */
560+ OnUser(hWnd);
561+ return 0;
562+
476563 /* その他 */
477564 default:
478565 break;
@@ -556,6 +643,9 @@ static BOOL InitInstance(HINSTANCE hInstance)
556643 /* static変数を初期化 */
557644 g_hFrameWnd = NULL;
558645 memset(&g_rcChilds, 0, sizeof(g_rcChilds));
646+ g_bUserPost = FALSE;
647+ g_bCloseReq = FALSE;
648+ g_bUserQuit = FALSE;
559649
560650 /* マルチメディアタイマの最小分解能を設定 */
561651 mmResult = timeBeginPeriod(1);
@@ -621,35 +711,38 @@ static void ExitInstance(void)
621711
622712 /*
623713 * WinMain
714+ * メッセージポンプ
715+ * ※アプリケーションを終了すべき場合はFALSEを返す
624716 */
625-int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
717+BOOL do_events(DWORD dwTimeOut)
626718 {
627719 MSG msg;
720+ DWORD dwTime;
721+ DWORD dwDiff;
628722
629- UNREFERENCED_PARAMETER(hPrevInstance);
630- UNREFERENCED_PARAMETER(pCmdLine);
723+ /* 現在の時間を記憶 */
724+ dwTime = timeGetTime();
631725
632- /* インスタンスの初期化 */
633- if (InitInstance(hInstance) == FALSE)
726+ /* ループ */
727+ for (;;)
634728 {
635- return 0;
636- }
729+ /* 時間差分を得る */
730+ dwDiff = (DWORD)(timeGetTime() - dwTime);
637731
638- /* ウィンドウの表示と更新 */
639- ShowWindow(g_hFrameWnd, nCmdShow);
640- UpdateWindow(g_hFrameWnd);
732+ /* 時間差分を超えたら抜ける */
733+ if (dwDiff > dwTimeOut)
734+ {
735+ break;
736+ }
641737
642- /* メッセージループ(メッセージポンプ対応) */
643- for (;;)
644- {
645- /* メッセージがキューにあるか */
738+ /* メッセージが到着しているか */
646739 if (TRUE == PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
647740 {
648741 /* メッセージをキューから取得 */
649742 if (GetMessage(&msg, NULL, 0, 0) <= 0)
650743 {
651- /* WM_QUITなら終了 */
652- break;
744+ /* WM_QUITならFALSEを返す */
745+ return FALSE;
653746 }
654747
655748 /* メッセージをディスパッチ */
@@ -658,14 +751,59 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
658751 }
659752 else
660753 {
661- /* アイドル処理 */
754+ /* アイドル処理*/
662755 screen_idle();
663756 cons_idle();
664757 monitor_idle();
665758
666- /* 必ずSleepを入れる */
759+ /* スリープ */
667760 Sleep(10);
668761 }
762+
763+ /* WM_CLOSEが到着していればFALSEを返す */
764+ if (FALSE != g_bCloseReq)
765+ {
766+ return FALSE;
767+ }
768+ }
769+
770+ /* アプリケーションを継続できるので、TRUEを返す */
771+ return TRUE;
772+}
773+
774+/*
775+ * WinMain
776+ */
777+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
778+{
779+ MSG msg;
780+
781+ UNREFERENCED_PARAMETER(hPrevInstance);
782+ UNREFERENCED_PARAMETER(pCmdLine);
783+
784+ /* インスタンスの初期化 */
785+ if (InitInstance(hInstance) == FALSE)
786+ {
787+ return 0;
788+ }
789+
790+ /* ウィンドウの表示と更新 */
791+ ShowWindow(g_hFrameWnd, nCmdShow);
792+ UpdateWindow(g_hFrameWnd);
793+
794+ /* メッセージループ */
795+ for (;;)
796+ {
797+ /* メッセージをキューから取得 */
798+ if (GetMessage(&msg, NULL, 0, 0) <= 0)
799+ {
800+ /* WM_QUITなら終了 */
801+ break;
802+ }
803+
804+ /* メッセージをディスパッチ */
805+ TranslateMessage(&msg);
806+ DispatchMessage(&msg);
669807 }
670808
671809 /* インスタンスの終了 */
--- a/DebugMonitor/src/framework/winmain.h
+++ b/DebugMonitor/src/framework/winmain.h
@@ -22,3 +22,10 @@ extern TEXTMETRIC g_tm;
2222
2323 /* フォントの高さ(マージン含む) */
2424 extern LONG g_tmAllHeight;
25+
26+/*
27+ * グローバル関数
28+ */
29+
30+/* イベント処理(FALSEを返すと脱出要求) */
31+BOOL do_events(DWORD dwTimeOut);