SSUJKHR6YUZAHDFNJ6I5YYYOFDD2WNQ26ESMUCBC3X3UE6XEKXKAC const PacketStateEnum = enum {
const Packet = struct {address: u8,instruction: Instruction,fn speed(self: @This()) Speed {var ret: u5 = self.instruction.speed << 1;ret |= self.instruction.headlight;return @enumFromInt(ret);}};const Direction = enum(u1) {backward,forward,};const Instruction = packed struct(u8) {speed: u4,headlight: u1, // lsb of speeddirection: Direction,itype: u2,};const ParserState = enum {
defer ddc.reset();const address: u8 = @truncate(ddc.buffer >> (2 * (8 + 1) + 1));const instruction: u8 = @truncate(ddc.buffer >> (8 + 1) + 1);const checksum: u8 = @truncate(ddc.buffer >> 1);if (address ^ instruction == checksum) {std.log.debug("DDC packet passed the validation", .{});const packet = DDC.Packet{.address = @bitCast(address),.instruction = @bitCast(instruction),};ddc.packets.writeItem(packet) catch {std.log.err("DDC packet FIFO full, dropping packet", .{});return;};std.log.debug("DCC packet added to FIFO", .{});} else {std.log.debug("DDC packet invalid", .{});}