aboutsummaryrefslogtreecommitdiff
path: root/apps/systemlib/mixer/mixer.h
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-12-29 00:01:04 -0800
committerpx4dev <px4@purgatory.org>2012-12-29 00:01:04 -0800
commit35c82ff2fc63ab823770f9776e6b6a0f81cd4452 (patch)
tree86956f9f00f1270eafc921748ac024a7daa92f80 /apps/systemlib/mixer/mixer.h
parentf0da789626c32695e670b55dab29283eed4a05c6 (diff)
downloadpx4-firmware-35c82ff2fc63ab823770f9776e6b6a0f81cd4452.tar.gz
px4-firmware-35c82ff2fc63ab823770f9776e6b6a0f81cd4452.tar.bz2
px4-firmware-35c82ff2fc63ab823770f9776e6b6a0f81cd4452.zip
Make mixer ioctls load from a memory buffer rather than a file. This is prep for uploading the memory buffer to IO to be processed there.
Diffstat (limited to 'apps/systemlib/mixer/mixer.h')
-rw-r--r--apps/systemlib/mixer/mixer.h140
1 files changed, 100 insertions, 40 deletions
diff --git a/apps/systemlib/mixer/mixer.h b/apps/systemlib/mixer/mixer.h
index 94c179eba..0023dc380 100644
--- a/apps/systemlib/mixer/mixer.h
+++ b/apps/systemlib/mixer/mixer.h
@@ -234,50 +234,45 @@ public:
void add_mixer(Mixer *mixer);
/**
- * Reads a mixer definition from a file and configures a corresponding
- * group.
+ * Adds mixers to the group based on a text description in a buffer.
*
- * The mixer group must be empty when this function is called.
+ * Mixer definitions begin with a single capital letter and a colon.
+ * The actual format of the mixer definition varies with the individual
+ * mixers; they are summarised here, but see ROMFS/mixers/README for
+ * more details.
*
- * A mixer definition is a text representation of the configuration of a
- * mixer. Definition lines begin with a capital letter followed by a colon.
+ * Null Mixer
+ * ..........
+ *
+ * The null mixer definition has the form:
+ *
+ * Z:
+ *
+ * Simple Mixer
+ * ............
+ *
+ * A simple mixer definition begins with:
+ *
+ * M: <control count>
+ * O: <-ve scale> <+ve scale> <offset> <lower limit> <upper limit>
+ *
+ * The definition continues with <control count> entries describing the control
+ * inputs and their scaling, in the form:
+ *
+ * S: <group> <index> <-ve scale> <+ve scale> <offset> <lower limit> <upper limit>
+ *
+ * Multirotor Mixer
+ * ................
+ *
+ * The multirotor mixer definition is a single line of the form:
+ *
+ * R: <geometry> <roll scale> <pitch scale> <yaw scale> <deadband>
*
- * Null Mixer:
- *
- * Z:
- *
- * This mixer generates a constant zero output, and is normally used to
- * skip over outputs that are not in use.
- *
- * Simple Mixer:
- *
- * M: <scaler count>
- * S: <control group> <control index> <negative_scale*> <positive_scale*> <offset*> <lower_limit*> <upper_limit*>
- * S: ...
- *
- * The definition consists of a single-line header indicating the
- * number of scalers and then one line defining each scaler. The first
- * scaler in the file is always the output scaler, followed by the input
- * scalers.
- *
- * The <control ...> values for the output scaler are ignored by the mixer.
- *
- *
- *
- * Values marked * are integers representing floating point values; values are
- * scaled by 10000 on load/save.
- *
- * Multiple mixer definitions may be stored in a single file; it is assumed that
- * the reader will know how many to expect and read accordingly.
- *
- * A mixer entry with a scaler count of zero indicates a disabled mixer. This
- * will return NULL for the mixer when processed by this function, and will be
- * generated by passing NULL as the mixer to mixer_save.
- *
- * @param path The mixer configuration file to read.
+ * @param buf The mixer configuration buffer.
+ * @param buflen The length of the buffer.
* @return Zero on successful load, nonzero otherwise.
*/
- int load_from_file(const char *path);
+ int load_from_buf(const char *buf, unsigned buflen);
private:
Mixer *_first; /**< linked list of mixers */
@@ -294,6 +289,21 @@ public:
NullMixer();
~NullMixer() {};
+ /**
+ * Factory method.
+ *
+ * Given a pointer to a buffer containing a text description of the mixer,
+ * returns a pointer to a new instance of the mixer.
+ *
+ * @param buf Buffer containing a text description of
+ * the mixer.
+ * @param buflen Length of the buffer in bytes, adjusted
+ * to reflect the bytes consumed.
+ * @return A new NullMixer instance, or nullptr
+ * if the text format is bad.
+ */
+ static NullMixer *from_text(const char *buf, unsigned &buflen);
+
virtual unsigned mix(float *outputs, unsigned space);
virtual void groups_required(uint32_t &groups);
};
@@ -318,6 +328,27 @@ public:
mixer_simple_s *mixinfo);
~SimpleMixer();
+ /**
+ * Factory method.
+ *
+ * Given a pointer to a buffer containing a text description of the mixer,
+ * returns a pointer to a new instance of the mixer.
+ *
+ * @param control_cb The callback to invoke when fetching a
+ * control value.
+ * @param cb_handle Handle passed to the control callback.
+ * @param buf Buffer containing a text description of
+ * the mixer.
+ * @param buflen Length of the buffer in bytes, adjusted
+ * to reflect the bytes consumed.
+ * @return A new SimpleMixer instance, or nullptr
+ * if the text format is bad.
+ */
+ static SimpleMixer *from_text(Mixer::ControlCallback control_cb,
+ uintptr_t cb_handle,
+ const char *buf,
+ unsigned &buflen);
+
virtual unsigned mix(float *outputs, unsigned space);
virtual void groups_required(uint32_t &groups);
@@ -330,10 +361,18 @@ public:
* @return Zero if the mixer makes sense, nonzero otherwise.
*/
int check();
+
protected:
private:
- mixer_simple_s *_info;
+ mixer_simple_s *_info;
+
+ static int parse_output_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler);
+ static int parse_control_scaler(const char *buf,
+ unsigned &buflen,
+ mixer_scaler_s &scaler,
+ uint8_t &control_group,
+ uint8_t &control_index);
};
/**
@@ -395,6 +434,27 @@ public:
float deadband);
~MultirotorMixer();
+ /**
+ * Factory method.
+ *
+ * Given a pointer to a buffer containing a text description of the mixer,
+ * returns a pointer to a new instance of the mixer.
+ *
+ * @param control_cb The callback to invoke when fetching a
+ * control value.
+ * @param cb_handle Handle passed to the control callback.
+ * @param buf Buffer containing a text description of
+ * the mixer.
+ * @param buflen Length of the buffer in bytes, adjusted
+ * to reflect the bytes consumed.
+ * @return A new MultirotorMixer instance, or nullptr
+ * if the text format is bad.
+ */
+ static MultirotorMixer *from_text(Mixer::ControlCallback control_cb,
+ uintptr_t cb_handle,
+ const char *buf,
+ unsigned &buflen);
+
virtual unsigned mix(float *outputs, unsigned space);
virtual void groups_required(uint32_t &groups);