MCPcopy Index your code
hub / github.com/RizeCrime/linuxblaster_control / decode_sb

Function decode_sb

sniffer/src/main.rs:265–453  ·  view source on GitHub ↗
(cmd: u8, len: usize, d: &[u8])

Source from the content-addressed store, hash-verified

263// ---------------------------------------------------------------------------
264
265fn decode_sb(cmd: u8, len: usize, d: &[u8]) -> SbCommand {
266 let g = |i: usize| d.get(i).copied().unwrap_or(0);
267 let tail = |from: usize| hbs(&d[from.min(d.len())..]);
268
269 match cmd {
270 // DeviceAck: 5a 02 0a [echoed_cmd] 00 [payload_echo...]
271 0x02 => SbCommand::DeviceAck { echoed_cmd: hb(g(3)) },
272
273 // DeviceIdentify
274 0x05 if len == 0 => SbCommand::DeviceIdentifyRequest,
275 0x05 => SbCommand::DeviceIdentifyResponse { flags: hb(g(3)) },
276
277 // Ping: 5a 06 01 01
278 0x06 => SbCommand::Ping,
279
280 // GetFirmwareString
281 0x07 if len == 1 => SbCommand::GetFirmwareStringRequest { typ: hb(g(3)) },
282 0x07 => {
283 let end = (3 + len).min(d.len());
284 SbCommand::GetFirmwareStringResponse {
285 firmware: String::from_utf8_lossy(&d[3..end]).into_owned(),
286 }
287 }
288
289 // GetSerial
290 0x10 if len == 0 => SbCommand::GetSerialRequest,
291 0x10 => {
292 let end = (3 + len).min(d.len());
293 SbCommand::GetSerialResponse { serial: hbs(&d[3..end]) }
294 }
295
296 // Status: LEN=3 → request; LEN≥8 → response (count at d[3], features at d[5])
297 0x11 if len == 3 => SbCommand::StatusRequest {
298 family: hb(g(4)),
299 feature_id: hb(g(5)),
300 },
301 0x11 => {
302 let count = g(3) as usize;
303 let mut features = Vec::with_capacity(count);
304 let mut off = 5;
305 for _ in 0..count {
306 if off + 6 <= d.len() {
307 features.push(feature_at(d, off));
308 off += 6;
309 }
310 }
311 SbCommand::StatusResponse { features }
312 }
313
314 // WriteSingleFeature: 5a 12 07 01 [family] [feature_id] 00 [f32_LE×4]
315 0x12 if len == 7 => {
316 let feature = if d.len() >= 11 {
317 feature_raw(g(4), g(5), [g(7), g(8), g(9), g(10)])
318 } else {
319 FeatureEntry { family: "?".into(), name: "?".into(), value: None }
320 };
321 SbCommand::WriteSingleFeature { feature }
322 }

Callers 1

parse_data_fragmentFunction · 0.85

Calls 4

hbsFunction · 0.85
hbFunction · 0.85
feature_atFunction · 0.85
feature_rawFunction · 0.85

Tested by

no test coverage detected