Skip to content

Commit db58efa

Browse files
committed
move TP function to GG_for_Arduino, add gg_con_RegistMemCMD()
1 parent af727a7 commit db58efa

File tree

13 files changed

+197
-145
lines changed

13 files changed

+197
-145
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ You can implement a command line interface on your Arduino and add your own comm
1818
### Pre-registered commands
1919

2020
* `help` help
21+
22+
### Prepared command (gg_con_RegistMemCMD())
23+
2124
* `md` mem dump
2225
* `ms` mem set
2326
* `mf` mem fill
27+
28+
See example below.
29+
30+
* [GG_console.ino](examples/GG_console/GG_console.ino).
31+
32+
### Prepared command (gg_tp_start())
33+
2434
* `tp` TP(test point) select
2535

2636
### How to add your own command
@@ -60,15 +70,11 @@ All functions do not use the heap.
6070
|--|---|
6171
|***GG_for_Arduino.h***||
6272
|int gg_start(const char \*title)|Start processing GG for Arduino|
63-
|int gg_tp1_no|Arduino output pin number for TP1. Set before gg_start() if necessary|
64-
|int gg_tp2_no|Arduino output pin number for TP2. Set before gg_start() if necessary|
6573
|long gg_con_baud|baud rate. Set before gg_start() if necessary|
66-
|***gg_base.h***||
74+
|int gg_tp_start(int tp1_no, int tp2_no)|TP function start (output pin initialization and command registration)|
6775
|GG_TP_ON(number)|Turn on the TP status number|
6876
|GG_TP_OFF(number)|Turn off the TP status number|
6977
|***gg_uty.h***||
70-
|GG_TP_ON(number)|Turn on the TP status number|
71-
|GG_TP_OFF(number)|Turn off the TP status number|
7278
|int gg_GetC(void)|1 character input (-1 = no input)|
7379
|int gg_PutC(int c)|1 character output|
7480
|int gg_PutS(const char \*s)|String output|
@@ -117,4 +123,4 @@ All functions do not use the heap.
117123
|int gg_con_CmdN(void)|Number of command registrations|
118124
|int gg_con_CmdHelp(char \*cmd)|Help for the specified command|
119125
|int gg_con_CmdHelpAll(void)|Display command list|
120-
|int gg_con_RegistCMD(void)|Registration of basic commands to be pre-registered|
126+
|int gg_con_RegistMemCMD(void)|Registration of memory commands|

README_J.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ Arduinoでコマンドラインインターフェース(コンソールの基
1313
* エコーバックはGGが出す(端末でキーを打てば打ったキーが表示されます)
1414
* CR(\r)またはLF(\n)でコマンド実行
1515

16-
### 定義済みコマンド
16+
### 登録済みコマンド
1717

1818
* `help` コマンド一覧の表示
19+
20+
### gg_con_RegistMemCMD()で追加登録されるコマンド
21+
1922
* `md` メモリダンプ
2023
* `ms` メモリセット
2124
* `mf` メモリフィル(ブロックセット)
25+
26+
下記の例をご覧ください。
27+
28+
* [GG_console.ino](examples/GG_console/GG_console.ino).
29+
30+
### gg_tp_start()で追加登録されるコマンド
31+
2232
* `tp` TP(テストポイント)の状態番号の表示と変更
2333

2434
### コマンドの追加方法
@@ -59,13 +69,15 @@ TP(テストポイント)機能を使ってプログラムのタイミング
5969
|--|---|
6070
|***GG_for_Arduino.h***||
6171
|int gg_start(const char \*title)|GG for Arduino の開始|
62-
|int gg_tp1_no|TP1のArduinoピン番号. TP1を使うならgg_start()の前にセット|
63-
|int gg_tp2_no|TP2のArduinoピン番号. TP2を使うならgg_start()の前にセット|
6472
|long gg_con_baud|ボーレート. 115200から変更するならgg_start()の前にセット|
65-
|***gg_base.h***||
73+
|int gg_tp_start(int tp1_no, int tp2_no)|TP機能スタート(出力ピン初期化とコマンド登録)|
6674
|GG_TP_ON(number)|TP状態番号をON|
6775
|GG_TP_OFF(number)|TP状態番号をOFF|
6876
|***gg_uty.h***||
77+
|int gg_GetC(void)|1 character input (-1 = no input)|
78+
|int gg_PutC(int c)|1 character output|
79+
|int gg_PutS(const char \*s)|String output|
80+
|***gg_uty.h***||
6981
|int gg_GetC(void)|1文字入力 (-1 = 入力なし)|
7082
|int gg_PutC(int c)|1文字出力|
7183
|int gg_PutS(const char \*s)|文字列出力|
@@ -114,4 +126,4 @@ TP(テストポイント)機能を使ってプログラムのタイミング
114126
|int gg_con_CmdN(void)|コマンド登録数|
115127
|int gg_con_CmdHelp(char \*cmd)|cmdのヘルプ表示|
116128
|int gg_con_CmdHelpAll(void)|コマンド一覧の表示|
117-
|int gg_con_RegistCMD(void)|定義済みコマンドの登録(内部で使用)|
129+
|int gg_con_RegistMemCMD(void)|メモリ系コマンド登録|

examples/GG_console/GG_console.ino

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@
44
GG for Arduino ** Simple console demo
55
Arduino standard serial (115200bps / 8bit length / non-parity)
66
Enter the help command to display the command list.
7+
8+
9+
Example
10+
11+
** GG **
12+
>help
13+
help [cmd..] : command help
14+
-- memory command --
15+
md [addr [alen]] : mem dump
16+
ms addr data.. : mem set
17+
mf addr alen data : mem fill
18+
>md 0x0000 20
19+
00000000 00 00 D8 21 04 00 00 00 00 00 00 00 06 03 F2 02 ...!.... ........
20+
00000010 D8 21 00 00 .!..
21+
>
22+
723
*/
824

925
void setup() {
1026
gg_start("** GG **\n>"); // Start processing GG for Arduino
27+
gg_con_RegistMemCMD(); // register memory command
1128
}
1229

1330
void loop() {

examples/GG_console_cmd/GG_console_cmd.ino

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
1616
** GG **
1717
>help
18-
-- GG standard command --
1918
help [cmd..] : command help
20-
md [addr [alen]] : mem dump
21-
ms addr data.. : mem set
22-
mf addr alen data : mem fill
23-
tp [#1 [#2]] : TP(test pin) set
24-
-- Example of registering a console command --
25-
test1 [...] : Displays the arguments when the command is executed
26-
>test1 1 22 333 0xabcd 100+20+0x1000
19+
-- Example of original command registration --
20+
test1 [...] : Display command line arguments when executing this command
21+
>test1 1 22 333 0xabcd 100+20+0x1000
2722
argc=6
2823
argv[ 0] test1 (0x00000000,0)
2924
argv[ 1] 1 (0x00000001,1)

examples/GG_printf/GG_printf.ino

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
GG for Arduino ** Printf() demo
55
Arduino standard serial (115200bps / 8bit length / non-parity)
66
No command line interface
7+
8+
9+
Example
10+
11+
** GG start
12+
[setup] millis()= 0
13+
[loop] millis()= 0
14+
c= 1=0x01=0b00000001
15+
delay(1000)
16+
[loop] millis()= 1002
17+
c= 2=0x02=0b00000010
18+
delay(1000)
19+
720
*/
821

922
void setup() {

examples/GG_tp/GG_tp.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,29 @@
1313
You can specify which status number to output to the output pin with the "tp" command.
1414
>tp 10 20 (TP1 output:status number 10, TP2 output:status number 20)
1515
16+
17+
Example
18+
19+
** GG **
20+
>help
21+
help [cmd..] : command help
22+
-- TP command --
23+
tp [#1 [#2]] : TP(test point) select
24+
>tp
25+
<TP status number(The specified status number appears in TP)>
26+
TP1 = -1 (-1=do nothing)
27+
TP2 = -1 (-1=do nothing)
28+
>tp 10 20
29+
<TP status number(The specified status number appears in TP)>
30+
TP1 = 10 (-1=do nothing)
31+
TP2 = 20 (-1=do nothing)
32+
>
33+
1634
*/
1735

1836
void setup() {
19-
gg_tp1_no = 2; // Arduino pin number for TP1
20-
gg_tp2_no = 3; // Arduino pin number for TP2
2137
gg_start("** GG **\n>"); // Start processing GG for Arduino
38+
gg_tp_start(2, 3); // regiter tp command, setup TP1 and TP2 (Arduino pin number)
2239
}
2340

2441
void loop() {

src/ggdef.h renamed to src/GG_HW_def.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*
2-
ggdef.h GGツール 個別定義部
2+
GG_HW_def.h GGツール HW定義(HW環境依存部)
33
44
2022.01.08 M.Kogan 初版開発開始
5+
2022.06.05 M.Kogan ファイル名変更,TP分離
56
67
***********************************
78
*** Arduino専用 ***
89
***********************************
910
1011
*/
1112

12-
#ifndef __GGDEF_H__
13-
#define __GGDEF_H__
13+
#ifndef __GG_HW_DEF_H__
14+
#define __GG_HW_DEF_H__
1415

1516
//------------------
1617
// 割込み禁止制御
@@ -46,20 +47,4 @@ typedef unsigned long long uint64_t;
4647

4748
#define NULL (0)
4849

49-
50-
//------------------
51-
// テストポイント(TP機能)設定
52-
//------------------
53-
// 以下のテストポイント(TP機能)設定が必要
54-
// GG_TP_NOCODE テストポイント(TP機能)コードの非生成(なければコード生成する)
55-
// GG_TP1_ON/OFF TP1(出力ピン1)制御
56-
// GG_TP2_ON/OFF TP2(出力ピン2)制御
57-
58-
extern void gg_tp1_set(int flag); // TP1(出力ピン1)出力(GG_for_Arduino.cpp)
59-
extern void gg_tp2_set(int flag); // TP2(出力ピン2)出力(GG_for_Arduino.cpp)
60-
#define GG_TP1_ON() (gg_tp1_set(1)) // TP1(出力ピン1)をON
61-
#define GG_TP1_OFF() (gg_tp1_set(0)) // TP1(出力ピン1)をOFF
62-
#define GG_TP2_ON() (gg_tp2_set(1)) // TP2(出力ピン2)をON
63-
#define GG_TP2_OFF() (gg_tp2_set(0)) // TP2(出力ピン2)をOFF
64-
65-
#endif // __GG_USERDEF_H__
50+
#endif // __GG_HW_DEF_H__

src/GG_for_Arduino.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "Arduino.h"
1010

1111
int gg_DI_count; // 割込み禁止ネスト数(0=割込み許可中)
12-
int gg_tp1_no = -1; // TP1出力ピン番号(-1=なし)
13-
int gg_tp2_no = -1; // TP2出力ピン番号(-1=なし)
1412
long gg_con_baud = 115200; // コンソール用シリアル(Serial)のボーレート(-1=gg_start()で初期化しない)
1513

1614
static int std_putc_sub(int c)
@@ -30,9 +28,6 @@ static int std_getc()
3028

3129
int gg_start(const char *title) // Arduino用GGの処理開始
3230
{
33-
// TP出力の初期化(セットされてれば出力に初期化)
34-
if (gg_tp1_no>=0) pinMode(gg_tp1_no, OUTPUT);
35-
if (gg_tp2_no>=0) pinMode(gg_tp2_no, OUTPUT);
3631

3732
// コンソール用シリアルのボーレート設定(負数であればセットしない)
3833
if (gg_con_baud>0) {
@@ -42,9 +37,13 @@ int gg_start(const char *title) // Arduino用GGの処理開始
4237
}
4338

4439
// GGツールベース初期化
45-
ggbase_init(); // GGツール初期化
46-
gg_con_MonInit(); // GGモニタ初期化
47-
gg_con_RegistCMD(); // 標準コマンド登録
40+
gg_con_MonInit(); // GGモニタ初期化
41+
gg_con_RegistHelpCMD(); // helpコマンド登録(最初はこれだけ)
42+
43+
// tp1/tp2番号指定あればTP機能スタート(旧v1.0.x対応) 2022.06.05 M.Kogan
44+
if ((gg_tp1_no>=0)||(gg_tp2_no>=0)) {
45+
gg_tp_start(gg_tp1_no, gg_tp2_no); // TP機能スタート(出力ピン初期化とコマンド登録)
46+
}
4847

4948
// デバッグモニタ開始(タイトル表示) 旧:gg_con_MonStart()
5049
if (title) gg_PutS(title);
@@ -55,6 +54,12 @@ int gg_start(const char *title) // Arduino用GGの処理開始
5554
//
5655
// テストポイント(TP機能)
5756
//
57+
int gg_tp1_sel = -1; // TP1(出力ピン1)状態番号変数
58+
int gg_tp2_sel = -1; // TP2(出力ピン2)状態番号変数
59+
60+
int gg_tp1_no = -1; // TP1出力ピン番号(-1=なし) Arduinoピン番号
61+
int gg_tp2_no = -1; // TP2出力ピン番号(-1=なし) Arduinoピン番号
62+
5863
void gg_tp1_set(int flag) // TP1(出力ピン1)出力(GG_for_Arduino.cpp)
5964
{
6065
if (gg_tp1_no>=0) {
@@ -67,3 +72,31 @@ void gg_tp2_set(int flag) // TP2(出力ピン2)出力(GG_for_Arduino.cpp)
6772
digitalWrite(gg_tp2_no, flag);
6873
}
6974
}
75+
76+
static int C_tp(int argc, char**argv) // TP設定
77+
{
78+
if (argc<=4) {
79+
if (argc>1) GG_TP1 = gg_asc2int(argv[1]);
80+
if (argc>2) GG_TP2 = gg_asc2int(argv[2]);
81+
gg_printf("<TP status number(The specified status number appears in TP)>\n");
82+
gg_printf("TP1 = %3d (-1=do nothing)\n", GG_TP1);
83+
gg_printf("TP2 = %3d (-1=do nothing)\n", GG_TP2);
84+
} else {
85+
gg_con_CmdHelp(argv[0]);
86+
}
87+
return 0;
88+
}
89+
90+
int gg_tp_start(int tp1_no, int tp2_no) // TP機能スタート(出力ピン初期化とコマンド登録)
91+
{
92+
// TP出力の初期化(セットされてれば出力に初期化)
93+
gg_tp1_no = tp1_no;
94+
gg_tp2_no = tp2_no;
95+
if (gg_tp1_no>=0) pinMode(gg_tp1_no, OUTPUT);
96+
if (gg_tp2_no>=0) pinMode(gg_tp2_no, OUTPUT);
97+
98+
// コマンド登録
99+
GG_CON_CMDMRK("-- TP command --"); // 区切り行(helpでコマンド一覧のときに表示)
100+
GG_CON_CMDADD(C_tp, "tp", "[#1 [#2]]", "TP(test point) select" ); //
101+
return 0;
102+
}

src/GG_for_Arduino.h

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,55 @@
1111
#include "ggbase.h"
1212

1313
// gg_start()時の変更可能パラメータ(事前にデフォルト値が入っている)(Arduino専用)
14-
extern int gg_tp1_no; // TP1出力ピン番号(-1=なし)
15-
extern int gg_tp2_no; // TP2出力ピン番号(-1=なし)
1614
extern long gg_con_baud; // コンソール用シリアル(Serial)のボーレート(負数ならgg_start()で初期化しない)
1715

1816
int gg_start(const char *title); // Arduino用GGの処理開始
1917

18+
//------------------
19+
// テストポイント(TP機能)
20+
//------------------
21+
// 以下のテストポイント(TP機能)設定が必要
22+
// GG_TP_NOCODE テストポイント(TP機能)コードの非生成(なければコード生成する)
23+
// GG_TP1_ON/OFF TP1(出力ピン1)制御
24+
// GG_TP2_ON/OFF TP2(出力ピン2)制御
25+
26+
extern void gg_tp1_set(int flag); // TP1(出力ピン1)出力(GG_for_Arduino.cpp)
27+
extern void gg_tp2_set(int flag); // TP2(出力ピン2)出力(GG_for_Arduino.cpp)
28+
#define GG_TP1_ON() (gg_tp1_set(1)) // TP1(出力ピン1)をON
29+
#define GG_TP1_OFF() (gg_tp1_set(0)) // TP1(出力ピン1)をOFF
30+
#define GG_TP2_ON() (gg_tp2_set(1)) // TP2(出力ピン2)をON
31+
#define GG_TP2_OFF() (gg_tp2_set(0)) // TP2(出力ピン2)をOFF
32+
33+
// GG_TP_ON(x)
34+
// GG_TP1==xならTP1(出力ピン1)をON
35+
// GG_TP2==xならTP2(出力ピン2)をON
36+
// GG_TP_OFF(x)
37+
// GG_TP1==xならTP1(出力ピン1)をOFF
38+
// GG_TP2==xならTP2(出力ピン2)をOFF
39+
//
40+
extern int gg_tp1_sel; // TP1(出力ピン1)に出力する状態番号変数
41+
extern int gg_tp2_sel; // TP2(出力ピン2)に出力する状態番号変数
42+
#ifndef GG_TP1
43+
#define GG_TP1 (gg_tp1_sel) // TP1(出力ピン1)に出力する状態番号
44+
#endif
45+
#ifndef GG_TP2
46+
#define GG_TP2 (gg_tp2_sel) // TP2(出力ピン2)に出力する状態番号
47+
#endif
48+
#ifndef GG_TP_NOCODE // テストポイント(TP機能)を使用する場合
49+
#define GG_TP_ON(x) {if (GG_TP1==(x)) GG_TP1_ON(); if (GG_TP2==(x)) GG_TP2_ON(); }
50+
#define GG_TP_OFF(x) {if (GG_TP1==(x)) GG_TP1_OFF(); if (GG_TP2==(x)) GG_TP2_OFF(); }
51+
#else // テストポイント(TP機能)を使用しない場合
52+
#define GG_TP_ON(x) // 無効
53+
#define GG_TP_OFF(x) // 無効
54+
#endif
55+
56+
// TP機能出力ピン番号
57+
// 旧v1.0.x対応のため公開している(本来は公開不要,GG_tp.inoサンプル参照)
58+
// gg_start()前にセットすれば自動的にgg_tp_start()が呼ばれる
59+
extern int gg_tp1_no; // TP1出力ピン番号(-1=なし)
60+
extern int gg_tp2_no; // TP2出力ピン番号(-1=なし)
61+
62+
int gg_tp_start(int tp1_no, int tp2_no); // TP機能スタート(出力ピン初期化とコマンド登録)
63+
2064

2165
#endif // __GG_FOR_ARDUINO_H__

0 commit comments

Comments
 (0)