Added Paparazzi support

This commit is contained in:
Martin Mueller
2005-05-25 21:58:10 +00:00
parent e003f52d72
commit 8b09e74ee9
7 changed files with 705 additions and 8 deletions
+6 -6
View File
@@ -11,11 +11,11 @@ endif
LDFLAGSX =-lX11 -L/usr/X11R6/lib -R/usr/X11R6/lib -lsocket -lnsl
else
ifeq ($(DEBUG),y)
CFLAGS +=-g -O -m486 -malign-loops=2 -malign-jumps=2 \
-malign-functions=2 -DARCH_I386
CFLAGS +=-g -O -march=i486 -falign-loops=2 -falign-jumps=2 \
-falign-functions=2 -DARCH_I386
else
CFLAGS +=-O3 -m486 -malign-loops=2 -malign-jumps=2 \
-malign-functions=2 -DARCH_I386
CFLAGS +=-O3 -march=i486 -falign-loops=2 -falign-jumps=2 \
-falign-functions=2 -DARCH_I386
endif
LDFLAGSX =-lX11 -L/usr/X11R6/lib
endif
@@ -48,8 +48,8 @@ $(BINDIR)/%.o: $(BINDIR)/%.s
$(BINDIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
SRC_L2 =hdlc.c pocsag.c
SRC_L1 =demod_afsk12.c demod_afsk24.c demod_afsk24_2.c
SRC_L2 =hdlc.c pocsag.c pprz.c
SRC_L1 =demod_afsk12.c demod_afsk24.c demod_afsk24_2.c demod_afsk48p.c demod_afsk48.c
SRC_L1 +=demod_hapn48.c demod_fsk96.c
SRC_L1 +=demod_poc5.c demod_poc12.c demod_poc24.c
SRC_L1 +=demod_dtmf.c demod_zvei.c demod_display.c
+34
View File
@@ -0,0 +1,34 @@
Linux Radio Transmission Decoder
by Thomas Sailer, HB9JNX/AE4WA
Paparazzi adaptions added by Martin Mueller, DL3FCC
Description
The multimon software can decode a variety of digital transmission modes commonly found on UHF radio. A standard PC soundcard is used to acquire the signal from a transceiver. The decoding is done completely in software. Currently, the following modes are supported:
* AX.25
o 1200 Baud AFSK
o 2400 Baud AFSK (2 variants)
o 4800 Baud HAPN
o 9600 Baud FSK (G3RUH)
* POCSAG
o 512 Baud
o 1200 Baud
o 2400 Baud
* Miscellaneous
o DTMF
o ZVEI
o 4800 Baud AFSK PPRZ (baudot and hdlc)
An arbitrary set of the above modes may run concurrently on the same input signal (provided the CPU power is sufficient), so you do not have to know in advance which mode is used. Note however that some modes might require modifications to the radio (especially the 9600 baud FSK and the POCSAG modes) to work properly.
POCSAG (Post Office Code Standards Advisory Group) is a common paging transmission format.
Download
PPRZ is a proprietary 4800 Baud baudot-like protocol. This is used by the Paparazzi project which is located at http://www.nongnu.org/paparazzi
Please note that monitoring commercial services may be prohibited in some countries, this software should therefore only be used to monitor the amateur radio service.
The software is published under the GNU GPL V2
The original software can be found at http://www.baycom.org/~tom/ham/linux/multimon.html
+133
View File
@@ -0,0 +1,133 @@
/*
* demod_afsk48.c -- 4800 baud AFSK demodulator
*
* Copyright (C) 1996
* Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
*
* 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ---------------------------------------------------------------------- */
#include "multimon.h"
#include "filter.h"
#include <math.h>
#include <string.h>
/* ---------------------------------------------------------------------- */
/*
* Standard CMX469A clock frequency: 4.032 Mhz
* Xtal used: 4 MHz
* Ratio: 0.992063
* Mark frequency: 4761.905 Hz
* Space frequency: 2380.952 Hz
*/
#define FREQ_MARK 4762
#define FREQ_SPACE 2381
#define FREQ_SAMP 22050
//#define FREQ_SAMP 44100
#define BAUD 4762
/* ---------------------------------------------------------------------- */
#define CORRLEN (2*(int)(FREQ_SAMP/BAUD))
#define SPHASEINC (0x10000u*BAUD/FREQ_SAMP)
static float corr_mark_i[CORRLEN];
static float corr_mark_q[CORRLEN];
static float corr_space_i[CORRLEN];
static float corr_space_q[CORRLEN];
/* ---------------------------------------------------------------------- */
static void afsk48_init(struct demod_state *s)
{
float f;
int i;
pprz_init(s);
memset(&s->l1.afsk48, 0, sizeof(s->l1.afsk48));
for (f = 0, i = 0; i < CORRLEN; i++) {
corr_mark_i[i] = cos(f);
corr_mark_q[i] = sin(f);
f += 2.0*M_PI*FREQ_MARK/FREQ_SAMP;
}
for (f = 0, i = 0; i < CORRLEN; i++) {
corr_space_i[i] = cos(f);
corr_space_q[i] = sin(f);
f += 2.0*M_PI*FREQ_SPACE/FREQ_SAMP;
}
for (i = 0; i < CORRLEN; i++) {
f = 0.54 - 0.46*cos(2*M_PI*i/(float)(CORRLEN-1));
corr_mark_i[i] *= f;
corr_mark_q[i] *= f;
corr_space_i[i] *= f;
corr_space_q[i] *= f;
}
}
/* ---------------------------------------------------------------------- */
static void afsk48_demod(struct demod_state *s, float *buffer, int length)
{
float f;
unsigned char curbit;
s->l1.afsk48p.sample_count += length;
if (s->l1.afsk48p.sample_count > FREQ_SAMP) {
s->l1.afsk48p.sample_count -= FREQ_SAMP;
pprz_status(s);
}
for (; length > 0; length--, buffer++) {
f = fsqr(mac(buffer, corr_mark_i, CORRLEN)) +
fsqr(mac(buffer, corr_mark_q, CORRLEN)) -
fsqr(mac(buffer, corr_space_i, CORRLEN)) -
fsqr(mac(buffer, corr_space_q, CORRLEN));
s->l1.afsk48.dcd_shreg <<= 1;
s->l1.afsk48.dcd_shreg |= (f > 0);
verbprintf(10, "%c", '0'+(s->l1.afsk48.dcd_shreg & 1));
/*
* check if transition
*/
if ((s->l1.afsk48.dcd_shreg ^ (s->l1.afsk48.dcd_shreg >> 1)) & 1) {
if (s->l1.afsk48.sphase < (0x8000u-(SPHASEINC/2)))
s->l1.afsk48.sphase += SPHASEINC/8;
else
s->l1.afsk48.sphase -= SPHASEINC/8;
}
s->l1.afsk48.sphase += SPHASEINC;
if (s->l1.afsk48.sphase >= 0x10000u) {
s->l1.afsk48.sphase &= 0xffffu;
s->l1.afsk48.lasts <<= 1;
s->l1.afsk48.lasts |= s->l1.afsk48.dcd_shreg & 1;
curbit = (s->l1.afsk48.lasts ^
(s->l1.afsk48.lasts >> 1) ^ 1) & 1;
verbprintf(9, " %c ", '0'+curbit);
pprz_hdlc_rxbit(s, curbit);
}
}
}
/* ---------------------------------------------------------------------- */
const struct demod_param demod_afsk4800 = {
"AFSK4800", FREQ_SAMP, CORRLEN, afsk48_init, afsk48_demod
};
/* ---------------------------------------------------------------------- */
+134
View File
@@ -0,0 +1,134 @@
/*
* demod_afsk48p.c -- 4800 baud AFSK demodulator for paparazzi
*
* Copyright (C) 1996
* Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
*
* 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ---------------------------------------------------------------------- */
#include "multimon.h"
#include "filter.h"
#include <math.h>
#include <string.h>
/* ---------------------------------------------------------------------- */
/*
* Standard CMX469A clock frequency: 4.032 Mhz
* Xtal used: 4 MHz
* Ratio: 0.992063
* Mark frequency: 4761.905 Hz
* Space frequency: 2380.952 Hz
*/
#define FREQ_MARK 4762
#define FREQ_SPACE 2381
#define FREQ_SAMP 22050
//#define FREQ_SAMP 44100
#define BAUD 4762
/* ---------------------------------------------------------------------- */
#define CORRLEN (2*(int)(FREQ_SAMP/BAUD))
#define SPHASEINC (0x10000u*BAUD/FREQ_SAMP)
static float corr_mark_i[CORRLEN];
static float corr_mark_q[CORRLEN];
static float corr_space_i[CORRLEN];
static float corr_space_q[CORRLEN];
/* ---------------------------------------------------------------------- */
static void afsk48p_init(struct demod_state *s)
{
float f;
int i;
pprz_init(s);
memset(&s->l1.afsk48p, 0, sizeof(s->l1.afsk48p));
for (f = 0, i = 0; i < CORRLEN; i++) {
corr_mark_i[i] = cos(f);
corr_mark_q[i] = sin(f);
f += 2.0*M_PI*FREQ_MARK/FREQ_SAMP;
}
for (f = 0, i = 0; i < CORRLEN; i++) {
corr_space_i[i] = cos(f);
corr_space_q[i] = sin(f);
f += 2.0*M_PI*FREQ_SPACE/FREQ_SAMP;
}
for (i = 0; i < CORRLEN; i++) {
f = 0.54 - 0.46*cos(2*M_PI*i/(float)(CORRLEN-1));
corr_mark_i[i] *= f;
corr_mark_q[i] *= f;
corr_space_i[i] *= f;
corr_space_q[i] *= f;
}
s->l1.afsk48p.sample_count = 0;
}
/* ---------------------------------------------------------------------- */
static void afsk48p_demod(struct demod_state *s, float *buffer, int length)
{
float f;
unsigned char curbit;
s->l1.afsk48p.sample_count += length;
if (s->l1.afsk48p.sample_count > FREQ_SAMP) {
s->l1.afsk48p.sample_count -= FREQ_SAMP;
pprz_status(s);
}
for (; length > 0; length--, buffer++) {
f = fsqr(mac(buffer, corr_mark_i, CORRLEN)) +
fsqr(mac(buffer, corr_mark_q, CORRLEN)) -
fsqr(mac(buffer, corr_space_i, CORRLEN)) -
fsqr(mac(buffer, corr_space_q, CORRLEN));
s->l1.afsk48p.dcd_shreg <<= 1;
s->l1.afsk48p.dcd_shreg |= (f > 0);
verbprintf(10, "%c", '0'+(s->l1.afsk48p.dcd_shreg & 1));
/*
* check if transition
*/
if ((s->l1.afsk48p.dcd_shreg ^ (s->l1.afsk48p.dcd_shreg >> 1)) & 1) {
if (s->l1.afsk48p.sphase < (0x8000u-(SPHASEINC/2)))
s->l1.afsk48p.sphase += SPHASEINC/8;
else
s->l1.afsk48p.sphase -= SPHASEINC/8;
}
s->l1.afsk48p.sphase += SPHASEINC;
if (s->l1.afsk48p.sphase >= 0x10000u) {
s->l1.afsk48p.sphase &= 0xffffu;
s->l1.afsk48p.lasts <<= 1;
s->l1.afsk48p.lasts |= s->l1.afsk48p.dcd_shreg & 1;
/* we use direct coded bits, not NRZI */
curbit = (s->l1.afsk48p.lasts ^ 1) & 1;
verbprintf(9, " %c ", '0'+curbit);
pprz_baudot_rxbit(s, curbit);
}
}
}
/* ---------------------------------------------------------------------- */
const struct demod_param demod_afsk4800p = {
"AFSK4800_P", FREQ_SAMP, CORRLEN, afsk48p_init, afsk48p_demod
};
/* ---------------------------------------------------------------------- */
+181
View File
@@ -50,6 +50,41 @@ extern inline float __mac_c(const float *a, const float *b, unsigned int size)
* inspired from Phil Karn, KA9Q's home page
*/
switch (size) {
case 8:
asm volatile ("flds (%1);\n\t"
"fmuls (%2);\n\t"
"flds 4(%1);\n\t"
"fmuls 4(%2);\n\t"
"flds 8(%1);\n\t"
"fmuls 8(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 12(%1);\n\t"
"fmuls 12(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 16(%1);\n\t"
"fmuls 16(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 20(%1);\n\t"
"fmuls 20(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 24(%1);\n\t"
"fmuls 24(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 28(%1);\n\t"
"fmuls 28(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"faddp;\n\t" :
"=t" (f) :
"r" (a),
"r" (b) : "memory");
return f;
case 9:
asm volatile ("flds (%1);\n\t"
"fmuls (%2);\n\t"
@@ -262,6 +297,152 @@ extern inline float __mac_c(const float *a, const float *b, unsigned int size)
"r" (a),
"r" (b) : "memory");
return f;
case 36:
asm volatile ("flds (%1);\n\t"
"fmuls (%2);\n\t"
"flds 4(%1);\n\t"
"fmuls 4(%2);\n\t"
"flds 8(%1);\n\t"
"fmuls 8(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 12(%1);\n\t"
"fmuls 12(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 16(%1);\n\t"
"fmuls 16(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 20(%1);\n\t"
"fmuls 20(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 24(%1);\n\t"
"fmuls 24(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 28(%1);\n\t"
"fmuls 28(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 32(%1);\n\t"
"fmuls 32(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 36(%1);\n\t"
"fmuls 36(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 40(%1);\n\t"
"fmuls 40(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 44(%1);\n\t"
"fmuls 44(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 48(%1);\n\t"
"fmuls 48(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 52(%1);\n\t"
"fmuls 52(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 56(%1);\n\t"
"fmuls 56(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 60(%1);\n\t"
"fmuls 60(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 64(%1);\n\t"
"fmuls 64(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 68(%1);\n\t"
"fmuls 68(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 72(%1);\n\t"
"fmuls 72(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 76(%1);\n\t"
"fmuls 76(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 80(%1);\n\t"
"fmuls 80(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 84(%1);\n\t"
"fmuls 84(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 88(%1);\n\t"
"fmuls 88(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 92(%1);\n\t"
"fmuls 92(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 96(%1);\n\t"
"fmuls 96(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 100(%1);\n\t"
"fmuls 100(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 104(%1);\n\t"
"fmuls 104(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 108(%1);\n\t"
"fmuls 108(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 112(%1);\n\t"
"fmuls 112(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 116(%1);\n\t"
"fmuls 116(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 120(%1);\n\t"
"fmuls 120(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 124(%1);\n\t"
"fmuls 124(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 128(%1);\n\t"
"fmuls 128(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 132(%1);\n\t"
"fmuls 132(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 136(%1);\n\t"
"fmuls 136(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"flds 140(%1);\n\t"
"fmuls 140(%2);\n\t"
"fxch %%st(2);\n\t"
"faddp;\n\t"
"faddp;\n\t" :
"=t" (f) :
"r" (a),
"r" (b) : "memory");
return f;
default:
printf("Warning: optimize __mac_c(..., ..., %d)\n", size);
+34 -2
View File
@@ -55,6 +55,15 @@ struct demod_state {
unsigned int numnibbles;
} rx[2];
} pocsag;
struct l2_state_pprz {
unsigned char rxbuf[512];
unsigned char *rxptr;
unsigned int rxstate;
unsigned int rxbitstream;
unsigned int rxbitbuf;
int pipe_fd;
} pprz;
} l2;
union {
struct l1_state_poc5 {
@@ -87,6 +96,22 @@ struct demod_state {
unsigned int lasts;
} afsk24;
struct l1_state_afsk48p {
unsigned int dcd_shreg;
unsigned int sphase;
unsigned int lasts;
unsigned int dcd_count;
unsigned int sample_count;
} afsk48p;
struct l1_state_afsk48 {
unsigned int dcd_shreg;
unsigned int sphase;
unsigned int lasts;
unsigned int dcd_count;
unsigned int sample_count;
} afsk48;
struct l1_state_hapn48 {
unsigned int shreg;
unsigned int sphase;
@@ -140,6 +165,8 @@ extern const struct demod_param demod_poc24;
extern const struct demod_param demod_afsk1200;
extern const struct demod_param demod_afsk2400;
extern const struct demod_param demod_afsk2400_2;
extern const struct demod_param demod_afsk4800p;
extern const struct demod_param demod_afsk4800;
extern const struct demod_param demod_hapn4800;
extern const struct demod_param demod_fsk9600;
@@ -150,8 +177,9 @@ extern const struct demod_param demod_zvei;
extern const struct demod_param demod_scope;
#define ALL_DEMOD &demod_poc5, &demod_poc12, &demod_poc24, \
&demod_afsk1200, &demod_afsk2400, &demod_afsk2400_2, &demod_hapn4800, \
&demod_fsk9600, &demod_dtmf, &demod_zvei, &demod_scope
&demod_afsk1200, &demod_afsk2400, &demod_afsk2400_2, &demod_afsk4800p, \
&demod_afsk4800, &demod_hapn4800, &demod_fsk9600, &demod_dtmf, \
&demod_zvei, &demod_scope
/* ---------------------------------------------------------------------- */
@@ -163,6 +191,10 @@ void hdlc_rxbit(struct demod_state *s, int bit);
void pocsag_init(struct demod_state *s);
void pocsag_rxbit(struct demod_state *s, int bit);
void pprz_init(struct demod_state *s);
void pprz_rxbit(struct demod_state *s, int bit);
void pprz_status(struct demod_state *s);
void xdisp_terminate(int cnum);
int xdisp_start(void);
int xdisp_update(int cnum, float *f);
+183
View File
@@ -0,0 +1,183 @@
/*
* pprz.c -- paparazzi decoder
*
* Copyright (C) 1996
* Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
* Copyright (C) 2005
* Martin Mueller (ma.mueller@tu-bs.de)
*
* 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ---------------------------------------------------------------------- */
#include "multimon.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#define STX 0x02
#define ETX 0x03
#define MSG_DATA 0
#define MSG_ERROR 1
#define MSG_CD 2
#define MSG_DEBUG 3
#define MSG_VALIM 4
#define INPUT_BUF_LEN 10
#define MULTIMON_PIPE_NAME "multimon"
/* ---------------------------------------------------------------------- */
static void pprz_tmtc_send(struct demod_state *s, unsigned char *data, unsigned int len, unsigned char type)
{
unsigned char msg[INPUT_BUF_LEN+6];
unsigned int count = 0;
int ret;
unsigned char checksum = 0;
const unsigned char real_len = len + 2;
unsigned char i;
msg[count++] = STX;
msg[count++] = real_len;
checksum ^= real_len;
msg[count++] = type;
checksum ^= type;
for (i=0; i < len; i++) {
msg[count++] = data[i];
checksum ^= data[i];
}
msg[count++] = checksum;
msg[count++] = ETX;
ret = write(s->l2.pprz.pipe_fd, msg, count);
if (count != ret)
perror("write pipe");
}
/* ---------------------------------------------------------------------- */
void pprz_init(struct demod_state *s)
{
memset(&s->l2.hdlc, 0, sizeof(s->l2.hdlc));
/* open named pipe */
if ((s->l2.pprz.pipe_fd = open(MULTIMON_PIPE_NAME, O_WRONLY /*| O_NONBLOCK*/)) < 0) {
perror("open pipe");
exit (10);
}
/* reset buffer pointer */
s->l2.pprz.rxptr = s->l2.hdlc.rxbuf;
}
/* ---------------------------------------------------------------------- */
void pprz_baudot_rxbit(struct demod_state *s, int bit)
{
/* (stop)bit found? */
if (bit & 1) {
/* check for sync and start bit */
if ((s->l2.hdlc.rxbitbuf & 1) &&
!(s->l2.hdlc.rxbitbuf & 2)) {
/* found new byte */
*s->l2.hdlc.rxptr++ = (s->l2.hdlc.rxbitbuf >> 2) & 0xFF;
verbprintf(8, "0x%02X ", (s->l2.hdlc.rxbitbuf >> 2) & 0xFF);
/* reset bit buffer */
s->l2.hdlc.rxbitbuf = 0x400;
} else {
/* add data bit */
s->l2.hdlc.rxbitbuf |= 0x400;
}
}
if ((s->l2.hdlc.rxptr - s->l2.hdlc.rxbuf) >= INPUT_BUF_LEN) {
pprz_tmtc_send(s, s->l2.hdlc.rxbuf, s->l2.hdlc.rxptr - s->l2.hdlc.rxbuf, MSG_DATA);
/* reset data buffer */
s->l2.hdlc.rxptr = s->l2.hdlc.rxbuf;
}
/* frame end / out of sync */
if (s->l2.hdlc.rxbitbuf & 1)
s->l2.hdlc.rxbitbuf |= 2;
/* shift in new data */
s->l2.hdlc.rxbitbuf >>= 1;
return;
}
/* ---------------------------------------------------------------------- */
void pprz_hdlc_rxbit(struct demod_state *s, int bit)
{
s->l2.hdlc.rxbitstream <<= 1;
s->l2.hdlc.rxbitstream |= !!bit;
if ((s->l2.hdlc.rxbitstream & 0xff) == 0x7e) {
if (s->l2.hdlc.rxstate && (s->l2.hdlc.rxptr - s->l2.hdlc.rxbuf) > 2)
pprz_tmtc_send(s, s->l2.hdlc.rxbuf, s->l2.hdlc.rxptr - s->l2.hdlc.rxbuf, MSG_DATA);
s->l2.hdlc.rxstate = 1;
s->l2.hdlc.rxptr = s->l2.hdlc.rxbuf;
s->l2.hdlc.rxbitbuf = 0x80;
return;
}
if ((s->l2.hdlc.rxbitstream & 0x7f) == 0x7f) {
s->l2.hdlc.rxstate = 0;
return;
}
if (!s->l2.hdlc.rxstate)
return;
if ((s->l2.hdlc.rxbitstream & 0x3f) == 0x3e) /* stuffed bit */
return;
if (s->l2.hdlc.rxbitstream & 1)
s->l2.hdlc.rxbitbuf |= 0x100;
if (s->l2.hdlc.rxbitbuf & 1) {
if (s->l2.hdlc.rxptr >= s->l2.hdlc.rxbuf+sizeof(s->l2.hdlc.rxbuf)) {
s->l2.hdlc.rxstate = 0;
verbprintf(1, "Error: packet size too large\n");
return;
}
*s->l2.hdlc.rxptr++ = s->l2.hdlc.rxbitbuf >> 1;
s->l2.hdlc.rxbitbuf = 0x80;
return;
}
s->l2.hdlc.rxbitbuf >>= 1;
}
/* ---------------------------------------------------------------------- */
void pprz_status(struct demod_state *s)
{
unsigned char data[2];
/* TODO find carrier */
data[0] = 0x01; pprz_tmtc_send(s, data, 1, MSG_CD);
/* just write some useful value (get it from acpi?) */
data[0] = 0x00; data[1] = 0x04; pprz_tmtc_send(s, data, 2, MSG_VALIM);
/* no debug value */
data[0] = 0x00; pprz_tmtc_send(s, data, 1, MSG_DEBUG);
return;
}
/* ---------------------------------------------------------------------- */