Tiny protocol  0.9.3
Tiny communication protocol for microcontrollers
TinyLightProtocol.h
Go to the documentation of this file.
1 /*
2  Copyright 2017-2019 (C) Alexey Dynda
3 
4  This file is part of Tiny Protocol Library.
5 
6  Protocol Library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Protocol Library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
27 #ifndef _TINY_LIGHT_PROTOCOL_H_
28 #define _TINY_LIGHT_PROTOCOL_H_
29 
30 #include "TinyPacket.h"
31 #include "proto/light/tiny_light.h"
32 
33 #ifdef ARDUINO
34 # include <HardwareSerial.h>
35 #else
36 # include <string.h>
37 #endif
38 
39 namespace Tiny {
40 
52 {
53 public:
54  inline ProtoLight(): m_data{} { }
55 
64  void begin (write_block_cb_t writecb,
65  read_block_cb_t readcb);
66 
67 #ifdef ARDUINO
68 
73  void beginToSerial();
74 
75 #ifdef HAVE_HWSERIAL1
76 
81  inline void beginToSerial1()
82  {
83  begin([](void *p, const void *b, int s)->int { return Serial1.write((const uint8_t *)b, s); },
84  [](void *p, void *b, int s)->int { return Serial1.readBytes((uint8_t *)b, s); });
85  }
86 #endif
87 
88 #ifdef HAVE_HWSERIAL2
89 
94  inline void beginToSerial2()
95  {
96  begin([](void *p, const void *b, int s)->int { return Serial2.write((const uint8_t *)b, s); },
97  [](void *p, void *b, int s)->int { return Serial2.readBytes((uint8_t *)b, s); });
98  }
99 #endif
100 
101 #ifdef HAVE_SERIALUSB
102 
107  inline void beginToSerialUSB()
108  {
109  begin([](void *p, const void *b, int s)->int { return SerialUSB.write((const char *)b, s); },
110  [](void *p, void *b, int s)->int { return SerialUSB.readBytes((char *)b, s); });
111  }
112 #endif
113 
114 #endif
115 
119  void end ();
120 
129  int write (char* buf, int size);
130 
139  int read (char* buf, int size);
140 
149  int write (IPacket &pkt);
150 
159  int read (IPacket &pkt);
160 
166  void disableCrc ();
167 
173  void enableCrc(hdlc_crc_t crc);
174 
182  bool enableCheckSum ();
183 
191  bool enableCrc16 ();
192 
201  bool enableCrc32 ();
202 
203 private:
204  STinyLightData m_data{};
205 
207 };
208 
213 } // Tiny namespace
214 
215 #endif
void enableCrc(hdlc_crc_t crc)
hdlc_crc_t
Definition: tiny_hdlc.h:33
Tiny protocol Arduino API.
If default is specified HDLC will auto select CRC option.
Definition: tiny_hdlc.h:35
Definition: TinyLightProtocol.h:39
int read(char *buf, int size)
void beginToSerial2()
Definition: TinyLightProtocol.h:94
void begin(write_block_cb_t writecb, read_block_cb_t readcb)
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_types.h:139
int write(char *buf, int size)
Definition: tiny_light.h:51
Definition: TinyPacket.h:46
Definition: TinyLightProtocol.h:51
Tiny Light protocol API.
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
Definition: tiny_types.h:128
void beginToSerial1()
Definition: TinyLightProtocol.h:81