Skip to content

Commit a653c3a

Browse files
authored
🎨 Binary Stream cleanup (#27799)
1 parent 7b083be commit a653c3a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Marlin/src/feature/binary_stream.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ class SDFileTransferProtocol {
134134
public:
135135

136136
static void idle() {
137-
// If a transfer is interrupted and a file is left open, abort it after TIMEOUT ms
137+
// If a transfer is interrupted and a file is left open, abort it after 'idle_period' ms
138138
const millis_t ms = millis();
139139
if (transfer_active && ELAPSED(ms, idle_timeout)) {
140-
idle_timeout = ms + IDLE_PERIOD;
140+
idle_timeout = ms + idle_period;
141141
if (ELAPSED(ms, transfer_timeout)) transfer_abort();
142142
}
143143
}
144144

145145
static void process(uint8_t packet_type, char *buffer, const uint16_t length) {
146-
transfer_timeout = millis() + TIMEOUT;
146+
transfer_timeout = millis() + timeout;
147147
switch (static_cast<FileTransfer>(packet_type)) {
148148
case FileTransfer::QUERY:
149-
SERIAL_ECHO(F("PFT:version:"), VERSION_MAJOR, C('.'), VERSION_MINOR, C('.'), VERSION_PATCH);
149+
SERIAL_ECHO(F("PFT:version:"), version_major, C('.'), version_minor, C('.'), version_patch);
150150
#if ENABLED(BINARY_STREAM_COMPRESSION)
151151
SERIAL_ECHOLN(F(":compression:heatshrink,"), HEATSHRINK_STATIC_WINDOW_BITS, C(','), HEATSHRINK_STATIC_LOOKAHEAD_BITS);
152152
#else
@@ -194,7 +194,7 @@ class SDFileTransferProtocol {
194194
}
195195
}
196196

197-
static const uint16_t VERSION_MAJOR = 0, VERSION_MINOR = 1, VERSION_PATCH = 0, TIMEOUT = 10000, IDLE_PERIOD = 1000;
197+
static const uint16_t version_major = 0, version_minor = 1, version_patch = 0, timeout = 10000, idle_period = 1000;
198198
};
199199

200200
class BinaryStream {
@@ -209,7 +209,7 @@ class BinaryStream {
209209
struct Packet { // 10 byte protocol overhead, ascii with checksum and line number has a minimum of 7 increasing with line
210210

211211
union Header {
212-
static constexpr uint16_t HEADER_TOKEN = 0xB5AD;
212+
static constexpr uint16_t header_token = 0xB5AD;
213213
struct [[gnu::packed]] {
214214
uint16_t token; // packet start token
215215
uint8_t sync; // stream sync, resend id and packet loss detection
@@ -245,7 +245,7 @@ class BinaryStream {
245245
bytes_received = 0;
246246
checksum = 0;
247247
header_checksum = 0;
248-
timeout = millis() + PACKET_MAX_WAIT;
248+
timeout = millis() + packet_max_wait;
249249
buffer = nullptr;
250250
}
251251
} packet{};
@@ -272,14 +272,14 @@ class BinaryStream {
272272
}
273273
if (!bs_serial_data_available(card.transfer_port_index)) return false;
274274
data = bs_read_serial(card.transfer_port_index);
275-
packet.timeout = millis() + PACKET_MAX_WAIT;
275+
packet.timeout = millis() + packet_max_wait;
276276
return true;
277277
}
278278

279279
template<const size_t buffer_size>
280280
void receive(char (&buffer)[buffer_size]) {
281281
uint8_t data = 0;
282-
millis_t transfer_window = millis() + RX_TIMESLICE;
282+
millis_t transfer_window = millis() + rx_timeslice;
283283

284284
#if HAS_MEDIA
285285
PORT_REDIRECT(SERIAL_PORTMASK(card.transfer_port_index));
@@ -299,7 +299,7 @@ class BinaryStream {
299299
case StreamState::PACKET_WAIT:
300300
if (!stream_read(data)) { idle(); return; } // no active packet so don't wait
301301
packet.header.data[1] = data;
302-
if (packet.header.token == packet.header.HEADER_TOKEN) {
302+
if (packet.header.token == packet.header.header_token) {
303303
packet.bytes_received = 2;
304304
stream_state = StreamState::PACKET_HEADER;
305305
}
@@ -322,7 +322,7 @@ class BinaryStream {
322322
if (packet.header.checksum == packet.header_checksum) {
323323
// The SYNC control packet is a special case in that it doesn't require the stream sync to be correct
324324
if (static_cast<Protocol>(packet.header.protocol()) == Protocol::CONTROL && static_cast<ProtocolControl>(packet.header.type()) == ProtocolControl::SYNC) {
325-
SERIAL_ECHOLN(F("ss"), sync, C(','), buffer_size, C(','), VERSION_MAJOR, C('.'), VERSION_MINOR, C('.'), VERSION_PATCH);
325+
SERIAL_ECHOLN(F("ss"), sync, C(','), buffer_size, C(','), version_major, C('.'), version_minor, C('.'), version_patch);
326326
stream_state = StreamState::PACKET_RESET;
327327
break;
328328
}
@@ -398,7 +398,7 @@ class BinaryStream {
398398
stream_state = StreamState::PACKET_RESET;
399399
break;
400400
case StreamState::PACKET_RESEND:
401-
if (packet_retries < MAX_RETRIES || MAX_RETRIES == 0) {
401+
if (packet_retries < max_retries || max_retries == 0) {
402402
packet_retries++;
403403
stream_state = StreamState::PACKET_RESET;
404404
SERIAL_ECHO_MSG("Resend request ", packet_retries);
@@ -446,7 +446,7 @@ class BinaryStream {
446446
SDFileTransferProtocol::idle();
447447
}
448448

449-
static const uint16_t PACKET_MAX_WAIT = 500, RX_TIMESLICE = 20, MAX_RETRIES = 0, VERSION_MAJOR = 0, VERSION_MINOR = 1, VERSION_PATCH = 0;
449+
static const uint16_t packet_max_wait = 500, rx_timeslice = 20, max_retries = 0, version_major = 0, version_minor = 1, version_patch = 0;
450450
uint8_t packet_retries, sync;
451451
uint16_t buffer_next_index;
452452
uint32_t bytes_received;

0 commit comments

Comments
 (0)