27 lines
770 B
C++
27 lines
770 B
C++
#include "utils.h"
|
|
|
|
std::optional<PrinterDevice> convertToPosPrinterDevice(const std::string& device,
|
|
const std::string& endpoint)
|
|
{
|
|
if (device.empty()) {
|
|
return std::nullopt;
|
|
}
|
|
|
|
PrinterDevice printerDevice;
|
|
std::string delimiter = ":";
|
|
try {
|
|
printerDevice.idVendor = std::stoi(device.substr(0, device.find(delimiter)), 0, 16);
|
|
printerDevice.idProduct = std::stoi(device.substr(device.find(delimiter) + 1), 0, 16);
|
|
if (endpoint.empty()) {
|
|
printerDevice.endpoint = 0x03;
|
|
} else {
|
|
printerDevice.endpoint = std::stoi(endpoint, 0, 16);
|
|
}
|
|
|
|
} catch (std::exception& ex) {
|
|
throw ex;
|
|
}
|
|
|
|
return printerDevice;
|
|
}
|