#include "poll_modbus.h"


int process_data_print(size_t sz, struct proc_data_t *proc_data, struct timespec *timeout) {
  size_t ix;
  size_t kx;
  size_t bsz = 0;

  (void) timeout;
  LOG_IF(!proc_data || !sz, LOG_ERR) return -1;

  for (ix = 0; ix < sz; ++ix) bsz += proc_data[ix].quantity;

  bsz *= 6; /* each value is 6 chars, e.g. " 65535" */
  bsz += 18+4; /* timespec + raw%d, assuming sz < 10000 */
  bsz += 1+1; /* newline and '\0' */

  {
    char buf[bsz];
    struct buf_t bd = { (uint8_t *) buf, bsz, 0, 0 };

    for (ix = 0; ix < sz; ++ix) {
      buf_printf(&bd, "%9ld.%02ld raw%d: ", timespec_current.tv_sec, timespec_current.tv_nsec/10000000, ix);
      for (kx = 0; kx < proc_data[ix].quantity; ++kx) {
	buf_printf(&bd, " %hd", proc_data[ix].data[kx]);
      }
      buf_printf(&bd, "\n");
      log_puts(buf);
      buf_flush(&bd);
    }
  }
  
  return 0;
}
