user_setup.c 13.1 KB
#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;                    
                }
            }
	    }
	}		
}