comm_car_485(5702).c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "comm_car_485.h"
  2. //-------------参数定义
  3. rs485RecDate s_rs485RecDate;
  4. rs485SendDate s_rs485SendDate;
  5. /**
  6. * @brief crc16计算
  7. * @param ptr: 数据首地址
  8. * @param len: 数据长度
  9. * @return
  10. */
  11. unsigned short mb_crc16(unsigned char *ptr, int len)
  12. {
  13. unsigned int i;
  14. unsigned short crc = 0xFFFF;
  15. while(len--)
  16. {
  17. crc ^= *ptr++;
  18. for (i = 0; i < 8; ++i)
  19. {
  20. if (crc & 1)
  21. crc = (crc >> 1) ^ 0xA001;
  22. else
  23. crc = (crc >> 1);
  24. }
  25. }
  26. return crc;
  27. }
  28. /**
  29. * @brief 485发送函数
  30. * @param data: 发送的数据
  31. * @param dataLen: 发送的数据长度
  32. * @note
  33. * @retval 无
  34. */
  35. void rs485_sendDate(uint8_t data[], uint32_t dataLen){
  36. }
  37. /**
  38. * @brief 485接收分析函数
  39. * @param data: 接收到的数据
  40. * @note
  41. * @retval 无
  42. */
  43. void rs485_recDateAnalyse(uint8_t data[]){
  44. /* 尝试获取互斥量,等待无限长时间 */
  45. if(osMutexAcquire(mutex_rs485RecDateHandle, osWaitForever) == osOK){
  46. /* 访问完成,释放互斥量 */
  47. osMutexRelease(mutex_rs485RecDateHandle);
  48. }
  49. }
  50. /**
  51. * @brief 轮询发送接收
  52. * @note
  53. * @retval 无
  54. */
  55. void rs485_poll_sendReceive(void){
  56. static uint8_t rs485Step = 0;
  57. switch(rs485Step){
  58. case 0:
  59. break;
  60. case 1:
  61. break;
  62. default: break;
  63. }
  64. }