Commander-API  V2.1.0
Simple Command Parser
Loading...
Searching...
No Matches
Commander-IO.cpp
Go to the documentation of this file.
1/*
2 * Created on June 18 2020
3 *
4 * Copyright (c) 2020 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Commander-API project.
7 * Modified 2022.02.06
8*/
9
10/*
11MIT License
12
13Copyright (c) 2020 Daniel Hajnal
14
15Permission is hereby granted, free of charge, to any person obtaining a copy
16of this software and associated documentation files (the "Software"), to deal
17in the Software without restriction, including without limitation the rights
18to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19copies of the Software, and to permit persons to whom the Software is
20furnished to do so, subject to the following conditions:
21
22The above copyright notice and this permission notice shall be included in all
23copies or substantial portions of the Software.
24
25THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31SOFTWARE.
32*/
33
34
35#include "Commander-IO.hpp"
36
38
40 return 0;
41 }
42
43 else if( writePointer > readPointer ){
45 }
46
47 else{
48
50
51 }
52
53}
54
56
57 int ret;
58
60
61 return -1;
62
63 }
64
65 else{
66
67 ret = (uint8_t)buffer[ readPointer ];
69
71 readPointer = 0;
72 }
73
74 }
75
76 return ret;
77
78}
79
82 // Hinestly I don't know what to do.
83 // Arduino flush methods are wierd.
84}
85
87
89
90 return -1;
91
92 }
93
94 else{
95
96 return (uint8_t)buffer[ readPointer ];
97
98 }
99
100}
101
102size_t commanderPipeChannel::write( uint8_t data ){
103
104 buffer[ writePointer ] = data;
105 writePointer++;
107 writePointer = 0;
108 }
109
110 return 1;
111
112}
113
114size_t commanderPipeChannel::write( const uint8_t *data, size_t size ){
115
116 uint32_t i;
117
118 for( i = 0; i < size; i++ ){
119
120 buffer[ writePointer ] = data[ i ];
121 writePointer++;
123 writePointer = 0;
124 }
125
126 }
127
128 return size;
129
130}
#define COMMANDER_MAX_COMMAND_SIZE
void flush() override
Flush the channel.
size_t write(uint8_t b) override
Write one byte to the channel.
uint8_t buffer[COMMANDER_MAX_COMMAND_SIZE]
int peek() override
Peek the firtst byte from the channel.
int read() override
Read one byte form the channel.
int available() override
Available bytes in the channel.