static int on_card(const uint16_t* data, m600_alarms_t alarms, void* ctx) { /* called for each read card data the card column data */ unsigned int i; /* unused */ ctx = ctx; if (alarms) { print_alarms(alarms); /* stop reading */ return -1; } for (i = 0; i < M600_COLUMN_COUNT; ++i, ++data) { if (!(i % 10)) { if (i) printf("\n"); printf("[%02x]: ", i); } printf(" %03x", *data); } printf("\n"); /* continue reading */ return 0; }
static void print_limits(struct sensor_subfeature_data *limits, int limit_count, struct sensor_subfeature_data *alarms, int alarm_count, int label_size, const char *fmt) { int i, slot, skip; int alarms_printed = 0; /* * We print limits on two columns, filling lines first, except for * hysteresis which must always go on the right column, with the * limit it relates to being in the left column on the same line. */ for (i = slot = 0; i < limit_count; i++, slot++) { if (!(slot & 1)) { if (slot) printf("\n%*s", label_size + 10, ""); printf("("); } else { printf(", "); } printf(fmt, limits[i].name, limits[i].value, limits[i].unit); /* If needed, skip one slot to avoid hyst on first column */ skip = i + 2 < limit_count && limits[i + 2].name == hyst_str && !(slot & 1); if (((slot + skip) & 1) || i == limit_count - 1) { printf(")"); if (alarm_count && !alarms_printed) { print_alarms(alarms, alarm_count, (slot & 1) ? 0 : 16); alarms_printed = 1; } } slot += skip; } if (alarm_count && !alarms_printed) print_alarms(alarms, alarm_count, 32); }
int main(int ac, char** av) { m600_handle_t* handle = NULL; int error = -1; uint16_t data[M600_COLUMN_COUNT]; if (ac == 1) { print_usage(av[0]); goto on_error; } if (m600_initialize() != M600_ERROR_SUCCESS) goto on_error; if (m600_open(&handle) != M600_ERROR_SUCCESS) goto on_error; if (!strcmp(av[1], "read_card")) { unsigned int count = 1; if (ac >= 3) count = atoi(av[2]); if (m600_read_cards(handle, count, on_card, NULL) != M600_ERROR_SUCCESS) goto on_error; } else if (!strcmp(av[1], "read_alarms")) { m600_alarms_t alarms; if (m600_read_alarms(handle, &alarms) != M600_ERROR_SUCCESS) goto on_error; print_alarms(alarms); } else if (!strcmp(av[1], "fill_data")) { clear_buffer(data); if (m600_fill_data(handle, data) != M600_ERROR_SUCCESS) goto on_error; if (check_buffer(data)) printf("invalidBuffer\n"); else printf("bufferOk\n"); } else if (!strcmp(av[1], "read_pins")) { clear_buffer(data); if (m600_read_pins(handle, (uint8_t*)data) != M600_ERROR_SUCCESS) goto on_error; print_pins((const uint8_t*)data); } else { print_usage(av[0]); goto on_error; } error = 0; on_error: if (handle != NULL) m600_close(handle); m600_cleanup(); return error; }