/*
 * SimpleTgtSimInfo.h
 *
 */

#ifndef SIMPLETGTSIMINFO_H_
#define SIMPLETGTSIMINFO_H_


class SimpleTgtSimInfo
{
public:
    enum { k_max_tgt=16};

    unsigned int enabled;
    unsigned int features;
    unsigned int sim_mp_hint;

    int tgt_move;

    int single_det_hint;

    float az_width;
    float el_width;

    struct tgt_t
    {
        unsigned int enabled;
        unsigned int features;
        int not_traceable;
        int auto_restart;
        unsigned int unique_id;
        int ext[8];	//reserved for higher level controller

        int restarted;

        float heading;

        float az_start;
        float el_start;
        float heading_start;
        float rng_start_meters;
        float speed_start;
        float altitude_start;
        int altitude_invalid;

        float az;
        float az_width; /*match for (az-az_with)<nav_az<(az+az_with)*/
        float el;
        float el_width;
        unsigned int batch_span; /*if >0, keep target valid for exactly batch_span calls to lookup*/
        float rng_start;	//usec, name not change for compatibility
        float rng_meters;	//if rng_start==0, then use rng_meters
        float rng_len;
        float rng_rate;
        float speed;
        float amplitude;
        float sdr;
        float altitude;

        float ground_range;
        float ground_velocity;

        float incomplete;
        float coast_time;
        int type;

        //Calculated data
        bool just_seen;
        float range;		//the calculate range in meters
        float range_delta;
        float range_rate;
        unsigned int id;
        int already_seen;
        unsigned int hit;
        int batch_hit;

        float x;
        float y;
        float z;
        float vx;
        float vy;
    };

    tgt_t t[k_max_tgt];

    static SimpleTgtSimInfo& instance();

    tgt_t* lookup(float az, float el);

    tgt_t* lookupNext(float az, float el, tgt_t* previous);

    void tracksUpdate(float delta_time, bool force_restart=false);

    void resetScan();

    void setLookupMode(int mode); //0=normal A/A, 1=A/S, -1=RBM

    tgt_t* lookupExt(float az, float el, float ac_altitude);
    tgt_t* lookupNextExt(float az, float el, float ac_altitude, tgt_t* previous);
    void tracksUpdateExt(float delta_time, float ac_altitude, bool force_restart=false);

public: //private:
    //Do not touch - calculated
    float tgt_start_us;
    float tgt_len_us;
    unsigned int tgt_amplitude;
    unsigned int tgt_sdr;
    unsigned int hit;
    int tgt_index;

    int lookup_mode;

    int space_invaders;

public:
    SimpleTgtSimInfo();
    SimpleTgtSimInfo(const SimpleTgtSimInfo&);
    void operator=(const SimpleTgtSimInfo&);

private:
    tgt_t* lookupN(float az, float el, int start_index=0);

    tgt_t* lookupExtN(float az, float el, float ac_latitude, int start_index=0);

};


#endif /* SIMPLETGTSIMINFO_H_ */
