tinyproto
TinyFdLinkLayer.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 "TinyLinkLayer.h"
32 #include "proto/fd/tiny_fd.h"
33 
34 #include <stdint.h>
35 #include <limits.h>
36 
37 namespace tinyproto
38 {
39 
40 class IFdLinkLayer: public ILinkLayer
41 {
42 public:
43  IFdLinkLayer(void *buffer, int size);
44 
45  ~IFdLinkLayer();
46 
47  bool begin(on_frame_read_cb_t onReadCb, on_frame_send_cb_t onSendCb, void *udata) override;
48 
49  void end() override;
50 
51  bool put(void *buf, int size, uint32_t timeout) override;
52 
53  void flushTx() override;
54 
55  int getWindow()
56  {
57  return m_txWindow;
58  }
59 
60  hdlc_crc_t getCrc()
61  {
62  return m_crc;
63  }
64 
65  void setCrc( hdlc_crc_t crc ) { m_crc = crc; }
66 
67  void setWindow(int window)
68  {
69  m_txWindow = window;
70  }
71 
72  void setBuffer(void *buffer, int size)
73  {
74  m_buffer = reinterpret_cast<uint8_t *>(buffer);
75  m_bufferSize = size;
76  }
77 
78 protected:
79 
80  int parseData(const uint8_t *data, int size);
81 
82  int getData(uint8_t *data, int size);
83 
84 private:
85  tiny_fd_handle_t m_handle = nullptr;
86  uint8_t *m_buffer = nullptr;
87  int m_bufferSize = 0;
88  uint8_t m_txWindow = 2;
89  hdlc_crc_t m_crc = HDLC_CRC_8;
90 };
91 
92 } // namespace tinyproto
Definition: tiny_fd_int.h:114
void end() override
Stops link layer protocol.
Definition: TinyFdLinkLayer.cpp:64
void flushTx() override
Flush tx operation if possible.
Definition: TinyFdLinkLayer.cpp:75
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
This is basic class for C++ Link Layer objects.
Definition: TinyLinkLayer.h:43
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
bool put(void *buf, int size, uint32_t timeout) override
Puts new data for sending over the link layer.
Definition: TinyFdLinkLayer.cpp:70
Definition: TinySerial.cpp:22
This is Tiny Full-Duplex protocol implementation for microcontrollers.
Definition: TinyFdLinkLayer.h:40
bool begin(on_frame_read_cb_t onReadCb, on_frame_send_cb_t onSendCb, void *udata) override
The method initializes the link layer protocol, and connects custom callbacks to link layer...
Definition: TinyFdLinkLayer.cpp:44