Executing commands

Executing commands SCADA and ICS protocols use commands to tell a device to open, close or pulse a relay; or to change the value of an analog output. Such commands have an effect on the real world, and are usually handled by the device's scan task, or equivalent.

In RTIMDB, when a protocol receives such a command, it sends it through the database, which will find the producer of the commanded point and add the command to the appropriate queue (no locking is required for this). From the protocol's point of view, the command is now accepted and can be acknowledged.

On its next scan, the scan task will find its command queue is no longer empty and will fetch the command at the front of the queue. As the scan task has exclusive access to the command as of the moment it is pushed into the queue, no locks are required here. The command is inspected and executed, and may then be removed from the queue.

if (!command_queue_.empty())
{
    auto queue_front(queue.front());
    assert(Command::crob__ == queue_front.type_); // we only have CROBs because we only have BOs
    auto crob(queue_front.get< Details::CROB >());
    execute(crob);
    queue.pop();
}
else
{ /* no commands pending */ }