123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #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 "../common/notifier.h"
-
- class CMessageQueue;
- #pragma pack(1)
- struct OpState{
- uint16_t func=htons(10);
- uint16_t boot_addr=htons(101);
- uint16_t boot_value=0;
- uint16_t start_addr=htons(102);
- uint16_t start_value=0;
- uint16_t stop_addr=htons(103);
- uint16_t stop_value=0;
- uint16_t emergency_addr=htons(104);
- uint16_t emergency_value=0;
- uint16_t gear_addr=htons(135);
- uint16_t gear_value=0;
- uint16_t wip_addr=htons(132);
- uint16_t wip_value=0;
- uint16_t flight_addr=htons(133);
- uint16_t flight_value=0;
- uint16_t blight_addr=htons(134);
- uint16_t blight_value=0;
- uint16_t park_addr=htons(135);
- uint16_t park_value=0;
- uint16_t ldlight_addr=htons(136);
- uint16_t ldlight_value=0;
- uint16_t rdlight_addr=htons(137);
- uint16_t rdlight_value=0;
- uint16_t gear_d_addr=htons(138);
- uint16_t gear_d_value=0;
- uint16_t buz_addr=htons(139);
- uint16_t buz_value=0;
- };
- struct Analog_rtu {
- int16_t func=htons(10);
- int16_t steer_addr=htons(113);
- int16_t steer_value=0;
- int16_t arm_addr=htons(117);
- int16_t arm_value=0;
- int16_t bucket_addr=htons(119);
- int16_t bucket_value=0;
- int16_t throttle_addr=htons(111);
- int16_t throttle_value=0;
- int16_t brake_addr=htons(115);
- int16_t brake_value=0;
-
- };
-
- struct ReadCmd
- {
- int16_t func=htons(03);
- int16_t boot_addr=htons(201);
- int16_t start_addr=htons(203);
- int16_t stop_addr=htons(205);
- int16_t emergenc_addr=htons(207);
- };
- struct ReadRet
- {
- int16_t func=3;
- int16_t boot_addr;
- int16_t boot_value;
- int16_t start_addr;
- int16_t start_value;
- int16_t stop_addr;
- int16_t stop_value;
- int16_t emergenc_addr;
- int16_t emergenc_value;
- };
- #pragma pack()
- class CRobotSensor
- {
- public:
- CRobotSensor(CMessageQueue * q);
- void Notify(TPCANMsg *buffer, int32_t size);
- void SetSensorSocket(SensorPeakCan<CRobotSensor>* can);
- void OnMessage(cannet_frame* frames, int32_t count = 4);
- void Start();
- void Stop();
- bool Emergency(); //急停 只局限于程序 和网络
- void Run();
- private:
- unsigned int CRC16(uint8_t *buf, int len);
-
-
- void OnPark(bool on);
- bool Resume();
-
- void CanSendProc();
- void SendStatusToMSG();
-
- private:
-
-
- CMessageQueue * _message;
- SensorPeakCan<CRobotSensor> * _socket;
-
- bool _resume=false;
- bool _emergency=false;
- bool _autorise=false;
- RemoNet::Gears _gears=RemoNet::Gears::N;
- RemoNet::DirectionLight _light=RemoNet::DirectionLight::OffLight;
- RemoNet::Gears_D _gears_d=RemoNet::Gears_D::None_d;
- bool _frontLight=false;
- bool _backLight=false;
- bool _wipe=false;
- bool _buzzer=false;
- bool _park=false;
-
- bool _run;
- int8_t value_g=1;
- OpState state;
-
- std::mutex _last_can_lock;
- std::thread _can_thread;
- bool _front_view = true;
- volatile int64_t _last_can_uptime = 0;
- TPCANMsg _msg[4];
- FeedData _data;
- int b_ready;
- int b_over;
- int model;//0本地,1远程
-
- };
|