soft_gs.h 2.0 KB

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