Assert report ID and length before sending
This commit is contained in:
parent
e40da5f0c0
commit
261d82390b
|
@ -100,8 +100,9 @@ namespace logid::backend::hidpp
|
||||||
bool isError20(hidpp20_error* error);
|
bool isError20(hidpp20_error* error);
|
||||||
|
|
||||||
std::vector<uint8_t> rawReport () const { return _data; }
|
std::vector<uint8_t> rawReport () const { return _data; }
|
||||||
private:
|
|
||||||
static constexpr std::size_t HeaderLength = 4;
|
static constexpr std::size_t HeaderLength = 4;
|
||||||
|
private:
|
||||||
std::vector<uint8_t> _data;
|
std::vector<uint8_t> _data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "../hidpp/defs.h"
|
#include "../hidpp/defs.h"
|
||||||
#include "../dj/defs.h"
|
#include "../dj/defs.h"
|
||||||
#include "../../util.h"
|
#include "../../util.h"
|
||||||
|
#include "../hidpp/Report.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
@ -22,8 +23,24 @@ using namespace logid::backend::raw;
|
||||||
using namespace logid::backend;
|
using namespace logid::backend;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
bool RawDevice::supportedReportID(uint8_t id)
|
bool RawDevice::supportedReport(uint8_t id, uint8_t length)
|
||||||
{
|
{
|
||||||
|
switch(id)
|
||||||
|
{
|
||||||
|
case hidpp::ReportType::Short:
|
||||||
|
return length == (hidpp::ShortParamLength +
|
||||||
|
hidpp::Report::HeaderLength);
|
||||||
|
case hidpp::ReportType::Long:
|
||||||
|
return length == (hidpp::LongParamLength +
|
||||||
|
hidpp::Report::HeaderLength);
|
||||||
|
case dj::ReportType::Short:
|
||||||
|
return length == (dj::ShortParamLength + dj::HeaderLength);
|
||||||
|
case dj::ReportType::Long:
|
||||||
|
return length == (dj::LongParamLength + dj::HeaderLength);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return (hidpp::ReportType::Short == id) || (hidpp::ReportType::Long == id)
|
return (hidpp::ReportType::Short == id) || (hidpp::ReportType::Long == id)
|
||||||
|| (dj::ReportType::Short == id) || (dj::ReportType::Long == id);
|
|| (dj::ReportType::Short == id) || (dj::ReportType::Long == id);
|
||||||
}
|
}
|
||||||
|
@ -116,8 +133,6 @@ std::vector<uint8_t> RawDevice::sendReport(const std::vector<uint8_t>& report)
|
||||||
// DJ commands are not systematically acknowledged, do not expect a result.
|
// DJ commands are not systematically acknowledged, do not expect a result.
|
||||||
void RawDevice::sendReportNoResponse(const std::vector<uint8_t>& report)
|
void RawDevice::sendReportNoResponse(const std::vector<uint8_t>& report)
|
||||||
{
|
{
|
||||||
assert(supportedReportID(report[0]));
|
|
||||||
|
|
||||||
/* If the listener will stop, handle I/O manually.
|
/* If the listener will stop, handle I/O manually.
|
||||||
* Otherwise, push to queue and wait for result. */
|
* Otherwise, push to queue and wait for result. */
|
||||||
if(continue_listen)
|
if(continue_listen)
|
||||||
|
@ -200,7 +215,7 @@ int RawDevice::_sendReport(const std::vector<uint8_t>& report)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(supportedReportID(report[0]));
|
assert(supportedReport(report[0], report.size()));
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(dev_io);
|
std::lock_guard<std::mutex> lock(dev_io);
|
||||||
int ret = ::write(fd, report.data(), report.size());
|
int ret = ::write(fd, report.data(), report.size());
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace raw
|
||||||
class RawDevice
|
class RawDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool supportedReportID(uint8_t id);
|
static bool supportedReport(uint8_t id, uint8_t length);
|
||||||
|
|
||||||
explicit RawDevice(std::string path);
|
explicit RawDevice(std::string path);
|
||||||
~RawDevice();
|
~RawDevice();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user