/*
 * Copyright (C) 2009, 2010 by Nicole Faerber <nicole.faerber@dpin.de>
 *
 * 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.
 *
 */

#define RDS_RECEIVE_INDICATOR	1 << 0
#define RDS_OUTPUT_STATION_ID	1 << 1
#define RDS_OUTPUT_RADIO_TEXT	1 << 2
#define RDS_OUTPUT_TMC		1 << 3
#define RDS_OUTPUT_DATETIME	1 << 4
#define RDS_OUTPUT_RDSINFO	1 << 5
#define RDS_OUTPUT_EON		1 << 6
#define RDS_OUTPUT_UNKNGRP	1 << 7

extern int OutputFlags;

/* defined in rds_consts.h */
extern const char *PTY_text[];
extern const char *ECC_text[];
extern const char *ptype_stext[];
extern const char *ptype_ltext[];

struct rds_info_s {
	struct tm dtime;
	char sname[9];
	char rtext[65];
	unsigned short AID;
	char LTN; /* location table number */
	unsigned char AFI;
	unsigned char M;
	unsigned char I;
	unsigned char N;
	unsigned char R;
	unsigned char U;
	unsigned char G;
	unsigned char SID;
	unsigned char Ta;
	unsigned char Tw;
	unsigned char Td;
	unsigned char PTY;
	unsigned char TPTN;
	unsigned char TPON;
	unsigned char PS[9];
	unsigned short PI;
	unsigned char ccode, ptype, pref;
	unsigned char ECC;
	unsigned char lang_code;
	unsigned char MS;
	unsigned char TP;
	unsigned char TA;
};

int rds_receive_group(int rds_fd, unsigned short *rdsgroup);
void rds_radio_retuned(void);
void rds_decode_group(unsigned short *rdsgroup);

void rds_init(void);

/* with every group but only once reported when PI changes */
void rds_set_PI_cb(void (*rds_PI_cb)(unsigned short PI, unsigned char ccode, unsigned char ptype, unsigned char pref, void *user_data), void *user_data);

/* group 0A */
void rds_set_sname_cb(void (*rds_sname_cb)(char *sname, void *user_data), void *user_data);
void rds_set_sinfo_cb(void (*rds_sinfo_cb)(unsigned char TP, unsigned char TA, unsigned char MS, unsigned char PTY, void *user_data), void *user_data);
void rds_set_afinfo_cb(void (*rds_afinfo_cb)(unsigned char cnt, double *AF, void *user_data), void *user_data);
/* group 2A/B */
void rds_set_radiotext_cb(void (*rds_radiotext_cb)(char *radio_text, void *user_data), void *user_data);
/* group 3A */

/* group 4A */
void rds_set_date_time_cb(void (*rds_date_time_cb)(struct tm *rds_time, void *user_data), void *user_data);


