# PAL\_Recv

TWELITE PAL のパケットデータの表示を行います。

![画面例](/files/-M075t8vg6MDdIkzcYy6)

TWELITE PALの親機用ファームウェア(App\_PAL-Parent-BLUE.binまたはApp\_PAL-Parent-RED.bin)をTWELITE DIPにあらかじめ書き込んでおきます。

{% hint style="info" %}
M5Stackに接続する前に書き込んだTWELITE DIPが無線パケットを受信してデータを出力するかPCで確認しておいてください。
{% endhint %}

M5Stack側のTWELITE DIPは、以下のような接続をしておきます。

```
                      TWELITE DIP
                 -01:GND        VCC:28-------M5 3V3
                 -02:D14         D3:27-
  M5 GPIO16-------03:D7          D2:26-
                 -04:D5          D1:25-
                 -05:D18         A2:24-
                 -06:C           D0:23-
                 -07:M           A1:22-
                 -08:D19        RST:21-
                 -09:D4         D17:20-
  M5 GPIO17-------10:D6         D15:19-
                 -11:D8         D16:18-
                 -12:D9         D11:17-
                 -13:D10        D13:16-
  M5 GND----------14:GND        D12:15-
```

## setup()

```cpp
Serial2.setRxBufferSize(512);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
```

シリアルポートの初期化を行っています。

```
setup_screen();
```

LCDスクリーンの初期化を行います。処理の内容はscreen.cにあり、[ターミナル](/0.9-1/getting-started/using-library/terminal.md)画面の初期設定を行います。

```
pkt_data.init_screen(fmt_title);
```

パケットデータの管理クラスの初期化を行います。

## loop()

```
check_for_serial();
```

シリアルポートの入力チェックを行います。入力したデータを `the_input_uart` キューにいったん投入します。

```
process_input();
```

シリアルポートから入力データを処理します。ここでは[パーサー](/0.9-1/getting-started/using-library/parser.md)に文字列を投入します。パーサーによりシリアル電文が解釈できた場合は、`update_screen()`を呼び出しターミナル画面に文字を更新します。

```
check_for_refresh();
```

LCD画面上のターミナル画面領域を書き換えます。処理の内容はscreen.cにあります。

## pkt\_data

入力データの管理と表示を行う関数です。

このクラスでは、パケットデータに含まれる送信元論理IDごとの[`spTwePacket`](/0.9-1/references/parser/twefmt/twepacket.md)データを保存しています。新しいデータを受信したら都度更新します。

画面表示は論理ID１から順に、最後のデータまで１行ずつ表示します。１画面に収まらない場合は、次のページに表示します。

### init\_screen(), reinit\_screen()

```cpp
void init_screen(const char *fmt_status) 
void reinit_screen()
```

`init_screen()`は初回の初期化を行います。`fmt_status`は上部タイトルエリアへの出力文字を指定します。

フォント変更などで画面サイズに変化があった場合は`reinit_screen()`を呼び出します。

### add\_entry()

```cpp
bool add_entry(spTwePacket spobj)
```

受信パケットデータを登録します。内部的にはIDに対応した`spTwePacket`の配列に値を入れます。

### next\_page(), prev\_page(), set\_page()

```cpp
void next_page()
void prev_page()
void set_page(int entry)
```

ページ設定を行います。画面の更新をするため、直後に`update_term()`を呼び出します。

`set_page()`は`entry`に対応する論理IDが含まれるページに移動します。

### update\_status()

```cpp
void update_status()
```

上部タイトルエリアの文字列を再設定します。

### update\_term()

```cpp
void update_term()
void update_term(spTwePacket pal_upd, bool update_all)
```

ターミナル画面の表示文字列の更新を行います。

パラメータなしで呼び出すか、update\_all=trueで呼び出すと、ターミナル全体の再描画を行います。

`pal_upd`を指定し`update_all=false`の場合は、`pal_upd`の表示行のみを更新します。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwm5.twelite.info/0.9-1/getting-started/examples/pal_recv.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
