Embedded Real-Time Systems (TI-IRTS) State Machine Implementation



Similar documents
Embedded Real-Time Systems (TI-IRTS) GoF State Pattern a Behavioral Pattern

How To Understand The Dependency Inversion Principle (Dip)

Designing a Home Alarm using the UML. And implementing it using C++ and VxWorks

UML By Examples. 0. Introduction. 2. Unified Modeling Language. Home UML. Resources

Integration, testing and debugging of C code together with UML-generated sources

Embedded/Real-Time Software Development with PathMATE and IBM Rational Systems Developer

Treemap by Category Visualizations. Product: IBM Cognos Active Report Area of Interest: Reporting

Architecture & Design of Embedded Real-Time Systems (TI-AREM)

Automotive System and Software Architecture

Singletons. The Singleton Design Pattern using Rhapsody in,c

A UML Documentation for an Elevator System. Distributed Embedded Systems, Fall 2000 PhD Project Report

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

The C Programming Language course syllabus associate level

UML for the C programming language.

Testing high-power hydraulic pumps with NI LabVIEW (RT) and the StateChart module. Jeffrey Habets & Roger Custers

This presentation introduces you to the new call home feature in IBM PureApplication System V2.0.

Lesson 5: The Trading Station

C++ INTERVIEW QUESTIONS

Designing Real-Time and Embedded Systems with the COMET/UML method

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Fundamentals of Programming and Software Development Lesson Objectives

IBM WebSphere Application Server

All Visualizations Documentation

Sources: On the Web: Slides will be available on:

Curriculum Map. Discipline: Computer Science Course: C++

Sofware Requirements Engineeing

Introduction. UML = Unified Modeling Language It is a standardized visual modeling language.

UML - Getting Started EA v4.0

BPMonline CRM + Service Desk Agent Desktop User Guide

Object Oriented Software Design II

Embedded State Machine Implementation

NETWORK ADMINISTRATION

DEVELOPING DATA PROVIDERS FOR NEEDFORTRADE STUDIO PLATFORM DATA PROVIDER TYPES

Lecture 2 Notes: Flow of Control

ECE 122. Engineering Problem Solving with Java

Integrating Legacy Code / Models with Model Based Development Using Rhapsody

Vending Machine using Verilog

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Building Web Services with Apache Axis2

Types of UML Diagram. UML Diagrams OOAD. Computer Engineering Sem -IV

Database lifecycle management

Questions? Assignment. Techniques for Gathering Requirements. Gathering and Analysing Requirements

From Systems to Services

Guardian Tracking Systems

Planning and Managing Projects with Microsoft Project Professional 2013

Combination Chart Extensible Visualizations. Product: IBM Cognos Business Intelligence Area of Interest: Reporting

Review of getting started: Dynamic Model - State Diagram. States Labeled with Conditions. Dynamic Models for E.S. More Dynamic Modeling

Banner Workflow. Creating FOAPAL Requests

C++FA 3.1 OPTIMIZING C++

Application of UML in Real-Time Embedded Systems

Rebuild Perfume With Python and PyPI

C++FA 5.1 PRACTICE MID-TERM EXAM

Model-driven development solutions To support your business objectives. IBM Rational Rhapsody edition comparison matrix

6. Control Structures

Term Project: Roulette

SETTING UP YOUR 6000 SERIES TIME RECORDER

Resource Management with VMware DRS

Digi Cellular Application Guide Using Digi Surelink

Kokii BatteryDAQ. BMS Software Manual. Battery Analyzer Battery DAS

Software Design. Software Design. Software design is the process that adds implementation details to the requirements.

Software Engineering Techniques

How To Develop A Telelogic Harmony/Esw Project

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15

Embedding Maps into Microsoft Office and Microsoft SharePoint

Chapter 3 Claims June 2012

Appendix K Introduction to Microsoft Visual C++ 6.0

Lab Manual: Using Rational Rose

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Off The Shelf Approach to ArcGIS Server & The Dashboard Approach to Gaining Insight to ArcGIS Server

Part VI. Object-relational Data Models

Moving from CS 61A Scheme to CS 61B Java

Database Access via Programming Languages

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

An Associate of the UOB Group A UTRADE FX ELITE QUICK START GUIDE

Monday, April 8, 13. Creating Successful Magento ERP Integrations

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Unified Static and Runtime Verification of Object-Oriented Software

Object Oriented Software Design

Connecting EWS using DDNS

Chapter 7. Address Translation

Google Drive: Access and organize your files

13 Classes & Objects with Constructors/Destructors

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

Using triggers and actions

Best Practices with IBM Cognos Framework Manager & the SAP Business Warehouse Agnes Chau Cognos SAP Solution Specialist

Using Microsoft Lync for Web Conferencing, Training & Support

Hello and welcome to this presentation of the STM32L4 Firewall. It covers the main features of this system IP used to secure sensitive code and data.

Setting up RDP on your ipad

Object Oriented Software Design

Vodafone Plus. User Guide for Windows Mobile

Contents. Introduction

Using switch/case as the core of your state machine

Project Server Plus Risk to Issue Escalator User Guide v1.1

Colorado Medical Assistance Program Web Portal Dental Claims User Guide

BIG DATA ANALYTICS For REAL TIME SYSTEM

Keil C51 Cross Compiler

Transcription:

Embedded Real-Time Systems (TI-IRTS) State Machine Implementation Version: 5-2-2010

Agenda STM notation and example Five state machine implementation techniques: 1. Switch based 2. Table driven implementation 3. GoF State Pattern (separate slides) Case tool STM generation Slide 2

UML State Chart Notation Class with State Machine State_0 event1(parameter1)[guard1]/action_1 State_1 entry/ action_2 event2/ action_3 do/ activity_1 exit/ action_4 +event1(parameter1) +event2() -entry() -exit() -action_1() -action_2() -action_3() -action_4() -activity() (task/thread) Slide 3

Two State Machine Types Mealy Machine Moore Machine IDLE IDLE start / start motor stop / stop motor start stop RUNNING RUNNING do/ motor running Slide 4

Example: Infusion Pump as a Mealy Machine /start_alarm Alarm alarmacknowledged / stopalarm stop / stopinfusion Infusion Inactive clear / cleartotal start [door_closed ] / startinfusion /stopinfusion; startalarm Infusion Active alarmdetected dooropened Slide 5

Example: Infusion Pump as a Moore Machine Alarm do/ givealarm alarmacknowledged Infusion Inactive clear / cleartotal stop start [doorclosed] Infusion Active do/ infusemedicine alarmdetected dooropened Slide 6

1. Switch Based Implementation (1) InfusionPumpControl -currentstate: STATES +handleevent(event: EVENTS) 1 1 pipump Infusion Pump main() // Mealy implementation InfusionPump infpump; InfusionPumpControl ipumpcontrol(&infpump); EVENTS event; while(forever) event = readevent(); ipumpcontrol.handleevent(event); Slide 7

Switch Based Implementation (2) class InfusionPumpControl public: InfusionPumpControl(InfusionPump* pip) pipump= pip; currentstate= ALARM; startalarm(); void handleevent(events event); private: STATES currentstate; InfusionPump* pipump; startalarm(); stopalarm(); cleartotal(); Slide 8

Switch Based Implementation (3) void InfusionPumpControl::handleEvent(Events event) switch (currentstate) case ALARM: if (event == ALARM_ACKNOWLEDGED) stopalarm(); currentstate = INFUSION_INACTIVE; break; case INFUSION_INACTIVE: if (event == CLEAR) cleartotal(); else if ((event == START) && doorclosed()) // Guarded transition pipump->startinfusion(); currentstate = INFUSION_ACTIVE; break; Slide 9

Discussion of Switch-based Implementation Advantages: Very easy and straightforward to implement Easy to implement guarded transitions and entry/exit actions Disadvantages: Problem with event parameters The logic and the behavior are tightly interconnected For larger state machines: the nested switch/case statements becomes very difficult to read and modify Recommendation: Use it only, for small and simple state machines Slide 10

2. State-Event Table Implementation Event1 Event2 Event3. State1 action1 State2 - action5 State3 State2 - action3 - action6 State1 State3 action2 State1 action4 State2 - New state Slide 11

Infusion Pump State-Event Table Notice start AND stop alarm alarmdetected doorclosed Acknowledged OR dooropened stopalarm ALARM X X X INFUSION INACTIVE start INFUSION infusion INACTIVE X X X INFUSION ACTIVE stop startalarm, INFUSION X Infusion stopinfusion ACTIVE X INFUSION ALARM INACTIVE clear X clear Total X X X represents don't cares Slide 12

State-Event Table Implementation (1) InfusionPumpControl -statetable +handleevent(event) -preprocessevent(event) -executeaction(actionno) 1 actionno= handleevent(event) StateTableMachine -actualstate +handleevent(event: int): int +getstate(): int class InfusionPumpControl static int[ ] statetable = /* EVENTS E1 E2 E3 E4 E5 */ /* ALARM 0 */ NO,NO, NO,NO, A1,1, NO,NO, NO,NO, /* INF_INA 1 */ A2, 2, NO,NO, NO,NO, NO,NO, A3,NO, /* INF_ACT 2 */ NO,NO, A4, 1, NO,NO, A5, 0, NO,NO ; Slide 13

State-Event Table Implementation (2) main() int eventno, actionno; InfusionPumpControl ipumpcontrol; while ((eventno=getevent())!= END_PROGRAM) ipumpcontrol.handleevent(eventno); Slide 14

State-Event Table Implementation (3) InfusionPumpControl::InfusionPumpControl() pstm = new statetablemachine( statetable,noofevents, ALARM); startalarm(); // call initial action InfusionPumpControl::handleEvent(int eventno) int pevent= preprocessevent(eventno); int actionno= pstm->handleevent(pevent); executeaction(actionno); Slide 15

State-Event Table Implementation (4) StateTableMachine::StateTableMachine(int[] _states, int maxevent, int initstate) nofevents = maxevent; states = _states; actualstate = initstate; int StateTableMachine:: handleevent(int eventno) int index = ((actualstate * nofevents) + eventno) * 2; // look for a state transition if (states[index+1]!= State.NO) actualstate = states[index+1]; // return action return (states[index]); int StateTableMachine:: getstate() return actualstate; Slide 16

State-Event Table Implementation (5) int InfusionPumpControl::preProcessEvent(int inevent) switch (inevent) case START: if (doorclosed()) // GUARDED TRANSITION return E1; break; case STOP: return E2; break; case ALARM_ACKNOWLEDGED: return E3; break; case ALARM_DETECTED: case DOOR_OPENED: return E4; break; case CLEAR: return E5; break; default: return NO_EVENT; return NO_EVENT; Slide 17

State-Event Table Implementation (6) void InfusionPumpController::executeAction(int actionno) switch (actionno) case NO: cout << "NO action defined in ; break; case A1: cout << "A1: stopalarm; new "; break; case A2: cout << "A2: startinfusion; new "; break; case A3: cout << "A3: cleartotal; new "; break; case A4: cout << A4: stopinfusion; new "; break; case A5: cout << A5: startalarm, stopinfusion; new "; break; default: cout << "undefined action in ; cout << "state = " << pstm->getstate()); Slide 18

State-Event Table Implementation (7) Example with guarded transition internal events start stop alarm alarm clear OK NOT_ Acknowled. Det.+xx OK stopalarm ALARM X X X X INFUSION INACTIVE check_ clear INFUSION for_start Total INACTIVE X X X TRANSIT. X STATE X X X X start TRANSI- Infusion X TION- X X X X X STATE INFUSION INFUSION ACTIVE INACTIVE stop stop INFUSION X Infusion Infusion ACTIVE X startal. X X X INFUSION INACTIVE ALARM Slide 19

State-Event Table Implementation (8) / start_alarm Alarm alarmacknowledged / stopalarm Special: Transition state NOT_OK Infusion Inactive start/ checkforstart clear / cleartotal /stopinfusion; startalarm stop / stopinfusion OK/ startinfusion Infusion Active alarmdetected dooropened Slide 20

Example with a Specialized State M. (1) Infusion Pump Control StateTableMachine +handleevent(int eventno) preprocessing eventtabel (cmdeventtable) as an extra constructor parameter PreprocessingStateTableMachine PreprocessingStateTableMachine( ) +handleevent(int eventno) Slide 21

Example with a Specialized State M. (2) static int[] cmdeventtable = START, E0, STOP, E1, ALARM_ACKNOWLEDGED, E2, ALARM_DETECTED, E3, DOOR_OPENED, E3, CLEAR, E4, OK, E5, NOT_OK, E6, END_OF_TABLE, NO_EVENT, ; InfusionPumpControl::InfusionPumpControl() // call of constructor with cmdeventtable pstm = new PreProcessingStateTableMachine( statetable,noofevents,alarm,cmdeventtable); Slide 22

Example with a Specialized State M. (3) int PreProcessingStateTableMachine:: handleevent(int actualeventno) int i=0; while ((cmdevent[i]!= END_OF_TABLE) && (cmdevent[i]!= actualeventno)) i += 2; if (cmdevent[i]!= END_OF_TABLE) return StateTableMachine::handleEvent( cmdevent[i+1]); else return NO; // NO= end of table Slide 23

Example with a Specialized State M. (4) int InfusionPumpControl::executeAction(int actionno) switch (actionno)... case A6: // check_for_start return (doorclosed()? OK : NOT_OK); break; default: return NO_EVENT; void InfusionPumpControl:: handleexternalevent(int inevent) while (inevent!= NO_EVENT) inevent = executeaction(pstm->handleevent(inevent)); Slide 24

Discussion of State-Event Table Implementation Disadvantages The events should be preprocessed, to consecutive constants, before table lookup Guarded transitions requires extra transition state plus internal events Difficult to implement hierarchic state machines Advantages if the state machine is specified as a state-event table: Easy to implement and verify The StateTableMachine can be a general utility class Recommendations: Use it for larger and flat state machines, with no or only few guarded transition Slide 25

3. State Pattern (GoF) Implementation See separate GoF State Pattern Slide Presentation Slide 26

Case tool STM Generations A few tools can automatically generate code for state machines: Visual State (IAR) Rhapsody (IBM (Telelogic)) Code generation for two different strategies supported (switch based or state pattern based) Slide 27