-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathwalk96.c
206 lines (145 loc) · 4.89 KB
/
walk96.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2015 John Langner, WB2OSZ
//
// 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, see <http://www.gnu.org/licenses/>.
//
//#define DEBUG 1
/*------------------------------------------------------------------
*
* Module: walk96.c
*
* Purpose: Quick hack to read GPS location and send very frequent
* position reports frames to a KISS TNC.
*
*
*---------------------------------------------------------------*/
#include "direwolf.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include "config.h"
#include "ax25_pad.h"
#include "textcolor.h"
#include "latlong.h"
#include "dwgps.h"
#include "encode_aprs.h"
#include "serial_port.h"
#include "kiss_frame.h"
#define MYCALL "WB2OSZ" /************ Change this if you use it!!! ***************/
#define HOWLONG 20 /* Run for 20 seconds then quit. */
static MYFDTYPE tnc;
static void walk96 (int fix, double lat, double lon, float knots, float course, float alt);
int main (int argc, char *argv[])
{
struct misc_config_s config;
char cmd[100];
int debug_gps = 0;
int n;
// TD-D72A USB - Look for Silicon Labs CP210x.
// Just happens to be same on desktop & laptop.
tnc = serial_port_open ("COM5", 9600);
if (tnc == MYFDERROR) {
text_color_set (DW_COLOR_ERROR);
dw_printf ("Can't open serial port to KISS TNC.\n");
exit (EXIT_FAILURE); // defined in stdlib.h
}
strlcpy (cmd, "\r\rhbaud 9600\rkiss on\rrestart\r", sizeof(cmd));
serial_port_write (tnc, cmd, strlen(cmd));
// USB GPS happens to be COM22
memset (&config, 0, sizeof(config));
strlcpy (config.gpsnmea_port, "COM22", sizeof(config.nmea_port));
dwgps_init (&config, debug_gps);
SLEEP_SEC(1); /* Wait for sample before reading. */
for (n=0; n<HOWLONG; n++) {
dwgps_info_t info;
dwfix_t fix;
fix = dwgps_read (&info);
if (fix > DWFIX_2D) {
walk96 (fix, info.dlat, info.dlon, info.speed_knots, info.track, info.altitude);
}
else if (fix < 0) {
text_color_set (DW_COLOR_ERROR);
dw_printf ("Can't communicate with GPS receiver.\n");
exit (EXIT_FAILURE);
}
else {
text_color_set (DW_COLOR_ERROR);
dw_printf ("GPS fix not available.\n");
}
SLEEP_SEC(1);
}
// Exit out of KISS mode.
serial_port_write (tnc, "\xc0\xff\xc0", 3);
SLEEP_MS(100);
exit (EXIT_SUCCESS);
}
/* Should be called once per second. */
static void walk96 (int fix, double lat, double lon, float knots, float course, float alt)
{
static int sequence = 0;
char comment[50];
sequence++;
snprintf (comment, sizeof(comment), "Sequence number %04d", sequence);
/*
* Construct the packet in normal monitoring format.
*/
int messaging = 0;
int compressed = 0;
char info[AX25_MAX_INFO_LEN];
int info_len;
char position_report[AX25_MAX_PACKET_LEN];
// TODO (high, bug): Why do we see !4237.13N/07120.84W=PHG0000... when all values set to unknown.
info_len = encode_position (messaging, compressed,
lat, lon, (int)(DW_METERS_TO_FEET(alt)),
'/', '=',
G_UNKNOWN, G_UNKNOWN, G_UNKNOWN, "", // PHGd
(int)roundf(course), (int)roundf(knots),
445.925, 0, 0,
comment,
info, sizeof(info));
snprintf (position_report, sizeof(position_report), "%s>WALK96:%s", MYCALL, info);
text_color_set (DW_COLOR_XMIT);
dw_printf ("%s\n", position_report);
/*
* Convert it into AX.25 frame.
*/
packet_t pp;
unsigned char ax25_frame[AX25_MAX_PACKET_LEN];
int frame_len;
pp = ax25_from_text (position_report, 1);
if (pp == NULL) {
text_color_set (DW_COLOR_ERROR);
dw_printf ("Unexpected error in ax25_from_text. Quitting.\n");
exit (EXIT_FAILURE); // defined in stdlib.h
}
ax25_frame[0] = 0; // Insert channel before KISS encapsulation.
frame_len = ax25_pack (pp, ax25_frame+1);
ax25_delete (pp);
/*
* Encapsulate as KISS and send to TNC.
*/
unsigned char kiss_frame[AX25_MAX_PACKET_LEN*2];
int kiss_len;
kiss_len = kiss_encapsulate (ax25_frame, frame_len+1, (unsigned char *)kiss_frame);
//text_color_set (DW_COLOR_DEBUG);
//dw_printf ("AX.25 frame length = %d, KISS frame length = %d\n", frame_len, kiss_len);
//kiss_debug_print (1, NULL, kiss_frame, kiss_len);
serial_port_write (tnc, kiss_frame, kiss_len);
}
/* end walk96.c */