Tiny protocol  0.7.0
Tiny communication protocol for microcontrollers
TinyProtocol.h
Go to the documentation of this file.
1 /*
2  Copyright 2016-2017 (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 
28 #ifndef _TINY_PROTOCOL_H_
29 #define _TINY_PROTOCOL_H_
30 
31 #include "TinyPacket.h"
32 #include "proto/_old/tiny_layer2.h"
33 
34 #ifdef ARDUINO
35 # include <HardwareSerial.h>
36 #else
37 # include <string.h>
38 #endif
39 
40 namespace Tiny {
41 
47 class Proto
48 {
49 public:
50  inline Proto(): m_data{0} { m_uidEnabled = false; }
51 
60  void begin (write_block_cb_t writecb,
61  read_block_cb_t readcb);
62 
63 #ifdef ARDUINO
64 
69  inline void beginToSerial()
70  {
71  begin([](void *p, const void *b, int s)->int { return Serial.write((const uint8_t *)b, s); },
72  [](void *p, void *b, int s)->int { return Serial.readBytes((uint8_t *)b, s); });
73  }
74 
75 #if HAVE_HWSERIAL1
76 
81  inline void beginToSerial1()
82  {
83  begin([](void *p, const uint8_t *b, int s)->int { return Serial1.write(b, s); },
84  [](void *p, uint8_t *b, int s)->int { return Serial1.readBytes(b, s); });
85  }
86 #endif
87 
88 #if HAVE_HWSERIAL2
89 
94  inline void beginToSerial2()
95  {
96  begin([](void *p, const uint8_t *b, int s)->int { return Serial2.write(b, s); },
97  [](void *p, uint8_t *b, int s)->int { return Serial2.readBytes(b, s); });
98  }
99 #endif
100 
101 #if HAVE_HWSERIAL3
102 
107  inline void beginToSerial3()
108  {
109  begin([](void *p, const uint8_t *b, int s)->int { return Serial3.write(b, s); },
110  [](void *p, uint8_t *b, int s)->int { return Serial3.readBytes(b, s); });
111  }
112 #endif
113 
114 #endif
115 
119  void end ();
120 
130  int write (char* buf, int size, uint8_t flags = TINY_FLAG_WAIT_FOREVER);
131 
141  int read (char* buf, int size, uint8_t flags = TINY_FLAG_WAIT_FOREVER);
142 
152  int write (Packet &pkt, uint8_t flags = TINY_FLAG_WAIT_FOREVER);
153 
163  int read (Packet &pkt, uint8_t flags = TINY_FLAG_WAIT_FOREVER);
164 
170  void disableCrc ();
171 
179  bool enableCheckSum ();
180 
188  bool enableCrc16 ();
189 
198  bool enableCrc32 ();
199 
206  inline void enableUid() { m_uidEnabled = true; }
207 
214  inline void disableUid(){ m_uidEnabled = false; }
215 
216 private:
217  STinyData m_data;
218  uint8_t m_uidEnabled;
219 };
220 
221 
222 } // Tiny namespace
223 
224 #endif
225 
bool enableCrc32()
int read(char *buf, int size, uint8_t flags=TINY_FLAG_WAIT_FOREVER)
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
Definition: tiny_proto_types.h:114
Tiny protocol Arduino API.
#define TINY_FLAG_WAIT_FOREVER
This flag makes tiny API functions perform in blocking mode.
Definition: tiny_proto_types.h:81
Definition: TinyLightProtocol.h:39
bool enableCrc16()
Definition: tiny_layer2.h:110
void beginToSerial()
Definition: TinyProtocol.h:69
Tiny protocol API.
void beginToSerial3()
Definition: TinyProtocol.h:107
Definition: TinyPacket.h:44
void enableUid()
Definition: TinyProtocol.h:206
void begin(write_block_cb_t writecb, read_block_cb_t readcb)
bool enableCheckSum()
void disableUid()
Definition: TinyProtocol.h:214
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_proto_types.h:125
int write(char *buf, int size, uint8_t flags=TINY_FLAG_WAIT_FOREVER)
Definition: TinyProtocol.h:47
void disableCrc()
void beginToSerial1()
Definition: TinyProtocol.h:81
void beginToSerial2()
Definition: TinyProtocol.h:94