UdonLibrary 1.0.0
機械システム研究部 C++ ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
Im920Reader.hpp
[詳解]
1//
2// IM920 受信クラス
3//
4// Copyright (c) 2022-2024 udonrobo
5//
6
7//
8// Sender --[UART]--> IM920 ~~[920MHz]~~> IM920 --[UART]--> Receiver
9//   ^^^^^^^^
10//
11
12#pragma once
13
14#include "IIm920.hpp"
15
17#include <Udon/Utility/Show.hpp>
18
19namespace Udon
20{
21
24 template <typename Message>
26 {
27 public:
28 static constexpr size_t Size = Udon::SerializedSize<Message>();
29
30 using MessageType = Message;
31
32 private:
33 IIm920& im920;
34
35 uint8_t buffer[Size];
36
37 Im920Node node;
38
39 public:
41 : im920(im920)
42 , buffer()
43 , node{ buffer, Size, 0 }
44 {
45 im920.joinRx(node);
46 }
48 : im920(other.im920)
49 , buffer()
50 , node{ buffer, Size, 0 }
51 {
52 im920.joinRx(node);
53 }
54
55 Udon::Optional<Message> getMessage(uint32_t timeOut = 700) const
56 {
57 if (millis() - node.transmitMs > timeOut)
58 {
59 return Udon::nullopt;
60 }
61 else
62 {
63 return Udon::Deserialize<Message>(buffer);
64 }
65 }
66
69 void show(char gap = '\t') const
70 {
71 if (const auto message = getMessage())
72 {
73 Udon::Show(*message, gap);
74 }
75 else
76 {
77 Serial.print(F("receive failed!"));
78 }
79 }
80
83 void showRaw(char gap = ' ') const
84 {
85 for (auto&& it : buffer)
86 {
87 Serial.print(it);
88 Serial.print(gap);
89 }
90 }
91 };
92} // namespace Udon
#define F(x)
Definition Show.hpp:17
IM920のインターフェース
Definition IIm920.hpp:31
virtual void joinRx(Im920Node &node)=0
受信ノードを登録
IM920受信クラス
Definition Im920Reader.hpp:26
Im920Reader(const Im920Reader &other)
Definition Im920Reader.hpp:47
void showRaw(char gap=' ') const
送信バッファを表示
Definition Im920Reader.hpp:83
Im920Reader(IIm920 &im920)
Definition Im920Reader.hpp:40
Udon::Optional< Message > getMessage(uint32_t timeOut=700) const
Definition Im920Reader.hpp:55
void show(char gap='\t') const
送信内容を表示
Definition Im920Reader.hpp:69
Message MessageType
Definition Im920Reader.hpp:30
static constexpr size_t Size
Definition Im920Reader.hpp:28
オプショナル型
Definition Optional.hpp:62
Definition Bit.hpp:12
Udon::Optional< T > Deserialize(ArrayView< const uint8_t > buffer)
バイト列からオブジェクトに逆シリアル化します
Definition Serializer.hpp:87
void Show(Args &&... args)
区切り文字ありで出力する
Definition Show.hpp:339
constexpr size_t SerializedSize() noexcept
Tをシリアライズした際のバイト列の要素数を取得する
Definition Serializer.hpp:22
constexpr NulloptT nullopt
無効値
Definition Optional.hpp:52
IM920ノード
Definition IIm920.hpp:20
uint32_t transmitMs
Definition IIm920.hpp:23