35 uint32_t receiveDeadTime;
38 Im920(HardwareSerial& uart,
bool twoWayNum =
false)
40 , twoWayNum(twoWayNum)
48 operator bool()
const override
50 switch (getTransmitMode())
52 case TransmitMode::Send:
53 return uart && (millis() - sendMitMs < 1000);
54 case TransmitMode::Receive:
55 return uart && (millis() - receiveDeadTime < 1000);
56 case TransmitMode::TwoWay:
57 return uart && (2 * millis() - (sendMitMs + receiveDeadTime) < 1000);
65 void begin(uint8_t channel);
69 switch (getTransmitMode())
71 case TransmitMode::Send:
74 case TransmitMode::Receive:
77 case TransmitMode::TwoWay:
90 Serial.print(
"IM920: OK ");
94 Serial.print(
"IM920: NG ");
97 switch (getTransmitMode())
99 case TransmitMode::Send:
100 Serial.print(
"SendMode ");
102 case TransmitMode::Receive:
103 Serial.print(
"ReceiveMode ");
105 case TransmitMode::TwoWay:
106 Serial.print(
"TwoWayMode ");
108 case TransmitMode::Empty:
109 Serial.print(
"Empty ");
122 enum class TransmitMode
131 TransmitMode getTransmitMode()
const
137 return TransmitMode::TwoWay;
141 return TransmitMode::Send;
146 return TransmitMode::Receive;
150 return TransmitMode::Empty;
159 { uart.write(data); });
167 constexpr int HeaderSize = 2 + 1 + 4 + 1 + 2 + 1;
170 constexpr int FooterSize = 1 + 1;
176 if (uart.available() < FrameSize)
182 for (
int i = 0; i < HeaderSize; ++i)
189 { return uart.read(); }))
192 while (uart.available())
200 for (
int i = 0; i < FooterSize; ++i)
206 while (uart.available())
219 const double sendTime = 10.0 + 5.2 + 3.2 + txNode->
size * 0.16;
220 const double receiveTime = 10.0 + 5.2 + 3.2 + rxNode->
size * 0.16;
224 if (2 * millis() - (sendMitMs + receiveDeadTime) > sendTime + receiveTime)
252 uart.print(
"STPO 3\r\n");
256 uart.print(
"STRT 1\r\n");
260 uart.print(
"ECIO\r\n");
IM920のインターフェース
Definition IIm920.hpp:31
IM920通信クラス
Definition Im920Normal.hpp:27
void update()
Definition Im920Normal.hpp:67
void begin(uint8_t channel)
通信開始
Definition Im920Normal.hpp:242
void joinRx(Im920Node &node) override
受信ノードを登録
Definition Im920Normal.hpp:119
void joinTx(Im920Node &node) override
送信ノードを登録
Definition Im920Normal.hpp:116
Im920(HardwareSerial &uart, bool twoWayNum=false)
Definition Im920Normal.hpp:38
void show()
バスの状態を表示
Definition Im920Normal.hpp:86
void BitPack(const InputIterator begin, const InputIterator end, Functor callback)
バイト列のMSB(最上位ビット)を抽出し、7bitごとに分割してコールバック関数に渡す
Definition BitPack.hpp:23
void Printf(const char *format, Args... args)
Definition Printf.hpp:44
bool BitUnpack(OutputIterator begin, OutputIterator end, Functor callback)
7bit分割されたデータを結合する
Definition BitPack.hpp:70
constexpr size_t BitPackedSize(size_t size)
ビットパックされたデータのサイズを取得する
Definition BitPack.hpp:132
IM920ノード
Definition IIm920.hpp:20
uint32_t transmitMs
Definition IIm920.hpp:23
uint8_t * data
Definition IIm920.hpp:21
uint8_t size
Definition IIm920.hpp:22