#include "Arduino.h"
#include "mrf24j40.h"
#include "protocol.h"
#include "extra-protocol.h"

#include <SPI/SPI.h>
#include "assert.h"

#define VERSION "v0.3"

void frame_cb(unsigned char *frame, unsigned int size)
{
  info_printf("Received a frame of size %d\n", size);
  send_control(PROT_CTYPE_OK, NULL, 0);
  delay(100);
  send_control(PROT_CTYPE_ACK, NULL, 0);
}

void control_cb(enum prot_ctype, unsigned char *data, unsigned int size)
{
  info_printf("Received a control of size %d\n", size);
}

void send(const unsigned char *data, unsigned int size)
{
  Serial.write(data, size);
}

void setup(void)
{
  /* setup UART */
  Serial.begin(115200);

  protocol_init(frame_cb,
                control_cb,
                send);

  send_info("Basic Firmware " VERSION "\n");
}

void serialEvent()
{
  input_step((unsigned char)Serial.read());
}

void loop()
{
  /* doing nothing */
}
