# TwePacketPal

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

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

PAL共通データは[`DataPal`](/1.0-2/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
        }
      }
    }
  }
}
```

## パケットデータ定関数

### has\_palEvent()

```cpp
bool has_PalEvent()
bool is_PalEvent()
```

パケットにイベント情報が含まれるかを判定します。

### get\_PalDataType()

```cpp
E_PAL_DATA_TYPE get_PalDataType()
```

パケットの種別を判定します。種別は[`E_PAL_DATA_TYPE`](/1.0-2/references/parser/twefmt/packet-types/twepacketpal/e_pal_data_type.md)として判定されます。

### has\_data\_info()

```cpp
bool has_data_info()
```

パケットプロパティ（パケットの補助情報）が含まれているか判定します。含まれている場合は`PalDataInfo`で定義されるメンバーにアクセスできます。

### is\_data\_source\_timer()

```cpp
bool is_data_source_timer()
```

パケットプロパティが存在する場合に呼び出しは有効。タイマー由来からの送信の場合trueを返します。

## ジェネレータ関数

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

### get\_PalMag()

```cpp
PalMag get_PalMag()
```

`.u8palpcb==E_PAL_PCB::MAG`の場合、開閉センサーパルのデータ[`PalMag`](/1.0-2/references/parser/twefmt/packet-types/twepacketpal/palbase/palmag.md)を取り出します。

### get\_PalAmb()

```
PalAmb get_PalAmb()
```

`.u8palpcb==E_PAL_PCB::AMB`の場合、環境センサーパルのデータ[`PalAmb`](/1.0-2/references/parser/twefmt/packet-types/twepacketpal/palbase/palamb.md)を取り出します。

### get\_PalMot()

```
PalMot get_PalMot()
```

`.u8palpcb==E_PAL_PCB::MOT`の場合、動作センサーパルのデータ[`PalMot`](/1.0-2/references/parser/twefmt/packet-types/twepacketpal/palbase/palmot.md)を取り出します。

### get\_PalEvent()

```
PalEvent get_PalEvent()
```

`.is_PalEvent()`が`true`の場合`PalEvent`(PALイベント)を取り出します。


---

# 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/1.0-2/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.
