Skip to content

Commit 6c9f7ab

Browse files
committed
WSPR Test + String Decode Bug Fix
1 parent dcd0015 commit 6c9f7ab

File tree

9 files changed

+22
-17
lines changed

9 files changed

+22
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
local.properties
1616
/.idea
1717
/.kotlin/errors
18+
*.log

Codex/src/main/java/org/operatorfoundation/codex/Decoder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class Decoder(private val symbols: List<Symbol>)
5555
if (symbol.size() == 1)
5656
{
5757
// Symbols with size 1 don't contribute to the numeric value
58-
println("decode_step(${encodedValue.decodeToString()}, $symbol, $index)")
58+
println("decode_step(encoded value: ${encodedValue.decodeToString()}, symbol: $symbol, index: $index)")
5959

6060
return 0.toBigInteger()
6161
}
6262
else
6363
{
64-
println("decode_step(${encodedValue.decodeToString()}, $symbol, $index)")
64+
println("decode_step(encoded value: ${encodedValue.decodeToString()}, symbol: $symbol, index: $index)")
6565

6666
if (index == symbols.size - 1)
6767
{
@@ -75,7 +75,7 @@ class Decoder(private val symbols: List<Symbol>)
7575
val remainingSymbolSizes = remainingSymbols.map { it.size() }
7676
val positionMultiplier = remainingSymbolSizes.fold(1) { acc, size -> acc * size }
7777

78-
println("history: $remainingSymbolSizes, p: $positionMultiplier")
78+
println("history:/n remaining symbol sizes - $remainingSymbolSizes, position multiplier: $positionMultiplier")
7979

8080
// Multiply decoded value by position weight
8181
val result = symbol.decode(encodedValue) * positionMultiplier.toBigInteger()

Codex/src/main/java/org/operatorfoundation/codex/Encoder.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class Encoder(private val symbols: List<Symbol>)
5959
{
6060
if (symbol.size() == 1)
6161
{
62-
// Fixed symbols (size = 1) don't consume any of the value
63-
println("encode_step($currentValue, $symbol, $index)")
62+
// (size = 1) don't consume any of the value
63+
println("encode_step( current value: $currentValue, symbol: $symbol, index: $index)")
6464

6565
// For debugging: show symbol capacity up to this point
6666
val symbolsUpToHere = if (index == 0)
@@ -75,24 +75,26 @@ class Encoder(private val symbols: List<Symbol>)
7575
val symbolSizes = symbolsUpToHere.map { it.size() }
7676
val totalCapacity = symbolSizes.fold(1) { acc, size -> acc * size }
7777

78-
println("history: $symbolSizes, p: $totalCapacity")
78+
println("history (symbol sizes): $symbolSizes, total capacity: $totalCapacity")
7979

8080
// Symbol with size 1 encodes its fixed value and passes through the current value
8181
val encodedBytes = symbol.encode(currentValue)
8282
val result = Pair(encodedBytes, currentValue)
83+
8384
println("result: (${encodedBytes.decodeToString()}, $currentValue)")
8485

8586
return result
8687
}
8788
else
8889
{
89-
println("encode_step($currentValue, $symbol, $index)")
90+
println("encode_step(currrent value: $currentValue, symbol: $symbol, index: $index)")
9091

9192
if (index == symbols.size - 1)
9293
{
9394
// Last symbol: encode all remaining value
9495
val encodedBytes = symbol.encode(currentValue)
9596
val result = Pair(encodedBytes, 0.toBigInteger())
97+
9698
println("result: (${encodedBytes.decodeToString()}, 0)")
9799

98100
return result
@@ -104,16 +106,16 @@ class Encoder(private val symbols: List<Symbol>)
104106
val remainingSymbolSizes = remainingSymbols.map { it.size() }
105107
val remainingCapacity = remainingSymbolSizes.fold(1) { acc, size -> acc * size }
106108

107-
println("history: $remainingSymbolSizes, p: $remainingCapacity")
109+
println("history:\n remaining symbol sizes $remainingSymbolSizes, remaining capacity: $remainingCapacity")
108110

109111
// Determine value for this symbol position
110112
// Division gives us how many "chunks" of remaining capacity we have
111113
val symbolValue = (currentValue / remainingCapacity.toBigInteger()).min(symbol.size().toBigInteger() - 1.toBigInteger())
112-
println("n: $symbolValue")
114+
println("Symbol value: $symbolValue")
113115

114116
// Modulo gives us what's left for the remaining symbols
115117
val leftoverValue = currentValue % remainingCapacity.toBigInteger()
116-
println("m: $leftoverValue")
118+
println("Leftover value: $leftoverValue")
117119

118120
// Encode this symbol's portion
119121
val encodedBytes = symbol.encode(symbolValue)

Codex/src/main/java/org/operatorfoundation/codex/symbols/CallLetterNumber.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CallLetterNumber : Symbol {
2626
override fun toString(): String = "CallLetterNumber"
2727

2828
override fun decode(encodedValue: ByteArray): BigInteger {
29-
return charToValue[encodedValue.toString()]
29+
return charToValue[encodedValue.decodeToString()]
3030
?: throw IllegalArgumentException("CallLetterNumber, bad value: $encodedValue")
3131
}
3232

Codex/src/main/java/org/operatorfoundation/codex/symbols/CallLetterSpace.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CallLetterSpace : Symbol {
2323
override fun toString(): String = "CallLetterSpace"
2424

2525
override fun decode(encodedValue: ByteArray): BigInteger {
26-
return charToValue[encodedValue.toString()]
26+
return charToValue[encodedValue.decodeToString()]
2727
?: throw IllegalArgumentException("CallLetterSpace, bad value: $encodedValue")
2828
}
2929

Codex/src/main/java/org/operatorfoundation/codex/symbols/GridLetter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class GridLetter : Symbol {
77
"A" to 0.toBigInteger(), "B" to 1.toBigInteger(), "C" to 2.toBigInteger(),
88
"D" to 3.toBigInteger(), "E" to 4.toBigInteger(), "F" to 5.toBigInteger(),
99
"G" to 6.toBigInteger(), "H" to 7.toBigInteger(), "I" to 8.toBigInteger(),
10-
"J" to 9.toBigInteger(), "K" to 10.toBigInteger()
10+
"J" to 9.toBigInteger(), "K" to 10.toBigInteger(), "L" to 11.toBigInteger(),
11+
"M" to 12.toBigInteger(), "N" to 13.toBigInteger(), "O" to 14.toBigInteger(),
12+
"P" to 15.toBigInteger(), "Q" to 16.toBigInteger(), "R" to 17.toBigInteger()
1113
)
1214

1315
private val valueToChar = (0..17).associate {
@@ -20,7 +22,7 @@ class GridLetter : Symbol {
2022
override fun toString(): String = "GridLetter"
2123

2224
override fun decode(encodedValue: ByteArray): BigInteger {
23-
return charToValue[encodedValue.toString()]
25+
return charToValue[encodedValue.decodeToString()]
2426
?: throw IllegalArgumentException("GridLetter, bad value $encodedValue")
2527
}
2628

Codex/src/main/java/org/operatorfoundation/codex/symbols/Number.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Number : Symbol {
1818
override fun toString(): String = "Number"
1919

2020
override fun decode(encodedValue: ByteArray): BigInteger {
21-
return charToValue[encodedValue.toString()]
21+
return charToValue[encodedValue.decodeToString()]
2222
?: throw IllegalArgumentException("Number, bad value: $encodedValue")
2323
}
2424

Codex/src/main/java/org/operatorfoundation/codex/symbols/Power.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Power : Symbol {
2121
override fun toString(): String = "Power"
2222

2323
override fun decode(encodedValue: ByteArray): BigInteger {
24-
return charToValue[encodedValue.toString()]
24+
return charToValue[encodedValue.decodeToString()]
2525
?: throw IllegalArgumentException("Power, bad value $encodedValue")
2626
}
2727

Codex/src/test/java/org/operatorfoundation/codex/EncoderDecoderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class EncoderDecoderTest
7777
val grid = wsprEncoding.subList(6, 10).joinToString("") { it.decodeToString() }
7878
val power = wsprEncoding[10].decodeToString()
7979

80-
println("$callsign $grid $power")
80+
println("WSPR Message: $callsign $grid $power")
8181

8282
// Verify decoding back to same integer
8383
val wsprDecoder = wsprEncoder.decoder()

0 commit comments

Comments
 (0)