123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #pragma once
- #ifdef WIN32
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include <WS2tcpip.h>
- #include <WinSock2.h>
- #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 <unistd.h>
- #include <arpa/inet.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netinet/tcp.h>
- #include <fcntl.h>
- #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 <fstream>
- #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<CCarSensor>* 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<CCanSensor> _can;
- std::unique_ptr<CEventLog> _log;
- //cannet_frame frames[21];
- bool _channelReady;
- bool _front_view=true;
- bool _automous=false;
- bool _delayset;
- // bool _finished=false;
- SensorSocket<CCarSensor> * _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:
-
-
-
-
- };
|