uart.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * uart.h
  3. *
  4. * Author: Andrey Koryagin https://blog.avislab.com/
  5. */
  6. #ifndef INC_UART_H_
  7. #define INC_UART_H_
  8. #define BUFFER_LENGTH 64
  9. #define SYNC_BYTE 0xC8
  10. #define FRAME_LENGTH_BYTE 1
  11. #define FRAME_TYPE_BYTE 2
  12. #define FRAME_TYPE_Battery_Sensor 0x08
  13. #define FRAME_TYPE_Link_Statistics 0x14
  14. #define FRAME_TYPE_RC_Channels 0x16
  15. typedef struct
  16. {
  17. uint8_t up_rssi_ant1; // Uplink RSSI Antenna 1 (dBm * -1)
  18. uint8_t up_rssi_ant2; // Uplink RSSI Antenna 2 (dBm * -1)
  19. uint8_t up_link_quality; // Uplink Package success rate / Link quality (%)
  20. int8_t up_snr; // Uplink SNR (dB)
  21. uint8_t active_antenna; // number of currently best antenna
  22. uint8_t rf_profile; // enum {4fps = 0 , 50fps, 150fps}
  23. uint8_t up_rf_power; // enum {0mW = 0, 10mW, 25mW, 100mW,
  24. // 500mW, 1000mW, 2000mW, 250mW, 50mW}
  25. uint8_t down_rssi; // Downlink RSSI (dBm * -1)
  26. uint8_t down_link_quality; // Downlink Package success rate / Link quality (%)
  27. int8_t down_snr;
  28. } RC_LinkStatistics;
  29. typedef struct
  30. {
  31. unsigned int channel_01: 11;
  32. unsigned int channel_02: 11;
  33. unsigned int channel_03: 11;
  34. unsigned int channel_04: 11;
  35. unsigned int channel_05: 11;
  36. unsigned int channel_06: 11;
  37. unsigned int channel_07: 11;
  38. unsigned int channel_08: 11;
  39. unsigned int channel_09: 11;
  40. unsigned int channel_10: 11;
  41. unsigned int channel_11: 11;
  42. unsigned int channel_12: 11;
  43. unsigned int channel_13: 11;
  44. unsigned int channel_14: 11;
  45. unsigned int channel_15: 11;
  46. unsigned int channel_16: 11;
  47. } __PACKED RC_Channels;
  48. /*
  49. typedef struct
  50. {
  51. int16_t voltage;
  52. int16_t current;
  53. int32_t capacity:24;
  54. int8_t remaining;
  55. } __PACKED RC_Battery_Sensors;
  56. */
  57. typedef struct
  58. {
  59. uint8_t sync_byte;
  60. uint8_t length;
  61. uint8_t type;
  62. unsigned int voltage:16;
  63. unsigned int current:16;
  64. unsigned int capacity:24;
  65. unsigned int remaining:8;
  66. uint8_t crc;
  67. } __PACKED RC_RC_BatterySensorsFrame;
  68. void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);
  69. void Uart_StartReceive();
  70. void Uart_StartSendFrame();
  71. void Make_Frame();
  72. unsigned int Uart_GetChannel(uint8_t ch);
  73. void Uart_IncCounter(void);
  74. uint8_t Uart_GetCounter(void);
  75. #endif /* INC_UART_H_ */