1 /*---------------------------------------------------------------------------*\
2 
3   FILE........: freedv_data_channel.h
4   AUTHOR......: Jeroen Vreeken
5   DATE CREATED: 03 March 2016
6 
7   Data channel for ethernet like packets in freedv VHF frames.
8   Currently designed for-
9   * 2 control bits per frame
10   * 4 byte counter bits per frame
11   * 64 bits of data per frame
12 \*---------------------------------------------------------------------------*/
13 
14 /*
15   Copyright (C) 2016 Jeroen Vreeken
16 
17   All rights reserved.
18 
19   This program is free software; you can redistribute it and/or modify
20   it under the terms of the GNU Lesser General Public License version 2.1, as
21   published by the Free Software Foundation.  This program is
22   distributed in the hope that it will be useful, but WITHOUT ANY
23   WARRANTY; without even the implied warranty of MERCHANTABILITY or
24   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
25   License for more details.
26 
27   You should have received a copy of the GNU Lesser General Public License
28   along with this program; if not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 #ifndef _FREEDV_DATA_CHANNEL_H
32 #define _FREEDV_DATA_CHANNEL_H
33 
34 #include <stdlib.h>
35 
36 #define FREEDV_DATA_CHANNEL_PACKET_MAX 2048
37 
38 typedef void (*freedv_data_callback_rx)(void *, unsigned char *packet, size_t size);
39 typedef void (*freedv_data_callback_tx)(void *, unsigned char *packet, size_t *size);
40 
41 struct freedv_data_channel {
42     freedv_data_callback_rx cb_rx;
43     void *cb_rx_state;
44      freedv_data_callback_tx cb_tx;
45     void *cb_tx_state;
46 
47     unsigned char rx_header[8];
48     unsigned char packet_rx[FREEDV_DATA_CHANNEL_PACKET_MAX + 2];
49     int packet_rx_cnt;
50 
51     unsigned char tx_header[8];
52     unsigned char packet_tx[FREEDV_DATA_CHANNEL_PACKET_MAX + 2];
53     int packet_tx_cnt;
54     size_t packet_tx_size;
55 };
56 
57 
58 struct freedv_data_channel *freedv_data_channel_create(void);
59 void freedv_data_channel_destroy(struct freedv_data_channel *fdc);
60 
61 void freedv_data_set_cb_rx(struct freedv_data_channel *fdc, freedv_data_callback_rx cb, void *state);
62 void freedv_data_set_cb_tx(struct freedv_data_channel *fdc, freedv_data_callback_tx cb, void *state);
63 
64 void freedv_data_channel_rx_frame(struct freedv_data_channel *fdc, unsigned char *data, size_t size, int from_bit, int bcast_bit, int crc_bit, int end_bits);
65 void freedv_data_channel_tx_frame(struct freedv_data_channel *fdc, unsigned char *data, size_t size, int *from_bit, int *bcast_bit, int *crc_bit, int *end_bits);
66 
67 void freedv_data_set_header(struct freedv_data_channel *fdc, unsigned char *header);
68 int freedv_data_get_n_tx_frames(struct freedv_data_channel *fdc, size_t size);
69 
70 #endif /* _FREEDV_DATA_CHANNEL_H */
71