Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. //Fonction qu'il faisait boucler à l'infini, maintenant c'est une interruption.
  2. //ça récupère un caractère dans la COM (com_read_byte) et ça le colle dans la fifo
  3. void Com_IsrRx(void* context, alt_u32 id)
  4. {
  5. int irqContext;
  6. char cByte;
  7.  
  8. irqContext = alt_irq_disable_all();
  9. while(TRUE)
  10. {
  11.  
  12. if(!COM_read_byte(&cByte))
  13. {
  14. break;
  15. }
  16. else
  17. {
  18. COM_FIFO_Write(cByte, &COM_FIFO_Object);
  19. }
  20. }
  21. alt_irq_enable_all(irqContext);
  22. }
  23.  
  24. //j'ai ajouté "ce petit truc" pour tester l'intégrité des message... "Ho, 95% d'erreurs en moins !"
  25.  
  26. BOOL COM_decode_state(TypeState_CharDecode *DecodeState,char *MsgBuffer, char cbyte, BOOL *bError)
  27. {
  28. BOOL bReady = FALSE;
  29.  
  30. *bError = FALSE;
  31.  
  32. switch(DecodeState->NextState)
  33. {
  34. case Char_StartOfText :
  35. if(cbyte==Char_STX)
  36. DecodeState->NextState = Char_LengthLow;
  37. else *bError = TRUE;
  38. break;
  39.  
  40. case Char_LengthLow :
  41. DecodeState->MsgLen = cbyte;
  42. DecodeState->NextState = Char_LengthHigh;
  43. break;
  44.  
  45. case Char_LengthHigh :
  46. DecodeState->MsgLen = DecodeState->MsgLen + (((unsigned int)cbyte)<<8);
  47. //printf("MsgLen = %d\n", DecodeState->MsgLen);
  48. if ((DecodeState->MsgLen > 0) && (DecodeState->MsgLen < 15 /*Char_MAX_BUFFER*/))
  49. {
  50. DecodeState->DataBytes = 0;
  51. DecodeState->Ccs = 0;
  52. if (MsgBuffer == (char *)NULL)
  53. *bError = TRUE;
  54. else
  55. {
  56. DecodeState->NextState =Char_Data;
  57. }
  58. }
  59. else
  60. *bError = TRUE + 1;
  61. break;
  62.  
  63. case Char_Data:
  64. if (!((cbyte<='z' && cbyte>='a') || (cbyte<='Z' && cbyte>='A') || (cbyte<='9' && cbyte>='0') || cbyte == ':' || cbyte == ',')) *bError = TRUE;
  65. MsgBuffer[DecodeState->DataBytes] = cbyte;
  66. DecodeState->Ccs += cbyte;
  67. DecodeState->DataBytes++;
  68. if (DecodeState->DataBytes >= DecodeState->MsgLen)
  69. {DecodeState->NextState = Char_Ccs;
  70. //printf("End of message\n");
  71. }
  72. break;
  73.  
  74. case Char_Ccs:
  75. if (DecodeState->Ccs == (unsigned char)cbyte)
  76. DecodeState->NextState = Char_EndOfText;
  77. else
  78. *bError = TRUE + 2;
  79. break;
  80.  
  81. case Char_EndOfText:
  82. if (cbyte == Char_ETX)
  83. {
  84. MsgBuffer[DecodeState->DataBytes] = 0x00;
  85. bReady = TRUE;
  86. }
  87. else
  88. *bError = TRUE + 3;
  89. DecodeState->NextState = Char_StartOfText;
  90. break;
  91. }
  92.  
  93. if(*bError)
  94. {
  95. DecodeState->MsgLen = 0 ;
  96. DecodeState->Ccs = 0;
  97. DecodeState->NextState = Char_StartOfText;
  98. }
  99.  
  100. return bReady;
  101.  
  102. }
Add Comment
Please, Sign In to add comment