Skip to main content

Module msg_id

Module msg_id 

Source
Available on crate feature std only.
Expand description

Module for handling PK Command Message IDs.

§Overview

Message ID is a 2-character string used to uniquely identify commands and support the ACK mechanism and retransmission detection in the PK Command protocol.

§Base-94 Encoding Scheme

  • Character Set: Printable ASCII characters from 0x21 (!) to 0x7E (~)
  • Total Characters: 94 characters
  • Encoding Formula: ID = (c1 - 0x21) * 94 + (c2 - 0x21)
    • c1 and c2 are the two characters of the MSG ID string

§ID Range and Rollover

  • Minimum Value: 0 (represented as !!)
  • Maximum Value: 8835 (represented as ~~)
  • Rollover Mechanism: When ID reaches 8835, the next increment returns 0

§Scope and Lifetime

  • IDs are cumulative throughout the entire session
  • IDs are NOT reset by ENDTR commands
  • Used for:
    1. Command tracking: Each command is uniquely identified by its MSG ID
    2. ACK validation: Receiver must return the same MSG ID in ACKNO response
    3. Retransmission detection: Receiving the same MSG ID indicates a retransmitted packet

§Special Case: ERROR Command

  • ERROR command’s MSG ID is fixed as two space characters (0x20 0x20)
  • Its acknowledgement (ACKNO ERROR) also has MSG ID fixed as two spaces

Functions§

from_u16
Converts a u16 integer ID back into its 2-character string representation.
increment
Increments a message ID, handling rollover.
to_u16
Converts a 2-character string ID into its u16 integer representation.