# on\_rx\_packet()

受信パケットを受け取ります。

```cpp
void on_rx_packet(mwx::packet_rx& pkt, bool_t &b_handled) 
```

無線パケットを受信したときに[packet\_rx](/api-reference/classes/packet_rx.md)として `pkt` にデータが格納された状態で、本関数が MWX ライブラリ内から呼び出されます。アプリケーション中で本関数が定義されない場合は何もしない weak 関数がリンクされます。

本関数中で `b_handled` に *true* をセットすると、MWX ライブラリに受信パケットがアプリケーション内で処理されたことを伝達します。処理済みとした場合、不要な処理を抑制します。（`the_twelite.receiver` の処理を行わない）

{% hint style="warning" %}
[ビヘイビア](/api-reference/behavior.md)を用いる場合は、ビヘイビア中のコールバック関数を用いてください。
{% endhint %}

{% hint style="warning" %}
`the_twelite.receiver`は推奨されません。

従来`loop()`内での記述を意図して `the_twelite.receiver` による処理を行っていましたが、キューによる遅延処理である点で原理的に取りこぼしが発生し、また記述も煩雑になりがちである点から `on_rx_packet()` を追加しました。
{% endhint %}


---

# 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://mwx.twelite.info/api-reference/sys_callbacks/on_rx_packet.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.
