Prusa MINI Firmware overview
binary_protocol.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 #include "../inc/MarlinConfig.h"
25 
26 #define BINARY_STREAM_COMPRESSION
27 
28 #if ENABLED(BINARY_STREAM_COMPRESSION)
29  #include "../libs/heatshrink/heatshrink_decoder.h"
30 #endif
31 
32 inline bool bs_serial_data_available(const uint8_t index) {
33  switch (index) {
34  case 0: return MYSERIAL0.available();
35  #if NUM_SERIAL > 1
36  case 1: return MYSERIAL1.available();
37  #endif
38  }
39  return false;
40 }
41 
42 inline int bs_read_serial(const uint8_t index) {
43  switch (index) {
44  case 0: return MYSERIAL0.read();
45  #if NUM_SERIAL > 1
46  case 1: return MYSERIAL1.read();
47  #endif
48  }
49  return -1;
50 }
51 
52 #if ENABLED(BINARY_STREAM_COMPRESSION)
54  static uint8_t decode_buffer[512] = {};
55 #endif
56 
58 private:
59  struct Packet {
60  struct [[gnu::packed]] Open {
61  static bool validate(char* buffer, size_t length) {
62  return (length > sizeof(Open) && buffer[length - 1] == '\0');
63  }
64  static Open& decode(char* buffer) {
65  data = &buffer[2];
66  return *reinterpret_cast<Open*>(buffer);
67  }
68  bool compression_enabled() { return compression & 0x1; }
69  bool dummy_transfer() { return dummy & 0x1; }
70  static char* filename() { return data; }
71  private:
72  uint8_t dummy, compression;
73  static char* data; // variable length strings complicate things
74  };
75  };
76 
77  static bool file_open(char* filename) {
78  if (!dummy_transfer) {
79  card.mount();
80  card.openFile(filename, false);
81  if (!card.isFileOpen()) return false;
82  }
83  transfer_active = true;
84  data_waiting = 0;
85  #if ENABLED(BINARY_STREAM_COMPRESSION)
87  #endif
88  return true;
89  }
90 
91  static bool file_write(char* buffer, const size_t length) {
92  #if ENABLED(BINARY_STREAM_COMPRESSION)
93  if (compression) {
94  size_t total_processed = 0, processed_count = 0;
95  HSD_poll_res presult;
96 
97  while (total_processed < length) {
98  heatshrink_decoder_sink(&hsd, reinterpret_cast<uint8_t*>(&buffer[total_processed]), length - total_processed, &processed_count);
99  total_processed += processed_count;
100  do {
101  presult = heatshrink_decoder_poll(&hsd, &decode_buffer[data_waiting], sizeof(decode_buffer) - data_waiting, &processed_count);
102  data_waiting += processed_count;
103  if (data_waiting == sizeof(decode_buffer)) {
104  if (!dummy_transfer)
105  if (card.write(decode_buffer, data_waiting) < 0) {
106  return false;
107  }
108  data_waiting = 0;
109  }
110  } while (presult == HSDR_POLL_MORE);
111  }
112  return true;
113  }
114  #endif
115  return (dummy_transfer || card.write(buffer, length) >= 0);
116  }
117 
118  static bool file_close() {
119  if (!dummy_transfer) {
120  #if ENABLED(BINARY_STREAM_COMPRESSION)
121  // flush any buffered data
122  if (data_waiting) {
123  if (card.write(decode_buffer, data_waiting) < 0) return false;
124  data_waiting = 0;
125  }
126  #endif
127  card.closefile();
128  card.release();
129  }
130  #if ENABLED(BINARY_STREAM_COMPRESSION)
132  #endif
133  transfer_active = false;
134  return true;
135  }
136 
137  static void transfer_abort() {
138  if (!dummy_transfer) {
139  card.closefile();
140  card.removeFile(card.filename);
141  card.release();
142  #if ENABLED(BINARY_STREAM_COMPRESSION)
144  #endif
145  }
146  transfer_active = false;
147  return;
148  }
149 
150  enum class FileTransfer : uint8_t { QUERY, OPEN, CLOSE, WRITE, ABORT };
151 
152  static size_t data_waiting, transfer_timeout, idle_timeout;
153  static bool transfer_active, dummy_transfer, compression;
154 
155 public:
156 
157  static void idle() {
158  // If a transfer is interrupted and a file is left open, abort it after TIMEOUT ms
159  const millis_t ms = millis();
160  if (transfer_active && ELAPSED(ms, idle_timeout)) {
161  idle_timeout = ms + IDLE_PERIOD;
162  if (ELAPSED(ms, transfer_timeout)) transfer_abort();
163  }
164  }
165 
166  static void process(uint8_t packet_type, char* buffer, const uint16_t length) {
167  transfer_timeout = millis() + TIMEOUT;
168  switch (static_cast<FileTransfer>(packet_type)) {
169  case FileTransfer::QUERY:
170  SERIAL_ECHOPAIR("PFT:version:", VERSION_MAJOR, ".", VERSION_MINOR, ".", VERSION_PATCH);
171  #if ENABLED(BINARY_STREAM_COMPRESSION)
173  #else
174  SERIAL_ECHOLNPGM(":compresion:none");
175  #endif
176  break;
177  case FileTransfer::OPEN:
178  if (transfer_active)
179  SERIAL_ECHOLNPGM("PFT:busy");
180  else {
181  if (Packet::Open::validate(buffer, length)) {
182  auto packet = Packet::Open::decode(buffer);
183  compression = packet.compression_enabled();
184  dummy_transfer = packet.dummy_transfer();
185  if (file_open(packet.filename())) {
186  SERIAL_ECHOLNPGM("PFT:success");
187  break;
188  }
189  }
190  SERIAL_ECHOLNPGM("PFT:fail");
191  }
192  break;
193  case FileTransfer::CLOSE:
194  if (transfer_active) {
195  if (file_close())
196  SERIAL_ECHOLNPGM("PFT:success");
197  else
198  SERIAL_ECHOLNPGM("PFT:ioerror");
199  }
200  else SERIAL_ECHOLNPGM("PFT:invalid");
201  break;
202  case FileTransfer::WRITE:
203  if (!transfer_active)
204  SERIAL_ECHOLNPGM("PFT:invalid");
205  else if (!file_write(buffer, length))
206  SERIAL_ECHOLNPGM("PFT:ioerror");
207  break;
208  case FileTransfer::ABORT:
209  transfer_abort();
210  SERIAL_ECHOLNPGM("PFT:success");
211  break;
212  default:
213  SERIAL_ECHOLNPGM("PTF:invalid");
214  break;
215  }
216  }
217 
218  static const uint16_t VERSION_MAJOR = 0, VERSION_MINOR = 1, VERSION_PATCH = 0, TIMEOUT = 10000, IDLE_PERIOD = 1000;
219 };
220 
222 public:
224 
225  enum class ProtocolControl : uint8_t { SYNC = 1, CLOSE };
226 
229 
230  struct Packet { // 10 byte protocol overhead, ascii with checksum and line number has a minimum of 7 increasing with line
231 
232  union Header {
233  static constexpr uint16_t HEADER_TOKEN = 0xB5AD;
234  struct [[gnu::packed]] {
235  uint16_t token; // packet start token
236  uint8_t sync; // stream sync, resend id and packet loss detection
237  uint8_t meta; // 4 bit protocol,
238  // 4 bit packet type
239  uint16_t size; // data length
240  uint16_t checksum; // header checksum
241  };
242  uint8_t protocol() { return (meta >> 4) & 0xF; }
243  uint8_t type() { return meta & 0xF; }
244  void reset() { token = 0; sync = 0; meta = 0; size = 0; checksum = 0; }
246  };
247 
248  union Footer {
249  struct [[gnu::packed]] {
250  uint16_t checksum; // full packet checksum
251  };
252  void reset() { checksum = 0; }
254  };
255 
258  uint32_t bytes_received;
261  char* buffer;
262 
263  void reset() {
264  header.reset();
265  footer.reset();
266  bytes_received = 0;
267  checksum = 0;
268  header_checksum = 0;
270  buffer = nullptr;
271  }
272  } packet{};
273 
274  void reset() {
275  sync = 0;
276  packet_retries = 0;
277  buffer_next_index = 0;
278  }
279 
280  // fletchers 16 checksum
281  uint32_t checksum(uint32_t cs, uint8_t value) {
282  uint16_t cs_low = (((cs & 0xFF) + value) % 255);
283  return ((((cs >> 8) + cs_low) % 255) << 8) | cs_low;
284  }
285 
286  // read the next byte from the data stream keeping track of
287  // whether the stream times out from data starvation
288  // takes the data variable by reference in order to return status
292  return false;
293  }
294  if (!bs_serial_data_available(card.transfer_port_index)) return false;
295  data = bs_read_serial(card.transfer_port_index);
297  return true;
298  }
299 
300  template<const size_t buffer_size>
301  void receive(char (&buffer)[buffer_size]) {
302  uint8_t data = 0;
303  millis_t transfer_window = millis() + RX_TIMESLICE;
304 
305  #if ENABLED(SDSUPPORT)
306  PORT_REDIRECT(card.transfer_port_index);
307  #endif
308 
309  #pragma GCC diagnostic push
310  #pragma GCC diagnostic ignored "-Warray-bounds"
311 
312  while (PENDING(millis(), transfer_window)) {
313  switch (stream_state) {
314  /**
315  * Data stream packet handling
316  */
318  packet.reset();
321  if (!stream_read(data)) { idle(); return; } // no active packet so don't wait
322  packet.header.data[1] = data;
326  }
327  else {
328  // stream corruption drop data
329  packet.header.data[0] = data;
330  }
331  break;
333  if (!stream_read(data)) break;
334 
337 
338  // header checksum calculation can't contain the checksum
339  if (packet.bytes_received == sizeof(Packet::header) - 2)
341 
342  if (packet.bytes_received == sizeof(Packet::header)) {
344  // The SYNC control packet is a special case in that it doesn't require the stream sync to be correct
345  if (static_cast<Protocol>(packet.header.protocol()) == Protocol::CONTROL && static_cast<ProtocolControl>(packet.header.type()) == ProtocolControl::SYNC) {
346  SERIAL_ECHOLNPAIR("ss", sync, ",", buffer_size, ",", VERSION_MAJOR, ".", VERSION_MINOR, ".", VERSION_PATCH);
348  break;
349  }
350  if (packet.header.sync == sync) {
351  buffer_next_index = 0;
353  if (packet.header.size) {
355  packet.buffer = static_cast<char *>(&buffer[0]); // multipacket buffering not implemented, always allocate whole buffer to packet
356  }
357  else
359  }
360  else if (packet.header.sync == sync - 1) { // ok response must have been lost
361  SERIAL_ECHOLNPAIR("ok", packet.header.sync); // transmit valid packet received and drop the payload
363  }
364  else if (packet_retries) {
365  stream_state = StreamState::PACKET_RESET; // could be packets already buffered on flow controlled connections, drop them without ack
366  }
367  else {
368  SERIAL_ECHO_MSG("Datastream packet out of order");
370  }
371  }
372  else {
374  SERIAL_ECHOLNPAIR("Packet header(", packet.header.sync, "?) corrupt");
376  }
377  }
378  break;
380  if (!stream_read(data)) break;
381 
382  if (buffer_next_index < buffer_size)
384  else {
385  SERIAL_ECHO_MSG("Datastream packet data buffer overrun");
387  break;
388  }
389 
393 
397  }
398  break;
400  if (!stream_read(data)) break;
401 
403  if (packet.bytes_received == sizeof(Packet::footer)) {
406  }
407  else {
409  SERIAL_ECHOLNPAIR("Packet(", packet.header.sync, ") payload corrupt");
411  }
412  }
413  break;
415  sync++;
416  packet_retries = 0;
418 
419  SERIAL_ECHOLNPAIR("ok", packet.header.sync); // transmit valid packet received
420  dispatch();
422  break;
424  if (packet_retries < MAX_RETRIES || MAX_RETRIES == 0) {
425  packet_retries++;
428  SERIAL_ECHOLNPAIR("Resend request ", int(packet_retries));
429  SERIAL_ECHOLNPAIR("rs", sync);
430  }
431  else
433  break;
435  SERIAL_ECHO_MSG("Datastream timeout");
437  break;
440  reset(); // reset everything, resync required
442  break;
443  }
444  }
445 
446  #pragma GCC diagnostic pop
447  }
448 
449  void dispatch() {
450  switch(static_cast<Protocol>(packet.header.protocol())) {
451  case Protocol::CONTROL:
452  switch(static_cast<ProtocolControl>(packet.header.type())) {
453  case ProtocolControl::CLOSE: // revert back to ASCII mode
454  card.flag.binary_mode = false;
455  break;
456  default:
457  SERIAL_ECHO_MSG("Unknown BinaryProtocolControl Packet");
458  }
459  break;
461  SDFileTransferProtocol::process(packet.header.type(), packet.buffer, packet.header.size); // send user data to be processed
462  break;
463  default:
464  SERIAL_ECHO_MSG("Unsupported Binary Protocol");
465  }
466  }
467 
468  void idle() {
469  // Some Protocols may need periodic updates without new data
471  }
472 
473  static const uint16_t PACKET_MAX_WAIT = 500, RX_TIMESLICE = 20, MAX_RETRIES = 0, VERSION_MAJOR = 0, VERSION_MINOR = 1, VERSION_PATCH = 0;
476  uint32_t bytes_received;
478 };
479 
SDFileTransferProtocol::Packet::Open::compression_enabled
bool compression_enabled()
Definition: binary_protocol.h:68
WITHIN
#define WITHIN(N, L, H)
Definition: macros.h:195
PENDING
#define PENDING(NOW, SOON)
Definition: millis_t.h:28
XYZval::z
T z
Definition: types.h:286
GET_TEXT
#define GET_TEXT(MSG)
Definition: multi_language.h:72
incremental_LSF
void incremental_LSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z)
Definition: least_squares_fit.h:72
BinaryStream::Packet::Header
Definition: binary_protocol.h:232
SERIAL_CHAR
#define SERIAL_CHAR(x)
Definition: serial.h:69
delta_segments_per_second
float delta_segments_per_second
NOLESS
#define NOLESS(v, n)
Definition: macros.h:127
PORT_REDIRECT
#define PORT_REDIRECT(p)
Definition: serial.h:66
unified_bed_leveling::G29
static void G29() _O0
XYZEval
Definition: types.h:101
X_CENTER
#define X_CENTER
Definition: Conditionals_post.h:76
sq
#define sq(x)
Definition: wiring_constants.h:83
BinaryStream::Packet::header
Header header
Definition: binary_protocol.h:256
XYZEval::z
T z
Definition: types.h:383
Planner::synchronize
static void synchronize()
Definition: planner.cpp:1556
_O2
#define _O2
Definition: macros.h:45
BinaryStream::StreamState::PACKET_DATA
unified_bed_leveling::z_correction_for_y_on_vertical_mesh_line
static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i)
Definition: ubl.h:206
SERIAL_ECHO
#define SERIAL_ECHO(x)
Definition: serial.h:70
bs_read_serial
int bs_read_serial(const uint8_t index)
Definition: binary_protocol.h:42
unified_bed_leveling::mesh_index_to_ypos
static float mesh_index_to_ypos(const uint8_t i)
Definition: ubl.h:290
unified_bed_leveling::adjust_mesh_to_mean
static void adjust_mesh_to_mean(const bool cflag, const float value)
XYZval::x
T x
Definition: types.h:286
DEPLOY_PROBE
#define DEPLOY_PROBE()
Definition: probe.h:60
matrix_3x3::create_look_at
static matrix_3x3 create_look_at(const vector_3 &target)
Definition: vector_3.cpp:114
SDFileTransferProtocol::IDLE_PERIOD
static const uint16_t IDLE_PERIOD
Definition: binary_protocol.h:218
BinaryStream::reset
void reset()
Definition: binary_protocol.h:274
probe_offset
constexpr xyz_pos_t probe_offset
Definition: probe.h:58
MYSERIAL0
#define MYSERIAL0
Definition: HAL.h:89
unified_bed_leveling::z_correction_for_x_on_horizontal_mesh_line
static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi)
Definition: ubl.h:177
binary_protocol.h
PROGMEM
#define PROGMEM
Definition: pgmspace.h:29
BinaryStream::Packet::header_checksum
uint16_t header_checksum
Definition: binary_protocol.h:259
BinaryStream::Packet::Header::size
uint16_t size
Definition: binary_protocol.h:239
settings
MarlinSettings settings
Definition: configuration_store.cpp:344
BinaryStream::StreamState::PACKET_HEADER
unified_bed_leveling::display_map
static void display_map(const int) _O0
RECIPROCAL
#define RECIPROCAL(x)
Definition: macros.h:273
g29_auto.gcode
list gcode
Definition: g29_auto.py:44
unified_bed_leveling::report_state
static void report_state()
DEBUG_EOL
#define DEBUG_EOL()
Definition: debug_out.h:86
DEBUG_ECHOLNPGM
#define DEBUG_ECHOLNPGM(...)
Definition: debug_out.h:79
BinaryStream::StreamState::PACKET_RESEND
heatshrink_decoder_finish
HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd)
Definition: heatshrink_decoder.cpp:325
Planner::buffer_segment
static bool buffer_segment(const float &a, const float &b, const float &c, const float &e, const feedRate_t &fr_mm_s, const uint8_t extruder, const float &millimeters=0.0)
Definition: planner.cpp:2568
_MAX
#define _MAX(V...)
Definition: macros.h:346
BinaryStream::Protocol::FILE_TRANSFER
BinaryStream::Packet::Header::HEADER_TOKEN
static constexpr uint16_t HEADER_TOKEN
Definition: binary_protocol.h:233
do_blocking_move_to_z
void do_blocking_move_to_z(const float &rz, const feedRate_t &fr_mm_s)
Definition: motion.cpp:450
incremental_LSF_reset
void incremental_LSF_reset(struct linear_fit_data *lsf)
Definition: least_squares_fit.h:47
Planner::leveling_active
static bool leveling_active
Definition: planner.h:276
decode_buffer
static uint8_t decode_buffer[512]
Definition: binary_protocol.h:54
PersistentStore::access_finish
static bool access_finish()
SERIAL_ECHOPAIR
#define SERIAL_ECHOPAIR(V...)
Definition: serial.h:114
unified_bed_leveling::reset
static void reset()
BinaryStream::packet_retries
uint8_t packet_retries
Definition: binary_protocol.h:474
do_blocking_move_to_xy_z
void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float &z, const feedRate_t &fr_mm_s)
Definition: motion.cpp:461
type
uint8_t type
Definition: UsbCore.h:184
do_blocking_move_to_xy
void do_blocking_move_to_xy(const float &rx, const float &ry, const feedRate_t &fr_mm_s)
Definition: motion.cpp:454
BinaryStream::ProtocolControl::SYNC
g29_auto.start
start
Definition: g29_auto.py:150
DEBUG_ECHO_F
#define DEBUG_ECHO_F(...)
Definition: debug_out.h:76
vector_3::get_normal
vector_3 get_normal() const
Definition: vector_3.cpp:61
data
uint8_t data[8]
Definition: masstorage.h:49
PGM_P
#define PGM_P
Definition: pgmspace.h:30
XYZEval::e
T e
Definition: types.h:383
BinaryStream::VERSION_MAJOR
static const uint16_t VERSION_MAJOR
Definition: binary_protocol.h:473
PersistentStore::access_start
static bool access_start()
BinaryStream::PACKET_MAX_WAIT
static const uint16_t PACKET_MAX_WAIT
Definition: binary_protocol.h:473
BinaryStream::sync
uint8_t sync
Definition: binary_protocol.h:474
HYPOT2
#define HYPOT2(x, y)
Definition: macros.h:100
print_hex_byte
void print_hex_byte(const uint8_t b)
Definition: hex_print_routines.cpp:77
i
uint8_t i
Definition: screen_test_graph.c:72
SERIAL_ECHOLNPAIR_F
#define SERIAL_ECHOLNPAIR_F(V...)
Definition: serial.h:177
BinaryStream::StreamState::PACKET_PROCESS
unified_bed_leveling::storage_slot
static int8_t storage_slot
Definition: ubl.h:106
STRINGIFY
#define STRINGIFY(M)
Definition: macros.h:73
BinaryStream::stream_read
bool stream_read(uint8_t &data)
Definition: binary_protocol.h:289
destination
xyze_pos_t destination
Definition: motion.cpp:110
unified_bed_leveling::line_to_destination_cartesian
static void line_to_destination_cartesian(const feedRate_t &scaled_fr_mm_s, const uint8_t e)
millis
uint32_t millis(void)
Definition: wiring_time.c:29
unified_bed_leveling::restore_ubl_active_state_and_leave
static void restore_ubl_active_state_and_leave()
linear_fit_data
Definition: least_squares_fit.h:39
LIMIT
#define LIMIT(v, n1, n2)
Definition: macros.h:139
BinaryStream::Packet::reset
void reset()
Definition: binary_protocol.h:263
xy_pos_t
xy_float_t xy_pos_t
Definition: types.h:159
SDFileTransferProtocol::Packet::Open::dummy_transfer
bool dummy_transfer()
Definition: binary_protocol.h:69
DEBUG_ECHOLNPAIR
#define DEBUG_ECHOLNPAIR(...)
Definition: debug_out.h:82
BinaryStream::Packet::Header::protocol
uint8_t protocol()
Definition: binary_protocol.h:242
unified_bed_leveling::mesh_index_to_xpos
static float mesh_index_to_xpos(const uint8_t i)
Definition: ubl.h:287
IS_KINEMATIC
#define IS_KINEMATIC
Definition: Conditionals_LCD.h:545
SDFileTransferProtocol::idle
static void idle()
Definition: binary_protocol.h:157
SERIAL_ECHO_START
#define SERIAL_ECHO_START()
Definition: serial.h:179
BinaryStream::VERSION_MINOR
static const uint16_t VERSION_MINOR
Definition: binary_protocol.h:473
HSDR_POLL_MORE
Definition: heatshrink_decoder.h:19
feedRate_t
float feedRate_t
Definition: types.h:80
KEEPALIVE_STATE
#define KEEPALIVE_STATE(N)
Definition: gcode.h:365
pgm_read_ptr
#define pgm_read_ptr(addr)
Definition: pgmspace.h:113
SDFileTransferProtocol::process
static void process(uint8_t packet_type, char *buffer, const uint16_t length)
Definition: binary_protocol.h:166
REAL
Definition: ubl.h:35
unified_bed_leveling::sanity_check
static bool sanity_check()
INVALID
Definition: ubl.h:35
DEBUG_ECHOPGM
#define DEBUG_ECHOPGM(...)
Definition: debug_out.h:78
POW
#define POW(x, y)
Definition: macros.h:280
matrix_3x3
Definition: vector_3.h:73
XYval::pos
T pos[2]
Definition: types.h:187
HSD_poll_res
HSD_poll_res
Definition: heatshrink_decoder.h:17
math.h
NOMORE
#define NOMORE(v, n)
Definition: macros.h:133
createSpeedLookupTable.end
end
Definition: createSpeedLookupTable.py:33
DEBUG_ECHOLNPAIR_F
#define DEBUG_ECHOLNPAIR_F(...)
Definition: debug_out.h:83
DEBUG_DELAY
#define DEBUG_DELAY(...)
Definition: debug_out.h:89
UBL_OK
#define UBL_OK
Definition: ubl.h:32
heatshrink_decoder_poll
HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size)
Definition: heatshrink_decoder.cpp:134
BinaryStream
Definition: binary_protocol.h:221
ABS
#define ABS(a)
Definition: macros.h:266
binaryStream
BinaryStream binaryStream[NUM_SERIAL]
unified_bed_leveling::find_closest_mesh_point_of_type
static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const xy_pos_t &, const bool=false, MeshFlags *done_flags=nullptr) _O0
Y_CENTER
#define Y_CENTER
Definition: Conditionals_post.h:77
BinaryStream::buffer_next_index
uint16_t buffer_next_index
Definition: binary_protocol.h:475
BinaryStream::StreamState::PACKET_FOOTER
pgm_read_byte
#define pgm_read_byte(addr)
Definition: pgmspace.h:95
BinaryStream::StreamState::PACKET_ERROR
unified_bed_leveling::invalidate
static void invalidate()
BinaryStream::checksum
uint32_t checksum(uint32_t cs, uint8_t value)
Definition: binary_protocol.h:281
heatshrink_decoder_sink
HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, uint8_t *in_buf, size_t size, size_t *input_size)
Definition: heatshrink_decoder.cpp:98
SERIAL_ECHO_MSG
#define SERIAL_ECHO_MSG(S)
Definition: serial.h:183
tool_change
void tool_change(const uint8_t new_tool, bool no_move)
Definition: tool_change.cpp:771
PSTR
#define PSTR(str)
Definition: pgmspace.h:31
set_bed_leveling_enabled
void set_bed_leveling_enabled(const bool enable=true)
BinaryStream::packet
struct BinaryStream::Packet packet
current_position
xyze_pos_t current_position
Definition: motion.cpp:102
XYval::set
FI void set(const T px)
Definition: types.h:189
position_is_reachable
bool position_is_reachable(const float &rx, const float &ry)
Definition: motion.h:325
Planner::apply_modifiers
static FORCE_INLINE void apply_modifiers(xyze_pos_t &pos, bool leveling=false)
Definition: planner.h:499
BinaryStream::Packet::Header::checksum
uint16_t checksum
Definition: binary_protocol.h:240
heatshrink_decoder
Definition: heatshrink_decoder.h:46
LROUND
#define LROUND(x)
Definition: macros.h:285
BinaryStream::receive
void receive(char(&buffer)[buffer_size])
Definition: binary_protocol.h:301
Z_CLEARANCE_BETWEEN_PROBES
#define Z_CLEARANCE_BETWEEN_PROBES
Definition: Configuration_A3ides_2209_MINI.h:893
Planner::leveling_active_at_z
static FORCE_INLINE bool leveling_active_at_z(const float &)
Definition: planner.h:447
LOGICAL_Y_POSITION
#define LOGICAL_Y_POSITION(POS)
Definition: motion.h:279
BinaryStream::Protocol
Protocol
Definition: binary_protocol.h:223
XYval::magnitude
FI T magnitude() const
Definition: types.h:192
apply_rotation_xyz
void apply_rotation_xyz(const matrix_3x3 &matrix, float &_x, float &_y, float &_z)
Definition: vector_3.cpp:88
Y_MIN_BED
#define Y_MIN_BED
Definition: Conditionals_post.h:83
COUNT
#define COUNT(a)
Definition: macros.h:200
BinaryStream::stream_state
StreamState stream_state
Definition: binary_protocol.h:477
X_HOME_POS
#define X_HOME_POS
Definition: Conditionals_post.h:156
do_blocking_move_to
void do_blocking_move_to(const float rx, const float ry, const float rz, const feedRate_t &fr_mm_s)
Definition: motion.cpp:344
BinaryStream::StreamState
StreamState
Definition: binary_protocol.h:227
isnan
#define isnan
Definition: Arduino.h:55
SDFileTransferProtocol::VERSION_PATCH
static const uint16_t VERSION_PATCH
Definition: binary_protocol.h:218
FLOOR
#define FLOOR(x)
Definition: macros.h:284
Y_HOME_POS
#define Y_HOME_POS
Definition: Conditionals_post.h:172
ExtUI::onMeshUpdate
void onMeshUpdate(const uint8_t xpos, const uint8_t ypos, const float zval)
Definition: marlin_server.cpp:945
position_is_reachable_by_probe
FORCE_INLINE bool position_is_reachable_by_probe(const xy_int_t &pos)
Definition: motion.h:358
X_BED_SIZE
#define X_BED_SIZE
Definition: Configuration_A3ides_2209_MINI.h:980
void
void
Definition: png.h:1083
probe_min_x
float probe_min_x()
Definition: probe.h:103
unified_bed_leveling::find_furthest_invalid_mesh_point
static mesh_index_pair find_furthest_invalid_mesh_point() _O0
BinaryStream::Packet::bytes_received
uint32_t bytes_received
Definition: binary_protocol.h:258
XYZEval::x
T x
Definition: types.h:383
unified_bed_leveling::cell_indexes
static xy_int8_t cell_indexes(const float &x, const float &y)
Definition: ubl.h:137
constrain
#define constrain(amt, low, high)
Definition: wiring_constants.h:79
SERIAL_ECHO_F
#define SERIAL_ECHO_F(V...)
Definition: serial.h:71
WRITE
#define WRITE(IO, V)
Definition: fastio.h:96
SERIAL_ECHOPGM
#define SERIAL_ECHOPGM(S)
Definition: serial.h:173
BinaryStream::Packet::footer
Footer footer
Definition: binary_protocol.h:257
Planner::buffer_line
static bool buffer_line(const float &rx, const float &ry, const float &rz, const float &e, const feedRate_t &fr_mm_s, const uint8_t extruder, const float millimeters=0.0)
Definition: planner.cpp:2663
SET_IN_BITMAP
Definition: ubl.h:35
BinaryStream::Packet::Header::data
uint8_t data[1]
Definition: binary_protocol.h:245
NUM_SERIAL
#define NUM_SERIAL
Definition: HAL.h:100
SERIAL_ECHOLNPAIR
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
BinaryStream::StreamState::PACKET_RESET
XYval
Definition: types.h:99
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
MESH_X_DIST
#define MESH_X_DIST
Definition: mesh_bed_leveling.h:35
matrix_3x3::debug
void debug(PGM_P const title)
Definition: vector_3.cpp:139
probe_max_x
float probe_max_x()
Definition: probe.h:104
HEATSHRINK_STATIC_LOOKAHEAD_BITS
#define HEATSHRINK_STATIC_LOOKAHEAD_BITS
Definition: heatshrink_config.h:19
unified_bed_leveling::get_z_correction
static float get_z_correction(const float &rx0, const float &ry0)
Definition: ubl.h:238
SQRT
#define SQRT(x)
Definition: macros.h:281
SDFileTransferProtocol::TIMEOUT
static const uint16_t TIMEOUT
Definition: binary_protocol.h:218
XYval::x
T x
Definition: types.h:185
XYval::asLogical
FI XYval< float > asLogical() const
Definition: types.h:204
SDFileTransferProtocol::VERSION_MINOR
static const uint16_t VERSION_MINOR
Definition: binary_protocol.h:218
SDFileTransferProtocol::Packet::Open::filename
static char * filename()
Definition: binary_protocol.h:70
BinaryStream::VERSION_PATCH
static const uint16_t VERSION_PATCH
Definition: binary_protocol.h:473
ELAPSED
#define ELAPSED(NOW, SOON)
Definition: millis_t.h:29
MESH_Y_DIST
#define MESH_Y_DIST
Definition: mesh_bed_leveling.h:36
probe_min_y
float probe_min_y()
Definition: probe.h:105
uint8_t
const uint8_t[]
Definition: 404_html.c:3
heatshrink_decoder_reset
void heatshrink_decoder_reset(heatshrink_decoder *hsd)
Definition: heatshrink_decoder.cpp:83
ui
MarlinUI ui
HYPOT
#define HYPOT(x, y)
Definition: macros.h:287
finish_incremental_LSF
int finish_incremental_LSF(struct linear_fit_data *lsf)
Definition: least_squares_fit.cpp:43
SDFileTransferProtocol::Packet::Open
Definition: binary_protocol.h:60
XYZval::y
T y
Definition: types.h:286
SDFileTransferProtocol::Packet::Open::decode
static Open & decode(char *buffer)
Definition: binary_protocol.h:64
Y_MAX_BED
#define Y_MAX_BED
Definition: Conditionals_post.h:84
DEBUG_ECHOPAIR_F
#define DEBUG_ECHOPAIR_F(...)
Definition: debug_out.h:81
SDFileTransferProtocol
Definition: binary_protocol.h:57
PersistentStore::read_data
static bool read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing=true)
BinaryStream::StreamState::PACKET_WAIT
SERIAL_FLUSH
#define SERIAL_FLUSH()
Definition: serial.h:76
Y_BED_SIZE
#define Y_BED_SIZE
Definition: Configuration_A3ides_2209_MINI.h:981
BinaryStream::Packet::Header::token
uint16_t token
Definition: binary_protocol.h:235
ubl
unified_bed_leveling ubl
unified_bed_leveling::set_all_mesh_points_to_value
static void set_all_mesh_points_to_value(const float value)
PersistentStore::capacity
static size_t capacity()
DEBUGGING
#define DEBUGGING(F)
Definition: serial.h:47
report_current_position
void report_current_position()
Definition: motion.cpp:199
isinf
#define isinf
Definition: Arduino.h:58
unified_bed_leveling::report_current_mesh
static void report_current_mesh()
SERIAL_ECHOPAIR_F
#define SERIAL_ECHOPAIR_F(S, V...)
Definition: serial.h:176
unified_bed_leveling::smart_fill_wlsf
static void smart_fill_wlsf(const float &) _O2
hsd
static heatshrink_decoder hsd
Definition: binary_protocol.h:53
ABORT
#define ABORT(fs, res)
Definition: ff.c:455
Planner::fade_scaling_factor_for_z
static FORCE_INLINE float fade_scaling_factor_for_z(const float &)
Definition: planner.h:445
unified_bed_leveling::encoder_diff
static volatile int encoder_diff
Definition: ubl.h:116
print_hex_word
void print_hex_word(const uint16_t w)
Definition: hex_print_routines.cpp:78
MeshPointType
MeshPointType
Definition: ubl.h:35
SERIAL_EOL
#define SERIAL_EOL()
Definition: serial.h:181
BinaryStream::Packet::Header::meta
uint8_t meta
Definition: binary_protocol.h:237
axes_need_homing
uint8_t axes_need_homing(uint8_t axis_bits)
Definition: motion.cpp:1041
STOW_PROBE
#define STOW_PROBE()
Definition: probe.h:61
KILL_PIN
#define KILL_PIN
Definition: pins_CHEAPTRONICv2.h:106
DEBUG_ECHOPAIR
#define DEBUG_ECHOPAIR(...)
Definition: debug_out.h:80
SDFileTransferProtocol::Packet::Open::validate
static bool validate(char *buffer, size_t length)
Definition: binary_protocol.h:61
vector_3
Definition: vector_3.h:47
BinaryStream::Packet::Header::sync
uint8_t sync
Definition: binary_protocol.h:236
TEST
#define TEST(n, b)
Definition: macros.h:81
LOGICAL_X_POSITION
#define LOGICAL_X_POSITION(POS)
Definition: motion.h:278
XYval::y
T y
Definition: types.h:185
persistentStore
PersistentStore persistentStore
Definition: persistent_store_api.cpp:28
BinaryStream::Packet::checksum
uint16_t checksum
Definition: binary_protocol.h:259
BinaryStream::Packet::timeout
millis_t timeout
Definition: binary_protocol.h:260
SDFileTransferProtocol::VERSION_MAJOR
static const uint16_t VERSION_MAJOR
Definition: binary_protocol.h:218
BinaryStream::Packet
Definition: binary_protocol.h:230
BinaryStream::dispatch
void dispatch()
Definition: binary_protocol.h:449
BinaryStream::Protocol::CONTROL
XYZval< float >
hex_address
char * hex_address(const void *const w)
Definition: hex_print_routines.cpp:67
X_MIN_BED
#define X_MIN_BED
Definition: Conditionals_post.h:81
UBL_ERR
#define UBL_ERR
Definition: ubl.h:33
serial_delay
void serial_delay(const millis_t ms)
Definition: utility.h:31
BinaryStream::StreamState::PACKET_TIMEOUT
BinaryStream::Packet::buffer
char * buffer
Definition: binary_protocol.h:261
length
png_uint_32 length
Definition: png.c:2247
Z_CLEARANCE_DEPLOY_PROBE
#define Z_CLEARANCE_DEPLOY_PROBE
Definition: Configuration_A3ides_2209_MINI.h:892
serialprintPGM
void serialprintPGM(PGM_P str)
Definition: serial.cpp:35
SBI
#define SBI(A, B)
Definition: macros.h:85
S_FMT
#define S_FMT
Definition: macros.h:68
SERIAL_ECHOLNPGM
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
DEBUG_CHAR
#define DEBUG_CHAR(...)
Definition: debug_out.h:74
BinaryStream::ProtocolControl::CLOSE
BinaryStream::Packet::Header::type
uint8_t type()
Definition: binary_protocol.h:243
HEATSHRINK_STATIC_WINDOW_BITS
#define HEATSHRINK_STATIC_WINDOW_BITS
Definition: heatshrink_config.h:18
BinaryStream::ProtocolControl
ProtocolControl
Definition: binary_protocol.h:225
idle
void idle()
Definition: Marlin.cpp:629
READ
#define READ(IO)
Definition: fastio.h:95
unified_bed_leveling::echo_name
static void echo_name()
unified_bed_leveling::save_ubl_active_state_and_disable
static void save_ubl_active_state_and_disable()
serial_spaces
void serial_spaces(uint8_t count)
Definition: serial.cpp:50
UNUSED
#define UNUSED(X)
Definition: stm32f4xx_hal_def.h:74
X_MAX_BED
#define X_MAX_BED
Definition: Conditionals_post.h:82
incremental_WLSF
void incremental_WLSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z, const float &w)
Definition: least_squares_fit.h:51
millis_t
uint32_t millis_t
Definition: millis_t.h:26
BinaryStream::MAX_RETRIES
static const uint16_t MAX_RETRIES
Definition: binary_protocol.h:473
bs_serial_data_available
bool bs_serial_data_available(const uint8_t index)
Definition: binary_protocol.h:32
BinaryStream::idle
void idle()
Definition: binary_protocol.h:468
active_extruder
constexpr uint8_t active_extruder
Definition: motion.h:107
BinaryStream::Packet::Header::reset
void reset()
Definition: binary_protocol.h:244
BinaryStream::bytes_received
uint32_t bytes_received
Definition: binary_protocol.h:476
BinaryStream::RX_TIMESLICE
static const uint16_t RX_TIMESLICE
Definition: binary_protocol.h:473
unified_bed_leveling::z_values
static bed_mesh_t z_values
Definition: ubl.h:108
ENABLED
#define ENABLED(V...)
Definition: macros.h:177
planner
Planner planner
Definition: planner.cpp:111
XYZEval::y
T y
Definition: types.h:383
createSpeedLookupTable.parser
parser
Definition: createSpeedLookupTable.py:14
probe_max_y
float probe_max_y()
Definition: probe.h:106
info
uint8_t info[12]
Definition: masstorage.h:54