Hyperfine-structure measurements in the Rydberg S and P states of rubidium and cesium