Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Fonction qu'il faisait boucler à l'infini, maintenant c'est une interruption.
- //ça récupère un caractère dans la COM (com_read_byte) et ça le colle dans la fifo
- void Com_IsrRx(void* context, alt_u32 id)
- {
- int irqContext;
- char cByte;
- irqContext = alt_irq_disable_all();
- while(TRUE)
- {
- if(!COM_read_byte(&cByte))
- {
- break;
- }
- else
- {
- COM_FIFO_Write(cByte, &COM_FIFO_Object);
- }
- }
- alt_irq_enable_all(irqContext);
- }
- //j'ai ajouté "ce petit truc" pour tester l'intégrité des message... "Ho, 95% d'erreurs en moins !"
- BOOL COM_decode_state(TypeState_CharDecode *DecodeState,char *MsgBuffer, char cbyte, BOOL *bError)
- {
- BOOL bReady = FALSE;
- *bError = FALSE;
- switch(DecodeState->NextState)
- {
- case Char_StartOfText :
- if(cbyte==Char_STX)
- DecodeState->NextState = Char_LengthLow;
- else *bError = TRUE;
- break;
- case Char_LengthLow :
- DecodeState->MsgLen = cbyte;
- DecodeState->NextState = Char_LengthHigh;
- break;
- case Char_LengthHigh :
- DecodeState->MsgLen = DecodeState->MsgLen + (((unsigned int)cbyte)<<8);
- //printf("MsgLen = %d\n", DecodeState->MsgLen);
- if ((DecodeState->MsgLen > 0) && (DecodeState->MsgLen < 15 /*Char_MAX_BUFFER*/))
- {
- DecodeState->DataBytes = 0;
- DecodeState->Ccs = 0;
- if (MsgBuffer == (char *)NULL)
- *bError = TRUE;
- else
- {
- DecodeState->NextState =Char_Data;
- }
- }
- else
- *bError = TRUE + 1;
- break;
- case Char_Data:
- if (!((cbyte<='z' && cbyte>='a') || (cbyte<='Z' && cbyte>='A') || (cbyte<='9' && cbyte>='0') || cbyte == ':' || cbyte == ',')) *bError = TRUE;
- MsgBuffer[DecodeState->DataBytes] = cbyte;
- DecodeState->Ccs += cbyte;
- DecodeState->DataBytes++;
- if (DecodeState->DataBytes >= DecodeState->MsgLen)
- {DecodeState->NextState = Char_Ccs;
- //printf("End of message\n");
- }
- break;
- case Char_Ccs:
- if (DecodeState->Ccs == (unsigned char)cbyte)
- DecodeState->NextState = Char_EndOfText;
- else
- *bError = TRUE + 2;
- break;
- case Char_EndOfText:
- if (cbyte == Char_ETX)
- {
- MsgBuffer[DecodeState->DataBytes] = 0x00;
- bReady = TRUE;
- }
- else
- *bError = TRUE + 3;
- DecodeState->NextState = Char_StartOfText;
- break;
- }
- if(*bError)
- {
- DecodeState->MsgLen = 0 ;
- DecodeState->Ccs = 0;
- DecodeState->NextState = Char_StartOfText;
- }
- return bReady;
- }
Add Comment
Please, Sign In to add comment