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