Skip to content

Commit f9a00b6

Browse files
committed
Add support for full CTCSS and DCS beacon options
1 parent d615187 commit f9a00b6

8 files changed

Lines changed: 52 additions & 28 deletions

File tree

src/beacon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
893893
bp->symtab, bp->symbol,
894894
bp->power, bp->height, bp->gain, bp->dir,
895895
G_UNKNOWN, G_UNKNOWN, /* course, speed */
896-
bp->freq, bp->tone, bp->offset,
896+
bp->freq, bp->tone_type, bp->tone, bp->offset,
897897
super_comment,
898898
info, sizeof(info));
899899
strlcat (beacon_text, info, sizeof(beacon_text));
@@ -905,7 +905,7 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
905905
bp->symtab, bp->symbol,
906906
bp->power, bp->height, bp->gain, bp->dir,
907907
G_UNKNOWN, G_UNKNOWN, /* course, speed */
908-
bp->freq, bp->tone, bp->offset, super_comment,
908+
bp->freq, bp-> tone_type, bp->tone, bp->offset, super_comment,
909909
info, sizeof(info));
910910
strlcat (beacon_text, info, sizeof(beacon_text));
911911
break;
@@ -936,7 +936,7 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
936936
bp->symtab, bp->symbol,
937937
bp->power, bp->height, bp->gain, bp->dir,
938938
coarse, (int)roundf(gpsinfo->speed_knots),
939-
bp->freq, bp->tone, bp->offset,
939+
bp->freq, bp->tone_type, bp->tone, bp->offset,
940940
super_comment,
941941
info, sizeof(info));
942942
strlcat (beacon_text, info, sizeof(beacon_text));

src/config.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6020,6 +6020,7 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
60206020
b->symtab = '/';
60216021
b->symbol = '-'; /* house */
60226022
b->freq = G_UNKNOWN;
6023+
b->tone_type = 'T';
60236024
b->tone = G_UNKNOWN;
60246025
b->offset = G_UNKNOWN;
60256026
b->source = NULL;
@@ -6270,7 +6271,18 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
62706271
b->freq = atof(value);
62716272
}
62726273
else if (strcasecmp(keyword, "TONE") == 0) {
6273-
b->tone = atof(value);
6274+
b->tone_type = 'T';
6275+
/* Try the legacy tone config, just a number */
6276+
if((b->tone = atof(value)) == 0) {
6277+
/* Legacy parsing failed, try with leading type char */
6278+
if(sscanf(value, "%c%f", &b->tone_type, &b->tone) != 2) {
6279+
/* That failed. Bad tone format, set to no tone */
6280+
b->tone_type = 'T';
6281+
b->tone = 0;
6282+
text_color_set(DW_COLOR_ERROR);
6283+
dw_printf ("Config file, line %d: Bad tone format, %s.\n", line, value);
6284+
}
6285+
}
62746286
}
62756287
else if (strcasecmp(keyword, "OFFSET") == 0 || strcasecmp(keyword, "OFF") == 0) {
62766288
b->offset = atof(value);

src/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ struct misc_config_s {
233233
char dir[3]; /* 1 or 2 of N,E,W,S, or empty for omni. */
234234

235235
float freq; /* MHz. */
236+
char tone_type; /* Tone(T), Tone Squelch(C) or DCS(D) */
236237
float tone; /* Hz. */
237238
float offset; /* MHz. */
238239

src/direwolf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
15911591
// Unknown not handled properly.
15921592
// Should encode_object take floating point here?
15931593
(int)(A.g_course+0.5), (int)(DW_MPH_TO_KNOTS(A.g_speed_mph)+0.5),
1594-
0, 0, 0, A.g_comment, // freq, tone, offset
1594+
0, 'T', 0, 0, A.g_comment, // freq, tone_type, tone, offset
15951595
ais_obj_info, sizeof(ais_obj_info));
15961596

15971597
snprintf (ais_obj_packet, sizeof(ais_obj_packet), "%s>%s%1d%1d,NOGATE:%s", A.g_src, APP_TOCALL, MAJOR_VERSION, MINOR_VERSION, ais_obj_info);

src/encode_aprs.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ static int cse_spd_data_extension (int course, int speed, char *presult)
405405
* Purpose: Put frequency specification in beginning of comment field.
406406
*
407407
* Inputs: freq - MHz.
408+
* tone_type - T/Tone, C/Tone Squelch, D/DCS
408409
* tone - Hz.
409410
* offset - MHz.
410411
*
@@ -430,7 +431,7 @@ static int cse_spd_data_extension (int course, int speed, char *presult)
430431
*----------------------------------------------------------------*/
431432

432433

433-
static int frequency_spec (float freq, float tone, float offset, char *presult)
434+
static int frequency_spec (float freq, char tone_type, float tone, float offset, char *presult)
434435
{
435436
int result_size = 24; // TODO: add as parameter.
436437

@@ -456,7 +457,15 @@ static int frequency_spec (float freq, float tone, float offset, char *presult)
456457
strlcpy (stemp, "Toff ", sizeof (stemp));
457458
}
458459
else {
459-
snprintf (stemp, sizeof(stemp), "T%03d ", (int)tone);
460+
/* Tone enabled */
461+
if (tone_type == 'T' || tone_type == 'C' || tone_type == 'D') {
462+
/* CTCSS Tone or DCS Code*/
463+
snprintf(stemp, sizeof(stemp), "%c%03d ", tone_type, (int)tone);
464+
} else {
465+
/* Error */
466+
text_color_set(DW_COLOR_ERROR);
467+
dw_printf("Invalid tone type\n");
468+
}
460469
}
461470

462471
strlcat (presult, stemp, result_size);
@@ -499,6 +508,7 @@ static int frequency_spec (float freq, float tone, float offset, char *presult)
499508
* speed - knots. // TODO: should distinguish unknown(not revevant) vs. known zero.
500509
*
501510
* freq - MHz.
511+
* tone_type - T/C/D
502512
* tone - Hz.
503513
* offset - MHz.
504514
*
@@ -544,7 +554,7 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
544554
char symtab, char symbol,
545555
int power, int height, int gain, char *dir,
546556
int course, int speed,
547-
float freq, float tone, float offset,
557+
float freq, char tone_type, float tone, float offset,
548558
char *comment,
549559
char *presult, size_t result_size)
550560
{
@@ -590,7 +600,7 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
590600
/* Optional frequency spec. */
591601

592602
if (freq != 0 || tone != 0 || offset != 0) {
593-
result_len += frequency_spec (freq, tone, offset, presult + result_len);
603+
result_len += frequency_spec (freq, tone_type, tone, offset, presult + result_len);
594604
}
595605

596606
presult[result_len] = '\0';
@@ -658,6 +668,7 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
658668
* speed - knots.
659669
*
660670
* freq - MHz.
671+
* tone_type - T/C/D
661672
* tone - Hz.
662673
* offset - MHz.
663674
*
@@ -695,7 +706,7 @@ int encode_object (char *name, int compressed, time_t thyme, double lat, double
695706
char symtab, char symbol,
696707
int power, int height, int gain, char *dir,
697708
int course, int speed,
698-
float freq, float tone, float offset, char *comment,
709+
float freq, char tone_type, float tone, float offset, char *comment,
699710
char *presult, size_t result_size)
700711
{
701712
aprs_object_t *p = (aprs_object_t *) presult;
@@ -761,7 +772,7 @@ int encode_object (char *name, int compressed, time_t thyme, double lat, double
761772
/* Optional frequency spec. */
762773

763774
if (freq != 0 || tone != 0 || offset != 0) {
764-
result_len += frequency_spec (freq, tone, offset, presult + result_len);
775+
result_len += frequency_spec (freq, tone_type, tone, offset, presult + result_len);
765776
}
766777

767778
presult[result_len] = '\0';
@@ -865,58 +876,58 @@ int main (int argc, char *argv[])
865876
/*********** Position ***********/
866877

867878
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
868-
0, 0, 0, NULL, G_UNKNOWN, 0, 0, 0, 0, NULL, result, sizeof(result));
879+
0, 0, 0, NULL, G_UNKNOWN, 0, 0, 'T', 0, 0, NULL, result, sizeof(result));
869880
dw_printf ("%s\n", result);
870881
if (strcmp(result, "!4234.61ND07126.47W&") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
871882

872883
/* with PHG. */
873884
// TODO: Need to test specifying some but not all.
874885

875886
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
876-
50, 100, 6, "N", G_UNKNOWN, 0, 0, 0, 0, NULL, result, sizeof(result));
887+
50, 100, 6, "N", G_UNKNOWN, 0, 0, 'T', 0, 0, NULL, result, sizeof(result));
877888
dw_printf ("%s\n", result);
878889
if (strcmp(result, "!4234.61ND07126.47W&PHG7368") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
879890

880891
/* with freq & tone. minus offset, no offset, explicit simplex. */
881892

882893
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
883-
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 74.4, -0.6, NULL, result, sizeof(result));
894+
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 'T', 74.4, -0.6, NULL, result, sizeof(result));
884895
dw_printf ("%s\n", result);
885896
if (strcmp(result, "!4234.61ND07126.47W&146.955MHz T074 -060 ") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
886897

887898
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
888-
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 74.4, G_UNKNOWN, NULL, result, sizeof(result));
899+
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 'T', 74.4, G_UNKNOWN, NULL, result, sizeof(result));
889900
dw_printf ("%s\n", result);
890901
if (strcmp(result, "!4234.61ND07126.47W&146.955MHz T074 ") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
891902

892903
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
893-
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 74.4, 0, NULL, result, sizeof(result));
904+
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 'T', 74.4, 0, NULL, result, sizeof(result));
894905
dw_printf ("%s\n", result);
895906
if (strcmp(result, "!4234.61ND07126.47W&146.955MHz T074 +000 ") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
896907

897908
/* with course/speed, freq, and comment! */
898909

899910
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
900-
0, 0, 0, NULL, 180, 55, 146.955, 74.4, -0.6, "River flooding", result, sizeof(result));
911+
0, 0, 0, NULL, 180, 55, 146.955, 'T', 74.4, -0.6, "River flooding", result, sizeof(result));
901912
dw_printf ("%s\n", result);
902913
if (strcmp(result, "!4234.61ND07126.47W&180/055146.955MHz T074 -060 River flooding") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
903914

904915
/* Course speed, no tone, + offset */
905916

906917
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
907-
0, 0, 0, NULL, 180, 55, 146.955, G_UNKNOWN, 0.6, "River flooding", result, sizeof(result));
918+
0, 0, 0, NULL, 180, 55, 146.955, 'T', G_UNKNOWN, 0.6, "River flooding", result, sizeof(result));
908919
dw_printf ("%s\n", result);
909920
if (strcmp(result, "!4234.61ND07126.47W&180/055146.955MHz +060 River flooding") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
910921

911922
/* Course speed, no tone, + offset + altitude */
912923

913924
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, 12345, 'D', '&',
914-
0, 0, 0, NULL, 180, 55, 146.955, G_UNKNOWN, 0.6, "River flooding", result, sizeof(result));
925+
0, 0, 0, NULL, 180, 55, 146.955, 'T', G_UNKNOWN, 0.6, "River flooding", result, sizeof(result));
915926
dw_printf ("%s\n", result);
916927
if (strcmp(result, "!4234.61ND07126.47W&180/055146.955MHz +060 /A=012345River flooding") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
917928

918929
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, 12345, 'D', '&',
919-
0, 0, 0, NULL, 180, 55, 146.955, 0, 0.6, "River flooding", result, sizeof(result));
930+
0, 0, 0, NULL, 180, 55, 146.955, 'T', 0, 0.6, "River flooding", result, sizeof(result));
920931
dw_printf ("%s\n", result);
921932
if (strcmp(result, "!4234.61ND07126.47W&180/055146.955MHz Toff +060 /A=012345River flooding") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
922933

@@ -925,22 +936,22 @@ int main (int argc, char *argv[])
925936
/*********** Compressed position. ***********/
926937

927938
encode_position (0, 1, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
928-
0, 0, 0, NULL, G_UNKNOWN, 0, 0, 0, 0, NULL, result, sizeof(result));
939+
0, 0, 0, NULL, G_UNKNOWN, 0, 0, 'T', 0, 0, NULL, result, sizeof(result));
929940
dw_printf ("%s\n", result);
930941
if (strcmp(result, "!D8yKC<Hn[& !") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
931942

932943

933944
/* with PHG. In this case it is converted to precomputed radio range. TODO: check on this. Is 27.4 correct? */
934945

935946
encode_position (0, 1, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
936-
50, 100, 6, "N", G_UNKNOWN, 0, 0, 0, 0, NULL, result, sizeof(result));
947+
50, 100, 6, "N", G_UNKNOWN, 0, 0, 'T', 0, 0, NULL, result, sizeof(result));
937948
dw_printf ("%s\n", result);
938949
if (strcmp(result, "!D8yKC<Hn[&{CG") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
939950

940951
/* with course/speed, freq, and comment! Roundoff. 55 knots should be 63 MPH. we get 62. */
941952

942953
encode_position (0, 1, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
943-
0, 0, 0, NULL, 180, 55, 146.955, 74.4, -0.6, "River flooding", result, sizeof(result));
954+
0, 0, 0, NULL, 180, 55, 146.955, 'T', 74.4, -0.6, "River flooding", result, sizeof(result));
944955
dw_printf ("%s\n", result);
945956
if (strcmp(result, "!D8yKC<Hn[&NUG146.955MHz T074 -060 River flooding") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
946957

@@ -950,7 +961,7 @@ int main (int argc, char *argv[])
950961
/*********** Object. ***********/
951962

952963
encode_object ("WB1GOF-C", 0, 0, 42+34.61/60, -(71+26.47/60), 0, 'D', '&',
953-
0, 0, 0, NULL, G_UNKNOWN, 0, 0, 0, 0, NULL, result, sizeof(result));
964+
0, 0, 0, NULL, G_UNKNOWN, 0, 0, 'T', 0, 0, NULL, result, sizeof(result));
954965
dw_printf ("%s\n", result);
955966
if (strcmp(result, ";WB1GOF-C *111111z4234.61ND07126.47W&") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
956967

src/encode_aprs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
33
char symtab, char symbol,
44
int power, int height, int gain, char *dir,
55
int course, int speed_knots,
6-
float freq, float tone, float offset,
6+
float freq, char tone_type, float tone, float offset,
77
char *comment,
88
char *presult, size_t result_size);
99

1010
int encode_object (char *name, int compressed, time_t thyme, double lat, double lon, int ambiguity,
1111
char symtab, char symbol,
1212
int power, int height, int gain, char *dir,
1313
int course, int speed_knots,
14-
float freq, float tone, float offset, char *comment,
14+
float freq, char tone_type, float tone, float offset, char *comment,
1515
char *presult, size_t result_size);
1616

1717
int encode_message (char *addressee, char *text, char *id, char *presult, size_t result_size);

src/tt_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ static void xmit_object_report (int i, int first_time)
847847
0,0,0,NULL, G_UNKNOWN, G_UNKNOWN, /* PHGD, Course/Speed */
848848
strlen(tt_user[i].freq) > 0 ? atof(tt_user[i].freq) : G_UNKNOWN,
849849
strlen(tt_user[i].ctcss) > 0 ? atof(tt_user[i].ctcss) : G_UNKNOWN,
850-
G_UNKNOWN, /* CTCSS */
850+
'T', G_UNKNOWN, /* CTCSS */
851851
info_comment, object_info, sizeof(object_info));
852852

853853
strlcat (stemp, object_info, sizeof(stemp));

src/walk96.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static void walk96 (int fix, double lat, double lon, float knots, float course,
156156
'/', '=',
157157
G_UNKNOWN, G_UNKNOWN, G_UNKNOWN, "", // PHGd
158158
(int)roundf(course), (int)roundf(knots),
159-
445.925, 0, 0,
159+
445.925, 'T', 0, 0,
160160
comment,
161161
info, sizeof(info));
162162

0 commit comments

Comments
 (0)