其中根据命令执行控制灯程序为:<p>static uint16_t Commandcmp(uint8_t* pCommand1, uint8_t* pCommand2, uint16_t CommandLength) //命令比较函数,其实字符串比较
{
while (CommandLength)
{
if ((*pCommand1) != *pCommand2)
{
return CommandLength;
}
pCommand1++;
pCommand2++;</p><p> CommandLength--;
}
return 0;
}
static uint16_t CommandHandle(uint8_t* Command) //命令处理
{
if (Commandcmp(Command, (uint8_t *)Command_Lib[0], RXBUFFERSIZE) == 0) //亮灯
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
return 1;
}
else if (Commandcmp(Command, (uint8_t *)Command_Lib[1], RXBUFFERSIZE) == 0) //灭灯
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
return 1;
}
else if (Commandcmp(Command, (uint8_t *)Command_Lib[2], RXBUFFERSIZE) == 0) //反转灯
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
return 1;
}
else if (Commandcmp(Command, (uint8_t *)Command_Lib[3], RXBUFFERSIZE) == 0) //查询状态
{
if ((GPIOA->ODR & GPIO_PIN_5) != (uint32_t)GPIO_PIN_RESET)
{
return 2; //亮
}
else
{
return 3;//灭
}
}
else
{
return 0;//无法识别命令
}
}</p>
|