-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotor.cc
70 lines (62 loc) · 1.87 KB
/
Motor.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <assert.h>
#include "Motor.h"
#include<iostream>
using namespace std;
// halt motor external event
void Motor::Halt(void)
{
// given the Halt event, transition to a new state based upon
// the current state of the state machine
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_Idle
TRANSITION_MAP_ENTRY (CANNOT_HAPPEN) // ST_Stop
TRANSITION_MAP_ENTRY (ST_STOP) // ST_Start
TRANSITION_MAP_ENTRY (ST_STOP) // ST_ChangeSpeed
END_TRANSITION_MAP(NULL)
}
// set motor speed external event
void Motor::SetSpeed(MotorData* pData)
{
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (ST_START) // ST_Idle
TRANSITION_MAP_ENTRY (CANNOT_HAPPEN) // ST_Stop
TRANSITION_MAP_ENTRY (ST_CHANGE_SPEED)// ST_Start
TRANSITION_MAP_ENTRY (ST_CHANGE_SPEED)// ST_ChangeSpeed
END_TRANSITION_MAP(pData)
}
// state machine sits here when motor is not running
void Motor::ST_Idle()
{
cout<<"Motor::ST_Idle"<<endl;
}
// stop the motor
void Motor::ST_Stop()
{
// perform the stop motor processing here
// transition to ST_Idle via an internal event
InternalEvent(ST_IDLE);
cout<<"Motor::ST_Stop"<<endl;
}
// start the motor going
void Motor::ST_Start(MotorData* pData)
{
// set initial motor speed processing here
cout<<"Motor::ST_Start"<<endl;
}
// changes the motor speed once the motor is moving
void Motor::ST_ChangeSpeed(MotorData* pData)
{
// perform the change motor speed to pData->speed here
cout<<"Motor::ST_ChangeSpeed"<<endl;
}
main()
{
Motor car;
MotorData *pData = new MotorData;
pData->speed= 400;
car.SetSpeed(pData);
MotorData *pcData = new MotorData;
pcData->speed = 10;
car.SetSpeed(pcData);
car.Halt();
}