/*
 * grifo_version.h
 *
 */

#ifndef GRIFO_VERSION_H_
#define GRIFO_VERSION_H_

#include <stdint.h>

class GrifoVersion
{
public:
	struct fw_info_record_t
	{
	    struct vinfo_t
	    {
			uint32_t id[2];
			union {
				uint16_t w16[2];
				uint32_t w32;
			} rel;
			uint32_t build;
	    };

		struct fpga_uc_info_t
		{
	    	vinfo_t vinfo;

			uint32_t slot_address;
			uint32_t spare[3];

			uint32_t supply_status[3];
			uint32_t temperature_status[1];

			int8_t temperature_value[8];
		};

		struct fpga_fw_info_t
		{
	    	vinfo_t vinfo;

			uint32_t lock_link;
			uint32_t lock_link_latched;

			uint32_t cbit_result;
			uint32_t cbit_result_latched;

			uint32_t detector_status;
			uint32_t detector_presence;
		};

		struct fpga_info_t
		{
			fpga_uc_info_t uc_info;

			uint8_t spare_uc[(32*4)-(sizeof(fpga_uc_info_t))];

			fpga_fw_info_t fw_info;

			uint8_t spare_fw[(32*4)-(sizeof(fpga_fw_info_t))];
		};
	};

	static void addEmbeddedFwItem(const char* lru, const char* sru, unsigned int majorId, unsigned int minorId, const void* address_override=0);

	static void addItemUc(const char* lru, const char* sru, const char* sub, unsigned int majorId, unsigned int minorId, unsigned sliceId, const fw_info_record_t::vinfo_t& vinfo);
	static void addItemFpga(const char* lru, const char* sru, const char* sub, unsigned int majorId, unsigned int minorId, unsigned sliceId, const fw_info_record_t::vinfo_t& vinfo);
	static void addItemPl(const char* lru, const char* sru, const char* sub, unsigned int majorId, unsigned int minorId, unsigned sliceId, const fw_info_record_t::vinfo_t& vinfo);

	static void addItem(const char* lru, const char* sru, const char* sub, unsigned int majorId, unsigned int minorId, unsigned sliceId, const char* itemId, const char* itemVersion, const char* itemBuild=0, const char* itemChecksum=0, const char* fullinfo=0);

	static const char* getFormattedVersionInfo(unsigned int& size);

	struct minimal_info_t
	{
		char ver[8];
		char fpga[2][8];
		unsigned int spare;
	};

	static bool getMinimalVersionInfo(unsigned int vid, minimal_info_t* info);
};


#endif /* GRIFO_VERSION_H_ */
