aboutsummaryrefslogtreecommitdiff
path: root/apps/systemcmds/mixer/mixer.c
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-08-10 00:30:40 -0700
committerpx4dev <px4@purgatory.org>2012-08-10 00:30:40 -0700
commit67e0f8b1791dfffe780a5add528bbcd1358c0421 (patch)
treea0db28b6cfe874aabbad67e8b0a270316984d963 /apps/systemcmds/mixer/mixer.c
parent04d280564cf915e73aa4bddd23cbfdd5b1c19796 (diff)
downloadpx4-firmware-67e0f8b1791dfffe780a5add528bbcd1358c0421.tar.gz
px4-firmware-67e0f8b1791dfffe780a5add528bbcd1358c0421.tar.bz2
px4-firmware-67e0f8b1791dfffe780a5add528bbcd1358c0421.zip
Rework the mixer architecture based on discussions about arbitrary geometry mixing and plugins.
Now the mixer is a C++ library that can be fairly easily bolted into an output driver to provide mixing services. Teach the FMU driver how to use it as an example. More testing is still required.
Diffstat (limited to 'apps/systemcmds/mixer/mixer.c')
-rw-r--r--apps/systemcmds/mixer/mixer.c261
1 files changed, 6 insertions, 255 deletions
diff --git a/apps/systemcmds/mixer/mixer.c b/apps/systemcmds/mixer/mixer.c
index bdf54bc20..9d52557e7 100644
--- a/apps/systemcmds/mixer/mixer.c
+++ b/apps/systemcmds/mixer/mixer.c
@@ -44,7 +44,6 @@
#include <fcntl.h>
#include <errno.h>
-#include <systemlib/mixer.h>
#include <drivers/drv_mixer.h>
#include <uORB/topics/actuator_controls.h>
@@ -52,8 +51,6 @@ __EXPORT int mixer_main(int argc, char *argv[]);
static void usage(const char *reason);
static void load(const char *devname, const char *fname);
-static void save(const char *devname, const char *fname);
-static void show(const char *devname);
int
mixer_main(int argc, char *argv[])
@@ -67,18 +64,6 @@ mixer_main(int argc, char *argv[])
load(argv[2], argv[3]);
- } else if (!strcmp(argv[1], "save")) {
- if (argc < 4)
- usage("missing device or filename");
-
- save(argv[2], argv[3]);
-
- } else if (!strcmp(argv[1], "show")) {
- if (argc < 3)
- usage("missing device name");
-
- show(argv[2]);
-
} else {
usage("unrecognised command");
}
@@ -93,146 +78,15 @@ usage(const char *reason)
fprintf(stderr, "%s\n", reason);
fprintf(stderr, "usage:\n");
- fprintf(stderr, " mixer show <device>\n");
- fprintf(stderr, " mixer {load|save} <device> [<filename>]\n");
+ fprintf(stderr, " mixer load <device> <filename>\n");
+ /* XXX automatic setups for quad, etc. */
exit(1);
}
static void
load(const char *devname, const char *fname)
{
- int defs = -1;
- int dev = -1;
- unsigned num_mixers = 0;
- int ret, result = 1;
- struct mixer_s *mixer = NULL;
-
- /* open the device */
- if ((dev = open(devname, 0)) < 0) {
- fprintf(stderr, "can't open %s\n", devname);
- goto out;
- }
-
- /* open the definition file */
- if ((defs = open(fname, O_RDONLY)) < 0) {
- fprintf(stderr, "can't open %s\n", fname);
- goto out;
- }
-
- /* find out how many mixers the device supports */
- ioctl(dev, MIXERIOCGETMIXERCOUNT, (unsigned long)&num_mixers);
-
- if (num_mixers < 1) {
- fprintf(stderr, "can't get mixer count from %s\n", devname);
- goto out;
- }
-
- /* send mixers to the device */
- for (unsigned i = 0; i < num_mixers; i++) {
- ret = mixer_load(defs, &mixer);
-
- if (ret < 0) {
- fprintf(stderr, "read for mixer %d failed\n", i);
- goto out;
- }
-
- /* end of file? */
- if (ret == 0)
- break;
-
- if (mixer != NULL) {
- /* sanity check the mixer */
- ret = mixer_check(mixer, NUM_ACTUATOR_CONTROL_GROUPS, NUM_ACTUATOR_CONTROLS);
-
- if (ret != 0) {
- fprintf(stderr, "mixer %u fails sanity check %d\n", i, ret);
- goto out;
- }
-
- /* send the mixer to the device */
- ret = ioctl(dev, MIXERIOCSETMIXER(i), (unsigned long)mixer);
-
- if (ret < 0) {
- fprintf(stderr, "mixer %d set failed\n", i);
- goto out;
- }
-
- free(mixer);
- mixer = NULL;
-
- } else {
- /* delete the mixer */
- ret = ioctl(dev, MIXERIOCSETMIXER(i), 0);
-
- if (ret < 0) {
- fprintf(stderr, "mixer %d clear failed\n", i);
- goto out;
- }
- }
- }
-
- result = 0;
-
-out:
-
- /* free the mixers array */
- if (mixer != NULL)
- free(mixer);
-
- if (defs != -1)
- close(defs);
-
- if (dev != -1)
- close(dev);
-
- exit(result);
-}
-
-static int
-getmixer(int dev, unsigned mixer_number, struct MixInfo **mip)
-{
- struct MixInfo *mi = *mip;
- int ret;
-
- /* first-round initialisation */
- if (mi == NULL) {
- mi = (struct MixInfo *)malloc(MIXINFO_SIZE(0));
- mi->num_controls = 0;
- }
-
- /* loop trying to get the next mixer until the buffer is big enough */
- do {
- /* try to get the mixer into the buffer as it stands */
- ret = ioctl(dev, MIXERIOCGETMIXER(mixer_number), (unsigned long)mi);
-
- if (ret < 0)
- return -1;
-
- /* did the mixer fit? */
- if (mi->mixer.control_count <= mi->num_controls)
- break;
-
- /* re-allocate to suit */
- mi->num_controls = mi->mixer.control_count;
- mi = (struct MixInfo *)realloc(mi, MIXINFO_SIZE(mi->num_controls));
-
- /* oops, blew up the heap */
- if (mi == NULL)
- return -1;
-
- } while (true);
-
- *mip = mi;
- return 0;
-}
-
-static void
-save(const char *devname, const char *fname)
-{
- struct MixInfo *mi = NULL;
- int defs = -1;
int dev = -1;
- unsigned num_mixers = 0;
int ret, result = 1;
/* open the device */
@@ -241,120 +95,17 @@ save(const char *devname, const char *fname)
goto out;
}
- /* find out how many mixers the device supports */
- ioctl(dev, MIXERIOCGETMIXERCOUNT, (unsigned long)&num_mixers);
-
- if (num_mixers < 1) {
- fprintf(stderr, "can't get mixer count from %s\n", devname);
- goto out;
- }
-
- /* open the definition file */
- if ((defs = open(fname, O_WRONLY | O_CREAT)) < 0) {
- fprintf(stderr, "can't open %s\n", fname);
- goto out;
- }
-
- /* get mixers from the device and save them */
- for (unsigned i = 0; i < num_mixers; i++) {
- struct mixer_s *mm;
-
- ret = getmixer(dev, i, &mi);
- mm = &mi->mixer;
-
- if (ret < 0) {
- if (errno != ENOENT)
- goto out;
-
- mm = NULL;
- }
-
- ret = mixer_save(defs, mm);
-
- if (ret < 0)
- goto out;
+ /* tell it to load the file */
+ ret = ioctl(dev, MIXERIOCLOADFILE, (unsigned long)fname);
+ if (ret != 0) {
+ fprintf(stderr, "failed loading %s\n", fname);
}
result = 0;
-
out:
- /* free the mixinfo */
- if (mi != NULL)
- free(mi);
-
- if (defs != -1)
- close(defs);
-
if (dev != -1)
close(dev);
exit(result);
}
-
-static void
-show(const char *devname)
-{
- struct MixInfo *mi = NULL;
- int dev = -1;
- unsigned num_mixers = 0;
- int ret;
-
- /* open the device */
- if ((dev = open(devname, 0)) < 0) {
- fprintf(stderr, "can't open %s\n", devname);
- goto out;
- }
-
- /* find out how many mixers the device supports */
- ioctl(dev, MIXERIOCGETMIXERCOUNT, (unsigned long)&num_mixers);
-
- if (num_mixers < 1) {
- fprintf(stderr, "can't get mixer count from %s\n", devname);
- goto out;
- }
-
- /* get mixers from the device and print them */
- for (unsigned i = 0; i < num_mixers; i++) {
-
- ret = getmixer(dev, i, &mi);
-
- if (ret < 0) {
- if (errno != ENOENT)
- goto out;
-
- continue;
- }
-
- printf("mixer %d:\n", i);
- printf(" -ve scale +ve scale offset low limit high limit\n");
- printf("output %8.4f %8.4f %8.4f %8.4f %8.4f\n",
- mi->mixer.output_scaler.negative_scale,
- mi->mixer.output_scaler.positive_scale,
- mi->mixer.output_scaler.offset,
- mi->mixer.output_scaler.lower_limit,
- mi->mixer.output_scaler.upper_limit);
-
- for (unsigned j = 0; j < mi->mixer.control_count; j++) {
- printf("(%u,%u) %8.4f %8.4f %8.4f %8.4f %8.4f\n",
- mi->mixer.control_scaler[j].control_group,
- mi->mixer.control_scaler[j].control_index,
- mi->mixer.control_scaler[j].negative_scale,
- mi->mixer.control_scaler[j].positive_scale,
- mi->mixer.control_scaler[j].offset,
- mi->mixer.control_scaler[j].lower_limit,
- mi->mixer.control_scaler[j].upper_limit);
- }
- }
-
-out:
-
- /* free the mixinfo */
- if (mi != NULL)
- free(mi);
-
- if (dev != -1)
- close(dev);
-
- exit(0);
-}