* \brief set the mode of the target VFO * \param rig The rig handle * \param vfo The target VFO * \param mode The mode to set to * \param width The passband width to set to * * Sets the mode and associated passband of the target VFO. The * passband \a width must be supported by the backend of the rig or * the special value RIG_PASSBAND_NOCHANGE which leaves the passband * unchanged
| 2836 | * \sa rig_get_mode() |
| 2837 | */ |
| 2838 | int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) |
| 2839 | { |
| 2840 | const struct rig_caps *caps; |
| 2841 | struct rig_state *rs; |
| 2842 | int retcode; |
| 2843 | int locked_mode; |
| 2844 | struct rig_cache *cachep; |
| 2845 | |
| 2846 | if (CHECK_RIG_ARG(rig)) |
| 2847 | { |
| 2848 | rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); |
| 2849 | return -RIG_EINVAL; |
| 2850 | } |
| 2851 | |
| 2852 | rs = STATE(rig); |
| 2853 | cachep = CACHE(rig); |
| 2854 | |
| 2855 | ENTERFUNC; |
| 2856 | ELAPSED1; |
| 2857 | LOCK(1); |
| 2858 | |
| 2859 | rig_debug(RIG_DEBUG_VERBOSE, |
| 2860 | "%s called, vfo=%s, mode=%s, width=%d, curr_vfo=%s\n", __func__, |
| 2861 | rig_strvfo(vfo), rig_strrmode(mode), (int)width, |
| 2862 | rig_strvfo(rs->current_vfo)); |
| 2863 | |
| 2864 | rig_get_lock_mode(rig, &locked_mode); |
| 2865 | |
| 2866 | if (locked_mode) |
| 2867 | { |
| 2868 | ELAPSED2; |
| 2869 | LOCK(0); |
| 2870 | RETURNFUNC(RIG_OK); |
| 2871 | } |
| 2872 | |
| 2873 | // do not mess with mode while PTT is on |
| 2874 | if (cachep->ptt) |
| 2875 | { |
| 2876 | rig_debug(RIG_DEBUG_VERBOSE, "%s PTT on so set_mode ignored\n", __func__); |
| 2877 | ELAPSED2; |
| 2878 | LOCK(0); |
| 2879 | RETURNFUNC(RIG_OK); |
| 2880 | } |
| 2881 | |
| 2882 | caps = rig->caps; |
| 2883 | |
| 2884 | if (caps->set_mode == NULL) |
| 2885 | { |
| 2886 | ELAPSED2; |
| 2887 | LOCK(0); |
| 2888 | RETURNFUNC(-RIG_ENAVAIL); |
| 2889 | } |
| 2890 | |
| 2891 | if (vfo == RIG_VFO_CURR) |
| 2892 | { |
| 2893 | vfo = rs->current_vfo; |
| 2894 | } |
| 2895 |