CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_CSVReader/AP_CSVReader.h
Views: 1798
1
#pragma once
2
3
// Note: term is always null-terminated so a final line with no cr/lf
4
// on it can still be fetched by the caller
5
6
#include <stdint.h>
7
8
class AP_CSVReader
9
{
10
11
public:
12
13
AP_CSVReader(uint8_t *_term, uint8_t _term_len, uint8_t _separator=',') :
14
separator{_separator},
15
term{_term},
16
term_len{_term_len}
17
{}
18
19
enum class RetCode : uint8_t {
20
OK,
21
ERROR,
22
TERM_DONE,
23
VECTOR_DONE,
24
};
25
26
RetCode feed(uint8_t c);
27
// RetCode feed(const uint8_t *buffer, uint8_t len);
28
29
private:
30
31
enum class State : uint8_t {
32
START_OF_START_OF_TERM = 46,
33
START_OF_TERM = 47,
34
END_OF_VECTOR_CR = 48,
35
IN_UNQUOTED_TERM = 49,
36
IN_QUOTED_TERM = 50,
37
END_OF_QUOTED_TERM = 51,
38
} state = State::START_OF_START_OF_TERM;
39
40
// term separator
41
const uint8_t separator;
42
43
// pointer to memory where term will be assembled
44
uint8_t *term;
45
46
// amount of memory term points to
47
const uint8_t term_len;
48
49
// offset into term for next character
50
uint8_t term_ofs;
51
52
void set_state(State newstate) {
53
state = newstate;
54
}
55
56
AP_CSVReader::RetCode handle_unquoted_term(uint8_t c);
57
AP_CSVReader::RetCode handle_quoted_term(uint8_t c);
58
};
59
60