|
1 | | -package org.operatorfoundation.Codex |
| 1 | +package org.operatorfoundation.codex |
2 | 2 |
|
3 | | -import org.operatorfoundation.codex.Decoder |
4 | | -import org.operatorfoundation.codex.Encoder |
5 | 3 | import org.operatorfoundation.codex.symbols.Number |
6 | 4 | import org.operatorfoundation.codex.symbols.* |
7 | 5 | import java.math.BigInteger |
@@ -72,15 +70,38 @@ class WSPRCodex |
72 | 70 | */ |
73 | 71 | fun getMaxPayloadBytes(): Int |
74 | 72 | { |
75 | | - // Calculate total capacity in bits |
| 73 | + // DEBUG: Print out what symbols we have and their sizes |
| 74 | + println("=== Symbol Configuration Debug ===") |
| 75 | + WSPR_SYMBOLS.forEachIndexed { index, symbol -> |
| 76 | + println("Symbol $index: $symbol, size: ${symbol.size()}") |
| 77 | + } |
| 78 | + |
| 79 | + // Calculate the product of all symbol sizes |
| 80 | + // e.g. if we have symbols with sizes [36, 36, 18, 10, 19] |
| 81 | + // total capacity = 36 x 36 x 18 x 10 x 19 (total number of unique calculations) |
| 82 | + |
| 83 | + // Convert list of symbols to list of their sizes |
76 | 84 | val symbolSizes = WSPR_SYMBOLS.map { it.size().toBigInteger() } |
77 | | - val totalCapacity = symbolSizes.fold(BigInteger.ONE) { acc, size -> acc * size } |
| 85 | + // Multiply all sizes together |
| 86 | + val totalCapacity = symbolSizes.fold(BigInteger.ONE) { acc, size -> acc * size} |
| 87 | + |
| 88 | + // The max integer we can encode is (totalCapacity - 1) |
| 89 | + val maxEncodableValue = totalCapacity - BigInteger.ONE |
| 90 | + |
| 91 | + // Convert maxEncodableValue to bytes so we know how many bytes we need (how many bytes it takes to store this number) |
| 92 | + val byteArray = maxEncodableValue.toByteArray() |
78 | 93 |
|
79 | | - // Convert to bits (log2 of total capacity) |
80 | | - val capacityBits = totalCapacity.bitLength() - 1 |
| 94 | + // BigInteger sometimes adds an extra leading zero byte for the sign |
| 95 | + // Remove the extra byte if it exists |
| 96 | + return if (byteArray.isNotEmpty() && byteArray[0] == 0.toByte()) |
| 97 | + { |
| 98 | + byteArray.size - 1 |
| 99 | + } |
| 100 | + else |
| 101 | + { |
| 102 | + byteArray.size |
| 103 | + } |
81 | 104 |
|
82 | | - // Convert to bytes (divide by 8) |
83 | | - return capacityBits / 8 |
84 | 105 | } |
85 | 106 |
|
86 | 107 | /** |
|
0 commit comments