You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. #include "tjc_screen_receive.h"
  2. #include "tick.h"
  3. #include <string.h>
  4. #include <stdio.h>
  5. /***********************************************************************************************************************
  6. * ݱ *
  7. ***********************************************************************************************************************/
  8. static uint8_t rxbuf[BUF_MAX_LEN];
  9. static uint8_t rxCache;
  10. static uint16_t size;
  11. static uint32_t ticktime;
  12. static UART_HandleTypeDef* m_uart;
  13. static uint8_t rxCache;
  14. void tjc_receive_init(UART_HandleTypeDef* uart) {
  15. HAL_UART_Receive_IT(uart, &rxCache, 1);
  16. m_uart = uart;
  17. }
  18. /*
  19. *
  20. * @brief ݽ
  21. *
  22. */
  23. void tjc_uart_receive(void) {
  24. if (size >= BUF_MAX_LEN) {
  25. return;
  26. }
  27. rxbuf[size] = rxCache;
  28. size++;
  29. ticktime = HAL_GetTick();
  30. }
  31. void tjc_date_pack(packet_t* packet) {
  32. if (size != 0 && pass_time(ticktime) > OVERTIME) {
  33. __disable_irq();
  34. if (size != 0 && pass_time(ticktime) > OVERTIME) {
  35. printf("buf:%s\n", rxbuf);
  36. memcpy(packet->date, rxbuf, sizeof(packet->date));
  37. packet->len = size;
  38. memset(rxbuf, 0, sizeof(rxbuf));
  39. size = 0;
  40. }
  41. __enable_irq();
  42. }
  43. }