aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/px4io
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-10-09 09:26:18 +0200
committerLorenz Meier <lm@inf.ethz.ch>2013-10-09 09:26:18 +0200
commitd63ad0fb817d76d2d818db47805b46742d2aae68 (patch)
treee566105dca81b06bd0cdf442cc8760c7613a1d8b /src/drivers/px4io
parenta3bdf536e5f6b95d54ef6684d7092ebff2d23dc8 (diff)
downloadpx4-firmware-d63ad0fb817d76d2d818db47805b46742d2aae68.tar.gz
px4-firmware-d63ad0fb817d76d2d818db47805b46742d2aae68.tar.bz2
px4-firmware-d63ad0fb817d76d2d818db47805b46742d2aae68.zip
Added debug output printing capabilities for IOv2
Diffstat (limited to 'src/drivers/px4io')
-rw-r--r--src/drivers/px4io/px4io.cpp88
1 files changed, 80 insertions, 8 deletions
diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp
index 7f67d02b5..38e183608 100644
--- a/src/drivers/px4io/px4io.cpp
+++ b/src/drivers/px4io/px4io.cpp
@@ -194,6 +194,11 @@ public:
int set_idle_values(const uint16_t *vals, unsigned len);
/**
+ * Disable RC input handling
+ */
+ int disable_rc_handling();
+
+ /**
* Print IO status.
*
* Print all relevant IO status information
@@ -201,9 +206,9 @@ public:
void print_status();
/**
- * Disable RC input handling
+ * Fetch and print debug console output.
*/
- int disable_rc_handling();
+ int print_debug();
#ifdef CONFIG_ARCH_BOARD_PX4FMU_V1
/**
@@ -1532,8 +1537,52 @@ PX4IO::io_reg_modify(uint8_t page, uint8_t offset, uint16_t clearbits, uint16_t
}
int
+PX4IO::print_debug()
+{
+#ifdef CONFIG_ARCH_BOARD_PX4FMU_V2
+ int io_fd = -1;
+
+ if (io_fd < 0) {
+ io_fd = ::open("/dev/ttyS0", O_RDONLY | O_NONBLOCK);
+ }
+
+ /* read IO's output */
+ if (io_fd > 0) {
+ pollfd fds[1];
+ fds[0].fd = io_fd;
+ fds[0].events = POLLIN;
+
+ usleep(500);
+ int pret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), 10);
+
+ if (pret > 0) {
+ int count;
+ char buf[65];
+
+ do {
+ count = ::read(io_fd, buf, sizeof(buf) - 1);
+ if (count > 0) {
+ /* enforce null termination */
+ buf[count] = '\0';
+ warnx("IO CONSOLE: %s", buf);
+ }
+
+ } while (count > 0);
+ }
+
+ ::close(io_fd);
+ return 0;
+ }
+#endif
+ return 1;
+
+}
+
+int
PX4IO::mixer_send(const char *buf, unsigned buflen, unsigned retries)
{
+ /* get debug level */
+ int debuglevel = io_reg_get(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_SET_DEBUG);
uint8_t frame[_max_transfer];
@@ -1572,6 +1621,15 @@ PX4IO::mixer_send(const char *buf, unsigned buflen, unsigned retries)
int ret = io_reg_set(PX4IO_PAGE_MIXERLOAD, 0, (uint16_t *)frame, total_len / 2);
+ /* print mixer chunk */
+ if (debuglevel > 5 || ret) {
+
+ warnx("fmu sent: \"%s\"", msg->text);
+
+ /* read IO's output */
+ print_debug();
+ }
+
if (ret) {
log("mixer send error %d", ret);
return ret;
@@ -1581,6 +1639,11 @@ PX4IO::mixer_send(const char *buf, unsigned buflen, unsigned retries)
} while (buflen > 0);
+ /* ensure a closing newline */
+ msg->text[0] = '\n';
+ msg->text[1] = '\0';
+ int ret = io_reg_set(PX4IO_PAGE_MIXERLOAD, 0, (uint16_t *)frame, 1);
+
retries--;
log("mixer sent");
@@ -2242,28 +2305,37 @@ test(void)
void
monitor(void)
{
+ /* clear screen */
+ printf("\033[2J");
+
unsigned cancels = 3;
- printf("Hit <enter> three times to exit monitor mode\n");
for (;;) {
pollfd fds[1];
fds[0].fd = 0;
fds[0].events = POLLIN;
- poll(fds, 1, 500);
+ poll(fds, 1, 2000);
if (fds[0].revents == POLLIN) {
int c;
read(0, &c, 1);
- if (cancels-- == 0)
+ if (cancels-- == 0) {
+ printf("\033[H"); /* move cursor home and clear screen */
exit(0);
+ }
}
-#warning implement this
+ if (g_dev != nullptr) {
-// if (g_dev != nullptr)
-// g_dev->dump_one = true;
+ printf("\033[H"); /* move cursor home and clear screen */
+ (void)g_dev->print_status();
+ (void)g_dev->print_debug();
+ printf("[ Use 'px4io debug <N>' for more output. Hit <enter> three times to exit monitor mode ]\n");
+ } else {
+ errx(1, "driver not loaded, exiting");
+ }
}
}