#ifndef EXTEN_HEADER_API_H
#define EXTEN_HEADER_API_H

#define IMPL_VER 2

#ifdef __cplusplus
extern "C" {
#endif
#if 0
}
#endif

struct fval {
    float val;
    int   set;
};

/** Position vector contents. Units are either m, m/sec, deg, or deg/sec */
struct xh_navdata {
    struct fval pitch;
    struct fval pitch_rate;
    struct fval roll;      
    struct fval roll_rate;
    struct fval heading;      
    struct fval heading_rate;
    struct fval latitude;
    struct fval longitude;
    struct fval altitude;
    struct fval vel_east;
    struct fval vel_north;
    struct fval vel_up;
};

struct xh_api;
struct xh_monitor;
struct xh_reader;

/** Load plugin by name and return handle */
struct xh_api * xh_init(const char * name);

/** Unload extended header plugin and free associated resources */
void xh_release(struct xh_api * handle);

/** Get extended header size */
size_t xh_get_header_size(struct xh_api * hdl);

/** Get min amount of memory needed to register reader */
size_t xh_get_reader_size(struct xh_api * hdl);

/** Print header content into a text buffer */
int xh_header2text(struct xh_api * hdl,
                   char* txt, uint8_t* buf, size_t txt_len);

/** Extract supported navigational data from the extended header */
int xh_header2navdata(struct xh_api * hdl,
                      struct xh_navdata * nav, uint8_t* buf);

/** Start listener threads
 * \note Only one thread/process is allowed to run monitor.
 */
struct xh_monitor * xh_monitor_start(struct xh_api * hdl);

/** Stop monitor and free its resources. */
int xh_monitor_stop(struct xh_api * hdl, struct xh_monitor * monitor);


/** Register data reader. */
volatile struct xh_reader * xh_register_reader(struct xh_api * hdl,
                                               volatile uint8_t * buf,
                                               size_t max_len);
int xh_unregister_reader(struct xh_api * hdl, volatile struct xh_reader * rdr);
int xh_get_header(struct xh_api * hdl,
                  volatile struct xh_reader * rdr, uint8_t* buf);
int xh_get_navdata(struct xh_api * hdl,
                   volatile struct xh_reader * rdr, struct xh_navdata * nav);

#if 0
{
#endif
#ifdef __cplusplus
}
#endif

#endif /* EXTEN_HEADER_API_H */
