1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
program test_packjt77_protocol_vectors
use packjt77
use packjt77_test_helpers
implicit none
integer :: ntests
ntests=0
call expect_hash_vector('K1ABC', 712, 2851, 2920267)
call expect_hash_vector('W9XYZ', 972, 3889, 3982604)
call expect_hash_vector('PJ4/K1ABC', 346, 1387, 1420834)
call expect_hash_vector('KH1/KH7Z', 201, 806, 825805)
call expect_hash_vector('K1JT/P', 959, 3839, 3931158)
call expect_hash_vector('W3CCX', 665, 2662, 2726483)
call expect_hash_vector('3DA0ABC', 48, 192, 196695)
call expect_hash_vector('3XABC', 563, 2254, 2308721)
call expect_hash_vector('///////////', 671, 2685, 2749801)
call expect_hash_vector('ZZZZZZZZZZZ', 902, 3609, 3695718)
call expect_hash_vector('99999999999', 762, 3050, 3123740)
call expect_hash_vector('A23456789Z/', 122, 488, 499902)
call expect_hash_vector(' ', 0, 0, 0)
call expect_pack_bits('K1ABC W9XYZ FN42', 1, 0, -1, -1, &
'00001001101111011110001101010000011000010100100111011100000010100001100110001')
call expect_pack_bits('<PJ4/K1ABC> W9XYZ RR73', 1, 0, -1, -1, &
'00000011010100101011000010100000011000010100100111011100000111111001110101001')
call expect_pack_bits('K1ABC RR73; W9XYZ <KH1/KH7Z> -12', 0, 1, -1, -1, &
'00001001101111011110001101010000110000101001001110111000001100100101001001000')
call expect_pack_bits('PJ2/W1AW <W7ABC> RR73', 4, 0, -1, -1, &
'00100100001100000000000000001011000010101110000110010100011010110100111100100')
call expect_pack_bits('<W3CCX> <K1JT/P> 592047 RR99XX', 5, 0, -1, -1, &
'10100110011011101111111100000101100111111111111111000111001100001111111111101')
call expect_pack_bits('K1ABC FN42 37', 0, 6, -1, -1, &
'00001001101111011110001101010101000011001100101100000000000000000000000110000')
! WSPR Type 2 prefix/suffix vectors need both exact bits and decoded text.
call expect_pack_bits('PJ2/K1ABC 37', 0, 6, -1, -1, &
'00001001101111011110001101011000000100111110010111000000000000000000000110000', &
'PJ2/K1ABC 37')
call expect_pack_bits('<PJ4/K1ABC> FK52AB', 0, 6, 0, 6, &
'01010110101110001000100010111111101110100000101010000000000000000000000110000')
call expect_unified_codec_bits('K1ABC W9XYZ FN42', -1, -1)
call expect_unified_codec_bits('FREE TEXT MSG', -1, -1)
call expect_unified_codec_bits('WA9XYZ KA1ABC R 16A EMA', -1, -1)
call expect_unified_codec_bits('WA9XYZ KA1ABC R 32A EMA', -1, -1)
call expect_unified_codec_bits('TU; W9XYZ G8ABC R 559 0013', -1, -1)
call expect_unified_codec_bits('K1ABC RR73; W9XYZ <KH1/KH7Z> -12', -1, -1)
call expect_unified_codec_bits('<PJ4/K1ABC> W9XYZ RR73', -1, -1)
call expect_unified_codec_bits('PJ2/W1AW <W7ABC> RR73', -1, -1)
call expect_unified_codec_bits('<W3CCX> <K1JT/P> 592047 RR99XX', -1, -1)
call expect_unified_codec_bits('K1ABC FN42 37', -1, -1)
call expect_unified_codec_bits('<PJ4/K1ABC> FK52AB', 0, 6)
call expect_binary_payload_for_wspr_message('PJ4/K1ABC 37')
call expect_not_wspr_payload('K1ABC/ABCD 37')
write(*,1000) ntests
1000 format('packjt77 protocol vector tests passed: ',i0)
contains
subroutine expect_hash_vector(callsign,want10,want12,want22)
character(len=*), intent(in) :: callsign
integer, intent(in) :: want10, want12, want22
character(len=13) :: c13
integer :: got10, got12, got22
c13=' '
c13=callsign
got10=ihashcall(c13,10)
got12=ihashcall(c13,12)
got22=ihashcall(c13,22)
if(got10.ne.want10 .or. got12.ne.want12 .or. got22.ne.want22) then
write(*,1010) trim(callsign), got10, got12, got22, want10, want12, want22
1010 format('Hash vector failure for "',a,'"; got ',i0,1x,i0,1x,i0, &
' wanted ',i0,1x,i0,1x,i0)
error stop 1
endif
if(got10.lt.0 .or. got10.gt.1023 .or. got12.lt.0 .or. got12.gt.4095 .or. &
got22.lt.0 .or. got22.gt.4194303) then
write(*,1040) trim(callsign), got10, got12, got22
1040 format('Hash range failure for "',a,'"; got ',i0,1x,i0,1x,i0)
error stop 1
endif
ntests=ntests+1
end subroutine expect_hash_vector
subroutine expect_pack_bits(input,want_i3,want_n3,pack_i3,pack_n3,expected_c77, &
expected_decode)
character(len=*), intent(in) :: input, expected_c77
character(len=*), intent(in), optional :: expected_decode
integer, intent(in) :: want_i3, want_n3, pack_i3, pack_n3
character(len=77) :: c77
character(len=37) :: decoded
integer :: got_i3, got_n3
logical :: ok
call pack_standard(input,pack_i3,pack_n3,got_i3,got_n3,c77)
call assert_message_type('pack77',input,want_i3,want_n3,got_i3,got_n3)
call assert_binary_payload('pack77',input,c77)
if(c77.ne.expected_c77) then
write(*,1030) trim(input), c77, expected_c77
1030 format('77-bit vector failure for "',a,'"; got ',a,' wanted ',a)
error stop 1
endif
if(present(expected_decode)) then
call reset_packjt77_state()
decoded=' '
ok=.false.
call unpack77(c77,0,decoded,ok)
call assert_decode('pack77 vector',input,expected_decode,decoded,ok)
endif
ntests=ntests+1
end subroutine expect_pack_bits
subroutine expect_unified_codec_bits(input,pack_i3,pack_n3)
character(len=*), intent(in) :: input
integer, intent(in) :: pack_i3, pack_n3
character(len=77) :: first_c77, second_c77
integer :: first_i3, first_n3, second_i3, second_n3
call pack_standard(input,pack_i3,pack_n3,first_i3,first_n3,first_c77)
call pack_standard(input,pack_i3,pack_n3,second_i3,second_n3,second_c77)
if(first_i3.ne.second_i3 .or. first_n3.ne.second_n3) then
write(*,1040) trim(input), first_i3, first_n3, second_i3, second_n3
1040 format('Unified codec type failure for "',a,'"; first pack77 got ',i0,'.',i0, &
' second pack77 got ',i0,'.',i0)
error stop 1
endif
call assert_binary_payload('pack77',input,first_c77)
call assert_binary_payload('pack77',input,second_c77)
if(first_c77.ne.second_c77) then
write(*,1050) trim(input), first_c77, second_c77
1050 format('Unified codec bit failure for "',a,'"; first pack77 ',a, &
' second pack77 ',a)
error stop 1
endif
ntests=ntests+1
end subroutine expect_unified_codec_bits
subroutine expect_binary_payload_for_wspr_message(input)
character(len=*), intent(in) :: input
character(len=77) :: c77
character(len=37) :: packed_input
integer :: got_i3, got_n3
packed_input=' '
packed_input=input
call reset_packjt77_state()
got_i3=-1
got_n3=-1
c77=''
block
type(pack77_result) :: encoded
encoded=pack77_result_from_api(packed_input)
call assert_pack77_result('pack77',packed_input,encoded)
got_i3=encoded%i3
got_n3=encoded%n3
c77=encoded%c77
end block
call assert_message_type('pack77',input,0,6,got_i3,got_n3)
call assert_binary_payload('pack77',input,c77)
ntests=ntests+1
end subroutine expect_binary_payload_for_wspr_message
subroutine expect_not_wspr_payload(input)
character(len=*), intent(in) :: input
character(len=37) :: packed_input
type(pack77_result) :: encoded
packed_input=' '
packed_input=input
call reset_packjt77_state()
encoded=pack77_result_from_api(packed_input)
if(encoded%encoded .and. encoded%i3.eq.0 .and. encoded%n3.eq.6) then
write(*,1060) trim(input)
1060 format('WSPR reject failure for "',a,'"; still packed as 0.6')
error stop 1
endif
ntests=ntests+1
end subroutine expect_not_wspr_payload
subroutine pack_standard(input,pack_i3,pack_n3,got_i3,got_n3,c77)
character(len=*), intent(in) :: input
integer, intent(in) :: pack_i3, pack_n3
integer, intent(out) :: got_i3, got_n3
character(len=77), intent(out) :: c77
character(len=37) :: packed_input
packed_input=' '
packed_input=input
call reset_packjt77_state()
got_i3=pack_i3
got_n3=pack_n3
c77=''
block
type(pack77_result) :: encoded
encoded=pack77_with_hint(packed_input,pack_i3,pack_n3)
call assert_pack77_result('pack77',packed_input,encoded)
call assert_true('pack77 gate not rejected',encoded%status.ne.PACK77_STATUS_INTERNAL_ROUNDTRIP_REJECTED)
got_i3=encoded%i3
got_n3=encoded%n3
c77=encoded%c77
end block
end subroutine pack_standard
subroutine reset_packjt77_state()
integer :: n10, n12, n22
call clear_all_state('N0AAA','N0BBB')
call save_hash_call(mycall13,hashmy10_configured,hashmy12_configured,hashmy22_configured)
hashdx10_configured=ihashcall(dxcall13,10)
call save_hash_call(dxcall13,n10,n12,n22)
call queue_hash_call_for_thread(dxcall13,1)
end subroutine reset_packjt77_state
end program test_packjt77_protocol_vectors
|