9 frequency_t frequency =
static_cast<frequency_t
> (
parseAbsInt());
14 microseconds_t *introData =
parseData(introLength);
15 microseconds_t *repeatData =
parseData(repeatLength);
16 microseconds_t *endingData =
parseData(endingLength);
18 return new IrSignal(introData, introLength, repeatData, repeatLength, endingData, endingLength, frequency);
27 while (stream.available() == 0)
33 int c = stream.read();
37 if (i == 0 && isblank(c))
43 if (i == buflen - 1) {
44 disposeUntilWhitespace();
47 buf[i] =
static_cast<char>(c);
56 while (stream.available() == 0)
62 int c = stream.read();
73 if (i == buflen - 1) {
74 disposeUntilWhitespace();
77 buf[i] =
static_cast<char>(c);
88 }
while (c ==
' ' || c ==
'\t' || c ==
'-' || c ==
'+');
90 if (c ==
'\r' || c ==
'\n')
100 }
while (isspace(c) || c ==
'-' || c ==
'+');
111 int32_t n =
static_cast<int> (c) -
static_cast<int> (
'0');
112 if (n < 0 || n > 9) {
113 disposeUntilWhitespace();
118 value = value * 10 + n;
119 c = customReadChar();
123 uint16_t StreamParser::parseProntoNumber() {
126 c = customReadChar();
127 }
while (isspace(c));
130 for (
unsigned i = 0; i < Pronto::digitsInProntoNumber; i++) {
132 value = value * 16 + n;
133 c = customReadChar();
139 uint16_t type = parseProntoNumber();
140 uint16_t frequencyCode = parseProntoNumber();
141 uint16_t introPairs = parseProntoNumber();
142 uint16_t repeatPairs = parseProntoNumber();
143 size_t size = Pronto::numbersInPreamble + 2 * (introPairs + repeatPairs);
144 uint16_t* data =
new microseconds_t[size];
146 data[1] = frequencyCode;
147 data[2] = introPairs;
148 data[3] = repeatPairs;
149 for (
unsigned i = Pronto::numbersInPreamble; i < size; i++)
150 data[i] = parseProntoNumber();
151 return Pronto::parse(data, size);
154 unsigned int StreamParser::parseHex(
char c) {
157 : c <= '9' ? static_cast<unsigned>(c -
'0')
159 : c <=
'F' ? static_cast<unsigned>(c -
'A') + 10U
161 : c <=
'f' ? static_cast<unsigned>(c -
'a') + 10U
165 char StreamParser::customReadChar() {
171 if (c ==
'\r' || c ==
'\n')
172 return static_cast<char>(c);
175 return static_cast<char>(c);
180 int c = stream.peek();
188 void StreamParser::disposeUntilWhitespace() {
192 }
while (isspace(c));
196 microseconds_t* data =
new microseconds_t[length];
201 for (
unsigned int i = 0; i < length; i++)
Simple class for parsing stuff from an (input) Stream.
int32_t parseAbsInt()
Reads a number and returns it as 16 bit unsigned.
static IrSignal * parse(Stream &stream)
Convenience function: combines the constructor and parseIrSignal.
const char * getLine(char *buf, size_t buflen)
int32_t parseAbsIntDefault(int32_t fallback)
Reads a number and returns it as 16 bit unsigned.
const char * parseWord(char *buf, size_t buflen)
Returns a word (separated by whitespace).
IrSignal * parseIrSignal()
Reads the stream and parses it into an IrSignal.
StreamParser(Stream &stream)
Constructor.
microseconds_t * parseData(microseconds_t *buffer, size_t length)
IrSignal * parsePronto()
Reads a Pronto Hex format IR signal.
static constexpr int invalid