#include <stdio.h>
#include <stdint.h>
#include <aspoutil.h>

#include "feig.h"
LOG_BUFFER(200)
/*
  All section and page referenses are for H20800-18e-ID-B.pdf,
  ask a Feig represenative for the file.
*/

#define BUFSZ 255
const size_t bufsize = BUFSZ;
uint8_t buf[BUFSZ];

static void Usage(void) {
  printf("Usage:\n"
         "\tTest... [adr] [cmd] [data...]\n"
         );
  exit(1);
}

int main(int argc, char *argv[]) {
  int ix;
  uint8_t com_adr;
  uint8_t cmd;
  uint8_t *data;
  uint16_t data_len;

  log_open(NULL, LOG_PRIO | 2, 0);
  if (argc < 3) Usage();
  argc--;
  argv++;

  ix = feig_strcmd(buf, bufsize, argc, argv);
  if (ix < 0) return 1;

  feig_prtpkg(NULL, buf, ix);
  feig_verify_pkg(buf, BUFSZ, &com_adr, &cmd, &data, &data_len);
  printf("adr cmd data_len, data: %02x %02x %d,", com_adr, cmd, data_len);
  for (ix = 0; ix < data_len; ++ix) printf(" %02x", data[ix]);
  printf("\n");

  return 0;
}
