soft_gs.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __SOFT_GS_H
  2. #define __SOFT_GS_H
  3. #include "common.h"
  4. #include "drv_usart.h"
  5. #include "rkfifo.h"
  6. // #include "stm32f4xx.h"
  7. #include "vklink.h"
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. /* 协议类型 */
  11. typedef enum
  12. {
  13. /* 地面站使用 VKLINK 协议 */
  14. GCS_LINK_PROTOCAL_TYPE_VKLINK = 0,
  15. } GcsLinkProtocalType;
  16. /* 地面站连接对象 */
  17. struct GCS_Link
  18. {
  19. /* 协议类型 */
  20. GcsLinkProtocalType link_protocal_type;
  21. /* 串口发收消息 */
  22. VKlink_Msg_Type vklink_rx_msg;
  23. VKlink_Msg_Type vklink_tx_msg;
  24. /* 地面站 vklink 协议版本, 现在有 300 版和 400 两个版本 */
  25. uint16_t vklink_protocal_version;
  26. /* 地面站连接状态 */
  27. comp_status link_status;
  28. uint32_t link_lost_time_us;
  29. uint32_t last_check_time_us;
  30. struct stm32_uart *uart;
  31. uint8_t msg_pack_buffer[512];
  32. /* 常发消息使用记时 */
  33. uint32_t _last_tx1hz_time_us;
  34. uint32_t _last_tx2hz_time_us;
  35. uint32_t _last_tx5hz_time_us;
  36. uint32_t _last_tx10hz_time_us;
  37. uint8_t _last_tx1hz_id;
  38. uint8_t _last_tx2hz_id;
  39. uint8_t _last_tx5hz_id;
  40. uint8_t _last_tx10hz_id;
  41. /* 当前多级模式选中的 sysid */
  42. uint8_t _current_sysid;
  43. };
  44. extern struct GCS_Link gcs_link;
  45. /* 地面站串口初始化 */
  46. int gcs_init(struct GCS_Link *gcs, unsigned int gs_bps);
  47. /* 地面站串口解析和发送消息轮询函数 */
  48. void gs_receive_msg_poll(struct GCS_Link *pgcs);
  49. void gs_send_msg_poll(struct GCS_Link *pgcs);
  50. uint8_t *gs_get_uart_tx_buffer_address(void);
  51. comp_status gs_get_link_status(struct GCS_Link *pgcs);
  52. void gs_tx_vklink_msg(struct GCS_Link *pgcs, const VKlink_Msg_Type *msg);
  53. void gs_set_vklink_protocal_version(struct GCS_Link *gcs, uint16_t version);
  54. /* 发送 pos 点信息 */
  55. void gs_send_pos_msg(struct GCS_Link *pgcs, uint32_t pos_num);
  56. /* 发送 ack 应答信息 */
  57. void gs_send_ack_msg(struct GCS_Link *pgcs, void *arg);
  58. /* 发送载荷透传信息 */
  59. void gs_send_payload_msg(struct GCS_Link *pgcs, const void * pdata, uint32_t len);
  60. #endif