Switch DS Sim Sockets to use UV loops (#1211)

Also adds the simulation packet to force switch the DS to local.
This commit is contained in:
Thad House
2018-07-22 23:03:55 -07:00
committed by Peter Johnson
parent eb2c6e19f8
commit a34df5589e
6 changed files with 147 additions and 178 deletions

View File

@@ -8,9 +8,13 @@
#pragma once
#include <vector>
namespace halsim {
typedef struct {
std::vector<int16_t> axes;
uint8_t button_count;
uint32_t buttons;
std::vector<int16_t> povs;
} DSCommJoystickPacket;
} // namespace halsim

View File

@@ -16,10 +16,16 @@
#include <DSCommJoystickPacket.h>
#include <FRCComm.h>
#include <mockdata/DriverStationData.h>
#include <wpi/uv/Buffer.h>
namespace halsim {
class DSCommPacket {
public:
DSCommPacket(void) { std::fill_n(m_joystick_types, kMaxJoysticks, -1); }
DSCommPacket(void) {
std::fill_n(m_joystick_types, kMaxJoysticks, -1);
sendDataBuffer = wpi::uv::Buffer::Allocate(8);
}
void Lock() { m_mutex.lock(); }
void Unlock() { m_mutex.unlock(); }
void SetIndex(uint8_t hi, uint8_t lo);
@@ -36,6 +42,7 @@ class DSCommPacket {
void SendTCPToHALSim(void);
void SendUDPToHALSim(void);
void SendJoysticks(void);
wpi::uv::Buffer& GetSendBuffer(void) { return sendDataBuffer; }
/* TCP (FMS) types */
static const uint8_t kGameDataType = 0x0e;
@@ -76,4 +83,7 @@ class DSCommPacket {
int m_udp_packets;
std::chrono::high_resolution_clock::time_point m_packet_time;
double m_match_time;
wpi::uv::Buffer sendDataBuffer;
};
} // namespace halsim

View File

@@ -15,13 +15,7 @@
#ifndef WPILIB_SIMULATION_HALSIM_DS_SOCKET_SRC_MAIN_NATIVE_INCLUDE_FRCCOMM_H_
#define WPILIB_SIMULATION_HALSIM_DS_SOCKET_SRC_MAIN_NATIVE_INCLUDE_FRCCOMM_H_
#ifdef _WIN32
#include <windows.h>
#elif defined(__vxworks)
#include <vxWorks.h>
#elif defined(__linux)
#include <stdint.h>
#endif
#define ERR_FRCSystem_NetCommNotResponding -44049
#define ERR_FRCSystem_NoDSConnection -44018