> For the complete documentation index, see [llms.txt](https://palscript.twelite.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://palscript.twelite.info/master/source-files/mnlib/apppal.py.md).

# apppal.py

### `Class AppPAL`

AppBaseを継承し、得られたペイロードを解釈して、使いやすいデータに変換して、辞書オブジェクトに登録するクラスです。

#### 定義するときのパラメータ

初期値が設定されているものは指定不要。

| 変数名     | 型       | 初期値    | 内容                                             |
| ------- | ------- | ------ | ---------------------------------------------- |
| port    | string  | None   | <p>開くシリアルポート名</p><p>例：COM3、/dev/ttyUSB0 など</p> |
| baud    | int     | 115200 | ボーレート                                          |
| tout    | float   | 0.1    | シリアル通信するときのタイムアウト時間(秒)                         |
| sformat | string  | Ascii  | 本設定値はAsciiで固定                                  |
| autolog | boolean | False  | ペイロードが解釈出来たときに自動でCSVファイルにログを出力する場合はTrue        |
| err     | boolean | False  | エラーメッセージを出力する場合はTrue                           |

### `ReadSensorData()`

本メソッドで読み込めたペイロードがあれば、 [TWELITE PAL 親機の書式フォーマット](https://mono-wireless.com/jp/products/TWE-APPS/App_pal/parent.html) に従ってそのペイロードの解釈を行います。

{% hint style="info" %}
[TWELITE PAL 親機の書式フォーマット](https://mono-wireless.com/jp/products/TWE-APPS/App_pal/parent.html) (ASCII形式のみ) を解釈しています。多くはその定義に従います。
{% endhint %}

#### パラメータ

なし

#### 戻り値

* データが読み込めた場合：`True`
* 読み込めなかった場合：`False`

辞書オブジェクトに格納されたデータのキーは下記の通りです。

{% hint style="info" %}
EventIDなどのデータの意味に関しては、[こちら](https://wings.twelite.info/how-to-use/parent-mode/receive-message/app_pal#chu-li-shu-shi)もご確認ください。
{% endhint %}

| キー                | 型          | 内容                                                              |
| ----------------- | ---------- | --------------------------------------------------------------- |
| ArriveTime        | datetime   | ペイロードを得たときの時間                                                   |
| LogicalID         | int        | 子機の論理デバイスID                                                     |
| EndDeviceSID      | int        | 子機のシリアル番号                                                       |
| RouterSID         | int        | <p>最初に受信した中継機のシリアル番号</p><p>(親機が直接子機のパケットを受信した場合は0x80000000)</p> |
| LQI               | int        | 受信電波品質                                                          |
| SequenceNumber    | int        | <p>パケットが送信されるごとにインクリメントされる続き番号</p><p>1からスタート、65535の次に0に戻る</p>   |
| Sensor            | int        | センサー種別（0x80で固定）                                                 |
| PALID             | int        | PAL基板ID                                                         |
| PALVersion        | int        | PAL基板バージョン                                                      |
| HALLIC            | int        | ホールICの状態                                                        |
| Temperature       | float      | 温度(degC)                                                        |
| Humidity          | float      | 湿度(%)                                                           |
| Illuminance       | int        | 照度(lux)                                                         |
| AccelerationX     | list,float | X軸の加速度(g)                                                       |
| AccelerationY     | list,float | Y軸の加速度(g)                                                       |
| AccelerationZ     | list,float | Z軸の加速度(g)                                                       |
| SamplingFrequency | int        | 加速度のサンプリング周波数                                                   |
| EventID           | list,int   | イベントの要因とイベントID                                                  |
| WakeupFactor      | list,int   | 起床した要因等のデータ                                                     |

### `OutputCSV()`

辞書オブジェクトをCSVファイルに出力します。

#### パラメータ

なし

#### 戻り値

なし


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://palscript.twelite.info/master/source-files/mnlib/apppal.py.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
