Browse Source

Tone alarm: IOCTL interface fix

sbg
Lorenz Meier 9 years ago
parent
commit
fa2b1ffa14
  1. 25
      src/platforms/posix/drivers/tonealrmsim/tone_alarm.cpp

25
src/platforms/posix/drivers/tonealrmsim/tone_alarm.cpp

@ -119,7 +119,7 @@ public:
ToneAlarm(); ToneAlarm();
~ToneAlarm(); ~ToneAlarm();
virtual int devIOCTL(unsigned long cmd, void *arg); virtual int devIOCTL(unsigned long cmd, unsigned long arg);
virtual ssize_t devWrite(const void *buffer, size_t len); virtual ssize_t devWrite(const void *buffer, size_t len);
inline const char *name(int tune) inline const char *name(int tune)
{ {
@ -641,21 +641,19 @@ ToneAlarm::next_trampoline(void *arg)
int int
ToneAlarm::devIOCTL(unsigned long cmd, void *arg) ToneAlarm::devIOCTL(unsigned long cmd, unsigned long arg)
{ {
int result = OK; int result = OK;
unsigned long ul_arg = (unsigned long)arg; PX4_DEBUG("ToneAlarm::devIOCTL %i %lu", cmd, arg);
PX4_DEBUG("ToneAlarm::devIOCTL %i %lu", cmd, ul_arg);
/* decide whether to increase the alarm level to cmd or leave it alone */ /* decide whether to increase the alarm level to cmd or leave it alone */
switch (cmd) { switch (cmd) {
case TONE_SET_ALARM: case TONE_SET_ALARM:
PX4_INFO("TONE_SET_ALARM %lu", ul_arg); PX4_INFO("TONE_SET_ALARM %lu", arg);
if (ul_arg < TONE_NUMBER_OF_TUNES) { if (arg < TONE_NUMBER_OF_TUNES) {
if (ul_arg == TONE_STOP_TUNE) { if (arg == TONE_STOP_TUNE) {
// stop the tune // stop the tune
_tune = nullptr; _tune = nullptr;
_next = nullptr; _next = nullptr;
@ -664,10 +662,10 @@ ToneAlarm::devIOCTL(unsigned long cmd, void *arg)
} else { } else {
/* always interrupt alarms, unless they are repeating and already playing */ /* always interrupt alarms, unless they are repeating and already playing */
if (!(_repeat && _default_tune_number == ul_arg)) { if (!(_repeat && _default_tune_number == arg)) {
/* play the selected tune */ /* play the selected tune */
_default_tune_number = ul_arg; _default_tune_number = arg;
start_tune(_default_tunes[ul_arg]); start_tune(_default_tunes[arg]);
} }
} }
@ -860,18 +858,19 @@ tone_alarm_main(int argc, char *argv[])
} }
/* if it looks like a PLAY string... */ /* if it looks like a PLAY string... */
else if (strlen(argv1) > 2) { else if (argv1 && (strlen(argv1) > 2)) {
if (*argv1 == 'M') { if (*argv1 == 'M') {
ret = play_string(argv1, false); ret = play_string(argv1, false);
} }
} else { } else {
/* It might be a tune name */ /* It might be a tune name */
for (tune = 1; tune < TONE_NUMBER_OF_TUNES; tune++) for (tune = 1; tune < TONE_NUMBER_OF_TUNES; tune++) {
if (!strcmp(g_dev->name(tune), argv1)) { if (!strcmp(g_dev->name(tune), argv1)) {
ret = play_tune(tune); ret = play_tune(tune);
return ret; return ret;
} }
}
PX4_WARN("unrecognized command, try 'start', 'stop', an alarm number or name, or a file name starting with a '/'"); PX4_WARN("unrecognized command, try 'start', 'stop', an alarm number or name, or a file name starting with a '/'");
ret = 1; ret = 1;

Loading…
Cancel
Save