user_setup.c
13.1 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#include "user_setup.h"
#define SETUP_UART_ID COM1
unsigned long *pSetup;
unsigned long setupMaxCount;
unsigned char ParameterNameStr[] = //数据内容暂时未定,以下只供参考,和当前并参数不对应。
{
"0- 导航方式:0.磁 条,1.二维码,2,SLAM, 3Vslam\r\n"
"1- 转向方式:0.单差速,1.双转向架差速,2.单舵轮,3.双舵轮,4三舵轮,5.四舵轮,6.改造转向轮\r\n"
"2- 角度编码器个数:0.0个,1.1个,2.2个,3.3个,4.4个\r\n"
"3- 角度编码器方向调整:0000.角度编码器方向不调整,1000.ID为0x10编码器方向反向,1100.ID为0x10和0x11编码器方向反向,1110.ID为0x10、0x11和0x12编码器方向反向,1111.4个行走都方向反向\r\n"
"4- 导引传感器方向调整:0000.传感器方向不调整,1000.前传感器方向反向,1100.前后传感器方向反向,1110前后左传感器方向反向,1111所有传感器方向反向\r\n"
"5- 拉线编码器个数:0.0个,1.1个,2.2个,3.3个,4.4个\r\n"
"6- 行走电机个数:0.0个,1.1个,2.2个,3.3个,4.4个\r\n"
"7-行走转速比分子\r\n"
"8-行走转速比分母\r\n"
"9-行走位置比分子\r\n"
"10-行走位置比分母\r\n"
"11-行走can线接法:0000.行走轮全接CAN1,1000.ID为1行走接CAN2,1100.ID为1和2的行走接CAN2,1110.ID为1、2和3的行走接CAN2,1111.4个行走都接CAN2\r\n"
"12-行走轮方向调整:0000.行走轮方向不调整,1000.ID为1行走方向反向,1100.ID为1和2的行走方向反向,1110.ID为1、2和3的行走方向反向,1111.4个行走都方向反向\r\n"
"13-转向电机个数:0.0个,1.1个,2.2个,3.3个,4.4个\r\n"
"14-转向转速比分子\r\n"
"15-转向转速比分母\r\n"
"16-转向位置比分子\r\n"
"17-转向位置比分母\r\n"
"18-转向can线接法:0000.转向全接CAN1,1000.ID为5转向接CAN2,1100.ID为5和6的转向接CAN2,1110.ID为5、6和7的转向接CAN2,1111.4个转向都接CAN2\r\n"
"19-转向方向调整:0000.转向方向不调整,1000.ID为5转向方向反向,1100.ID为5和6的转向方向反向,1110.ID为5、6和7的转向方向反向,1111.4个转向都方向反向\r\n"
"20-举升电机个数:0.0个,1.1个,2.2个,3.3个,4.4个\r\n"
"21-举升转速比分子\r\n"
"22-举升转速比分母\r\n"
"23-举升位置比分子\r\n"
"24-举升位置比分母\r\n"
"25-举升can线接法:0000.举升全接CAN1,1000.ID为9举升接CAN2,1100.ID为9和10的举升接CAN2,1110.ID为9、10和11的举升接CAN2,1111.4个举升都接CAN2\r\n"
"26-举升方向调整:0000.举升方向不调整,1000.ID为9举升方向反向,1100.ID为9和10的举升方向反向,1110.ID为9、10和11的举升方向反向,1111.4个举升都方向反向\r\n"
"27-移轴电机个数:0.0个,1.1个,2.2个,3.3个\r\n"
"28-移轴转速比分子\r\n"
"29-移轴转速比分母\r\n"
"30-移轴位置比分子\r\n"
"31-移轴位置比分母\r\n"
"32-移轴can线接法:0000.举升全接CAN1,1000.ID为12举升接CAN2,1100.ID为12和13的举升接CAN2,1110.ID为12、13和14的举升接CAN2,1111.4个举升都接CAN2\r\n"
"33-移轴方向调整:0000.举升方向不调整,1000.ID为12举升方向反向,1100.ID为12和13的举升方向反向,1110.ID为12、13和14的举升方向反向,1111.4个举升都方向反向\r\n"
"34-推杆电机个数:0.0个,1.1个,2.2个,3.3个\r\n"
"35-推杆转速比分子\r\n"
"36-推杆转速比分母\r\n"
"37-推杆位置比分子\r\n"
"38-推杆位置比分母\r\n"
"39-推杆can线接法:0000.举升全接CAN1,1000.ID为12举升接CAN2,1100.ID为12和13的举升接CAN2,1110.ID为12、13和14的举升接CAN2,1111.4个举升都接CAN2\r\n"
"40-推杆方向调整:0000.举升方向不调整,1000.ID为12举升方向反向,1100.ID为12和13的举升方向反向,1110.ID为12、13和14的举升方向反向,1111.4个举升都方向反向\r\n"
"41-行走驱动品牌:0.兴颂BLD2L ,1.步科 ,2.风得控 3.兴颂BL30 ,255.非can通讯\r\n"
"42-转向驱动品牌:0.兴颂BLD2L ,1.步科 ,2.风得控 3.兴颂BL30 ,255.非can通讯\r\n"
"43-举升驱动品牌:0.兴颂BLD2L ,1.步科 ,2.风得控 3.兴颂BL30 ,255.非can通讯\r\n"
"44-移轴驱动品牌:0.兴颂BLD2L ,1.步科 ,2.风得控 3.兴颂BL30 ,255.非can通讯\r\n"
"45-推杆驱动品牌:0.兴颂BLD2L ,1.步科 ,2.风得控 3.兴颂BL30 ,255.非can通讯\r\n"
"\r\n"
"1IP地址为和车上PLC通讯地址\r\n"
"46-控制器1IP地址-192\r\n"
"47-控制器1IP地址-168\r\n"
"48-控制器1IP地址-0\r\n"
"49-控制器1IP地址-30\r\n"
"\r\n"
"2IP地址为和NAV通讯地址\r\n"
"50-控制器2IP地址-192\r\n"
"51-控制器2IP地址-168\r\n"
"52-控制器2IP地址-0\r\n"
"53-控制器2IP地址-30\r\n"
"\r\n"
"3IP地址预留\r\n"
"54-控制器3IP地址-192\r\n"
"55-控制器3IP地址-168\r\n"
"56-控制器3IP地址-0\r\n"
"57-控制器3IP地址-30\r\n"
"\r\n"
"4IP地址预留\r\n"
"58-控制器4IP地址-192\r\n"
"59-控制器4IP地址-168\r\n"
"60-控制器4IP地址-0\r\n"
"61-控制器4IP地址-30\r\n"
"62-雷达到运动中心X距离(mm)\r\n"
"63-雷达到运动中心Y距离(mm)\r\n"
"64-雷达和车体前进方向夹角(0.1度)(-45.0°写成3150对应315.0°)\r\n"
"65-双舵轮X方向距离(mm)\r\n"
"66-双舵轮Y方向距离(mm)\r\n"
"98-电池类型,1冠宇电池\r\n"
"99-平台类型,1悬臂轴,2双层SMT \r\n"
};
void initSetup(unsigned long *pStart,unsigned long len)
{
pSetup = pStart;
setupMaxCount = len;
}
unsigned long Setup_GetValue(unsigned char *nameStrInput,unsigned char *valueBufOutput)
{
unsigned char *pInput,*pOutput;
unsigned char indexBuf[200];
unsigned char Index_Step = 0;
unsigned long index = 0;
unsigned long offset = 0;
unsigned long value;
unsigned char nameStrEnd = 0;
pInput = nameStrInput;
pOutput = valueBufOutput;
while(*pInput)
{
if((pInput[0] == '\r') || (pInput[0] == '\n'))
{
break;
}
else if(pInput[0] == ':')
{
nameStrEnd = 1;
}
if((Index_Step != 2) && (pInput[0] >= '0') && (pInput[0] <= '9'))
{
Index_Step = 1;
}
else if(Index_Step == 1)
{
Index_Step = 2;
}
if(Index_Step == 1)
{
indexBuf[offset] = pInput[0];
offset++;
if(offset > 5)
{
Index_Step = 3;
break;
}
}
if(nameStrEnd != 1)
{
pOutput[0] = pInput[0];
pOutput++;
}
pInput++;
}
if(Index_Step == 2)
{
indexBuf[offset] = 0;
sscanf((const char *)indexBuf, "%lu", &index);
value = pSetup[index];
sprintf((char*)pOutput, ":%lu\r\n",value);
}
else
{
valueBufOutput[0] = 0;
}
while((pInput[0] == '\r') || (pInput[0] == '\n'))
{
pInput++;
}
return pInput - nameStrInput;
}
void Setup_Process(void)
{
int i = 0;
unsigned long len = 0;
unsigned char ch;
unsigned char CMD_Step = 0;
unsigned char num_Buffer[10] = {0};
unsigned char num_Len = 0;
unsigned char data_Buffer[10] = {0};
unsigned char data_Len = 0;
unsigned long index;
unsigned long data;
unsigned char *pNameStr;
unsigned char StrBuf[64];
Uart_Printf(SETUP_UART_ID,"\r\n<- - - - - - - - - - ->已进入参数修改任务<- - - - - - - - - - ->\r\n\r\n");
Uart_Printf(SETUP_UART_ID,"查看参数名 -n\r\n");
Uart_Printf(SETUP_UART_ID,"查看参数值 -v\r\n");
Uart_Printf(SETUP_UART_ID,"导出参数值 -e\r\n");
Uart_Printf(SETUP_UART_ID,"查看帮助 -h\r\n");
Uart_Printf(SETUP_UART_ID,"修改参数 参数序号-参数值\r\n");
Uart_Printf(SETUP_UART_ID,"保存参数 -s\r\n");
Uart_Printf(SETUP_UART_ID,"退出 -q\r\n\r\n");
while(1)
{
if(ReadUart(COM1,&ch,1))
{
if((ch == '-') || (ch == 's') || (ch == 'S') || (ch == 'n') || (ch == 'N') || (ch == 'v') || (ch == 'V') || (ch == 'e') || (ch == 'E') || (ch == 'h') || (ch == 'H') || (ch == 'q') || (ch == 'Q') || ((ch >= '0') && (ch <= '9')) || (ch == '\r') || (ch == '\n'))
{
if( (ch == '\r') || (ch == '\n'))
{
Uart_Printf(SETUP_UART_ID,"\r\n");
}
else
{
Uart_Printf(SETUP_UART_ID,"%c",ch);//合法字符则回显
}
if(CMD_Step == 0)//开始输入
{
if(ch == '-')
{
CMD_Step = 1;
}
else if((ch >= '0') && (ch <= '9'))
{
num_Buffer[0] = ch;
num_Len = 1;
data_Len = 0;
CMD_Step = 2;
}
}
else if(CMD_Step == 1)//命令
{
if((ch == 'n') || (ch == 'N'))
{
Uart_Printf(SETUP_UART_ID,"\r\n");
i = 0;
//需要输出的字符串过长,按单个字符发送,防止溢出
while(1)
{
if(ParameterNameStr[i])
{
Uart_Printf(SETUP_UART_ID,"%c",ParameterNameStr[i]);
bsp_DelayMS(2);
}
else
{
break;
}
i++;
}
//显示所有参数名
}
else if((ch == 'v') || (ch == 'V'))
{
Uart_Printf(SETUP_UART_ID,"\r\n");
pNameStr = ParameterNameStr;
len = 0;
while(1)
{
len = Setup_GetValue(pNameStr,StrBuf);
if(len == 0)
{
break;
}
pNameStr += len;
Uart_Printf(SETUP_UART_ID,(const char*)StrBuf);
bsp_DelayMS(2);
}
//显示所有参数值
}
else if((ch == 'e') || (ch == 'E'))
{
Uart_Printf(SETUP_UART_ID,"\r\n");
for(i = 0; i < setupMaxCount; i++)
{
Uart_Printf(SETUP_UART_ID,"%d-%d\r\n",i,pSetup[i]);
bsp_DelayMS(2);
}
//显示所有参数值
}
else if((ch == 'h') || (ch == 'H'))
{
Uart_Printf(SETUP_UART_ID,"\r\n");
//显示帮助信息
}
else if((ch == 'q') || (ch == 'Q'))
{
Uart_Printf(SETUP_UART_ID,"\r\n退出参数设置\r\n");
break;
}
else if((ch == 's') || (ch == 'S'))
{
PowerOff_ClearConstFlash();
PowerOn_WriteFlash_ConstData();
PowerOn_ReadFlash_ConstData();
Uart_Printf(SETUP_UART_ID,"\r\n");
for(i = 0; i < setupMaxCount; i++)
{
Uart_Printf(SETUP_UART_ID,"%d-%d\r\n",i,pSetup[i]);
bsp_DelayMS(1);
}
}
else
{
Uart_Printf(SETUP_UART_ID,"\r\n警告: 输入异常,请重新输入\r\n");
}
CMD_Step = 0;
}
else if(CMD_Step == 2)//参数,序号
{
if((ch >= '0') && (ch <= '9'))
{
num_Buffer[num_Len] = ch;
num_Len++;
if(num_Len > 3)//参数序号超过3位数
{
Uart_Printf(SETUP_UART_ID,"\r\n警告: 输入异常,请重新输入\r\n");
num_Len = 0;
data_Len = 0;
CMD_Step = 0;
}
}
else if(ch == '-')
{
num_Buffer[num_Len] = 0;
CMD_Step = 3;
}
}
else if(CMD_Step == 3)//参数,值
{
if((ch >= '0') && (ch <= '9'))
{
data_Buffer[data_Len] = ch;
data_Len++;
if(data_Len > 9)//参数序号超过3位数
{
Uart_Printf(SETUP_UART_ID,"\r\n警告: 输入异常,请重新输入\r\n");
num_Len = 0;
data_Len = 0;
CMD_Step = 0;
}
}
else if((ch == '\r') || (ch == '\n'))
{
data_Buffer[data_Len] = 0;
CMD_Step = 4;
}
else
{
Uart_Printf(SETUP_UART_ID,"\r\n警告: 输入异常,请重新输入\r\n");
num_Len = 0;
data_Len = 0;
CMD_Step = 0;
}
}
if(CMD_Step == 4)//参数输入结束
{
sscanf((const char *)num_Buffer, "%lu", &index);
sscanf((const char *)data_Buffer, "%lu", &data);
if(index < setupMaxCount)
{
pSetup[index] = data;
}
else
{
Uart_Printf(SETUP_UART_ID,"\r\n警告: 参数序号超出范围,请重新输入\r\n");
}
//参数写入
num_Len = 0;
data_Len = 0;
CMD_Step = 0;
}
}
}
}
}