Skip to content

Commit 9bd53fd

Browse files
committed
Added getMillisUntilNextEvenMinute()
1 parent 748fa23 commit 9bd53fd

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

AudioCoder/src/main/java/org/operatorfoundation/audiocoder/WSPRTimingCoordinator.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ class WSPRTimingCoordinator
177177
)
178178
}
179179

180+
/**
181+
* Calculates milliseconds until the next even minute boundary.
182+
*
183+
* Used for WSPR transmission timing — transmissions must begin at even minutes.
184+
* Unlike [calculateNextDecodeWindowStartTime], this returns the raw even minute
185+
* boundary with no decode start delay applied.
186+
*
187+
* @return Milliseconds until the next even minute boundary (always > 0)
188+
*/
189+
fun getMillisUntilNextEvenMinute(): Long
190+
{
191+
val calendar = Calendar.getInstance()
192+
val currentMinute = calendar.get(Calendar.MINUTE)
193+
val currentSecond = calendar.get(Calendar.SECOND)
194+
val currentMillis = calendar.get(Calendar.MILLISECOND)
195+
196+
val cyclePosition = calculatePositionInCurrentWSPRCycle(currentMinute, currentSecond)
197+
198+
// Time remaining until end of current 2-minute cycle = start of next even minute.
199+
// Subtract currentMillis for sub-second precision.
200+
val secondsRemaining = WSPRTimingConstants.WSPR_CYCLE_DURATION_SECONDS - cyclePosition
201+
return (secondsRemaining * 1000L) - currentMillis
202+
}
203+
180204
/**
181205
* Provides real-time information about the current position within the WSPR cycle.
182206
*

0 commit comments

Comments
 (0)