Skip to content

Commit a18449a

Browse files
committed
re-worked makefile. FEC enable/disable flag for EDI2ETI.
1 parent 6f100f5 commit a18449a

File tree

5 files changed

+124
-53
lines changed

5 files changed

+124
-53
lines changed

Makefile

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
1-
2-
3-
CFLAGS=-O2 -I.
4-
LDFLAGS=-lm
1+
CC = gcc
2+
CFLAGS =-O2 -Wall
3+
OBJS_EDI2ETI = network.o af_parser.o pf_parser.o tag_parser.o crc.o eti_assembler.o logging.o edi2eti.o
4+
OBJS_TS2NA = ts2na.o
5+
OBJS_TS2NA_DREAMBOX = ts2na.o tune.o
6+
OBJS_NA2NI = na2ni.o
7+
OBJS_NI2HTTP = ni2http.o wffigproc.o wfficproc.o wfbyteops.o wftables.o wffirecrc.o wfcrc.o parse_config.o
8+
CFLAGS+=-I. -Ilibshout-2.2.2/include
9+
LDFLAGS+=-lm
510

611

712
#####################################################
813
# Uncomment this 2 lines if you want to enable ZeroMQ
914
#####################################################
10-
#CFLAGS+= -DHAVE_ZMQ
11-
#ZMQ_LDFLAGS:= -lzmq
15+
CFLAGS+= -DHAVE_ZMQ
16+
LDFLAGS+= -lzmq
1217

1318

1419
##################################################
1520
# Uncomment this 2 lines if you want to enable FEC
1621
##################################################
1722
#CFLAGS+= -DHAVE_FEC
18-
#FEC_LDFLAGS:= -lfec
23+
#LDFLAGS+= -lfec
24+
25+
26+
all: cleanapps ni2http ts2na na2ni edi2eti
1927

28+
%.o: %.c
29+
$(CC) $(CFLAGS) -c -o $@ $<
2030

21-
all: cleanapps ts2na na2ni ni2http edi2eti
31+
edi2eti: $(OBJS_EDI2ETI)
32+
$(CC) -o $@ $(OBJS_EDI2ETI) $(LDFLAGS)
2233

23-
edi2eti:
24-
gcc -g $(CFLAGS) -Wall -o edi2eti network.c af_parser.c pf_parser.c tag_parser.c crc.c eti_assembler.c logging.c edi2eti.c -lfec -lzmq
34+
ts2na: $(OBJS_TS2NA)
35+
$(CC) -o $@ $(OBJS_TS2NA) $(LDFLAGS)
2536

26-
ts2na:
27-
gcc -g $(CFLAGS) -Wall -o ts2na ts2na.c
37+
ts2na_dreambox: $(OBJS_TS2NA_DREAMBOX)
38+
$(CC) -o $@ $(OBJS_TS2NA_DREAMBOX) $(LDFLAGS)
2839

29-
ts2na_dreambox:
30-
gcc -g $(CFLAGS) -Wall -o ts2na ts2na.c tune.c
40+
na2ni: $(OBJS_NA2NI)
41+
$(CC) -o $@ $(OBJS_NA2NI) $(LDFLAGS)
3142

32-
na2ni:
33-
gcc -g $(CFLAGS) -Wall -o na2ni na2ni.c $(LDFLAGS) $(FEC_LDFLAGS)
43+
ni2http: libshout-2.2.2/src/.libs/libshout.a $(OBJS_NI2HTTP)
44+
$(CC) -o $@ $(OBJS_NI2HTTP) libshout-2.2.2/src/.libs/libshout.a -lpthread $(LDFLAGS)
3445

35-
ni2http:
36-
test -f ./libshout-2.2.2/src/.libs/libshout.a || { tar -xvzf libshout-2.2.2.tar.gz; cd libshout-2.2.2; ./configure --enable-shared=no --enable-static=yes; make; cd ..; }
37-
gcc -g $(CFLAGS) -Wall -o ni2http ni2http.c wffigproc.c wfficproc.c wfbyteops.c wftables.c wffirecrc.c wfcrc.c parse_config.c $(LDFLAGS) -I./libshout-2.2.2/include ./libshout-2.2.2/src/.libs/libshout.a -lpthread $(FEC_LDFLAGS) $(ZMQ_LDFLAGS)
46+
libshout-2.2.2/src/.libs/libshout.a:
47+
tar -xvzf libshout-2.2.2.tar.gz; cd libshout-2.2.2; ./configure --enable-shared=no --enable-static=yes; make; cd ..;
3848

3949
cleanapps:
40-
rm -f *.o
41-
rm -f ts2na na2ni ni2http edi2eti
50+
rm -f $(OBJS_EDI2ETI) $(OBJS_TS2NA) $(OBJS_TS2NA_DREAMBOX) $(OBJS_NA2NI) $(OBJS_NI2HTTP)
51+
rm -f ts2na na2ni ni2http edi2eti
4252

4353
clean: cleanapps
44-
if [ -f ./libshout-2.2.2/src/.libs/libshout.a ]; then cd libshout-2.2.2; make clean; cd ..; fi;
54+
if [ -f ./libshout-2.2.2/src/.libs/libshout.a ]; then cd libshout-2.2.2; make clean; cd ..; fi;

af_parser.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <unistd.h>
1515
#include <ctype.h>
1616

17+
#ifdef HAVE_FEC
1718
#include <fec.h>
19+
#endif
1820

1921
#include "edi_parser.h"
2022
#include "crc.h"
@@ -28,7 +30,9 @@ edi_handler_t *initEDIHandle(int fmt, callback_t outCallback, void *priv_data)
2830
edi_handler_t *h = calloc(1, sizeof(edi_handler_t));
2931
h->eti_format = fmt;
3032

33+
#ifdef HAVE_FEC
3134
h->afb.m_rs_handler = init_rs_char(8, 0x11d, 1, 1, 255 - 207, ((1 << 8) - 1) - 255);
35+
#endif
3236
h->write_cb = outCallback;
3337
h->write_cb_priv = priv_data;
3438
return h;
@@ -40,8 +44,9 @@ void closeEDIHandle(edi_handler_t *h)
4044
msg_Log("EDI: stats: packets lost: %u/%u errors:%u/%u",
4145
h->afb.PktLost, h->afb.PktCount, h->afb.errorsCorrected, h->afb.PktCount*h->afb.Plen);
4246
if(h) {
47+
#ifdef HAVE_FEC
4348
free_rs_char(h->afb.m_rs_handler);
44-
49+
#endif
4550
for(i=0;i<64;i++) {
4651
if(h->eti.m_stc[i].mst) {
4752
free(h->eti.m_stc[i].mst);
@@ -101,20 +106,9 @@ static int HandleAFPacket(edi_handler_t *h, uint8_t *edi_pkt, uint32_t pktsize)
101106
msg_Log("EDI-AF: packet not supported, has no CRC");
102107
return -1;
103108
}
104-
#if 0
105-
uint16_t crc = 0xffff;
106-
for (i = 0; i < AFPACKET_HEADER_LEN + taglength; i++) {
107-
crc = crc16(crc, &edi_pkt[i], 1);
108-
}
109-
crc ^= 0xffff;
110-
111-
uint16_t packet_crc = read_16b(edi_pkt + AFPACKET_HEADER_LEN + taglength);
112-
113-
#endif
114-
//msg_Dump(edi_pkt , pktsize);
115109

116-
//bool ok = checkCRC(edi_pkt, AFPACKET_HEADER_LEN + taglength + crclength);
117-
bool ok = checkCRC(edi_pkt, AFPACKET_HEADER_LEN + taglength + crclength);
110+
//this is checked at the second time if PS is used
111+
bool ok = checkCRC(edi_pkt, AFPACKET_HEADER_LEN + taglength + crclength);
118112

119113
if (!ok) {
120114
msg_Log("EDI-AF: Packet crc wrong pos:%u max:%u", AFPACKET_HEADER_LEN + taglength, pktsize);

edi2eti.c

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include "network.h"
2020
#include "logging.h"
2121

22+
#ifdef HAVE_ZMQ
2223
#include <zmq.h>
24+
#endif
2325

2426
#define VERSION_ID "$Rev$"
2527
#define DEFAULT_TTL 16
@@ -41,18 +43,38 @@ char *ip = DEFAULT_HOST;
4143
static void usage(char *name) {
4244
fprintf(
4345
stderr,
44-
"%s udp unicast/multicast tester.\n"
46+
"%s udp unicast/multicast EDI-to-ETI coverter.\n"
4547
"This is UDP unicast/multicast EDI-stream receiver that converts received stream to ETI-format %s.\n"
4648
"Usage: %s [options] [address]:[port]\n"
47-
"-v, --verbose : Show more info (default: no)\n"
48-
"-q, --quiet : Minimum info (default: no)\n"
49-
"-I, --interval <value> : Application udp reception interval\n"
50-
"-o, --output <file|url> : Output file path or zeromq url (default: stdout)\n"
51-
"-a, --activity : Dislay activity cursor (default: no)\n"
52-
"-h, --help : Show this help\n"
49+
"-v, --verbose : Show more info (default: no)\n"
50+
"-q, --quiet : Minimum info (default: no)\n"
51+
"-I, --interval <value> : Application udp reception time in seconds. Exit after that. (default:run forever)\n"
52+
#ifdef HAVE_ZMQ
53+
"-o, --output <file|zmq-url> : Output file path or zeromq url (default: stdout)\n"
54+
"-L, --no-align : Disable eti-packets alignment for ZeroMQ packing\n"
55+
#else
56+
"-o, --output <file> : Output file path (default: stdout)\n"
57+
#endif
58+
"-a, --activity : Dislay activity cursor (default: no)\n"
59+
"-h, --help : Show this help\n"
5360
"\n", name, VERSION_ID, name);
5461
}
5562

63+
static void build_info(char *name) {
64+
fprintf(stderr, "ZeroMQ:%s, FEC:%s\n",
65+
#ifdef HAVE_ZMQ
66+
"enabled",
67+
#else
68+
"disabled",
69+
#endif
70+
#ifdef HAVE_FEC
71+
"enabled"
72+
#else
73+
"disabled"
74+
#endif
75+
);
76+
}
77+
5678
static void signal_handler(int signum) {
5779
// if (signum != SIGPIPE) {
5880
if (signum != SIGPIPE) {
@@ -80,6 +102,7 @@ void write_file(void *privData, void *etiData, int etiLen)
80102

81103

82104

105+
#ifdef HAVE_ZMQ
83106

84107
#define NUM_FRAMES_PER_ZMQ_MESSAGE 4
85108

@@ -98,13 +121,17 @@ typedef struct {
98121
int is_initial = 1;
99122
zmq_dab_message_t zmq_msg;
100123
int zmq_msg_ix;
124+
int zmq_align = 1;
101125

102126
void write_zmq(void *privData, void *etiData, int etiLen)
103127
{
104-
int i;
105-
if(verbosity > 1)
106-
msg_Log("write:%u bytes to zmq part: %d", etiLen, zmq_msg_ix);
107-
int offset = 0;
128+
int i;
129+
int offset = 0;
130+
uint8_t *etiPkt = (uint8_t *) etiData;
131+
132+
if(verbosity > 1)
133+
msg_Log("write:%u bytes to zmq part: %d", etiLen, zmq_msg_ix);
134+
108135
// Increment the offset by the accumulated frame offsets
109136
for (i = 0; i < zmq_msg_ix; i++) {
110137
offset += zmq_msg.buflen[i];
@@ -115,8 +142,18 @@ void write_zmq(void *privData, void *etiData, int etiLen)
115142
return;
116143
}
117144

145+
if(etiLen < 16 || (zmq_align && zmq_msg_ix != ((etiPkt[6] >> 5) & 0x03))) {
146+
zmq_msg_ix=0;
147+
zmq_msg.buflen[0] = -1;
148+
zmq_msg.buflen[1] = -1;
149+
zmq_msg.buflen[2] = -1;
150+
zmq_msg.buflen[3] = -1;
151+
msg_Log("ZMQ: skip non-aligned frames: %02x != %02x", zmq_msg_ix, ((etiPkt[6] >> 5) & 0x03));
152+
return;
153+
}
154+
118155
// Append the new frame to our message
119-
memcpy(zmq_msg.buf + offset, etiData, etiLen);
156+
memcpy(zmq_msg.buf + offset, etiPkt, etiLen);
120157
zmq_msg.buflen[zmq_msg_ix] = etiLen;
121158
zmq_msg_ix++;
122159

@@ -142,7 +179,7 @@ void write_zmq(void *privData, void *etiData, int etiLen)
142179
}
143180
}
144181
}
145-
182+
#endif
146183

147184

148185
int main(int argc, char **argv) {
@@ -153,26 +190,30 @@ int main(int argc, char **argv) {
153190
int port = DEFAULT_PORT;
154191
int activity=0;
155192
edi_handler_t *edi_p=NULL;
193+
#ifdef HAVE_ZMQ
156194
void *zmq_context = NULL;
157195
void *zmq_publisher = NULL;
196+
#endif
158197

159198
/******************************************************
160199
* Getopt
161200
******************************************************/
162-
const char short_options[] = "vaqhI:o:";
201+
const char short_options[] = "vLaqhI:o:";
163202
const struct option long_options[] = {
164203
{ "interval", optional_argument, NULL, 'I' },
165204
{ "verbose", optional_argument, NULL, 'v' },
166205
{ "quiet", optional_argument, NULL, 'q' },
167206
{ "output", optional_argument, NULL, 'o' },
168207
{ "activity", optional_argument, NULL, 'a' },
208+
{ "no-align", no_argument, NULL, 'L' },
169209
{ "help", no_argument, NULL, 'h' },
170210
{ 0, 0, 0, 0 }
171211
};
172212
int c, option_index = 0;
173213

174214
if (argc == 1) {
175215
usage(argv[0]);
216+
build_info(argv[0]);
176217
exit(-1);
177218
}
178219

@@ -192,7 +233,11 @@ int main(int argc, char **argv) {
192233
case 'a':
193234
activity++;
194235
break;
195-
236+
#ifdef HAVE_ZMQ
237+
case 'L':
238+
zmq_align=0;
239+
break;
240+
#endif
196241
case 'I':
197242
timeout = atoi(optarg);
198243
break;
@@ -203,19 +248,25 @@ int main(int argc, char **argv) {
203248

204249
case 'h':
205250
usage(argv[0]);
251+
build_info(argv[0]);
206252
exit(0);
207253
break;
208254
}
209255
}
210256

257+
if(verbosity > 0)
258+
build_info(argv[0]);
259+
211260
if (argc <= optind) {
212261
if (verbosity > 0)
213262
msg_Log("need to specify ip:port a:%d, o:%d", argc, optind);
214263
exit(-1);
215264
}
216265

266+
217267
if(outpath) {
218268
if(strncmp("zmq+", outpath, 4) == 0 && strlen(outpath) > 10) {
269+
#ifdef HAVE_ZMQ
219270
zmq_context = zmq_ctx_new ();
220271
zmq_publisher = zmq_socket (zmq_context, ZMQ_PUB);
221272
zmq_bind (zmq_publisher, outpath+4);
@@ -226,8 +277,13 @@ int main(int argc, char **argv) {
226277
zmq_msg.buflen[3] = -1;
227278
zmq_msg.version = 1;
228279
zmq_msg_ix=0;
280+
#else
281+
msg_Log("ZEROMQ is disabled! Can't stream to specified destination: %s", outpath);
282+
exit(-1);
283+
#endif
229284

230-
} else {
285+
} else
286+
{
231287
out_fh = fopen(outpath, "wb");
232288
edi_p = initEDIHandle(ETI_FMT_RAW, write_file, out_fh);
233289
}
@@ -322,10 +378,12 @@ int main(int argc, char **argv) {
322378
sock = 0;
323379
free(buff);
324380

381+
#ifdef HAVE_ZMQ
325382
if(zmq_publisher)
326383
zmq_close (zmq_publisher);
327384
if(zmq_context)
328385
zmq_term (zmq_context);
386+
#endif
329387

330388
return 1;
331389
}

ni2http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ int process_dabplus(uint8_t *data_ptr, int data_len, ni2http_channel_t *chan)
638638
cbuf[j] = chan->dabplus_data[s * j + i];
639639
#ifdef HAVE_FEC
640640
int errs = decode_rs_char(chan->dabplus_rs, cbuf, (int*)NULL, 0);
641-
/* fprintf(stderr,"errs = %d\n",errs);*/
641+
if(errs!=0) fprintf(stderr,"DAB+ errors: %d\n",errs);
642642
#endif
643643
/* Write checked/corrected data back to sfbuf */
644644
for (j = 0; j < 110; j++)

pf_parser.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <unistd.h>
1515
#include <ctype.h>
1616

17+
#ifdef HAVE_FEC
1718
#include <fec.h>
19+
#endif
1820

1921
#include "edi_parser.h"
2022
#include "crc.h"
@@ -167,12 +169,15 @@ static bool decodePFTFrags(struct afBuilders *afb, uint8_t _pseqIdx, uint32_t *e
167169
fprintf(stderr, "\n");
168170
}
169171
#endif
172+
173+
#ifdef HAVE_FEC
170174
//int errors_corrected = fec_decode(chunk, erasures[i], cnt);
171175
int num_err = decode_rs_char(afb->m_rs_handler, chunk, erasures[i], erasures_cnt);
172176
if (num_err == -1) {
173177
msg_Log("Too many errors in FEC %d", erasures_cnt);
174178
return false;
175179
}
180+
#endif
176181

177182
//if(num_err) {
178183
// fprintf(stderr, "corrected %d errors of %d\n", num_err, erasures_cnt);
@@ -183,6 +188,7 @@ static bool decodePFTFrags(struct afBuilders *afb, uint8_t _pseqIdx, uint32_t *e
183188

184189
//TODO: increase afb->bytesCollected
185190
_afSingle->bytesCollected = (afb->_cmax)*afb->RSk - afb->RSz;
191+
186192
} else {
187193
//afb->afPacket = _afSingle->pfPackets;
188194
memcpy(afb->afPacket, _afSingle->pfPackets, afb->Fcount*afb->Plen);
@@ -302,6 +308,9 @@ int pushPFTFrag(struct pfPkt *pf, struct afBuilders *afb)
302308
/* Receiving _rxmin fragments does not guarantee that decoding
303309
* will succeed! */
304310
afb->_rxmin = afb->Fcount - (afb->_cmax*48)/afb->Plen;
311+
#ifndef HAVE_FEC
312+
msg_Log("FEC is disabled in this application. Lost packets will not be recovered!");
313+
#endif
305314
} else {
306315
afb->_rxmin = afb->Fcount;
307316
afb->rs_block=NULL;

0 commit comments

Comments
 (0)