
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"
#include "nrf_uart.h"
#include "UartProcess.h"
#include "EsbProcess.h"
#include "Node.h"
#include "app_timer.h"

#define MAX_TEST_DATA_BYTES     (15U)                /**< max number of test bytes to be used for tx and rx. */
APP_TIMER_DEF(m_RxPacketProcess_timer_id);                                  /**< Battery timer. */
#define	RxPacketProcess_INTERVAL		APP_TIMER_TICKS(2000)                   /**< Battery level measurement interval (ticks). */

static void RxPacketProcess_timeout_handler(void * p_context)
{
	UNUSED_PARAMETER(p_context);  
	printf("(0001)\r\n");
}

void TimerTaskInit(void)
{
	uint32_t		err_code;

    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

	err_code = app_timer_create(&m_RxPacketProcess_timer_id, APP_TIMER_MODE_REPEATED, RxPacketProcess_timeout_handler);
	APP_ERROR_CHECK(err_code);

	err_code = app_timer_start(m_RxPacketProcess_timer_id, RxPacketProcess_INTERVAL, NULL);
	APP_ERROR_CHECK(err_code);
}

void clocks_start( void )
{
    // Start HFCLK and wait for it to start.
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
}

/**
 * @brief Function for main application entry.
 */
int main(void)
{
    //	uint32_t err_code;

    bsp_board_init(BSP_INIT_LEDS);
    clocks_start();
    UART_Init();
    TimerTaskInit();
    esb_init();

	printf(" ... UART Test ...\r\n");

	my_tx_payload.noack = false;
    while (true)
    {
    	my_tx_payload.data[0]++;
    	gEsbModeStatus = 0;
    	printf(" Send: %.2X\r\n", my_tx_payload.data[0]);
    	nrf_esb_write_payload(&my_tx_payload);
    	nrf_delay_ms(1000);
    }
}


/** @} */
