Pre-defined device structures#
In some situations the structure of an AES70 device is fixed and known by the controller application. In those situations it can be simpler and more efficient to construct the OCA object handles manually using the connection and the object number.
After establishing the connection to the device, the object handles can be constructed using the connection and object number as arguments.
This example can be found in examples/simple_controller/
. It assumes a fixed device structure
with well-known object numbers.
struct Channel
{
aes70::controller::OcaBlock block;
aes70::controller::OcaGain gain1, gain2;
aes70::controller::OcaUint8Sensor level;
Channel(std::shared_ptr<aes70::controller::connection> connection,
size_t channel_index)
: block{connection, 5000 + channel_index},
gain1{connection, 6000 + channel_index},
gain2{connection, 7000 + channel_index},
level{connection, 8000 + channel_index}
{
if (channel_index >= 4)
throw std::runtime_error("Channel index is out of bounds.");
}
};
static void subscribeLevels(aes70::controller::device remote)
{
auto connection = remote.get_connection();
// cork the connection in order to combine several calls into
// the same packet
auto handle = connection->cork_handle();
Channel channel1{connection, 0};
Channel channel2{connection, 1};
Channel channel3{connection, 2};
Channel channel4{connection, 3};
subs.add(channel1.level.observeReading(
[](float reading) {
std::cerr << "Channel1.Level: " << reading << std::endl;
},
[](const aes70::controller::failure &) {
std::cerr << "failed." << std::endl;
}));
channel1.gain1.SetGain(1.0);
channel2.gain1.SetGain(2.0);
channel3.gain1.SetGain(3.0);
channel4.gain1.SetGain(4.0);
}
static void connected(aes70::controller::device remote)
{
auto connection = remote.get_connection();
subscribeLevels(remote);
}
Note
Object handles are state-less and light-weight. It is often not necessary to store them like
we do in the example above. It can sometimes be more appropriate to create them on demand.
In the above example this could be done by adding methods such as OcaGain GetGain1()
to
the Channel
class.