CJT188.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef __CJT188_H
  2. #define __CJT188_H
  3. #include "stm32f2xx.h"
  4. #include "stdint.h"
  5. #include "usart.h"
  6. #include "stdbool.h"
  7. #define _CJT_RXSIZE 64
  8. #define _CTJ_CTRL_GPIO USART_485_DE_GPIO_PORT
  9. #define _CTJ_CTRL_PIN USART_485_DE_PIN
  10. typedef struct
  11. {
  12. uint16_t rxIndex;
  13. uint8_t rxBuf[_CJT_RXSIZE];
  14. uint32_t rxTime;
  15. uint8_t txBusy;
  16. uint32_t timeout;
  17. uint8_t done;
  18. }CTJBus_t;
  19. #define gettick( ) ( xTaskGetTickCount() )
  20. // 初始化
  21. bool cjt_init(uint32_t timeout);
  22. // 回调函数
  23. void cjt_callback(UART_HandleTypeDef *husart);
  24. // 接收函数
  25. uint16_t cjt_receiveRaw(uint32_t timeout);
  26. // 发送函数
  27. bool cjt_sendRaw(uint8_t *data, uint16_t size, uint32_t timeout);
  28. // 读取数据
  29. bool cjt_read_meter_data(uint8_t* slaveAddress, double* data, uint8_t protocol);
  30. // 读取地址
  31. bool cjt_read_addr(uint8_t *data);
  32. // 设置地址
  33. bool cjt_set_addr(uint8_t *addr);
  34. double data_translate_to_float(uint8_t* msg);
  35. #endif