/*
 * mainloop.h
 *
 *  Created on: Sep 11, 2019
 *      Author: abody
 */

#ifndef MAINLOOP_H_
#define MAINLOOP_H_

#if defined(__cplusplus)
extern "C" {
#endif

void AppInit();

#if defined(__cplusplus)
}
#endif

#if defined(__cplusplus)
#include <f4ll_cpp/serialconsole.h>
#include <fsl/task.h>
#include "../Application/globals.h"

struct GlobalsInitializer {
	GlobalsInitializer(f4ll_cpp::SerialConsole<257> *console) {
		g_console = console;
	}
};

#define APPLICATION_STACK_SIZE 16384

class Application 	: public GlobalsInitializer
					, public f4ll_cpp::SerialConsole<257>::ISerialConsoleCallback
					, public fsl::Task<Application, APPLICATION_STACK_SIZE>
{
public:
	Application();
    void Loop();

	friend class fsl::Task<Application, APPLICATION_STACK_SIZE>;
private:

	virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
	virtual void TransmissionComplete(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
	virtual char const * getName() { return "Application"; }

	f4ll_cpp::SerialConsole<257>	m_console;
	volatile bool m_lineReceived = false;
	volatile f4ll_cpp::SerialConsole<257>::Buffer *m_rcvdBuffer;
	char m_appBuffer[128];

	volatile bool m_transmissionCompleted = true;
};
#endif	//	__cplusplus


#endif /* MAINLOOP_H_ */
