-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMsgPacketizer.h
More file actions
126 lines (110 loc) · 3.42 KB
/
MsgPacketizer.h
File metadata and controls
126 lines (110 loc) · 3.42 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#ifndef HT_SERIAL_MSGPACKETIZER_H
#define HT_SERIAL_MSGPACKETIZER_H
#if defined(ARDUINO) || defined(OF_VERSION_MAJOR) || defined(SERIAL_H)
#define MSGPACKETIZER_ENABLE_STREAM
#ifdef ARDUINO // TODO: support more platforms
#if defined(ESP_PLATFORM) || defined(ESP8266) || defined(ARDUINO_AVR_UNO_WIFI_REV2) \
|| defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_SAMD_MKR1000) \
|| defined(ARDUINO_SAMD_NANO_33_IOT)
#define MSGPACKETIZER_ENABLE_WIFI
#endif
#if defined(ESP_PLATFORM) || defined(ESP8266) || !defined(MSGPACKETIZER_ENABLE_WIFI)
#define MSGPACKETIZER_ENABLE_ETHER
#endif
#endif
#endif
#ifdef MSGPACKETIZER_DISABLE_NETWORK
#define PACKETIZER_DISABLE_NETWORK
#else
#if defined(MSGPACKETIZER_ENABLE_ETHER) || defined(MSGPACKETIZER_ENABLE_WIFI)
#define MSGPACKETIZER_ENABLE_NETWORK
#include <Udp.h>
#include <Client.h>
#endif
#endif // MSGPACKETIZER_DISABLE_NETWORK
#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11
// use standard c++ libraries
#else
#ifndef MSGPACKETIZER_MAX_PUBLISH_ELEMENT_SIZE
#define MSGPACKETIZER_MAX_PUBLISH_ELEMENT_SIZE 5
#endif
#ifndef MSGPACKETIZER_MAX_PUBLISH_DESTINATION_SIZE
#define MSGPACKETIZER_MAX_PUBLISH_DESTINATION_SIZE 2
#endif
#ifndef MSGPACK_MAX_PACKET_BYTE_SIZE
#define MSGPACK_MAX_PACKET_BYTE_SIZE 96
#endif
#ifndef MSGPACK_MAX_ARRAY_SIZE
#define MSGPACK_MAX_ARRAY_SIZE 3
#endif
#ifndef MSGPACK_MAX_MAP_SIZE
#define MSGPACK_MAX_MAP_SIZE 3
#endif
#ifndef MSGPACK_MAX_OBJECT_SIZE
#define MSGPACK_MAX_OBJECT_SIZE 16
#endif
#ifndef PACKETIZER_MAX_PACKET_QUEUE_SIZE
#define PACKETIZER_MAX_PACKET_QUEUE_SIZE 1
#endif
#ifndef PACKETIZER_MAX_PACKET_BINARY_SIZE
#define PACKETIZER_MAX_PACKET_BINARY_SIZE 96
#endif
#ifndef PACKETIZER_MAX_CALLBACK_QUEUE_SIZE
#define PACKETIZER_MAX_CALLBACK_QUEUE_SIZE 3
#endif
#ifndef PACKETIZER_MAX_STREAM_MAP_SIZE
#define PACKETIZER_MAX_STREAM_MAP_SIZE 1
#endif
#endif // have libstdc++11
#define PACKETIZER_USE_INDEX_AS_DEFAULT
#define PACKETIZER_USE_CRC_AS_DEFAULT
#include <DebugLog.h>
#ifdef MSGPACKETIZER_DEBUGLOG_ENABLE
#include <DebugLogEnable.h>
#define MSGPACK_DEBUGLOG_ENABLE
#else
#include <DebugLogDisable.h>
#endif
#include <Packetizer.h>
#include <MsgPack.h>
namespace arduino {
namespace msgpack {
namespace msgpacketizer {
#ifdef ARDUINO
using StreamType = Stream;
#define MSGPACKETIZER_ELAPSED_MICROS micros
#elif defined(OF_VERSION_MAJOR)
using StreamType = ofSerial;
#define MSGPACKETIZER_ELAPSED_MICROS ofGetElapsedTimeMicros
#elif defined(SERIAL_H)
#include "serial/serial.h"
using StreamType = ::serial::Serial;
#include <chrono>
using namespace std::chrono;
steady_clock::time_point time_start {steady_clock::now()};
#define MSGPACKETIZER_ELAPSED_MICROS() duration_cast<microseconds>(steady_clock::now() - time_start).count()
#endif
#ifdef ARDUINO
using str_t = String;
#else
using str_t = std::string;
#ifndef F
inline const char* F(const char* c) {
return c;
}
#endif
#endif
enum class TargetStreamType : uint8_t {
STREAM_SERIAL,
STREAM_UDP,
STREAM_TCP,
};
} // namespace msgpacketizer
} // namespace msgpack
} // namespace arduino
#include "MsgPacketizer/Publisher.h"
#include "MsgPacketizer/Subscriber.h"
namespace MsgPacketizer = arduino::msgpack::msgpacketizer;
#include <DebugLogRestoreState.h>
#endif // HT_SERIAL_MSGPACKETIZER_H