/**
 * @file
 * @version     1.0.0
 *
 * \cond HIDDEN_SYMBOLS
 *
 * Copyright (c) 2013
 * VoXel Interaction Design GmbH
 *
 * @author VoXel Interaction Design <office@voxel.at>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * \endcond
 * @section DESCRIPTION
 *
 * Example application for the sentis-ToF-m100 camera API
 *
 * This application shows how to connect to the camera with
 * the default network values and how to read the registers.
 *
 * It reads all the status registers of the camera and prints
 * the values in the console.
 *
 */

#include <stdlib.h>
#include <stdio.h> // printf
#include <m100api.h>

int main (int argc, char *argv[]) {
	T_SENTIS_CONFIG config;
	T_SENTIS_HANDLE handle;
	T_ERROR_CODE error;

	config.tcp_ip = "192.168.0.10"; 
	config.udp_ip = "224.0.0.1";
	config.udp_port = 10002;
	config.tcp_port = 10001;
	config.flags = HOLD_CONTROL_ALIVE;
	
	
	/*int i;
	for (i = 0;i<5; i++) {*/

	printf("CLIENT: open connection\n");
	handle = STSopen(&config,&error);

	if (error != 0) {
		printf("Not possible to open the connection. Error: %d\n", error);
		exit(1);
	}

	unsigned short res;

	error = STSreadRegister(handle, Mode0, &res, 0, 0);
	printf("Mode0: %#X\n", res);
	
	//Sleep(1);
	error = STSreadRegister(handle, Status, &res, 0, 0);
	printf("Status: %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, ImageDataFormat, &res, 0, 0);
	printf("ImageDataFormat: %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, IntegrationTime, &res, 0, 0);
	printf("IntegrationTime: %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, DeviceType, &res, 0, 0);
	printf("DeviceType: %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, DeviceInfo, &res, 0, 0);
	printf("DeviceInfo: %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, FirmwareInfo, &res, 0, 0);
	printf("FirmwareInfo: %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, ModulationFrecuency, &res, 0, 0);
	printf("ModulationFrecuency: %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, FrameRate, &res, 0, 0);
	printf("FrameRate %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, HardwareConfiguration, &res, 0, 0);
	printf("HardwareConfiguration %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, SerialNumberLowWord, &res, 0, 0);
	printf("SerialNumberLowWord %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, SerialNumberHighWord, &res, 0, 0);
	printf("SerialNumberHighWord %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, FrameCounter, &res, 0, 0);
	printf("FrameCounter %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, ConfidenceThresLow, &res, 0, 0);
	printf("ConfidenceThresLow %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, ConfidenceThresHig, &res, 0, 0);
	printf("ConfidenceThresHig %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, Mode1, &res, 0, 0);
	printf("Mode1 %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, CalculationTime, &res, 0, 0);
	printf("CalculationTime %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, LedboarsTemp, &res, 0, 0);
	printf("LedboarsTemp %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, MainboardTemp, &res, 0, 0);
	printf("MainboardTemp %#X\n", res);
	
	//sleep(1);
	error = STSreadRegister(handle, LinearizationAmplitude, &res, 0, 0);
	printf("LinearizationAmplitude %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, LinearizationPhasseShift, &res, 0, 0);
	printf("LinearizationPhasseShift %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, MaxLedTemp, &res, 0, 0);
	printf("MaxLedTemp %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, HorizontalFov, &res, 0, 0);
	printf("HorizontalFov %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, VerticalFov, &res, 0, 0);
	printf("VerticalFov %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, TriggerDelay, &res, 0, 0);
	printf("TriggerDelay %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, BootloaderStatus, &res, 0, 0);
	printf("BootloaderStatus %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, TemperatureCompensationGradient, &res, 0, 0);
	printf("TemperatureCompensationGradient %#X\n", res);

	//sleep(1);
	error = STSreadRegister(handle, ApplicationVersion, &res, 0, 0);
	printf("ApplicationVersion %#X\n", res);
	
	printf("CLIENT: Close connection\n");
	error = STSclose(handle);

	//}

	return 1;
}

