WIP: rpc: work around hamlib <=4.5.5 reporting incorrect IC-9700 power

The 70cm and 23cm power reported by hamlib for IC-9700 is wrong.  This was
fixed in upstream commit 76a1a58 which is part of hamlib 4.6.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
3 files changed, 36 insertions(+), 3 deletions(-)

M rpc/hamlib-impl.h
M rpc/hamlib-quirks.c
M rpc/hamlib.c
M rpc/hamlib-impl.h +4 -1
@@ 1,5 1,5 @@ 
 /*
- * Copyright (c) 2021-2023 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2021-2023,2025 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal

          
@@ 37,6 37,7 @@ struct hrig {
 
 	struct {
 		bool no_txpower;
+		bool bad_txpower;
 	} quirks;
 
 	/* cached values */

          
@@ 46,5 47,7 @@ struct hrig {
 };
 
 extern void hamlib_set_quirks(struct hrig *rig, uint32_t model);
+extern uint32_t hamlib_correct_power(struct hrig *rig, uint64_t freq,
+				     uint32_t power);
 
 #endif

          
M rpc/hamlib-quirks.c +28 -1
@@ 1,5 1,5 @@ 
 /*
- * Copyright (c) 2021-2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2021-2025 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal

          
@@ 54,6 54,7 @@ void hamlib_set_quirks(struct hrig *rig,
 {
 	/* initialize all quirks as disabled */
 	rig->quirks.no_txpower = false;
+	rig->quirks.bad_txpower = false;
 
 	if ((model == RIG_MODEL_NETRIGCTL) && (CURRENT <= MKVER(4, 3, 1))) {
 		rig->quirks.no_txpower = true;

          
@@ 66,4 67,30 @@ void hamlib_set_quirks(struct hrig *rig,
 		cmn_err(CE_WARN, "Hamlib 4.5.5 and older has buggy KX2 backend");
 		cmn_err(CE_WARN, "Disabling power announcements");
 	}
+
+	if ((model == RIG_MODEL_IC9700) && (CURRENT <= MKVER(4, 5, 5))) {
+		rig->quirks.bad_txpower = true;
+		cmn_err(CE_WARN, "Hamlib 4.5.5 and older has buggy IC9700 backend");
+		cmn_err(CE_WARN, "Working around bad 23cm band tx power info");
+	}
 }
+
+uint32_t hamlib_correct_power(struct hrig *rig, uint64_t freq, uint32_t power)
+{
+	ASSERT(rig->quirks.bad_txpower);
+
+	/* IC-9700 */
+	if (rig->rig->caps->rig_model == RIG_MODEL_IC9700) {
+		/* 2m is correct, 100W max */
+
+		/* 70cm is wrong, 75W max */
+		if ((freq >= 420000000) && (freq <= 450000000))
+			power = (power * 75) / 100;
+
+		/* 23cm is wrong, 10W max */
+		if ((freq >= 1240000000) && (freq <= 1300000000))
+			power = (power * 10) / 100;
+	}
+
+	return power;
+}

          
M rpc/hamlib.c +4 -1
@@ 1,5 1,5 @@ 
 /*
- * Copyright (c) 2021-2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2021-2025 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal

          
@@ 349,6 349,9 @@ static int hamlib_get_state_unlocked(str
 		ret = rig_power2mW(rig->rig, &power, val.f, tx_freq, tx_mode);
 		if (ret)
 			goto err;
+
+		if (rig->quirks.bad_txpower)
+			power = hamlib_correct_power(rig, tx_freq, power);
 	}
 
 	/* get ptt */