Merge branch 'ext_mag_param' into logging

This commit is contained in:
Lorenz Meier
2014-07-16 15:00:58 +02:00
16 changed files with 124 additions and 59 deletions
+27 -10
View File
@@ -6,28 +6,45 @@
ms5611 start ms5611 start
adc start adc start
# Mag might be external
if hmc5883 start
then
echo "[init] Using HMC5883"
fi
if mpu6000 start if mpu6000 start
then then
echo "[init] Using MPU6000" echo "Internal MPU6000"
fi fi
if l3gd20 start if l3gd20 start
then then
echo "[init] Using L3GD20(H)" echo "Internal L3GD20(H)"
fi
# MAG selection
if param compare SENS_EXT_MAG 2
then
if hmc5883 -I start
then
echo "Internal HMC5883"
fi
else
# Use only external as primary
if param compare SENS_EXT_MAG 1
then
if hmc5883 -X start
then
echo "External HMC5883"
fi
else
# auto-detect the primary, prefer external
if hmc5883 start
then
echo "Default HMC5883"
fi
fi
fi fi
if ver hwcmp PX4FMU_V2 if ver hwcmp PX4FMU_V2
then then
# IMPORTANT: EXTERNAL BUSES SHOULD BE SCANNED FIRST
if lsm303d start if lsm303d start
then then
echo "[init] Using LSM303D" echo "Internal LSM303D"
fi fi
fi fi
+5
View File
@@ -240,6 +240,7 @@ private:
* @param context Pointer to the interrupted context. * @param context Pointer to the interrupted context.
*/ */
static void dev_interrupt(int irq, void *context); static void dev_interrupt(int irq, void *context);
}; };
/** /**
@@ -469,6 +470,10 @@ private:
* @return OK, or -errno on error. * @return OK, or -errno on error.
*/ */
int remove_poll_waiter(struct pollfd *fds); int remove_poll_waiter(struct pollfd *fds);
/* do not allow copying this class */
CDev(const CDev&);
CDev operator=(const CDev&);
}; };
/** /**
+7 -2
View File
@@ -1358,8 +1358,8 @@ namespace hmc5883
#endif #endif
const int ERROR = -1; const int ERROR = -1;
HMC5883 *g_dev_int; HMC5883 *g_dev_int = nullptr;
HMC5883 *g_dev_ext; HMC5883 *g_dev_ext = nullptr;
void start(int bus, enum Rotation rotation); void start(int bus, enum Rotation rotation);
void test(int bus); void test(int bus);
@@ -1395,6 +1395,11 @@ start(int bus, enum Rotation rotation)
errx(0, "already started internal"); errx(0, "already started internal");
g_dev_int = new HMC5883(PX4_I2C_BUS_ONBOARD, HMC5883L_DEVICE_PATH_INT, rotation); g_dev_int = new HMC5883(PX4_I2C_BUS_ONBOARD, HMC5883L_DEVICE_PATH_INT, rotation);
if (g_dev_int != nullptr && OK != g_dev_int->init()) { if (g_dev_int != nullptr && OK != g_dev_int->init()) {
/* tear down the failing onboard instance */
delete g_dev_int;
g_dev_int = nullptr;
if (bus == PX4_I2C_BUS_ONBOARD) { if (bus == PX4_I2C_BUS_ONBOARD) {
goto fail; goto fail;
} }
+20 -31
View File
@@ -204,12 +204,8 @@ PX4IO_Uploader::upload(const char *filenames[])
if (bl_rev <= 2) { if (bl_rev <= 2) {
ret = verify_rev2(fw_size); ret = verify_rev2(fw_size);
} else if(bl_rev == 3) {
ret = verify_rev3(fw_size);
} else { } else {
/* verify rev 4 and higher still uses the same approach and /* verify rev 3 and higher. Every version *needs* to be verified. */
* every version *needs* to be verified.
*/
ret = verify_rev3(fw_size); ret = verify_rev3(fw_size);
} }
@@ -276,14 +272,14 @@ PX4IO_Uploader::recv(uint8_t &c, unsigned timeout)
int int
PX4IO_Uploader::recv(uint8_t *p, unsigned count) PX4IO_Uploader::recv(uint8_t *p, unsigned count)
{ {
int ret;
while (count--) { while (count--) {
int ret = recv(*p++, 5000); ret = recv(*p++, 5000);
if (ret != OK) if (ret != OK)
return ret; break;
} }
return ret;
return OK;
} }
void void
@@ -314,21 +310,19 @@ PX4IO_Uploader::send(uint8_t c)
#endif #endif
if (write(_io_fd, &c, 1) != 1) if (write(_io_fd, &c, 1) != 1)
return -errno; return -errno;
return OK; return OK;
} }
int int
PX4IO_Uploader::send(uint8_t *p, unsigned count) PX4IO_Uploader::send(uint8_t *p, unsigned count)
{ {
int ret;
while (count--) { while (count--) {
int ret = send(*p++); ret = send(*p++);
if (ret != OK) if (ret != OK)
return ret; break;
} }
return ret;
return OK;
} }
int int
@@ -419,12 +413,15 @@ PX4IO_Uploader::program(size_t fw_size)
int ret; int ret;
size_t sent = 0; size_t sent = 0;
file_buf = (uint8_t *)malloc(PROG_MULTI_MAX); file_buf = new uint8_t[PROG_MULTI_MAX];
if (!file_buf) { if (!file_buf) {
log("Can't allocate program buffer"); log("Can't allocate program buffer");
return -ENOMEM; return -ENOMEM;
} }
ASSERT((fw_size & 3) == 0);
ASSERT((PROG_MULTI_MAX & 3) == 0);
log("programming %u bytes...", (unsigned)fw_size); log("programming %u bytes...", (unsigned)fw_size);
ret = lseek(_fw_fd, 0, SEEK_SET); ret = lseek(_fw_fd, 0, SEEK_SET);
@@ -443,34 +440,26 @@ PX4IO_Uploader::program(size_t fw_size)
(unsigned)sent, (unsigned)sent,
(int)count, (int)count,
(int)errno); (int)errno);
} ret = -errno;
break;
if (count == 0) {
free(file_buf);
return OK;
} }
sent += count; sent += count;
if (count < 0)
return -errno;
ASSERT((count % 4) == 0);
send(PROTO_PROG_MULTI); send(PROTO_PROG_MULTI);
send(count); send(count);
send(&file_buf[0], count); send(file_buf, count);
send(PROTO_EOC); send(PROTO_EOC);
ret = get_sync(1000); ret = get_sync(1000);
if (ret != OK) { if (ret != OK) {
free(file_buf); break;
return ret;
} }
} }
free(file_buf);
return OK; delete [] file_buf;
return ret;
} }
int int
-1
View File
@@ -75,7 +75,6 @@ private:
INFO_FLASH_SIZE = 4, /**< max firmware size in bytes */ INFO_FLASH_SIZE = 4, /**< max firmware size in bytes */
PROG_MULTI_MAX = 60, /**< protocol max is 255, must be multiple of 4 */ PROG_MULTI_MAX = 60, /**< protocol max is 255, must be multiple of 4 */
READ_MULTI_MAX = 60, /**< protocol max is 255, something overflows with >= 64 */
}; };
+5 -2
View File
@@ -40,9 +40,12 @@
#include "mavlink_commands.h" #include "mavlink_commands.h"
MavlinkCommandsStream::MavlinkCommandsStream(Mavlink *mavlink, mavlink_channel_t channel) : _channel(channel), _cmd_time(0) MavlinkCommandsStream::MavlinkCommandsStream(Mavlink *mavlink, mavlink_channel_t channel) :
_cmd_sub(mavlink->add_orb_subscription(ORB_ID(vehicle_command))),
_cmd{},
_channel(channel),
_cmd_time(0)
{ {
_cmd_sub = mavlink->add_orb_subscription(ORB_ID(vehicle_command));
} }
void void
+9 -5
View File
@@ -50,16 +50,20 @@ MavlinkFTP::getServer()
return _server; return _server;
} }
MavlinkFTP::MavlinkFTP() MavlinkFTP::MavlinkFTP() :
_session_fds{},
_workBufs{},
_workFree{},
_lock{}
{ {
// initialise the request freelist // initialise the request freelist
dq_init(&_workFree); dq_init(&_workFree);
sem_init(&_lock, 0, 1); sem_init(&_lock, 0, 1);
// initialize session list // initialize session list
for (size_t i=0; i<kMaxSession; i++) { for (size_t i=0; i<kMaxSession; i++) {
_session_fds[i] = -1; _session_fds[i] = -1;
} }
// drop work entries onto the free list // drop work entries onto the free list
for (unsigned i = 0; i < kRequestQueueSize; i++) { for (unsigned i = 0; i < kRequestQueueSize; i++) {
+9 -1
View File
@@ -216,6 +216,7 @@ Mavlink::Mavlink() :
_device_name(DEFAULT_DEVICE_NAME), _device_name(DEFAULT_DEVICE_NAME),
_task_should_exit(false), _task_should_exit(false),
next(nullptr), next(nullptr),
_instance_id(0),
_mavlink_fd(-1), _mavlink_fd(-1),
_task_running(false), _task_running(false),
_hil_enabled(false), _hil_enabled(false),
@@ -230,17 +231,24 @@ Mavlink::Mavlink() :
_mission_pub(-1), _mission_pub(-1),
_mission_result_sub(-1), _mission_result_sub(-1),
_mode(MAVLINK_MODE_NORMAL), _mode(MAVLINK_MODE_NORMAL),
_channel(MAVLINK_COMM_0),
_logbuffer{},
_total_counter(0), _total_counter(0),
_receive_thread{},
_verbose(false), _verbose(false),
_forwarding_on(false), _forwarding_on(false),
_passing_on(false), _passing_on(false),
_ftp_on(false), _ftp_on(false),
_uart_fd(-1), _uart_fd(-1),
_baudrate(57600),
_datarate(10000),
_mavlink_param_queue_index(0), _mavlink_param_queue_index(0),
mavlink_link_termination_allowed(false),
_subscribe_to_stream(nullptr), _subscribe_to_stream(nullptr),
_subscribe_to_stream_rate(0.0f), _subscribe_to_stream_rate(0.0f),
_flow_control_enabled(true), _flow_control_enabled(true),
_message_buffer({}), _message_buffer{},
_message_buffer_mutex{},
_param_initialized(false), _param_initialized(false),
_param_system_id(0), _param_system_id(0),
_param_component_id(0), _param_component_id(0),
+4
View File
@@ -372,4 +372,8 @@ private:
* Main mavlink task. * Main mavlink task.
*/ */
int task_main(int argc, char *argv[]); int task_main(int argc, char *argv[]);
/* do not allow copying this class */
Mavlink(const Mavlink&);
Mavlink operator=(const Mavlink&);
}; };
+4
View File
@@ -174,4 +174,8 @@ private:
mavlink_channel_t _channel; mavlink_channel_t _channel;
uint8_t _comp_id; uint8_t _comp_id;
/* do not allow copying this class */
MavlinkMissionManager(const MavlinkMissionManager&);
MavlinkMissionManager operator=(const MavlinkMissionManager&);
}; };
@@ -82,6 +82,10 @@ private:
const orb_id_t _topic; ///< topic metadata const orb_id_t _topic; ///< topic metadata
int _fd; ///< subscription handle int _fd; ///< subscription handle
bool _published; ///< topic was ever published bool _published; ///< topic was ever published
/* do not allow copying this class */
MavlinkOrbSubscription(const MavlinkOrbSubscription&);
MavlinkOrbSubscription operator=(const MavlinkOrbSubscription&);
}; };
+6 -6
View File
@@ -86,7 +86,9 @@ static const float mg2ms2 = CONSTANTS_ONE_G / 1000.0f;
MavlinkReceiver::MavlinkReceiver(Mavlink *parent) : MavlinkReceiver::MavlinkReceiver(Mavlink *parent) :
_mavlink(parent), _mavlink(parent),
status{},
hil_local_pos{},
_control_mode{},
_global_pos_pub(-1), _global_pos_pub(-1),
_local_pos_pub(-1), _local_pos_pub(-1),
_attitude_pub(-1), _attitude_pub(-1),
@@ -111,15 +113,13 @@ MavlinkReceiver::MavlinkReceiver(Mavlink *parent) :
_manual_pub(-1), _manual_pub(-1),
_telemetry_heartbeat_time(0), _telemetry_heartbeat_time(0),
_radio_status_available(false), _radio_status_available(false),
_control_mode_sub(-1), _control_mode_sub(orb_subscribe(ORB_ID(vehicle_control_mode))),
_hil_frames(0), _hil_frames(0),
_old_timestamp(0), _old_timestamp(0),
_hil_local_proj_inited(0), _hil_local_proj_inited(0),
_hil_local_alt0(0.0) _hil_local_alt0(0.0f),
_hil_local_proj_ref{}
{ {
_control_mode_sub = orb_subscribe(ORB_ID(vehicle_control_mode));
memset(&hil_local_pos, 0, sizeof(hil_local_pos));
memset(&_control_mode, 0, sizeof(_control_mode));
// make sure the FTP server is started // make sure the FTP server is started
(void)MavlinkFTP::getServer(); (void)MavlinkFTP::getServer();
+4
View File
@@ -156,4 +156,8 @@ private:
bool _hil_local_proj_inited; bool _hil_local_proj_inited;
float _hil_local_alt0; float _hil_local_alt0;
struct map_projection_reference_s _hil_local_proj_ref; struct map_projection_reference_s _hil_local_proj_ref;
/* do not allow copying this class */
MavlinkReceiver(const MavlinkReceiver&);
MavlinkReceiver operator=(const MavlinkReceiver&);
}; };
+4
View File
@@ -77,6 +77,10 @@ protected:
private: private:
hrt_abstime _last_sent; hrt_abstime _last_sent;
/* do not allow top copying this class */
MavlinkStream(const MavlinkStream&);
MavlinkStream& operator=(const MavlinkStream&);
}; };
+2
View File
@@ -52,3 +52,5 @@ INCLUDE_DIRS += $(MAVLINK_SRC)/include/mavlink
MAXOPTIMIZATION = -Os MAXOPTIMIZATION = -Os
MODULE_STACKSIZE = 1024 MODULE_STACKSIZE = 1024
EXTRACXXFLAGS = -Weffc++
+13
View File
@@ -292,6 +292,19 @@ PARAM_DEFINE_FLOAT(SENS_BOARD_Z_OFF, 0.0f);
*/ */
PARAM_DEFINE_INT32(SENS_EXT_MAG_ROT, 0); PARAM_DEFINE_INT32(SENS_EXT_MAG_ROT, 0);
/**
* Set usage of external magnetometer
*
* * Set to 0 (default) to auto-detect (will try to get the external as primary)
* * Set to 1 to force the external magnetometer as primary
* * Set to 2 to force the internal magnetometer as primary
*
* @min 0
* @max 2
* @group Sensor Calibration
*/
PARAM_DEFINE_INT32(SENS_EXT_MAG, 0);
/** /**
* RC Channel 1 Minimum * RC Channel 1 Minimum