-
Notifications
You must be signed in to change notification settings - Fork 1
/
FakeStream.cpp
68 lines (51 loc) · 1.49 KB
/
FakeStream.cpp
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
/* Copyright (C) 2015 Willi Menapace <[email protected]>, Simone Lorengo - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Willi Menapace <[email protected]>
*/
#include "FakeStream.h"
#include "GlobalDefines.h"
#ifdef OFFBOARD
#include <assert.h>
void Stream::write(unsigned char byte) {
//Interrompe l'applicazione se il buffer non e' in grado di contenere tutti i dati
if(bytesCount >= FAKE_STREAM_BUFFER_LENGTH) {
assert(false);
}
buffer[bytesCount] = byte;
++bytesCount;
}
unsigned char *Stream::getBuffer() {
return buffer;
}
unsigned long Stream::getBytesCount() {
return bytesCount;
}
bool Stream::available() {
return bytesLeft > 0;
}
unsigned char Stream::read() {
//Interrompe l'applicazione se viene chiamato read senza byte da leggere
if(!available()) {
assert(false);
}
unsigned char readByte = 0;
readByte = receptionBuffer[receptionIndex];
++receptionIndex;
--bytesLeft;
return readByte;
}
Stream::Stream() {
bytesCount = 0;
receptionIndex = 0;
bytesLeft = 0;
}
Stream::Stream(unsigned char *_receptionBuffer, unsigned long _size) {
bytesCount = 0;
receptionIndex = 0;
bytesLeft = _size;
for(unsigned long i = 0; i < _size; ++i) {
receptionBuffer[i] = _receptionBuffer[i];
}
}
#endif // OFFBOARD