# TwePacketPal

`TwePacketPal`クラスは、TWELITE PALのパケットデータを解釈したものです。このクラスはTWELITE PAL（センサーデータなど上り方向）共通に取り扱います。

```cpp
class TwePacketPal : public TwePacket, public DataPal { ... };
```

PAL共通データは[`DataPal`](/0.8/references/parser/twefmt/packet-types/twepacketpal/datapal.md)に定義されています。

PALの各センサー基板特有のデータを取り出すためのジェネレータ関数を用意しています。

### spTwePacketからの参照

```cpp
TwePacketPal& refTwePacketPal(spTwePacket& p)
```

`spTwePacket`オブジェクトから`TwePacketPal`オブジェクトを参照します。`spTwePacket`に`TwePacketPal`以外が格納されている場合は、未解釈のオブジェクトを戻します。

### 実行例

```cpp
if (parse_ascii) { // アスキー形式のパーサーの解釈完了
  if (identify_packet_type(parse_ascii.get_payload()) == E_PKT::PKT_PAL) {
    auto&& pkt = newTwePacket(parse_ascii.get_payload(), E_PKT::PKT_PAL);
    
    if (pkt == E_PKT::PKT_PAL) { // パケット解釈成功時
      auto&& pal = refTwePacketPal(pkt);
      
      // 開閉センサーパル
      if (pal.u8palpcb == E_PAL_PCB::MAG) {
        PalMag mag = pal.get_PalMag();
        if (mag.u8MagStat == 0) {
          // OPEN
        } else {
          // CLOSE
        }
      }
    }
  }
}
```

## ジェネレータ関数

センサーPALの各種データを取り出すためのジェネレータ関数です。

### get\_PalMag()

```cpp
PalMag get_PalMag()
```

開閉センサーパルのデータ[`PalMag`](/0.8/references/parser/twefmt/packet-types/twepacketpal/palbase/palmag.md)を取り出します。

### get\_PalAmb()

```
PalAmb get_PalAmb()
```

環境センサーパルのデータ[`PalAmb`](/0.8/references/parser/twefmt/packet-types/twepacketpal/palbase/palamb.md)を取り出します。

### get\_PalMot()

```
PalMot get_PalMot()
```

動作センサーパルのデータ[`PalMot`](/0.8/references/parser/twefmt/packet-types/twepacketpal/palbase/palmot.md)を取り出します。


---

# 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.8/references/parser/twefmt/packet-types/twepacketpal.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.
