#pragma once #include "ComplexCommand.h" #include "ByteCommandQueue.h" #include "SetTimeCommand.h" #include "ByteArrayProvider.h" #include "UsbDeviceManager.h" #include "DateTimeObject.h" namespace Incart::DeviceComplexCommands { class MicroMonSetTimeCommand : public SetTimeCommand { private: Common::DateTimeObject m_dateTime; Usb::UsbDeviceManager* const m_usbDeviceManager; public: MicroMonSetTimeCommand(uint32_t uid, const Common::DateTimeObject& dateTime, Usb::UsbDeviceManager* const usbDeviceManager) : SetTimeCommand(uid) , m_dateTime(dateTime), m_usbDeviceManager(usbDeviceManager) { } public: std::shared_ptr execute() override { std::vector commandDataBytes { Common::ByteArrayProvider::toHexFromDec(m_dateTime.time.getSeconds()), Common::ByteArrayProvider::toHexFromDec(m_dateTime.time.getMinutes()), Common::ByteArrayProvider::toHexFromDec(m_dateTime.time.getHours()), Common::ByteArrayProvider::toHexFromDec(m_dateTime.date.getDay()), Common::ByteArrayProvider::toHexFromDec(m_dateTime.date.getMonth()), Common::ByteArrayProvider::toHexFromDec(m_dateTime.date.getYear() % 100) }; std::vector commandBytes; Usb::ByteCommandQueue* commandQueue = m_usbDeviceManager->getCommandQueue(); std::shared_ptr commandInfo = std::make_shared("WriteRtc", commandQueue->generateUid(), commandDataBytes); Usb::DeviceCommand::EStatus status = m_usbDeviceManager->getCommandSet()->createCommandBytes(commandInfo, commandBytes); if (status != Usb::DeviceCommand::EStatus::OK) { return Usb::DeviceCommandStatusCreator::create({}, status); } std::shared_ptr command = std::make_shared(commandInfo->name, commandInfo->uid, std::move(commandBytes)); connect(command.get(), &Usb::ByteCommand::answerIsReady, this, &MicroMonSetTimeCommand::handleAnswerIsReady); commandQueue->enqueue(command); return std::make_shared(Usb::DeviceCommand::EStatus::OK); } private slots: void handleAnswerIsReady(std::shared_ptr /*command*/, std::vector answer, int32_t status) { emit answerIsReady(this, Usb::DeviceCommandStatusCreator::create(answer, status)); } }; } // namespace Incart::DeviceComplexCommands