| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #ifndef RUNNER_READER_SERVICE_H_
- #define RUNNER_READER_SERVICE_H_
- #include <iostream>
- #include <vector>
- #include <string>
- #include <functional>
- #include <thread>
- #include <atomic>
- #include <chrono>
- extern "C"
- {
- #include "SWHidApi.h"
- }
- // Define data callback type to notify UI of received tag data
- typedef std::function<void(const std::string &)> DataCallback;
- // Service for handling USB scanning functionality
- class ReaderService
- {
- public:
- // Get singleton instance
- static ReaderService *GetInstance();
- // Scan USB devices and return list of device names
- std::vector<std::string> ScanUsb();
- // Connect to specified USB device by index
- bool Connect(int deviceIndex);
- // Disconnect
- void Disconnect();
- // Start reading in answer mode
- bool StartRead();
- // Stop reading in answer mode
- void StopRead();
- void AnswerMode();
- // Set data callback function to notify UI of received data
- void SetDataCallback(DataCallback callback) { data_callback_ = callback; }
- // Get device system information and return it as a string
- std::string GetDeviceInfo();
- // Get current power level (returns true on success)
- bool GetPower(unsigned char& power);
- // Set power level (returns true on success)
- bool SetPower(unsigned char power);
- private:
- ReaderService() = default;
- ~ReaderService();
- // Disable copy constructor and assignment operator
- ReaderService(const ReaderService &) = delete;
- ReaderService &operator=(const ReaderService &) = delete;
- // Static callback function for receiving device data
- static void DeviceCallback(int msg, int param1, unsigned char *param2, int param3, unsigned char *param4);
- // Function to run the timer loop for periodically calling AnswerMode
- void RunTimer();
- // Member variables
- bool connected_ = false;
- bool reading_ = false;
- std::atomic<bool> timer_running_{false};
- std::unique_ptr<std::thread> timer_thread_;
- DataCallback data_callback_;
- };
- #endif // RUNNER_READER_SERVICE_H_
|