changeset 102:80281b67511f

fc-rfcal-txband: fixed bug in the corner case when the target power level is above the highest basis point
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 12 Aug 2017 08:47:09 +0000
parents b0618796d28d
children 16aab86384a7
files autocal/txlevels.c
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/autocal/txlevels.c	Fri Aug 11 03:20:43 2017 +0000
+++ b/autocal/txlevels.c	Sat Aug 12 08:47:09 2017 +0000
@@ -22,7 +22,7 @@
 	double target_dbm;
 	vout_t *pslope;
 {
-	vout_t target_vout;
+	vout_t target_vout, slope;
 	unsigned n;
 	int apc_delta;
 
@@ -30,9 +30,13 @@
 	for (n = 0; n < num_basis_points - 1; n++)
 		if (target_vout < tx_basis[n+1].vout)
 			break;
+	if (n == num_basis_points - 1)
+		slope = tx_basis[n-1].slope;
+	else
+		slope = tx_basis[n].slope;
 	if (pslope)
-		*pslope = tx_basis[n].slope;
-	apc_delta = (target_vout - tx_basis[n].vout) / tx_basis[n].slope;
+		*pslope = slope;
+	apc_delta = (target_vout - tx_basis[n].vout) / slope;
 	return tx_basis[n].apc + apc_delta;
 }