-
Notifications
You must be signed in to change notification settings - Fork 1
/
remote-mgmt.h
162 lines (141 loc) · 4.41 KB
/
remote-mgmt.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef REMOTE_MGMGT_H
#define REMOTE_MGMGT_H
#include <cstdint>
#include <string>
#include <memory>
#include "ei_device_info_lib.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
DECODE_OK = 0,
ERR_MAP_EXPECTED,
ERR_UNKNOWN_FIELD,
ERR_UNEXPECTED_TYPE,
ERR_UNEXPECTED_VALUE,
ERR_UNKNOWN
} decode_result_t;
enum class MessageType {
DecoderErrorType,
HelloResponseType,
ErrorResponseType,
SampleRequestType,
StreamingStartRequestType,
StreamingStopRequestType,
};
class DecodedMessage {
public:
virtual ~DecodedMessage() {}
virtual MessageType getType() const = 0;
};
class DecoderError : public DecodedMessage {
public:
decode_result_t err_code;
std::string err_message;
virtual MessageType getType() const override {
return MessageType::DecoderErrorType;
}
};
class HelloResponse : public DecodedMessage {
public:
bool status;
std::string err_message;
virtual MessageType getType() const override {
return MessageType::HelloResponseType;
}
};
class ErrorResponse : public DecodedMessage {
public:
std::string err_message;
virtual MessageType getType() const override {
return MessageType::ErrorResponseType;
}
};
class SampleRequest : public DecodedMessage {
public:
std::string sensor;
virtual MessageType getType() const override {
return MessageType::SampleRequestType;
}
};
class StreamingStartRequest : public DecodedMessage {
public:
bool status;
virtual MessageType getType() const override {
return MessageType::StreamingStartRequestType;
}
};
class StreamingStopRequest : public DecodedMessage {
public:
bool status;
virtual MessageType getType() const override {
return MessageType::StreamingStopRequestType;
}
};
/**
* @brief This message should be sent after receiving SampleRequest (it is ack message)
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @return actual message length
*/
int get_sample_start_msg(uint8_t* buf, size_t buf_len);
/**
* @brief This message should be sent after receiving SampleRequest
* if there is any error on the device side (e.g. sensor error etc.)
* Put an error description in the msg argument
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @param msg Error message
* @return actual message length
*/
int get_sample_failed_msg(uint8_t* buf, size_t buf_len, const char* error_msg);
/**
* @brief This message should be sent right after starting sampling
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @return actual message length
*/
int get_sample_started_msg(uint8_t* buf, size_t buf_len);
/**
* @brief Send this message if the device is done sampling, but is processing the sample before
* uploading, such as a device preprocessing audio or signing the file.
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @return actual message length
*/
int get_sample_processing_msg(uint8_t* buf, size_t buf_len);
/**
* @brief Send this message before you start the upload of sample to ingestion service
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @return actual message length
*/
int get_sample_uploading_msg(uint8_t* buf, size_t buf_len);
/**
* @brief Send this message after the sample has been uploaded to ingestion service
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @return actual message length
*/
int get_sample_finished_msg(uint8_t* buf, size_t buf_len);
/**
* @brief Create a message with base64 encoded snapshot frame
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @param frame Base64 encoded snapshot frame
* @return actual message length
*/
int get_snapshot_frame_msg(uint8_t* buf, size_t buf_len, const char* frame);
/**
* @brief Create a hello message (send as a first message to Remote Management Service)
* @param buf Buffer to write the message to
* @param buf_len Length of the buffer
* @param device device instance, the required data will be extracted from this instance
* @return actual message length
*/
int get_hello_msg(uint8_t* buf, size_t buf_len, EiDeviceInfo* device);
std::unique_ptr<DecodedMessage> decode_message(const uint8_t* buf, size_t buf_len, EiDeviceInfo *device);
#ifdef __cplusplus
};
#endif
#endif /* REMOTE_MGMGT_H */