-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferStore.cpp
More file actions
executable file
·101 lines (78 loc) · 2.64 KB
/
BufferStore.cpp
File metadata and controls
executable file
·101 lines (78 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
SoftwareSerial.cpp (formerly NewSoftSerial.cpp) -
Multi-instance software serial library for Arduino/Wiring
-- Interrupt-driven receive and other improvements by ladyada
(http://ladyada.net)
-- Tuning, circular buffer, derivation from class Print/Stream,
multi-instance support, porting to 8MHz processors,
various optimizations, PROGMEM delay tables, inverse logic and
direct port writing by Mikal Hart (http://www.arduiniana.org)
-- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
-- 20MHz processor support by Garrett Mace (http://www.macetech.com)
-- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
The latest version of this library can always be found at
http://arduiniana.org.
*/
//
// Includes
//
#include <Arduino.h>
#include <BufferStore.h>
//
// Statics
//
char BufferStore::_transmit_buffer[_SS_MAX_TX_BUFF];
volatile uint8_t BufferStore::_transmit_buffer_tail = 0;
//constructor
union MsgLength //this means I can acces the bytes and the long value for a 4 didgit int (long)
{
unsigned long value;
byte bytes[4];
};
BufferStore::BufferStore()
{
}
//
// Private methods
//
//
// Destructor
//
BufferStore::~BufferStore()
{
}
//
// Public methods
//
size_t BufferStore::write(uint8_t b)
{
if (_transmit_buffer_tail<_SS_MAX_TX_BUFF)
{
_transmit_buffer[_transmit_buffer_tail++ +4] = b; //add 4 to the end so that we can prepend the size on the top
return _transmit_buffer_tail;
}
return 1;
}
void BufferStore::sendOut(Print &p)
{
//add the size
MsgLength tLen;
tLen.value = _transmit_buffer_tail;
_transmit_buffer[3] = tLen.bytes[0];
_transmit_buffer[2] = tLen.bytes[1];
_transmit_buffer[1] = tLen.bytes[2];
_transmit_buffer[0] = tLen.bytes[3];
p.write(_transmit_buffer, _transmit_buffer_tail+4);
_transmit_buffer_tail = 0;
}