/
AppUartAsciiExtendedPacketParser.h
52 lines (45 loc) · 1.65 KB
/
AppUartAsciiExtendedPacketParser.h
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
/**
* @file AppUartAsciiExtendedPacketParser.h
* @brief App_Uart (Mode A) extended packet parser for MWings.
*
* Copyright (C) 2023 Mono Wireless Inc. All Rights Reserved.
* Released under MW-OSSLA-1J,1E (MONO WIRELESS OPEN SOURCE SOFTWARE LICENSE AGREEMENT).
*/
#ifndef APPUARTASCIIEXTENDEDPACKETPARSER_H
#define APPUARTASCIIEXTENDEDPACKETPARSER_H
#include "MWings_Common.h"
/**
* @struct ParsedAppUartAsciiExtendedPacket
* @brief Extended packet content for App_Uart (Mode A)
*/
struct ParsedAppUartAsciiExtendedPacket final : public mwings::ParsedPacketBase {
uint32_t u32DestinationSerialId;
uint8_t u8CommandId;
uint8_t* u8Data;
uint16_t u16DataSize;
};
/**
* @class appuartascii::ExtendedPacketParser
* @brief Extended packet parser for App_Uart (Mode A)
*/
namespace appuartascii {
class ExtendedPacketParser final : public mwings::PacketParserBase {
public:
// Check if the packet is from App_Uart (Mode A)
inline bool isValid(const BarePacket& barePacket) const override {
if (((0x00 <= barePacket.u8At(0) and barePacket.u8At(0) <= 0x64)
or barePacket.u8At(0) == 0x78)
and barePacket.u8At(1) == 0xA0
and barePacket.u8At(2) < 0x80
and (barePacket.u8At(3) & 0x80) == 0x80
and barePacket.u16At(12) == barePacket.u16PayloadSize - 14) {
return true;
}
return false;
}
// Parse from bare packet
bool parse(const BarePacket& barePacket, mwings::ParsedPacketBase* const parsedPacket) const override;
};
}
extern appuartascii::ExtendedPacketParser AppUartAsciiExtendedPacketParser;
#endif // APPUARTASCIIEXTENDEDPACKETPARSER_H