/*
 * Copyright (c) 2018, Suprock Technologies
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdlib.h>

#include "snprintf.h" // for msvc++ compatability

#include "asphodel.h"
#include "version_autogen.h"


static char protocol_version_string[10] = "\0";


// Return the protocol version supported by this device in BCD form (e.g. 0x0200).
ASPHODEL_API uint16_t asphodel_get_library_protocol_version(void)
{
	return ((ASPHODEL_PROTOCOL_VERSION_MAJOR & 0xFF) << 8) |
			((ASPHODEL_PROTOCOL_VERSION_MINOR & 0x0F) << 4) |
			(ASPHODEL_PROTOCOL_VERSION_SUBMINOR & 0x0F);
}

// Return the protocol version supported by this device in string form (e.g. "2.0.0").
ASPHODEL_API const char * asphodel_get_library_protocol_version_string(void)
{
	if (protocol_version_string[0] == '\0')
	{
		// need to fill protocol_version_string
		snprintf(protocol_version_string, sizeof(protocol_version_string), "%d.%d.%d",
				ASPHODEL_PROTOCOL_VERSION_MAJOR & 0xFF,
				ASPHODEL_PROTOCOL_VERSION_MINOR & 0x0F,
				ASPHODEL_PROTOCOL_VERSION_SUBMINOR & 0x0F);
	}

	return protocol_version_string;
}

// Return the library's build info string.
ASPHODEL_API const char * asphodel_get_library_build_info(void)
{
	return BUILD_INFO_STR;
}

// Return the library's build date as a string.
ASPHODEL_API const char * asphodel_get_library_build_date(void)
{
	return BUILD_DATE_STR;
}
