4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 * \author Francesco Sacchi <batt@develer.com>
34 * \author Luca Ottaviano <lottaviano@develer.com>
35 * \author Daniele Basile <asterix@develer.com>
37 * \brief Arduino APRS radio demo.
39 * This example shows how to read and decode APRS radio packets.
40 * It uses the following modules:
45 * You will see how to use a serial port to output messages, init the afsk demodulator and
46 * how to parse input messages using ax25 module.
50 #include <cfg/debug.h>
56 #include <drv/timer.h>
68 * Print on console the message that we have received.
70 static void message_callback(struct AX25Msg *msg)
72 kfile_printf(&ser.fd, "\n\nSRC[%.6s-%d], DST[%.6s-%d]\r\n", msg->src.call, msg->src.ssid, msg->dst.call, msg->dst.ssid);
74 for (int i = 0; i < msg->rpt_cnt; i++)
75 kfile_printf(&ser.fd, "via: [%.6s-%d]\r\n", msg->rpt_lst[i].call, msg->rpt_lst[i].ssid);
77 kfile_printf(&ser.fd, "DATA: %.*s\r\n", msg->len, msg->info);
80 static void init(void)
87 * Init afsk demodulator. We need to implement the macros defined in hw_afsk.h, which
88 * is the hardware abstraction layer.
89 * We do not need transmission for now, so we set transmission DAC channel to 0.
91 afsk_init(&afsk, ADC_CH, 0);
93 * Here we initialize AX25 context, the channel (KFile) we are going to read messages
94 * from and the callback that will be called on incoming messages.
96 ax25_init(&ax25, &afsk.fd, message_callback);
98 /* Initialize serial port, we are going to use it to show APRS messages*/
99 ser_init(&ser, SER_UART0);
100 ser_setbaudrate(&ser, 115200L);
103 static AX25Call path[] = AX25_PATH(AX25_CALL("apzbrt", 0), AX25_CALL("nocall", 0), AX25_CALL("wide1", 1), AX25_CALL("wide2", 2));
105 #define APRS_MSG ">Test BeRTOS APRS http://www.bertos.org"
110 ticks_t start = timer_clock();
115 * This function will look for new messages from the AFSK channel.
116 * It will call the message_callback() function when a new message is received.
117 * If there's nothing to do, this function will call cpu_relax()
122 /* Send out message every 15sec */
123 if (timer_clock() - start > ms_to_ticks(15000L))
125 start = timer_clock();
126 ax25_sendVia(&ax25, path, countof(path), APRS_MSG, sizeof(APRS_MSG));