-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameters.c
More file actions
317 lines (265 loc) · 9.57 KB
/
Parameters.c
File metadata and controls
317 lines (265 loc) · 9.57 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/****************************************************************/
/* Parameters list */
/* File : Parameters.c */
/* Description : */
/* Global Parameters list for internal and external com */
/* */
/* Author : MPE */
/* */
/****************************************************************/
#include "includes.h"
const char SOFT_VER[] = "0.1.0";
const char PARAM_VER[] = "1.2";
t_Param Params;
static t_paramblock const p_rec_Info =
{
1, /* Parameter ID */
&Params.Info, /* Pointer to parameter value(s) in table 1 */
64, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_Analog_Values =
{
2, /* Parameter ID */
&Params.Analog_Values, /* Pointer to parameter value(s) in table 1 */
14, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_LeftMotorCommand =
{
3, /* Parameter ID */
&Params.LeftMotorCommand, /* Pointer to parameter value(s) in table 1 */
4, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_RightMotorCommand =
{
4, /* Parameter ID */
&Params.RightMotorCommand, /* Pointer to parameter value(s) in table 1 */
4, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_CommandReg =
{
5, /* Parameter ID */
&Params.CommandReg, /* Pointer to parameter value(s) in table 1 */
10, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_StatusReg =
{
6, /* Parameter ID */
&Params.StatusReg, /* Pointer to parameter value(s) in table 1 */
10, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_FailureReg =
{
7, /* Parameter ID */
&Params.FailureReg, /* Pointer to parameter value(s) in table 1 */
2, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_PConfIRDistanceDetect =
{
8, /* Parameter ID */
&Params.ProtectionConf.IRDistanceDetect, /* Pointer to parameter value(s) in table 1 */
8, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_PConfVoltageBatteryDetect =
{
9, /* Parameter ID */
&Params.ProtectionConf.VoltageBatteryDetect, /* Pointer to parameter value(s) in table 1 */
8, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_PConfVoltage12VDetect =
{
10, /* Parameter ID */
&Params.ProtectionConf.Voltage12VDetect, /* Pointer to parameter value(s) in table 1 */
8, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_PConfCPUTemperatureDetect =
{
11, /* Parameter ID */
&Params.ProtectionConf.CPUTemperatureDetect, /* Pointer to parameter value(s) in table 1 */
8, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_PConfAuxTemperatureDetect =
{
12, /* Parameter ID */
&Params.ProtectionConf.AuxTemperatureDetect, /* Pointer to parameter value(s) in table 1 */
8, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_XMotorCommand =
{
13, /* Parameter ID */
&Params.XMotorCommand, /* Pointer to parameter value(s) in table 1 */
4, /* Size in bytes */
0, /* Security and storage flags */
};
static t_paramblock const p_rec_YMotorCommand =
{
14, /* Parameter ID */
&Params.YMotorCommand, /* Pointer to parameter value(s) in table 1 */
4, /* Size in bytes */
0, /* Security and storage flags */
};
const t_paramblock* ParamMap[] = {
&p_rec_Info,
&p_rec_Analog_Values,
&p_rec_LeftMotorCommand,
&p_rec_RightMotorCommand,
&p_rec_CommandReg,
&p_rec_StatusReg,
&p_rec_FailureReg,
&p_rec_PConfIRDistanceDetect,
&p_rec_PConfVoltageBatteryDetect,
&p_rec_PConfVoltage12VDetect,
&p_rec_PConfCPUTemperatureDetect,
&p_rec_PConfAuxTemperatureDetect,
&p_rec_XMotorCommand,
&p_rec_YMotorCommand,
NULL
};
/*** Parameter Initializations ***/
CPU_VOID Init_Params()
{
strcpy((char *)Params.Info.SoftVersion,SOFT_VER);
strcpy((char *)Params.Info.ParamVersion,PARAM_VER);
#if defined (Win32)
sprintf((char *)Params.Info.SoftVersion,"%s emulator",Params.Info.SoftVersion);
#endif
Params.Analog_Values.LongIRDistance = 0;
Params.Analog_Values.ShortIRDistance = 0;
Params.Analog_Values.VoltageBattery = 0;
Params.Analog_Values.Voltage12V = 0;
Params.Analog_Values.CPUTemperature = 0;
Params.Analog_Values.AuxTemperature = 0;
Params.LeftMotorCommand.Speed = 0;
Params.LeftMotorCommand.Steps = 0;
Params.RightMotorCommand.Speed = 0;
Params.RightMotorCommand.Steps = 0;
Params.CommandReg.Manual = 0;
Params.CommandReg.LineFollow = 0;
Params.CommandReg.Survey = 0;
Params.CommandReg.UDPLiveFeed = 0;
Params.CommandReg.MovementMotorEnable = 0;
Params.CommandReg.TurretMotorEnable = 0;
Params.CommandReg.MoveDirection = 0;
Params.CommandReg.MoveDuration = 0;
Params.StatusReg.Manual = 0;
Params.StatusReg.LineFollow = 0;
Params.StatusReg.Survey = 0;
Params.StatusReg.UDPLiveFeed = 0;
Params.StatusReg.MovementMotorEnable = 0;
Params.StatusReg.TurretMotorEnable = 0;
Params.StatusReg.MoveDirection = 0;
Params.StatusReg.MoveDuration = 0;
Params.FailureReg.global_1.all = 0;
Params.ProtectionConf.IRDistanceDetect.DetectionThreshold = 0;
Params.ProtectionConf.IRDistanceDetect.CompDirection = -1;
Params.ProtectionConf.IRDistanceDetect.TimeWindow = 100;
Params.ProtectionConf.IRDistanceDetect.ConfThreshold = 80;
Params.ProtectionConf.VoltageBatteryDetect.DetectionThreshold = 4500;
Params.ProtectionConf.VoltageBatteryDetect.CompDirection = -1;
Params.ProtectionConf.VoltageBatteryDetect.TimeWindow = 100;
Params.ProtectionConf.VoltageBatteryDetect.ConfThreshold = 80;
Params.ProtectionConf.Voltage12VDetect.DetectionThreshold = 10000;
Params.ProtectionConf.Voltage12VDetect.CompDirection = -1;
Params.ProtectionConf.Voltage12VDetect.TimeWindow = 100;
Params.ProtectionConf.Voltage12VDetect.ConfThreshold = 80;
Params.ProtectionConf.CPUTemperatureDetect.DetectionThreshold = 80;
Params.ProtectionConf.CPUTemperatureDetect.CompDirection = 1;
Params.ProtectionConf.CPUTemperatureDetect.TimeWindow = 1000;
Params.ProtectionConf.CPUTemperatureDetect.ConfThreshold = 800;
Params.ProtectionConf.AuxTemperatureDetect.DetectionThreshold = 20;
Params.ProtectionConf.AuxTemperatureDetect.CompDirection = 1;
Params.ProtectionConf.AuxTemperatureDetect.TimeWindow = 1000;
Params.ProtectionConf.AuxTemperatureDetect.ConfThreshold = 800;
Params.XMotorCommand.Speed = 10;
Params.XMotorCommand.Steps = 0;
Params.YMotorCommand.Speed = 10;
Params.YMotorCommand.Steps = 0;
}
/********************************************//**
* \brief
*
* \param paramID CPU_INT16U
* \return CPU_INT08U*
*
***********************************************/
CPU_INT08U* GetPointerFromParamID(CPU_INT16U paramID)
{
const t_paramblock* param = NULL;
CPU_INT16U i;
// Search for the parameter record
for (i = 0; i < e_NumberOfParam; i++)
{
if (ParamMap[i]->id == paramID)
{
param = ParamMap[i];
break;
}
}
return (CPU_INT08U*)param->pValue;
}
/********************************************//**
* \brief
*
* \param paramID CPU_INT16U
* \param paramValues const CPU_INT16U*
* \return CPU_VOID
*
***********************************************/
CPU_VOID SetValueFromParamID(CPU_INT16U paramID, const CPU_INT08U* paramValues)
{
const t_paramblock* param = NULL;
CPU_INT16U i;
// Search for the parameter record
for (i = 0; i < e_NumberOfParam; i++)
{
if (ParamMap[i]->id == paramID)
{
param = ParamMap[i];
break;
}
}
memcpy((CPU_VOID*)param->pValue, paramValues, param->psize);
}
/********************************************//**
* \brief
*
* \param paramID CPU_INT16U
* \return CPU_INT16U
*
***********************************************/
CPU_INT16U GetSizeFromParamID(CPU_INT16U paramID)
{
const t_paramblock* param = NULL;
CPU_INT16U i;
CPU_INT16U ret = 0;
// Search for the parameter record
for (i = 0; i < e_NumberOfParam; i++)
{
if (ParamMap[i]->id == paramID)
{
param = ParamMap[i];
break;
}
}
if(param != NULL)
{
// something has been found
ret = param->psize;
}else
{
// nothing found
ret = 0;
}
return ret;
}