Got serial control working this weekend! Here’s a very exciting video demonstrating a volume control mapped to an amplitude parameter in the test instrument:
I’m working my way toward sorting through the param handling stuff:
-
[C] is the instrument command console which parses cmdlines breaking on
spaces, then
=to build up a series oflpmsg_tupdate messages: one for each space-separated param in the cmdline. -
[P] is the instrument param decode callback, which takes a string token
for the key, a string token for the value, and a pointer to an
lpmsg_tstruct to fill. It looks up the key ID enum value with strcmp, then switches on the ID to encode the value in the appropriate way. Error handling here is TBD, at this point the callback expects to get sane data. - [M] is the instrument message thread which handles new messages on the instrument mqueue. The update msg handler passes the update msg to [U] which at this point is already encoded and ready to be handled by the instrument callback. (The [U] instrument callback is what actually gets the values and does something.)
-
[U] is the instrument update callback which takes an
lpmsg_tupdate message whosemsgfield has a payload of a key/value pair encoded as bytes. The callback decodes the payload (differently depending on the key value, more on that later)
For example, the cmdline u amp=0.5 freq=220 gets parsed by
[C] into two lpmsg_t update messages via [p] into payloads
which are IDs (mapped to an enum in the instrument) and float values
encoded into the msg field of the update message, then
relayed back via [M] and finally received by [U] for processing.
The video above is a simpler version of this flow that doesn’t include the [C] console parsing. That’s tonight’s project!
The procedure is basically:
-
Loop over each param with
strtok_rbreaking the cmdline on spaces. -
Loop over the key/value pairs in each paramline by breaking it on
=withstrtok_r - For keys, just store them in a tmp variable for later (very soon) processing
- For values, pass the key, value and a pointer to a fresh update message to [P] which encodes the msg
- Then send the msg!
The way encoding happens is determined by the instrument [P] callback, which means instruments get to decide what kinds of params they support and how to deal with them…