/* Generated by XDS Modula-2 to ANSI C v4.20 translator */ #define X2C_int32 #define X2C_index32 #ifndef X2C_H_ #include "X2C.h" #endif #define tetradec_C_ #ifndef osi_H_ #include "osi.h" #endif #include #ifndef mlib_H_ #include "mlib.h" #endif #ifndef udp_H_ #include "udp.h" #endif #ifndef aprspos_H_ #include "aprspos.h" #endif #ifndef aprsstr_H_ #include "aprsstr.h" #endif #ifndef viterbi_cch_H_ #include "viterbi_cch.h" #endif #include #include /* decode demodulated and frame synced tetra d4psk by OE5DXL */ /*, execv*/ #define tetradec_PI 3.1415926535898 #define tetradec_PI2 6.2831853071796 #define tetradec_RAD 1.7453292519943E-2 #define tetradec_D4BITS 2 /* bits per symbol */ #define tetradec_SBBLK1BITS 120 #define tetradec_SBBLK2BITS 216 #define tetradec_SBBBKBITS 30 #define tetradec_NDBBBK1BITS 14 #define tetradec_NDBBBK1OFFSET 230 #define tetradec_NDBBBK2OFFSET 266 #define tetradec_NDBBBK2BITS 16 #define tetradec_NDBBLKBITS 216 #define tetradec_NDBBLK1OFFSET 14 #define tetradec_NDBBLK2OFFSET 282 #define tetradec_UNDBBLK1OFFSET 28 #define tetradec_UNDBBLK2OFFSET 266 struct CONTEXT; struct CONTEXT { uint32_t xor; uint32_t mn; uint32_t tn; uint32_t fn; char istrafic; }; struct PROCESSHANDLE; struct PROCESSHANDLE { int32_t pid; char started; char runs; int32_t ptyfd; int32_t exitcode; }; static uint32_t tetradec_SCRAMBINIT = 0x3UL; #define tetradec_INB 16384 #define tetradec_CHANS 4 static char isuplink; static char verb; static uint32_t jipnum; static int32_t soundfd; static int32_t udpsock; static uint32_t nosoundcnt; static uint32_t channels; static uint32_t judpport; static uint32_t RMTAB[16384]; static char codeccmd[1024]; struct _0; union _1; union _1 { char b[32768]; short w[16384]; }; struct _0 { int32_t fd; uint32_t len; float alc; union _1 buf; }; static struct _0 child[4]; static struct CONTEXT context; static void Err(const char text[], uint32_t text_len) { osi_WrStr("tetradec: ", 11ul); osi_WrStr(text, text_len); osi_WrStrLn(" error abort", 13ul); X2C_ABORT(); } /* end Err() */ /**********************************************************************/ /* open the corresponding slave of a pseudo tty pair, adjust the * terminal setting, redirect our stdin/out/err to this tty, and * finalle make it our controlling terminal. * return: 0=success, -1=failure */ static int32_t GetSlavePty(char name[], uint32_t name_len) { int32_t fd; int32_t res; int32_t GetSlavePty_ret; X2C_PCOPY((void **)&name,name_len); res = chown((char *)name, 0L, 0L); res = chmod((char *)name, 384L); /* IF setsid()<0 THEN Close(fd); RETURN -1; END; */ /* fd:=open(name, O_RDWR+O_NOCTTY); */ fd = open(name, O_RDWR); if (fd<0L) { GetSlavePty_ret = -1L; goto label; } /* (* now adjust the terminal settings *) res:=tcgetattr( fd, term ); WITH term DO c_lflag := CARDINAL( BITSET(c_lflag)+BITSET(ECHO)+BITSET(ICANON) ); c_oflag := CARDINAL( BITSET(c_oflag)+BITSET(ONLCR)); c_iflag := CARDINAL( BITSET(c_iflag)+BITSET(ICRNL)+BITSET(ISIG) -BITSET(IXOFF)); -- c_cflag := CARDINAL( BITSET(c_cflag)-BITSET(CLOCAL)); END; res:=tcsetattr(fd, TCSANOW, term); */ /* create new session id, and set controlling terminal */ if (setsid()<0L) { osic_Close(fd); GetSlavePty_ret = -1L; goto label; } /* IF ioctl(fd, TIOCSCTTY, NIL) < 0 THEN Close(fd); RETURN -1; END; */ if (osi_setttybaudraw(fd, 1200UL)<0L) X2C_ABORT(); /* and finally redirect stdin, stdout, stderr */ if (fd) res = dup2(fd, 0L); if (fd!=1L) res = dup2(fd, 1L); if (fd!=2L) res = dup2(fd, 2L); if (fd>2L) osic_Close(fd); GetSlavePty_ret = 0L; label:; X2C_PFREE(name); return GetSlavePty_ret; } /* end GetSlavePty() */ /**********************************************************************/ /* Find a currently unused pseudo tty and open its master side; * return-value: 0=ok, <0=error * on successfull function return, fd will contain the file descriptor, * and PtyName the absolute path to the master-pty in the file system */ static int32_t GetNewTty(int32_t * fd, char ptsname[], uint32_t ptsname_len) { int32_t res; struct termios term; *fd = open("/dev/ptmx", O_RDWR+O_NONBLOCK); if (*fd<0L) osi_WrStrLn("error /dev/ptmx open", 21ul); if (osi_getptsname(*fd, (char *)ptsname, ptsname_len)) { osi_WrStrLn("no ttyname", 11ul); } /* WrStrLn(ptsname); */ if (osic_grantpts(*fd)) osi_WrStrLn("error ptty grant", 17ul); if (osic_unlockpts(*fd)) osi_WrStrLn("error ptty unlock", 18ul); res = tcgetattr(*fd, &term); term.c_lflag = 0UL; res = tcsetattr(*fd, 0L, &term); return 0L; } /* end GetNewTty() */ #define tetradec_ARGS 100 #define tetradec_QUOTT "\"" static void StartProg(char name[], uint32_t name_len, struct PROCESSHANDLE * chpid, int32_t * childfd) { int32_t e; char pgmname[1025]; char argt[100][1025]; X2C_pCHAR * args; char * arga[100]; char quot; uint32_t a; uint32_t len; uint32_t j; uint32_t i0; char PtyName[1024]; X2C_PCOPY((void **)&name,name_len); /*WrStr("start: "); WrStrLn(name); */ if (GetNewTty(childfd, PtyName, 1024ul)<0L) { Err("tty for child process failed", 29ul); } chpid->pid = fork(); if (chpid->pid==0L) { /* child */ for (i0 = 0UL; i0<=1023UL; i0++) { osic_Close((int32_t)i0); } /* end for */ /* Close(childfd); */ e = GetSlavePty(PtyName, 1024ul); if (e<0L) X2C_ABORT(); len = aprsstr_Length(name, name_len); i0 = 0UL; j = 0UL; quot = 0; while (i0' ')) { if (name[i0]=='\"') quot = !quot; else if (j<1024UL) { pgmname[j] = name[i0]; ++j; } ++i0; } pgmname[j] = 0; /*WrStr(" <<<");WrStr(pgmname);WrStrLn(">>>"); */ /* WHILE (i" ") DO INC(i) END; (* end of program name *) */ quot = 0; while (i0>0UL && name[i0-1UL]!='/') { if (name[i0]=='\"') quot = !quot; --i0; } /* program name without path */ for (a = 0UL; a<=99UL; a++) { while (i0' ')) { if (name[i0]=='\"') quot = !quot; else if (j<1024UL) { argt[a][j] = name[i0]; ++j; } ++i0; } argt[a][j] = 0; /*WrInt(a, 5); WrStr(" <<");WrStr(argt[a]);WrStrLn(">>"); */ if (j>0UL) arga[a] = (char *)argt[a]; else arga[a] = 0; } /* end for */ /*WrStrLn("child start"); */ args = (X2C_pCHAR *)arga; e = execv(pgmname, args); /*WrStrLn("child end"); */ X2C_ABORT(); } chpid->runs = chpid->pid>=0L; /* ok or fork error */ /* parent */ X2C_PFREE(name); } /* end StartProg() */ #define tetradec_bytes 2 /*-------- write wav header */ static void wwav(int32_t fd, uint32_t hz, uint32_t chan) { char b[44]; strncpy(b,"RIFF WAVEfmt ",44u); b[4U] = '\377'; /* len */ b[5U] = '\377'; b[6U] = '\377'; b[7U] = '\377'; b[16U] = '\020'; b[17U] = 0; b[18U] = 0; b[19U] = 0; b[20U] = '\001'; /* PCM/ALAW */ b[21U] = 0; b[22U] = (char)chan; /* channels */ b[23U] = 0; b[24U] = (char)(hz&255UL); /* samp */ b[25U] = (char)(hz/256UL&255UL); b[26U] = (char)(hz/65536UL&255UL); b[27U] = (char)(hz/16777216UL); b[28U] = (char)(hz*2UL&255UL); /* byte/s */ b[29U] = (char)((hz*2UL)/256UL&255UL); b[30U] = (char)((hz*2UL)/65536UL); b[31U] = 0; b[32U] = '\002'; /* block byte */ b[33U] = 0; b[34U] = '\020'; /* bit/samp */ b[35U] = 0; b[36U] = 'd'; b[37U] = 'a'; b[38U] = 't'; b[39U] = 'a'; b[40U] = '\377'; /* len */ b[41U] = '\377'; b[42U] = '\377'; b[43U] = '\377'; if (fd>=0L) osi_WrBin(fd, (char *)b, 44u/1u, 44UL); } /* end wwav() */ /*------- init reed muller decode */ static uint8_t tetradec_RM3014[224] = {1U,0U,0U,1U,1U,0U,1U,1U,0U,1U,1U,0U, 0U,0U,0U,0U,0U,0U,1U,0U,1U,1U,0U,1U,1U,1U,1U,0U,0U,0U,0U,0U, 1U,1U,1U,1U,1U,1U,0U,0U,0U,0U,1U,0U,0U,0U,0U,0U,1U,1U,1U,0U, 0U,0U,0U,0U,0U,0U,1U,1U,1U,1U,0U,0U,1U,0U,0U,1U,1U,0U,0U,0U, 0U,0U,1U,1U,1U,0U,1U,0U,0U,1U,0U,1U,0U,1U,0U,0U,0U,0U,1U,1U, 0U,1U,1U,0U,0U,0U,1U,0U,1U,1U,0U,0U,0U,0U,1U,0U,1U,1U,1U,0U, 1U,1U,1U,1U,1U,1U,1U,1U,1U,1U,0U,1U,1U,1U,1U,1U,1U,0U,0U,0U, 0U,0U,1U,1U,0U,0U,1U,1U,1U,0U,0U,1U,0U,1U,0U,0U,0U,0U,1U,0U, 1U,0U,1U,1U,0U,1U,0U,1U,0U,0U,1U,0U,0U,0U,0U,1U,1U,0U,1U,0U, 1U,1U,0U,1U,0U,0U,0U,1U,0U,0U,1U,0U,0U,1U,1U,1U,0U,0U,1U,1U, 0U,0U,0U,0U,1U,0U,0U,1U,0U,1U,1U,0U,1U,0U,1U,1U,0U,0U,0U,0U, 0U,1U,0U,0U,1U,1U,1U,0U,0U,1U,1U,1U}; static uint8_t _cnst[224] = {1U,0U,0U,1U,1U,0U,1U,1U,0U,1U,1U,0U,0U,0U,0U, 0U,0U,0U,1U,0U,1U,1U,0U,1U,1U,1U,1U,0U,0U,0U,0U,0U,1U,1U,1U, 1U,1U,1U,0U,0U,0U,0U,1U,0U,0U,0U,0U,0U,1U,1U,1U,0U,0U,0U,0U, 0U,0U,0U,1U,1U,1U,1U,0U,0U,1U,0U,0U,1U,1U,0U,0U,0U,0U,0U,1U, 1U,1U,0U,1U,0U,0U,1U,0U,1U,0U,1U,0U,0U,0U,0U,1U,1U,0U,1U,1U, 0U,0U,0U,1U,0U,1U,1U,0U,0U,0U,0U,1U,0U,1U,1U,1U,0U,1U,1U,1U, 1U,1U,1U,1U,1U,1U,1U,0U,1U,1U,1U,1U,1U,1U,0U,0U,0U,0U,0U,1U, 1U,0U,0U,1U,1U,1U,0U,0U,1U,0U,1U,0U,0U,0U,0U,1U,0U,1U,0U,1U, 1U,0U,1U,0U,1U,0U,0U,1U,0U,0U,0U,0U,1U,1U,0U,1U,0U,1U,1U,0U, 1U,0U,0U,0U,1U,0U,0U,1U,0U,0U,1U,1U,1U,0U,0U,1U,1U,0U,0U,0U, 0U,1U,0U,0U,1U,0U,1U,1U,0U,1U,0U,1U,1U,0U,0U,0U,0U,0U,1U,0U, 0U,1U,1U,1U,0U,0U,1U,1U,1U}; static void RMinit(void) { uint32_t j; uint32_t i0; uint32_t b; uint32_t rows[14]; for (i0 = 0UL; i0<=13UL; i0++) { b = X2C_LSH(0x1UL,32,(int32_t)i0); for (j = 0UL; j<=15UL; j++) { if ((uint32_t)_cnst[j+16UL*i0]>0UL) b |= (1UL<<14UL+j); } /* end for */ rows[i0] = b; } /* end for */ for (j = 0UL; j<=16383UL; j++) { b = 0UL; for (i0 = 0UL; i0<=13UL; i0++) { if (X2C_IN(13UL-i0,32,(uint32_t)j)) b = b^rows[i0]; } /* end for */ RMTAB[j] = b; } /* end for */ } /* end RMinit() */ static int32_t createnonblockfile(char fn[], uint32_t fn_len) { int32_t fd; int32_t createnonblockfile_ret; X2C_PCOPY((void **)&fn,fn_len); fd = osi_OpenNONBLOCK(fn, fn_len); if (fd<0L || !osi_IsFifo(fd)) { /* no pipe */ if (fd>=0L) osic_Close(fd); fd = osi_OpenWrite(fn, fn_len); } createnonblockfile_ret = fd; X2C_PFREE(fn); return createnonblockfile_ret; } /* end createnonblockfile() */ #define tetradec_DEFAULTIP 0x7F000001 #define tetradec_PORTSEP ":" static int32_t GetIp(char h[], uint32_t h_len, uint32_t * ip, uint32_t * port) { uint32_t p; uint32_t n; uint32_t i0; char ok0; int32_t GetIp_ret; X2C_PCOPY((void **)&h,h_len); p = 0UL; h[h_len-1] = 0; *ip = 0UL; for (i0 = 0UL; i0<=4UL; i0++) { if (i0>=3UL || h[0UL]!=':') { n = 0UL; ok0 = 0; while ((uint8_t)h[p]>='0' && (uint8_t)h[p]<='9') { ok0 = 1; n = (n*10UL+(uint32_t)(uint8_t)h[p])-48UL; ++p; } if (!ok0) { GetIp_ret = -1L; goto label; } } if (i0<3UL) { if (h[0UL]!=':') { if (h[p]!='.' || n>255UL) { GetIp_ret = -1L; goto label; } *ip = *ip*256UL+n; } } else if (i0==3UL) { if (h[0UL]!=':') { *ip = *ip*256UL+n; if (h[p]!=':' || n>255UL) { GetIp_ret = -1L; goto label; } } else { p = 0UL; *ip = 2130706433UL; } } else if (n>65535UL) { GetIp_ret = -1L; goto label; } *port = n; ++p; } /* end for */ GetIp_ret = 0L; label:; X2C_PFREE(h); return GetIp_ret; } /* end GetIp() */ static void parms(void) { char h[4096]; char lasth; char err; uint32_t val; err = 0; udpsock = -1L; soundfd = -1L; channels = 2UL; strncpy(codeccmd,"decode.sh",1024u); for (;;) { osi_NextArg(h, 4096ul); if (h[0U]==0) break; if ((h[0U]=='-' && h[1U]) && h[2U]==0) { lasth = h[1U]; if (lasth=='h') { osi_WrStrLn("Tetra dqpsk decoder with 1 2 or 4 channel .wav voice\ output (unencrypted trunking mode)", 88ul); osi_WrStrLn(" -C task command for voice decoder (deco\ de.sh)", 59ul); osi_WrStrLn(" #!/bin/bash", 31ul); osi_WrStrLn(" cdecode /dev/stdin /dev/stdout 2>\ /dev/null | sdecode /dev/stdin /dev/stdout 2>/dev/null | tee /tmp/slot$1.raw", 129ul); osi_WrStrLn(" -c audio channels 1, 2 or 4, less than \ 4: mono/stereo downmix (2)", 79ul); osi_WrStrLn(" -h this", 21ul); osi_WrStrLn(" -J receive udp json tetra frames\ with metadata, ip=0.0.0.0 reveive from any source", 103ul); osi_WrStrLn(" -v verbous", 24ul); osi_WrStrLn(" -u decoding uplink needs scrambler code\ seen by decoding downlink -v \"sc\" or give any number and decode a while do\ wnlink before uplink", 148ul); osi_WrStrLn(" -w write wav file or unbreakable pi\ pe", 55ul); osi_WrStrLn("", 1ul); osi_WrStrLn("mknod pipe.wav p", 17ul); osi_WrStrLn("rtl_sdr -f 430.5m -s 1000000 - | fsk4rx -i /dev/stdi\ n -m d,18000,20000 -r 1000000 -t 37500,10000 -J 127.0.0.1:7000", 115ul); osi_WrStrLn("tetradec -J 0.0.0.0:7000 -w pipe.wav -v", 40ul); osi_WrStrLn("aplay pipe.wav", 15ul); X2C_ABORT(); } if (lasth=='v') verb = 1; else if (lasth=='u') { osi_NextArg(h, 4096ul); if (!aprsstr_StrToCard(h, 4096ul, &val)) { Err("-u ", 22ul); } context.xor = (uint32_t)val; isuplink = 1; } else if (lasth=='J') { osi_NextArg(h, 4096ul); if (GetIp(h, 4096ul, &jipnum, &judpport)<0L) { Err("-J ip:port number", 18ul); } if (udpsock<0L) udpsock = openudp(); if (udpsock<0L) Err("-J cannot open udp socket", 26ul); if (bindudp(udpsock, judpport)<0L) { Err("-J cannot bind input udp port", 30ul); } } else if (lasth=='c') { osi_NextArg(h, 4096ul); if (!aprsstr_StrToCard(h, 4096ul, &channels) || (channels!=1UL && channels!=2UL) && channels!=4UL) Err("-c 1,2,4", 25ul); } else if (lasth=='w') { osi_NextArg(h, 4096ul); soundfd = createnonblockfile(h, 4096ul); soundfd = osi_OpenWrite(h, 4096ul); if (soundfd>=0L) wwav(soundfd, 8000UL, channels); else { Err("-w cannot open sound output", 44ul); } } else if (lasth=='C') osi_NextArg(codeccmd, 1024ul); else err = 1; } else err = 1; if (err) break; } if (err) { osi_WrStr(">", 2ul); osi_WrStr(h, 4096ul); osi_WrStrLn("< use -h", 9ul); X2C_ABORT(); } } /* end parms() */ static int32_t inlen; static int32_t rdp; static char inb[4096]; static char getch(void) { char ch; uint32_t fromport; uint32_t ip; if (rdp>=inlen) { inlen = udpreceive(udpsock, inb, 4096L, &fromport, &ip); if ((inlen<=0L || inlen>4096L) || jipnum && jipnum!=ip) { inlen = 0L; usleep(10000UL); return 0; } rdp = 0L; } ch = inb[rdp]; ++rdp; return ch; } /* end getch() */ static char getstr(char s[], uint32_t s_len, char * ch) { uint32_t i0; do { *ch = getch(); if ((uint8_t)*ch<' ') return 0; } while (*ch!='\"'); i0 = 0UL; for (;;) { *ch = getch(); if ((uint8_t)*ch<' ') return 0; if (*ch=='\"') { if (i0='0' && (uint8_t)*ch<='9') { if (f==0.0f) { *v = *v*10.0f+(float)((uint32_t)(uint8_t)*ch-48UL); } else { *v = *v+f*(float)((uint32_t)(uint8_t)*ch-48UL); f = f*0.1f; } } else break; *ch = getch(); } if (neg) *v = -*v; return 1; } /* end getfix() */ static char getint(int32_t * v, char * ch) { char neg; *v = 0L; *ch = getch(); if ((uint8_t)*ch<' ') return 0; while (*ch==' ') *ch = getch(); neg = 0; if (*ch=='-') { neg = 1; *ch = getch(); } for (;;) { if ((uint8_t)*ch>='0' && (uint8_t)*ch<='9') { *v = *v*10L+(int32_t)((uint32_t)(uint8_t)*ch-48UL); } else break; *ch = getch(); } if (neg) *v = -*v; return 1; } /* end getint() */ static uint32_t d640(char c) { if (c=='=') return 64UL; if (c=='+') return 62UL; if (c=='/') return 63UL; if ((uint8_t)c>='0' && (uint8_t)c<='9') { return ((uint32_t)(uint8_t)c+52UL)-48UL; } if ((uint8_t)c>='A' && (uint8_t)c<='Z') { return (uint32_t)(uint8_t)c-65UL; } if ((uint8_t)c>='a' && (uint8_t)c<='z') { return ((uint32_t)(uint8_t)c+26UL)-97UL; } return 255UL; } /* end d64() */ static int32_t d64(const char d[], uint32_t d_len, char b[], uint32_t b_len) { uint32_t w; uint32_t c; uint32_t wh; uint32_t p; uint32_t wp; uint32_t a; a = 0UL; wp = 0UL; p = 0UL; while (p<=d_len-1 && (uint8_t)d[p]>0) { c = d640(d[p]); if (c==255UL) return -1L; if (c<64UL) { w = w*64UL+c; ++a; } if (c==64UL || a>=4UL) { if (a==2UL) w = w/16UL; else if (a==3UL) w = w/4UL; if (a>=2UL) { --a; wp += a; if (wp-1UL>b_len-1) return -2L; wh = wp-1UL; do { b[wh] = (char)(uint8_t)(char)(w&255UL); w = w/256UL; --wh; --a; } while (a); } } ++p; } return (int32_t)wp; } /* end d64() */ static char getframe(float * mhz0, float * db0, int32_t * offset0, signed char dat0[], uint32_t dat_len, uint32_t * len) /* this is better than nothing json reader... */ { char ch; char key[100]; char h[1001]; int32_t ret; do { } while (getch()!='{'); for (;;) { if (!getstr(key, 100ul, &ch) || ch!=':') break; if (aprsstr_StrCmp(key, 100ul, "rxmhz", 6ul)) { if (!getfix(mhz0, &ch)) break; } else if (aprsstr_StrCmp(key, 100ul, "rfdb", 5ul)) { if (!getfix(db0, &ch)) break; } else if (aprsstr_StrCmp(key, 100ul, "offset", 7ul)) { if (!getint(offset0, &ch)) break; } else if (aprsstr_StrCmp(key, 100ul, "payload", 8ul)) { if (!getstr(h, 1001ul, &ch)) break; } else if (!skip(&ch)) break; if ((uint8_t)ch<' ') break; if (ch=='}') { ret = d64(h, 1001ul, (char *)dat0, (dat_len)/1u); *len = (uint32_t)ret; return ret>0L; } } return 0; } /* end getframe() */ static uint32_t tetradec_TRAINn = 0xB970BUL; static uint32_t tetradec_TRAINp = 0x1EC25EUL; static uint32_t tetradec_TRAINy = 0x83973983UL; static uint32_t tetradec_TRAINy1 = 0x39UL; static uint32_t tetradec_TRAINx = 0x30B970B9UL; #define tetradec_NOTFOUND 100 static uint32_t frametyp(const signed char f[], uint32_t f_len, uint32_t len) { uint32_t j; uint32_t m; uint32_t i0; uint32_t e[4]; e[0U] = 0UL; e[1U] = 0UL; e[2U] = 0UL; e[3U] = 0UL; if (len==510UL) { for (i0 = 0UL; i0<=21UL; i0++) { if (X2C_IN(i0,32,0xB970BUL)!=(int32_t)f[i0+244UL]<0L) ++e[0U]; if (X2C_IN(i0,32,0x1EC25EUL)!=(int32_t)f[i0+244UL]<0L) ++e[1U]; } /* end for */ for (i0 = 0UL; i0<=31UL; i0++) { if (X2C_IN(i0,32,0x83973983UL)!=(int32_t)f[i0+214UL]<0L) ++e[2U]; } /* end for */ for (i0 = 0UL; i0<=5UL; i0++) { if (X2C_IN(i0,32,0x39UL)!=(int32_t)f[i0+246UL]<0L) ++e[2U]; } /* end for */ } else { e[0U] = 100UL; e[1U] = 100UL; e[2U] = 100UL; } if (len==206UL) { for (i0 = 0UL; i0<=29UL; i0++) { if (X2C_IN(i0,32,0x30B970B9UL)!=(int32_t)f[i0+88UL]<0L) ++e[3U]; } /* end for */ } else e[3U] = 100UL; m = 100UL; j = 0UL; for (i0 = 0UL; i0<=3UL; i0++) { if (e[i0]0UL) { n += n+(uint32_t)b[from]; ++from; --len; } return n; } /* end bton() */ static uint32_t btoni(const char b[], uint32_t b_len, uint32_t * from, uint32_t len) { uint32_t r; r = bton(b, b_len, *from, len); *from += len; return r; } /* end btoni() */ static void showSBBLK1(const char b[], uint32_t b_len, uint32_t len, struct CONTEXT * cont) { if (verb) { osi_WrStr("CC=", 4ul); osic_WrUINT32(bton(b, b_len, 4UL, 6UL), 1UL); } cont->tn = bton(b, b_len, 10UL, 2UL); if (verb) { osi_WrStr(" TN=", 5ul); osic_WrUINT32(cont->tn, 1UL); } cont->fn = bton(b, b_len, 12UL, 5UL); if (verb) { osi_WrStr(" FN=", 5ul); osic_WrUINT32(cont->fn, 2UL); } cont->mn = bton(b, b_len, 17UL, 6UL); if (verb) { osi_WrStr(" MN=", 5ul); osic_WrUINT32(cont->mn, 1UL); osi_WrStr(" MCC=", 6ul); osic_WrUINT32(bton(b, b_len, 31UL, 10UL), 1UL); osi_WrStr(" MNC=", 6ul); osic_WrUINT32(bton(b, b_len, 41UL, 14UL), 1UL); osi_WrStr(" sc=", 5ul); osic_WrUINT32((uint32_t)cont->xor, 1UL); osi_WrStr(" ", 2ul); } } /* end showSBBLK1() */ static uint8_t tetradec_LEN[8] = {0U,24U,10U,24U,34U,34U,30U,34U}; static uint8_t _cnst5[8] = {0U,24U,10U,24U,34U,34U,30U,34U}; static void showSCHf(const char b[], uint32_t b_len, uint32_t len) { uint32_t ssi; uint32_t styp; uint32_t n; uint32_t type; uint32_t p; if (verb) { p = 0UL; type = btoni(b, b_len, &p, 2UL); osi_WrStr(" MACres=", 9ul); osic_WrUINT32(type, 1UL); if (type==0UL) { n = btoni(b, b_len, &p, 5UL); n = btoni(b, b_len, &p, 6UL); styp = btoni(b, b_len, &p, 3UL); osi_WrStr(" styp=", 7ul); osic_WrUINT32(styp, 1UL); ssi = btoni(b, b_len, &p, (uint32_t)_cnst5[styp]); osi_WrStr(" ssi=", 6ul); osic_WrUINT32(ssi, 1UL); } osi_WrStr(" ", 2ul); } } /* end showSCHf() */ static float tetradec_OFFS[4] = {0.0f,(-6.25f),6.25f,12.5f}; static int32_t tetradec_DUPLEX[128] = {-1L,1600L,10000L,10000L,10000L, 10000L,10000L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,4500L, -1L,36000L,7000L,-1L,-1L,-1L,45000L,45000L,-1L,-1L,-1L,-1L, -1L,-1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,-1L, -1L,-1L,8000L,8000L,-1L,-1L,-1L,18000L,18000L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,18000L,5000L,-1L,30000L,30000L,-1L, 39000L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,9500L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L}; static float _cnst7[4] = {0.0f,(-6.25f),6.25f,12.5f}; static int32_t _cnst6[128] = {-1L,1600L,10000L,10000L,10000L,10000L,10000L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,4500L,-1L,36000L, 7000L,-1L,-1L,-1L,45000L,45000L,-1L,-1L,-1L,-1L,-1L,-1L,0L, 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,-1L,-1L,-1L, 8000L,8000L,-1L,-1L,-1L,18000L,18000L,-1L,-1L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,18000L,5000L,-1L,30000L,30000L,-1L,39000L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,9500L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L, -1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L,-1L}; static void showSBBLK2(const char b[], uint32_t b_len, uint32_t len) { uint32_t subscrclass; uint32_t la; uint32_t hyperframenr; uint32_t cckid; uint32_t norf; uint32_t rtimeout; uint32_t accparm; uint32_t rxlev; uint32_t mspwr; uint32_t ncsh; uint32_t revers; uint32_t duplexspacing; uint32_t offs; uint32_t ch; uint32_t band; uint32_t i0; uint32_t bsservicedetails; int32_t shift; /*WrStr("B["); FOR i:=0 TO len-1 DO WrInt(ORD(b[i]),1) END; WrStrLn("]"); */ if (bton(b, b_len, 0UL, 4UL)==8UL) { /* SYSINFO */ i0 = 4UL; ch = btoni(b, b_len, &i0, 12UL); band = btoni(b, b_len, &i0, 4UL); offs = btoni(b, b_len, &i0, 2UL); duplexspacing = btoni(b, b_len, &i0, 3UL); revers = btoni(b, b_len, &i0, 1UL); ncsh = btoni(b, b_len, &i0, 2UL); mspwr = btoni(b, b_len, &i0, 3UL); rxlev = btoni(b, b_len, &i0, 4UL); accparm = btoni(b, b_len, &i0, 4UL); rtimeout = btoni(b, b_len, &i0, 4UL); norf = btoni(b, b_len, &i0, 1UL); if (norf>0UL) cckid = btoni(b, b_len, &i0, 16UL); else hyperframenr = btoni(b, b_len, &i0, 16UL); i0 = 82UL; la = btoni(b, b_len, &i0, 14UL); subscrclass = btoni(b, b_len, &i0, 16UL); bsservicedetails = (uint32_t)btoni(b, b_len, &i0, 12UL); shift = _cnst6[band+duplexspacing*16UL]; if (verb) { osi_WrStr("TX=", 4ul); osic_WrFixed(((float)(band*100000UL+ch*25UL)+_cnst7[offs]) *0.001f, 4L, 1UL); if (shift>=0L) { if (revers>0UL) shift = -shift; osi_WrStr(" RX=", 5ul); osic_WrFixed((((float)(band*100000UL+ch*25UL)+_cnst7[offs]) -(float)shift)*0.001f, 4L, 1UL); } osi_WrStr(" Po=", 5ul); osic_WrUINT32(mspwr*5UL+10UL, 1UL); osi_WrStr("dBm", 4ul); osi_WrStr(" LA=", 5ul); osic_WrUINT32(la, 1UL); if ((0x20UL & bsservicedetails)) osi_WrStr(" Voice-Sv", 10ul); if ((0x2UL & bsservicedetails)) osi_WrStr(" Air-encr", 10ul); } } } /* end showSBBLK2() */ static void SCHf(const char b[], uint32_t b_len, const signed char type4[], uint32_t type4_len, uint32_t len, uint32_t slot) { uint32_t i0; short block[690]; char tmpstr[1393]; /*WrStr("S["); FOR i:=0 TO len-1 DO WrInt(ORD(b[i]),1) END; WrStrLn("]"); */ /* Generate a block */ memset((char *)block,(char)0,1380UL); /* FOR i:=0 TO 5 DO block[115*i]:= 06B21H + i END; FOR i:=0 TO 113 DO block[1+i]:= 127-254*ORD(type4[i]<0) END; FOR i:=0 TO 113 DO block[116+i]:= 127-254*ORD(type4[114+i]<0) END; FOR i:=0 TO 113 DO block[231+i]:= 127-254*ORD(type4[228+i]<0) END; FOR i:=0 TO 89 DO block[346+i]:= 127-254*ORD(type4[342+i]<0) END; */ for (i0 = 0UL; i0<=5UL; i0++) { block[115UL*i0] = (short)(27425UL+i0); } /* end for */ for (i0 = 0UL; i0<=113UL; i0++) { block[1UL+i0] = (short)type4[i0]; } /* end for */ for (i0 = 0UL; i0<=113UL; i0++) { block[116UL+i0] = (short)type4[114UL+i0]; } /* end for */ for (i0 = 0UL; i0<=113UL; i0++) { block[231UL+i0] = (short)type4[228UL+i0]; } /* end for */ for (i0 = 0UL; i0<=89UL; i0++) { block[346UL+i0] = (short)type4[342UL+i0]; } /* end for */ /* tmpstr:="TRA:01 RX:01"; */ /* MOVE(ADR(block), ADR(tmpstr[13]), SIZE(block)); */ X2C_MOVE((char *)block,(char *)tmpstr,1380UL); /*WrStr("V["); FOR i:=0 TO len-1 DO WrHex(ORD(tmpstr[i]),1) END; WrStrLn("]"); */ if (slot>3UL) slot = 3UL; if (child[slot].fd>=0L) { osi_WrBin(child[slot].fd, (char *)tmpstr, 1393u/1u, 1380UL); } } /* end SCHf() */ static uint8_t tetradec_B[256] = {0U,1U,1U,2U,1U,2U,2U,3U,1U,2U,2U,3U,2U, 3U,3U,4U,1U,2U,2U,3U,2U,3U,3U,4U,2U,3U,3U,4U,3U,4U,4U,5U,1U, 2U,2U,3U,2U,3U,3U,4U,2U,3U,3U,4U,3U,4U,4U,5U,2U,3U,3U,4U,3U, 4U,4U,5U,3U,4U,4U,5U,4U,5U,5U,6U,1U,2U,2U,3U,2U,3U,3U,4U,2U, 3U,3U,4U,3U,4U,4U,5U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U, 5U,5U,6U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U,5U,5U,6U,3U, 4U,4U,5U,4U,5U,5U,6U,4U,5U,5U,6U,5U,6U,6U,7U,1U,2U,2U,3U,2U, 3U,3U,4U,2U,3U,3U,4U,3U,4U,4U,5U,2U,3U,3U,4U,3U,4U,4U,5U,3U, 4U,4U,5U,4U,5U,5U,6U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U, 5U,5U,6U,3U,4U,4U,5U,4U,5U,5U,6U,4U,5U,5U,6U,5U,6U,6U,7U,2U, 3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U,5U,5U,6U,3U,4U,4U,5U,4U, 5U,5U,6U,4U,5U,5U,6U,5U,6U,6U,7U,3U,4U,4U,5U,4U,5U,5U,6U,4U, 5U,5U,6U,5U,6U,6U,7U,4U,5U,5U,6U,5U,6U,6U,7U,5U,6U,6U,7U,6U, 7U,7U,8U}; /* number of ones in a byte */ static uint32_t tetradec_M8 = 0xFFUL; static uint8_t _cnst8[256] = {0U,1U,1U,2U,1U,2U,2U,3U,1U,2U,2U,3U,2U,3U,3U, 4U,1U,2U,2U,3U,2U,3U,3U,4U,2U,3U,3U,4U,3U,4U,4U,5U,1U,2U,2U, 3U,2U,3U,3U,4U,2U,3U,3U,4U,3U,4U,4U,5U,2U,3U,3U,4U,3U,4U,4U, 5U,3U,4U,4U,5U,4U,5U,5U,6U,1U,2U,2U,3U,2U,3U,3U,4U,2U,3U,3U, 4U,3U,4U,4U,5U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U,5U,5U, 6U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U,5U,5U,6U,3U,4U,4U, 5U,4U,5U,5U,6U,4U,5U,5U,6U,5U,6U,6U,7U,1U,2U,2U,3U,2U,3U,3U, 4U,2U,3U,3U,4U,3U,4U,4U,5U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U, 5U,4U,5U,5U,6U,2U,3U,3U,4U,3U,4U,4U,5U,3U,4U,4U,5U,4U,5U,5U, 6U,3U,4U,4U,5U,4U,5U,5U,6U,4U,5U,5U,6U,5U,6U,6U,7U,2U,3U,3U, 4U,3U,4U,4U,5U,3U,4U,4U,5U,4U,5U,5U,6U,3U,4U,4U,5U,4U,5U,5U, 6U,4U,5U,5U,6U,5U,6U,6U,7U,3U,4U,4U,5U,4U,5U,5U,6U,4U,5U,5U, 6U,5U,6U,6U,7U,4U,5U,5U,6U,5U,6U,6U,7U,5U,6U,6U,7U,6U,7U,7U, 8U}; static uint32_t decodeRM(const signed char inb0[], uint32_t inb_len, char outb[], uint32_t outb_len) { uint32_t errs; uint32_t best; uint32_t min0; uint32_t i0; uint32_t out; uint32_t in; in = 0UL; i0 = 0UL; do { if ((int32_t)inb0[i0]<=0L) in |= (1UL<0UL) { osi_WrStr(" RM-corr-bit=", 14ul); osic_WrUINT32(min0, 1UL); osi_WrStr(" ", 2ul); } /*WrStr("D["); FOR i:=0 TO 13 DO WrCard(ORD(outb[i]),1) END; WrStrLn("]"); */ return (uint32_t)(min0>3UL); } /* end decodeRM() */ static uint32_t getscramb(uint32_t mcc, uint32_t mnc, uint32_t colour) /*p.723*/ { return 0x3UL|X2C_LSH((uint32_t)colour&0x3FUL|X2C_LSH((uint32_t) mnc&0x3FFFUL,32,6)|X2C_LSH((uint32_t)mcc&0x3FFUL,32,20),32, 2); } /* end getscramb() */ static void showBB(const char b[], uint32_t b_len, struct CONTEXT * cont) /* p. 634 */ { uint32_t f2; uint32_t f1; uint32_t head; head = bton(b, b_len, 0UL, 2UL); f1 = bton(b, b_len, 2UL, 6UL); f2 = bton(b, b_len, 8UL, 6UL); cont->istrafic = 0; /*WrInt(cont.fn,1);WrStr("B["); FOR i:=0 TO 13 DO WrCard(ORD(b[i]),1) END; WrStrLn("]"); */ /* IF cont.fn=18 THEN */ /* ELSE */ if ((head&1)) { /* downlink usage */ /*WrStr("DL-Usage=");WrCard(f1, 1); WrStr(" "); */ cont->istrafic = f1>=4UL; } /* cont.istrafic:=TRUE; */ /* END; */ } /* end showBB() */ static void decode(signed char fr0[], uint32_t fr_len, uint32_t start, uint32_t len, struct CONTEXT * cont, uint32_t ftyp) { uint32_t deint; uint32_t crclen; uint32_t vitlen; uint32_t i0; signed char bd[510]; signed char b[510]; signed char bdp[2001]; char bdv[2001]; uint32_t crcok; uint32_t tmp; X2C_PCOPY((void **)&fr0,fr_len); tmp = len-1UL; i0 = 0UL; if (i0<=tmp) for (;; i0++) { b[i0] = fr0[i0+start]; if (i0==tmp) break; } /* end for */ /*WrStr("U["); FOR i:=start TO start+len-1 DO WrInt(ORD(fr[i]<0),1); END; WrStrLn("]"); */ if (len==120UL) { vitlen = 80UL; crclen = 60UL; deint = 11UL; } else if (len==216UL) { vitlen = 144UL; crclen = 124UL; deint = 101UL; } else if (len==30UL) { vitlen = 0UL; crclen = 0UL; } else if (len==432UL) { vitlen = 288UL; crclen = 268UL; deint = 103UL; } /*WrStr(" len=");WrCard(len,1); */ /*WrStr(" xor="); WrCard(CAST(CARDINAL, xor),1); WrStrLn(""); */ descramble(b, 510ul, cont->xor, len); if (len==30UL) { /* reed muller */ crcok = decodeRM(b, 510ul, bdv, 2001ul); showBB(bdv, 2001ul, cont); } else { deinterleave(len, deint, b, 510ul, bd, 510ul); depuncture(tetradec_PUNCT23, bd, 510ul, len, bdp, 2001ul); /*WrStr("d["); FOR i:=0 TO len DO WrInt(bd[i],1); WrStr(" "); END; WrStrLn("]"); */ viterbidec(bdp, 2001ul, vitlen, (char *)bdv, 2001u/1u); /*WrInt(vitlen,1);WrStr(" v["); FOR i:=0 TO vitlen-1 DO WrInt(ORD(bdv[i]),1); END; WrStrLn("]"); */ crcok = crc16(bdv, 2001ul, crclen+16UL); if (verb) { osi_WrStr("crc=", 5ul); osic_WrUINT32(crcok, 1UL); osi_WrStr(" ", 2ul); } if (crcok==0UL) { if (len==120UL) { cont->xor = getscramb(bton(bdv, 2001ul, 31UL, 10UL), bton(bdv, 2001ul, 41UL, 14UL), bton(bdv, 2001ul, 4UL, 6UL)); showSBBLK1(bdv, 2001ul, crclen, &context); } else if (len==216UL) { showSBBLK2(bdv, 2001ul, crclen); if (ftyp==2UL) showSCHf(bdv, 2001ul, crclen); } else if (len==432UL) showSCHf(bdv, 2001ul, crclen); } /* ELSIF len=NDBBLKBITS THEN showNDB(bdv, crclen); */ if (len==432UL && (isuplink || cont->istrafic)) { SCHf(bdv, 2001ul, b, 510ul, crclen, cont->tn); if (verb) { osi_WrStr(" Data[", 7ul); osic_WrUINT32(context.fn, 1UL); osi_WrStr("/", 2ul); osic_WrUINT32(context.tn, 1UL); osi_WrStr("]", 2ul); } } } X2C_PFREE(fr0); } /* end decode() */ #define tetradec_MAXG 10.0 static short lim(short u, float * mul, float lim0) { float ll; float r; r = (float)u*(10.0f-*mul); ll = (float)fabs(r)-lim0; if (ll>0.0f) *mul = *mul+(10.0f-*mul)*ll*0.00001f; else *mul = *mul*0.9999f; if (r>32767.0f) return 32767; else if (r<(-3.2767E+4f)) return -32767; else return (short)X2C_TRUNCI(r,-32768,32767); return 0; } /* end lim() */ static char soundout(void) { uint32_t p; uint32_t sp; uint32_t max0; uint32_t ch; int32_t le; short sb[65536]; char * pa; char done; uint32_t tmp; done = 0; max0 = 0UL; ch = 0UL; ++nosoundcnt; for (ch = 0UL; ch<=3UL; ch++) { pa = (char *) &child[ch].buf.b[child[ch].len]; le = (int32_t)(32768UL-child[ch].len); if (le>1024L) le = 1024L; le = osi_RdBin(child[ch].fd, pa, 65536ul, (uint32_t)le); if (le>0L) { child[ch].len += (uint32_t)le; nosoundcnt = 0UL; } /*IF le>0 THEN WrStr(" +++("); WrInt(ch,1); WrStr(","); WrInt(le,1); WrStr(") ") END;; */ if (child[ch].len>max0) max0 = child[ch].len; } /* end for */ /*WrStr("***[");WrInt(nosoundcnt,1);WrStr("] "); */ /* IF max>=INB*2 THEN */ /* IF (max>=INB*2) OR (max>0) & NOT ODD(max) THEN */ if (max0>=32768UL || max0>0UL && nosoundcnt>=3UL) { /*WrStr(" ::: "); */ sp = 0UL; memset((char *)sb,(char)0,131072UL); /* IF nosoundcnt>50 THEN WrStr("("); WrInt(nosoundcnt,1); WrStr(")"); WrBin(soundfd, sb, 2048); nosoundcnt:=0 END; */ if (channels==1UL) { tmp = max0/2UL-1UL; p = 0UL; if (p<=tmp) for (;; p++) { for (ch = 0UL; ch<=3UL; ch++) { sb[sp] += lim(child[ch].buf.w[p], &child[ch].alc, 8000.0f); } /* end for */ ++sp; if (p==tmp) break; } /* end for */ } else if (channels==2UL) { tmp = max0/2UL-1UL; p = 0UL; if (p<=tmp) for (;; p++) { sb[sp] += lim(child[0U].buf.w[p], &child[1U].alc, 16000.0f); sb[sp] += lim(child[1U].buf.w[p], &child[0U].alc, 10600.0f); sb[sp] += lim(child[2U].buf.w[p], &child[2U].alc, 5300.0f); ++sp; sb[sp] += lim(child[1U].buf.w[p], &child[0U].alc, 5300.0f); sb[sp] += lim(child[2U].buf.w[p], &child[2U].alc, 10600.0f); sb[sp] += lim(child[3U].buf.w[p], &child[3U].alc, 16000.0f); ++sp; if (p==tmp) break; } /* end for */ } else { tmp = max0/2UL-1UL; p = 0UL; if (p<=tmp) for (;; p++) { for (ch = 0UL; ch<=3UL; ch++) { sb[sp] = lim(child[ch].buf.w[p], &child[ch].alc, 32000.0f); ++sp; } /* end for */ if (p==tmp) break; } /* end for */ } osi_WrBin(soundfd, (char *)sb, 131072u/1u, sp*2UL); osic_flush(); for (ch = 0UL; ch<=3UL; ch++) { child[ch].len = 0UL; memset((char *)child[ch].buf.b,(char)0,32768UL); } /* end for */ done = 1; } return done; } /* end soundout() */ static char dat[510]; static signed char fr[510]; static signed char fb[510]; static int32_t offset; static float mhz; static float db; static uint32_t i; static uint32_t frlen; static uint32_t typ; static struct PROCESSHANDLE codecp[4]; X2C_STACK_LIMIT(8000000l) extern int main(int argc, char **argv) { char tmp; X2C_BEGIN(&argc,argv,1,20000000l,32000000l); aprsstr_BEGIN(); aprspos_BEGIN(); osi_BEGIN(); parms(); RMinit(); i = 0UL; while (i<4UL) { dat[0] = 0; aprsstr_Append(dat, 510ul, codeccmd, 1024ul); aprsstr_Append(dat, 510ul, " ", 2ul); aprsstr_Append(dat, 510ul, (char *)(tmp = (char)(i+48UL),&tmp), 1u/1u); StartProg(dat, 510ul, &codecp[i], &child[i].fd); ++i; } inlen = 0L; rdp = 0L; for (;;) { if (getframe(&mhz, &db, &offset, fr, 510ul, &frlen) && frlen>0UL) { if (verb) { if (mhz!=0.0f) { osic_WrFixed(mhz, 5L, 1UL); osi_WrStr("MHz ", 5ul); } osic_WrFixed(db, 1L, 1UL); osi_WrStr("dB ", 4ul); osic_WrINT32((uint32_t)offset, 1UL); osi_WrStr("Hz ", 4ul); } typ = frametyp(fr, 510ul, frlen); if (verb) { osi_WrStr("FT=", 4ul); osic_WrUINT32(typ, 1UL); osi_WrStr(" ", 2ul); } /*WrStr("r["); FOR i:=0 TO frlen-1 DO WrInt(fr[i],1); WrStr(" "); END; WrStrLn("]"); */ /*WrStr("r["); FOR i:=0 TO frlen-1 DO WrInt(ORD(fr[i]<0),1) END; WrStrLn("]"); */ if (typ==3UL) { context.xor = 0x3UL; decode(fr, 510ul, 94UL, 120UL, &context, 3UL); decode(fr, 510ul, 252UL, 30UL, &context, 3UL); decode(fr, 510ul, 282UL, 216UL, &context, 3UL); if (verb) osi_WrStrLn("", 1ul); } else if (typ==2UL) { if (isuplink) { decode(fr, 510ul, 28UL, 216UL, &context, 2UL); decode(fr, 510ul, 266UL, 216UL, &context, 2UL); } else { /* re-combine the broadcast block */ for (i = 0UL; i<=13UL; i++) { fb[i] = fr[i+230UL]; } /* end for */ for (i = 0UL; i<=15UL; i++) { fb[i+14UL] = fr[i+266UL]; } /* end for */ decode(fb, 510ul, 0UL, 30UL, &context, 2UL); decode(fr, 510ul, 14UL, 216UL, &context, 2UL); decode(fr, 510ul, 282UL, 216UL, &context, 2UL); } if (verb) osi_WrStrLn("", 1ul); } else if (typ==1UL) { /* SCH/F */ if (!isuplink) ++context.tn; if (context.tn>3UL) { context.tn = 0UL; context.fn = context.fn%18UL+1UL; } if (isuplink) { /*WrStr("u["); FOR i:=0 TO frlen-1 DO WrInt(ORD(fr[i]<0),1); END; WrStrLn("]"); */ for (i = 0UL; i<=215UL; i++) { fb[i] = fr[i+28UL]; } /* end for */ for (i = 0UL; i<=215UL; i++) { fb[i+216UL] = fr[i+266UL]; } /* end for */ decode(fb, 510ul, 0UL, 432UL, &context, 1UL); } else { /* re-combine the broadcast block */ for (i = 0UL; i<=13UL; i++) { fb[i] = fr[i+230UL]; } /* end for */ for (i = 0UL; i<=15UL; i++) { fb[i+14UL] = fr[i+266UL]; } /* end for */ decode(fb, 510ul, 0UL, 30UL, &context, 1UL); for (i = 0UL; i<=215UL; i++) { fb[i] = fr[i+14UL]; } /* end for */ for (i = 0UL; i<=215UL; i++) { fb[i+216UL] = fr[i+282UL]; } /* end for */ decode(fb, 510ul, 0UL, 432UL, &context, 1UL); } if (verb) osi_WrStrLn("", 1ul); } else if (verb) osi_WrStrLn("", 1ul); } if (context.tn==3UL) { do { } while (soundout()); } } X2C_EXIT(); return 0; } X2C_MAIN_DEFINITION