Newer
Older
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "Motor2.h"
// Header code defined in the model
void __userImplemented__Motor2__initt(int port){
init2(port);
}
int __userImplemented__Motor2__runmotor(int pow, int flagA){
return set_val(pow, flagA, 66);
}
int __userImplemented__Motor2__modify_motor(int pow, int factor, int flagA, int flagB){
return modify2(pow, factor, flagA, flagB);
}
int __userImplemented__Motor2__turn(int flag, int deg){
return turn(flag, deg, 66);
}
// End of header code defined in the model
#define STATE__START__STATE 0
#define STATE__WaitingForMotorCommand 1
#define STATE__STOP__STATE 2
void Motor2__initt(int port) {
char my__attr[CHAR_ALLOC_SIZE];
sprintf(my__attr, "%d",port);
traceFunctionCall("Motor2", "initt", my__attr);
__userImplemented__Motor2__initt(port);
}
int Motor2__runmotor(int pow, int flagA) {
char my__attr[CHAR_ALLOC_SIZE];
sprintf(my__attr, "%d,%d",pow,flagA);
traceFunctionCall("Motor2", "runmotor", my__attr);
return __userImplemented__Motor2__runmotor(pow, flagA);
}
int Motor2__modify_motor(int speed, int factor, int flagA, int flagB) {
char my__attr[CHAR_ALLOC_SIZE];
sprintf(my__attr, "%d,%d,%d,%d",speed,factor,flagA,flagB);
traceFunctionCall("Motor2", "modify_motor", my__attr);
return __userImplemented__Motor2__modify_motor(speed, factor, flagA, flagB);
}
void Motor2__turn(int flag, int deg) {
char my__attr[CHAR_ALLOC_SIZE];
sprintf(my__attr, "%d,%d",flag,deg);
traceFunctionCall("Motor2", "turn", my__attr);
__userImplemented__Motor2__turn(flag, deg);
}
void *mainFunc__Motor2(void *arg){
int port = 66;
int speed = 0;
int factor = 0;
int flagA = 0;
int flagB = 0;
int flag = 0;
int deg = 0;
int __currentState = STATE__START__STATE;
__attribute__((unused)) request __req0;
__attribute__((unused))int *__params0[4];
__attribute__((unused)) request __req1;
__attribute__((unused))int *__params1[4];
__attribute__((unused)) request __req2;
__attribute__((unused))int *__params2[4];
__attribute__((unused))setOfRequests __list;
__attribute__((unused))pthread_cond_t __myCond;
__attribute__((unused))request *__returnRequest;
char * __myname = (char *)arg;
pthread_cond_init(&__myCond, NULL);
fillListOfRequests(&__list, __myname, &__myCond, &__mainMutex);
//printf("my name = %s\n", __myname);
/* Main loop on states */
while(__currentState != STATE__STOP__STATE) {
switch(__currentState) {
case STATE__START__STATE:
traceStateEntering(__myname, "__StartState");
Motor2__initt(port);
__currentState = STATE__WaitingForMotorCommand;
break;
case STATE__WaitingForMotorCommand:
traceStateEntering(__myname, "WaitingForMotorCommand");
__params0[0] = &speed;
__params0[1] = &flagA;
makeNewRequest(&__req0, 2782, RECEIVE_SYNC_REQUEST, 0, 0, 0, 2, __params0);
__req0.syncChannel = &__Controller_run_motor2__Motor2_run_motor;
addRequestToList(&__list, &__req0);
__params1[0] = &speed;
__params1[1] = &factor;
__params1[2] = &flagA;
__params1[3] = &flagB;
makeNewRequest(&__req1, 2783, RECEIVE_SYNC_REQUEST, 0, 0, 0, 4, __params1);
__req1.syncChannel = &__Controller_modify_motor2__Motor2_modify_motor;
addRequestToList(&__list, &__req1);
__params2[0] = &flag;
__params2[1] = °
makeNewRequest(&__req2, 2781, RECEIVE_SYNC_REQUEST, 0, 0, 0, 2, __params2);
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
__req2.syncChannel = &__Controller_turn2__Motor2_turn;
addRequestToList(&__list, &__req2);
if (nbOfRequests(&__list) == 0) {
debug2Msg(__myname, "No possible request");
__currentState = STATE__STOP__STATE;
break;
}
__returnRequest = executeListOfRequests(&__list);
clearListOfRequests(&__list);
traceRequest(__myname, __returnRequest);
if (__returnRequest == &__req0) {
speed = Motor2__runmotor(speed, flagA);
traceVariableModification("Motor2", "speed", speed,0);
__currentState = STATE__WaitingForMotorCommand;
}
else if (__returnRequest == &__req1) {
speed = Motor2__modify_motor(speed, factor, flagA, flagB);
traceVariableModification("Motor2", "speed", speed,0);
__currentState = STATE__WaitingForMotorCommand;
}
else if (__returnRequest == &__req2) {
Motor2__turn(flag, deg);
__currentState = STATE__WaitingForMotorCommand;
}
break;
}
}
//printf("Exiting = %s\n", __myname);
return NULL;
}