Skip to content

Conversation

@minlux
Copy link

@minlux minlux commented Dec 13, 2025

This PR adds a module "commands" with an enum for all zvt commands.
This enum can be used to to simplify reception - see example below.

This PR also adds a new attribute zvt_instr_any for the ZvtEnum macro.
When this attribute is added to an command enum, the respective match arm, generated by the ZvtEnum macro evaluates only the packet's CLASS byte, and ignores the INSTR byte.
It was mainly created for the Nack packet, where the INSTR is the actual error code - and can be any value.

The following example shows the usage of Commands enum to receive any zvt packet:

match transport.read_packet::<zvt::commands::Command>().await {
    Ok(packet) => {
        let result = match packet {
            zvt::commands::Command::Registration(reg) => {
                handle_registration(&mut transport, reg).await
            }
            zvt::commands::Command::Authorization(auth) => {
                handle_authorization(&mut transport, auth).await
            }
            zvt::commands::Command::Nack(nack) => {
                handle_nack(&mut transport, nack).await
            }

Note: The enum, already contains commands for the Authorization and Nack packet - which are provided in my other PRs :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant