/*
 *
 * Copyright (c) Vaisala Group 2009. All rights reserved.
 *
 * The terms "Vaisala" and "Vaisala Group" are defined as
 * "Vaisala Oyj and all its subsidiaries".
 *
 */

/** @file nav_system.h
 *  API to handle data from the navigational or geopositioning systems.
 */

#ifndef NAVIGATIONAL_SYSTEM_H
#define NAVIGATIONAL_SYSTEM_H

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup gr_nav_system Navigational Systems Support
 
 *  @ingroup gr_sigmet
 *  @{
 */

/** Supported platform types. */
enum platform_type {
    PLT_FIXED,  /**< Normal ground based location   */
    PLT_MOVING, /**< Moving platphorm: ship, plane  */
    PLT_COUNT   /**< Number of known platform types */
};

/** Orientation of the radar main axis of rotation and azimuth offset */
struct radar_orientation {
    double zenith;  /**< theta in ISO 31-11. */
    double azimuth; /**< phi in ISO 31-11 (if x axis is heading direction ) */
};

/** Fixed platform location */
struct fixed_platform {
    double latitude;  /**< [rad] */
    double longitude; /**< [rad] */
    double tower_height;    /**< Height of radar(tower) above ground [m] */
    double radar_altitude;  /**< Altitude of radar above see level [m] */
};

/** Moving platform location */
struct moving_platform {
    double latitude;       /**< [rad]     */
    double longitude;      /**< [rad]     */
    double altitude;       /**< The altitude over see level [m] */
    double velocity_east;  /**< [m/sec]   */
    double velocity_north; /**< [m/sec]   */
    double velocity_up;    /**< [m/sec]   */
    double pitch;          /**< [rad]     */
    double roll;           /**< [rad]     */
    double heading;        /**< [rad]     */
    double pitch_rate;     /**< [rad/sec] */
    double roll_rate;      /**< [rad/sec] */
    double heading_rate;   /**< [rad/sec] */
    struct timeval aq_time; /**< Time of the last update */
    struct config_set * extra_data; /**< Additional data, default NULL */
};

struct radar_position;

struct radar_position * rposition_new_fixed(const struct fixed_platform * pos);
struct radar_position * rposition_new_moving(void);

struct radar_orientation rposition_get_orientation(struct radar_position * pos);
enum platform_type rposition_get_type(struct radar_position * pos);

const struct fixed_platform * rposition_get_fixed(struct radar_position * pos,
                                                  struct fixed_platform * buf);

const struct moving_platform * rposition_get_nav(struct radar_position * pos,
                                                 int index,
                                                 struct moving_platform * buf);

/* Long term :TODO: add platform to earth conversion functions  */

/** aquire reference */ 
struct radar_position * rposition_ref(struct radar_position * pos);

/** Drop reference, pos will be freed if it was the last reference  */
void rposition_unref(struct radar_position * pos);

/** @}  gr_nav_system */

#ifdef __cplusplus
}
#endif
#endif /* NAVIGATIONAL_SYSTEM_H */
