summaryrefslogtreecommitdiff
path: root/lib/wsprd/unpk.c.obsolete
blob: fae2bcf8beb59dcbc7fa20411ccc4d4f50685564 (plain)
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
/* the routine unpk() is not in wsprd_utils.c */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdint.h>
#include <time.h>

#include "wsprd_utils.h"

unsigned int nhash_( const void *key, size_t length, uint32_t initval);

void unpk_(signed char message[], int *nhashtab, char call_loc_pow[])
{
  int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh;
  char callsign[13],grid[5],grid6[7],cdbm[3];
  static char hashtab[32768][13];
  FILE *fhash;

  if(*nhashtab==1) {
    char line[80], hcall[12];
    if( (fhash=fopen("hashtable.txt","r+")) ) {
      while (fgets(line, sizeof(line), fhash) != NULL) {
	sscanf(line,"%d %s",&nh,hcall);
	strcpy(*hashtab+nh*13,hcall);
      }
    } else {
      fhash=fopen("hashtable.txt","w+");
    }
    fclose(fhash);
    return;
  }

  if(*nhashtab==2) {
    fhash=fopen("hashtable.txt","w");
    for (i=0; i<32768; i++) {
      if( strncmp(hashtab[i],"\0",1) != 0 ) {
	fprintf(fhash,"%5d %s\n",i,*hashtab+i*13);
      }
    }
    fclose(fhash);
    return;
  }

  unpack50(message,&n1,&n2);
  unpackcall(n1,callsign);
  unpackgrid(n2, grid);
  int ntype = (n2&127) - 64;
  callsign[12]=0;
  grid[4]=0;

/*
 Based on the value of ntype, decide whether this is a Type 1, 2, or 
 3 message.

 * Type 1: 6 digit call, grid, power - ntype is positive and is a member 
         of the set {0,3,7,10,13,17,20...60}

 * Type 2: extended callsign, power - ntype is positive but not
         a member of the set of allowed powers

 * Type 3: hash, 6 digit grid, power - ntype is negative.
*/

  if( (ntype >= 0) && (ntype <= 62) ) {
    int nu=ntype%10;
    if( nu == 0 || nu == 3 || nu == 7 ) {
      ndbm=ntype;
      memset(call_loc_pow,0,sizeof(char)*23);
      sprintf(cdbm,"%2d",ndbm);
      strncat(call_loc_pow,callsign,strlen(callsign));
      strncat(call_loc_pow," ",1);
      strncat(call_loc_pow,grid,4);
      strncat(call_loc_pow," ",1);
      strncat(call_loc_pow,cdbm,2);
      strncat(call_loc_pow,"\0",1);
      ihash=nhash_(callsign,strlen(callsign),(uint32_t)146);
      strcpy(*hashtab+ihash*13,callsign);
    } else {
      nadd=nu;
      if( nu > 3 ) nadd=nu-3;
      if( nu > 7 ) nadd=nu-7;
      n3=n2/128+32768*(nadd-1);
      unpackpfx(n3,callsign);
      ndbm=ntype-nadd;
      memset(call_loc_pow,0,sizeof(char)*23);
      sprintf(cdbm,"%2d",ndbm);
      strncat(call_loc_pow,callsign,strlen(callsign));
      strncat(call_loc_pow," ",1);
      strncat(call_loc_pow,cdbm,2);
      strncat(call_loc_pow,"\0",1);
      ihash=nhash_(callsign,strlen(callsign),(uint32_t)146);
      strcpy(*hashtab+ihash*13,callsign);
      noprint=0;
    }
  } else if ( ntype < 0 ) {
    ndbm=-(ntype+1);
    memset(grid6,0,sizeof(char)*7);
    strncat(grid6,callsign+5,1);
    strncat(grid6,callsign,5);
    ihash=(n2-ntype-64)/128;
    if( strncmp(hashtab[ihash],"\0",1) != 0 ) {
      sprintf(callsign,"<%s>",hashtab[ihash]);
    } else {
      sprintf(callsign,"%5s","<...>");
    }

    memset(call_loc_pow,0,sizeof(char)*23);
    sprintf(cdbm,"%2d",ndbm);
    strncat(call_loc_pow,callsign,strlen(callsign));
    strncat(call_loc_pow," ",1);
    strncat(call_loc_pow,grid6,strlen(grid6));
    strncat(call_loc_pow," ",1);
    strncat(call_loc_pow,cdbm,2);
    strncat(call_loc_pow,"\0",1);
                
    noprint=0;
                
// I don't know what to do with these... They show up as "A000AA" grids.
    if( ntype == -64 ) noprint=1;  
  }
  //  printf("\nUnpacked in C:    %s\n",call_loc_pow);
}