pcan_sensor.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef WIN32
  3. #ifndef WIN32_LEAN_AND_MEAN
  4. #define WIN32_LEAN_AND_MEAN
  5. #endif
  6. #include <WS2tcpip.h>
  7. #include <WinSock2.h>
  8. #define socketerrno WSAGetLastError()
  9. #define SOCKET_EAGAIN_EINPROGRESS WSAEINPROGRESS
  10. #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
  11. #ifndef _SSIZE_T_DEFINED
  12. typedef int ssize_t;
  13. #define _SSIZE_T_DEFINED
  14. #endif
  15. #ifndef _SOCKET_T_DEFINED
  16. typedef SOCKET socket_t;
  17. #define _SOCKET_T_DEFINED
  18. #endif
  19. #else
  20. #include <unistd.h>
  21. #include <arpa/inet.h>
  22. #include <sys/types.h>
  23. #include <sys/socket.h>
  24. #include <netinet/in.h>
  25. #include <netinet/tcp.h>
  26. #include <fcntl.h>
  27. #define socketerrno errno
  28. #define SOCKET_EAGAIN_EINPROGRESS EAGAIN
  29. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  30. #define INVALID_SOCKET -1
  31. #define SOCKET_ERROR -1
  32. #ifndef _SOCKET_T_DEFINED
  33. typedef int socket_t;
  34. #define _SOCKET_T_DEFINED
  35. #endif
  36. #endif
  37. #include "../common/notifier.h"
  38. #include <stdint.h>
  39. #include "../common/comm.h"
  40. #include "../common/iobuffer.h"
  41. #include "../common/sensor_socket.h"
  42. #include <thread>
  43. #include <math.h>
  44. class CMessageQueue;
  45. class CPcanSensor
  46. {
  47. public:
  48. CPcanSensor(CMessageQueue * q);
  49. void Notify(TPCANMsg *buffer, int32_t size);
  50. void SetSensorSocket(SensorPeakCan<CPcanSensor>* can);
  51. void OnMessage(cannet_frame* frames, int32_t count = 4);
  52. void Start();
  53. void Stop();
  54. bool Emergency(); //急停 只局限于程序 和网络
  55. void Run();
  56. private:
  57. void SendStatusToMSG();
  58. private:
  59. CMessageQueue * _message;
  60. SensorPeakCan<CPcanSensor> * _socket;
  61. bool _run;
  62. std::mutex _last_can_lock;
  63. bool _front_view = true;
  64. TPCANMsg _msg[4];
  65. FeedData _data;
  66. //int b_ready;
  67. //int b_over;
  68. int model;//0本地,1远程
  69. int16_t Direction;//方向
  70. int16_t Hand_Throttle;//手油门
  71. int16_t Foot_Throttle;//脚油门
  72. int16_t Brake;//刹车
  73. };