tinyproto
TinyLinkLayer.h
1 /*
2  Copyright 2016-2024 (C) Alexey Dynda
3 
4  This file is part of Tiny Protocol Library.
5 
6  GNU General Public License Usage
7 
8  Protocol Library is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Protocol Library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
20 
21  Commercial License Usage
22 
23  Licensees holding valid commercial Tiny Protocol licenses may use this file in
24  accordance with the commercial license agreement provided in accordance with
25  the terms contained in a written agreement between you and Alexey Dynda.
26  For further information contact via email on github account.
27 */
28 
29 #pragma once
30 
31 #include "TinyPacket.h"
32 #include "proto/fd/tiny_fd.h"
33 
34 #include <stdint.h>
35 #include <limits.h>
36 
37 namespace tinyproto
38 {
39 
44 {
45 public:
46  ILinkLayer() {}
47 
58  virtual bool begin(on_frame_read_cb_t onReadCb, on_frame_send_cb_t onSendCb, void *udata) = 0;
59 
63  virtual void end() = 0;
64 
69  virtual void runRx() = 0;
70 
75  virtual void runTx() = 0;
76 
85  virtual bool put(void *buf, int size, uint32_t timeout) = 0;
86 
90  virtual void flushTx() = 0;
91 
98  void setTimeout(uint32_t timeout)
99  {
100  m_timeout = timeout;
101  }
102 
106  uint32_t getTimeout()
107  {
108  return m_timeout;
109  }
110 
114  int getMtu()
115  {
116  return m_mtu;
117  }
118 
126  void setMtu(int mtu)
127  {
128  m_mtu = mtu;
129  }
130 
134  virtual ~ILinkLayer() = default;
135 
136 private:
137  int m_mtu = 16384;
138  uint32_t m_timeout = 0;
139 };
140 
141 } // namespace tinyproto
This is Tiny protocol implementation for microcontrollers.
virtual void flushTx()=0
Flush tx operation if possible.
void(* on_frame_send_cb_t)(void *udata, uint8_t address, const uint8_t *pdata, int size)
on_frame_send_cb_t is a callback function, which is called every time new frame is sent...
Definition: tiny_types.h:223
virtual bool put(void *buf, int size, uint32_t timeout)=0
Puts new data for sending over the link layer.
virtual void end()=0
Stops link layer protocol.
virtual void runRx()=0
Runs rx part of the protocol.
This is basic class for C++ Link Layer objects.
Definition: TinyLinkLayer.h:43
int getMtu()
Returns current mtu for the link layer protocol in bytes.
Definition: TinyLinkLayer.h:114
virtual void runTx()=0
Runs tx part of the protocol.
void(* on_frame_read_cb_t)(void *udata, uint8_t address, uint8_t *pdata, int size)
on_frame_read_cb_t is a callback function, which is called every time new frame is received...
Definition: tiny_types.h:213
virtual bool begin(on_frame_read_cb_t onReadCb, on_frame_send_cb_t onSendCb, void *udata)=0
The method initializes the link layer protocol, and connects custom callbacks to link layer...
virtual ~ILinkLayer()=default
Default virtual destructor.
Definition: TinySerial.cpp:22
This is Tiny Full-Duplex protocol implementation for microcontrollers.
void setTimeout(uint32_t timeout)
Sets timeout of Rx/Tx operations in milliseconds for the link layer protocol.
Definition: TinyLinkLayer.h:98
void setMtu(int mtu)
Set protocol mtu (maximum transmission unit) payload.
Definition: TinyLinkLayer.h:126
uint32_t getTimeout()
Returns current timeout of Rx/Tx operations.
Definition: TinyLinkLayer.h:106