forked from bambulab/BambuStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbambu_networking.hpp
239 lines (210 loc) · 11.5 KB
/
bambu_networking.hpp
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef __BAMBU_NETWORKING_HPP__
#define __BAMBU_NETWORKING_HPP__
#include <string>
#include <functional>
#include <map>
extern std::string g_log_folder;
extern std::string g_log_start_time;
namespace BBL {
#define BAMBU_NETWORK_SUCCESS 0
#define BAMBU_NETWORK_ERR_INVALID_HANDLE -1
#define BAMBU_NETWORK_ERR_CONNECT_FAILED -2
#define BAMBU_NETWORK_ERR_DISCONNECT_FAILED -3
#define BAMBU_NETWORK_ERR_SEND_MSG_FAILED -4
#define BAMBU_NETWORK_ERR_BIND_FAILED -5
#define BAMBU_NETWORK_ERR_UNBIND_FAILED -6
#define BAMBU_NETWORK_ERR_REQUEST_SETTING_FAILED -7
#define BAMBU_NETWORK_ERR_PUT_SETTING_FAILED -8
#define BAMBU_NETWORK_ERR_GET_SETTING_LIST_FAILED -9
#define BAMBU_NETWORK_ERR_DEL_SETTING_FAILED -10
#define BAMBU_NETWORK_ERR_GET_USER_PRINTINFO_FAILED -11
#define BAMBU_NETWORK_ERR_QUERY_BIND_INFO_FAILED -12
#define BAMBU_NETWORK_ERR_MODIFY_PRINTER_NAME_FAILED -13
#define BAMBU_NETWORK_ERR_FILE_NOT_EXIST -14
#define BAMBU_NETWORK_ERR_FILE_OVER_SIZE -15
#define BAMBU_NETWORK_ERR_CHECK_MD5_FAILED -16
#define BAMBU_NETWORK_ERR_TIMEOUT -17
#define BAMBU_NETWORK_ERR_CANCELED -18
#define BAMBU_NETWORK_ERR_INVALID_RESULT -19
#define BAMBU_NETWORK_ERR_FTP_UPLOAD_FAILED -20
#define BAMBU_NETWORK_ERR_GET_RATING_ID_FAILED -21
#define BAMBU_NETWORK_ERR_OPEN_FILE_FAILED -22
#define BAMBU_NETWORK_ERR_PARSE_CONFIG_FAILED -23
#define BAMBU_NETWORK_ERR_NO_CORRESPONDING_BUCKET -24
#define BAMBU_NETWORK_ERR_GET_INSTANCE_ID_FAILED -25
//bind error
#define BAMBU_NETWORK_ERR_BIND_CREATE_SOCKET_FAILED -1010 //failed to create socket
#define BAMBU_NETWORK_ERR_BIND_SOCKET_CONNECT_FAILED -1020 //failed to socket connect
#define BAMBU_NETWORK_ERR_BIND_PUBLISH_LOGIN_REQUEST -1030 //failed to publish login request
#define BAMBU_NETWORK_ERR_BIND_GET_PRINTER_TICKET_TIMEOUT -1040 //timeout to get ticket from printer
#define BAMBU_NETWORK_ERR_BIND_GET_CLOUD_TICKET_TIMEOUT -1050 //timeout to get ticket from cloud server
#define BAMBU_NETWORK_ERR_BIND_POST_TICKET_TO_CLOUD_FAILED -1060 //failed to post ticket to cloud server
#define BAMBU_NETWORK_ERR_BIND_PARSE_LOGIN_REPORT_FAILED -1070 //failed to parse login report reason no error code
#define BAMBU_NETWORK_ERR_BIND_ECODE_LOGIN_REPORT_FAILED -1080 //failed to parse login report reason has error code
#define BAMBU_NETWORK_ERR_BIND_RECEIVE_LOGIN_REPORT_TIMEOUT -1090 //timeout to receive login report
//start_local_print_with_record error
#define BAMBU_NETWORK_ERR_PRINT_WR_REQUEST_PROJECT_ID_FAILED -2010 //failed to request project id
#define BAMBU_NETWORK_ERR_PRINT_WR_CHECK_MD5_FAILED -2020 //failed to check md5 for upload 3mf to oss
#define BAMBU_NETWORK_ERR_PRINT_WR_UPLOAD_3MF_CONFIG_TO_OSS_FAILED -2030 //failed to upload 3mf config to oss
#define BAMBU_NETWORK_ERR_PRINT_WR_FILE_OVER_SIZE -2040 //the size of the uploaded file cannot exceed 1 GB
#define BAMBU_NETWORK_ERR_PRINT_WR_PUT_NOTIFICATION_FAILED -2050 //timeout to get notification
#define BAMBU_NETWORK_ERR_PRINT_WR_GET_NOTIFICATION_TIMEOUT -2060 //timeout to get notification
#define BAMBU_NETWORK_ERR_PRINT_WR_GET_NOTIFICATION_FAILED -2070 //failed to get notification
#define BAMBU_NETWORK_ERR_PRINT_WR_PATCH_PROJECT_FAILED -2080 //failed to patch project
#define BAMBU_NETWORK_ERR_PRINT_WR_GET_MY_SETTING_FAILED -2090 //failed to get my setting
#define BAMBU_NETWORK_ERR_PRINT_WR_FILE_NOT_EXIST -2100 //3mf file is not exists
#define BAMBU_NETWORK_ERR_PRINT_WR_UPLOAD_3MF_TO_OSS_FAILED -2110 //failed to upload 3mf to oss
#define BAMBU_NETWORK_ERR_PRINT_WR_POST_TASK_FAILED -2120 //failed to post task
#define BAMBU_NETWORK_ERR_PRINT_WR_UPLOAD_FTP_FAILED -2130 //failed to upload to ftp
#define BAMBU_NETWORK_ERR_PRINT_WR_GET_USER_UPLOAD_FAILED -2140 //failed to get_user_upload
//start_print error
#define BAMBU_NETWORK_ERR_PRINT_SP_REQUEST_PROJECT_ID_FAILED -3010 //failed to request project id
#define BAMBU_NETWORK_ERR_PRINT_SP_CHECK_MD5_FAILED -3020 //failed to check md5 for upload 3mf to oss
#define BAMBU_NETWORK_ERR_PRINT_SP_UPLOAD_3MF_CONFIG_TO_OSS_FAILED -3030 //failed to upload 3mf config to oss
#define BAMBU_NETWORK_ERR_PRINT_SP_PUT_NOTIFICATION_FAILED -3040 //failed to put notification
#define BAMBU_NETWORK_ERR_PRINT_SP_GET_NOTIFICATION_TIMEOUT -3050 //timeout to get notification
#define BAMBU_NETWORK_ERR_PRINT_SP_GET_NOTIFICATION_FAILED -3060 //failed to get notification
#define BAMBU_NETWORK_ERR_PRINT_SP_FILE_NOT_EXIST -3070 //3mf file is not exists
#define BAMBU_NETWORK_ERR_PRINT_SP_GET_USER_UPLOAD_FAILED -3080 //failed to get_user_upload
#define BAMBU_NETWORK_ERR_PRINT_SP_FILE_OVER_SIZE -3090 //the size of the uploaded file cannot exceed 1 GB
#define BAMBU_NETWORK_ERR_PRINT_SP_UPLOAD_3MF_TO_OSS_FAILED -3100 //failed to upload 3mf to oss
#define BAMBU_NETWORK_ERR_PRINT_SP_PATCH_PROJECT_FAILED -3110 //failed to patch project
#define BAMBU_NETWORK_ERR_PRINT_SP_POST_TASK_FAILED -3120 //failed to post task
#define BAMBU_NETWORK_ERR_PRINT_SP_WAIT_PRINTER_FAILED -3130 //failed to wait the ack from printer
//start_local_print error
#define BAMBU_NETWORK_ERR_PRINT_LP_FILE_OVER_SIZE -4010 //the size of the uploaded file cannot exceed 1 GB
#define BAMBU_NETWORK_ERR_PRINT_LP_UPLOAD_FTP_FAILED -4020 //failed to upload ftp
#define BAMBU_NETWORK_ERR_PRINT_LP_PUBLISH_MSG_FAILED -4030 //failed to send mqtt message to device
//start_send_gcode_to_sdcard error
#define BAMBU_NETWORK_ERR_PRINT_SG_UPLOAD_FTP_FAILED -5010 //failed to upload ftp
//connection to printer failed
#define BAMBU_NETWORK_ERR_CONNECTION_TO_PRINTER_FAILED -6010 //Connection to printer failed
#define BAMBU_NETWORK_ERR_CONNECTION_TO_SERVER_FAILED -6020 //Connection to server failed
#define BAMBU_NETWORK_LIBRARY "bambu_networking"
#define BAMBU_NETWORK_AGENT_NAME "bambu_network_agent"
#define BAMBU_NETWORK_AGENT_VERSION "01.07.09.02"
//iot preset type strings
#define IOT_PRINTER_TYPE_STRING "printer"
#define IOT_FILAMENT_STRING "filament"
#define IOT_PRINT_TYPE_STRING "print"
#define IOT_JSON_KEY_VERSION "version"
#define IOT_JSON_KEY_NAME "name"
#define IOT_JSON_KEY_TYPE "type"
#define IOT_JSON_KEY_UPDATE_TIME "updated_time"
#define IOT_JSON_KEY_BASE_ID "base_id"
#define IOT_JSON_KEY_SETTING_ID "setting_id"
#define IOT_JSON_KEY_FILAMENT_ID "filament_id"
#define IOT_JSON_KEY_USER_ID "user_id"
#define IOT_JSON_KEY_SIGN_DATE "sign_date"
#define IOT_JSON_KEY_CERT_START_DATE "cert_start_date"
#define IOT_JSON_KEY_CERT_END_DATE "cert_end_date"
#define IOT_JSON_KEY_CERT_ISSUE_NAME "issue_name"
#define IOT_JSON_KEY_CERT_SUBJECT_NAME "subject_name"
#define IOT_JSON_KEY_CERT_SERIAL_NUMBER "serial_number"
#define IOT_JSON_KEY_CERT_HASH_VALUE "hash_value"
#define IOT_JSON_KEY_CERT_VERIFY_RESULT "verify_result"
#define EMBEDDED_ISSUER_NAME "GlobalSign GCC R45 EV CodeSigning CA 2020"
#define EMBEDDED_SUBJECT_NAME "Shenzhen Tuozhu Technology Co., Ltd."
#define EMBEDDED_SERIAL_NAME "0b209295a54b188466ad7478"
#define EMBEDDED_HASH_NAME "9690647085f910ffe2098129bc1229956a51e250"
// user callbacks
typedef std::function<void(int online_login, bool login)> OnUserLoginFn;
// printer callbacks
typedef std::function<void(std::string topic_str)> OnPrinterConnectedFn;
typedef std::function<void(int status, std::string dev_id, std::string msg)> OnLocalConnectedFn;
typedef std::function<void(int return_code, int reason_code)> OnServerConnectedFn;
typedef std::function<void(std::string dev_id, std::string msg)> OnMessageFn;
// http callbacks
typedef std::function<void(unsigned http_code, std::string http_body)> OnHttpErrorFn;
typedef std::function<std::string()> GetCountryCodeFn;
typedef std::function<void(std::string topic)> GetSubscribeFailureFn;
// print callbacks
typedef std::function<void(int status, int code, std::string msg)> OnUpdateStatusFn;
typedef std::function<bool()> WasCancelledFn;
typedef std::function<bool(int status, std::string job_info)> OnWaitFn;
// local callbacks
typedef std::function<void(std::string dev_info_json_str)> OnMsgArrivedFn;
// queue call to main thread
typedef std::function<void(std::function<void()>)> QueueOnMainFn;
typedef std::function<void(int progress)> ProgressFn;
typedef std::function<void(int retcode, std::string info)> LoginFn;
typedef std::function<void(int result, std::string info)> ResultFn;
typedef std::function<bool()> CancelFn;
typedef std::function<bool(std::map<std::string, std::string> info)> CheckFn;
enum SendingPrintJobStage {
PrintingStageCreate = 0,
PrintingStageUpload = 1,
PrintingStageWaiting = 2,
PrintingStageSending = 3,
PrintingStageRecord = 4,
PrintingStageWaitPrinter = 5,
PrintingStageFinished = 6,
PrintingStageERROR = 7,
};
enum PublishingStage {
PublishingCreate = 0,
PublishingUpload = 1,
PublishingWaiting = 2,
PublishingJumpUrl = 3,
};
enum BindJobStage {
LoginStageConnect = 0,
LoginStageLogin = 1,
LoginStageWaitForLogin = 2,
LoginStageGetIdentify = 3,
LoginStageWaitAuth = 4,
LoginStageFinished = 5,
};
enum ConnectStatus {
ConnectStatusOk = 0,
ConnectStatusFailed = 1,
ConnectStatusLost = 2,
};
/* print job*/
struct PrintParams {
/* basic info */
std::string dev_id;
std::string task_name;
std::string project_name;
std::string preset_name;
std::string filename;
std::string config_filename;
int plate_index;
std::string ftp_folder;
std::string ftp_file;
std::string ftp_file_md5;
std::string ams_mapping;
std::string ams_mapping_info;
std::string connection_type;
std::string comments;
int origin_profile_id = 0;
int stl_design_id = 0;
std::string origin_model_id;
std::string print_type;
std::string dst_file;
/* access options */
std::string dev_ip;
bool use_ssl_for_ftp;
bool use_ssl_for_mqtt;
std::string username;
std::string password;
/*user options */
bool task_bed_leveling; /* bed leveling of task */
bool task_flow_cali; /* flow calibration of task */
bool task_vibration_cali; /* vibration calibration of task */
bool task_layer_inspect; /* first layer inspection of task */
bool task_record_timelapse; /* record timelapse of task */
bool task_use_ams;
std::string task_bed_type;
std::string extra_options;
};
struct PublishParams {
std::string project_name;
std::string project_3mf_file;
std::string preset_name;
std::string project_model_id;
std::string design_id;
std::string config_filename;
};
}
#endif