# DataPal

PALは接続されるセンサーなどによってパケットデータ構造が異なりますが、`DataPal`では共通部のデータ構造を保持します。

```cpp
struct DataPal {
	uint8_t u8lqi;        // LQI値

	uint32_t u32addr_rpt; // 中継器のアドレス

	uint32_t u32addr_src; // 送信元のアドレス
	uint8_t u8addr_src;   // 送信元の論理アドレス

	uint16_t u16seq;      // シーケンス番号

	E_PAL_PCB u8palpcb;		// PAL基板の種別
	uint8_t u8pkt_type;　　// Packet タイプ (0:PalDataInfo付, 1:シンプル)
	uint8_t u8sensors;		// データに含まれるセンサーデータの数 (MSB=1はエラー)
	uint8_t u8snsdatalen; // センサーデータ長(バイト数), MSB=1は動的確保

	uint8_t au8snsdata[32]; // センサーデータ（解釈前の生データ）
	std::unique_ptr<uint8_t[]> uptr_snsdata; // センサーデータ（動的確保）
};
```

PALのパケットデータ構造は大まかに２つのブロックからなり、全てのPAL共通部と個別のデータ部になります。個別のデータ部は、パケットの解釈を行わずそのまま格納しています。取り扱いを単純化するため32バイトを超えるデータは動的に確保する`uptr_snsdata`に格納します。

個別のデータ部は、`PalBase`をベースクラスに持つ構造体に格納されます。この構造体は、`TwePacketPal`に定義されるジェネレータ関数により生成されます。

`u8pkt_type`が`0`の時は`PalDataInfo`データ構造が付与された形式となります。比較的複雑な情報を格納するための形式です。`1`の場合は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/latest/references/parser/twefmt/packet-types/twepacketpal/datapal.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.
