DSM pairing cleanup in px4io.cpp

- Simplify parameter range checking in dsm_bind_ioctl
- Replace DSM magic numbers with symbolic constants
This commit is contained in:
Jean Cyr 2013-09-12 21:36:20 -04:00
parent 41982579b3
commit 41610ff7dd
3 changed files with 17 additions and 14 deletions

View File

@ -118,6 +118,9 @@ ORB_DECLARE(output_pwm);
/** start DSM bind */ /** start DSM bind */
#define DSM_BIND_START _IOC(_PWM_SERVO_BASE, 7) #define DSM_BIND_START _IOC(_PWM_SERVO_BASE, 7)
#define DSM2_BIND_PULSES 3 /* DSM_BIND_START ioctl parameter, pulses required to start dsm2 pairing */
#define DSMX_BIND_PULSES 7 /* DSM_BIND_START ioctl parameter, pulses required to start dsmx pairing */
/** Power up DSM receiver */ /** Power up DSM receiver */
#define DSM_BIND_POWER_UP _IOC(_PWM_SERVO_BASE, 8) #define DSM_BIND_POWER_UP _IOC(_PWM_SERVO_BASE, 8)

View File

@ -415,10 +415,9 @@ private:
/** /**
* Handle issuing dsm bind ioctl to px4io. * Handle issuing dsm bind ioctl to px4io.
* *
* @param valid true: the dsm mode is in range * @param dsmMode 0:dsm2, 1:dsmx
* @param isDsm2 true: dsm2m false: dsmx
*/ */
void dsm_bind_ioctl(bool valid, bool isDsm2); void dsm_bind_ioctl(int dsmMode);
}; };
@ -816,7 +815,7 @@ PX4IO::task_main()
orb_copy(ORB_ID(vehicle_command), _t_vehicle_command, &cmd); orb_copy(ORB_ID(vehicle_command), _t_vehicle_command, &cmd);
// Check for a DSM pairing command // Check for a DSM pairing command
if ((cmd.command == VEHICLE_CMD_START_RX_PAIR) && (cmd.param1== 0.0f)) { if ((cmd.command == VEHICLE_CMD_START_RX_PAIR) && (cmd.param1== 0.0f)) {
dsm_bind_ioctl((cmd.param2 == 0.0f) || (cmd.param2 == 1.0f), cmd.param2 == 0.0f); dsm_bind_ioctl((int)cmd.param2);
} }
} }
@ -857,8 +856,8 @@ PX4IO::task_main()
// See if bind parameter has been set, and reset it to 0 // See if bind parameter has been set, and reset it to 0
param_get(dsm_bind_param = param_find("RC_DSM_BIND"), &dsm_bind_val); param_get(dsm_bind_param = param_find("RC_DSM_BIND"), &dsm_bind_val);
if (dsm_bind_val) { if (dsm_bind_val) {
dsm_bind_ioctl((dsm_bind_val == 1) || (dsm_bind_val == 2), dsm_bind_val == 1); dsm_bind_ioctl(dsm_bind_val);
dsm_bind_val = 0; dsm_bind_val = -1;
param_set(dsm_bind_param, &dsm_bind_val); param_set(dsm_bind_param, &dsm_bind_val);
} }
@ -1166,14 +1165,15 @@ PX4IO::io_handle_status(uint16_t status)
} }
void void
PX4IO::dsm_bind_ioctl(bool valid, bool isDsm2) PX4IO::dsm_bind_ioctl(int dsmMode)
{ {
if (!(_status & PX4IO_P_STATUS_FLAGS_OUTPUTS_ARMED)) { if (!(_status & PX4IO_P_STATUS_FLAGS_OUTPUTS_ARMED)) {
if (valid) { /* 0: dsm2, 1:dsmx */
mavlink_log_info(_thread_mavlink_fd, "[IO] binding dsm%c rx", isDsm2 ? '2' : 'x'); if ((dsmMode >= 0) && (dsmMode <= 1)) {
ioctl(nullptr, DSM_BIND_START, isDsm2 ? 3 : 7); mavlink_log_info(_thread_mavlink_fd, "[IO] binding dsm%c rx", (dsmMode == 0) ? '2' : 'x');
ioctl(nullptr, DSM_BIND_START, (dsmMode == 0) ? DSM2_BIND_PULSES : DSMX_BIND_PULSES);
} else { } else {
mavlink_log_info(_thread_mavlink_fd, "[IO] invalid bind type, bind request rejected"); mavlink_log_info(_thread_mavlink_fd, "[IO] invalid dsm bind mode, bind request rejected");
} }
} else { } else {
mavlink_log_info(_thread_mavlink_fd, "[IO] system armed, bind request rejected"); mavlink_log_info(_thread_mavlink_fd, "[IO] system armed, bind request rejected");
@ -2035,9 +2035,9 @@ bind(int argc, char *argv[])
errx(0, "needs argument, use dsm2 or dsmx"); errx(0, "needs argument, use dsm2 or dsmx");
if (!strcmp(argv[2], "dsm2")) if (!strcmp(argv[2], "dsm2"))
pulses = 3; pulses = DSM2_BIND_PULSES;
else if (!strcmp(argv[2], "dsmx")) else if (!strcmp(argv[2], "dsmx"))
pulses = 7; pulses = DSMX_BIND_PULSES;
else else
errx(1, "unknown parameter %s, use dsm2 or dsmx", argv[2]); errx(1, "unknown parameter %s, use dsm2 or dsmx", argv[2]);

View File

@ -166,7 +166,7 @@ PARAM_DEFINE_FLOAT(RC15_DZ, 0.0f);
PARAM_DEFINE_INT32(RC_RL1_DSM_VCC, 0); /* Relay 1 controls DSM VCC */ PARAM_DEFINE_INT32(RC_RL1_DSM_VCC, 0); /* Relay 1 controls DSM VCC */
PARAM_DEFINE_INT32(RC_DSM_BIND, 0); /* 0 = Idle, 1 = Start DSM2 bind, 2 = Start DSMX bind */ PARAM_DEFINE_INT32(RC_DSM_BIND, -1); /* -1 = Idle, 0 = Start DSM2 bind, 1 = Start DSMX bind */
#ifdef CONFIG_ARCH_BOARD_PX4FMU_V2 #ifdef CONFIG_ARCH_BOARD_PX4FMU_V2
PARAM_DEFINE_FLOAT(BAT_V_SCALING, 0.0082f); PARAM_DEFINE_FLOAT(BAT_V_SCALING, 0.0082f);