-
Notifications
You must be signed in to change notification settings - Fork 119
ConsumerTask
In this task, we will consume the temperature value produced in the producer task. We will first create a consume task. For this, execute the following command
DH> python programs/scripts/dune-create-task.py . DuneAuthor Tutorials/TempConsume
This will create TempConsume task. To use the temperature value produced by the producer task we need for first bind the message from IMC and write a consume method.
First binding the value from the IMC message, for this include bind IMC::Temperature(this) in the constructor.
Task(const std::string& name, Tasks::Context& ctx):
DUNE::Tasks::Task(name, ctx)
{
bind<IMC::Temperature>(this);
}
Then create a consumer method before the main loop. The following is the consumer method
void
consume(const IMC::Temperature* msg)
{
inf("temperature is %f", msg->value);
}
In order to compile the consumer task, follow the instructions of the producer task.
cd DH>/build
DH>/build$ make rebuild_cache
DH>/build$ make
This will compile the consumer task.
Create consumer.ini file in DH>/etc/development folder. In this folder include the contents as given below
[Include ../common/transports.ini]
[Tutorials.TempConsume]
Enabled = Always
Entity Label = Consumer
[Transports.Logging]
Enabled = Always
Entity Label = Logger
Transports = Temperature
The first line "[Include ..]" includes the transports.ini file into the current file. [Tutorials.TempConsume] directs the task towards the TempConsume directory. Enabled = Always tells that the task is always enabled. Entity Label = Consumer informs that this task is a consumer. For the entity label there is no need provide in the Task.cpp file, rather dune takes care of the entity label.
Then run the command
DH>/build/$ ./dune -c ../etc/development/Tutorials/consumer
Upon execution you can see the output as:
[2013/05/31 17:40:46] - MSG [Transports.Logging] >> starting
[2013/05/31 17:40:46] - MSG [Tutorials.TempProd] >> starting
[2013/05/31 17:40:46] - MSG [Transports.Logging] >> log started '20130531/174046_idle'
We can see that the tasks Tutorials.TempConsumer and Transports.Logging have started.