/***************************************************************** ;Project: Light ;MCU: ;Date: ;File: ;Function: ******************************************************************/ #include "uartdate.h" #include "uart.h" /*---------------------------------------------------------------*/ //变量定义 //Uart_Rx_Buf_t uart_rx_buf; //static unsigned char Rx_Pack[DATA_MAXSIZE]; //接收数据帧打包 /*---------------------------------------------------------------*/ //函数声明 //static void Command_Execute(unsigned char *Buff); ///*---------------------------------------------------------------*/ ////外部变量调用声明 //extern unsigned short cycSpeed; //骑行速度 //extern unsigned char cycReSpeedFlag; //骑行速度刷新标志 ///*---------------------------------------------------------------*/ ////串口初始化 //void Uart_Init(void) //{ // uart_1_init(); //} ///*---------------------------------------------------------------*/ ////串口接收回调函数 //void uartRx_callback(void) //{ // uint8_t cnt,i,temp[4]; // uart_1_read(&cnt,temp); // // for(i=0;i= MAX_RX_LENGTH) // { // uart_rx_buf.header = 0; // } // } //} /*---------------------------------------------------------------*/ //发送数据 //static void uart_cmd(uint8_t *p_cmd, uint8_t sz) //{ // unsigned char i; // // for(i=0; i DATA_MAXSIZE) //判断数据长度是否异常 // { // state = 0; //重新寻找帧头 // break; // } // Rx_Pack[Rx_Pack_Index++] = uart_rx_buf.data[uart_rx_buf.tail]; //接收帧的剩余长度 // state = 3; // break; // // case 3: //判断一帧结束 // Rx_Pack[Rx_Pack_Index++] = uart_rx_buf.data[uart_rx_buf.tail]; // //--判断是否接收到想要的帧长 // if( Rx_Pack_Index >= (Rx_Pack_Len+2) ) //2:1个起始字符和1个数据长度字符 // { // state = 0; //失能帧接收标志 // Command_Execute(Rx_Pack); //指令执行 // } // break; // // default: state = 0;break; // // } // // uart_rx_buf.tail++; // if(uart_rx_buf.tail >= MAX_RX_LENGTH) // { // uart_rx_buf.tail = 0; // } // // } //} /*---------------------------------------------------------------*/ //解析骑行速度 //static void Command_Execute(unsigned char *Buff) // 指令处理 //{ // static unsigned short LastcycSpeed = 0; // // if(Buff[2] == 0x0C) //0x0C:判断是不是电机的应答帧 // { // if(Buff[3]==0x01) //判断是否查询成功 // if(Buff[4]==0xBF) //判断是否查询成功 // if(Buff[5]==0x02) //判断是否为2个字节的速度 // { // //转换成速度 // LastcycSpeed = cycSpeed; // cycSpeed = ((unsigned short )Buff[6]<<8) + (unsigned short)Buff[7]; //把这两个字节拼接成速度,eg:(0x12,0x34)->(0x1234)->(4660) // cycSpeed = cycSpeed/10; //过滤小数部分,(4660)->(466.0) // if((LastcycSpeed == 0)&&(cycSpeed > 10)) // { // cycSpeed = 1; // } // cycReSpeedFlag = 1; // } // } //} /*---------------------------------------------------------------*/