diff options
| author | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
| commit | c25cbdf6fb6d946175f4335fab77bfea601b56db (patch) | |
| tree | 6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /lib/superfox | |
| parent | 71f5689252c9f13e70e1c24856904475b2307809 (diff) | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (diff) | |
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'lib/superfox')
| -rw-r--r-- | lib/superfox/qpc/nhash2.c | 382 | ||||
| -rw-r--r-- | lib/superfox/qpc/nhash2.h | 7 | ||||
| -rw-r--r-- | lib/superfox/qpc/np_rnd.c | 2 | ||||
| -rw-r--r-- | lib/superfox/qpc_decode2.f90 | 6 | ||||
| -rw-r--r-- | lib/superfox/qpc_sync.f90 | 23 | ||||
| -rw-r--r-- | lib/superfox/ran1.f90 | 18 | ||||
| -rw-r--r-- | lib/superfox/sfox_pack.f90 | 249 | ||||
| -rw-r--r-- | lib/superfox/sfox_remove_ft8.f90 | 7 | ||||
| -rw-r--r-- | lib/superfox/sfox_remove_tone.f90 | 1 | ||||
| -rw-r--r-- | lib/superfox/sfox_unpack.f90 | 31 | ||||
| -rw-r--r-- | lib/superfox/sfoxsim.f90 | 7 | ||||
| -rw-r--r-- | lib/superfox/sfrx_sub.f90 | 5 | ||||
| -rw-r--r-- | lib/superfox/sftx.f90 | 21 | ||||
| -rw-r--r-- | lib/superfox/sftx_sub.f90 | 15 | ||||
| -rw-r--r-- | lib/superfox/superfox_qpc_2.txt | 5 |
15 files changed, 314 insertions, 465 deletions
diff --git a/lib/superfox/qpc/nhash2.c b/lib/superfox/qpc/nhash2.c index 78817c7d..5453947b 100644 --- a/lib/superfox/qpc/nhash2.c +++ b/lib/superfox/qpc/nhash2.c @@ -1,383 +1,9 @@ -/* - - File name: nhash2.c - - *------------------------------------------------------------------------------ - * - * This file is part of the WSPR application, Weak Signal Propogation Reporter - * - * File Name: nhash.c - * Description: Functions to produce 32-bit hashes for hash table lookup - * - * Copyright (C) 2008-2014 Joseph Taylor, K1JT - * License: GNU GPL v3+ - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Files: lookup3.c - * Copyright: Copyright (C) 2006 Bob Jenkins <bob_jenkins@burtleburtle.net> - * License: public-domain - * You may use this code any way you wish, private, educational, or commercial. - * It's free. - * - *------------------------------------------------------------------------------- -*/ - -/* -These are functions for producing 32-bit hashes for hash table lookup. -hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() -are externally useful functions. Routines to test the hash are included -if SELF_TEST is defined. You can use this free for any purpose. It's in -the public domain. It has no warranty. - -You probably want to use hashlittle(). hashlittle() and hashbig() -hash byte arrays. hashlittle() is is faster than hashbig() on -little-endian machines. Intel and AMD are little-endian machines. -On second thought, you probably want hashlittle2(), which is identical to -hashlittle() except it returns two 32-bit hashes for the price of one. -You could implement hashbig2() if you wanted but I haven't bothered here. - -If you want to find a hash of, say, exactly 7 integers, do - a = i1; b = i2; c = i3; - mix(a,b,c); - a += i4; b += i5; c += i6; - mix(a,b,c); - a += i7; - final(a,b,c); -then use c as the hash value. If you have a variable length array of -4-byte integers to hash, use hashword(). If you have a byte array (like -a character string), use hashlittle(). If you have several byte arrays, or -a mix of things, see the comments above hashlittle(). - -Why is this so big? I read 12 bytes at a time into 3 4-byte integers, -then mix those integers. This is fast (you can do a lot more thorough -mixing with 12*3 instructions on 3 integers than you can with 3 instructions -on 1 byte), but shoehorning those bytes into integers efficiently is messy. -*/ - -#define SELF_TEST 1 - -#include <stdio.h> /* defines printf for tests */ -#include <time.h> /* defines time_t for timings in the test */ #include "nhash2.h" -//#include <sys/param.h> /* attempt to define endianness */ -//#ifdef linux -//# include <endian.h> /* attempt to define endianness */ -//#endif - -#define HASH_LITTLE_ENDIAN 1 - -#define hashsize(n) ((uint32_t)1<<(n)) -#define hashmask(n) (hashsize(n)-1) -#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) - -/* -------------------------------------------------------------------------------- -mix -- mix 3 32-bit values reversibly. - -This is reversible, so any information in (a,b,c) before mix() is -still in (a,b,c) after mix(). - -If four pairs of (a,b,c) inputs are run through mix(), or through -mix() in reverse, there are at least 32 bits of the output that -are sometimes the same for one pair and different for another pair. -This was tested for: -* pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). -* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. -* the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. - -Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that -satisfy this are - 4 6 8 16 19 4 - 9 15 3 18 27 15 - 14 9 3 7 17 3 -Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing -for "differ" defined as + with a one-bit base and a two-bit delta. I -used http://burtleburtle.net/bob/hash/avalanche.html to choose -the operations, constants, and arrangements of the variables. - -This does not achieve avalanche. There are input bits of (a,b,c) -that fail to affect some output bits of (a,b,c), especially of a. The -most thoroughly mixed value is c, but it doesn't really even achieve -avalanche in c. - -This allows some parallelism. Read-after-writes are good at doubling -the number of bits affected, so the goal of mixing pulls in the opposite -direction as the goal of parallelism. I did what I could. Rotates -seem to cost as much as shifts on every machine I could lay my hands -on, and rotates are much kinder to the top and bottom bits, so I used -rotates. -------------------------------------------------------------------------------- -*/ -#define mix(a,b,c) \ -{ \ - a -= c; a ^= rot(c, 4); c += b; \ - b -= a; b ^= rot(a, 6); a += c; \ - c -= b; c ^= rot(b, 8); b += a; \ - a -= c; a ^= rot(c,16); c += b; \ - b -= a; b ^= rot(a,19); a += c; \ - c -= b; c ^= rot(b, 4); b += a; \ -} - -/* -------------------------------------------------------------------------------- -final -- final mixing of 3 32-bit values (a,b,c) into c - -Pairs of (a,b,c) values differing in only a few bits will usually -produce values of c that look totally different. This was tested for -* pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). -* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. -* the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. - -These constants passed: - 14 11 25 16 4 14 24 - 12 14 25 16 4 14 24 -and these came close: - 4 8 15 26 3 22 24 - 10 8 15 26 3 22 24 - 11 8 15 26 3 22 24 -------------------------------------------------------------------------------- -*/ -#define final(a,b,c) \ -{ \ - c ^= b; c -= rot(b,14); \ - a ^= c; a -= rot(c,11); \ - b ^= a; b -= rot(a,25); \ - c ^= b; c -= rot(b,16); \ - a ^= c; a -= rot(c,4); \ - b ^= a; b -= rot(a,14); \ - c ^= b; c -= rot(b,24); \ -} -/* -------------------------------------------------------------------------------- -hashlittle() -- hash a variable-length key into a 32-bit value - k : the key (the unaligned variable-length array of bytes) - length : the length of the key, counting by bytes - initval : can be any 4-byte value -Returns a 32-bit value. Every bit of the key affects every bit of -the return value. Two keys differing by one or two bits will have -totally different hash values. +#include "../../lookup3.h" -The best hash table sizes are powers of 2. There is no need to do -mod a prime (mod is sooo slow!). If you need less than 32 bits, -use a bitmask. For example, if you need only 10 bits, do - h = (h & hashmask(10)); -In which case, the hash table should have hashsize(10) elements. - -If you are hashing n strings (uint8_t **)k, do it like this: - for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h); - -By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this -code any way you wish, private, educational, or commercial. It's free. - -Use for hash table lookup, or anything where one collision in 2^^32 is -acceptable. Do NOT use for cryptographic purposes. -------------------------------------------------------------------------------- -*/ - -uint32_t nhash2( const void *key, uint64_t length, uint32_t initval) -//int nhash( const char *key, int length, int initval) +uint32_t nhash2(const void *key, uint64_t length, uint32_t initval) { - uint32_t a,b,c; /* internal state */ - union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ - - /* Set up the internal state */ - a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; - - u.ptr = key; - if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { - const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ - - /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } - - // printf("AAA %x %d %x %d\n",c,c,c&32767,c&32767); - - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]&0xffffff" actually reads beyond the end of the string, but - * then masks off the part it's not allowed to read. Because the - * string is aligned, the masked-off tail is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticably faster for short strings (like English words). - */ -#ifndef VALGRIND - - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff; a+=k[0]; break; - case 6 : b+=k[1]&0xffff; a+=k[0]; break; - case 5 : b+=k[1]&0xff; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff; break; - case 2 : a+=k[0]&0xffff; break; - case 1 : a+=k[0]&0xff; break; - case 0 : return c; /* zero length strings require no mixing */ - } - -#else /* make valgrind happy */ - - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ - case 1 : a+=k8[0]; break; - case 0 : return c; - } - -#endif /* !valgrind */ - - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { - const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ - const uint8_t *k8; - - /*--------------- all but last block: aligned reads and different mixing */ - while (length > 12) - { - a += k[0] + (((uint32_t)k[1])<<16); - b += k[2] + (((uint32_t)k[3])<<16); - c += k[4] + (((uint32_t)k[5])<<16); - mix(a,b,c); - length -= 12; - k += 6; - } - - /*----------------------------- handle the last (probably partial) block */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[4]+(((uint32_t)k[5])<<16); - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=k[4]; - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=k[2]; - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=k[0]; - break; - case 1 : a+=k8[0]; - break; - case 0 : return c; /* zero length requires no mixing */ - } - - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; - - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - a += ((uint32_t)k[1])<<8; - a += ((uint32_t)k[2])<<16; - a += ((uint32_t)k[3])<<24; - b += k[4]; - b += ((uint32_t)k[5])<<8; - b += ((uint32_t)k[6])<<16; - b += ((uint32_t)k[7])<<24; - c += k[8]; - c += ((uint32_t)k[9])<<8; - c += ((uint32_t)k[10])<<16; - c += ((uint32_t)k[11])<<24; - mix(a,b,c); - length -= 12; - k += 12; - } - - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=((uint32_t)k[11])<<24; - /* fall through */ - case 11: c+=((uint32_t)k[10])<<16; - /* fall through */ - case 10: c+=((uint32_t)k[9])<<8; - /* fall through */ - case 9 : c+=k[8]; - /* fall through */ - case 8 : b+=((uint32_t)k[7])<<24; - /* fall through */ - case 7 : b+=((uint32_t)k[6])<<16; - /* fall through */ - case 6 : b+=((uint32_t)k[5])<<8; - /* fall through */ - case 5 : b+=k[4]; - /* fall through */ - case 4 : a+=((uint32_t)k[3])<<24; - /* fall through */ - case 3 : a+=((uint32_t)k[2])<<16; - /* fall through */ - case 2 : a+=((uint32_t)k[1])<<8; - /* fall through */ - case 1 : a+=k[0]; - break; - case 0 : return c; - } - } - - final(a,b,c); - return c; + /* SuperFox applies its 21-bit CRC mask after hashing. */ + return wsjt_hashlittle(key, (size_t)length, initval); } diff --git a/lib/superfox/qpc/nhash2.h b/lib/superfox/qpc/nhash2.h index 1864a93f..4cdcd4a1 100644 --- a/lib/superfox/qpc/nhash2.h +++ b/lib/superfox/qpc/nhash2.h @@ -1,5 +1,5 @@ -#ifndef NHASH_H_ -#define NHASH_H_ +#ifndef SUPERFOX_NHASH2_H_ +#define SUPERFOX_NHASH2_H_ #ifdef Win32 #include "win_stdint.h" /* defines uint32_t etc */ @@ -12,8 +12,7 @@ extern "C" { #endif -uint32_t nhash( const void * key, uint64_t length, uint32_t initval); - //int nhash(const char *key, int length, int initval); +uint32_t nhash2(const void *key, uint64_t length, uint32_t initval); #ifdef __cplusplus } diff --git a/lib/superfox/qpc/np_rnd.c b/lib/superfox/qpc/np_rnd.c index df2afacc..ca6f675b 100644 --- a/lib/superfox/qpc/np_rnd.c +++ b/lib/superfox/qpc/np_rnd.c @@ -27,7 +27,7 @@ #elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ #include <stdlib.h> #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF - #define K_RAND_MAX 0x7FFFFFFF // that's the max number + #define K_RAND_MAX 2147483647.0f // that's the max number // generated by lrand48 #else #error "No good quality PRNG found" diff --git a/lib/superfox/qpc_decode2.f90 b/lib/superfox/qpc_decode2.f90 index 57152ab8..fb1dde88 100644 --- a/lib/superfox/qpc_decode2.f90 +++ b/lib/superfox/qpc_decode2.f90 @@ -5,11 +5,11 @@ subroutine qpc_decode2(c0,fsync,ftol,xdec,ndepth,dth,damp,crc_ok, & parameter(NMAX=15*12000,NFT=365,NZ=100) complex c0(NMAX) !Signal as received - complex c(NMAX) !Signal as received + complex, allocatable :: c(:) !Signal as received real py(0:127,0:127) !Probabilities for received synbol values real py0(0:127,0:127) !Probabilities for strong signal real pyd(0:127,0:127) !Dithered values for py - real s2(0:127,0:151) !Symbol spectra, including sync + real, allocatable :: s2(:,:) !Symbol spectra, including sync real s3(0:127,0:127) !Synchronized symbol spectra real No integer crc_chk,crc_sent @@ -49,6 +49,8 @@ subroutine qpc_decode2(c0,fsync,ftol,xdec,ndepth,dth,damp,crc_ok, & -5, 4, -4, 3, -5, 4, -4, -5, 4, -5/ + allocate(c(NMAX),s2(0:127,0:151)) + s2=0.0 fsample=12000.0 baud=12000.0/1024.0 nstype=1 diff --git a/lib/superfox/qpc_sync.f90 b/lib/superfox/qpc_sync.f90 index ea9afb5b..9c80b390 100644 --- a/lib/superfox/qpc_sync.f90 +++ b/lib/superfox/qpc_sync.f90 @@ -46,6 +46,12 @@ subroutine qpc_sync(crcvd0,fsample,isync,fsync,ftol,f2,t2,snrsync) s0=s0+s(i) s1=s1+(i-i0)*s(i) enddo + if(.not. (s0 .gt. 0.0)) then + f2=fsync-750.0 + t2=0.0 + snrsync=0.0 + return + endif delta=s1/s0 i0=nint(i0+delta) f2=i0*df2-750.0 @@ -105,9 +111,22 @@ subroutine qpc_sync(crcvd0,fsample,isync,fsync,ftol,f2,t2,snrsync) sp=sp + p(lag) sq=sq + p(lag)*p(lag) enddo + if(nsum .le. 0) then + snrsync=0.0 + return + endif ave=sp/nsum - rms=sqrt(sq/nsum-ave*ave) - snrsync=(pmax-ave)/rms + var=sq/nsum-ave*ave + if(.not. (var .gt. 0.0)) then + snrsync=0.0 + return + endif + rms=sqrt(var) + if(rms .gt. 0.0) then + snrsync=(pmax-ave)/rms + else + snrsync=0.0 + endif return end subroutine qpc_sync diff --git a/lib/superfox/ran1.f90 b/lib/superfox/ran1.f90 index b09b9bab..8ea83bdf 100644 --- a/lib/superfox/ran1.f90 +++ b/lib/superfox/ran1.f90 @@ -1,18 +1,24 @@ FUNCTION ran1(idum) - INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV - REAL ran1,AM,EPS,RNMX - PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836, & - NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS) + INTEGER idum + INTEGER, PARAMETER :: IA=16807,IM=2147483647,IQ=127773,IR=2836,NTAB=32 + INTEGER, PARAMETER :: NDIV=1+INT(DBLE(IM-1)/DBLE(NTAB)) + REAL ran1 + REAL, PARAMETER :: AM=1.0/REAL(IM),EPS=1.2e-7,RNMX=1.-EPS INTEGER j,k,iv(NTAB),iy SAVE iv,iy DATA iv /NTAB*0/, iy /0/ if (idum.le.0.or.iy.eq.0) then idum=max(-idum,1) - do j=NTAB+8,1,-1 + do j=NTAB+8,NTAB+1,-1 k=idum/IQ idum=IA*(idum-k*IQ)-IR*k if (idum.lt.0) idum=idum+IM - if (j.le.NTAB) iv(j)=idum + enddo + do j=NTAB,1,-1 + k=idum/IQ + idum=IA*(idum-k*IQ)-IR*k + if (idum.lt.0) idum=idum+IM + iv(j)=idum enddo iy=iv(1) endif diff --git a/lib/superfox/sfox_pack.f90 b/lib/superfox/sfox_pack.f90 index c5a6d94c..1a482422 100644 --- a/lib/superfox/sfox_pack.f90 +++ b/lib/superfox/sfox_pack.f90 @@ -1,79 +1,132 @@ -subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) +subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin,pack_error) use qpc_mod use packjt use packjt77 - use julian parameter (NQU1RKS=203514677) - integer*8 n47,n58,now + integer*8 n47,n58 integer*1 xin(0:49) !Packed message as 7-bit symbols logical*1 bMoreCQs,bSendMsg - logical text,allz + integer pack_error + integer, parameter :: SFOX_PACK_OK=0 + integer, parameter :: SFOX_PACK_BAD_TOKEN=1 + integer, parameter :: SFOX_PACK_BAD_OTP=2 + integer, parameter :: SFOX_PACK_BAD_CQ=3 + integer, parameter :: SFOX_PACK_BAD_CALL=4 + integer, parameter :: SFOX_PACK_BAD_REPORT=5 + integer, parameter :: SFOX_PACK_BAD_FREE_TEXT=6 + logical text,allz,split_success character*120 line !SuperFox message pieces character*10 ckey character*26 freeTextMsg character*13 w(16) + character*13 w1,w2,w3 !Scalar copies of w() elements passed to + !explicit-interface functions/subroutines + !below: gfortran's -Wcharacter-truncation + !treats an array-element actual argument + !as spanning the rest of w()'s storage + !sequence, so pass a same-length scalar + !instead to give it an exact length character*11 c11 character*329 msgbits !Packed message as bits character*38 c data c/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/'/ - i0=index(line,'/') + pack_error=SFOX_PACK_BAD_TOKEN + xin=0 i3=0 !Default to i3=0, standard message nh1=0 !Number of Hound calls with RR73 nh2=0 !Number of Hound calls with report ! Split the command line into words - w=' ' - i1=1 - do j=1,16 - do i=i1,min(i1+12,120) - if(line(i:i).eq.' ') exit - enddo - i2=i-1 - w(j)=line(i1:i2) - do i=i2+1,120 - if(line(i:i).ne.' ') exit - enddo - i1=i - if(i1.ge.120) exit - enddo - nwords=j - - do i=1,nwords - if(w(i)(1:1).eq.' ') then - nwords=i-1 - exit - endif - enddo + call split_sfox_line(line,w,nwords,split_success) + if(.not.split_success .or. nwords.lt.1) then + pack_error=SFOX_PACK_BAD_TOKEN + return + endif do i=1,329 !Set all msgbits to '0' msgbits(i:i)='0' enddo - now=itime8()/30 - now=30*now - read(ckey(5:10),*) notp + read(ckey(5:10),*,err=910) notp write(msgbits(307:326),'(b20.20)') notp !Insert the digital signature if(w(1)(1:3).eq.'CQ ') then + if(nwords.ne.3) then + pack_error=SFOX_PACK_BAD_CQ + return + endif + w2=w(2) + w3=w(3) + if(.not.valid_sfox_cq_call(w2) .or. .not.valid_sfox_grid4(w3)) then + pack_error=SFOX_PACK_BAD_CQ + return + endif i3=3 - c11=w(2)(1:11) + c11=w2(1:11) n58=0 do i=1,11 n58=n58*38 + index(c,c11(i:i)) - 1 enddo write(msgbits(1:58),'(b58.58)') n58 - call packgrid(w(3)(1:4),n15,text) + call packgrid(w3(1:4),n15,text) + if(text) then + pack_error=SFOX_PACK_BAD_CQ + return + endif write(msgbits(59:73),'(b15.15)') n15 write(msgbits(327:329),'(b3.3)') i3 !Message type i3=3 go to 800 endif - call pack28(w(1),n28) !Fox call + w1=w(1) + if(.not.valid_sfox_call(w1)) then + pack_error=SFOX_PACK_BAD_CALL + return + endif + call pack28(w1,n28) !Fox call write(msgbits(1:28),'(b28.28)') n28 + nrr73_total=0 + nreport_total=0 + i=2 + do while(i.le.nwords) + if(w(i)(1:1).eq.'+' .or. w(i)(1:1).eq.'-') then + pack_error=SFOX_PACK_BAD_TOKEN + return + endif + if(.not.valid_sfox_call(w(i))) then + pack_error=SFOX_PACK_BAD_CALL + return + endif + i1=i+1 + if(i1.le.nwords .and. & + (w(i1)(1:1).eq.'+' .or. w(i1)(1:1).eq.'-')) then + if(.not.valid_sfox_report(w(i1),n)) then + pack_error=SFOX_PACK_BAD_REPORT + return + endif + nreport_total=nreport_total+1 + i=i+2 + else + nrr73_total=nrr73_total+1 + i=i+1 + endif + enddo + + if(bSendMsg) then + if(nrr73_total+nreport_total.gt.4 .or. nreport_total.gt.4) then + pack_error=SFOX_PACK_BAD_TOKEN + return + endif + else if(nrr73_total.gt.5 .or. nreport_total.gt.4 .or. & + nrr73_total+nreport_total.gt.9) then + pack_error=SFOX_PACK_BAD_TOKEN + return + endif + ! Default report is RR73 if we're also sending a free text message. if(bSendMsg) msgbits(141:160)='11111111111111111111' @@ -84,6 +137,10 @@ subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) if(w(i)(1:1).eq.'+' .or. w(i)(1:1).eq.'-') cycle !Skip report words i1=min(i+1,nwords) if(w(i1)(1:1) .eq.'+' .or. w(i1)(1:1).eq.'-') cycle !Skip if i+1 is report + if(.not.valid_sfox_call(w(i))) then + pack_error=SFOX_PACK_BAD_CALL + return + endif call pack28(w(i),n28) write(msgbits(j:j+27),1002) n28 !Insert this call for RR73 message 1002 format(b28.28) @@ -104,11 +161,16 @@ subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) do i=2,nwords i1=min(i+1,nwords) if(w(i1)(1:1).eq.'+' .or. w(i1)(1:1).eq.'-') then + if(.not.valid_sfox_call(w(i))) then + pack_error=SFOX_PACK_BAD_CALL + return + endif call pack28(w(i),n28) write(msgbits(j:j+27),1002) n28 !Insert this call - read(w(i1),*) n !Valid reports are -18 to +12, plus RR73 - if(n.lt.-18) n=-18 !... Even numbers only ... - if(n.gt.12) n=12 + if(.not.valid_sfox_report(w(i1),n)) then + pack_error=SFOX_PACK_BAD_REPORT + return + endif write(msgbits(j2:j2+4),1000) n+18 1000 format(b5.5) w(i1)="" @@ -121,6 +183,10 @@ subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) enddo 800 if(bSendMsg) then + if(.not.valid_sfox_free_text(freeTextMsg)) then + pack_error=SFOX_PACK_BAD_FREE_TEXT + return + endif i1=26 do i=1,26 if(freeTextMsg(i:i).ne.' ') i1=i @@ -174,5 +240,116 @@ subroutine sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) xin=xin(49:0:-1) !Reverse the symbol order ! NB: CRC is now in first three symbols, fox call in the last four. + pack_error=SFOX_PACK_OK +900 continue return +910 pack_error=SFOX_PACK_BAD_OTP + go to 900 + +contains + + subroutine split_sfox_line(text,words,nwords,success) + character*120 text + character*13 words(16) + integer nwords + logical success + integer first,last + + words=' ' + nwords=0 + success=.true. + first=1 + do while(first.le.120) + do while(first.le.120) + if(text(first:first).ne.' ') exit + first=first+1 + enddo + if(first.gt.120) exit + + last=first + do while(last.le.120) + if(text(last:last).eq.' ') exit + last=last+1 + enddo + if(last-first.gt.13) then + success=.false. + return + endif + if(nwords.ge.16) then + success=.false. + return + endif + nwords=nwords+1 + words(nwords)=text(first:last-1) + first=last+1 + enddo + end subroutine split_sfox_line + + logical function valid_sfox_call(call) + character*13 call + character*13 decoded + logical success + integer n28 + + valid_sfox_call=.false. + call pack28(call,n28) + call unpack28(n28,decoded,success) + if(.not.success) return + valid_sfox_call=trim(decoded).eq.trim(call) + return + end function valid_sfox_call + + logical function valid_sfox_cq_call(callsign) + character*13 callsign + integer n + + valid_sfox_cq_call=.false. + n=len(trim(callsign)) + if(n.lt.3 .or. n.gt.11) return + do i=1,n + if(index(c(2:38),callsign(i:i)).eq.0) return + enddo + + valid_sfox_cq_call=.true. + return + end function valid_sfox_cq_call + + logical function valid_sfox_grid4(grid) + character*13 grid + + valid_sfox_grid4=len(trim(grid)).eq.4 .and. & + grid(1:1).ge.'A' .and. grid(1:1).le.'R' .and. & + grid(2:2).ge.'A' .and. grid(2:2).le.'R' .and. & + grid(3:3).ge.'0' .and. grid(3:3).le.'9' .and. & + grid(4:4).ge.'0' .and. grid(4:4).le.'9' + return + end function valid_sfox_grid4 + + logical function valid_sfox_report(word,n) + character*13 word + integer n + + valid_sfox_report=.false. + read(word,*,err=910,end=910) n + if(n.lt.-18 .or. n.gt.12) return + valid_sfox_report=.true. +910 return + end function valid_sfox_report + + logical function valid_sfox_free_text(text) + character*26 text + character*42 text_chars +! Authoritative free-text charset; the GUI precheck in on_pbFreeText_clicked +! (widgets/mainwindow_slots.cpp) must mirror this string. + data text_chars/' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-./?'/ + + valid_sfox_free_text=.true. + do i=1,26 + if(index(text_chars,text(i:i)).eq.0) then + valid_sfox_free_text=.false. + return + endif + enddo + return + end function valid_sfox_free_text end subroutine sfox_pack diff --git a/lib/superfox/sfox_remove_ft8.f90 b/lib/superfox/sfox_remove_ft8.f90 index fc990bca..75687659 100644 --- a/lib/superfox/sfox_remove_ft8.f90 +++ b/lib/superfox/sfox_remove_ft8.f90 @@ -133,8 +133,11 @@ subroutine sfox_remove_ft8(dd,npts) nt=2**(3*nsym) do ihalf=1,2 do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 + if(ihalf.eq.1) then + ks=k+7 + else + ks=k+43 + endif amax=-1.0 do i=0,nt-1 i3=iand(i,7) diff --git a/lib/superfox/sfox_remove_tone.f90 b/lib/superfox/sfox_remove_tone.f90 index c8f9e033..35a6fbec 100644 --- a/lib/superfox/sfox_remove_tone.f90 +++ b/lib/superfox/sfox_remove_tone.f90 @@ -68,6 +68,7 @@ subroutine sfox_remove_tone(c0,fsync) s0=s0+s(i) s1=s1+(i-i0)*s(i) enddo + if(.not. (s0 .gt. 0.0)) exit delta=s1/s0 i0=nint(i0+delta) f2=i0*df diff --git a/lib/superfox/sfox_unpack.f90 b/lib/superfox/sfox_unpack.f90 index 56168963..fd940347 100644 --- a/lib/superfox/sfox_unpack.f90 +++ b/lib/superfox/sfox_unpack.f90 @@ -23,16 +23,16 @@ subroutine sfox_unpack(nutc,x,nsnr,f0,dt0,foxcall,notp) endif write(msgbits,1000) x(0:46) 1000 format(47b7.7) - read(msgbits(327:329),'(b6)') i3 !Message type + read(msgbits(327:329),'(b3)') i3 !Message type read(msgbits(1:28),'(b28)') n28 !Standard Fox call call unpack28(n28,foxcall,success) - if(i3.eq.1) then !Compound Fox callsign -! read(msgbits(87:101),'(b15)') n15 -! call unpackgrid(n15,grid4) -! msg(1)='CQ '//trim(foxcall)//' '//grid4 -! write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1)) -! go to 100 + if(i3.eq.1) then +! Type i3=1 is documented for a compound-Fox c58 layout, but the +! current transmitter does not emit it and this decoder does not +! implement the c58 field offsets. Do not render hound messages with +! a mis-decoded c28 Fox call. + go to 900 else if(i3.eq.2) then !Up to 4 Hound calls and free text call unpacktext77(msgbits(161:231),freeTextMsg(1:13)) call unpacktext77(msgbits(232:302),freeTextMsg(14:26)) @@ -54,8 +54,12 @@ subroutine sfox_unpack(nutc,x,nsnr,f0,dt0,foxcall,notp) call unpackgrid(n15,grid4) msg(1)='CQ '//trim(foxcall)//' '//grid4 write(*,1100) nutc,nsnr,dt0,nint(f0),trim(msg(1)) - read(msgbits(74:105),'(b32)') n32 - if(n32.eq.NQU1RKS) go to 100 + allz=1 + do i=0,6 + read(msgbits(74+32*i:105+32*i),'(b32)') n32 + if(n32.ne.NQU1RKS) allz=0 + enddo + if(allz.eq.1) go to 100 call unpacktext77(msgbits(74:144),freeTextMsg(1:13)) call unpacktext77(msgbits(145:215),freeTextMsg(14:26)) do i=26,1,-1 @@ -112,8 +116,9 @@ subroutine sfox_unpack(nutc,x,nsnr,f0,dt0,foxcall,notp) 100 read(msgbits(307:326),'(b20)') notp if (use_otp) then - write(ssignature,'(I6.6)') notp - write(*,1100) nutc,nsnr,dt0,nint(f0),'$VERIFY$ '//trim(foxcall)//' '//trim(ssignature) - endif - return + write(ssignature,'(I6.6)') notp + write(*,1100) nutc,nsnr,dt0,nint(f0),'$VERIFY$ '//trim(foxcall)// & + ' '//trim(ssignature) + endif +900 return end subroutine sfox_unpack diff --git a/lib/superfox/sfoxsim.f90 b/lib/superfox/sfoxsim.f90 index 86f7019e..1b4bb9f2 100644 --- a/lib/superfox/sfoxsim.f90 +++ b/lib/superfox/sfoxsim.f90 @@ -11,6 +11,7 @@ program sfoxsim type(hdr) h !Header for .wav file logical*1 bMoreCQs !Include a CQ when space available? logical*1 bSendMsg !Send a Free text message + integer pack_error integer*2 iwave(NMAX) !Generated i*2 waveform integer isync(24) !Indices of sync symbols integer itone(151) !Symbol values, data and sync @@ -112,7 +113,8 @@ program sfoxsim ! Generate a SuperFox message nslots=5 call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages - call sfox_pack(line,ckey,bMoreCQs,bSendMsg,text_msg,xin) + call sfox_pack(line,ckey,bMoreCQs,bSendMsg,text_msg,xin,pack_error) + if(pack_error.ne.0) error stop 'SuperFox pack failed' call qpc_encode(y,xin) y=cshift(y,1) @@ -137,6 +139,7 @@ program sfoxsim xdt=ran1(idum)-0.5 endif ! Generate cdat, the SuperFox waveform + cdat=0. call sfox_gen_gfsk(chansym,f1,isync,itone,cdat) crcvd=0. @@ -156,7 +159,7 @@ program sfoxsim nmin=(nsec-nhr*3600)/60 nsec=mod(nsec,60) write(fname(8:13),'(3i2.2)') nhr,nmin,nsec - open(10,file=trim(fname),access='stream',status='unknown') + open(10,file=trim(fname),access='stream',status='replace') write(10) h,iwave(1:NMAX) !Save the .wav file close(10) enddo ! ifile diff --git a/lib/superfox/sfrx_sub.f90 b/lib/superfox/sfrx_sub.f90 index 12a48e08..fed03461 100644 --- a/lib/superfox/sfrx_sub.f90 +++ b/lib/superfox/sfrx_sub.f90 @@ -7,8 +7,8 @@ subroutine sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave) integer*8 secday,ntime8 integer*1 xdec(0:49) character*13 foxcall - complex c0(NMAX) !Complex form of signal as received - real dd(NMAX) + complex, allocatable :: c0(:) !Complex form of signal as received + real, allocatable :: dd(:) logical crc_ok data secday/86400/ @@ -31,6 +31,7 @@ subroutine sfrx_sub(nyymmdd,nutc,nfqso,ntol,iwave) ntime8=secday*(JD(iyr,imo,iday)-2440588) + 3600*ih + 60*im + is endif + allocate(c0(NMAX),dd(NMAX)) dd=iwave call sfox_remove_ft8(dd,npts) diff --git a/lib/superfox/sftx.f90 b/lib/superfox/sftx.f90 index 78b5ca15..d629eb7d 100644 --- a/lib/superfox/sftx.f90 +++ b/lib/superfox/sftx.f90 @@ -17,22 +17,15 @@ program sftx character*120 line !List of SuperFox message pieces character*40 cmsg(5) !Old-style Fox messages character*26 freeTextMsg - character*2 arg character*10 ckey ! character*9 foxkey character*11 foxcall0,foxcall logical*1 bMoreCQs,bSendMsg - logical crc_ok - real py(0:127,0:127) !Probabilities for received synbol values - integer*8 n47 + integer pack_error integer itone(151) !SuperFox channel-symbol values integer*1 xin(0:49) !Packed message as 7-bit symbols - integer*1 xdec(0:49) !Decoded message integer*1 y(0:127) !Encoded symbols as i*1 integers - integer*1 ydec(0:127) !Decoded codeword - integer*1 yy(0:10) integer chansym0(127) !Transmitted symbols, data only - integer chansym(127) !Received symbols, data only integer isync(24) !Symbol numbers for sync tones data isync/1,2,4,7,11,16,22,29,37,39,42,43,45,48,52,57,63,70,78,80, & 83,84,86,89/ @@ -70,15 +63,21 @@ program sftx freeTextMsg=' ' bMoreCQs=cmsg(1)(40:40).eq.'1' bSendMsg=cmsg(nslots)(39:39).eq.'1' + nDataSlots=nslots if(bSendMsg) then freeTextMsg=cmsg(nslots)(1:26) - if(nslots.gt.2) nslots=2 + nDataSlots=nslots-1 + if(nDataSlots.gt.4) nDataSlots=4 endif - call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages + call foxgen2(nDataSlots,cmsg,line,foxcall) !Parse old-style Fox messages ! Pack message information and CRC into xin(0:49) - call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) + call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin,pack_error) + if(pack_error.ne.0) then + itone=-99 + go to 100 + endif call qpc_encode(y,xin) !Encode the message to 128 symbols y=cshift(y,1) !Puncture the code by removing y(0) y(127)=0 diff --git a/lib/superfox/sftx_sub.f90 b/lib/superfox/sftx_sub.f90 index ed6c678c..310bb059 100644 --- a/lib/superfox/sftx_sub.f90 +++ b/lib/superfox/sftx_sub.f90 @@ -1,4 +1,4 @@ -subroutine sftx_sub(ckey0) +subroutine sftx_sub(ckey0,pack_error) ! This routine is required in order to create a SuperFox transmission. @@ -20,6 +20,7 @@ subroutine sftx_sub(ckey0) character*10 ckey character*11 foxcall logical*1 bMoreCQs,bSendMsg + integer pack_error integer*1 xin(0:49) !Packed message as 7-bit symbols integer*1 y(0:127) !Encoded symbols as i*1 integers integer chansym0(127) !Transmitted symbols, data only @@ -35,15 +36,21 @@ subroutine sftx_sub(ckey0) freeTextMsg=' ' bMoreCQs=cmsg(1)(40:40).eq.'1' bSendMsg=cmsg(nslots)(39:39).eq.'1' + nDataSlots=nslots if(bSendMsg) then freeTextMsg=cmsg(nslots)(1:26) - if(nslots.gt.4) nslots=4 + nDataSlots=nslots-1 + if(nDataSlots.gt.4) nDataSlots=4 endif - call foxgen2(nslots,cmsg,line,foxcall) !Parse old-style Fox messages + call foxgen2(nDataSlots,cmsg,line,foxcall) !Parse old-style Fox messages ! Pack message information and CRC into xin(0:49) - call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin) + call sfox_pack(line,ckey,bMoreCQs,bSendMsg,freeTextMsg,xin,pack_error) + if(pack_error.ne.0) then + itone=-99 + return + endif call qpc_encode(y,xin) !Encode the message to 128 symbols y=cshift(y,1) !Puncture the code by removing y(0) y(127)=0 diff --git a/lib/superfox/superfox_qpc_2.txt b/lib/superfox/superfox_qpc_2.txt index f89bffe1..51bf80ac 100644 --- a/lib/superfox/superfox_qpc_2.txt +++ b/lib/superfox/superfox_qpc_2.txt @@ -50,13 +50,14 @@ G Grid locator (15 bits) H Hound call (28 bits) M Message type (3 bits) Q MoreCQs flag -R Report, (5 bits: -18 to +12 dB, or RR73) +R Report, (5 bits: integer dB value -18 through +12, or RR73) T Free text, up to 26 characters total U Unused bits Unused callsign slots are set to the numerical value for "QU1RKS", and ignored when received. Similarly for unused t71 slots. Unused report -slots are set to 0 (-20 dB). "CQ FoxCall" will be displayed along +slots are set to raw value 0, which decodes as -18 dB if displayed. +"CQ FoxCall" will be displayed along with other messages if the "q1" bit is 1. The SuperFox decoder displays its results with a separate line for each Hound. |
