mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-05 18:28:53 +08:00
POSIX: Changed px4_debug.h to px4_log.h
Also changed use of printf to PX4_WARN or PX4_INFO in posix and qurt tests. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -48,8 +48,6 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define PX4_DEBUG(...)
|
||||
|
||||
using namespace device;
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
* A device simulator
|
||||
*/
|
||||
|
||||
#include <px4_debug.h>
|
||||
#include <px4_log.h>
|
||||
#include <px4_tasks.h>
|
||||
#include <px4_time.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
* Implementation of existing task API for Linux
|
||||
*/
|
||||
|
||||
#include <px4_debug.h>
|
||||
#include <px4_log.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -57,14 +57,14 @@ int hello_main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: hello {start|stop|status}\n");
|
||||
PX4_WARN("usage: hello {start|stop|status}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "start")) {
|
||||
|
||||
if (HelloExample::appState.isRunning()) {
|
||||
printf("already running\n");
|
||||
PX4_INFO("already running\n");
|
||||
/* this is not an error */
|
||||
return 0;
|
||||
}
|
||||
@@ -86,15 +86,15 @@ int hello_main(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(argv[1], "status")) {
|
||||
if (HelloExample::appState.isRunning()) {
|
||||
printf("is running\n");
|
||||
PX4_INFO("is running\n");
|
||||
|
||||
} else {
|
||||
printf("not started\n");
|
||||
PX4_INFO("not started\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("usage: hello_main {start|stop|status}\n");
|
||||
PX4_WARN("usage: hello_main {start|stop|status}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ static int writer_main(int argc, char *argv[])
|
||||
|
||||
int fd = px4_open(TESTDEV, PX4_F_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("--- Open failed %d %d", fd, px4_errno);
|
||||
PX4_INFO("--- Open failed %d %d", fd, px4_errno);
|
||||
return -px4_errno;
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ static int writer_main(int argc, char *argv[])
|
||||
int i=0;
|
||||
while (i<3) {
|
||||
// Wait for 3 seconds
|
||||
printf("--- Sleeping for 4 sec\n");
|
||||
PX4_INFO("--- Sleeping for 4 sec\n");
|
||||
ret = sleep(4);
|
||||
if (ret < 0) {
|
||||
printf("--- sleep failed %d %d\n", ret, errno);
|
||||
PX4_INFO("--- sleep failed %d %d\n", ret, errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
printf("--- writing to fd\n");
|
||||
PX4_INFO("--- writing to fd\n");
|
||||
ret = px4_write(fd, buf, 1);
|
||||
++i;
|
||||
}
|
||||
@@ -110,16 +110,16 @@ static int test_pub_block(int fd, unsigned long blocked)
|
||||
{
|
||||
int ret = px4_ioctl(fd, DEVIOCSPUBBLOCK, blocked);
|
||||
if (ret < 0) {
|
||||
printf("ioctl PX4_DEVIOCSPUBBLOCK failed %d %d", ret, px4_errno);
|
||||
PX4_INFO("ioctl PX4_DEVIOCSPUBBLOCK failed %d %d", ret, px4_errno);
|
||||
return -px4_errno;
|
||||
}
|
||||
|
||||
ret = px4_ioctl(fd, DEVIOCGPUBBLOCK, 0);
|
||||
if (ret < 0) {
|
||||
printf("ioctl PX4_DEVIOCGPUBBLOCK failed %d %d", ret, px4_errno);
|
||||
PX4_INFO("ioctl PX4_DEVIOCGPUBBLOCK failed %d %d", ret, px4_errno);
|
||||
return -px4_errno;
|
||||
}
|
||||
printf("pub_blocked = %d %s\n", ret, (unsigned long)ret == blocked ? "PASS" : "FAIL");
|
||||
PX4_INFO("pub_blocked = %d %s\n", ret, (unsigned long)ret == blocked ? "PASS" : "FAIL");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -131,29 +131,29 @@ int VCDevExample::main()
|
||||
_node = new VCDevNode();
|
||||
|
||||
if (_node == 0) {
|
||||
printf("Failed to allocate VCDevNode\n");
|
||||
PX4_INFO("Failed to allocate VCDevNode\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (_node->init() != PX4_OK) {
|
||||
printf("Failed to init VCDevNode\n");
|
||||
PX4_INFO("Failed to init VCDevNode\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = px4_open(TESTDEV, PX4_F_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
printf("Open failed %d %d", fd, px4_errno);
|
||||
PX4_INFO("Open failed %d %d", fd, px4_errno);
|
||||
return -px4_errno;
|
||||
}
|
||||
|
||||
void *p = 0;
|
||||
int ret = px4_ioctl(fd, DIOC_GETPRIV, (unsigned long)&p);
|
||||
if (ret < 0) {
|
||||
printf("ioctl DIOC_GETPRIV failed %d %d", ret, px4_errno);
|
||||
PX4_INFO("ioctl DIOC_GETPRIV failed %d %d", ret, px4_errno);
|
||||
return -px4_errno;
|
||||
}
|
||||
printf("priv data = %p %s\n", p, p == (void *)_node ? "PASS" : "FAIL");
|
||||
PX4_INFO("priv data = %p %s\n", p, p == (void *)_node ? "PASS" : "FAIL");
|
||||
|
||||
ret = test_pub_block(fd, 1);
|
||||
if (ret < 0)
|
||||
@@ -174,32 +174,32 @@ int VCDevExample::main()
|
||||
(char* const*)NULL);
|
||||
|
||||
while (!appState.exitRequested() && i<13) {
|
||||
printf("=====================\n");
|
||||
printf("==== sleeping 2 sec ====\n");
|
||||
PX4_INFO("=====================\n");
|
||||
PX4_INFO("==== sleeping 2 sec ====\n");
|
||||
sleep(2);
|
||||
|
||||
fds[0].fd = fd;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].revents = 0;
|
||||
|
||||
printf("==== Calling Poll\n");
|
||||
PX4_INFO("==== Calling Poll\n");
|
||||
ret = px4_poll(fds, 1, 1000);
|
||||
printf("==== Done poll\n");
|
||||
PX4_INFO("==== Done poll\n");
|
||||
if (ret < 0) {
|
||||
printf("==== poll failed %d %d\n", ret, px4_errno);
|
||||
PX4_INFO("==== poll failed %d %d\n", ret, px4_errno);
|
||||
px4_close(fd);
|
||||
}
|
||||
else if (i > 0) {
|
||||
if (ret == 0)
|
||||
printf("==== Nothing to read - PASS\n");
|
||||
PX4_INFO("==== Nothing to read - PASS\n");
|
||||
else
|
||||
printf("==== poll returned %d\n", ret);
|
||||
PX4_INFO("==== poll returned %d\n", ret);
|
||||
}
|
||||
else if (i == 0) {
|
||||
if (ret == 1)
|
||||
printf("==== %d to read - %s\n", ret, fds[0].revents & POLLIN ? "PASS" : "FAIL");
|
||||
PX4_INFO("==== %d to read - %s\n", ret, fds[0].revents & POLLIN ? "PASS" : "FAIL");
|
||||
else
|
||||
printf("==== %d to read - FAIL\n", ret);
|
||||
PX4_INFO("==== %d to read - FAIL\n", ret);
|
||||
|
||||
}
|
||||
++i;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
*
|
||||
* @author Mark Charlebois <charlebm@gmail.com>
|
||||
*/
|
||||
#include <px4_log.h>
|
||||
#include <px4_middleware.h>
|
||||
#include <px4_app.h>
|
||||
#include "wqueue_test.h"
|
||||
@@ -46,10 +47,10 @@ int PX4_MAIN(int argc, char **argv)
|
||||
{
|
||||
px4::init(argc, argv, "wqueue_test");
|
||||
|
||||
printf("wqueue hello\n");
|
||||
PX4_INFO("wqueue hello\n");
|
||||
WQueueTest wq;
|
||||
wq.main();
|
||||
|
||||
printf("goodbye\n");
|
||||
PX4_INFO("goodbye\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
*/
|
||||
#include "wqueue_test.h"
|
||||
#include <px4_app.h>
|
||||
#include <px4_log.h>
|
||||
#include <px4_tasks.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -53,14 +54,14 @@ int wqueue_test_main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: wqueue_test {start|stop|status}\n");
|
||||
PX4_INFO("usage: wqueue_test {start|stop|status}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "start")) {
|
||||
|
||||
if (WQueueTest::appState.isRunning()) {
|
||||
printf("already running\n");
|
||||
PX4_INFO("already running\n");
|
||||
/* this is not an error */
|
||||
return 0;
|
||||
}
|
||||
@@ -82,15 +83,15 @@ int wqueue_test_main(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(argv[1], "status")) {
|
||||
if (WQueueTest::appState.isRunning()) {
|
||||
printf("is running\n");
|
||||
PX4_INFO("is running\n");
|
||||
|
||||
} else {
|
||||
printf("not started\n");
|
||||
PX4_INFO("not started\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("usage: wqueue_test {start|stop|status}\n");
|
||||
PX4_INFO("usage: wqueue_test {start|stop|status}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <px4_debug.h>
|
||||
#include <px4_log.h>
|
||||
|
||||
/* Get the name of the default value fiven the param name */
|
||||
#define PX4_PARAM_DEFAULT_VALUE_NAME(_name) PARAM_##_name##_DEFAULT
|
||||
|
||||
@@ -32,13 +32,25 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file px4_debug.h
|
||||
* Platform dependant debug
|
||||
* @file px4_log.h
|
||||
* Platform dependant logging/debug
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(__PX4_LINUX) || defined(__PX4_QURT)
|
||||
#if defined(__PX4_QURT)
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern void qurt_log(const char *fmt, ...);
|
||||
__END_DECLS
|
||||
|
||||
#define PX4_DBG(...) qurt_log(__VA_ARGS__)
|
||||
#define PX4_DEBUG(...) qurt_log(__VA_ARGS__)
|
||||
#define PX4_INFO(...) qurt_log(__VA_ARGS__)
|
||||
#define PX4_WARN(...) qurt_log(__VA_ARGS__)
|
||||
#define PX4_ERR(...) { qurt_log("ERROR file %s line %d:", __FILE__, __LINE__); qurt_log(__VA_ARGS__); }
|
||||
|
||||
#elif defined(__PX4_LINUX)
|
||||
|
||||
#if defined(__PX4_LINUX)
|
||||
#include <err.h>
|
||||
@@ -53,11 +53,13 @@
|
||||
#include <string>
|
||||
|
||||
#include <px4_tasks.h>
|
||||
#include <px4_log.h>
|
||||
#include <hexagon_standalone.h>
|
||||
|
||||
#define MAX_CMD_LEN 100
|
||||
|
||||
#define PX4_MAX_TASKS 100
|
||||
#define PX4_MAX_TASKS 5
|
||||
|
||||
struct task_entry
|
||||
{
|
||||
int pid;
|
||||
@@ -73,28 +75,28 @@ typedef struct
|
||||
{
|
||||
px4_main_t entry;
|
||||
int argc;
|
||||
char *argv[];
|
||||
// strings are allocated after the
|
||||
char * argv[];
|
||||
// strings are allocated after
|
||||
} pthdata_t;
|
||||
|
||||
static void entry_adapter ( void *ptr )
|
||||
{
|
||||
printf("entry_adapter\n");
|
||||
pthdata_t *data = (pthdata_t *) ptr;
|
||||
PX4_DEBUG("entry_adapter %p %p entry %p %d %p\n", ptr, data, data->entry, data->argc, data->argv[0]);
|
||||
|
||||
printf("data->entry = %p\n", data->entry);
|
||||
PX4_DEBUG("data->entry = %p\n", data->entry);
|
||||
data->entry(data->argc, data->argv);
|
||||
free(ptr);
|
||||
printf("after entry\n");
|
||||
printf("Before px4_task_exit\n");
|
||||
PX4_DEBUG("after entry\n");
|
||||
PX4_DEBUG("Before px4_task_exit\n");
|
||||
px4_task_exit(0);
|
||||
printf("After px4_task_exit\n");
|
||||
PX4_DEBUG("After px4_task_exit\n");
|
||||
}
|
||||
|
||||
void
|
||||
px4_systemreset(bool to_bootloader)
|
||||
{
|
||||
printf("Called px4_system_reset\n");
|
||||
PX4_DEBUG("Called px4_system_reset\n");
|
||||
}
|
||||
|
||||
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry, char * const *argv)
|
||||
@@ -107,7 +109,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
||||
unsigned long structsize;
|
||||
char * p = (char *)argv;
|
||||
|
||||
printf("px4_task_spawn_cmd entry = %p\n", entry);
|
||||
PX4_DEBUG("px4_task_spawn_cmd entry = %p %p %s\n", entry, argv, argv[0]);
|
||||
// Calculate argc
|
||||
while (p != (char *)0) {
|
||||
p = argv[argc];
|
||||
@@ -116,20 +118,24 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
||||
++argc;
|
||||
len += strlen(p)+1;
|
||||
}
|
||||
printf("arg %d %p\n", argc, argv);
|
||||
PX4_DEBUG("arg %d %p\n", argc, argv);
|
||||
structsize = sizeof(pthdata_t)+(argc+1)*sizeof(char *);
|
||||
pthdata_t *taskdata;
|
||||
|
||||
PX4_DEBUG("arg %d %p\n", argc, argv);
|
||||
// not safe to pass stack data to the thread creation
|
||||
taskdata = (pthdata_t *)malloc(structsize+len);
|
||||
PX4_DEBUG("arg %d %p\n", argc, argv);
|
||||
offset = ((unsigned long)taskdata)+structsize;
|
||||
PX4_DEBUG("arg %d %p\n", argc, argv);
|
||||
|
||||
taskdata->entry = entry;
|
||||
taskdata->argc = argc;
|
||||
|
||||
PX4_DEBUG("arg %d %p\n", argc, argv);
|
||||
for (i=0; i<argc; i++) {
|
||||
printf("TEST\n");
|
||||
printf("arg %d %s\n", i, argv[i]);
|
||||
PX4_DEBUG("TEST\n");
|
||||
PX4_DEBUG("arg %d %s\n", i, argv[i]);
|
||||
taskdata->argv[i] = (char *)offset;
|
||||
strcpy((char *)offset, argv[i]);
|
||||
offset+=strlen(argv[i])+1;
|
||||
@@ -142,11 +148,11 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
||||
taskmap[i].pid = i+1;
|
||||
taskmap[i].name = name;
|
||||
taskmap[i].isused = true;
|
||||
taskmap[i].sp = malloc(stack_size);
|
||||
taskmap[i].sp = malloc(2048);
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("TEST2\n");
|
||||
PX4_DEBUG("taskdata %p entry %p %d %p\n", taskdata, taskdata->entry, taskdata->argc, taskdata->argv[0]);
|
||||
thread_create(entry_adapter, taskmap[i].sp, i+1, (void *) taskdata);
|
||||
|
||||
return i+1;
|
||||
@@ -154,7 +160,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
||||
|
||||
int px4_task_delete(px4_task_t id)
|
||||
{
|
||||
printf("Called px4_task_delete\n");
|
||||
PX4_DEBUG("Called px4_task_delete\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -167,7 +173,7 @@ void px4_task_exit(int ret)
|
||||
|
||||
int px4_task_kill(px4_task_t id, int sig)
|
||||
{
|
||||
printf("Called px4_task_kill\n");
|
||||
PX4_DEBUG("Called px4_task_kill\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -176,16 +182,16 @@ void px4_show_tasks()
|
||||
int idx;
|
||||
int count = 0;
|
||||
|
||||
printf("Active Tasks:\n");
|
||||
PX4_DEBUG("Active Tasks:\n");
|
||||
for (idx=0; idx < PX4_MAX_TASKS; idx++)
|
||||
{
|
||||
if (taskmap[idx].isused) {
|
||||
printf(" %-10s %d\n", taskmap[idx].name.c_str(), taskmap[idx].pid);
|
||||
PX4_DEBUG(" %-10s %d\n", taskmap[idx].name.c_str(), taskmap[idx].pid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0)
|
||||
printf(" No running tasks\n");
|
||||
PX4_DEBUG(" No running tasks\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id)
|
||||
|
||||
work_unlock(lock_id);
|
||||
if (!worker) {
|
||||
printf("MESSED UP: worker = 0\n");
|
||||
PX4_WARN("MESSED UP: worker = 0\n");
|
||||
}
|
||||
else
|
||||
worker(arg);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
|
||||
@@ -40,6 +39,7 @@
|
||||
*/
|
||||
|
||||
#include "hello_example.h"
|
||||
#include <px4_log.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -52,7 +52,7 @@ int HelloExample::main()
|
||||
int i=0;
|
||||
while (!appState.exitRequested() && i<5) {
|
||||
|
||||
printf(" Doing work...\n");
|
||||
PX4_DEBUG(" Doing work...\n");
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
* @author Mark Charlebois <charlebm@gmail.com>
|
||||
*/
|
||||
#include <px4_middleware.h>
|
||||
#include <px4_log.h>
|
||||
#include <px4_app.h>
|
||||
#include "hello_example.h"
|
||||
#include <stdio.h>
|
||||
@@ -46,10 +47,10 @@ int PX4_MAIN(int argc, char **argv)
|
||||
{
|
||||
px4::init(argc, argv, "hello");
|
||||
|
||||
printf("hello\n");
|
||||
PX4_DEBUG("hello\n");
|
||||
HelloExample hello;
|
||||
hello.main();
|
||||
|
||||
printf("goodbye\n");
|
||||
PX4_DEBUG("goodbye\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
* @author Mark Charlebois <mcharleb@gmail.com>
|
||||
*/
|
||||
#include "hello_example.h"
|
||||
#include <px4_log.h>
|
||||
#include <px4_app.h>
|
||||
#include <px4_tasks.h>
|
||||
#include <stdio.h>
|
||||
@@ -52,11 +53,11 @@ extern "C" __EXPORT int hello_main(int argc, char *argv[]);
|
||||
|
||||
static void usage()
|
||||
{
|
||||
printf("usage: hello {start|stop|status}\n");
|
||||
PX4_DEBUG("usage: hello {start|stop|status}\n");
|
||||
}
|
||||
int hello_main(int argc, char *argv[])
|
||||
{
|
||||
printf("argc = %d %s %s %p\n", argc, argv[0], argv[1], argv[2]);
|
||||
PX4_DEBUG("argc = %d %s %s %p\n", argc, argv[0], argv[1], argv[2]);
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
return 1;
|
||||
@@ -64,8 +65,9 @@ int hello_main(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(argv[1], "start")) {
|
||||
|
||||
PX4_DEBUG("Starting\n");
|
||||
if (HelloExample::appState.isRunning()) {
|
||||
printf("already running\n");
|
||||
PX4_DEBUG("already running\n");
|
||||
/* this is not an error */
|
||||
return 0;
|
||||
}
|
||||
@@ -73,7 +75,7 @@ int hello_main(int argc, char *argv[])
|
||||
daemon_task = px4_task_spawn_cmd("hello",
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_MAX - 5,
|
||||
2000,
|
||||
16000,
|
||||
PX4_MAIN,
|
||||
(char* const*)argv);
|
||||
|
||||
@@ -87,10 +89,10 @@ int hello_main(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(argv[1], "status")) {
|
||||
if (HelloExample::appState.isRunning()) {
|
||||
printf("is running\n");
|
||||
PX4_DEBUG("is running\n");
|
||||
|
||||
} else {
|
||||
printf("not started\n");
|
||||
PX4_DEBUG("not started\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user