39 #include <px4_platform_common/px4_config.h> 40 #include <px4_platform_common/defines.h> 42 #include <sys/types.h> 61 PX4_ERR(
"can't open ADC device");
69 ssize_t count =
read(fd, data,
sizeof(data));
73 PX4_ERR(
"can't read from ADC driver. Forgot 'adc start' command?");
77 unsigned channels = count /
sizeof(data[0]);
79 for (
unsigned j = 0; j < channels; j++) {
80 printf(
"%d: %u ", data[j].am_channel, data[j].am_data);
85 PX4_INFO(
"\t ADC operational.\n");
88 int16_t expected_min[] = {2800, 2800, 1800, 800};
89 int16_t expected_max[] = {3100, 3100, 2100, 1100};
90 char *check_res[channels];
94 PX4_ERR(
"not all four test channels available, aborting.");
99 check_res[0] = (expected_min[0] < data[0].am_data && expected_max[0] > data[0].am_data) ?
"OK" :
"FAIL";
100 check_res[1] = (expected_min[1] < data[1].am_data && expected_max[1] > data[1].am_data) ?
"OK" :
"FAIL";
101 check_res[2] = (expected_min[2] < data[2].am_data && expected_max[2] > data[2].am_data) ?
"OK" :
"FAIL";
102 check_res[3] = (expected_min[3] < data[3].am_data && expected_max[3] > data[3].am_data) ?
"OK" :
"FAIL";
105 ret += (expected_min[0] > data[0].am_data || expected_max[0] < data[0].am_data) ? 1 : 0;
106 ret += (expected_min[1] > data[1].am_data || expected_max[1] < data[1].am_data) ? 1 : 0;
107 ret += (expected_min[2] > data[2].am_data || expected_max[2] < data[2].am_data) ? 1 : 0;
108 ret += (expected_min[3] > data[3].am_data || expected_max[3] < data[3].am_data) ? 1 : 0;
111 PX4_INFO(
"channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
112 data[0].am_channel, (
int)(data[0].am_data), expected_min[0], expected_max[0], check_res[0]);
113 PX4_INFO(
"channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
114 data[1].am_channel, (
int)(data[1].am_data), expected_min[1], expected_max[1], check_res[1]);
115 PX4_INFO(
"channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
116 data[2].am_channel, (
int)(data[2].am_data), expected_min[2], expected_max[2], check_res[2]);
117 PX4_INFO(
"channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
118 data[3].am_channel, (
int)(data[3].am_data), expected_min[3], expected_max[3], check_res[3]);
121 PX4_ERR(
"\t JIG voltages test FAILED. Some channels where out of allowed range. Check supply voltages.");
122 goto errout_with_dev;
126 PX4_INFO(
"JIG voltages test successful.");
130 if (fd != 0) { close(fd); }
#define PX4_MAX_ADC_CHANNELS
static void read(bootloader_app_shared_t *pshared)
int test_jig_voltages(int argc, char *argv[])
Simple error/warning functions, heavily inspired by the BSD functions of the same names...