#pragma once #ifdef WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include #include #define socketerrno WSAGetLastError() #define SOCKET_EAGAIN_EINPROGRESS WSAEINPROGRESS #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK #ifndef _SSIZE_T_DEFINED typedef int ssize_t; #define _SSIZE_T_DEFINED #endif #ifndef _SOCKET_T_DEFINED typedef SOCKET socket_t; #define _SOCKET_T_DEFINED #endif #else #include #include #include #include #include #include #include #define socketerrno errno #define SOCKET_EAGAIN_EINPROGRESS EAGAIN #define SOCKET_EWOULDBLOCK EWOULDBLOCK #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 #ifndef _SOCKET_T_DEFINED typedef int socket_t; #define _SOCKET_T_DEFINED #endif #endif #include #include "../common/notifier.h" #include "event_log.h" class CCanSensor; class CMessageQueue; class CCarSensor; class CCarSensor { public: CCarSensor(CMessageQueue * q); ~CCarSensor(); void Notify(TPCANMsg& canmsg); void SetSensorSocket(SensorSocket* can); bool Start(); void Stop(); void Notify(int8_t * buffer,int32_t size); void OnMessage(cannet_frame* frames,int32_t count=5); void SetChannelReady(bool bRet); void Write(TPCANMsg& msg); void SetAutomous(bool value,int32_t delay); int64_t GetLastEncodeTime(); void StartParking(bool b); bool IsFrontView(); int16_t GetRiseDownValue() const; int16_t GetTipValue() const; //void OnSignal(RemoNet::CCRobotSignal& req); private: void Run(); void CanSendProc(); void DelayFn(); // bool Throttle(int32_t value); // bool Brake(int32_t value); // bool Steer(int32_t value); // bool Bucket(int32_t value); // bool DriverAnalog(int32_t steer,int32_t throttle,int32_t brake,bool onoff); // bool EmbraceAnalog(int32_t tip,int32_t zoomL,int32_t zoomR,bool onoff); // bool JobAnalog(int16_t n1,int16_t n2,int16_t n3,int16_t n4); // bool EmergencyAnalog(int16_t n1,int16_t n2,int16_t n3,int16_t n4); private: CMessageQueue * _message; std::thread _thread; std::thread _can_thread; bool _can_run; bool _run; bool _tip; bool _rise_down; int16_t _rise_down_value=0; int16_t _tip_value=0; bool _can_ready=false; std::unique_ptr _can; std::unique_ptr _log; //cannet_frame frames[21]; bool _channelReady; bool _front_view=true; bool _automous=false; bool _delayset; // bool _finished=false; SensorSocket * _socket; FeedData _data; int32_t _low_rpm_count=0; std::thread _delay; int32_t _delayseconds; int16_t _brake=0; volatile int64_t _last_encode_uptime=0; volatile int64_t _last_can_uptime=0; std::mutex _last_can_lock; TPCANMsg _msg[5]; int32_t _range_count=0; int16_t _steer=0; private: };