Hello, welcome back.
In this lesson, we going to see how to send more complex data using our cues.
I'm going to make a copy of the last project.
I'll copy this and I'll paste over here and I'll rename this to number 16.
Send in complex data with Qs.
Later, with cues like this.
It's done, karpin, I'm going to expand to number 16 over here and I'm going to open my window to see.
OK, so.
In order to make this easily understandable, I'm going to delete all of our tasks so that we start
from scratch.
So this is the receiver task in this last project, I'm going to delete it, I'm going to delete our
send a task one and two as well.
OK.
And in here, our main function, I'm going to delete everything in it.
OK.
So what we have.
We have just our project with you at this hour, you are to function the targets in for printf and these
are our standard system Klok, the one that we started with when we created a project which Cuba makes
this our main function.
Currently, there is no ARTUS running.
We've just included our Simms's always thought each file here.
OK, so we're going to start off by creating a structure.
Our data is going to be held in this structure.
I'm going to create unenumerated type and then from that accretes structure, I'll start off by creating
an enumerator type.
Let's say our system has humidity sensor and a pressure saying so.
So we're going to have this enumerator taip.
Humidity, Senso is the first element, pressure sensor is the second element, and we call in this
data source.
OK, so now.
We going to create a structure or structure, it's going to have two members.
The first member is going to be the value of the senso so value and then the second member is of type
datasource.
So we have this structure, we first created an enumerator type humidity saying so in Pregerson so as
its members, and then we have this structure with two members and this structure here, which represents
our data and the data item here has a value and the source of the data.
OK, so far, so good.
Next, we're going to declare two data variables that will be passed to our cue because we want to see
how to parse these complex data types to our cue.
So we're going to declare two variables.
So I'm going to come over here.
Sorry about that.
We have this array here called struct instructed to send and the array has a size of two.
The first I remember.
Is this one here, remember, the array type is of data type of data over here, so if it's of data,
then each each element in the array has to members.
Because this year has two members, so.
We've we've created an array of data.
And then the first data is this one here, which has seventy seven and then humidity, SENSO And the
second data is this one here, OK?
And I hope you understand this.
The reason we have this and this is in our data structure, the first element is that you each value.
The second element is of type data source, which can be humidity sensor or pressure.
And so that is why we have this, because our structure is of type data.
OK.
So we've created our data that our Q is going to send, OK, so we're going to have.
We're going to have three tasks, we're going to have the humidity task, the pressure task, and they
receive a task to do this, we first declared task on those.
So we have three task condos here.
We have this one for humidity, tasc, this one for pressure task and this one for the receiver task.
Also, we're going to declare a Q.
We declare AQ here, we call in this Q excuse the standard name we use for our Qs.
OK.
So once this is done, we're going to go to our main function and create a queue, so we're going to
create a queue to hold.
Data, remember, we've created our own variable, our own data type known as data, so our cue is going
to hold this type.
Our previous Qs have held you into 32 and other data types.
This time we've defined our own data type that AQ is going to hold.
So come down here and create.
Q I'll see Lidsky.
You have a maximum of three structures, so the size is of safe size data over here, a maximum of three.
Once that is done, we're going to create.
Our receiver, TASC.
With a priority of one.
We have this receiver task, then we're going to create our center task.
We're going to create two center tasks, one is going to be for our humidity task and then the other
one is going to be for our pressure task.
So we create this center task with priority of two higher than the priority of the receiver task.
And over here, we're going to have the same task function called center task for both tasks such that
we pass what is sent as task argument.
That is why over here we see the center task.
The name of this task is humidity center task.
And we pass another argument.
Our structure, our array.
Here we see the first element in the array should be parsed as argument to this task as we have structures
to send index zero for this first element.
Once that is done, we going to create the task for the precious angel.
And we have our essential task here.
OK, so we have three tasks.
We have the receiver task humidities and our task pressure center task, however, our humidity center
task and pressure sensor pressure center task would share the same task function and we'll be passing
what is to be sent a document to the task function.
As we've indicated over here, over here, we are sending the content of our struct to send our index
one because we know index one here corresponds to the pressure information, pressure, sensor information.
And then in the humidity sensor, we send in struct to send index zero because we know index zero corresponds
with the humidity sensor information.
OK, so once that is done.
We going to create our center task.
So come down here, the task function for us in the task.
We can use this to hold a status of any action we take, such as when we want to receive data such as
one such as when we want to send data across course the a task and also we're going to define it.
Blocked states.
So over here, we are going to see into the block two states for two hundred milliseconds if the queue
is full, because this center task.
They are to send the tasks that will be sent into the same queue, so enter the blocked state for two
hundred four for space to become available in the queue each time the queue is full.
So we've just defined this week's time here.
And we're going to take this wait time and parse out the third argument in our excuse and function.
So we can see.
We can open our one loop here.
You see, while.
One over here, and then we start off by sending.
What are we going to send?
We're going to send the parents remember, we passing parameters to these to the send a task and the
parameter here is what we want to send.
So we just said we send in this to our HQ and we want to wait for this amount of time and then we save
the status here.
And if status is not equal to pass, we want to we could print something.
Or we could give an indication to show that AQ is full so we can make use of our status here, but now
I wouldn't print anything or just leave it empty or do something here.
And then we can put a bit of delay, a bit of a delay here by just putting a loop.
Right, so this loop is just like delay without putting the task in a blocked state.
OK.
So this whole center task, this single center task is going to service.
The two center tasks that we've created and we are using task parameters here.
To send their respective data.
OK, so once that is done, we're going to deal with the humidity task over here, we said a humidity
task.
Oh, sorry, we're going to deal with a receiver task.
Let's call it receiver task.
The name is written us.
Task one over here, so receive a task.
We're going to create the task function for the receiver task force, avoid receive receiver task and
this takes just like all tasks, PvP firearms or Peevey parameters.
So argument and then open, close.
So we're going to receive data, the data we're going to receive is going to be of type data because
that is what we are sending is going to be of this type.
So we have to create a variable of this type to hold the data we receive.
So I'll create that variable, I'll call it received structure.
Here we are, and then we created a variable to hold a status.
OK, so once that is done, we're going to open our infinite loop.
And we're going to we're going to receive.
So to receive, we call our security function and when we receive Wistar, it's in our variable that
we've created over here.
OK.
And then once that is done, we're going to check the status.
If the status is passed, then we're going to inspect the data to know where it came from so that we
can identify whether it's humidity data or it's pressure data.
So over here, Q Status equals speed pass, meaning we've received.
So if we've received then then we can check the structure contents, because we know in our data, in
our data.
Elements here, if we can find this member, the second member of the data, we can know whether it's
from humidity sense or from pressure saying so.
So we're going to access the data and then access the second member to find where it is from.
OK, so to do that, we simply use on this condition to check.
So I'll come in here and I'll see.
This is the received data.
This is where we start to receive data.
So receive data dots as datasource, remember, receive data.
It's a structure.
Is of this type, and this type has a member states Assoc., and this is DataSource is off type Annu,
the values can be humidity or pressure preciousness.
So, OK, so we check that.
So we see.
Where are we?
If DataSource is humidity sensible, then we want to preserve humidity, sense of value percentage,
and then we can print the value with the actual value by accessing the value member of the structure.
OK, so since we have this.
Two data sources we can use on Ellis condition to see, OK, if it's not humidity or.
Then it has to be our precious and so.
So in that case, we print the value the same way, but we use the word precious and so here, OK,
so this is if we receive the data, if Kyuss, that is equal speed pass.
What if it's not PDE pass?
Perhaps we want to do something, print something or do something over here or simply say do something.
You can add your own code here if you want some particular action or a particular flag.
To be set when Q status is not true or is not passed, you can put that information here.
OK, so once we've done this, we are ready to test out our project.
What are we going to do is put the prototypes of our to ask and receive a task at the top of the file,
a copy of this controversy.
And then.
I'll come over here, send a task, and then come down here to grab our receiver task.
Is the receiver task controversy.
And then I'll paste this over here.
OK, now we're looking good.
So I'm going to build.
Going to right click and then would project over here.
We have a number of errors, see?
It says.
Receiver TASC.
But as I say, let's see.
Expect a declaration specify before start talking.
OK, I forgot to put the word void here in the receiver task.
OK.
Click to build.
OK, we have no error now I'm going to right click.
And I'm going to say run us SDM 30 to.
A select number 16 over here.
OK.
And then OK, over here.
OK, it's flushing onto the board.
It's done, I'm going to open our realtor.
I'll clean the previous experiment and I'm going to click to open the port.
I'm going to reset the board by pressing the MCU.
Let's see real time, it's not responded.
I'm going to restart real time to see.
OK, here it is, I'm going to select New Line Mode Port over here, it's the same.
And then.
Moderate's is the same policies, 16.
OK, so this has to be from our quote, let's see what the issue could be up.
Let's make sure we initialised our you out.
All right.
Oh, goodness, forgive me.
I forgot to start the scheduler.
We created the tasks.
And over here is our main function there.
Snow starts churchly here, of course.
That is not supposed to work, so we have to start our scheduler.
Click here to build again.
It's built successfully, we're right, click over here, run us SDM 30 to.
Click on number 16 over here for the current project, and it's flashing onto the board.
And to see.
Download successful.
OK, now we can see our data.
And indeed, we can see it come one after the other and of of close the ports, if you see indeed our
precious sense of value.
Precious sense of value is 63 and our humidity sense of value is seventy seven, and that's what we're
seeing and we can replace these static values with value being recorded from a pressure sensor installed
in the structure.
We can easily do that by initializing our ADC and then just collecting the sensor data and placing it
at this particular location.
OK.
So in a way, this is how to send more complex data using our cues and to be able to identify the data
as well.
So that's all there is.
I'll see you in the next lesson.
Have a nice day.