Skyward boardcore
Loading...
Searching...
No Matches
APIFrameParser.h
Go to the documentation of this file.
1
/* Copyright (c) 2021 Skyward Experimental Rocketry
2
* Author: Luca Erbetta
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
* THE SOFTWARE.
21
*/
22
23
#pragma once
24
25
#include <
diagnostic/PrintLogger.h
>
26
27
#include <cstdint>
28
29
#include "
APIFrames.h
"
30
31
namespace
Boardcore
32
{
33
34
namespace
Xbee
35
{
36
40
class
APIFrameParser
41
{
42
public
:
46
enum class
ParserState
47
{
48
FIND_START
,
49
READ_LENGTH_1
,
50
READ_LENGTH_2
,
51
READ_FRAME_TYPE
,
52
READ_FRAME_DATA
,
53
READ_CHECKSUM
54
};
55
60
enum class
ParseResult
: uint8_t
61
{
62
IDLE
= 0,
// No frame has been found yet
63
PARSING
,
// Currently paring a frame
64
SUCCESS
,
// A frame has been parsed successfully
65
FAIL
// The parsed frame was invalid (eg wrong length, wrong checksum)
66
};
67
68
APIFrameParser
();
69
79
ParseResult
parse
(uint8_t
byte
,
APIFrame
* frame);
80
84
ParserState
getParserState
() {
return
parserState; }
85
86
private
:
87
ParserState
parserState =
ParserState::FIND_START
;
88
uint16_t currentFrameDataIndex = 0;
89
90
PrintLogger
logger =
Logging::getLogger
(
"apiframeparser"
);
91
};
92
93
}
// namespace Xbee
94
95
}
// namespace Boardcore
APIFrames.h
PrintLogger.h
Boardcore::Logging::getLogger
static PrintLogger getLogger(const string &name)
Definition
PrintLogger.h:103
Boardcore::PrintLogger
Definition
PrintLogger.h:58
Boardcore::Xbee::APIFrameParser
Parses a byte sequence into an Xbee APIFrame.
Definition
APIFrameParser.h:41
Boardcore::Xbee::APIFrameParser::ParserState
ParserState
Current state of the parser internal state machine.
Definition
APIFrameParser.h:47
Boardcore::Xbee::APIFrameParser::ParserState::READ_FRAME_DATA
@ READ_FRAME_DATA
Boardcore::Xbee::APIFrameParser::ParserState::READ_FRAME_TYPE
@ READ_FRAME_TYPE
Boardcore::Xbee::APIFrameParser::ParserState::READ_LENGTH_1
@ READ_LENGTH_1
Boardcore::Xbee::APIFrameParser::ParserState::READ_CHECKSUM
@ READ_CHECKSUM
Boardcore::Xbee::APIFrameParser::ParserState::READ_LENGTH_2
@ READ_LENGTH_2
Boardcore::Xbee::APIFrameParser::ParserState::FIND_START
@ FIND_START
Boardcore::Xbee::APIFrameParser::ParseResult
ParseResult
Result of the last parse operation.
Definition
APIFrameParser.h:61
Boardcore::Xbee::APIFrameParser::ParseResult::IDLE
@ IDLE
Boardcore::Xbee::APIFrameParser::ParseResult::FAIL
@ FAIL
Boardcore::Xbee::APIFrameParser::ParseResult::SUCCESS
@ SUCCESS
Boardcore::Xbee::APIFrameParser::ParseResult::PARSING
@ PARSING
Boardcore::Xbee::APIFrameParser::getParserState
ParserState getParserState()
Returns the current state of the parser.
Definition
APIFrameParser.h:84
Boardcore::Xbee::APIFrameParser::APIFrameParser
APIFrameParser()
Definition
APIFrameParser.cpp:33
Boardcore::Xbee::APIFrameParser::parse
ParseResult parse(uint8_t byte, APIFrame *frame)
Parses a single byte. When this function returns ParseResult:SUCESS, frame contains a valid APIFrame.
Definition
APIFrameParser.cpp:35
Boardcore
This file includes all the types the logdecoder script will decode.
Definition
ActiveObject.h:31
Boardcore::Xbee::APIFrame
Definition
APIFrames.h:139
src
shared
radio
Xbee
APIFrameParser.h
Generated by
1.10.0