/******************************************************************************
/ 函数功能:指令(ASCII或HEX指令)未处理消息回执
/ 修改日期:2013/9/12 20:25:45
/ 输入参数:none
/ 输出参数:none
/ 使用说明:一字节一字节接收数据,拼装为指令
******************************************************************************/
void Shell_Invalid_Service(void)
{
int tx_len,i,led_id,msg_id;
uint8_t * ptSrc;
uint8_t * ptDst;
uint8_t tmp_buff[64];
//指令识别
if(2 > shell_rx_rdy)
{
shell_rx_buff[0] = 0;
return;
}
else if( ('\r' == shell_rx_buff[shell_rx_rdy-2]) && ('\n' == shell_rx_buff[shell_rx_rdy-1]) )
{
ptSrc = (uint8_t *)shell_rx_buff;
if(2 == shell_rx_rdy)
{
//填写数据
tx_len = (uint16_t)sprintf((void *)tmp_buff,"\r\nAT:OK!\r\n");
//发送数据
shell_SendHex(tmp_buff,tx_len); //发送数据
}
else if(StrComp(ptSrc,"led rd\r\n")) //显示LED的信号配置
{
//填写数据
tx_len = (uint16_t)sprintf((void *)tmp_buff,
#if (6 == SHELL_LED_MAX)
"->LED0=%d LED1=%d tLED2=%d LED3=%d LED4=%d LED5=%d\r\n",
msg_led_cfg[0],msg_led_cfg[1],msg_led_cfg[2],
msg_led_cfg[3],msg_led_cfg[4],msg_led_cfg[5]);
#elif (5 == SHELL_LED_MAX)
"->LED0=%d LED1=%d tLED2=%d LED3=%d LED4=%d\r\n",
msg_led_cfg[0],msg_led_cfg[1],msg_led_cfg[2],
msg_led_cfg[3],msg_led_cfg[4]);
#elif (4 == SHELL_LED_MAX)
"->LED0=%d LED1=%d tLED2=%d LED3=%d\r\n",
msg_led_cfg[0],msg_led_cfg[1],msg_led_cfg[2],
msg_led_cfg[3]);
#elif (3 == SHELL_LED_MAX)
"->LED0=%d LED1=%d tLED2=%d\r\n",
msg_led_cfg[0],msg_led_cfg[1],msg_led_cfg[2]);
#elif (2 == SHELL_LED_MAX)
"->LED0=%d LED1=%d\r\n",
msg_led_cfg[0],msg_led_cfg[1]);
#elif (1 == SHELL_LED_MAX)
"->LED0=%d\r\n",
msg_led_cfg[0]);
#endif
//发送数据
shell_SendHex(tmp_buff,tx_len); //发送数据
}
else if(StrComp(ptSrc,"led wr ")) //设置LED的信号配置
{
if(2 != sscanf((void *)ptSrc,"%*s%*s%d=%d",&led_id,&msg_id) )goto ERROR_LOOP;
if( (led_id>(SHELL_LED_MAX-1)) || (msg_id >65535) )goto ERROR_LOOP;
Ledx_config((uint8_t)led_id,(uint16_t)msg_id); //配置信号
//填写数据
tx_len = (uint16_t)sprintf((void *)tmp_buff,
"->LED[%d]_Msg=%d\r\n",led_id,msg_led_cfg[led_id]);
//发送数据
shell_SendHex(tmp_buff,tx_len); //发送数据
}
else goto ERROR_LOOP;
}
else
{
ERROR_LOOP:
//填写指令码
tx_len = (uint16_t)sprintf((void *)tmp_buff,"\r\nAT: Cmd Error:\t\"");
//计算地址,填写数据,填写尾部
ptDst = tmp_buff + tx_len;
ptSrc = (uint8_t *)shell_rx_buff;
if(shell_rx_rdy > 32)
{
for(i=0; i<32; i++)
{
if( (*ptSrc > 126) || (*ptSrc < 32) )
{
*ptDst++ = '?';
ptSrc++;
}
else
{
*ptDst++ = *ptSrc++;
}
}
*(ptDst-2) = '-';
*(ptDst-1) = '>';
tx_len += 32;
}
else
{
for(i=0; i<shell_rx_rdy; i++)
{
*ptDst++ = *ptSrc++;
tx_len++;
}
*(ptDst-2) = '<';
*(ptDst-1) = '-';
}
tx_len += (uint16_t)sprintf((void *)ptDst,"\"\r\n");
//发送数据
shell_SendHex(tmp_buff,tx_len); //发送数据
}
//清除数据返回程序
shell_rx_buff[0] = 0;
shell_rx_rdy = 0;
}
|