forked from arduino-libraries/ArduinoIoTCloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageDecoder.h
75 lines (57 loc) · 2.22 KB
/
MessageDecoder.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
This file is part of the ArduinoIoTCloud library.
Copyright (c) 2024 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef ARDUINO_CBOR_MESSAGE_DECODER_H_
#define ARDUINO_CBOR_MESSAGE_DECODER_H_
/******************************************************************************
INCLUDE
******************************************************************************/
#include <Arduino.h>
#undef max
#undef min
#include <list>
#include "CBOR.h"
#include "../interfaces/Decoder.h"
#include <Arduino_TinyCBOR.h>
/******************************************************************************
CLASS DECLARATION
******************************************************************************/
class CBORMessageDecoder: public Decoder
{
public:
CBORMessageDecoder() { }
CBORMessageDecoder(CBORMessageDecoder const &) { }
/* decode a CBOR payload received from the cloud */
Decoder::Status decode(Message * msg, uint8_t const * const payload, size_t& length);
private:
enum class DecoderState {
Success,
MessageNotSupported,
MalformedMessage,
Error
};
enum class ArrayParserState {
EnterArray,
ParseParam,
LeaveArray,
Complete,
Error,
MessageNotSupported
};
ArrayParserState handle_EnterArray(CborValue * main_iter, CborValue * array_iter);
ArrayParserState handle_Param(CborValue * param, Message * message);
ArrayParserState handle_LeaveArray(CborValue * main_iter, CborValue * array_iter);
bool ifNumericConvertToDouble(CborValue * value_iter, double * numeric_val);
double convertCborHalfFloatToDouble(uint16_t const half_val);
// Message specific decoders
ArrayParserState decodeThingUpdateCmd(CborValue * param, Message * message);
ArrayParserState decodeThingDetachCmd(CborValue * param, Message * message);
ArrayParserState decodeTimezoneCommandDown(CborValue * param, Message * message);
ArrayParserState decodeLastValuesUpdateCmd(CborValue * param, Message * message);
ArrayParserState decodeOtaUpdateCmdDown(CborValue * param, Message * message);
};
#endif /* ARDUINO_CBOR_MESSAGE_DECODER_H_ */