-
Notifications
You must be signed in to change notification settings - Fork 1
/
Commands.c
186 lines (169 loc) · 5.6 KB
/
Commands.c
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
101
102
103
104
105
106
107
108
109
110
111
112
113
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//----------------------------------------------------------------------------
//Модуль реализации выполнения команд Wake
//----------------------------------------------------------------------------
#include "Commands.h"
//----------------------------------------------------------------------------
//------------------------------- Переменные: --------------------------------
const char Info[] = {"MDR32F9Q2 Rev2.0\n\0"}; //имя устройства
extern char Rx_Cmd, //принятая команда
Rx_Nbt, //принятое количество байт в пакете
Rx_Dat[FRAME]; //массив принятых данных
extern char Command; //код принятой команды на выполнение
extern char Tx_Cmd, //команда, передаваемая в пакете
Tx_Nbt, //количество байт данных в пакете
Tx_Dat[FRAME]; //массив данных для передачи
bool _powerStatus = false;
bool _lightStatus = false;
bool _highTemperature = false;
bool _hookWarning = false;
bool _currentMode = true; //Опоры или Cтойка, стрела, лебедка (1/0)
//----------------------------------------------------------------------------
//---------------------- Передача ответа на команду: -------------------------
void Tx_Replay(char n, char err)
{
Tx_Nbt = n; //количество байт
Tx_Dat[0] = err; //код ошибка
Tx_Cmd = Command; //команда
Port_StartWrite(); //инициализация передачи
Command = CMD_NOP; //команда обработана
}
//---------------------------- Выполнение команд: ----------------------------
void Commands_Exe(void)
{
char i;
switch(Command)
{
case CMD_ERR: //обработка ошибки
{
Tx_Replay(1, ERR_TX);
break;
}
case CMD_ECHO: //команда "эхо"
{
for(i = 0; i < Rx_Nbt && i < FRAME; i++)
Tx_Dat[i] = Rx_Dat[i];
Tx_Replay(Rx_Nbt, Tx_Dat[0]);
break;
}
case CMD_INFO: //команда "инфо"
{
char ch = 1;
for(i = 0; i < FRAME && ch; i++)
ch = Tx_Dat[i] = Info[i];
Tx_Replay(i, Tx_Dat[0]);
break;
}
case soundSignal: //гудок
{
//if(Rx_Dat[0] == 1) "гудим" else "не гудим";
//Tx_Replay(1, ERR_NO);
break;
}
case speedButton: //скорость
{
//if(Rx_Dat[0] == 1) "быстро" else "медленно";
//Tx_Replay(1, ERR_NO);
break;
}
case modeCrOrP: //режим работы (Опоры или Cтойка, стрела, лебедка)
{
//if(Rx_Dat[0] == 1) "Опоры" else "Cтойка, стрела, лебедка";
if(Rx_Dat[0] == 1 || Rx_Dat[0] == 0)
_currentMode = Rx_Dat[0];
Tx_Replay(1, _currentMode);
break;
}
case modeCrOrPStatus: //режим работы (Опоры или Cтойка, стрела, лебедка)
{
//if(Rx_Dat[0] == 1) "Опоры" else "Cтойка, стрела, лебедка";
//if(Rx_Dat[0] == 3)
Tx_Replay(1, _currentMode);
break;
}
case powerButton: //включить питание
{
if(Rx_Dat[0] == 1 || Rx_Dat[0] == 0)
_powerStatus=Rx_Dat[0];
Tx_Replay(1, _powerStatus);
break;
}
case powerStatus: //узнать включено ли питание
{
Tx_Replay(1, _powerStatus);
break;
}
case lightButton: //включить свет
{
if(Rx_Dat[0] == 1 || Rx_Dat[0] == 0)
_lightStatus=Rx_Dat[0];
Tx_Replay(1, _lightStatus);
break;
}
case lightStatus: //узнать включен ли свет
{
Tx_Replay(1, _lightStatus);
break;
}
case highTemperature: //узнать есть ли опасность перегрева РЖ
{
Tx_Replay(1, _highTemperature);
break;
}
case hookWarning: //узнать перекручен ли трос лебедки
{
Tx_Replay(1, _hookWarning);
break;
}
case pillar: //поворот стойки
{
//if(Rx_Dat[0] == ??) ... else ...;
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
case derrick: //подъем или опускание подъемной стрелы
{
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
case outrigger: //подъем или опускание выносной стрелы
{
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
case telescopic: //выдвижение или втягивание телескопической стрелы
{
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
case hook: //подъем или опускание лебедки
{
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
case leftCrutch: //подъем или опускание левой опоры
{
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
case rightCrutch: //подъем или опускание правой опоры
{
#if SEND_REPLY
Tx_Replay(1, ERR_NO);
#endif
break;
}
}
}
//----------------------------------------------------------------------------