Ejemplo n.º 1
0
void MavSerialPort::uartRead(QByteArray* ba){
    unsigned char *buf;
    buf = (unsigned char*)ba->data();

    //kernel part of the code
    for(int i = 0 ; i < ba->size(); i++){
        //does it matter if i change it to COMM_0 ?
        msgReceived = mavlink_parse_char(MAVLINK_COMM_1, buf[i], &message, &status);
        if(msgReceived){
            uartDecode(message);
            msgReceived = false;
        }
    }
}
Ejemplo n.º 2
0
void USART1_IRQHandler(void)
{
	static u16 receiveCounter = 0;
	static u8 temp,flagStart = 0;
	
	if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
	{
		USART_ClearITPendingBit(USART1,USART_IT_RXNE);
		
		temp = USART_ReceiveData(USART1);
		if(flagStart == 1)
		{
			receiveBuffer[receiveCounter] = temp;
			receiveCounter ++;
            
			if(receiveCounter == receiveBuffer[3])
			{
				flagStart = 0;
				receiveCounter = 0;
				uartDecode();
			}
            /* 最长的报文长度为12 */
            else if (receiveCounter > 12)
            {
                receiveCounter = 0;
                flagStart = 0;
            }
		}
		else if(temp == 0x7f)
		{
			flagStart = 1;
			receiveBuffer[receiveCounter] = temp;
			receiveCounter ++;
		}
	}
}