/*
 * Check and Toggle Sensor Replay State.c
 *
 * Gocator Sample
 * Copyright (C) 2011-2019 by LMI Technologies Inc.
 *
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 *
 * Purpose: Connect to Gocator system and modify parameters
 *
 */
#include <GoSdk/GoSdk.h>
#include <stdio.h>

#define SENSOR_IP           "127.0.0.1"                      // serial number of the sensor used for sensor connection GoSystem_FindSensor() call. This is currently set for use with the GoEmulator.exe utility IP address

void main(int argc, char **argv)
{
	kStatus status;
	kAssembly api = kNULL;
	GoSystem system = kNULL;
	GoSensor sensor = kNULL;
	GoSetup setup = kNULL;
	k64f currentExposure;
	k64f newExposure;
	kIpAddress ipAddress;
	GoInputSource inputSource;								//returns GO_INPUT_SOURCE_LIVE or GO_INPUT_SOURCE_RECORDING, values 0 and 1

	// construct Gocator API Library
	if ((status = GoSdk_Construct(&api)) != kOK)
	{
		printf("Error: GoSdk_Construct:%d\n", status);
		return;
	}

	// construct GoSystem object
	if ((status = GoSystem_Construct(&system, kNULL)) != kOK)
	{
		printf("Error: GoSystem_Construct:%d\n", status);
		return;
	}

	// Parse IP address into address data structure
	kIpAddress_Parse(&ipAddress, SENSOR_IP);

	// obtain GoSensor object by IP address
	if ((status = GoSystem_FindSensorByIpAddress(system, &ipAddress, &sensor)) != kOK)
	{
		printf("Error: GoSystem_FindSensor:%d\n", status);
		return;
	}

	// create connection to GoSensor object
	if ((status = GoSensor_Connect(sensor)) != kOK)
	{
		printf("Error: GoSensor_Connect:%d\n", status);
		return;
	}
	
	//	Read Input Source
	//retrive current input source and display
	inputSource = GoSensor_InputSource(sensor);

	//Display current input source
	if (inputSource == 0)
	{
		printf("Current input source is GO_INPUT_SOURCE_LIVE\n");
	}
	else
	{
		printf("Current input source is GO_INPUT_SOURCE_RECORDING\n");
	}

	//	Write Input Source
	//inputSource = GO_INPUT_SOURCE_LIVE;			//select which state you would like to put the sensor in; the default here is the place the sensor in REPLAY mode
	inputSource = GO_INPUT_SOURCE_RECORDING;

	// set sensor input source
	if ((status = GoSensor_SetInputSource(sensor, inputSource)) != kOK)
	{
		printf("Error: GoSensor_SetInputSource:%d\n", status);
		return;
	}
	
	//Display new input source
	if (inputSource == GO_INPUT_SOURCE_LIVE)
	{
		printf("Input source has been set to GO_INPUT_SOURCE_LIVE\n");
	}
	else if (inputSource == GO_INPUT_SOURCE_RECORDING)
	{
		printf("Input source has been set to GO_INPUT_SOURCE_RECORDING\n");
	}
	

	// flush the new sensor configuration
	if ((status = GoSensor_Flush(sensor)) != kOK)
	{
		printf("Error: GoSensor_Flush:%d\n", status);
		return;
	}
	

	// destroy handles
	GoDestroy(system);
	GoDestroy(api);

	printf("Press any key to continue...\n");
	getchar();

	return;
}
