#include "ipio.h"
#include <aspoutil.h>

volatile sig_atomic_t g_sig;

#define LOG_BUFSZ 200
const size_t log_bufsz = LOG_BUFSZ;
char log_buffer[LOG_BUFSZ];

#define OLEN 4
#define ILEN 10

void Usage(void);
void Usage(void) {
  exit(1);
}

int main(int argc, char *argv[]) {
  int fd = 0;
  struct sockaddr_in endpoint;
  struct timeval tv = { 0, 100 * 1000 };
  int id = 0;
  uint8_t obuf[OLEN] = { IPIOMOD_DAC_WRITE, 0, 3, 0 };
  uint8_t ibuf[ILEN];

  if (argc != 4) Usage();

  (void) cmdline_extrpgm(argv);
  log_open(NULL, LOG_PRIO | 2, 0);
  setlogmask(LOG_UPTO(LOG_DEBUG));
  LOG_IF( ipio_open(&fd, &endpoint, NULL, 0) < 0, LOG_CRIT) return -1;

  obuf[0] = strtoul(argv[1],NULL,0);
  obuf[1] = ++id;
  obuf[2] = strtoul(argv[2],NULL,0);
  obuf[3] = strtoul(argv[3],NULL,0);
  (void) ipio_exec(fd, &endpoint, obuf, OLEN, ibuf, ILEN, &tv);

  return 0;
}
