Prusa MINI Firmware overview
SDFileTransferProtocol Class Reference

#include <binary_protocol.h>

Collaboration diagram for SDFileTransferProtocol:

Static Public Member Functions

static void idle ()
 
static void process (uint8_t packet_type, char *buffer, const uint16_t length)
 

Static Public Attributes

static const uint16_t VERSION_MAJOR = 0
 
static const uint16_t VERSION_MINOR = 1
 
static const uint16_t VERSION_PATCH = 0
 
static const uint16_t TIMEOUT = 10000
 
static const uint16_t IDLE_PERIOD = 1000
 

Member Function Documentation

◆ idle()

static void SDFileTransferProtocol::idle ( )
static
157  {
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  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

static void SDFileTransferProtocol::process ( uint8_t  packet_type,
char *  buffer,
const uint16_t  length 
)
static
166  {
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  }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ VERSION_MAJOR

const uint16_t SDFileTransferProtocol::VERSION_MAJOR = 0
static

◆ VERSION_MINOR

const uint16_t SDFileTransferProtocol::VERSION_MINOR = 1
static

◆ VERSION_PATCH

const uint16_t SDFileTransferProtocol::VERSION_PATCH = 0
static

◆ TIMEOUT

const uint16_t SDFileTransferProtocol::TIMEOUT = 10000
static

◆ IDLE_PERIOD

const uint16_t SDFileTransferProtocol::IDLE_PERIOD = 1000
static
SDFileTransferProtocol::IDLE_PERIOD
static const uint16_t IDLE_PERIOD
Definition: binary_protocol.h:218
SERIAL_ECHOPAIR
#define SERIAL_ECHOPAIR(V...)
Definition: serial.h:114
millis
uint32_t millis(void)
Definition: wiring_time.c:29
SDFileTransferProtocol::VERSION_PATCH
static const uint16_t VERSION_PATCH
Definition: binary_protocol.h:218
SERIAL_ECHOLNPAIR
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
HEATSHRINK_STATIC_LOOKAHEAD_BITS
#define HEATSHRINK_STATIC_LOOKAHEAD_BITS
Definition: heatshrink_config.h:19
SDFileTransferProtocol::TIMEOUT
static const uint16_t TIMEOUT
Definition: binary_protocol.h:218
SDFileTransferProtocol::VERSION_MINOR
static const uint16_t VERSION_MINOR
Definition: binary_protocol.h:218
ELAPSED
#define ELAPSED(NOW, SOON)
Definition: millis_t.h:29
SDFileTransferProtocol::Packet::Open::decode
static Open & decode(char *buffer)
Definition: binary_protocol.h:64
SDFileTransferProtocol::Packet::Open::validate
static bool validate(char *buffer, size_t length)
Definition: binary_protocol.h:61
SDFileTransferProtocol::VERSION_MAJOR
static const uint16_t VERSION_MAJOR
Definition: binary_protocol.h:218
length
png_uint_32 length
Definition: png.c:2247
SERIAL_ECHOLNPGM
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
HEATSHRINK_STATIC_WINDOW_BITS
#define HEATSHRINK_STATIC_WINDOW_BITS
Definition: heatshrink_config.h:18
millis_t
uint32_t millis_t
Definition: millis_t.h:26