// lcm-test1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include <chrono>
#include <lcm/lcm-cpp.hpp>
#include "total_focus_image.hpp"
#include "recorder_status.hpp"


#include <chrono>
#include <thread>

int main()
{
	std::cout << "lcm-test1\n";
	lcm::LCM lcm;
	time_t ltime;

	unsigned char* testImage;

	if (!lcm.good())
		return 1;

	exlcm::recorder_status recStat;
	exlcm::total_focus_image totalFocusImage;

	int counter = 0;
	int frameCount = 0;
	int zigCounter = 60;
	time(&ltime);
	long long lastTime = ltime;
	while (!_kbhit()) {

		time(&ltime);

		recStat.estimatedFPS = 20;
		recStat.exposureTime = 0.5;
		recStat.frameQueueSize = 1;
		recStat.procQueueSize = 3;
		recStat.writeQueueSize = 2;
		recStat.gain = 0.0;
		recStat.recordedFrames = counter;
		recStat.timestamp = (long long)ltime;
		recStat.recording = 1;
		recStat.cameraConnected = 1;
		recStat.processorMode = 10;

		if (lastTime != ltime) {

			std::cout << recStat.timestamp << " frame rate: " << frameCount  << std::endl;
			frameCount = 0;
			lastTime = ltime;
		}

		lcm.publish("RECSTAT", &recStat);

		using namespace std::chrono;
		totalFocusImage.timestamp = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
		totalFocusImage.width = 2560/2;
		totalFocusImage.height = 2560/2;
		totalFocusImage.dataType = 1;
		totalFocusImage.dataSize = totalFocusImage.width * totalFocusImage.height;
		totalFocusImage.pixelType = 1;


		std::vector<uint8_t> testImage(totalFocusImage.width * totalFocusImage.height);

		for (int i = 0; i < totalFocusImage.dataSize; i++) {
			testImage[i] = 0;
			if ((i % zigCounter) == 0)
				testImage[i] = 255;
		}

		zigCounter += 1;

		totalFocusImage.data = testImage;

		lcm.publish("TFIMAGE", &totalFocusImage);
		frameCount++;

		std::this_thread::sleep_for(std::chrono::milliseconds(2));



	}


}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
