Skip to content

Commit 110b85a

Browse files
committed
Add EAS to gen_packets.
1 parent 4ac666d commit 110b85a

File tree

6 files changed

+323
-24
lines changed

6 files changed

+323
-24
lines changed

man/gen_packets.1

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Data rate in bits/sec for first channel. Standard values are 300, 1200, 2400, 4
4646
4800 bps uses 8PSK based on V.27 standard.
4747
.P
4848
9600 bps and up uses K9NG/G3RUH standard.
49+
.P
50+
EAS for Emergency Alert System (EAS) Specific Area Message Encoding (SAME).
4951
.RE
5052
.RE
5153
.PD

src/gen_packets.c

+78-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// This file is part of Dire Wolf, an amateur radio packet TNC.
33
//
4-
// Copyright (C) 2011, 2013, 2014, 2015, 2016, 2019, 2021 John Langner, WB2OSZ
4+
// Copyright (C) 2011, 2013, 2014, 2015, 2016, 2019, 2021, 2023 John Langner, WB2OSZ
55
//
66
// This program is free software: you can redistribute it and/or modify
77
// it under the terms of the GNU General Public License as published by
@@ -118,13 +118,48 @@ static void send_packet (char *str)
118118
packet_t pp;
119119
unsigned char fbuf[AX25_MAX_PACKET_LEN+2];
120120
int flen;
121-
int c;
121+
int c = 0; // channel number.
122122

123123
if (g_morse_wpm > 0) {
124124

125-
// TODO: Why not use the destination field instead of command line option?
125+
// Why not use the destination field instead of command line option?
126+
// For one thing, this is not in TNC-2 monitor format.
126127

127-
morse_send (0, str, g_morse_wpm, 100, 100);
128+
morse_send (c, str, g_morse_wpm, 100, 100);
129+
}
130+
else if (modem.achan[0].modem_type == MODEM_EAS) {
131+
132+
// Generate EAS SAME signal FOR RESEARCH AND TESTING ONLY!!!
133+
// There could be legal consequences for sending unauhorized SAME
134+
// over the radio so don't do it!
135+
136+
// I'm expecting to see TNC 2 monitor format.
137+
// The source and destination are ignored.
138+
// The optional destination SSID is the number of times to repeat.
139+
// The user defined data type indicator can optionally be used
140+
// for compatibility with how it is received and presented to client apps.
141+
// Examples:
142+
// X>X-3:{DEZCZC-WXR-RWT-033019-033017-033015-033013-033011-025011-025017-033007-033005-033003-033001-025009-025027-033009+0015-1691525-KGYX/NWS-
143+
// X>X:NNNN
144+
145+
pp = ax25_from_text (str, 1);
146+
if (pp == NULL) {
147+
text_color_set(DW_COLOR_ERROR);
148+
dw_printf ("\"%s\" is not valid TNC2 monitoring format.\n", str);
149+
return;
150+
}
151+
unsigned char *pinfo;
152+
int info_len = ax25_get_info (pp, &pinfo);
153+
if (info_len >= 3 && strncmp((char*)pinfo, "{DE", 3) == 0) {
154+
pinfo += 3;
155+
info_len -= 3;
156+
}
157+
158+
int repeat = ax25_get_ssid (pp, AX25_DESTINATION);
159+
if (repeat == 0) repeat = 1;
160+
161+
eas_send (c, pinfo, repeat, 500, 500);
162+
ax25_delete (pp);
128163
}
129164
else {
130165
pp = ax25_from_text (str, 1);
@@ -135,6 +170,9 @@ static void send_packet (char *str)
135170
}
136171
flen = ax25_pack (pp, fbuf);
137172
(void)flen;
173+
174+
// If stereo, put same thing in each channel.
175+
138176
for (c=0; c<modem.adev[0].num_channels; c++)
139177
{
140178

@@ -282,23 +320,31 @@ int main(int argc, char **argv)
282320

283321
// FIXME: options should not be order dependent.
284322

285-
modem.achan[0].baud = atoi(optarg);
323+
if (strcasecmp(optarg, "EAS") == 0) {
324+
modem.achan[0].baud = 0xEA5EA5; // See special case below.
325+
}
326+
else {
327+
modem.achan[0].baud = atoi(optarg);
328+
}
329+
286330
text_color_set(DW_COLOR_INFO);
287331
dw_printf ("Data rate set to %d bits / second.\n", modem.achan[0].baud);
288-
if (modem.achan[0].baud != 100 && (modem.achan[0].baud < MIN_BAUD || modem.achan[0].baud > MAX_BAUD)) {
289-
text_color_set(DW_COLOR_ERROR);
290-
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
291-
exit (EXIT_FAILURE);
292-
}
293332

294333
/* We have similar logic in direwolf.c, config.c, gen_packets.c, and atest.c, */
295334
/* that need to be kept in sync. Maybe it could be a common function someday. */
296335

297-
if (modem.achan[0].baud == 100) {
336+
if (modem.achan[0].baud == 100) { // What was this for?
298337
modem.achan[0].modem_type = MODEM_AFSK;
299338
modem.achan[0].mark_freq = 1615;
300339
modem.achan[0].space_freq = 1785;
301340
}
341+
else if (modem.achan[0].baud == 0xEA5EA5) {
342+
modem.achan[0].baud = 521; // Fine tuned later. 520.83333
343+
// Proper fix is to make this float.
344+
modem.achan[0].modem_type = MODEM_EAS;
345+
modem.achan[0].mark_freq = 2083.3333; // Ideally these should be floating point.
346+
modem.achan[0].space_freq = 1562.5000 ;
347+
}
302348
else if (modem.achan[0].baud < 600) {
303349
modem.achan[0].modem_type = MODEM_AFSK;
304350
modem.achan[0].mark_freq = 1600; // Typical for HF SSB
@@ -334,6 +380,11 @@ int main(int argc, char **argv)
334380
text_color_set(DW_COLOR_INFO);
335381
dw_printf ("Using scrambled baseband signal rather than AFSK.\n");
336382
}
383+
if (modem.achan[0].baud != 100 && (modem.achan[0].baud < MIN_BAUD || modem.achan[0].baud > MAX_BAUD)) {
384+
text_color_set(DW_COLOR_ERROR);
385+
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
386+
exit (EXIT_FAILURE);
387+
}
337388
break;
338389

339390
case 'g': /* -g for g3ruh scrambling */
@@ -740,14 +791,23 @@ int main(int argc, char **argv)
740791
}
741792
else {
742793

794+
// This should send a total of 6.
795+
// Note that sticking in the user defined type {DE is optional.
796+
797+
if (modem.achan[0].modem_type == MODEM_EAS) {
798+
send_packet ("X>X-3:{DEZCZC-WXR-RWT-033019-033017-033015-033013-033011-025011-025017-033007-033005-033003-033001-025009-025027-033009+0015-1691525-KGYX/NWS-");
799+
send_packet ("X>X-2:{DENNNN");
800+
send_packet ("X>X:NNNN");
801+
}
802+
else {
743803
/*
744804
* Builtin default 4 packets.
745805
*/
746-
747-
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 1 of 4");
748-
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 2 of 4");
749-
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 3 of 4");
750-
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 4 of 4");
806+
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 1 of 4");
807+
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 2 of 4");
808+
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 3 of 4");
809+
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 4 of 4");
810+
}
751811
}
752812

753813
audio_file_close();
@@ -765,7 +825,7 @@ static void usage (char **argv)
765825
dw_printf ("Options:\n");
766826
dw_printf (" -a <number> Signal amplitude in range of 0 - 200%%. Default 50.\n");
767827
dw_printf (" -b <number> Bits / second for data. Default is %d.\n", DEFAULT_BAUD);
768-
dw_printf (" -B <number> Bits / second for data. Proper modem selected for 300, 1200, 2400, 4800, 9600.\n");
828+
dw_printf (" -B <number> Bits / second for data. Proper modem selected for 300, 1200, 2400, 4800, 9600, EAS.\n");
769829
dw_printf (" -g Scrambled baseband rather than AFSK.\n");
770830
dw_printf (" -j 2400 bps QPSK compatible with direwolf <= 1.5.\n");
771831
dw_printf (" -J 2400 bps QPSK compatible with MFJ-2400.\n");
@@ -788,6 +848,7 @@ static void usage (char **argv)
788848
dw_printf ("the default built-in message. The format should correspond to\n");
789849
dw_printf ("the standard packet monitoring representation such as,\n\n");
790850
dw_printf (" WB2OSZ-1>APDW12,WIDE2-2:!4237.14NS07120.83W#\n");
851+
dw_printf ("User defined content can't be used with -n option.\n");
791852
dw_printf ("\n");
792853
dw_printf ("Example: gen_packets -o x.wav \n");
793854
dw_printf ("\n");

0 commit comments

Comments
 (0)