| 1 | /* |
| 2 | * Hamlib Yaesu backend - FTX-1 Noise Reduction Group |
| 3 | * Copyright (c) 2025 by Terrell Deppe (KJ5HST) |
| 4 | * |
| 5 | * This file implements helper functions for noise blanker and digital noise reduction. |
| 6 | * |
| 7 | * CAT Commands in this file: |
| 8 | * NL P1 P2P3P4; - Noise Blanker Level (P1=VFO 0/1, P2P3P4=000-010) |
| 9 | * Set to 000 for OFF, 001-010 for level |
| 10 | * RL P1 P2P3; - Noise Reduction Level (P1=VFO 0/1, P2P3=00-10) |
| 11 | * Set to 00 for OFF, 01-10 for level |
| 12 | * |
| 13 | * Note: NB and NR on/off commands return ?; on FTX-1. |
| 14 | * Use NL/RL level commands instead (level 0 = OFF). |
| 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <hamlib/rig.h>cxx . . $ `<file>/include/hamlib/rig.h`/ |
| 20 | #include "misc.h"cxx . . $ `<file>/src/misc.h`/ |
| 21 | #include "yaesu.h"cxx . . $ `<file>/rigs/yaesu/yaesu.h`/ |
| 22 | #include "newcat.h"cxx . . $ `<file>/rigs/yaesu/newcat.h`/ |
| 23 | #include "ftx1.h"cxx . . $ `<file>/rigs/yaesu/ftx1/ftx1.h`/ |
| 24 | |
| 25 | /* Level ranges */ |
| 26 | #define FTX1_NB_LEVEL_MINcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:26:9`! 0 |
| 27 | #define FTX1_NB_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:27:9`! 10 /* 0=OFF, 1-10=level */ |
| 28 | #define FTX1_NR_LEVEL_MINcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:28:9`! 0 |
| 29 | #define FTX1_NR_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:29:9`! 10 /* 0=OFF, 1-10=level (CAT manual p.23) */ |
| 30 | |
| 31 | /* |
| 32 | * ftx1_set_nb_helper - Set Noise Blanker on/off via NL level |
| 33 | * |
| 34 | * FTX-1 doesn't have NB on/off command, so we use NL level: |
| 35 | * NL P1 000; = OFF |
| 36 | * NL P1 005; = ON (mid-level) |
| 37 | */ |
| 38 | int ftx1_set_nb_helpercxx . . $ ftx1_set_nb_helper(4d3c1218b83869ed).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, int status) |
| 39 | { |
| 40 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 41 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 42 | int level = status ? 5 : 0; /* Default to mid-level when turning on */ |
| 43 | |
| 44 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d status=%d\n", __func__, |
| 45 | rig_strvfo(vfo), p1, status); |
| 46 | |
| 47 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "NL%d%03d;", p1, level); |
| 48 | return newcat_set_cmdcxx . . $ newcat_set_cmd(88e39314625ee3ba).(rig); |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * ftx1_get_nb_helper - Get Noise Blanker on/off status |
| 53 | * |
| 54 | * Query NL level - if > 0, NB is on |
| 55 | */ |
| 56 | int ftx1_get_nb_helpercxx . . $ ftx1_get_nb_helper(fa3fdaf9f2d3e254).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, int *status) |
| 57 | { |
| 58 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 59 | int ret; |
| 60 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 61 | int p1_resp, level; |
| 62 | |
| 63 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__, |
| 64 | rig_strvfo(vfo), p1); |
| 65 | |
| 66 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "NL%d;", p1); |
| 67 | |
| 68 | ret = newcat_get_cmdcxx . . $ newcat_get_cmd(88e39314625ee3ba).(rig); |
| 69 | if (ret != RIG_OKcxx . . $ RIG_OK.) return ret; |
| 70 | |
| 71 | /* Response: NL P1 P2P3P4; (VFO + 3-digit level 000-010) */ |
| 72 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(priv->ret_datacxx . . $ newcat_priv_data#ret_data. + 2, "%1d%3d", &p1_resp, &level) != 2) |
| 73 | { |
| 74 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__, |
| 75 | priv->ret_data); |
| 76 | return -RIG_EPROTOcxx . . $ RIG_EPROTO.; |
| 77 | } |
| 78 | |
| 79 | *status = (level > 0) ? 1 : 0; |
| 80 | return RIG_OKcxx . . $ RIG_OK.; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * ftx1_set_nr_helper - Set Noise Reduction on/off via RL level |
| 85 | * |
| 86 | * FTX-1 doesn't have NR on/off command, so we use RL level: |
| 87 | * RL P1 00; = OFF |
| 88 | * RL P1 08; = ON (mid-level) |
| 89 | */ |
| 90 | int ftx1_set_nr_helpercxx . . $ ftx1_set_nr_helper(4d3c1218b83869ed).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, int status) |
| 91 | { |
| 92 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 93 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 94 | int level = status ? 8 : 0; /* Default to mid-level when turning on */ |
| 95 | |
| 96 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d status=%d\n", __func__, |
| 97 | rig_strvfo(vfo), p1, status); |
| 98 | |
| 99 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "RL%d%02d;", p1, level); |
| 100 | return newcat_set_cmdcxx . . $ newcat_set_cmd(88e39314625ee3ba).(rig); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * ftx1_get_nr_helper - Get Noise Reduction on/off status |
| 105 | * |
| 106 | * Query RL level - if > 0, NR is on |
| 107 | */ |
| 108 | int ftx1_get_nr_helpercxx . . $ ftx1_get_nr_helper(fa3fdaf9f2d3e254).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, int *status) |
| 109 | { |
| 110 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 111 | int ret; |
| 112 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 113 | int p1_resp, level; |
| 114 | |
| 115 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__, |
| 116 | rig_strvfo(vfo), p1); |
| 117 | |
| 118 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "RL%d;", p1); |
| 119 | |
| 120 | ret = newcat_get_cmdcxx . . $ newcat_get_cmd(88e39314625ee3ba).(rig); |
| 121 | if (ret != RIG_OKcxx . . $ RIG_OK.) return ret; |
| 122 | |
| 123 | /* Response: RL P1 P2P3; (VFO + 2-digit level 00-10) */ |
| 124 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(priv->ret_datacxx . . $ newcat_priv_data#ret_data. + 2, "%1d%2d", &p1_resp, &level) != 2) |
| 125 | { |
| 126 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__, |
| 127 | priv->ret_data); |
| 128 | return -RIG_EPROTOcxx . . $ RIG_EPROTO.; |
| 129 | } |
| 130 | |
| 131 | *status = (level > 0) ? 1 : 0; |
| 132 | return RIG_OKcxx . . $ RIG_OK.; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * ftx1_set_nb_level_helper - Set Noise Blanker Level |
| 137 | * CAT command: NL P1 P2P3P4; (P1=VFO, P2P3P4=000-010) |
| 138 | */ |
| 139 | int ftx1_set_nb_level_helpercxx . . $ ftx1_set_nb_level_helper(e145d5f582c2b8e6).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, value_tcxx . . $ value_t# val) |
| 140 | { |
| 141 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 142 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 143 | int level = (int)(val.fcxx . . $ $anonymous_type_eb6f353080003b96_14#f. * FTX1_NB_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:27:9`!); |
| 144 | |
| 145 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d level=%d\n", __func__, |
| 146 | rig_strvfo(vfo), p1, level); |
| 147 | |
| 148 | if (level < FTX1_NB_LEVEL_MINcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:26:9`!) level = FTX1_NB_LEVEL_MINcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:26:9`!; |
| 149 | if (level > FTX1_NB_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:27:9`!) level = FTX1_NB_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:27:9`!; |
| 150 | |
| 151 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "NL%d%03d;", p1, level); |
| 152 | return newcat_set_cmdcxx . . $ newcat_set_cmd(88e39314625ee3ba).(rig); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * ftx1_get_nb_level_helper - Get Noise Blanker Level |
| 157 | * CAT command: NL P1; Response: NL P1 P2P3P4; |
| 158 | */ |
| 159 | int ftx1_get_nb_level_helpercxx . . $ ftx1_get_nb_level_helper(bd13eeae47424625).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, value_tcxx . . $ value_t# *val) |
| 160 | { |
| 161 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 162 | int ret; |
| 163 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 164 | int p1_resp, level; |
| 165 | |
| 166 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__, |
| 167 | rig_strvfo(vfo), p1); |
| 168 | |
| 169 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "NL%d;", p1); |
| 170 | |
| 171 | ret = newcat_get_cmdcxx . . $ newcat_get_cmd(88e39314625ee3ba).(rig); |
| 172 | if (ret != RIG_OKcxx . . $ RIG_OK.) return ret; |
| 173 | |
| 174 | /* Response: NL P1 P2P3P4; (3-digit level 000-010) */ |
| 175 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(priv->ret_datacxx . . $ newcat_priv_data#ret_data. + 2, "%1d%3d", &p1_resp, &level) != 2) |
| 176 | { |
| 177 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__, |
| 178 | priv->ret_data); |
| 179 | return -RIG_EPROTOcxx . . $ RIG_EPROTO.; |
| 180 | } |
| 181 | |
| 182 | val->fcxx . . $ $anonymous_type_eb6f353080003b96_14#f. = (float)level / FTX1_NB_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:27:9`!; |
| 183 | return RIG_OKcxx . . $ RIG_OK.; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * ftx1_set_nr_level_helper - Set Noise Reduction Level |
| 188 | * CAT command: RL P1 P2P3; (P1=VFO, P2P3=00-10) |
| 189 | */ |
| 190 | int ftx1_set_nr_level_helpercxx . . $ ftx1_set_nr_level_helper(e145d5f582c2b8e6).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, value_tcxx . . $ value_t# val) |
| 191 | { |
| 192 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 193 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 194 | int level = (int)(val.fcxx . . $ $anonymous_type_eb6f353080003b96_14#f. * FTX1_NR_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:29:9`!); |
| 195 | |
| 196 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d level=%d\n", __func__, |
| 197 | rig_strvfo(vfo), p1, level); |
| 198 | |
| 199 | if (level < FTX1_NR_LEVEL_MINcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:28:9`!) level = FTX1_NR_LEVEL_MINcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:28:9`!; |
| 200 | if (level > FTX1_NR_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:29:9`!) level = FTX1_NR_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:29:9`!; |
| 201 | |
| 202 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "RL%d%02d;", p1, level); |
| 203 | return newcat_set_cmdcxx . . $ newcat_set_cmd(88e39314625ee3ba).(rig); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * ftx1_get_nr_level_helper - Get Noise Reduction Level |
| 208 | * CAT command: RL P1; Response: RL P1 P2P3; |
| 209 | */ |
| 210 | int ftx1_get_nr_level_helpercxx . . $ ftx1_get_nr_level_helper(bd13eeae47424625).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, value_tcxx . . $ value_t# *val) |
| 211 | { |
| 212 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 213 | int ret; |
| 214 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 215 | int p1_resp, level; |
| 216 | |
| 217 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__, |
| 218 | rig_strvfo(vfo), p1); |
| 219 | |
| 220 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "RL%d;", p1); |
| 221 | |
| 222 | ret = newcat_get_cmdcxx . . $ newcat_get_cmd(88e39314625ee3ba).(rig); |
| 223 | if (ret != RIG_OKcxx . . $ RIG_OK.) return ret; |
| 224 | |
| 225 | /* Response: RL P1 P2P3; (2-digit level 00-10) */ |
| 226 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(priv->ret_datacxx . . $ newcat_priv_data#ret_data. + 2, "%1d%2d", &p1_resp, &level) != 2) |
| 227 | { |
| 228 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__, |
| 229 | priv->ret_data); |
| 230 | return -RIG_EPROTOcxx . . $ RIG_EPROTO.; |
| 231 | } |
| 232 | |
| 233 | val->fcxx . . $ $anonymous_type_eb6f353080003b96_14#f. = (float)level / FTX1_NR_LEVEL_MAXcxx . . $ `rigs/yaesu/ftx1/ftx1_noise.c:29:9`!; |
| 234 | return RIG_OKcxx . . $ RIG_OK.; |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * ftx1_set_na_helper - Set Narrow filter (NA command) |
| 239 | * CAT command: NA P1 P2; (P1=VFO 0/1, P2=0/1 off/on) |
| 240 | */ |
| 241 | int ftx1_set_na_helpercxx . . $ ftx1_set_na_helper(4d3c1218b83869ed).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, int status) |
| 242 | { |
| 243 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 244 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 245 | int p2 = status ? 1 : 0; |
| 246 | |
| 247 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d status=%d\n", __func__, |
| 248 | rig_strvfo(vfo), p1, status); |
| 249 | |
| 250 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "NA%d%d;", p1, p2); |
| 251 | return newcat_set_cmdcxx . . $ newcat_set_cmd(88e39314625ee3ba).(rig); |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * ftx1_get_na_helper - Get Narrow filter status |
| 256 | * CAT command: NA P1; Response: NA P1 P2; |
| 257 | */ |
| 258 | int ftx1_get_na_helpercxx . . $ ftx1_get_na_helper(fa3fdaf9f2d3e254).(RIGcxx . . $ RIG# *rig, vfo_tcxx . . $ vfo_t# vfo, int *status) |
| 259 | { |
| 260 | struct newcat_priv_datacxx . . $ newcat_priv_data# *priv = STATEcxx . . $ `include/hamlib/rig_state.h:388:9`!(rig)->privcxx . . $ rig_state#priv.; |
| 261 | int ret; |
| 262 | int p1 = ftx1_vfo_to_p1cxx . . $ ftx1_vfo_to_p1(21e77196da3206ed).(rig, vfo); |
| 263 | int p1_resp, p2; |
| 264 | |
| 265 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__, |
| 266 | rig_strvfo(vfo), p1); |
| 267 | |
| 268 | SNPRINTFcxx . . $ `include/hamlib/rig.h:3353:9`!(priv->cmd_str, sizeof(priv->cmd_str), "NA%d;", p1); |
| 269 | |
| 270 | ret = newcat_get_cmdcxx . . $ newcat_get_cmd(88e39314625ee3ba).(rig); |
| 271 | if (ret != RIG_OKcxx . . $ RIG_OK.) return ret; |
| 272 | |
| 273 | /* Response: NA P1 P2; (P1=VFO, P2=on/off) */ |
| 274 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(priv->ret_datacxx . . $ newcat_priv_data#ret_data. + 2, "%1d%1d", &p1_resp, &p2) != 2) |
| 275 | { |
| 276 | rig_debugcxx . . $ `include/hamlib/rig.h:3344:9`!(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__, |
| 277 | priv->ret_data); |
| 278 | return -RIG_EPROTOcxx . . $ RIG_EPROTO.; |
| 279 | } |
| 280 | |
| 281 | *status = p2; |
| 282 | return RIG_OKcxx . . $ RIG_OK.; |
| 283 | } |