A State Machine Solution to Control Superconducting Cavities