#ifndef _MESSAGE_HPP_
#define _MESSAGE_HPP_
#include "zstream.h"

NAMESPACE_POINT_BEGIN(NAMESPACE_POINT)
struct package
{
	zistream m_is;
	int64_t m_recv_time;
	uint16_t m_len;
	uint16_t m_cmd_id;
	uint16_t m_crc;
	package(const void*d,uint64_t recv_time);
};

struct loc_info
{
	int64_t  m_loc_time;//timestamp ms
	uint32_t  m_card_id;//id
	int32_t	 m_tof;     //fly time
	int32_t	 m_card_ct; //ct
	uint16_t m_cmd_id;  //message type
	int8_t   m_card_type;//card_type
	int8_t   m_bat_level;//battery state
	int8_t   m_ant_id; //ant_id
	int16_t  m_rav;   //recv angle
	int16_t  m_acc;   // acc 
	float    m_card_sp;//recv_signal_power
	loc_info(uint32_t cmd_id, uint64_t loc_time,const void*d);
	loc_info()
	{}

	int ant_id()const
	{
		return m_ant_id;
	}

	int ct()const
	{
		return (unsigned)m_card_ct;
	}

//	static loc_info*init(uint64_t loc_time,const void*d,loc_info*b);
};

struct loc_package:package
{
	time_t   m_sit_time;
	uint32_t m_sit_id;
	uint16_t m_sit_ct;
	uint8_t  m_sit_temp;
	uint16_t m_sit_status;
	int16_t  m_card_count;
	const uint8_t *m_card_data;

	loc_package(uint64_t recv_time,const void*data);

	uint32_t id()const
	{
		return m_sit_id;
	}

	int count()const
	{
		return m_card_count;
	}

	int ct()const
	{
		return (uint32_t)m_sit_ct;
	}

	int bytes_per_card()const
	{
		if(m_cmd_id==0x843b)
			return 20;

		if(m_cmd_id==0x753b)
			return 16;

		return 0;
	}

	loc_info get(int index)const;
};
NAMESPACE_POINT_END(NAMESPACE_POINT)
#endif

