FSM Lecture 83| Exercise-008: Implementation part 2

 

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.

Figure 1. Convert the Class into an Active object
Figure 1. Convert the Class into an Active object

 

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. 

Figure 2. Creating a class Button: QActive
Figure 2. Creating a class Button: QActive

 

And we should also create one component class for this Alarm region. 

Figure 3. Exercise using the active objects approach
Figure 3. Exercise using the active objects approach

 

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. 

Figure 4. Creating a class Alarm: QHsm
Figure 4. Creating a class Alarm: QHsm

 

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)

Exercise-008: Implementation part 2
Figure 5. Creating an object of Alarm class inside the Clock_Alarm class

 

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.

active object
Figure 6. Creating a pointer

 

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.

active object
Figure 7. Creating an another pointer for Button

 

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.

active object
Figure 8. Initializer for Both Clock_alarm

 

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. 

active object
Figure 9. Creating an object for Button

 

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

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.