Exercise-008: Implementation part 2
Now, select Clock_Alarm:QHsm and convert this class into an active object. You have to go to the right-hand side and change the superclass from QHsm to QActive. That’s the first change you have to make.
After that, we have got another active object called Button. Let’s create that. Click on the package name AOs, Right-click, Add a class. We will call this a Button and select superclass as QActive, as shown in Figure 2. Now there are two active objects.
And we should also create one component class for this Alarm region.
Let’s create one class. Select the package name AOs→ right-click→ Add class→ I’ll call this Alarm. Its superclass could be QActive, QHsm, or it could be anything. I will select QHsm for this Alarm class.
And we have to use the composition of classes. Clock_Alarm is a container of this Alarm class. An alarm is a component class. Whenever Clock_Alarm comes into existence, the memory for Alarm also should come into existence. That’s why you must create an object of Alarm class inside this Clock_Alarm.
That’s why now select the Clock_Alarm class and add attribute. Attribute name is ‘alarm’, type is ‘Alarm’, and it is ‘private’. (Figure 5)
For the Alarm class, let’s define a constructor and other things later.
Now, let’s create some opec pointers.
/*.${HSMs::Clock_Alarm} ....................................................*/ typedef struct Clock_Alarm { /* protected: */ QActive super; /* private: */ uint32_t temp_time; uint8_t time_mode; uint8_t temp_format; uint8_t temp_digit; uint8_t curr_setting; Alarm alarm; /* private state histories */ QStateHandler hist_Clock; } Clock_Alarm;
When you generate the code, your main class, the Clock_Alarm ack class, looks like this. Now, it is derived from QActive. That’s how this class becomes an active object class. And this QActive provides all the Event queues, methods of context, etc. That’s why to post-event to the Event queue such things you need now a pointer to this QActive super class.
So, just like what you did previously. In the previous exercise, it was QHsm. Now it is QActive. That’s why now we have to create a pointer to this superclass, and you have to make that public.
Let’s click on the AOs package name, and we will add a free attribute. Select Add Attribute. I’ll name it AO_ClockAlarm. Type is QActive *const; visibility is ‘global.’ AO_ClockAlarm is an opec pointer to access this Clock_Alarm active object.
Let’s create another opec pointer for the button. Select the package AOs→ Add attribute→ Name is AO_Button; the type is QActive *const; Visibility is global.
What is an initializer for this? Select the Clock_Alarm, add attribute, the initializer will be = &Clock_Alarm_obj.super. And for the AO button, the initializer is the same = &Button_obj.super.
We have not created any object for the Button. Let’s create an object. Select Button→ right-click→ Add attribute. I’ll name it as ‘obj,’ type is Button, visibility is ‘private,’ it is a static variable, let’s select ‘static’ here.
In the following article, we will create the constructors for the button active object and the Alarm component.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1