POSIX: change pthreads to px4_tasks in simulator

The simulator was using pthread APIs directly so calls to px4_getpid()
would fail since the task ID was not known. Changed simulator to use
px4_task_spawn_cmd.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-06-13 14:12:17 -07:00
committed by Lorenz Meier
parent 7263402cec
commit 7e7513bc15
3 changed files with 12 additions and 21 deletions
+11 -19
View File
@@ -33,6 +33,7 @@
#include <termios.h>
#include <px4_log.h>
#include <px4_time.h>
#include <px4_tasks.h>
#include "simulator.h"
#include "errno.h"
#include <drivers/drv_pwm_output.h>
@@ -250,9 +251,9 @@ void Simulator::poll_actuators() {
}
}
void *Simulator::sending_trampoline(void *) {
int Simulator::sending_trampoline(int argv, char *argc[]) {
_instance->send();
return 0; // why do I have to put this???
return 0;
}
void Simulator::send() {
@@ -326,21 +327,6 @@ void Simulator::updateSamples()
return;
}
// create a thread for sending data to the simulator
pthread_t sender_thread;
// initialize threads
pthread_attr_t sender_thread_attr;
pthread_attr_init(&sender_thread_attr);
pthread_attr_setstacksize(&sender_thread_attr, 1000);
struct sched_param param;
(void)pthread_attr_getschedparam(&sender_thread_attr, &param);
/* low priority */
param.sched_priority = SCHED_PRIORITY_DEFAULT;
(void)pthread_attr_setschedparam(&sender_thread_attr, &param);
// setup serial connection to autopilot (used to get manual controls)
int serial_fd = openUart(PIXHAWK_DEVICE, 115200);
@@ -381,9 +367,15 @@ void Simulator::updateSamples()
// subscribe to topics
_actuator_outputs_sub = orb_subscribe_multi(ORB_ID(actuator_outputs), 0);
char * argv[2] = { nullptr, nullptr };
// got data from simulator, now activate the sending thread
pthread_create(&sender_thread, &sender_thread_attr, Simulator::sending_trampoline, NULL);
pthread_attr_destroy(&sender_thread_attr);
px4_task_spawn_cmd("simulator-send",
SCHED_DEFAULT,
SCHED_PRIORITY_DEFAULT,
1000,
(px4_main_t)&Simulator::sending_trampoline,
(char *const *)argv);
// wait for new mavlink messages to arrive
while (true) {